[PATCH net-next v2 2/2] ice: ptp: add control over HW timestamp latch point

Arkadiusz Kubalewski posted 2 patches 3 weeks, 6 days ago
There is a newer version of this series
[PATCH net-next v2 2/2] ice: ptp: add control over HW timestamp latch point
Posted by Arkadiusz Kubalewski 3 weeks, 6 days ago
Allow user to control the latch point of ptp HW timestamps in E825
devices.

Usage, examples:

** Obtain current state:
$ cat /sys/class/net/eth<N>/device/ptp/ts_point
Command returns enum/integer:
* 0 - timestamp latched by PHY at the beginning of SFD,
* 1 - timestamp latched by PHY after the SFD,
* None - callback returns error to the user.

** Configure timestamp latch point at the beginning of SFD:
$ echo 0 > /sys/class/net/eth<N>/device/ptp/ts_point

** Configure timestamp latch point after the SFD:
$ echo 1 > /sys/class/net/eth<N>/device/ptp/ts_point

Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
---
v2:
- add kernel doc return description on ice_get_ts_point(..),
- use enum ptp_ts_point directly, instead of additional bool to pass tx
  timestamp latch point from userspace callback up to ptp_hw
  configuration,
- fix bit logic.
---
 drivers/net/ethernet/intel/ice/ice_ptp.c    | 44 +++++++++++++++
 drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 59 +++++++++++++++++++++
 drivers/net/ethernet/intel/ice/ice_ptp_hw.h |  2 +
 3 files changed, 105 insertions(+)

diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c
index a999fface272..21fc6b5e2d69 100644
--- a/drivers/net/ethernet/intel/ice/ice_ptp.c
+++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
@@ -2509,6 +2509,48 @@ static int ice_ptp_parse_sdp_entries(struct ice_pf *pf, __le16 *entries,
 	return 0;
 }
 
