netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Cochran <richardcochran@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: netdev <netdev@vger.kernel.org>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Vivien Didelot <vivien.didelot@savoirfairelinux.com>,
	sean.wang@mediatek.com, Woojung.Huh@microchip.com,
	john@phrozen.org, jbe@pengutronix.de,
	Brandon Streiff <brandon.streiff@ni.com>
Subject: Re: [RFC PATCH 04/10] net: dsa: mv88e6xxx: expose switch time as a PTP hardware clock
Date: Fri, 9 Feb 2018 12:33:36 -0800	[thread overview]
Message-ID: <20180209203336.fqkuliaqmonl67jg@localhost> (raw)
In-Reply-To: <1517694016-6692-5-git-send-email-andrew@lunn.ch>

On Sat, Feb 03, 2018 at 10:40:08PM +0100, Andrew Lunn wrote:
> +static int mv88e6xxx_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
> +{
> +	struct mv88e6xxx_chip *chip = ptp_to_chip(ptp);
> +	int neg_adj = 0;
> +	u32 diff, mult;
> +	u64 adj;
> +
> +	if (scaled_ppm < 0) {
> +		neg_adj = 1;
> +		scaled_ppm = -scaled_ppm;
> +	}
> +	mult = CC_MULT;
> +	adj = scaled_ppm * CC_MULT_NUM;
              ^^^^^^^^^^^^^^^^^^^^^^^^
This easily overflows on 32 bit platforms.  My bad.  Fix below...

> +	diff = div_u64(adj, CC_MULT_DEM);
> +
> +	mutex_lock(&chip->reg_lock);
> +
> +	timecounter_read(&chip->tstamp_tc);
> +	chip->tstamp_cc.mult = neg_adj ? mult - diff : mult + diff;
> +
> +	mutex_unlock(&chip->reg_lock);
> +
> +	return 0;
> +}

Thanks,
Richard

---
diff --git a/drivers/net/dsa/mv88e6xxx/ptp.c b/drivers/net/dsa/mv88e6xxx/ptp.c
index 92f318743bd4..bd85e2c390e1 100644
--- a/drivers/net/dsa/mv88e6xxx/ptp.c
+++ b/drivers/net/dsa/mv88e6xxx/ptp.c
@@ -177,7 +177,8 @@ static int mv88e6xxx_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
 		scaled_ppm = -scaled_ppm;
 	}
 	mult = CC_MULT;
-	adj = scaled_ppm * CC_MULT_NUM;
+	adj = CC_MULT_NUM;
+	adj *= scaled_ppm;
 	diff = div_u64(adj, CC_MULT_DEM);
 
 	mutex_lock(&chip->reg_lock);

  reply	other threads:[~2018-02-09 20:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-03 21:40 [RFC PATCH 00/10] PTP support for DSA and mv88e6xxx driver Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 01/10] net: ptp: Add stub for ptp_classify_raw() Andrew Lunn
2018-02-04  9:34   ` Sergei Shtylyov
2018-02-03 21:40 ` [RFC PATCH 02/10] net: dsa: mv88e6xxx: export g2 register accessors Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 03/10] net: dsa: mv88e6xxx: add accessors for PTP/TAI registers Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 04/10] net: dsa: mv88e6xxx: expose switch time as a PTP hardware clock Andrew Lunn
2018-02-09 20:33   ` Richard Cochran [this message]
2018-02-09 21:04     ` Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 05/10] net: dsa: mv88e6xxx: add support for GPIO configuration Andrew Lunn
2018-02-04 19:53   ` Florian Fainelli
2018-02-04 20:17     ` Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 06/10] net: dsa: mv88e6xxx: add support for event capture Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 07/10] net: dsa: forward hardware timestamping ioctls to switch driver Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 08/10] net: dsa: forward timestamping callbacks to switch drivers Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 09/10] net: dsa: mv88e6xxx: add rx/tx timestamping support Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 10/10] net: dsa: mv88e6xxx: add workaround for 6341 timestamping Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 11/12] net: dsa: mv88e6xxx: Release mutex between each statistics read Andrew Lunn
2018-02-03 21:40 ` [RFC PATCH 12/12] net: dsa: mv88e6xxx: Release mutex between each ATU read Andrew Lunn
2018-02-06 19:44 ` [RFC PATCH 00/10] PTP support for DSA and mv88e6xxx driver Brandon Streiff

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=20180209203336.fqkuliaqmonl67jg@localhost \
    --to=richardcochran@gmail.com \
    --cc=Woojung.Huh@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=brandon.streiff@ni.com \
    --cc=f.fainelli@gmail.com \
    --cc=jbe@pengutronix.de \
    --cc=john@phrozen.org \
    --cc=netdev@vger.kernel.org \
    --cc=sean.wang@mediatek.com \
    --cc=vivien.didelot@savoirfairelinux.com \
    /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).