diff mbox series

[net-next,7/9] ptp: bnxt: convert .adjfreq to .adjfine

Message ID 20221109230945.545440-8-jacob.e.keller@intel.com (mailing list archive)
State Accepted
Commit a29c132f92ed5af6e7116966b7e9899d4c22783c
Delegated to: Netdev Maintainers
Headers show
Series ptp: convert remaining users of .adjfreq | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 3 maintainers not CCed: davem@davemloft.net pabeni@redhat.com edumazet@google.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 50 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jacob Keller Nov. 9, 2022, 11:09 p.m. UTC
When the BNXT_FW_CAP_PTP_RTC flag is not set, the bnxt driver implements
.adjfreq on a cyclecounter in terms of the straightforward "base * ppb / 1
billion" calculation. When BNXT_FW_CAP_PTP_RTC is set, the driver forwards
the ppb value to firmware for configuration.

Convert the driver to the newer .adjfine interface, updating the
cyclecounter calculation to use adjust_by_scaled_ppm to perform the
calculation. Use scaled_ppm_to_ppb when forwarding the correction to
firmware.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Michael Chan <michael.chan@broadcom.com>
Cc: Richard Cochran <richardcochran@gmail.com>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c | 22 +++++--------------
 1 file changed, 6 insertions(+), 16 deletions(-)

Comments

Pavan Chebbi Nov. 10, 2022, 5:24 a.m. UTC | #1
On Thu, Nov 10, 2022 at 4:40 AM Jacob Keller <jacob.e.keller@intel.com> wrote:
>
> When the BNXT_FW_CAP_PTP_RTC flag is not set, the bnxt driver implements
> .adjfreq on a cyclecounter in terms of the straightforward "base * ppb / 1
> billion" calculation. When BNXT_FW_CAP_PTP_RTC is set, the driver forwards
> the ppb value to firmware for configuration.
>
> Convert the driver to the newer .adjfine interface, updating the
> cyclecounter calculation to use adjust_by_scaled_ppm to perform the
> calculation. Use scaled_ppm_to_ppb when forwarding the correction to
> firmware.
>
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> Cc: Michael Chan <michael.chan@broadcom.com>
> Cc: Richard Cochran <richardcochran@gmail.com>
> ---
>  drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c | 22 +++++--------------
>  1 file changed, 6 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
> index 460cb20599f6..4ec8bba18cdd 100644
> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
> @@ -205,7 +205,7 @@ static int bnxt_ptp_adjtime(struct ptp_clock_info *ptp_info, s64 delta)
>         return 0;
>  }
>
> -static int bnxt_ptp_adjfreq(struct ptp_clock_info *ptp_info, s32 ppb)
> +static int bnxt_ptp_adjfine(struct ptp_clock_info *ptp_info, long scaled_ppm)
>  {
>         struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg,
>                                                 ptp_info);
> @@ -214,23 +214,13 @@ static int bnxt_ptp_adjfreq(struct ptp_clock_info *ptp_info, s32 ppb)
>         int rc = 0;
>
>         if (!(ptp->bp->fw_cap & BNXT_FW_CAP_PTP_RTC)) {
> -               int neg_adj = 0;
> -               u32 diff;
> -               u64 adj;
> -
> -               if (ppb < 0) {
> -                       neg_adj = 1;
> -                       ppb = -ppb;
> -               }
> -               adj = ptp->cmult;
> -               adj *= ppb;
> -               diff = div_u64(adj, 1000000000ULL);
> -
>                 spin_lock_bh(&ptp->ptp_lock);
>                 timecounter_read(&ptp->tc);
> -               ptp->cc.mult = neg_adj ? ptp->cmult - diff : ptp->cmult + diff;
> +               ptp->cc.mult = adjust_by_scaled_ppm(ptp->cmult, scaled_ppm);
>                 spin_unlock_bh(&ptp->ptp_lock);
>         } else {
> +               s32 ppb = scaled_ppm_to_ppb(scaled_ppm);
> +
>                 rc = hwrm_req_init(bp, req, HWRM_PORT_MAC_CFG);
>                 if (rc)
>                         return rc;
> @@ -240,7 +230,7 @@ static int bnxt_ptp_adjfreq(struct ptp_clock_info *ptp_info, s32 ppb)
>                 rc = hwrm_req_send(ptp->bp, req);
>                 if (rc)
>                         netdev_err(ptp->bp->dev,
> -                                  "ptp adjfreq failed. rc = %d\n", rc);
> +                                  "ptp adjfine failed. rc = %d\n", rc);
>         }
>         return rc;
>  }
> @@ -769,7 +759,7 @@ static const struct ptp_clock_info bnxt_ptp_caps = {
>         .n_per_out      = 0,
>         .n_pins         = 0,
>         .pps            = 0,
> -       .adjfreq        = bnxt_ptp_adjfreq,
> +       .adjfine        = bnxt_ptp_adjfine,
>         .adjtime        = bnxt_ptp_adjtime,
>         .do_aux_work    = bnxt_ptp_ts_aux_work,
>         .gettimex64     = bnxt_ptp_gettimex,
> --
> 2.38.0.83.gd420dda05763
>
Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
index 460cb20599f6..4ec8bba18cdd 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
@@ -205,7 +205,7 @@  static int bnxt_ptp_adjtime(struct ptp_clock_info *ptp_info, s64 delta)
 	return 0;
 }
 