+/**
+ * ice_get_ts_point - get the tx timestamp latch point
+ * @info: the driver's PTP info structure
+ * @point: return the configured tx timestamp latch point
+ *
+ * Return: 0 on success, negative on failure.
+ */
+static int
+ice_get_ts_point(struct ptp_clock_info *info, enum ptp_ts_point *point)
+{
+	struct ice_pf *pf = ptp_info_to_pf(info);
+	struct ice_hw *hw = &pf->hw;
+	int ret;
+
+	ice_ptp_lock(hw);
+	ret = ice_ptp_hw_ts_point_get(hw, point);
+	ice_ptp_unlock(hw);
+
+	return ret;
+}
+
+/**
+ * ice_set_ts_point - set the tx timestamp latch point
+ * @info: the driver's PTP info structure
+ * @point: requested tx timestamp latch point
+ *
+ * Return: 0 on success, negative on failure.
+ */
+static int
+ice_set_ts_point(struct ptp_clock_info *info, enum ptp_ts_point point)
+{
+	struct ice_pf *pf = ptp_info_to_pf(info);
+	struct ice_hw *hw = &pf->hw;
+	int ret;
+
+	ice_ptp_lock(hw);
+	ret = ice_ptp_hw_ts_point_set(hw, point);
+	ice_ptp_unlock(hw);
+
+	return ret;
+}
+
 /**
  * ice_ptp_set_funcs_e82x - Set specialized functions for E82X support
  * @pf: Board private structure
@@ -2529,6 +2571,8 @@ static void ice_ptp_set_funcs_e82x(struct ice_pf *pf)
 	if (ice_is_e825c(&pf->hw)) {
 		pf->ptp.ice_pin_desc = ice_pin_desc_e825c;
 		pf->ptp.info.n_pins = ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e825c);
+		pf->ptp.info.set_ts_point = ice_set_ts_point;
+		pf->ptp.info.get_ts_point = ice_get_ts_point;
 	} else {
 		pf->ptp.ice_pin_desc = ice_pin_desc_e82x;
 		pf->ptp.info.n_pins = ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e82x);
diff --git a/drivers/net/ethernet/intel/ice/ice_ptp_hw.c b/drivers/net/ethernet/intel/ice/ice_ptp_hw.c
index da88c6ccfaeb..0d2d3e36341e 100644
--- a/drivers/net/ethernet/intel/ice/ice_ptp_hw.c
+++ b/drivers/net/ethernet/intel/ice/ice_ptp_hw.c
@@ -6303,3 +6303,62 @@ int ice_cgu_get_output_pin_state_caps(struct ice_hw *hw, u8 pin_id,
 
 	return 0;
 }
+
+/**
+ * ice_ptp_hw_ts_point_get - check if tx timestamping is latched on/post SFD
+ * @hw: pointer to the HW struct
+ * @point: return the configured tx timestamp latch point
+ *
+ * Verify if HW timestamping point is configured to measure at the beginning or
+ * post of SFD (Start of Frame Delimiter)
+ *
+ * Return: 0 on success, negative on error
+ */
+int ice_ptp_hw_ts_point_get(struct ice_hw *hw, enum ptp_ts_point *point)
+{
+	u8 port = hw->port_info->lport;
+	u32 val;
+	int err;
+
+	err = ice_read_mac_reg_eth56g(hw, port, PHY_MAC_XIF_MODE, &val);
+	if (err)
+		return err;
+	if (val & PHY_MAC_XIF_TS_SFD_ENA_M)
+		*point = PTP_TS_POINT_SFD;
+	else
+		*point = PTP_TS_POINT_POST_SFD;
+
+	return err;
+}
+
+/**
+ * ice_ptp_hw_ts_point_set - configure timestamping on/post SFD
+ * @hw: pointer to the HW struct
+ * @point: requested tx timestamp latch point
+ *
+ * Configure timestamping to measure at the beginning/post SFD (Start of Frame
+ * Delimiter)
+ *
+ * Return: 0 on success, negative on error
+ */
+int ice_ptp_hw_ts_point_set(struct ice_hw *hw, enum ptp_ts_point point)
+{
+	u8 port = hw->port_info->lport;
+	int err, val;
+
+	err = ice_read_mac_reg_eth56g(hw, port, PHY_MAC_XIF_MODE, &val);
+	if (err)
+		return err;
+	if ((val & PHY_MAC_XIF_TS_SFD_ENA_M && point == PTP_TS_POINT_SFD) ||
+	    (!(val & PHY_MAC_XIF_TS_SFD_ENA_M) &&
+	     point == PTP_TS_POINT_POST_SFD))
+		return -EINVAL;
+	if (point == PTP_TS_POINT_SFD)
+		val |= PHY_MAC_XIF_TS_SFD_ENA_M;
+	else if (point == PTP_TS_POINT_POST_SFD)
+		val &= ~PHY_MAC_XIF_TS_SFD_ENA_M;
+	else
+		return -EINVAL;
+
+	return ice_write_mac_reg_eth56g(hw, port, PHY_MAC_XIF_MODE, val);
+}
diff --git a/drivers/net/ethernet/intel/ice/ice_ptp_hw.h b/drivers/net/ethernet/intel/ice/ice_ptp_hw.h
index 656daff3447e..f8e495b82653 100644
--- a/drivers/net/ethernet/intel/ice/ice_ptp_hw.h
+++ b/drivers/net/ethernet/intel/ice/ice_ptp_hw.h
@@ -348,6 +348,8 @@ void ice_ptp_init_hw(struct ice_hw *hw);
 int ice_get_phy_tx_tstamp_ready(struct ice_hw *hw, u8 block, u64 *tstamp_ready);
 int ice_ptp_one_port_cmd(struct ice_hw *hw, u8 configured_port,
 			 enum ice_ptp_tmr_cmd configured_cmd);
+int ice_ptp_hw_ts_point_get(struct ice_hw *hw, enum ptp_ts_point *point);
+int ice_ptp_hw_ts_point_set(struct ice_hw *hw, enum ptp_ts_point point);
 
 /* E822 family functions */
 int ice_read_quad_reg_e82x(struct ice_hw *hw, u8 quad, u16 offset, u32 *val);
-- 
2.38.1
Re: [PATCH net-next v2 2/2] ice: ptp: add control over HW timestamp latch point
Posted by Przemek Kitszel 3 weeks, 5 days ago
On 10/28/24 21:47, Arkadiusz Kubalewski wrote:
> Allow user to control the latch point of ptp HW timestamps in E825

