Message ID | 20221109230945.545440-4-jacob.e.keller@intel.com (mailing list archive) |
---|---|
State | Accepted |
Commit | e3f18e9d353aa8bd9e4db10acab21df380e212f5 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | ptp: convert remaining users of .adjfreq | expand |
On Thu, Nov 10, 2022 at 4:40 AM Jacob Keller <jacob.e.keller@intel.com> wrote: > > The tg3 implementation of .adjfreq is implemented in terms of a > straight forward "base * ppb / 1 billion" calculation. > > Convert this to the newer .adjfine, using the recently added > diff_by_scaled_ppm helper function to calculate the difference and > direction of the adjustment. > > 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> > Cc: Richard Cochran <richardcochran@gmail.com> > --- > drivers/net/ethernet/broadcom/tg3.c | 22 +++++++--------------- > 1 file changed, 7 insertions(+), 15 deletions(-) > > diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c > index 4179a12fc881..59debdc344a5 100644 > --- a/drivers/net/ethernet/broadcom/tg3.c > +++ b/drivers/net/ethernet/broadcom/tg3.c > @@ -6179,34 +6179,26 @@ 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; > - } > + u64 correction; > + bool neg_adj; > > /* 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 > */ > - correction = div_u64((u64)ppb * (1 << 24), 1000000000ULL) & > - TG3_EAV_REF_CLK_CORRECT_MASK; > + neg_adj = diff_by_scaled_ppm(1 << 24, scaled_ppm, &correction); > > tg3_full_lock(tp, 0); > > if (correction) > tw32(TG3_EAV_REF_CLK_CORRECT_CTL, > TG3_EAV_REF_CLK_CORRECT_EN | > - (neg_adj ? TG3_EAV_REF_CLK_CORRECT_NEG : 0) | correction); > + (neg_adj ? TG3_EAV_REF_CLK_CORRECT_NEG : 0) | > + ((u32)correction & TG3_EAV_REF_CLK_CORRECT_MASK)); > else > tw32(TG3_EAV_REF_CLK_CORRECT_CTL, 0); > > @@ -6330,7 +6322,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.38.0.83.gd420dda05763 > Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com>
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c index 4179a12fc881..59debdc344a5 100644 --- a/drivers/net/ethernet/broadcom/tg3.c +++ b/drivers/net/ethernet/broadcom/tg3.c @@ -6179,34 +6179,26 @@ 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; - } + u64 correction; + bool neg_adj; /* 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 */ - correction = div_u64((u64)ppb * (1 << 24), 1000000000ULL) & - TG3_EAV_REF_CLK_CORRECT_MASK; + neg_adj = diff_by_scaled_ppm(1 << 24, scaled_ppm, &correction); tg3_full_lock(tp, 0); if (correction) tw32(TG3_EAV_REF_CLK_CORRECT_CTL, TG3_EAV_REF_CLK_CORRECT_EN | - (neg_adj ? TG3_EAV_REF_CLK_CORRECT_NEG : 0) | correction); + (neg_adj ? TG3_EAV_REF_CLK_CORRECT_NEG : 0) | + ((u32)correction & TG3_EAV_REF_CLK_CORRECT_MASK)); else tw32(TG3_EAV_REF_CLK_CORRECT_CTL, 0); @@ -6330,7 +6322,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,
The tg3 implementation of .adjfreq is implemented in terms of a straight forward "base * ppb / 1 billion" calculation. Convert this to the newer .adjfine, using the recently added diff_by_scaled_ppm helper function to calculate the difference and direction of the adjustment. 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> Cc: Richard Cochran <richardcochran@gmail.com> --- drivers/net/ethernet/broadcom/tg3.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)