All of lore.kernel.org
 help / color / mirror / Atom feed
* [net-next 00/14] ptp: convert drivers to .adjfine
@ 2022-08-18 22:27 Jacob Keller
  2022-08-18 22:27 ` [net-next 01/14] ptp: add missing documentation for parameters Jacob Keller
                   ` (14 more replies)
  0 siblings, 15 replies; 30+ messages in thread
From: Jacob Keller @ 2022-08-18 22:27 UTC (permalink / raw)
  To: netdev
  Cc: Jacob Keller, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

Many drivers implementing PTP have not yet migrated to the new .adjfine
frequency adjustment implementation.

A handful of these drivers use hardware with a simple increment value which
is adjusted by multiplying by the adjustment factor and then dividing by
1 billion. This calculation is very easy to convert to .adjfine, by simply
updating the divisor.

Introduce new helper functions, diff_by_scaled_ppm and adjust_by_scaled_ppm
which perform the most common calculations used by drivers for this purpose.

The adjust_by_scaled_ppm takes the base increment and scaled PPM value, and
calculates the new increment to use.

A few drivers need the difference and direction rather than a raw increment
value. The diff_by_scaled_ppm calculates the difference and returns true if
it should be a subtraction, false otherwise. This most closely aligns with
existing driver implementations.

I recently updated all of the Intel drivers to the same calculation which is
now factored out into the two helper functions. These drivers are all
migrated in one change with the introduction of the helper functions.

The other driver changes are separated out. I do not have access to the
hardware necessary to test these, so they've only been compile tested. The
conversion is straight forward, but I expect driver maintainers will want to
test these changes appropriately. I've done my best to Cc relevant
maintainers on the cover letter and the appropriate change.

With this applied, there are still a handful of remaining drivers which are
not yet converted including:

 * drivers/net/ethernet/broadcom/bnx2x
 * drivers/net/ethernet/broadcom/bnxt
 * drivers/net/ethernet/cavium/liquidio
 * drivers/net/ethernet/chelsio/cxgb4
 * drivers/net/ethernet/freescale
 * drivers/net/ethernet/qlogic/qed
 * drivers/net/ethernet/qlogic/qede
 * drivers/net/ethernet/sfc
 * drivers/net/ethernet/sfc/siena
 * drivers/net/ethernet/ti/am65-cpts.c
 * drivers/ptp/ptp_dte.c

These drivers use varying calculation methods which are not directly
compatible with the adjust_by_scaled_ppm method. I lack access to the
hardware and knowledge of its implementation to convert them directly to
using scaled parts per million. Instead, I plan to follow up this series
with one which converts the remaining drivers to .adjfine by using
scaled_ppm_to_ppb in their .adjfine implementation. This will then allow
dropping the .adjfreq interface from the ptp_clock_info interface.

Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Siva Reddy Kallam <siva.kallam@broadcom.com>
Cc: Prashant Sreedharan <prashant@broadcom.com>
Cc: Michael Chan <mchan@broadcom.com>
Cc: Yisen Zhuang <yisen.zhuang@huawei.com>
Cc: Salil Mehta <salil.mehta@huawei.com>
Cc: Jesse Brandeburg <jesse.brandeburg@intel.com>
Cc: Tony Nguyen <anthony.l.nguyen@intel.com>
Cc: Tariq Toukan <tariqt@nvidia.com>
Cc: Saeed Mahameed <saeedm@nvidia.com>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Bryan Whitehead <bryan.whitehead@microchip.com>
Cc: Sergey Shtylyov <s.shtylyov@omp.ru>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Jose Abreu <joabreu@synopsys.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Vivek Thampi <vithampi@vmware.com>
Cc: VMware PV-Drivers Reviewers <pv-drivers@vmware.com>
Cc: Jie Wang <wangjie125@huawei.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Guangbin Huang <huangguangbin2@huawei.com>
Cc: Eran Ben Elisha <eranbe@nvidia.com>
Cc: Aya Levin <ayal@nvidia.com>
Cc: Cai Huoqing <cai.huoqing@linux.dev>
Cc: Biju Das <biju.das.jz@bp.renesas.com>
Cc: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Cc: Phil Edworthy <phil.edworthy@renesas.com>
Cc: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Lv Ruyi <lv.ruyi@zte.com.cn>
Cc: Arnd Bergmann <arnd@arndb.de>

Jacob Keller (14):
  ptp: add missing documentation for parameters
  ptp: introduce helpers to adjust by scaled parts per million
  drivers: convert unsupported .adjfreq to .adjfine
  ptp_phc: convert to .adjfine and ptp_adj_scaled_ppm
  ptp_ixp46x: convert to .adjfine and adjust_by_scaled_ppm
  ptp: tg3: convert to .adjfine and diff_by_scaled_ppm
  ptp: hclge: convert to .adjfine and adjust_by_scaled_ppm
  ptp: mlx4: convert to .adjfine and adjust_by_scaled_ppm
  ptp: mlx5: convert to .adjfine and adjust_by_scaled_ppm
  ptp: lan743x: convert to .adjfine and diff_by_scaled_ppm
  ptp: ravb: convert to .adjfine and adjust_by_scaled_ppm
  ptp: stmac: convert to .adjfine and adjust_by_scaled_ppm
  ptp: cpts: convert to .adjfine and adjust_by_scaled_ppm
  ptp: xgbe: convert to .adjfine and adjust_by_scaled_ppm

 drivers/hv/hv_util.c                          |  4 +-
 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c      | 20 ++-----
 drivers/net/ethernet/broadcom/tg3.c           | 22 ++++----
 .../hisilicon/hns3/hns3pf/hclge_ptp.c         | 22 ++------
 drivers/net/ethernet/intel/e1000e/ptp.c       | 16 ++----
 drivers/net/ethernet/intel/i40e/i40e_ptp.c    | 17 ++----
 drivers/net/ethernet/intel/ice/ice_ptp.c      | 18 +------
 drivers/net/ethernet/intel/igb/igb_ptp.c      | 18 +------
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c  | 24 ++-------
 drivers/net/ethernet/mellanox/mlx4/en_clock.c | 25 ++++-----
 .../ethernet/mellanox/mlx5/core/lib/clock.c   | 22 +++-----
 drivers/net/ethernet/microchip/lan743x_ptp.c  | 28 ++++------
 drivers/net/ethernet/renesas/ravb_ptp.c       | 16 ++----
 .../net/ethernet/stmicro/stmmac/stmmac_ptp.c  | 23 +++-----
 drivers/net/ethernet/ti/cpts.c                | 21 +++-----
 drivers/net/ethernet/xscale/ptp_ixp46x.c      | 19 ++-----
 drivers/ptp/ptp_kvm_common.c                  |  4 +-
 drivers/ptp/ptp_pch.c                         | 19 ++-----
 drivers/ptp/ptp_vmw.c                         |  4 +-
 include/linux/ptp_clock_kernel.h              | 53 +++++++++++++++++++
 20 files changed, 143 insertions(+), 252 deletions(-)


base-commit: 9017462f006c4b686cb1e1e1a3a52ea8363076e6
-- 
2.37.1.208.ge72d93e88cb2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [net-next 01/14] ptp: add missing documentation for parameters
  2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
@ 2022-08-18 22:27 ` Jacob Keller
  2022-08-18 22:27 ` [net-next 02/14] ptp: introduce helpers to adjust by scaled parts per million Jacob Keller
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 30+ messages in thread
From: Jacob Keller @ 2022-08-18 22:27 UTC (permalink / raw)
  To: netdev
  Cc: Jacob Keller, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

The ptp_find_pin_unlocked function and the ptp_system_timestamp structure
didn't document their parameters and fields. Fix this.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
---
 include/linux/ptp_clock_kernel.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h