sometimes you write ptp, sometimes PTP, I would make it consistent
(but subject line is fine as is)

> devices.
> 
> Usage, examples:
> 
> ** Obtain current state:
> $ cat /sys/class/net/eth<N>/device/ptp/ts_point
> Command returns enum/integer:
> * 0 - timestamp latched by PHY at the beginning of SFD,
> * 1 - timestamp latched by PHY after the SFD,

perhaps those values could be exported to uAPI?
(the enum from the prev patch)
+enum ptp_ts_point {
+	PTP_TS_POINT_SFD,
+	PTP_TS_POINT_POST_SFD,

> * None - callback returns error to the user.
> 
> ** Configure timestamp latch point at the beginning of SFD:
> $ echo 0 > /sys/class/net/eth<N>/device/ptp/ts_point
> 
> ** Configure timestamp latch point after the SFD:
> $ echo 1 > /sys/class/net/eth<N>/device/ptp/ts_point
> 
> Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
> Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>

general ask: for future submissions please use --base switch of
git-send-email, this will aid resolving conflicts or applying the patch
locally for review;

this series in particular would likely conflicts with current
Tony's dev-queue (didn't checked, but Karol removes ice_is_e825c(),
called within 3-line context of your changes).

> ---
> v2:
> - add kernel doc return description on ice_get_ts_point(..),
> - use enum ptp_ts_point directly, instead of additional bool to pass tx
>    timestamp latch point from userspace callback up to ptp_hw
>    configuration,
> - fix bit logic.
> ---
>   drivers/net/ethernet/intel/ice/ice_ptp.c    | 44 +++++++++++++++
>   drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 59 +++++++++++++++++++++
>   drivers/net/ethernet/intel/ice/ice_ptp_hw.h |  2 +
>   3 files changed, 105 insertions(+)
> 
> diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c
> index a999fface272..21fc6b5e2d69 100644
> --- a/drivers/net/ethernet/intel/ice/ice_ptp.c
> +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
> @@ -2509,6 +2509,48 @@ static int ice_ptp_parse_sdp_entries(struct ice_pf *pf, __le16 *entries,
>   	return 0;
>   }
>   
> +/**
> + * ice_get_ts_point - get the tx timestamp latch point

Tx, please apply in the whole patch

> + * @info: the driver's PTP info structure
> + * @point: return the configured tx timestamp latch point
> + *
> + * Return: 0 on success, negative on failure.
> + */
> +static int
> +ice_get_ts_point(struct ptp_clock_info *info, enum ptp_ts_point *point)

nit: the current preferred style is to break line after "info,"

> +{
> +	struct ice_pf *pf = ptp_info_to_pf(info);
> +	struct ice_hw *hw = &pf->hw;
> +	int ret;
> +
> +	ice_ptp_lock(hw);
> +	ret = ice_ptp_hw_ts_point_get(hw, point);
> +	ice_ptp_unlock(hw);
> +
> +	return ret;
> +}

[...]

