netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Cochran <richardcochran@gmail.com>
To: Yuval Mintz <Yuval.Mintz@cavium.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org,
	Sudarsana.Kalluru@cavium.com
Subject: Re: [PATCH net-next v5 1/2] qed: Add infrastructure for PTP support
Date: Mon, 13 Feb 2017 21:25:50 +0100	[thread overview]
Message-ID: <20170213202550.GA3005@localhost.localdomain> (raw)
In-Reply-To: <1486993586-16431-2-git-send-email-Yuval.Mintz@cavium.com>

On Mon, Feb 13, 2017 at 03:46:25PM +0200, Yuval Mintz wrote:
> +static int qed_ptp_hw_adjfreq(struct qed_dev *cdev, s32 ppb)
> +{
> +	struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
> +	struct qed_ptt *p_ptt = p_hwfn->p_ptp_ptt;
> +	int drift_dir, best_val, best_period;
> +	s64 period, dif, dif2;
> +	u32 drift_ctr_cfg = 0;
> +	s64 best_dif, val;
> +	u32 drift_state;
> +
> +	best_dif = ppb;
> +	best_period = 2;
> +	best_val = 0;
> +	drift_dir = 1;
> +
> +	if (ppb < 0) {
> +		ppb = -ppb;
> +		drift_dir = 0;
> +	}
> +
> +	if (ppb == 0) {
> +		/* No clock adjustment required */
> +		best_val = 0;
> +		best_period = 0xFFFFFFF;
> +	} else {
> +		/* Adjustment value is up to +/-7ns, find an optimal value in
> +		 * this range.
> +		 */
> +		for (val = 7; val > 0; val++) {

This is an endless loop. ------------- ^^^^^

Besides that, this code returns some very strange values.  For
example, for ppb = 100106, 100107, and 100108.  Also ppb = 1...8
all return 0/40.

Trouble with the -= 8?

I can only recommend plotting all of the raw errors and also average
(RMS) error over the nominal interval ppb = 1...500000.


Thanks,
Richard

> +			period = div_s64(val * 1000000000, ppb);
> +			period -= 8;
> +			period >>= 4;
> +			if (period < 1)
> +				period = 1;
> +			if (period > 0xFFFFFFE)
> +				period = 0xFFFFFFE;
> +
> +			/* Check both rounding ends for approximate error */
> +			dif = ppb * (period * 16 + 8) - val * 1000000000;
> +			dif2 = dif + 16 * ppb;
> +
> +			if (dif < 0)
> +				dif = -dif;
> +			if (dif2 < 0)
> +				dif2 = -dif2;
> +			if (dif2 < dif) {
> +				period++;
> +				dif = dif2;
> +			}
> +
> +			/* Track best approximation found so far */
> +			if (dif < best_dif) {
> +				best_dif = dif;
> +				best_val = (int)val;
> +				best_period = (int)period;
> +			}
> +		}
> +	}
> +
> +	drift_ctr_cfg = (best_period << QED_DRIFT_CNTR_TIME_QUANTA_SHIFT) |
> +			(best_val << QED_DRIFT_CNTR_ADJUSTMENT_SHIFT) |
> +			(drift_dir << QED_DRIFT_CNTR_DIRECTION_SHIFT);
> +
> +	qed_wr(p_hwfn, p_ptt, NIG_REG_TSGEN_RST_DRIFT_CNTR, 0x1);
> +
> +	drift_state = qed_rd(p_hwfn, p_ptt, NIG_REG_TSGEN_RST_DRIFT_CNTR);
> +	if (drift_state & 1) {
> +		qed_wr(p_hwfn, p_ptt, NIG_REG_TSGEN_DRIFT_CNTR_CONF,
> +		       drift_ctr_cfg);
> +	} else {
> +		DP_INFO(p_hwfn, "Drift counter is not reset\n");
> +		return -EINVAL;
> +	}
> +
> +	qed_wr(p_hwfn, p_ptt, NIG_REG_TSGEN_RST_DRIFT_CNTR, 0x0);
> +
> +	return 0;
> +}

  reply	other threads:[~2017-02-13 20:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-13 13:46 [PATCH net-next v5 0/2] qed*: Add support for PTP Yuval Mintz
2017-02-13 13:46 ` [PATCH net-next v5 1/2] qed: Add infrastructure for PTP support Yuval Mintz
2017-02-13 20:25   ` Richard Cochran [this message]
2017-02-13 21:51     ` Mintz, Yuval
2017-02-13 13:46 ` [PATCH net-next v5 2/2] qede: Add driver support for PTP Yuval Mintz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170213202550.GA3005@localhost.localdomain \
    --to=richardcochran@gmail.com \
    --cc=Sudarsana.Kalluru@cavium.com \
    --cc=Yuval.Mintz@cavium.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).