index 92b44161408e..ad4aaadc2f7a 100644
--- a/include/linux/ptp_clock_kernel.h
+++ b/include/linux/ptp_clock_kernel.h
@@ -45,6 +45,8 @@ struct system_device_crosststamp;
 
 /**
  * struct ptp_system_timestamp - system time corresponding to a PHC timestamp
+ * @pre_ts: system timestamp before capturing PHC
+ * @post_ts: system timestamp after capturing PHC
  */
 struct ptp_system_timestamp {
 	struct timespec64 pre_ts;
@@ -316,6 +318,11 @@ int ptp_find_pin(struct ptp_clock *ptp,
  * should most likely call ptp_find_pin() directly from their
  * ptp_clock_info::enable() method.
  *
+* @ptp:    The clock obtained from ptp_clock_register().
+* @func:   One of the ptp_pin_function enumerated values.
+* @chan:   The particular functional channel to find.
+* Return:  Pin index in the range of zero to ptp_clock_caps.n_pins - 1,
+*          or -1 if the auxiliary function cannot be found.
  */
 
 int ptp_find_pin_unlocked(struct ptp_clock *ptp,
-- 
2.37.1.208.ge72d93e88cb2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [net-next 02/14] ptp: introduce helpers to adjust by scaled parts per million
  2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
  2022-08-18 22:27 ` [net-next 01/14] ptp: add missing documentation for parameters Jacob Keller
@ 2022-08-18 22:27 ` Jacob Keller
  2022-08-18 22:27 ` [net-next 03/14] drivers: convert unsupported .adjfreq to .adjfine Jacob Keller
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 30+ messages in thread
From: Jacob Keller @ 2022-08-18 22:27 UTC (permalink / raw)
  To: netdev
  Cc: Jacob Keller, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

Many drivers implement the .adjfreq or .adjfine PTP op function with the
same basic logic:

  1. Determine a base frequency value
  2. Multiply this by the abs() of the requested adjustment, then divide by
     the appropriate divisor (1 billion, or 65,536 billion).
  3. Add or subtract this difference from the base frequency to calculate a
     new adjustment.

A few drivers need the difference and direction rather than the combined
new increment value.

I recently converted the Intel drivers to .adjfine and the scaled parts per
million (65.536 parts per billion) logic. To avoid overflow with minimal
loss of precision, mul_u64_u64_div_u64 was used.

The basic logic used by all of these drivers is very similar, and leads to
a lot of duplicate code to perform the same task.

Rather than keep this duplicate code, introduce diff_by_scaled_ppm and
adjust_by_scaled_ppm. These helper functions calculate the difference or
adjustment necessary based on the scaled parts per million input.

The diff_by_scaled_ppm function returns true if the difference should be
subtracted, and false otherwise.

Update the Intel drivers to use the new helper functions. Other vendor
drivers will be converted to .adjfine and this helper function in the
following changes.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Richard Cochran <richardcochran@gmail.com>
---
 drivers/net/ethernet/intel/e1000e/ptp.c      | 16 ++-----
 drivers/net/ethernet/intel/i40e/i40e_ptp.c   | 17 ++------
 drivers/net/ethernet/intel/ice/ice_ptp.c     | 18 +-------
 drivers/net/ethernet/intel/igb/igb_ptp.c     | 18 +-------
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c | 24 ++--------
 include/linux/ptp_clock_kernel.h             | 46 ++++++++++++++++++++
 6 files changed, 60 insertions(+), 79 deletions(-)

diff --git a/drivers/net/ethernet/intel/e1000e/ptp.c b/drivers/net/ethernet/intel/e1000e/ptp.c
index 0e488e4fa5c1..6e5a1720e6cd 100644
--- a/drivers/net/ethernet/intel/e1000e/ptp.c
+++ b/drivers/net/ethernet/intel/e1000e/ptp.c
@@ -29,17 +29,11 @@ static int e1000e_phc_adjfine(struct ptp_clock_info *ptp, long delta)
 	struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter,
 						     ptp_clock_info);
 	struct e1000_hw *hw = &adapter->hw;
-	bool neg_adj = false;
 	unsigned long flags;
-	u64 adjustment;
-	u32 timinca, incvalue;
+	u64 incvalue;
+	u32 timinca;
 	s32 ret_val;
 
-	if (delta < 0) {
-		neg_adj = true;
-		delta = -delta;
-	}
-
 	/* Get the System Time Register SYSTIM base frequency */
 	ret_val = e1000e_get_base_timinca(adapter, &timinca);
 	if (ret_val)
@@ -48,11 +42,7 @@ static int e1000e_phc_adjfine(struct ptp_clock_info *ptp, long delta)
 	spin_lock_irqsave(&adapter->systim_lock, flags);
 
 	incvalue = timinca & E1000_TIMINCA_INCVALUE_MASK;
-
-	adjustment = mul_u64_u64_div_u64(incvalue, (u64)delta,
-					 1000000ULL << 16);
-
-	incvalue = neg_adj ? (incvalue - adjustment) : (incvalue + adjustment);
+	incvalue = adjust_by_scaled_ppm(incvalue, delta);
 
 	timinca &= ~E1000_TIMINCA_INCVALUE_MASK;
 	timinca |= incvalue;
diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
index 2d3533f38d7b..33afa13b7812 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
@@ -347,23 +347,12 @@ static int i40e_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
 {
 	struct i40e_pf *pf = container_of(ptp, struct i40e_pf, ptp_caps);
 	struct i40e_hw *hw = &pf->hw;
-	u64 adj, freq, diff;
-	int neg_adj = 0;
-
-	if (scaled_ppm < 0) {
-		neg_adj = 1;
-		scaled_ppm = -scaled_ppm;
-	}
+	u64 adj, base_adj;
 
 	smp_mb(); /* Force any pending update before accessing. */
-	freq = I40E_PTP_40GB_INCVAL * READ_ONCE(pf->ptp_adj_mult);
-	diff = mul_u64_u64_div_u64(freq, (u64)scaled_ppm,
-				   1000000ULL << 16);
+	base_adj = I40E_PTP_40GB_INCVAL * READ_ONCE(pf->ptp_adj_mult);
 
-	if (neg_adj)
-		adj = I40E_PTP_40GB_INCVAL - diff;
-	else
-		adj = I40E_PTP_40GB_INCVAL + diff;
+	adj = adjust_by_scaled_ppm(base_adj, scaled_ppm);
 
 	wr32(hw, I40E_PRTTSYN_INC_L, adj & 0xFFFFFFFF);
 	wr32(hw, I40E_PRTTSYN_INC_H, adj >> 32);
diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c
index 72b663108a4a..1c5bdc5394f4 100644
--- a/drivers/net/ethernet/intel/ice/ice_ptp.c
+++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
@@ -1103,24 +1103,10 @@ static int ice_ptp_adjfine(struct ptp_clock_info *info, long scaled_ppm)
 {
 	struct ice_pf *pf = ptp_info_to_pf(info);
 	struct ice_hw *hw = &pf->hw;
-	u64 incval, diff;
-	int neg_adj = 0;
+	u64 incval;
 	int err;
 
-	incval = ice_base_incval(pf);
-
-	if (scaled_ppm < 0) {
-		neg_adj = 1;
-		scaled_ppm = -scaled_ppm;
-	}
-
-	diff = mul_u64_u64_div_u64(incval, (u64)scaled_ppm,
-				   1000000ULL << 16);
-	if (neg_adj)
-		incval -= diff;
-	else
-		incval += diff;
-
+	incval = adjust_by_scaled_ppm(ice_base_incval(pf), scaled_ppm);
 	err = ice_ptp_write_incval_locked(hw, incval);
 	if (err) {
 		dev_err(ice_pf_to_dev(pf), "PTP failed to set incval, err %d\n",
diff --git a/drivers/net/ethernet/intel/igb/igb_ptp.c b/drivers/net/ethernet/intel/igb/igb_ptp.c
index 15e57460e19e..6f471b91f562 100644
--- a/drivers/net/ethernet/intel/igb/igb_ptp.c
+++ b/drivers/net/ethernet/intel/igb/igb_ptp.c
@@ -195,23 +195,9 @@ static int igb_ptp_adjfine_82576(struct ptp_clock_info *ptp, long scaled_ppm)
 	struct igb_adapter *igb = container_of(ptp, struct igb_adapter,
 					       ptp_caps);
 	struct e1000_hw *hw = &igb->hw;
-	int neg_adj = 0;
-	u64 rate;
-	u32 incvalue;
+	u64 incvalue;
 
-	if (scaled_ppm < 0) {
-		neg_adj = 1;
-		scaled_ppm = -scaled_ppm;
-	}
-
-	incvalue = INCVALUE_82576;
-	rate = mul_u64_u64_div_u64(incvalue, (u64)scaled_ppm,
-				   1000000ULL << 16);
-
-	if (neg_adj)
-		incvalue -= rate;
-	else
-		incvalue += rate;
+	incvalue = adjust_by_scaled_ppm(INCVALUE_82576, scaled_ppm);
 
 	wr32(E1000_TIMINCA, INCPERIOD_82576 | (incvalue & INCVALUE_82576_MASK));
 
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
index 9f06896a049b..a78ff4ed8c8b 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
@@ -451,21 +451,11 @@ static int ixgbe_ptp_adjfine_82599(struct ptp_clock_info *ptp, long scaled_ppm)
 	struct ixgbe_adapter *adapter =
 		container_of(ptp, struct ixgbe_adapter, ptp_caps);
 	struct ixgbe_hw *hw = &adapter->hw;
-	u64 incval, diff;
-	int neg_adj = 0;
-
-	if (scaled_ppm < 0) {
-		neg_adj = 1;
-		scaled_ppm = -scaled_ppm;
-	}
+	u64 incval;
 
 	smp_mb();
 	incval = READ_ONCE(adapter->base_incval);
-
-	diff = mul_u64_u64_div_u64(incval, scaled_ppm,
-				   1000000ULL << 16);
-
-	incval = neg_adj ? (incval - diff) : (incval + diff);
+	incval = adjust_by_scaled_ppm(incval, scaled_ppm);
 
 	switch (hw->mac.type) {
 	case ixgbe_mac_X540:
@@ -502,17 +492,11 @@ static int ixgbe_ptp_adjfine_X550(struct ptp_clock_info *ptp, long scaled_ppm)
 	struct ixgbe_adapter *adapter =
 			container_of(ptp, struct ixgbe_adapter, ptp_caps);
 	struct ixgbe_hw *hw = &adapter->hw;
-	int neg_adj = 0;
+	bool neg_adj;
 	u64 rate;
 	u32 inca;
 
-	if (scaled_ppm < 0) {
-		neg_adj = 1;
-		scaled_ppm = -scaled_ppm;
-	}
-
-	rate = mul_u64_u64_div_u64(IXGBE_X550_BASE_PERIOD, scaled_ppm,
-				   1000000ULL << 16);
+	neg_adj = diff_by_scaled_ppm(IXGBE_X550_BASE_PERIOD, scaled_ppm, &rate);
 
 	/* warn if rate is too large */
 	if (rate >= INCVALUE_MASK)
diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h
index ad4aaadc2f7a..f4781c5766d6 100644
--- a/include/linux/ptp_clock_kernel.h
+++ b/include/linux/ptp_clock_kernel.h
@@ -248,6 +248,52 @@ static inline long scaled_ppm_to_ppb(long ppm)
 	return (long)ppb;
 }
 
+/**
+ * diff_by_scaled_ppm - Calculate difference using scaled ppm
+ * @base: the base increment value to adjust
+ * @scaled_ppm: scaled parts per million to adjust by
+ * @diff: on return, the absolute value of calculated diff
+ *
+ * Calculate the difference to adjust the base increment using scaled parts
+ * per million.
+ *
+ * Use mul_u64_u64_div_u64 to perform the difference calculation in avoid
+ * possible overflow.
+ *
+ * Returns: true if scaled_ppm is negative, false otherwise
+ */
+static inline bool diff_by_scaled_ppm(u64 base, long scaled_ppm, u64 *diff)
+{
+	bool negative = false;
+
+	if (scaled_ppm < 0) {
+		negative = true;
+		scaled_ppm = -scaled_ppm;
+	}
+
+	*diff = mul_u64_u64_div_u64(base, (u64)scaled_ppm, 1000000ULL << 16);
+
+	return negative;
+}
+
+/**
+ * adjust_by_scaled_ppm - Adjust a base increment by scaled parts per million
+ * @base: the base increment value to adjust
+ * @scaled_ppm: scaled parts per million frequency adjustment
+ *
+ * Helper function which calculates a new increment value based on the
+ * requested scaled parts per million adjustment.
+ */
+static inline u64 adjust_by_scaled_ppm(u64 base, long scaled_ppm)
+{
+	u64 diff;
+
+	if (diff_by_scaled_ppm(base, scaled_ppm, &diff))
+		return base - diff;
+
+	return base + diff;
+}
+
 #if IS_ENABLED(CONFIG_PTP_1588_CLOCK)
 
 /**
-- 
2.37.1.208.ge72d93e88cb2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [net-next 03/14] drivers: convert unsupported .adjfreq to .adjfine
  2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
  2022-08-18 22:27 ` [net-next 01/14] ptp: add missing documentation for parameters Jacob Keller
  2022-08-18 22:27 ` [net-next 02/14] ptp: introduce helpers to adjust by scaled parts per million Jacob Keller
@ 2022-08-18 22:27 ` Jacob Keller
  2022-08-18 22:27 ` [net-next 04/14] ptp_phc: convert to .adjfine and ptp_adj_scaled_ppm Jacob Keller
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 30+ messages in thread
From: Jacob Keller @ 2022-08-18 22:27 UTC (permalink / raw)
  To: netdev
  Cc: Jacob Keller, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

A few PTP drivers implement a .adjfreq handler which indicates the
operation is not supported. Convert all of these to .adjfine.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Vivek Thampi <vithampi@vmware.com>
---

I've only compile tested these changes, but its a very straight forward
conversion because they all just return -EOPNOTUSPP.

 drivers/hv/hv_util.c         | 4 ++--
 drivers/ptp/ptp_kvm_common.c | 4 ++--
 drivers/ptp/ptp_vmw.c        | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c
index 835e6039c186..d776074b49cb 100644
--- a/drivers/hv/hv_util.c
+++ b/drivers/hv/hv_util.c
@@ -706,7 +706,7 @@ static int hv_ptp_settime(struct ptp_clock_info *p, const struct timespec64 *ts)
 	return -EOPNOTSUPP;
 }
 
-static int hv_ptp_adjfreq(struct ptp_clock_info *ptp, s32 delta)
+static int hv_ptp_adjfine(struct ptp_clock_info *ptp, long delta)
 {
 	return -EOPNOTSUPP;
 }
@@ -724,7 +724,7 @@ static struct ptp_clock_info ptp_hyperv_info = {
 	.name		= "hyperv",
 	.enable         = hv_ptp_enable,
 	.adjtime        = hv_ptp_adjtime,
-	.adjfreq        = hv_ptp_adjfreq,
+	.adjfine        = hv_ptp_adjfine,
 	.gettime64      = hv_ptp_gettime,
 	.settime64      = hv_ptp_settime,
 	.owner		= THIS_MODULE,
diff --git a/drivers/ptp/ptp_kvm_common.c b/drivers/ptp/ptp_kvm_common.c
index fcae32f56f25..9141162c4237 100644
--- a/drivers/ptp/ptp_kvm_common.c
+++ b/drivers/ptp/ptp_kvm_common.c
@@ -66,7 +66,7 @@ static int ptp_kvm_getcrosststamp(struct ptp_clock_info *ptp,
  * PTP clock operations
  */
 
-static int ptp_kvm_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
+static int ptp_kvm_adjfine(struct ptp_clock_info *ptp, long delta)
 {
 	return -EOPNOTSUPP;
 }
@@ -115,7 +115,7 @@ static const struct ptp_clock_info ptp_kvm_caps = {
 	.n_ext_ts	= 0,
 	.n_pins		= 0,
 	.pps		= 0,
-	.adjfreq	= ptp_kvm_adjfreq,
+	.adjfine	= ptp_kvm_adjfine,
 	.adjtime	= ptp_kvm_adjtime,
 	.gettime64	= ptp_kvm_gettime,
 	.settime64	= ptp_kvm_settime,
diff --git a/drivers/ptp/ptp_vmw.c b/drivers/ptp/ptp_vmw.c
index 5dca26e14bdc..d64eec5b1788 100644
--- a/drivers/ptp/ptp_vmw.c
+++ b/drivers/ptp/ptp_vmw.c
@@ -47,7 +47,7 @@ static int ptp_vmw_adjtime(struct ptp_clock_info *info, s64 delta)
 	return -EOPNOTSUPP;
 }
 
-static int ptp_vmw_adjfreq(struct ptp_clock_info *info, s32 delta)
+static int ptp_vmw_adjfine(struct ptp_clock_info *info, long delta)
 {
 	return -EOPNOTSUPP;
 }
@@ -79,7 +79,7 @@ static struct ptp_clock_info ptp_vmw_clock_info = {
 	.name		= "ptp_vmw",
 	.max_adj	= 0,
 	.adjtime	= ptp_vmw_adjtime,
-	.adjfreq	= ptp_vmw_adjfreq,
+	.adjfine	= ptp_vmw_adjfine,
 	.gettime64	= ptp_vmw_gettime,
 	.settime64	= ptp_vmw_settime,
 	.enable		= ptp_vmw_enable,
-- 
2.37.1.208.ge72d93e88cb2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [net-next 04/14] ptp_phc: convert to .adjfine and ptp_adj_scaled_ppm
  2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
                   ` (2 preceding siblings ...)
  2022-08-18 22:27 ` [net-next 03/14] drivers: convert unsupported .adjfreq to .adjfine Jacob Keller
@ 2022-08-18 22:27 ` Jacob Keller
  2022-08-18 22:27 ` [net-next 05/14] ptp_ixp46x: convert to .adjfine and adjust_by_scaled_ppm Jacob Keller
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 30+ messages in thread
From: Jacob Keller @ 2022-08-18 22:27 UTC (permalink / raw)
  To: netdev
  Cc: Jacob Keller, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann,
	Takahiro Shimizu

The ptp_phc implementation of .adjfreq is implemented in terms of a
straight forward "base * ppb / 1 billion" calculation.

Convert this driver to .adjfine and use the new ptp_adj_scaled_ppm function
to calculate the adjustment.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Takahiro Shimizu <tshimizu818@gmail.com>
Cc: Richard Cochran <richardcochran@gmail.com>
---

I do not have this hardware, and have only compile tested the change.

 drivers/ptp/ptp_pch.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/ptp/ptp_pch.c b/drivers/ptp/ptp_pch.c
index 7d4da9e605ef..6bfe5c8eb61e 100644
--- a/drivers/ptp/ptp_pch.c
+++ b/drivers/ptp/ptp_pch.c
@@ -336,24 +336,13 @@ static irqreturn_t isr(int irq, void *priv)
  * PTP clock operations
  */
 
-static int ptp_pch_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
+static int ptp_pch_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
 {
-	u64 adj;
-	u32 diff, addend;
-	int neg_adj = 0;
+	u32 addend;
 	struct pch_dev *pch_dev = container_of(ptp, struct pch_dev, caps);
 	struct pch_ts_regs __iomem *regs = pch_dev->regs;
 
-	if (ppb < 0) {
-		neg_adj = 1;
-		ppb = -ppb;
-	}
-	addend = DEFAULT_ADDEND;
-	adj = addend;
-	adj *= ppb;
-	diff = div_u64(adj, 1000000000ULL);
-
-	addend = neg_adj ? addend - diff : addend + diff;
+	addend = (u32)adjust_by_scaled_ppm(DEFAULT_ADDEND, scaled_ppm);
 
 	iowrite32(addend, &regs->addend);
 
@@ -440,7 +429,7 @@ static const struct ptp_clock_info ptp_pch_caps = {
 	.n_ext_ts	= N_EXT_TS,
 	.n_pins		= 0,
 	.pps		= 0,
-	.adjfreq	= ptp_pch_adjfreq,
+	.adjfine	= ptp_pch_adjfine,
 	.adjtime	= ptp_pch_adjtime,
 	.gettime64	= ptp_pch_gettime,
 	.settime64	= ptp_pch_settime,
-- 
2.37.1.208.ge72d93e88cb2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [net-next 05/14] ptp_ixp46x: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
                   ` (3 preceding siblings ...)
  2022-08-18 22:27 ` [net-next 04/14] ptp_phc: convert to .adjfine and ptp_adj_scaled_ppm Jacob Keller
@ 2022-08-18 22:27 ` Jacob Keller
  2022-08-18 22:27 ` [net-next 06/14] ptp: tg3: convert to .adjfine and diff_by_scaled_ppm Jacob Keller
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 30+ messages in thread
From: Jacob Keller @ 2022-08-18 22:27 UTC (permalink / raw)
  To: netdev
  Cc: Jacob Keller, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

The ptp_ixp46x implementation of .adjfreq is implemented in terms of a
straight forward "base * ppb / 1 billion" calculation.

Convert this driver to .adjfine and use the adjust_by_scaled_ppm helper
function.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Wan Jiabing <wanjiabing@vivo.com>
---

I do not have this hardware, and have only compile tested this change.

 drivers/net/ethernet/xscale/ptp_ixp46x.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/net/ethernet/xscale/ptp_ixp46x.c b/drivers/net/ethernet/xscale/ptp_ixp46x.c
index 9abbdb71e629..dcdfd6e69d42 100644
--- a/drivers/net/ethernet/xscale/ptp_ixp46x.c
+++ b/drivers/net/ethernet/xscale/ptp_ixp46x.c
@@ -120,24 +120,13 @@ static irqreturn_t isr(int irq, void *priv)
  * PTP clock operations
  */
 
-static int ptp_ixp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
+static int ptp_ixp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
 {
-	u64 adj;
-	u32 diff, addend;
-	int neg_adj = 0;
+	u32 addend;
 	struct ixp_clock *ixp_clock = container_of(ptp, struct ixp_clock, caps);
 	struct ixp46x_ts_regs *regs = ixp_clock->regs;
 
-	if (ppb < 0) {
-		neg_adj = 1;
-		ppb = -ppb;
-	}
-	addend = DEFAULT_ADDEND;
-	adj = addend;
-	adj *= ppb;
-	diff = div_u64(adj, 1000000000ULL);
-
-	addend = neg_adj ? addend - diff : addend + diff;
+	addend = (u32)adjust_by_scaled_ppm(DEFAULT_ADDEND, scaled_ppm);
 
 	__raw_writel(addend, &regs->addend);
 
@@ -230,7 +219,7 @@ static const struct ptp_clock_info ptp_ixp_caps = {
 	.n_ext_ts	= N_EXT_TS,
 	.n_pins		= 0,
 	.pps		= 0,
-	.adjfreq	= ptp_ixp_adjfreq,
+	.adjfine	= ptp_ixp_adjfine,
 	.adjtime	= ptp_ixp_adjtime,
 	.gettime64	= ptp_ixp_gettime,
 	.settime64	= ptp_ixp_settime,
-- 
2.37.1.208.ge72d93e88cb2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [net-next 06/14] ptp: tg3: convert to .adjfine and diff_by_scaled_ppm
  2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
                   ` (4 preceding siblings ...)
  2022-08-18 22:27 ` [net-next 05/14] ptp_ixp46x: convert to .adjfine and adjust_by_scaled_ppm Jacob Keller
@ 2022-08-18 22:27 ` Jacob Keller
  2022-08-18 22:27 ` [net-next 07/14] ptp: hclge: convert to .adjfine and adjust_by_scaled_ppm Jacob Keller
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 30+ messages in thread
From: Jacob Keller @ 2022-08-18 22:27 UTC (permalink / raw)
  To: netdev
  Cc: Jacob Keller, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

The tg3 implementation of .adjfreq is implemented in terms of a
straight forward "base * ppb / 1 billion" calculation.

Convert this driver to the .adjfine implementation, and use
diff_by_scaled_ppm to calculate the correction value.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Siva Reddy Kallam <siva.kallam@broadcom.com>
Cc: Prashant Sreedharan <prashant@broadcom.com>
Cc: Michael Chan <mchan@broadcom.com>
---

I do not have this hardware, and have only compile tested this change.

 drivers/net/ethernet/broadcom/tg3.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index db1e9d810b41..c5dcbd83ae66 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -6179,27 +6179,23 @@ static int tg3_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
 	return 0;
 }
 
-static int tg3_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
+static int tg3_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
 {
 	struct tg3 *tp = container_of(ptp, struct tg3, ptp_info);
-	bool neg_adj = false;
-	u32 correction = 0;
-
-	if (ppb < 0) {
-		neg_adj = true;
-		ppb = -ppb;
-	}
+	u32 correction;
+	bool neg_adj;
+	u64 diff;
 
 	/* Frequency adjustment is performed using hardware with a 24 bit
 	 * accumulator and a programmable correction value. On each clk, the
 	 * correction value gets added to the accumulator and when it
 	 * overflows, the time counter is incremented/decremented.
 	 *
-	 * So conversion from ppb to correction value is
-	 *		ppb * (1 << 24) / 1000000000
+	 * So conversion from scaled_ppm to correction value is
+	 *		(1 << 24) * scaled_ppm / (1000000 << 16)
 	 */
-	correction = div_u64((u64)ppb * (1 << 24), 1000000000ULL) &
-		     TG3_EAV_REF_CLK_CORRECT_MASK;
+	neg_adj = diff_by_scaled_ppm(1 << 24, scaled_ppm, &diff);
+	correction = diff & TG3_EAV_REF_CLK_CORRECT_MASK;
 
 	tg3_full_lock(tp, 0);
 
@@ -6330,7 +6326,7 @@ static const struct ptp_clock_info tg3_ptp_caps = {
 	.n_per_out	= 1,
 	.n_pins		= 0,
 	.pps		= 0,
-	.adjfreq	= tg3_ptp_adjfreq,
+	.adjfine	= tg3_ptp_adjfine,
 	.adjtime	= tg3_ptp_adjtime,
 	.gettimex64	= tg3_ptp_gettimex,
 	.settime64	= tg3_ptp_settime,
-- 
2.37.1.208.ge72d93e88cb2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [net-next 07/14] ptp: hclge: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
                   ` (5 preceding siblings ...)
  2022-08-18 22:27 ` [net-next 06/14] ptp: tg3: convert to .adjfine and diff_by_scaled_ppm Jacob Keller
@ 2022-08-18 22:27 ` Jacob Keller
  2022-08-18 22:27 ` [net-next 08/14] ptp: mlx4: " Jacob Keller
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 30+ messages in thread
From: Jacob Keller @ 2022-08-18 22:27 UTC (permalink / raw)
  To: netdev
  Cc: Jacob Keller, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

The hclge implementation of .adjfreq is implemented in terms of a
straight forward "base * ppb / 1 billion" calculation.

Convert this driver to the .adjfine implementation and use
adjust_by_scaled_ppm to calculate the new adjustment value.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Yisen Zhuang <yisen.zhuang@huawei.com>
Cc: Salil Mehta <salil.mehta@huawei.com>
Cc: Jie Wang <wangjie125@huawei.com>
---

I do not have this hardware, and have only compile tested the change.

 .../hisilicon/hns3/hns3pf/hclge_ptp.c         | 22 +++++--------------
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c
index a40b1583f114..80a2a0073d97 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c
@@ -22,28 +22,16 @@ static int hclge_ptp_get_cycle(struct hclge_dev *hdev)
 	return 0;
 }
 
-static int hclge_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
+static int hclge_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
 {
 	struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp);
 	struct hclge_ptp_cycle *cycle = &hdev->ptp->cycle;
-	u64 adj_val, adj_base, diff;
+	u64 adj_val, adj_base;
 	unsigned long flags;
-	bool is_neg = false;
 	u32 quo, numerator;
 
-	if (ppb < 0) {
-		ppb = -ppb;
-		is_neg = true;
-	}
-
 	adj_base = (u64)cycle->quo * (u64)cycle->den + (u64)cycle->numer;
-	adj_val = adj_base * ppb;
-	diff = div_u64(adj_val, 1000000000ULL);
-
-	if (is_neg)
-		adj_val = adj_base - diff;
-	else
-		adj_val = adj_base + diff;
+	adj_val = adjust_by_scaled_ppm(adj_base, scaled_ppm);
 
 	/* This clock cycle is defined by three part: quotient, numerator
 	 * and denominator. For example, 2.5ns, the quotient is 2,
@@ -446,7 +434,7 @@ static int hclge_ptp_create_clock(struct hclge_dev *hdev)
 	ptp->info.max_adj = HCLGE_PTP_CYCLE_ADJ_MAX;
 	ptp->info.n_ext_ts = 0;
 	ptp->info.pps = 0;
-	ptp->info.adjfreq = hclge_ptp_adjfreq;
+	ptp->info.adjfine = hclge_ptp_adjfine;
 	ptp->info.adjtime = hclge_ptp_adjtime;
 	ptp->info.gettimex64 = hclge_ptp_gettimex;
 	ptp->info.settime64 = hclge_ptp_settime;
@@ -504,7 +492,7 @@ int hclge_ptp_init(struct hclge_dev *hdev)
 		goto out;
 
 	set_bit(HCLGE_PTP_FLAG_EN, &hdev->ptp->flags);
-	ret = hclge_ptp_adjfreq(&hdev->ptp->info, 0);
+	ret = hclge_ptp_adjfine(&hdev->ptp->info, 0);
 	if (ret) {
 		dev_err(&hdev->pdev->dev,
 			"failed to init freq, ret = %d\n", ret);
-- 
2.37.1.208.ge72d93e88cb2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [net-next 08/14] ptp: mlx4: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
                   ` (6 preceding siblings ...)
  2022-08-18 22:27 ` [net-next 07/14] ptp: hclge: convert to .adjfine and adjust_by_scaled_ppm Jacob Keller
@ 2022-08-18 22:27 ` Jacob Keller
  2022-08-18 22:27 ` [net-next 09/14] ptp: mlx5: " Jacob Keller
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 30+ messages in thread
From: Jacob Keller @ 2022-08-18 22:27 UTC (permalink / raw)
  To: netdev
  Cc: Jacob Keller, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

The mlx4 implementation of .adjfreq is implemented in terms of a
straight forward "base * ppb / 1 billion" calculation.

Convert this driver to .adjfine and use adjust_by_scaled_ppm to perform the
calculation.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Tariq Toukan <tariqt@nvidia.com>
---

I do not have this hardware, and have only compile tested the change.

 drivers/net/ethernet/mellanox/mlx4/en_clock.c | 25 +++++++------------
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_clock.c b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
index 024788549c25..bea75392087d 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_clock.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
@@ -111,34 +111,27 @@ void mlx4_en_ptp_overflow_check(struct mlx4_en_dev *mdev)
 }
 
 /**
- * mlx4_en_phc_adjfreq - adjust the frequency of the hardware clock
+ * mlx4_en_phc_adjfine - adjust the frequency of the hardware clock
  * @ptp: ptp clock structure
- * @delta: Desired frequency change in parts per billion
+ * @delta: Desired frequency change in scaled parts per million
  *
  * Adjust the frequency of the PHC cycle counter by the indicated delta from
  * the base frequency.
+ *
+ * Scaled parts per million is ppm with a 16-bit binary fractional field.
  **/
-static int mlx4_en_phc_adjfreq(struct ptp_clock_info *ptp, s32 delta)
+static int mlx4_en_phc_adjfine(struct ptp_clock_info *ptp, long delta)
 {
-	u64 adj;
-	u32 diff, mult;
-	int neg_adj = 0;
+	u32 mult;
 	unsigned long flags;
 	struct mlx4_en_dev *mdev = container_of(ptp, struct mlx4_en_dev,
 						ptp_clock_info);
 
-	if (delta < 0) {
-		neg_adj = 1;
-		delta = -delta;
-	}
-	mult = mdev->nominal_c_mult;
-	adj = mult;
-	adj *= delta;
-	diff = div_u64(adj, 1000000000ULL);
+	mult = (u32)adjust_by_scaled_ppm(mdev->nominal_c_mult, delta);
 
 	write_seqlock_irqsave(&mdev->clock_lock, flags);
 	timecounter_read(&mdev->clock);
-	mdev->cycles.mult = neg_adj ? mult - diff : mult + diff;
+	mdev->cycles.mult = mult;
 	write_sequnlock_irqrestore(&mdev->clock_lock, flags);
 
 	return 0;
@@ -237,7 +230,7 @@ static const struct ptp_clock_info mlx4_en_ptp_clock_info = {
 	.n_per_out	= 0,
 	.n_pins		= 0,
 	.pps		= 0,
-	.adjfreq	= mlx4_en_phc_adjfreq,
+	.adjfine	= mlx4_en_phc_adjfine,
 	.adjtime	= mlx4_en_phc_adjtime,
 	.gettime64	= mlx4_en_phc_gettime,
 	.settime64	= mlx4_en_phc_settime,
-- 
2.37.1.208.ge72d93e88cb2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [net-next 09/14] ptp: mlx5: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
                   ` (7 preceding siblings ...)
  2022-08-18 22:27 ` [net-next 08/14] ptp: mlx4: " Jacob Keller
@ 2022-08-18 22:27 ` Jacob Keller
  2022-08-23 15:30   ` Gal Pressman
  2022-08-18 22:27 ` [net-next 10/14] ptp: lan743x: convert to .adjfine and diff_by_scaled_ppm Jacob Keller
                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 30+ messages in thread
From: Jacob Keller @ 2022-08-18 22:27 UTC (permalink / raw)
  To: netdev
  Cc: Jacob Keller, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

The mlx5 implementation of .adjfreq is implemented in terms of a
straight forward "base * ppb / 1 billion" calculation.

Convert this to the .adjfine interface and use adjust_by_scaled_ppm for the
calculation  of the new mult value.

Note that the mlx5_ptp_adjfreq_real_time function expects input in terms of
ppb, so use the scaled_ppm_to_ppb to convert before passing to this
function.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Saeed Mahameed <saeedm@nvidia.com>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Aya Levin <ayal@nvidia.com>
---

I do not have this hardware, and have only compile tested the change.

 .../ethernet/mellanox/mlx5/core/lib/clock.c   | 22 +++++--------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
index 91e806c1aa21..34871ab659d9 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
@@ -330,35 +330,25 @@ static int mlx5_ptp_adjfreq_real_time(struct mlx5_core_dev *mdev, s32 freq)
 	return mlx5_set_mtutc(mdev, in, sizeof(in));
 }
 
-static int mlx5_ptp_adjfreq(struct ptp_clock_info *ptp, s32 delta)
+static int mlx5_ptp_adjfine(struct ptp_clock_info *ptp, long delta)
 {
 	struct mlx5_clock *clock = container_of(ptp, struct mlx5_clock, ptp_info);
 	struct mlx5_timer *timer = &clock->timer;
 	struct mlx5_core_dev *mdev;
 	unsigned long flags;
-	int neg_adj = 0;
-	u32 diff;
-	u64 adj;
+	u32 mult;
 	int err;
 
 	mdev = container_of(clock, struct mlx5_core_dev, clock);
-	err = mlx5_ptp_adjfreq_real_time(mdev, delta);
+	err = mlx5_ptp_adjfreq_real_time(mdev, scaled_ppm_to_ppb(delta));
 	if (err)
 		return err;
 
-	if (delta < 0) {
-		neg_adj = 1;
-		delta = -delta;
-	}
-
-	adj = timer->nominal_c_mult;
-	adj *= delta;
-	diff = div_u64(adj, 1000000000ULL);
+	mult = (u32)adjust_by_scaled_ppm(timer->nominal_c_mult, delta);
 
 	write_seqlock_irqsave(&clock->lock, flags);
 	timecounter_read(&timer->tc);
-	timer->cycles.mult = neg_adj ? timer->nominal_c_mult - diff :
-				       timer->nominal_c_mult + diff;
+	timer->cycles.mult = mult;
 	mlx5_update_clock_info_page(mdev);
 	write_sequnlock_irqrestore(&clock->lock, flags);
 
@@ -605,7 +595,7 @@ static const struct ptp_clock_info mlx5_ptp_clock_info = {
 	.n_per_out	= 0,
 	.n_pins		= 0,
 	.pps		= 0,
-	.adjfreq	= mlx5_ptp_adjfreq,
+	.adjfine	= mlx5_ptp_adjfine,
 	.adjtime	= mlx5_ptp_adjtime,
 	.gettimex64	= mlx5_ptp_gettimex,
 	.settime64	= mlx5_ptp_settime,
-- 
2.37.1.208.ge72d93e88cb2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [net-next 10/14] ptp: lan743x: convert to .adjfine and diff_by_scaled_ppm
  2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
                   ` (8 preceding siblings ...)
  2022-08-18 22:27 ` [net-next 09/14] ptp: mlx5: " Jacob Keller
@ 2022-08-18 22:27 ` Jacob Keller
  2022-08-19  2:47   ` kernel test robot
  2022-08-21 15:22   ` kernel test robot
  2022-08-18 22:27 ` [net-next 11/14] ptp: ravb: convert to .adjfine and adjust_by_scaled_ppm Jacob Keller
                   ` (4 subsequent siblings)
  14 siblings, 2 replies; 30+ messages in thread
From: Jacob Keller @ 2022-08-18 22:27 UTC (permalink / raw)
  To: netdev
  Cc: Jacob Keller, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann,
	UNGLinuxDriver

The lan743x implementation of .adjfreq is implemented in terms of a
straight forward "base * ppb / 1 billion" calculation.

Convert this driver to .adjfine and use diff_by_scaled_ppm to calculate the
difference value for the PTP_CLOCK_RATE_ADJ csr.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Bryan Whitehead <bryan.whitehead@microchip.com>
Cc: UNGLinuxDriver@microchip.com
---

I do not have this hardware, and have only compile tested the change.

 drivers/net/ethernet/microchip/lan743x_ptp.c | 28 ++++++++------------
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ethernet/microchip/lan743x_ptp.c b/drivers/net/ethernet/microchip/lan743x_ptp.c
index 6a11e2ceb013..a88606236710 100644
--- a/drivers/net/ethernet/microchip/lan743x_ptp.c
+++ b/drivers/net/ethernet/microchip/lan743x_ptp.c
@@ -365,33 +365,27 @@ static int lan743x_ptpci_adjfine(struct ptp_clock_info *ptpci, long scaled_ppm)
 	return 0;
 }
 
-static int lan743x_ptpci_adjfreq(struct ptp_clock_info *ptpci, s32 delta_ppb)
+static int lan743x_ptpci_adjfine(struct ptp_clock_info *ptpci, long delta)
 {
 	struct lan743x_ptp *ptp =
 		container_of(ptpci, struct lan743x_ptp, ptp_clock_info);
 	struct lan743x_adapter *adapter =
 		container_of(ptp, struct lan743x_adapter, ptp);
-	u32 lan743x_rate_adj = 0;
-	bool positive = true;
-	u32 u32_delta = 0;
-	u64 u64_delta = 0;
+	u64 lan743x_rate_adj;
+	s32 delta_ppb;
+	u64 diff;
 
+	delta_ppb = scaled_ppm_to_ppb(delta);
 	if ((delta_ppb < (-LAN743X_PTP_MAX_FREQ_ADJ_IN_PPB)) ||
 	    delta_ppb > LAN743X_PTP_MAX_FREQ_ADJ_IN_PPB) {
 		return -EINVAL;
 	}
-	if (delta_ppb > 0) {
-		u32_delta = (u32)delta_ppb;
-		positive = true;
-	} else {
-		u32_delta = (u32)(-delta_ppb);
-		positive = false;
-	}
-	u64_delta = (((u64)u32_delta) << 35);
-	lan743x_rate_adj = div_u64(u64_delta, 1000000000);
 
-	if (positive)
-		lan743x_rate_adj |= PTP_CLOCK_RATE_ADJ_DIR_;
+	/* diff_by_scaled_ppm returns true if the difference is negative */
+	if (diff_by_scaled_ppm(1ULL << 35, delta, &diff))
+		lan743_rate_adj = (u32)diff;
+	else
+		lan74e_rage_adj = (u32)diff | PTP_CLOCK_RATE_ADJ_DIR_;
 
 	lan743x_csr_write(adapter, PTP_CLOCK_RATE_ADJ,
 			  lan743x_rate_adj);
@@ -1576,7 +1570,7 @@ int lan743x_ptp_open(struct lan743x_adapter *adapter)
 	ptp->ptp_clock_info.pps = LAN743X_PTP_N_PPS;
 	ptp->ptp_clock_info.pin_config = ptp->pin_config;
 	ptp->ptp_clock_info.adjfine = lan743x_ptpci_adjfine;
-	ptp->ptp_clock_info.adjfreq = lan743x_ptpci_adjfreq;
+	ptp->ptp_clock_info.adjfine = lan743x_ptpci_adjfine;
 	ptp->ptp_clock_info.adjtime = lan743x_ptpci_adjtime;
 	ptp->ptp_clock_info.gettime64 = lan743x_ptpci_gettime64;
 	ptp->ptp_clock_info.getcrosststamp = NULL;
-- 
2.37.1.208.ge72d93e88cb2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [net-next 11/14] ptp: ravb: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
                   ` (9 preceding siblings ...)
  2022-08-18 22:27 ` [net-next 10/14] ptp: lan743x: convert to .adjfine and diff_by_scaled_ppm Jacob Keller
@ 2022-08-18 22:27 ` Jacob Keller
  2022-08-20 19:33   ` Sergey Shtylyov
  2022-08-18 22:27 ` [net-next 12/14] ptp: stmac: " Jacob Keller
                   ` (3 subsequent siblings)
  14 siblings, 1 reply; 30+ messages in thread
From: Jacob Keller @ 2022-08-18 22:27 UTC (permalink / raw)
  To: netdev
  Cc: Jacob Keller, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann,
	linux-renesas-soc

The ravb implementation of .adjfreq is implemented in terms of a
straight forward "base * ppb / 1 billion" calculation.

Convert this driver to .adjfine and use the adjust_by_scaled_ppm helper
function to calculate the new addend.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Sergey Shtylyov <s.shtylyov@omp.ru>
Cc: Biju Das <biju.das.jz@bp.renesas.com>
Cc: Phil Edworthy <phil.edworthy@renesas.com>
Cc: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Cc: linux-renesas-soc@vger.kernel.org
---

I do not have this hardware, and have only compile tested the change.

 drivers/net/ethernet/renesas/ravb_ptp.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c
index 87c4306d66ec..941aa3b0e8a0 100644
--- a/drivers/net/ethernet/renesas/ravb_ptp.c
+++ b/drivers/net/ethernet/renesas/ravb_ptp.c
@@ -88,24 +88,18 @@ static int ravb_ptp_update_compare(struct ravb_private *priv, u32 ns)
 }
 
 /* PTP clock operations */
-static int ravb_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
+static int ravb_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
 {
 	struct ravb_private *priv = container_of(ptp, struct ravb_private,
 						 ptp.info);
 	struct net_device *ndev = priv->ndev;
 	unsigned long flags;
-	u32 diff, addend;
-	bool neg_adj = false;
+	u32 addend;
 	u32 gccr;
 
-	if (ppb < 0) {
-		neg_adj = true;
-		ppb = -ppb;
-	}
 	addend = priv->ptp.default_addend;
-	diff = div_u64((u64)addend * ppb, NSEC_PER_SEC);
-
-	addend = neg_adj ? addend - diff : addend + diff;
+	addend = (u32)adjust_by_scaled_ppm(priv->ptp.default_addend,
+					   scaled_ppm);
 
 	spin_lock_irqsave(&priv->lock, flags);
 
@@ -295,7 +289,7 @@ static const struct ptp_clock_info ravb_ptp_info = {
 	.max_adj	= 50000000,
 	.n_ext_ts	= N_EXT_TS,
 	.n_per_out	= N_PER_OUT,
-	.adjfreq	= ravb_ptp_adjfreq,
+	.adjfine	= ravb_ptp_adjfine,
 	.adjtime	= ravb_ptp_adjtime,
 	.gettime64	= ravb_ptp_gettime64,
 	.settime64	= ravb_ptp_settime64,
-- 
2.37.1.208.ge72d93e88cb2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [net-next 12/14] ptp: stmac: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
                   ` (10 preceding siblings ...)
  2022-08-18 22:27 ` [net-next 11/14] ptp: ravb: convert to .adjfine and adjust_by_scaled_ppm Jacob Keller
@ 2022-08-18 22:27 ` Jacob Keller
  2022-08-18 22:27 ` [net-next 13/14] ptp: cpts: " Jacob Keller
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 30+ messages in thread
From: Jacob Keller @ 2022-08-18 22:27 UTC (permalink / raw)
  To: netdev
  Cc: Jacob Keller, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

The stmac implementation of .adjfreq is implemented in terms of a
straight forward "base * ppb / 1 billion" calculation.

Convert this driver to .adjfine and use the adjust_by_scaled_ppm helper
function to perform the calculation of the new addend.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Jose Abreu <joabreu@synopsys.com>
---

I do not have this hardware, and have only compile tested the change.

 .../net/ethernet/stmicro/stmmac/stmmac_ptp.c  | 23 ++++++-------------
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
index 4d11980dcd64..0d5e6819ee5d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
@@ -15,29 +15,20 @@
  * stmmac_adjust_freq
  *
  * @ptp: pointer to ptp_clock_info structure
- * @ppb: desired period change in parts ber billion
+ * @scaled_ppm: desired period change in scaled parts per million
  *
  * Description: this function will adjust the frequency of hardware clock.
+ *
+ * Scaled parts per million is ppm with a 16-bit binary fractional field.
  */
-static int stmmac_adjust_freq(struct ptp_clock_info *ptp, s32 ppb)
+static int stmmac_adjust_freq(struct ptp_clock_info *ptp, long scaled_ppm)
 {
 	struct stmmac_priv *priv =
 	    container_of(ptp, struct stmmac_priv, ptp_clock_ops);
 	unsigned long flags;
-	u32 diff, addend;
-	int neg_adj = 0;
-	u64 adj;
+	u32 addend;
 
-	if (ppb < 0) {
-		neg_adj = 1;
-		ppb = -ppb;
-	}
-
-	addend = priv->default_addend;
-	adj = addend;
-	adj *= ppb;
-	diff = div_u64(adj, 1000000000ULL);
-	addend = neg_adj ? (addend - diff) : (addend + diff);
+	addend = (u32)adjust_by_scaled_ppm(priv->default_addend, scaled_ppm);
 
 	write_lock_irqsave(&priv->ptp_lock, flags);
 	stmmac_config_addend(priv, priv->ptpaddr, addend);
@@ -269,7 +260,7 @@ static struct ptp_clock_info stmmac_ptp_clock_ops = {
 	.n_per_out = 0, /* will be overwritten in stmmac_ptp_register */
 	.n_pins = 0,
 	.pps = 0,
-	.adjfreq = stmmac_adjust_freq,
+	.adjfine = stmmac_adjust_freq,
 	.adjtime = stmmac_adjust_time,
 	.gettime64 = stmmac_get_time,
 	.settime64 = stmmac_set_time,
-- 
2.37.1.208.ge72d93e88cb2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [net-next 13/14] ptp: cpts: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
                   ` (11 preceding siblings ...)
  2022-08-18 22:27 ` [net-next 12/14] ptp: stmac: " Jacob Keller
@ 2022-08-18 22:27 ` Jacob Keller
  2022-08-18 22:27 ` [net-next 14/14] ptp: xgbe: " Jacob Keller
  2022-08-19  7:39 ` [net-next 00/14] ptp: convert drivers to .adjfine Richard Cochran
  14 siblings, 0 replies; 30+ messages in thread
From: Jacob Keller @ 2022-08-18 22:27 UTC (permalink / raw)
  To: netdev
  Cc: Jacob Keller, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

The cpts implementation of .adjfreq is implemented in terms of a
straight forward "base * ppb / 1 billion" calculation.

Convert this driver to .adjfine and use the adjust_by_scaled_ppm helper
function.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---

I do not have this hardware, and have only compile tested the change.

 drivers/net/ethernet/ti/cpts.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
index 92ca739fac01..ea3a10576d03 100644
--- a/drivers/net/ethernet/ti/cpts.c
+++ b/drivers/net/ethernet/ti/cpts.c
@@ -213,25 +213,16 @@ static void cpts_update_cur_time(struct cpts *cpts, int match,
 
 /* PTP clock operations */
 
-static int cpts_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
+static int cpts_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
 {
 	struct cpts *cpts = container_of(ptp, struct cpts, info);
-	int neg_adj = 0;
-	u32 diff, mult;
-	u64 adj;
+	u32 mult;
 
-	if (ppb < 0) {
-		neg_adj = 1;
-		ppb = -ppb;
-	}
-	mult = cpts->cc_mult;
-	adj = mult;
-	adj *= ppb;
-	diff = div_u64(adj, 1000000000ULL);
+	mult = (u32)adjust_by_scaled_ppm(cpts->cc_mult, scaled_ppm);
 
 	mutex_lock(&cpts->ptp_clk_mutex);
 
-	cpts->mult_new = neg_adj ? mult - diff : mult + diff;
+	cpts->mult_new = mult;
 
 	cpts_update_cur_time(cpts, CPTS_EV_PUSH, NULL);
 
@@ -435,7 +426,7 @@ static const struct ptp_clock_info cpts_info = {
 	.n_ext_ts	= 0,
 	.n_pins		= 0,
 	.pps		= 0,
-	.adjfreq	= cpts_ptp_adjfreq,
+	.adjfine	= cpts_ptp_adjfine,
 	.adjtime	= cpts_ptp_adjtime,
 	.gettimex64	= cpts_ptp_gettimeex,
 	.settime64	= cpts_ptp_settime,
@@ -794,7 +785,7 @@ struct cpts *cpts_create(struct device *dev, void __iomem *regs,
 
 	cpts_calc_mult_shift(cpts);
 	/* save cc.mult original value as it can be modified
-	 * by cpts_ptp_adjfreq().
+	 * by cpts_ptp_adjfine().
 	 */
 	cpts->cc_mult = cpts->cc.mult;
 
-- 
2.37.1.208.ge72d93e88cb2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [net-next 14/14] ptp: xgbe: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
                   ` (12 preceding siblings ...)
  2022-08-18 22:27 ` [net-next 13/14] ptp: cpts: " Jacob Keller
@ 2022-08-18 22:27 ` Jacob Keller
  2022-08-19 16:05   ` Tom Lendacky
  2022-08-19  7:39 ` [net-next 00/14] ptp: convert drivers to .adjfine Richard Cochran
  14 siblings, 1 reply; 30+ messages in thread
From: Jacob Keller @ 2022-08-18 22:27 UTC (permalink / raw)
  To: netdev
  Cc: Jacob Keller, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

The xgbe implementation of .adjfreq is implemented in terms of a
straight forward "base * ppb / 1 billion" calculation.

Convert this driver to .adjfine and use adjust_by_scaled_ppm to calculate
the new addend value.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
---

I do not have this hardware, and have only compile tested the change.

 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
index d06d260cf1e2..7051bd7cf6dc 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
@@ -134,27 +134,15 @@ static u64 xgbe_cc_read(const struct cyclecounter *cc)
 	return nsec;
 }
 
-static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
+static int xgbe_adjfine(struct ptp_clock_info *info, long scaled_ppm)
 {
 	struct xgbe_prv_data *pdata = container_of(info,
 						   struct xgbe_prv_data,
 						   ptp_clock_info);
 	unsigned long flags;
-	u64 adjust;
-	u32 addend, diff;
-	unsigned int neg_adjust = 0;
+	u64 addend;
 
-	if (delta < 0) {
-		neg_adjust = 1;
-		delta = -delta;
-	}
-
-	adjust = pdata->tstamp_addend;
-	adjust *= delta;
-	diff = div_u64(adjust, 1000000000UL);
-
-	addend = (neg_adjust) ? pdata->tstamp_addend - diff :
-				pdata->tstamp_addend + diff;
+	addend = adjust_by_scaled_ppm(pdata->tstamp_addend, scaled_ppm);
 
 	spin_lock_irqsave(&pdata->tstamp_lock, flags);
 
@@ -235,7 +223,7 @@ void xgbe_ptp_register(struct xgbe_prv_data *pdata)
 		 netdev_name(pdata->netdev));
 	info->owner = THIS_MODULE;
 	info->max_adj = pdata->ptpclk_rate;
-	info->adjfreq = xgbe_adjfreq;
+	info->adjfine = xgbe_adjfine;
 	info->adjtime = xgbe_adjtime;
 	info->gettime64 = xgbe_gettime;
 	info->settime64 = xgbe_settime;
-- 
2.37.1.208.ge72d93e88cb2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: [net-next 10/14] ptp: lan743x: convert to .adjfine and diff_by_scaled_ppm
  2022-08-18 22:27 ` [net-next 10/14] ptp: lan743x: convert to .adjfine and diff_by_scaled_ppm Jacob Keller
@ 2022-08-19  2:47   ` kernel test robot
  2022-08-21 15:22   ` kernel test robot
  1 sibling, 0 replies; 30+ messages in thread
From: kernel test robot @ 2022-08-19  2:47 UTC (permalink / raw)
  To: Jacob Keller, netdev
  Cc: llvm, kbuild-all, Jacob Keller, K. Y. Srinivasan, Haiyang Zhang,
	Stephen Hemminger, Wei Liu, Dexuan Cui, Tom Lendacky,
	Shyam Sundar S K, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi

Hi Jacob,

I love your patch! Yet something to improve:

[auto build test ERROR on 9017462f006c4b686cb1e1e1a3a52ea8363076e6]

url:    https://github.com/intel-lab-lkp/linux/commits/Jacob-Keller/ptp-convert-drivers-to-adjfine/20220819-063154
base:   9017462f006c4b686cb1e1e1a3a52ea8363076e6
config: i386-randconfig-a015 (https://download.01.org/0day-ci/archive/20220819/202208191003.18DiEs1l-lkp@intel.com/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project aed5e3bea138ce581d682158eb61c27b3cfdd6ec)
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/d3c6eac5778f2ce74e7d6d7be90a60f616551718
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Jacob-Keller/ptp-convert-drivers-to-adjfine/20220819-063154
        git checkout d3c6eac5778f2ce74e7d6d7be90a60f616551718
        # 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=i386 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/net/ethernet/microchip/lan743x_ptp.c:368:12: error: redefinition of 'lan743x_ptpci_adjfine'
   static int lan743x_ptpci_adjfine(struct ptp_clock_info *ptpci, long delta)
              ^
   drivers/net/ethernet/microchip/lan743x_ptp.c:335:12: note: previous definition is here
   static int lan743x_ptpci_adjfine(struct ptp_clock_info *ptpci, long scaled_ppm)
              ^
>> drivers/net/ethernet/microchip/lan743x_ptp.c:386:3: error: use of undeclared identifier 'lan743_rate_adj'; did you mean 'lan743x_rate_adj'?
                   lan743_rate_adj = (u32)diff;
                   ^~~~~~~~~~~~~~~
                   lan743x_rate_adj
   drivers/net/ethernet/microchip/lan743x_ptp.c:374:6: note: 'lan743x_rate_adj' declared here
           u64 lan743x_rate_adj;
               ^
>> drivers/net/ethernet/microchip/lan743x_ptp.c:388:3: error: use of undeclared identifier 'lan74e_rage_adj'; did you mean 'lan743x_rate_adj'?
                   lan74e_rage_adj = (u32)diff | PTP_CLOCK_RATE_ADJ_DIR_;
                   ^~~~~~~~~~~~~~~
                   lan743x_rate_adj
   drivers/net/ethernet/microchip/lan743x_ptp.c:374:6: note: 'lan743x_rate_adj' declared here
           u64 lan743x_rate_adj;
               ^
   3 errors generated.


vim +386 drivers/net/ethernet/microchip/lan743x_ptp.c

   367	
   368	static int lan743x_ptpci_adjfine(struct ptp_clock_info *ptpci, long delta)
   369	{
   370		struct lan743x_ptp *ptp =
   371			container_of(ptpci, struct lan743x_ptp, ptp_clock_info);
   372		struct lan743x_adapter *adapter =
   373			container_of(ptp, struct lan743x_adapter, ptp);
   374		u64 lan743x_rate_adj;
   375		s32 delta_ppb;
   376		u64 diff;
   377	
   378		delta_ppb = scaled_ppm_to_ppb(delta);
   379		if ((delta_ppb < (-LAN743X_PTP_MAX_FREQ_ADJ_IN_PPB)) ||
   380		    delta_ppb > LAN743X_PTP_MAX_FREQ_ADJ_IN_PPB) {
   381			return -EINVAL;
   382		}
   383	
   384		/* diff_by_scaled_ppm returns true if the difference is negative */
   385		if (diff_by_scaled_ppm(1ULL << 35, delta, &diff))
 > 386			lan743_rate_adj = (u32)diff;
   387		else
 > 388			lan74e_rage_adj = (u32)diff | PTP_CLOCK_RATE_ADJ_DIR_;
   389	
   390		lan743x_csr_write(adapter, PTP_CLOCK_RATE_ADJ,
   391				  lan743x_rate_adj);
   392	
   393		return 0;
   394	}
   395	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [net-next 00/14] ptp: convert drivers to .adjfine
  2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
                   ` (13 preceding siblings ...)
  2022-08-18 22:27 ` [net-next 14/14] ptp: xgbe: " Jacob Keller
@ 2022-08-19  7:39 ` Richard Cochran
  2022-08-19 20:56   ` Keller, Jacob E
  14 siblings, 1 reply; 30+ messages in thread
From: Richard Cochran @ 2022-08-19  7:39 UTC (permalink / raw)
  To: Jacob Keller
  Cc: netdev, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Dexuan Cui, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

On Thu, Aug 18, 2022 at 03:27:28PM -0700, Jacob Keller wrote:
> Many drivers implementing PTP have not yet migrated to the new .adjfine
> frequency adjustment implementation.

The re-factoring looks like it will remove much duplicated code.
I guess you tested the Intel drivers yourself?

The other drivers want sanity testing to make sure nothing broke.

I'm on vacation until Monday, but I can test cpts on BBB then.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [net-next 14/14] ptp: xgbe: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-18 22:27 ` [net-next 14/14] ptp: xgbe: " Jacob Keller
@ 2022-08-19 16:05   ` Tom Lendacky
  2022-08-19 21:04     ` Keller, Jacob E
  0 siblings, 1 reply; 30+ messages in thread
From: Tom Lendacky @ 2022-08-19 16:05 UTC (permalink / raw)
  To: Jacob Keller, netdev
  Cc: K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu,
	Dexuan Cui, Shyam Sundar S K, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Siva Reddy Kallam,
	Prashant Sreedharan, Michael Chan, Yisen Zhuang, Salil Mehta,
	Jesse Brandeburg, Tony Nguyen, Tariq Toukan, Saeed Mahameed,
	Leon Romanovsky, Bryan Whitehead, Sergey Shtylyov,
	Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

On 8/18/22 17:27, Jacob Keller wrote:
> The xgbe implementation of .adjfreq is implemented in terms of a
> straight forward "base * ppb / 1 billion" calculation.
> 
> Convert this driver to .adjfine and use adjust_by_scaled_ppm to calculate
> the new addend value.
> 
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Cc: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
> ---
> 
> I do not have this hardware, and have only compile tested the change.
> 
>   drivers/net/ethernet/amd/xgbe/xgbe-ptp.c | 20 ++++----------------
>   1 file changed, 4 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
> index d06d260cf1e2..7051bd7cf6dc 100644
> --- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
> +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
> @@ -134,27 +134,15 @@ static u64 xgbe_cc_read(const struct cyclecounter *cc)
>   	return nsec;
>   }
>   
> -static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
> +static int xgbe_adjfine(struct ptp_clock_info *info, long scaled_ppm)
>   {
>   	struct xgbe_prv_data *pdata = container_of(info,
>   						   struct xgbe_prv_data,
>   						   ptp_clock_info);
>   	unsigned long flags;
> -	u64 adjust;
> -	u32 addend, diff;
> -	unsigned int neg_adjust = 0;
> +	u64 addend;
>   
> -	if (delta < 0) {
> -		neg_adjust = 1;
> -		delta = -delta;
> -	}
> -
> -	adjust = pdata->tstamp_addend;
> -	adjust *= delta;
> -	diff = div_u64(adjust, 1000000000UL);
> -
> -	addend = (neg_adjust) ? pdata->tstamp_addend - diff :
> -				pdata->tstamp_addend + diff;
> +	addend = adjust_by_scaled_ppm(pdata->tstamp_addend, scaled_ppm);

Since addend is now a u64, but the called function just afterwards, 
xgbe_update_tstamp_addend(), expects an unsigned int, won't this generate 
a compiler warning depending on the flags used?

Thanks,
Tom

>   
>   	spin_lock_irqsave(&pdata->tstamp_lock, flags);
>   
> @@ -235,7 +223,7 @@ void xgbe_ptp_register(struct xgbe_prv_data *pdata)
>   		 netdev_name(pdata->netdev));
>   	info->owner = THIS_MODULE;
>   	info->max_adj = pdata->ptpclk_rate;
> -	info->adjfreq = xgbe_adjfreq;
> +	info->adjfine = xgbe_adjfine;
>   	info->adjtime = xgbe_adjtime;
>   	info->gettime64 = xgbe_gettime;
>   	info->settime64 = xgbe_settime;

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [net-next 00/14] ptp: convert drivers to .adjfine
  2022-08-19  7:39 ` [net-next 00/14] ptp: convert drivers to .adjfine Richard Cochran
@ 2022-08-19 20:56   ` Keller, Jacob E
  2022-08-23 16:28     ` Richard Cochran
  0 siblings, 1 reply; 30+ messages in thread
From: Keller, Jacob E @ 2022-08-19 20:56 UTC (permalink / raw)
  To: Richard Cochran
  Cc: netdev, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Cui, Dexuan, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Brandeburg, Jesse, Nguyen, Anthony L,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Thampi, Vivek,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann



> -----Original Message-----
> From: Richard Cochran <richardcochran@gmail.com>
> Sent: Friday, August 19, 2022 12:39 AM
> To: Keller, Jacob E <jacob.e.keller@intel.com>
> Cc: netdev@vger.kernel.org; K. Y. Srinivasan <kys@microsoft.com>; Haiyang
> Zhang <haiyangz@microsoft.com>; Stephen Hemminger
> <sthemmin@microsoft.com>; Wei Liu <wei.liu@kernel.org>; Cui, Dexuan
> <decui@microsoft.com>; Tom Lendacky <thomas.lendacky@amd.com>; Shyam
> Sundar S K <Shyam-sundar.S-k@amd.com>; David S. Miller
> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub Kicinski
> <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Siva Reddy Kallam
> <siva.kallam@broadcom.com>; Prashant Sreedharan
> <prashant@broadcom.com>; Michael Chan <mchan@broadcom.com>; Yisen
> Zhuang <yisen.zhuang@huawei.com>; Salil Mehta <salil.mehta@huawei.com>;
> Brandeburg, Jesse <jesse.brandeburg@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Tariq Toukan <tariqt@nvidia.com>; Saeed
> Mahameed <saeedm@nvidia.com>; Leon Romanovsky <leon@kernel.org>;
> Bryan Whitehead <bryan.whitehead@microchip.com>; Sergey Shtylyov
> <s.shtylyov@omp.ru>; Giuseppe Cavallaro <peppe.cavallaro@st.com>;
> Alexandre Torgue <alexandre.torgue@foss.st.com>; Jose Abreu
> <joabreu@synopsys.com>; Maxime Coquelin <mcoquelin.stm32@gmail.com>;
> Thampi, Vivek <vithampi@vmware.com>; VMware PV-Drivers Reviewers <pv-
> drivers@vmware.com>; Jie Wang <wangjie125@huawei.com>; Guangbin Huang
> <huangguangbin2@huawei.com>; Eran Ben Elisha <eranbe@nvidia.com>; Aya
> Levin <ayal@nvidia.com>; Cai Huoqing <cai.huoqing@linux.dev>; Biju Das
> <biju.das.jz@bp.renesas.com>; Lad Prabhakar <prabhakar.mahadev-
> lad.rj@bp.renesas.com>; Phil Edworthy <phil.edworthy@renesas.com>; Jiasheng
> Jiang <jiasheng@iscas.ac.cn>; Gustavo A. R. Silva <gustavoars@kernel.org>; Linus
> Walleij <linus.walleij@linaro.org>; Wan Jiabing <wanjiabing@vivo.com>; Lv Ruyi
> <lv.ruyi@zte.com.cn>; Arnd Bergmann <arnd@arndb.de>
> Subject: Re: [net-next 00/14] ptp: convert drivers to .adjfine
> 
> On Thu, Aug 18, 2022 at 03:27:28PM -0700, Jacob Keller wrote:
> > Many drivers implementing PTP have not yet migrated to the new .adjfine
> > frequency adjustment implementation.
> 
> The re-factoring looks like it will remove much duplicated code.
> I guess you tested the Intel drivers yourself?
> 
> The other drivers want sanity testing to make sure nothing broke.
> 

Yes. I tried to CC as many folks as look like involved in the maintenance of the PTP for those parts, and testing + sanity checks are necessary.

> I'm on vacation until Monday, but I can test cpts on BBB then.
> 
> Thanks,
> Richard

That would be great, thanks!

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [net-next 14/14] ptp: xgbe: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-19 16:05   ` Tom Lendacky
@ 2022-08-19 21:04     ` Keller, Jacob E
  2022-08-22 20:47       ` Tom Lendacky
  0 siblings, 1 reply; 30+ messages in thread
From: Keller, Jacob E @ 2022-08-19 21:04 UTC (permalink / raw)
  To: Tom Lendacky, netdev
  Cc: K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu, Cui,
	Dexuan, Shyam Sundar S K, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Siva Reddy Kallam,
	Prashant Sreedharan, Michael Chan, Yisen Zhuang, Salil Mehta,
	Brandeburg, Jesse, Nguyen, Anthony L, Tariq Toukan,
	Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Thampi, Vivek,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann



> -----Original Message-----
> From: Tom Lendacky <thomas.lendacky@amd.com>
> Sent: Friday, August 19, 2022 9:05 AM
> To: Keller, Jacob E <jacob.e.keller@intel.com>; netdev@vger.kernel.org
> Cc: K. Y. Srinivasan <kys@microsoft.com>; Haiyang Zhang
> <haiyangz@microsoft.com>; Stephen Hemminger <sthemmin@microsoft.com>;
> Wei Liu <wei.liu@kernel.org>; Cui, Dexuan <decui@microsoft.com>; Shyam
> Sundar S K <Shyam-sundar.S-k@amd.com>; David S. Miller
> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub Kicinski
> <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Siva Reddy Kallam
> <siva.kallam@broadcom.com>; Prashant Sreedharan
> <prashant@broadcom.com>; Michael Chan <mchan@broadcom.com>; Yisen
> Zhuang <yisen.zhuang@huawei.com>; Salil Mehta <salil.mehta@huawei.com>;
> Brandeburg, Jesse <jesse.brandeburg@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Tariq Toukan <tariqt@nvidia.com>; Saeed
> Mahameed <saeedm@nvidia.com>; Leon Romanovsky <leon@kernel.org>;
> Bryan Whitehead <bryan.whitehead@microchip.com>; Sergey Shtylyov
> <s.shtylyov@omp.ru>; Giuseppe Cavallaro <peppe.cavallaro@st.com>;
> Alexandre Torgue <alexandre.torgue@foss.st.com>; Jose Abreu
> <joabreu@synopsys.com>; Maxime Coquelin <mcoquelin.stm32@gmail.com>;
> Richard Cochran <richardcochran@gmail.com>; Thampi, Vivek
> <vithampi@vmware.com>; VMware PV-Drivers Reviewers <pv-
> drivers@vmware.com>; Jie Wang <wangjie125@huawei.com>; Guangbin Huang
> <huangguangbin2@huawei.com>; Eran Ben Elisha <eranbe@nvidia.com>; Aya
> Levin <ayal@nvidia.com>; Cai Huoqing <cai.huoqing@linux.dev>; Biju Das
> <biju.das.jz@bp.renesas.com>; Lad Prabhakar <prabhakar.mahadev-
> lad.rj@bp.renesas.com>; Phil Edworthy <phil.edworthy@renesas.com>; Jiasheng
> Jiang <jiasheng@iscas.ac.cn>; Gustavo A. R. Silva <gustavoars@kernel.org>; Linus
> Walleij <linus.walleij@linaro.org>; Wan Jiabing <wanjiabing@vivo.com>; Lv Ruyi
> <lv.ruyi@zte.com.cn>; Arnd Bergmann <arnd@arndb.de>
> Subject: Re: [net-next 14/14] ptp: xgbe: convert to .adjfine and
> adjust_by_scaled_ppm
> 
> On 8/18/22 17:27, Jacob Keller wrote:
> > The xgbe implementation of .adjfreq is implemented in terms of a
> > straight forward "base * ppb / 1 billion" calculation.
> >
> > Convert this driver to .adjfine and use adjust_by_scaled_ppm to calculate
> > the new addend value.
> >
> > Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> > Cc: Tom Lendacky <thomas.lendacky@amd.com>
> > Cc: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
> > ---
> >
> > I do not have this hardware, and have only compile tested the change.
> >
> >   drivers/net/ethernet/amd/xgbe/xgbe-ptp.c | 20 ++++----------------
> >   1 file changed, 4 insertions(+), 16 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
> b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
> > index d06d260cf1e2..7051bd7cf6dc 100644
> > --- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
> > +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
> > @@ -134,27 +134,15 @@ static u64 xgbe_cc_read(const struct cyclecounter
> *cc)
> >   	return nsec;
> >   }
> >
> > -static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
> > +static int xgbe_adjfine(struct ptp_clock_info *info, long scaled_ppm)
> >   {
> >   	struct xgbe_prv_data *pdata = container_of(info,
> >   						   struct xgbe_prv_data,
> >   						   ptp_clock_info);
> >   	unsigned long flags;
> > -	u64 adjust;
> > -	u32 addend, diff;
> > -	unsigned int neg_adjust = 0;
> > +	u64 addend;
> >
> > -	if (delta < 0) {
> > -		neg_adjust = 1;
> > -		delta = -delta;
> > -	}
> > -
> > -	adjust = pdata->tstamp_addend;
> > -	adjust *= delta;
> > -	diff = div_u64(adjust, 1000000000UL);
> > -
> > -	addend = (neg_adjust) ? pdata->tstamp_addend - diff :
> > -				pdata->tstamp_addend + diff;
> > +	addend = adjust_by_scaled_ppm(pdata->tstamp_addend, scaled_ppm);
> 
> Since addend is now a u64, but the called function just afterwards,
> xgbe_update_tstamp_addend(), expects an unsigned int, won't this generate
> a compiler warning depending on the flags used?
> 

It doesn't seem to generate anything with W=1 or W=2 on my system. Its possible that the compiler can deduce that this won't overflow a u32?

We could add a check to ensure it doesn't overflow the u32 size?

> Thanks,
> Tom
> 
> >
> >   	spin_lock_irqsave(&pdata->tstamp_lock, flags);
> >
> > @@ -235,7 +223,7 @@ void xgbe_ptp_register(struct xgbe_prv_data *pdata)
> >   		 netdev_name(pdata->netdev));
> >   	info->owner = THIS_MODULE;
> >   	info->max_adj = pdata->ptpclk_rate;
> > -	info->adjfreq = xgbe_adjfreq;
> > +	info->adjfine = xgbe_adjfine;
> >   	info->adjtime = xgbe_adjtime;
> >   	info->gettime64 = xgbe_gettime;
> >   	info->settime64 = xgbe_settime;

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [net-next 11/14] ptp: ravb: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-18 22:27 ` [net-next 11/14] ptp: ravb: convert to .adjfine and adjust_by_scaled_ppm Jacob Keller
@ 2022-08-20 19:33   ` Sergey Shtylyov
  2022-08-22 17:07     ` Keller, Jacob E
  0 siblings, 1 reply; 30+ messages in thread
From: Sergey Shtylyov @ 2022-08-20 19:33 UTC (permalink / raw)
  To: Jacob Keller, netdev
  Cc: K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu,
	Dexuan Cui, Tom Lendacky, Shyam Sundar S K, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Siva Reddy Kallam,
	Prashant Sreedharan, Michael Chan, Yisen Zhuang, Salil Mehta,
	Jesse Brandeburg, Tony Nguyen, Tariq Toukan, Saeed Mahameed,
	Leon Romanovsky, Bryan Whitehead, Giuseppe Cavallaro,
	Alexandre Torgue, Jose Abreu, Maxime Coquelin, Richard Cochran,
	Vivek Thampi, VMware PV-Drivers Reviewers, Jie Wang,
	Guangbin Huang, Eran Ben Elisha, Aya Levin, Cai Huoqing,
	Biju Das, Lad Prabhakar, Phil Edworthy, Jiasheng Jiang,
	Gustavo A. R. Silva, Linus Walleij, Wan Jiabing, Lv Ruyi,
	Arnd Bergmann, linux-renesas-soc

Hello!

On 8/19/22 1:27 AM, Jacob Keller wrote:

> The ravb implementation of .adjfreq is implemented in terms of a
> straight forward "base * ppb / 1 billion" calculation.
> 
> Convert this driver to .adjfine and use the adjust_by_scaled_ppm helper
> function to calculate the new addend.
> 
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> Cc: Sergey Shtylyov <s.shtylyov@omp.ru>
> Cc: Biju Das <biju.das.jz@bp.renesas.com>
> Cc: Phil Edworthy <phil.edworthy@renesas.com>
> Cc: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> Cc: linux-renesas-soc@vger.kernel.org
> ---
> 
> I do not have this hardware, and have only compile tested the change.
> 
>  drivers/net/ethernet/renesas/ravb_ptp.c | 16 +++++-----------
>  1 file changed, 5 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c b/drivers/net/ethernet/renesas/ravb_ptp.c
> index 87c4306d66ec..941aa3b0e8a0 100644
> --- a/drivers/net/ethernet/renesas/ravb_ptp.c
> +++ b/drivers/net/ethernet/renesas/ravb_ptp.c
> @@ -88,24 +88,18 @@ static int ravb_ptp_update_compare(struct ravb_private *priv, u32 ns)
>  }
>  
>  /* PTP clock operations */
> -static int ravb_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
> +static int ravb_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
>  {
>  	struct ravb_private *priv = container_of(ptp, struct ravb_private,
>  						 ptp.info);
>  	struct net_device *ndev = priv->ndev;
>  	unsigned long flags;
> -	u32 diff, addend;
> -	bool neg_adj = false;
> +	u32 addend;
>  	u32 gccr;
>  
> -	if (ppb < 0) {
> -		neg_adj = true;
> -		ppb = -ppb;
> -	}
>  	addend = priv->ptp.default_addend;

   I don't think we should keep this line -- it has no effect now...

> -	diff = div_u64((u64)addend * ppb, NSEC_PER_SEC);
> -
> -	addend = neg_adj ? addend - diff : addend + diff;
> +	addend = (u32)adjust_by_scaled_ppm(priv->ptp.default_addend,
> +					   scaled_ppm);
>  
>  	spin_lock_irqsave(&priv->lock, flags);
>  
[...]

MBR, Sergey

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [net-next 10/14] ptp: lan743x: convert to .adjfine and diff_by_scaled_ppm
  2022-08-18 22:27 ` [net-next 10/14] ptp: lan743x: convert to .adjfine and diff_by_scaled_ppm Jacob Keller
  2022-08-19  2:47   ` kernel test robot
@ 2022-08-21 15:22   ` kernel test robot
  2022-08-22 17:10     ` Keller, Jacob E
  1 sibling, 1 reply; 30+ messages in thread
From: kernel test robot @ 2022-08-21 15:22 UTC (permalink / raw)
  To: Jacob Keller, netdev
  Cc: llvm, kbuild-all, Jacob Keller, K. Y. Srinivasan, Haiyang Zhang,
	Stephen Hemminger, Wei Liu, Dexuan Cui, Tom Lendacky,
	Shyam Sundar S K, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Jesse Brandeburg, Tony Nguyen,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Vivek Thampi

Hi Jacob,

I love your patch! Yet something to improve:

[auto build test ERROR on 9017462f006c4b686cb1e1e1a3a52ea8363076e6]

url:    https://github.com/intel-lab-lkp/linux/commits/Jacob-Keller/ptp-convert-drivers-to-adjfine/20220819-063154
base:   9017462f006c4b686cb1e1e1a3a52ea8363076e6
config: powerpc-allyesconfig (https://download.01.org/0day-ci/archive/20220821/202208212326.87xlsbQB-lkp@intel.com/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 01ffe31cbb54bfd8e38e71b3cf804a1d67ebf9c1)
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
        # install powerpc cross compiling tool for clang build
        # apt-get install binutils-powerpc-linux-gnu
        # https://github.com/intel-lab-lkp/linux/commit/d3c6eac5778f2ce74e7d6d7be90a60f616551718
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Jacob-Keller/ptp-convert-drivers-to-adjfine/20220819-063154
        git checkout d3c6eac5778f2ce74e7d6d7be90a60f616551718
        # 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=powerpc SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/net/ethernet/microchip/lan743x_ptp.c:368:12: error: redefinition of 'lan743x_ptpci_adjfine'
   static int lan743x_ptpci_adjfine(struct ptp_clock_info *ptpci, long delta)
              ^
   drivers/net/ethernet/microchip/lan743x_ptp.c:335:12: note: previous definition is here
   static int lan743x_ptpci_adjfine(struct ptp_clock_info *ptpci, long scaled_ppm)
              ^
>> drivers/net/ethernet/microchip/lan743x_ptp.c:386:3: error: use of undeclared identifier 'lan743_rate_adj'; did you mean 'lan743x_rate_adj'?
                   lan743_rate_adj = (u32)diff;
                   ^~~~~~~~~~~~~~~
                   lan743x_rate_adj
   drivers/net/ethernet/microchip/lan743x_ptp.c:374:6: note: 'lan743x_rate_adj' declared here
           u64 lan743x_rate_adj;
               ^
>> drivers/net/ethernet/microchip/lan743x_ptp.c:388:3: error: use of undeclared identifier 'lan74e_rage_adj'; did you mean 'lan743x_rate_adj'?
                   lan74e_rage_adj = (u32)diff | PTP_CLOCK_RATE_ADJ_DIR_;
                   ^~~~~~~~~~~~~~~
                   lan743x_rate_adj
   drivers/net/ethernet/microchip/lan743x_ptp.c:374:6: note: 'lan743x_rate_adj' declared here
           u64 lan743x_rate_adj;
               ^
   3 errors generated.


vim +/lan743x_ptpci_adjfine +368 drivers/net/ethernet/microchip/lan743x_ptp.c

   367	
 > 368	static int lan743x_ptpci_adjfine(struct ptp_clock_info *ptpci, long delta)
   369	{
   370		struct lan743x_ptp *ptp =
   371			container_of(ptpci, struct lan743x_ptp, ptp_clock_info);
   372		struct lan743x_adapter *adapter =
   373			container_of(ptp, struct lan743x_adapter, ptp);
   374		u64 lan743x_rate_adj;
   375		s32 delta_ppb;
   376		u64 diff;
   377	
   378		delta_ppb = scaled_ppm_to_ppb(delta);
   379		if ((delta_ppb < (-LAN743X_PTP_MAX_FREQ_ADJ_IN_PPB)) ||
   380		    delta_ppb > LAN743X_PTP_MAX_FREQ_ADJ_IN_PPB) {
   381			return -EINVAL;
   382		}
   383	
   384		/* diff_by_scaled_ppm returns true if the difference is negative */
   385		if (diff_by_scaled_ppm(1ULL << 35, delta, &diff))
 > 386			lan743_rate_adj = (u32)diff;
   387		else
 > 388			lan74e_rage_adj = (u32)diff | PTP_CLOCK_RATE_ADJ_DIR_;
   389	
   390		lan743x_csr_write(adapter, PTP_CLOCK_RATE_ADJ,
   391				  lan743x_rate_adj);
   392	
   393		return 0;
   394	}
   395	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [net-next 11/14] ptp: ravb: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-20 19:33   ` Sergey Shtylyov
@ 2022-08-22 17:07     ` Keller, Jacob E
  0 siblings, 0 replies; 30+ messages in thread
From: Keller, Jacob E @ 2022-08-22 17:07 UTC (permalink / raw)
  To: Sergey Shtylyov, netdev
  Cc: K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu, Cui,
	Dexuan, Tom Lendacky, Shyam Sundar S K, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Siva Reddy Kallam,
	Prashant Sreedharan, Michael Chan, Yisen Zhuang, Salil Mehta,
	Brandeburg, Jesse, Nguyen, Anthony L, Tariq Toukan,
	Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	Maxime Coquelin, Richard Cochran, Thampi, Vivek,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann,
	linux-renesas-soc



> -----Original Message-----
> From: Sergey Shtylyov <s.shtylyov@omp.ru>
> Sent: Saturday, August 20, 2022 12:34 PM
> To: Keller, Jacob E <jacob.e.keller@intel.com>; netdev@vger.kernel.org
> Cc: K. Y. Srinivasan <kys@microsoft.com>; Haiyang Zhang
> <haiyangz@microsoft.com>; Stephen Hemminger <sthemmin@microsoft.com>;
> Wei Liu <wei.liu@kernel.org>; Cui, Dexuan <decui@microsoft.com>; Tom
> Lendacky <thomas.lendacky@amd.com>; Shyam Sundar S K <Shyam-sundar.S-
> k@amd.com>; David S. Miller <davem@davemloft.net>; Eric Dumazet
> <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
> <pabeni@redhat.com>; Siva Reddy Kallam <siva.kallam@broadcom.com>;
> Prashant Sreedharan <prashant@broadcom.com>; Michael Chan
> <mchan@broadcom.com>; Yisen Zhuang <yisen.zhuang@huawei.com>; Salil
> Mehta <salil.mehta@huawei.com>; Brandeburg, Jesse
> <jesse.brandeburg@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Tariq Toukan <tariqt@nvidia.com>; Saeed
> Mahameed <saeedm@nvidia.com>; Leon Romanovsky <leon@kernel.org>;
> Bryan Whitehead <bryan.whitehead@microchip.com>; Giuseppe Cavallaro
> <peppe.cavallaro@st.com>; Alexandre Torgue <alexandre.torgue@foss.st.com>;
> Jose Abreu <joabreu@synopsys.com>; Maxime Coquelin
> <mcoquelin.stm32@gmail.com>; Richard Cochran <richardcochran@gmail.com>;
> Thampi, Vivek <vithampi@vmware.com>; VMware PV-Drivers Reviewers <pv-
> drivers@vmware.com>; Jie Wang <wangjie125@huawei.com>; Guangbin Huang
> <huangguangbin2@huawei.com>; Eran Ben Elisha <eranbe@nvidia.com>; Aya
> Levin <ayal@nvidia.com>; Cai Huoqing <cai.huoqing@linux.dev>; Biju Das
> <biju.das.jz@bp.renesas.com>; Lad Prabhakar <prabhakar.mahadev-
> lad.rj@bp.renesas.com>; Phil Edworthy <phil.edworthy@renesas.com>; Jiasheng
> Jiang <jiasheng@iscas.ac.cn>; Gustavo A. R. Silva <gustavoars@kernel.org>; Linus
> Walleij <linus.walleij@linaro.org>; Wan Jiabing <wanjiabing@vivo.com>; Lv Ruyi
> <lv.ruyi@zte.com.cn>; Arnd Bergmann <arnd@arndb.de>; linux-renesas-
> soc@vger.kernel.org
> Subject: Re: [net-next 11/14] ptp: ravb: convert to .adjfine and
> adjust_by_scaled_ppm
> 
> Hello!
> 
> On 8/19/22 1:27 AM, Jacob Keller wrote:
> 
> > The ravb implementation of .adjfreq is implemented in terms of a
> > straight forward "base * ppb / 1 billion" calculation.
> >
> > Convert this driver to .adjfine and use the adjust_by_scaled_ppm helper
> > function to calculate the new addend.
> >
> > Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> > Cc: Sergey Shtylyov <s.shtylyov@omp.ru>
> > Cc: Biju Das <biju.das.jz@bp.renesas.com>
> > Cc: Phil Edworthy <phil.edworthy@renesas.com>
> > Cc: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> > Cc: linux-renesas-soc@vger.kernel.org
> > ---
> >
> > I do not have this hardware, and have only compile tested the change.
> >
> >  drivers/net/ethernet/renesas/ravb_ptp.c | 16 +++++-----------
> >  1 file changed, 5 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/renesas/ravb_ptp.c
> b/drivers/net/ethernet/renesas/ravb_ptp.c
> > index 87c4306d66ec..941aa3b0e8a0 100644
> > --- a/drivers/net/ethernet/renesas/ravb_ptp.c
> > +++ b/drivers/net/ethernet/renesas/ravb_ptp.c
> > @@ -88,24 +88,18 @@ static int ravb_ptp_update_compare(struct
> ravb_private *priv, u32 ns)
> >  }
> >
> >  /* PTP clock operations */
> > -static int ravb_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
> > +static int ravb_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
> >  {
> >  	struct ravb_private *priv = container_of(ptp, struct ravb_private,
> >  						 ptp.info);
> >  	struct net_device *ndev = priv->ndev;
> >  	unsigned long flags;
> > -	u32 diff, addend;
> > -	bool neg_adj = false;
> > +	u32 addend;
> >  	u32 gccr;
> >
> > -	if (ppb < 0) {
> > -		neg_adj = true;
> > -		ppb = -ppb;
> > -	}
> >  	addend = priv->ptp.default_addend;
> 
>    I don't think we should keep this line -- it has no effect now...
> 

Yea this can be dropped.

> > -	diff = div_u64((u64)addend * ppb, NSEC_PER_SEC);
> > -
> > -	addend = neg_adj ? addend - diff : addend + diff;
> > +	addend = (u32)adjust_by_scaled_ppm(priv->ptp.default_addend,
> > +					   scaled_ppm);
> >
> >  	spin_lock_irqsave(&priv->lock, flags);
> >
> [...]
> 
> MBR, Sergey

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [net-next 10/14] ptp: lan743x: convert to .adjfine and diff_by_scaled_ppm
  2022-08-21 15:22   ` kernel test robot
@ 2022-08-22 17:10     ` Keller, Jacob E
  0 siblings, 0 replies; 30+ messages in thread
From: Keller, Jacob E @ 2022-08-22 17:10 UTC (permalink / raw)
  To: lkp, netdev
  Cc: llvm, kbuild-all, K. Y. Srinivasan, Haiyang Zhang,
	Stephen Hemminger, Wei Liu, Cui, Dexuan, Tom Lendacky,
	Shyam Sundar S K, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Brandeburg, Jesse, Nguyen, Anthony L,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Thampi, Vivek



> -----Original Message-----
> From: lkp <lkp@intel.com>
> Sent: Sunday, August 21, 2022 8:22 AM
> To: Keller, Jacob E <jacob.e.keller@intel.com>; netdev@vger.kernel.org
> Cc: llvm@lists.linux.dev; kbuild-all@lists.01.org; Keller, Jacob E
> <jacob.e.keller@intel.com>; K. Y. Srinivasan <kys@microsoft.com>; Haiyang
> Zhang <haiyangz@microsoft.com>; Stephen Hemminger
> <sthemmin@microsoft.com>; Wei Liu <wei.liu@kernel.org>; Cui, Dexuan
> <decui@microsoft.com>; Tom Lendacky <thomas.lendacky@amd.com>; Shyam
> Sundar S K <Shyam-sundar.S-k@amd.com>; Eric Dumazet
> <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
> <pabeni@redhat.com>; Siva Reddy Kallam <siva.kallam@broadcom.com>;
> Prashant Sreedharan <prashant@broadcom.com>; Michael Chan
> <mchan@broadcom.com>; Yisen Zhuang <yisen.zhuang@huawei.com>; Salil
> Mehta <salil.mehta@huawei.com>; Brandeburg, Jesse
> <jesse.brandeburg@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Tariq Toukan <tariqt@nvidia.com>; Saeed
> Mahameed <saeedm@nvidia.com>; Leon Romanovsky <leon@kernel.org>;
> Bryan Whitehead <bryan.whitehead@microchip.com>; Sergey Shtylyov
> <s.shtylyov@omp.ru>; Giuseppe Cavallaro <peppe.cavallaro@st.com>;
> Alexandre Torgue <alexandre.torgue@foss.st.com>; Jose Abreu
> <joabreu@synopsys.com>; Maxime Coquelin <mcoquelin.stm32@gmail.com>;
> Richard Cochran <richardcochran@gmail.com>; Thampi, Vivek
> <vithampi@vmware.com>
> Subject: Re: [net-next 10/14] ptp: lan743x: convert to .adjfine and
> diff_by_scaled_ppm
> 
> Hi Jacob,
> 
> I love your patch! Yet something to improve:
> 
> [auto build test ERROR on 9017462f006c4b686cb1e1e1a3a52ea8363076e6]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Jacob-Keller/ptp-convert-
> drivers-to-adjfine/20220819-063154
> base:   9017462f006c4b686cb1e1e1a3a52ea8363076e6
> config: powerpc-allyesconfig (https://download.01.org/0day-
> ci/archive/20220821/202208212326.87xlsbQB-lkp@intel.com/config)
> compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project
> 01ffe31cbb54bfd8e38e71b3cf804a1d67ebf9c1)
> 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
>         # install powerpc cross compiling tool for clang build
>         # apt-get install binutils-powerpc-linux-gnu
>         # https://github.com/intel-lab-
> lkp/linux/commit/d3c6eac5778f2ce74e7d6d7be90a60f616551718
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review Jacob-Keller/ptp-convert-drivers-to-
> adjfine/20220819-063154
>         git checkout d3c6eac5778f2ce74e7d6d7be90a60f616551718
>         # 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=powerpc SHELL=/bin/bash
> 
> If you fix the issue, kindly add following tag where applicable
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All errors (new ones prefixed by >>):
> 
> >> drivers/net/ethernet/microchip/lan743x_ptp.c:368:12: error: redefinition of
> 'lan743x_ptpci_adjfine'
>    static int lan743x_ptpci_adjfine(struct ptp_clock_info *ptpci, long delta)
>               ^
>    drivers/net/ethernet/microchip/lan743x_ptp.c:335:12: note: previous
> definition is here
>    static int lan743x_ptpci_adjfine(struct ptp_clock_info *ptpci, long scaled_ppm)
>               ^
> >> drivers/net/ethernet/microchip/lan743x_ptp.c:386:3: error: use of undeclared
> identifier 'lan743_rate_adj'; did you mean 'lan743x_rate_adj'?
>                    lan743_rate_adj = (u32)diff;
>                    ^~~~~~~~~~~~~~~
>                    lan743x_rate_adj
>    drivers/net/ethernet/microchip/lan743x_ptp.c:374:6: note: 'lan743x_rate_adj'
> declared here
>            u64 lan743x_rate_adj;
>                ^
> >> drivers/net/ethernet/microchip/lan743x_ptp.c:388:3: error: use of undeclared
> identifier 'lan74e_rage_adj'; did you mean 'lan743x_rate_adj'?
>                    lan74e_rage_adj = (u32)diff | PTP_CLOCK_RATE_ADJ_DIR_;
>                    ^~~~~~~~~~~~~~~
>                    lan743x_rate_adj
>    drivers/net/ethernet/microchip/lan743x_ptp.c:374:6: note: 'lan743x_rate_adj'
> declared here
>            u64 lan743x_rate_adj;
>                ^
>    3 errors generated.
> 
> 

I'll fix this in v2 once I get feedback for the rest of the patches.

Thanks,
Jake

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [net-next 14/14] ptp: xgbe: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-19 21:04     ` Keller, Jacob E
@ 2022-08-22 20:47       ` Tom Lendacky
  2022-08-22 21:11         ` Keller, Jacob E
  0 siblings, 1 reply; 30+ messages in thread
From: Tom Lendacky @ 2022-08-22 20:47 UTC (permalink / raw)
  To: Keller, Jacob E, netdev
  Cc: K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu, Cui,
	Dexuan, Shyam Sundar S K, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Siva Reddy Kallam,
	Prashant Sreedharan, Michael Chan, Yisen Zhuang, Salil Mehta,
	Brandeburg, Jesse, Nguyen, Anthony L, Tariq Toukan,
	Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Thampi, Vivek,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

On 8/19/22 16:04, Keller, Jacob E wrote:
>> -----Original Message-----
>> From: Tom Lendacky <thomas.lendacky@amd.com>
>> Sent: Friday, August 19, 2022 9:05 AM
>> To: Keller, Jacob E <jacob.e.keller@intel.com>; netdev@vger.kernel.org
>> Cc: K. Y. Srinivasan <kys@microsoft.com>; Haiyang Zhang
>> <haiyangz@microsoft.com>; Stephen Hemminger <sthemmin@microsoft.com>;
>> Wei Liu <wei.liu@kernel.org>; Cui, Dexuan <decui@microsoft.com>; Shyam
>> Sundar S K <Shyam-sundar.S-k@amd.com>; David S. Miller
>> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub Kicinski
>> <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Siva Reddy Kallam
>> <siva.kallam@broadcom.com>; Prashant Sreedharan
>> <prashant@broadcom.com>; Michael Chan <mchan@broadcom.com>; Yisen
>> Zhuang <yisen.zhuang@huawei.com>; Salil Mehta <salil.mehta@huawei.com>;
>> Brandeburg, Jesse <jesse.brandeburg@intel.com>; Nguyen, Anthony L
>> <anthony.l.nguyen@intel.com>; Tariq Toukan <tariqt@nvidia.com>; Saeed
>> Mahameed <saeedm@nvidia.com>; Leon Romanovsky <leon@kernel.org>;
>> Bryan Whitehead <bryan.whitehead@microchip.com>; Sergey Shtylyov
>> <s.shtylyov@omp.ru>; Giuseppe Cavallaro <peppe.cavallaro@st.com>;
>> Alexandre Torgue <alexandre.torgue@foss.st.com>; Jose Abreu
>> <joabreu@synopsys.com>; Maxime Coquelin <mcoquelin.stm32@gmail.com>;
>> Richard Cochran <richardcochran@gmail.com>; Thampi, Vivek
>> <vithampi@vmware.com>; VMware PV-Drivers Reviewers <pv-
>> drivers@vmware.com>; Jie Wang <wangjie125@huawei.com>; Guangbin Huang
>> <huangguangbin2@huawei.com>; Eran Ben Elisha <eranbe@nvidia.com>; Aya
>> Levin <ayal@nvidia.com>; Cai Huoqing <cai.huoqing@linux.dev>; Biju Das
>> <biju.das.jz@bp.renesas.com>; Lad Prabhakar <prabhakar.mahadev-
>> lad.rj@bp.renesas.com>; Phil Edworthy <phil.edworthy@renesas.com>; Jiasheng
>> Jiang <jiasheng@iscas.ac.cn>; Gustavo A. R. Silva <gustavoars@kernel.org>; Linus
>> Walleij <linus.walleij@linaro.org>; Wan Jiabing <wanjiabing@vivo.com>; Lv Ruyi
>> <lv.ruyi@zte.com.cn>; Arnd Bergmann <arnd@arndb.de>
>> Subject: Re: [net-next 14/14] ptp: xgbe: convert to .adjfine and
>> adjust_by_scaled_ppm
>>
>> On 8/18/22 17:27, Jacob Keller wrote:
>>> The xgbe implementation of .adjfreq is implemented in terms of a
>>> straight forward "base * ppb / 1 billion" calculation.
>>>
>>> Convert this driver to .adjfine and use adjust_by_scaled_ppm to calculate
>>> the new addend value.
>>>
>>> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
>>> Cc: Tom Lendacky <thomas.lendacky@amd.com>
>>> Cc: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
>>> ---
>>>
>>> I do not have this hardware, and have only compile tested the change.
>>>
>>>    drivers/net/ethernet/amd/xgbe/xgbe-ptp.c | 20 ++++----------------
>>>    1 file changed, 4 insertions(+), 16 deletions(-)
>>>
>>> diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
>> b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
>>> index d06d260cf1e2..7051bd7cf6dc 100644
>>> --- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
>>> +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
>>> @@ -134,27 +134,15 @@ static u64 xgbe_cc_read(const struct cyclecounter
>> *cc)
>>>    	return nsec;
>>>    }
>>>
>>> -static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
>>> +static int xgbe_adjfine(struct ptp_clock_info *info, long scaled_ppm)
>>>    {
>>>    	struct xgbe_prv_data *pdata = container_of(info,
>>>    						   struct xgbe_prv_data,
>>>    						   ptp_clock_info);
>>>    	unsigned long flags;
>>> -	u64 adjust;
>>> -	u32 addend, diff;
>>> -	unsigned int neg_adjust = 0;
>>> +	u64 addend;
>>>
>>> -	if (delta < 0) {
>>> -		neg_adjust = 1;
>>> -		delta = -delta;
>>> -	}
>>> -
>>> -	adjust = pdata->tstamp_addend;
>>> -	adjust *= delta;
>>> -	diff = div_u64(adjust, 1000000000UL);
>>> -
>>> -	addend = (neg_adjust) ? pdata->tstamp_addend - diff :
>>> -				pdata->tstamp_addend + diff;
>>> +	addend = adjust_by_scaled_ppm(pdata->tstamp_addend, scaled_ppm);
>>
>> Since addend is now a u64, but the called function just afterwards,
>> xgbe_update_tstamp_addend(), expects an unsigned int, won't this generate
>> a compiler warning depending on the flags used?
>>
> 
> It doesn't seem to generate anything with W=1 or W=2 on my system. Its possible that the compiler can deduce that this won't overflow a u32?
> 
> We could add a check to ensure it doesn't overflow the u32 size?

As long as we don't see a warning, I'm ok with it.

Acked-by: Tom Lendacky <thomas.lendacky@amd.com>

Thanks,
Tom

> 
>> Thanks,
>> Tom
>>
>>>
>>>    	spin_lock_irqsave(&pdata->tstamp_lock, flags);
>>>
>>> @@ -235,7 +223,7 @@ void xgbe_ptp_register(struct xgbe_prv_data *pdata)
>>>    		 netdev_name(pdata->netdev));
>>>    	info->owner = THIS_MODULE;
>>>    	info->max_adj = pdata->ptpclk_rate;
>>> -	info->adjfreq = xgbe_adjfreq;
>>> +	info->adjfine = xgbe_adjfine;
>>>    	info->adjtime = xgbe_adjtime;
>>>    	info->gettime64 = xgbe_gettime;
>>>    	info->settime64 = xgbe_settime;

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [net-next 14/14] ptp: xgbe: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-22 20:47       ` Tom Lendacky
@ 2022-08-22 21:11         ` Keller, Jacob E
  0 siblings, 0 replies; 30+ messages in thread
From: Keller, Jacob E @ 2022-08-22 21:11 UTC (permalink / raw)
  To: Tom Lendacky, netdev
  Cc: K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu, Cui,
	Dexuan, Shyam Sundar S K, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Siva Reddy Kallam,
	Prashant Sreedharan, Michael Chan, Yisen Zhuang, Salil Mehta,
	Brandeburg, Jesse, Nguyen, Anthony L, Tariq Toukan,
	Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Thampi, Vivek,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann



> -----Original Message-----
> From: Tom Lendacky <thomas.lendacky@amd.com>
> Sent: Monday, August 22, 2022 1:48 PM
> To: Keller, Jacob E <jacob.e.keller@intel.com>; netdev@vger.kernel.org
> Cc: K. Y. Srinivasan <kys@microsoft.com>; Haiyang Zhang
> <haiyangz@microsoft.com>; Stephen Hemminger <sthemmin@microsoft.com>;
> Wei Liu <wei.liu@kernel.org>; Cui, Dexuan <decui@microsoft.com>; Shyam
> Sundar S K <Shyam-sundar.S-k@amd.com>; David S. Miller
> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub Kicinski
> <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Siva Reddy Kallam
> <siva.kallam@broadcom.com>; Prashant Sreedharan
> <prashant@broadcom.com>; Michael Chan <mchan@broadcom.com>; Yisen
> Zhuang <yisen.zhuang@huawei.com>; Salil Mehta <salil.mehta@huawei.com>;
> Brandeburg, Jesse <jesse.brandeburg@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Tariq Toukan <tariqt@nvidia.com>; Saeed
> Mahameed <saeedm@nvidia.com>; Leon Romanovsky <leon@kernel.org>;
> Bryan Whitehead <bryan.whitehead@microchip.com>; Sergey Shtylyov
> <s.shtylyov@omp.ru>; Giuseppe Cavallaro <peppe.cavallaro@st.com>;
> Alexandre Torgue <alexandre.torgue@foss.st.com>; Jose Abreu
> <joabreu@synopsys.com>; Maxime Coquelin <mcoquelin.stm32@gmail.com>;
> Richard Cochran <richardcochran@gmail.com>; Thampi, Vivek
> <vithampi@vmware.com>; VMware PV-Drivers Reviewers <pv-
> drivers@vmware.com>; Jie Wang <wangjie125@huawei.com>; Guangbin Huang
> <huangguangbin2@huawei.com>; Eran Ben Elisha <eranbe@nvidia.com>; Aya
> Levin <ayal@nvidia.com>; Cai Huoqing <cai.huoqing@linux.dev>; Biju Das
> <biju.das.jz@bp.renesas.com>; Lad Prabhakar <prabhakar.mahadev-
> lad.rj@bp.renesas.com>; Phil Edworthy <phil.edworthy@renesas.com>; Jiasheng
> Jiang <jiasheng@iscas.ac.cn>; Gustavo A. R. Silva <gustavoars@kernel.org>; Linus
> Walleij <linus.walleij@linaro.org>; Wan Jiabing <wanjiabing@vivo.com>; Lv Ruyi
> <lv.ruyi@zte.com.cn>; Arnd Bergmann <arnd@arndb.de>
> Subject: Re: [net-next 14/14] ptp: xgbe: convert to .adjfine and
> adjust_by_scaled_ppm
> 
> On 8/19/22 16:04, Keller, Jacob E wrote:
> >> -----Original Message-----
> >> From: Tom Lendacky <thomas.lendacky@amd.com>
> >> Sent: Friday, August 19, 2022 9:05 AM
> >> To: Keller, Jacob E <jacob.e.keller@intel.com>; netdev@vger.kernel.org
> >> Cc: K. Y. Srinivasan <kys@microsoft.com>; Haiyang Zhang
> >> <haiyangz@microsoft.com>; Stephen Hemminger
> <sthemmin@microsoft.com>;
> >> Wei Liu <wei.liu@kernel.org>; Cui, Dexuan <decui@microsoft.com>; Shyam
> >> Sundar S K <Shyam-sundar.S-k@amd.com>; David S. Miller
> >> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub
> Kicinski
> >> <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Siva Reddy Kallam
> >> <siva.kallam@broadcom.com>; Prashant Sreedharan
> >> <prashant@broadcom.com>; Michael Chan <mchan@broadcom.com>; Yisen
> >> Zhuang <yisen.zhuang@huawei.com>; Salil Mehta
> <salil.mehta@huawei.com>;
> >> Brandeburg, Jesse <jesse.brandeburg@intel.com>; Nguyen, Anthony L
> >> <anthony.l.nguyen@intel.com>; Tariq Toukan <tariqt@nvidia.com>; Saeed
> >> Mahameed <saeedm@nvidia.com>; Leon Romanovsky <leon@kernel.org>;
> >> Bryan Whitehead <bryan.whitehead@microchip.com>; Sergey Shtylyov
> >> <s.shtylyov@omp.ru>; Giuseppe Cavallaro <peppe.cavallaro@st.com>;
> >> Alexandre Torgue <alexandre.torgue@foss.st.com>; Jose Abreu
> >> <joabreu@synopsys.com>; Maxime Coquelin
> <mcoquelin.stm32@gmail.com>;
> >> Richard Cochran <richardcochran@gmail.com>; Thampi, Vivek
> >> <vithampi@vmware.com>; VMware PV-Drivers Reviewers <pv-
> >> drivers@vmware.com>; Jie Wang <wangjie125@huawei.com>; Guangbin
> Huang
> >> <huangguangbin2@huawei.com>; Eran Ben Elisha <eranbe@nvidia.com>; Aya
> >> Levin <ayal@nvidia.com>; Cai Huoqing <cai.huoqing@linux.dev>; Biju Das
> >> <biju.das.jz@bp.renesas.com>; Lad Prabhakar <prabhakar.mahadev-
> >> lad.rj@bp.renesas.com>; Phil Edworthy <phil.edworthy@renesas.com>;
> Jiasheng
> >> Jiang <jiasheng@iscas.ac.cn>; Gustavo A. R. Silva <gustavoars@kernel.org>;
> Linus
> >> Walleij <linus.walleij@linaro.org>; Wan Jiabing <wanjiabing@vivo.com>; Lv
> Ruyi
> >> <lv.ruyi@zte.com.cn>; Arnd Bergmann <arnd@arndb.de>
> >> Subject: Re: [net-next 14/14] ptp: xgbe: convert to .adjfine and
> >> adjust_by_scaled_ppm
> >>
> >> On 8/18/22 17:27, Jacob Keller wrote:
> >>> The xgbe implementation of .adjfreq is implemented in terms of a
> >>> straight forward "base * ppb / 1 billion" calculation.
> >>>
> >>> Convert this driver to .adjfine and use adjust_by_scaled_ppm to calculate
> >>> the new addend value.
> >>>
> >>> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> >>> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> >>> Cc: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
> >>> ---
> >>>
> >>> I do not have this hardware, and have only compile tested the change.
> >>>
> >>>    drivers/net/ethernet/amd/xgbe/xgbe-ptp.c | 20 ++++----------------
> >>>    1 file changed, 4 insertions(+), 16 deletions(-)
> >>>
> >>> diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
> >> b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
> >>> index d06d260cf1e2..7051bd7cf6dc 100644
> >>> --- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
> >>> +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
> >>> @@ -134,27 +134,15 @@ static u64 xgbe_cc_read(const struct cyclecounter
> >> *cc)
> >>>    	return nsec;
> >>>    }
> >>>
> >>> -static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
> >>> +static int xgbe_adjfine(struct ptp_clock_info *info, long scaled_ppm)
> >>>    {
> >>>    	struct xgbe_prv_data *pdata = container_of(info,
> >>>    						   struct xgbe_prv_data,
> >>>    						   ptp_clock_info);
> >>>    	unsigned long flags;
> >>> -	u64 adjust;
> >>> -	u32 addend, diff;
> >>> -	unsigned int neg_adjust = 0;
> >>> +	u64 addend;
> >>>
> >>> -	if (delta < 0) {
> >>> -		neg_adjust = 1;
> >>> -		delta = -delta;
> >>> -	}
> >>> -
> >>> -	adjust = pdata->tstamp_addend;
> >>> -	adjust *= delta;
> >>> -	diff = div_u64(adjust, 1000000000UL);
> >>> -
> >>> -	addend = (neg_adjust) ? pdata->tstamp_addend - diff :
> >>> -				pdata->tstamp_addend + diff;
> >>> +	addend = adjust_by_scaled_ppm(pdata->tstamp_addend, scaled_ppm);
> >>
> >> Since addend is now a u64, but the called function just afterwards,
> >> xgbe_update_tstamp_addend(), expects an unsigned int, won't this generate
> >> a compiler warning depending on the flags used?
> >>
> >
> > It doesn't seem to generate anything with W=1 or W=2 on my system. Its
> possible that the compiler can deduce that this won't overflow a u32?
> >
> > We could add a check to ensure it doesn't overflow the u32 size?
> 
> As long as we don't see a warning, I'm ok with it.
> 
> Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
> 
> Thanks,
> Tom
> 

Thanks. Since I'll need to send a v2 to fix some other drivers, I will double check this doesn't produce a warning carefully when I send the v2.

Thanks,
Jake

> >
> >> Thanks,
> >> Tom
> >>
> >>>
> >>>    	spin_lock_irqsave(&pdata->tstamp_lock, flags);
> >>>
> >>> @@ -235,7 +223,7 @@ void xgbe_ptp_register(struct xgbe_prv_data *pdata)
> >>>    		 netdev_name(pdata->netdev));
> >>>    	info->owner = THIS_MODULE;
> >>>    	info->max_adj = pdata->ptpclk_rate;
> >>> -	info->adjfreq = xgbe_adjfreq;
> >>> +	info->adjfine = xgbe_adjfine;
> >>>    	info->adjtime = xgbe_adjtime;
> >>>    	info->gettime64 = xgbe_gettime;
> >>>    	info->settime64 = xgbe_settime;

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [net-next 09/14] ptp: mlx5: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-18 22:27 ` [net-next 09/14] ptp: mlx5: " Jacob Keller
@ 2022-08-23 15:30   ` Gal Pressman
  2022-08-25  6:31     ` Gal Pressman
  2022-08-25 21:59     ` Keller, Jacob E
  0 siblings, 2 replies; 30+ messages in thread
From: Gal Pressman @ 2022-08-23 15:30 UTC (permalink / raw)
  To: Jacob Keller, netdev
  Cc: K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu,
	Dexuan Cui, Tom Lendacky, Shyam Sundar S K, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Siva Reddy Kallam,
	Prashant Sreedharan, Michael Chan, Yisen Zhuang, Salil Mehta,
	Jesse Brandeburg, Tony Nguyen, Tariq Toukan, Saeed Mahameed,
	Leon Romanovsky, Bryan Whitehead, Sergey Shtylyov,
	Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

On 19/08/2022 01:27, Jacob Keller wrote:
> The mlx5 implementation of .adjfreq is implemented in terms of a
> straight forward "base * ppb / 1 billion" calculation.
>
> Convert this to the .adjfine interface and use adjust_by_scaled_ppm for the
> calculation  of the new mult value.
>
> Note that the mlx5_ptp_adjfreq_real_time function expects input in terms of
> ppb, so use the scaled_ppm_to_ppb to convert before passing to this
> function.
>
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> Cc: Saeed Mahameed <saeedm@nvidia.com>
> Cc: Leon Romanovsky <leon@kernel.org>
> Cc: Aya Levin <ayal@nvidia.com>
> ---
>
> I do not have this hardware, and have only compile tested the change.
>
>  .../ethernet/mellanox/mlx5/core/lib/clock.c   | 22 +++++--------------
>  1 file changed, 6 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> index 91e806c1aa21..34871ab659d9 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> @@ -330,35 +330,25 @@ static int mlx5_ptp_adjfreq_real_time(struct mlx5_core_dev *mdev, s32 freq)
>  	return mlx5_set_mtutc(mdev, in, sizeof(in));
>  }
>  
> -static int mlx5_ptp_adjfreq(struct ptp_clock_info *ptp, s32 delta)
> +static int mlx5_ptp_adjfine(struct ptp_clock_info *ptp, long delta)

Small nit, please rename delta to scaled_ppm.
I'll try to get this tested in our regression soon.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [net-next 00/14] ptp: convert drivers to .adjfine
  2022-08-19 20:56   ` Keller, Jacob E
@ 2022-08-23 16:28     ` Richard Cochran
  0 siblings, 0 replies; 30+ messages in thread
From: Richard Cochran @ 2022-08-23 16:28 UTC (permalink / raw)
  To: Keller, Jacob E
  Cc: netdev, K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, Cui, Dexuan, Tom Lendacky, Shyam Sundar S K,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Siva Reddy Kallam, Prashant Sreedharan, Michael Chan,
	Yisen Zhuang, Salil Mehta, Brandeburg, Jesse, Nguyen, Anthony L,
	Tariq Toukan, Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Thampi, Vivek,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann

On Fri, Aug 19, 2022 at 08:56:38PM +0000, Keller, Jacob E wrote:
> > I'm on vacation until Monday, but I can test cpts on BBB then.
> > 
> > Thanks,
> > Richard
> 
> That would be great, thanks!

Oh well, net-next doesn't even boot out of the box on BBB.  Maybe the
TI folks have a recent working board with cpts...

Thanks,
Richard

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [net-next 09/14] ptp: mlx5: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-23 15:30   ` Gal Pressman
@ 2022-08-25  6:31     ` Gal Pressman
  2022-08-25 21:59     ` Keller, Jacob E
  1 sibling, 0 replies; 30+ messages in thread
From: Gal Pressman @ 2022-08-25  6:31 UTC (permalink / raw)
  To: Jacob Keller, netdev
  Cc: K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu,
	Dexuan Cui, Tom Lendacky, Shyam Sundar S K, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Siva Reddy Kallam,
	Prashant Sreedharan, Michael Chan, Yisen Zhuang, Salil Mehta,
	Jesse Brandeburg, Tony Nguyen, Tariq Toukan, Saeed Mahameed,
	Leon Romanovsky, Bryan Whitehead, Sergey Shtylyov,
	Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu,
	Maxime Coquelin, Richard Cochran, Vivek Thampi,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann,
	Shirly Ohnona

On 23/08/2022 18:30, Gal Pressman wrote:
> On 19/08/2022 01:27, Jacob Keller wrote:
>> The mlx5 implementation of .adjfreq is implemented in terms of a
>> straight forward "base * ppb / 1 billion" calculation.
>>
>> Convert this to the .adjfine interface and use adjust_by_scaled_ppm for the
>> calculation  of the new mult value.
>>
>> Note that the mlx5_ptp_adjfreq_real_time function expects input in terms of
>> ppb, so use the scaled_ppm_to_ppb to convert before passing to this
>> function.
>>
>> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
>> Cc: Saeed Mahameed <saeedm@nvidia.com>
>> Cc: Leon Romanovsky <leon@kernel.org>
>> Cc: Aya Levin <ayal@nvidia.com>
>> ---
>>
>> I do not have this hardware, and have only compile tested the change.
>>
>>  .../ethernet/mellanox/mlx5/core/lib/clock.c   | 22 +++++--------------
>>  1 file changed, 6 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
>> index 91e806c1aa21..34871ab659d9 100644
>> --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
>> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
>> @@ -330,35 +330,25 @@ static int mlx5_ptp_adjfreq_real_time(struct mlx5_core_dev *mdev, s32 freq)
>>  	return mlx5_set_mtutc(mdev, in, sizeof(in));
>>  }
>>  
>> -static int mlx5_ptp_adjfreq(struct ptp_clock_info *ptp, s32 delta)
>> +static int mlx5_ptp_adjfine(struct ptp_clock_info *ptp, long delta)
> Small nit, please rename delta to scaled_ppm.
> I'll try to get this tested in our regression soon.

Tested-by: Shirly Ohnona <shirlyo@nvidia.com>

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [net-next 09/14] ptp: mlx5: convert to .adjfine and adjust_by_scaled_ppm
  2022-08-23 15:30   ` Gal Pressman
  2022-08-25  6:31     ` Gal Pressman
@ 2022-08-25 21:59     ` Keller, Jacob E
  1 sibling, 0 replies; 30+ messages in thread
From: Keller, Jacob E @ 2022-08-25 21:59 UTC (permalink / raw)
  To: Gal Pressman, netdev
  Cc: K. Y. Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu, Cui,
	Dexuan, Tom Lendacky, Shyam Sundar S K, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Siva Reddy Kallam,
	Prashant Sreedharan, Michael Chan, Yisen Zhuang, Salil Mehta,
	Brandeburg, Jesse, Nguyen, Anthony L, Tariq Toukan,
	Saeed Mahameed, Leon Romanovsky, Bryan Whitehead,
	Sergey Shtylyov, Giuseppe Cavallaro, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Richard Cochran, Thampi, Vivek,
	VMware PV-Drivers Reviewers, Jie Wang, Guangbin Huang,
	Eran Ben Elisha, Aya Levin, Cai Huoqing, Biju Das, Lad Prabhakar,
	Phil Edworthy, Jiasheng Jiang, Gustavo A. R. Silva,
	Linus Walleij, Wan Jiabing, Lv Ruyi, Arnd Bergmann



> -----Original Message-----
> From: Gal Pressman <gal@nvidia.com>
> Sent: Tuesday, August 23, 2022 8:31 AM
> To: Keller, Jacob E <jacob.e.keller@intel.com>; netdev@vger.kernel.org
> Cc: K. Y. Srinivasan <kys@microsoft.com>; Haiyang Zhang
> <haiyangz@microsoft.com>; Stephen Hemminger <sthemmin@microsoft.com>;
> Wei Liu <wei.liu@kernel.org>; Cui, Dexuan <decui@microsoft.com>; Tom
> Lendacky <thomas.lendacky@amd.com>; Shyam Sundar S K <Shyam-sundar.S-
> k@amd.com>; David S. Miller <davem@davemloft.net>; Eric Dumazet
> <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni
> <pabeni@redhat.com>; Siva Reddy Kallam <siva.kallam@broadcom.com>;
> Prashant Sreedharan <prashant@broadcom.com>; Michael Chan
> <mchan@broadcom.com>; Yisen Zhuang <yisen.zhuang@huawei.com>; Salil
> Mehta <salil.mehta@huawei.com>; Brandeburg, Jesse
> <jesse.brandeburg@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; Tariq Toukan <tariqt@nvidia.com>; Saeed
> Mahameed <saeedm@nvidia.com>; Leon Romanovsky <leon@kernel.org>;
> Bryan Whitehead <bryan.whitehead@microchip.com>; Sergey Shtylyov
> <s.shtylyov@omp.ru>; Giuseppe Cavallaro <peppe.cavallaro@st.com>;
> Alexandre Torgue <alexandre.torgue@foss.st.com>; Jose Abreu
> <joabreu@synopsys.com>; Maxime Coquelin <mcoquelin.stm32@gmail.com>;
> Richard Cochran <richardcochran@gmail.com>; Thampi, Vivek
> <vithampi@vmware.com>; VMware PV-Drivers Reviewers <pv-
> drivers@vmware.com>; Jie Wang <wangjie125@huawei.com>; Guangbin Huang
> <huangguangbin2@huawei.com>; Eran Ben Elisha <eranbe@nvidia.com>; Aya
> Levin <ayal@nvidia.com>; Cai Huoqing <cai.huoqing@linux.dev>; Biju Das
> <biju.das.jz@bp.renesas.com>; Lad Prabhakar <prabhakar.mahadev-
> lad.rj@bp.renesas.com>; Phil Edworthy <phil.edworthy@renesas.com>; Jiasheng
> Jiang <jiasheng@iscas.ac.cn>; Gustavo A. R. Silva <gustavoars@kernel.org>; Linus
> Walleij <linus.walleij@linaro.org>; Wan Jiabing <wanjiabing@vivo.com>; Lv Ruyi
> <lv.ruyi@zte.com.cn>; Arnd Bergmann <arnd@arndb.de>
> Subject: Re: [net-next 09/14] ptp: mlx5: convert to .adjfine and
> adjust_by_scaled_ppm
> 
> On 19/08/2022 01:27, Jacob Keller wrote:
> > The mlx5 implementation of .adjfreq is implemented in terms of a
> > straight forward "base * ppb / 1 billion" calculation.
> >
> > Convert this to the .adjfine interface and use adjust_by_scaled_ppm for the
> > calculation  of the new mult value.
> >
> > Note that the mlx5_ptp_adjfreq_real_time function expects input in terms of
> > ppb, so use the scaled_ppm_to_ppb to convert before passing to this
> > function.
> >
> > Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> > Cc: Saeed Mahameed <saeedm@nvidia.com>
> > Cc: Leon Romanovsky <leon@kernel.org>
> > Cc: Aya Levin <ayal@nvidia.com>
> > ---
> >
> > I do not have this hardware, and have only compile tested the change.
> >
> >  .../ethernet/mellanox/mlx5/core/lib/clock.c   | 22 +++++--------------
> >  1 file changed, 6 insertions(+), 16 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> > index 91e806c1aa21..34871ab659d9 100644
> > --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> > +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> > @@ -330,35 +330,25 @@ static int mlx5_ptp_adjfreq_real_time(struct
> mlx5_core_dev *mdev, s32 freq)
> >  	return mlx5_set_mtutc(mdev, in, sizeof(in));
> >  }
> >
> > -static int mlx5_ptp_adjfreq(struct ptp_clock_info *ptp, s32 delta)
> > +static int mlx5_ptp_adjfine(struct ptp_clock_info *ptp, long delta)
> 
> Small nit, please rename delta to scaled_ppm.
> I'll try to get this tested in our regression soon.

Will fix that in v2. Thanks for testing!

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2022-08-25 21:59 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-18 22:27 [net-next 00/14] ptp: convert drivers to .adjfine Jacob Keller
2022-08-18 22:27 ` [net-next 01/14] ptp: add missing documentation for parameters Jacob Keller
2022-08-18 22:27 ` [net-next 02/14] ptp: introduce helpers to adjust by scaled parts per million Jacob Keller
2022-08-18 22:27 ` [net-next 03/14] drivers: convert unsupported .adjfreq to .adjfine Jacob Keller
2022-08-18 22:27 ` [net-next 04/14] ptp_phc: convert to .adjfine and ptp_adj_scaled_ppm Jacob Keller
2022-08-18 22:27 ` [net-next 05/14] ptp_ixp46x: convert to .adjfine and adjust_by_scaled_ppm Jacob Keller
2022-08-18 22:27 ` [net-next 06/14] ptp: tg3: convert to .adjfine and diff_by_scaled_ppm Jacob Keller
2022-08-18 22:27 ` [net-next 07/14] ptp: hclge: convert to .adjfine and adjust_by_scaled_ppm Jacob Keller
2022-08-18 22:27 ` [net-next 08/14] ptp: mlx4: " Jacob Keller
2022-08-18 22:27 ` [net-next 09/14] ptp: mlx5: " Jacob Keller
2022-08-23 15:30   ` Gal Pressman
2022-08-25  6:31     ` Gal Pressman
2022-08-25 21:59     ` Keller, Jacob E
2022-08-18 22:27 ` [net-next 10/14] ptp: lan743x: convert to .adjfine and diff_by_scaled_ppm Jacob Keller
2022-08-19  2:47   ` kernel test robot
2022-08-21 15:22   ` kernel test robot
2022-08-22 17:10     ` Keller, Jacob E
2022-08-18 22:27 ` [net-next 11/14] ptp: ravb: convert to .adjfine and adjust_by_scaled_ppm Jacob Keller
2022-08-20 19:33   ` Sergey Shtylyov
2022-08-22 17:07     ` Keller, Jacob E
2022-08-18 22:27 ` [net-next 12/14] ptp: stmac: " Jacob Keller
2022-08-18 22:27 ` [net-next 13/14] ptp: cpts: " Jacob Keller
2022-08-18 22:27 ` [net-next 14/14] ptp: xgbe: " Jacob Keller
2022-08-19 16:05   ` Tom Lendacky
2022-08-19 21:04     ` Keller, Jacob E
2022-08-22 20:47       ` Tom Lendacky
2022-08-22 21:11         ` Keller, Jacob E
2022-08-19  7:39 ` [net-next 00/14] ptp: convert drivers to .adjfine Richard Cochran
2022-08-19 20:56   ` Keller, Jacob E
2022-08-23 16:28     ` Richard Cochran

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.