> +/**
> + * ice_ptp_hw_ts_point_set - configure timestamping on/post SFD
> + * @hw: pointer to the HW struct
> + * @point: requested tx timestamp latch point
> + *
> + * Configure timestamping to measure at the beginning/post SFD (Start of Frame
> + * Delimiter)
> + *
> + * Return: 0 on success, negative on error
> + */
> +int ice_ptp_hw_ts_point_set(struct ice_hw *hw, enum ptp_ts_point point)
> +{
> +	u8 port = hw->port_info->lport;
> +	int err, val;
> +
> +	err = ice_read_mac_reg_eth56g(hw, port, PHY_MAC_XIF_MODE, &val);
> +	if (err)
> +		return err;
> +	if ((val & PHY_MAC_XIF_TS_SFD_ENA_M && point == PTP_TS_POINT_SFD) ||
> +	    (!(val & PHY_MAC_XIF_TS_SFD_ENA_M) &&
> +	     point == PTP_TS_POINT_POST_SFD))

that's the thing that urged me to start commenting on this patch ;)

put braces around (bit & arith) combined with logical && or ||

you could also split into multiple if branches for readability

> +		return -EINVAL;
> +	if (point == PTP_TS_POINT_SFD)
> +		val |= PHY_MAC_XIF_TS_SFD_ENA_M;
> +	else if (point == PTP_TS_POINT_POST_SFD)
> +		val &= ~PHY_MAC_XIF_TS_SFD_ENA_M;
> +	else
> +		return -EINVAL;
> +
> +	return ice_write_mac_reg_eth56g(hw, port, PHY_MAC_XIF_MODE, val);
> +}
> diff --git a/drivers/net/ethernet/intel/ice/ice_ptp_hw.h b/drivers/net/ethernet/intel/ice/ice_ptp_hw.h
> index 656daff3447e..f8e495b82653 100644
> --- a/drivers/net/ethernet/intel/ice/ice_ptp_hw.h
> +++ b/drivers/net/ethernet/intel/ice/ice_ptp_hw.h
> @@ -348,6 +348,8 @@ void ice_ptp_init_hw(struct ice_hw *hw);
>   int ice_get_phy_tx_tstamp_ready(struct ice_hw *hw, u8 block, u64 *tstamp_ready);
>   int ice_ptp_one_port_cmd(struct ice_hw *hw, u8 configured_port,
>   			 enum ice_ptp_tmr_cmd configured_cmd);
> +int ice_ptp_hw_ts_point_get(struct ice_hw *hw, enum ptp_ts_point *point);
> +int ice_ptp_hw_ts_point_set(struct ice_hw *hw, enum ptp_ts_point point);
>   
>   /* E822 family functions */
>   int ice_read_quad_reg_e82x(struct ice_hw *hw, u8 quad, u16 offset, u32 *val);
RE: [PATCH net-next v2 2/2] ice: ptp: add control over HW timestamp latch point
Posted by Kubalewski, Arkadiusz 2 weeks, 5 days ago
>From: Kitszel, Przemyslaw <przemyslaw.kitszel@intel.com>
>Sent: Tuesday, October 29, 2024 9:22 AM
>
>On 10/28/24 21:47, Arkadiusz Kubalewski wrote:
>> Allow user to control the latch point of ptp HW timestamps in E825
>
>sometimes you write ptp, sometimes PTP, I would make it consistent
>(but subject line is fine as is)
>
>> devices.
>>
>> Usage, examples:
>>
>> ** Obtain current state:
>> $ cat /sys/class/net/eth<N>/device/ptp/ts_point
>> Command returns enum/integer:
>> * 0 - timestamp latched by PHY at the beginning of SFD,
>> * 1 - timestamp latched by PHY after the SFD,
>
>perhaps those values could be exported to uAPI?
>(the enum from the prev patch)
>+enum ptp_ts_point {
>+	PTP_TS_POINT_SFD,
>+	PTP_TS_POINT_POST_SFD,
>
>> * None - callback returns error to the user.
>>
>> ** Configure timestamp latch point at the beginning of SFD:
>> $ echo 0 > /sys/class/net/eth<N>/device/ptp/ts_point
>>
>> ** Configure timestamp latch point after the SFD:
>> $ echo 1 > /sys/class/net/eth<N>/device/ptp/ts_point
>>
>> Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
>> Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
>
>general ask: for future submissions please use --base switch of
>git-send-email, this will aid resolving conflicts or applying the patch
>locally for review;
>
>this series in particular would likely conflicts with current
>Tony's dev-queue (didn't checked, but Karol removes ice_is_e825c(),
>called within 3-line context of your changes).
>
>> ---
>> v2:
>> - add kernel doc return description on ice_get_ts_point(..),
>> - use enum ptp_ts_point directly, instead of additional bool to pass tx
>>    timestamp latch point from userspace callback up to ptp_hw
>>    configuration,
>> - fix bit logic.
>> ---
>>   drivers/net/ethernet/intel/ice/ice_ptp.c    | 44 +++++++++++++++
>>   drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 59 +++++++++++++++++++++
>>   drivers/net/ethernet/intel/ice/ice_ptp_hw.h |  2 +
>>   3 files changed, 105 insertions(+)
>>
>> diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c
>b/drivers/net/ethernet/intel/ice/ice_ptp.c
>> index a999fface272..21fc6b5e2d69 100644
>> --- a/drivers/net/ethernet/intel/ice/ice_ptp.c
>> +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
>> @@ -2509,6 +2509,48 @@ static int ice_ptp_parse_sdp_entries(struct ice_pf
>>*pf, __le16 *entries,
>>   	return 0;
>>   }
>>
>> +/**
>> + * ice_get_ts_point - get the tx timestamp latch point
>
>Tx, please apply in the whole patch
>
>> + * @info: the driver's PTP info structure
>> + * @point: return the configured tx timestamp latch point
>> + *
>> + * Return: 0 on success, negative on failure.
>> + */
>> +static int
>> +ice_get_ts_point(struct ptp_clock_info *info, enum ptp_ts_point *point)
>
>nit: the current preferred style is to break line after "info,"
>
>> +{
>> +	struct ice_pf *pf = ptp_info_to_pf(info);
>> +	struct ice_hw *hw = &pf->hw;
>> +	int ret;
>> +
>> +	ice_ptp_lock(hw);
>> +	ret = ice_ptp_hw_ts_point_get(hw, point);
>> +	ice_ptp_unlock(hw);
>> +
>> +	return ret;
>> +}
>
>[...]
>
>> +/**
>> + * ice_ptp_hw_ts_point_set - configure timestamping on/post SFD
>> + * @hw: pointer to the HW struct
>> + * @point: requested tx timestamp latch point
>> + *
>> + * Configure timestamping to measure at the beginning/post SFD (Start of
>> Frame
>> + * Delimiter)
>> + *
>> + * Return: 0 on success, negative on error
>> + */
>> +int ice_ptp_hw_ts_point_set(struct ice_hw *hw, enum ptp_ts_point point)
>> +{
>> +	u8 port = hw->port_info->lport;
>> +	int err, val;
>> +
>> +	err = ice_read_mac_reg_eth56g(hw, port, PHY_MAC_XIF_MODE, &val);
>> +	if (err)
>> +		return err;
>> +	if ((val & PHY_MAC_XIF_TS_SFD_ENA_M && point == PTP_TS_POINT_SFD) ||
>> +	    (!(val & PHY_MAC_XIF_TS_SFD_ENA_M) &&
>> +	     point == PTP_TS_POINT_POST_SFD))
>
>that's the thing that urged me to start commenting on this patch ;)
>
>put braces around (bit & arith) combined with logical && or ||
>
>you could also split into multiple if branches for readability
>
>> +		return -EINVAL;
>> +	if (point == PTP_TS_POINT_SFD)
>> +		val |= PHY_MAC_XIF_TS_SFD_ENA_M;
>> +	else if (point == PTP_TS_POINT_POST_SFD)
>> +		val &= ~PHY_MAC_XIF_TS_SFD_ENA_M;
>> +	else
>> +		return -EINVAL;
>> +
>> +	return ice_write_mac_reg_eth56g(hw, port, PHY_MAC_XIF_MODE, val);
>> +}
>> diff --git a/drivers/net/ethernet/intel/ice/ice_ptp_hw.h
>>b/drivers/net/ethernet/intel/ice/ice_ptp_hw.h
>> index 656daff3447e..f8e495b82653 100644
>> --- a/drivers/net/ethernet/intel/ice/ice_ptp_hw.h
>> +++ b/drivers/net/ethernet/intel/ice/ice_ptp_hw.h
>> @@ -348,6 +348,8 @@ void ice_ptp_init_hw(struct ice_hw *hw);
>>   int ice_get_phy_tx_tstamp_ready(struct ice_hw *hw, u8 block, u64
>>*tstamp_ready);
>>   int ice_ptp_one_port_cmd(struct ice_hw *hw, u8 configured_port,
>>   			 enum ice_ptp_tmr_cmd configured_cmd);
>> +int ice_ptp_hw_ts_point_get(struct ice_hw *hw, enum ptp_ts_point
>>*point);
>> +int ice_ptp_hw_ts_point_set(struct ice_hw *hw, enum ptp_ts_point point);
>>
>>   /* E822 family functions */
>>   int ice_read_quad_reg_e82x(struct ice_hw *hw, u8 quad, u16 offset, u32
>>*val);

Fixed all in v3.

Thank you!
Arkadiusz