ptp: xgbe: convert to .adjfine and adjust_by_scaled_ppm
authorJacob Keller <jacob.e.keller@intel.com>
Fri, 28 Oct 2022 11:04:20 +0000 (04:04 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 31 Oct 2022 11:14:16 +0000 (11:14 +0000)
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>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/amd/xgbe/xgbe-ptp.c

index d06d260..7051bd7 100644 (file)
@@ -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;