-static int bnxt_ptp_adjfreq(struct ptp_clock_info *ptp_info, s32 ppb)
+static int bnxt_ptp_adjfine(struct ptp_clock_info *ptp_info, long scaled_ppm)
 {
 	struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg,
 						ptp_info);
@@ -214,23 +214,13 @@  static int bnxt_ptp_adjfreq(struct ptp_clock_info *ptp_info, s32 ppb)
 	int rc = 0;
 
 	if (!(ptp->bp->fw_cap & BNXT_FW_CAP_PTP_RTC)) {
-		int neg_adj = 0;
-		u32 diff;
-		u64 adj;
-
-		if (ppb < 0) {
-			neg_adj = 1;
-			ppb = -ppb;
-		}
-		adj = ptp->cmult;
-		adj *= ppb;
-		diff = div_u64(adj, 1000000000ULL);
-
 		spin_lock_bh(&ptp->ptp_lock);
 		timecounter_read(&ptp->tc);
-		ptp->cc.mult = neg_adj ? ptp->cmult - diff : ptp->cmult + diff;
+		ptp->cc.mult = adjust_by_scaled_ppm(ptp->cmult, scaled_ppm);
 		spin_unlock_bh(&ptp->ptp_lock);
 	} else {
+		s32 ppb = scaled_ppm_to_ppb(scaled_ppm);
+
 		rc = hwrm_req_init(bp, req, HWRM_PORT_MAC_CFG);
 		if (rc)
 			return rc;
@@ -240,7 +230,7 @@  static int bnxt_ptp_adjfreq(struct ptp_clock_info *ptp_info, s32 ppb)
 		rc = hwrm_req_send(ptp->bp, req);
 		if (rc)
 			netdev_err(ptp->bp->dev,
-				   "ptp adjfreq failed. rc = %d\n", rc);
+				   "ptp adjfine failed. rc = %d\n", rc);
 	}
 	return rc;
 }
@@ -769,7 +759,7 @@  static const struct ptp_clock_info bnxt_ptp_caps = {
 	.n_per_out	= 0,
 	.n_pins		= 0,
 	.pps		= 0,
-	.adjfreq	= bnxt_ptp_adjfreq,
+	.adjfine	= bnxt_ptp_adjfine,
 	.adjtime	= bnxt_ptp_adjtime,
 	.do_aux_work	= bnxt_ptp_ts_aux_work,
 	.gettimex64	= bnxt_ptp_gettimex,