netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rahul Rameshbabu <rrameshbabu@nvidia.com>
To: Saeed Mahameed <saeedm@nvidia.com>,
	Leon Romanovsky <leon@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Richard Cochran <richardcochran@gmail.com>,
	Rahul Rameshbabu <rrameshbabu@nvidia.com>,
	Jacob Keller <jacob.e.keller@intel.com>,
	Aya Levin <ayal@nvidia.com>, Gal Pressman <gal@nvidia.com>
Cc: netdev@vger.kernel.org
Subject: [PATCH net-next 1/2] ptp: Add .getfine function to support reporting frequency offset from hardware
Date: Fri,  2 Dec 2022 12:15:29 -0800	[thread overview]
Message-ID: <20221202201528.26634-2-rrameshbabu@nvidia.com> (raw)
In-Reply-To: <20221202201528.26634-1-rrameshbabu@nvidia.com>

Query the hardware for the operational frequency (represented in 16-bit
fractional parts-per-million) instead of caching the value last set by the
last adjfine command. Prevent inconsistencies between the ptp driver and
the hardware.

For drivers that do not implement the .getfine callback, the cached value
is used.

The linuxptp community has seen cases where the cached value for frequency
is incorrect due to concurrent ptp4l processes adjusting frequency but each
using a stale cache value for frequency. The .getfine callback remedies
that by letting implementers provide a method for querying the frequency.

Signed-off-by: Rahul Rameshbabu <rrameshbabu@nvidia.com>
Reviewed-by: Gal Pressman <gal@nvidia.com>
Cc: Richard Cochran <richardcochran@gmail.com>
---
 drivers/ptp/ptp_clock.c          | 18 +++++++++++++++++-
 include/linux/ptp_clock_kernel.h |  6 ++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index 62d4d29e7c05..1655381ae731 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -66,6 +66,22 @@ static void enqueue_external_timestamp(struct timestamp_event_queue *queue,
 
 /* posix clock implementation */
 
+static long ptp_get_fine(struct ptp_clock *ptp)
+{
+	struct ptp_clock_info *ops = ptp->info;
+
+	if (ops->getfine) {
+		long fine;
+
+		if (ops->getfine(ops, &fine))
+			return ptp->dialed_frequency;
+
+		return fine;
+	}
+
+	return ptp->dialed_frequency;
+}
+
 static int ptp_clock_getres(struct posix_clock *pc, struct timespec64 *tp)
 {
 	tp->tv_sec = 0;
@@ -143,7 +159,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct __kernel_timex *tx)
 			err = ops->adjphase(ops, offset);
 		}
 	} else if (tx->modes == 0) {
-		tx->freq = ptp->dialed_frequency;
+		tx->freq = ptp_get_fine(ptp);
 		err = 0;
 	}
 
diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h
index fdffa6a98d79..f17097de349e 100644
--- a/include/linux/ptp_clock_kernel.h
+++ b/include/linux/ptp_clock_kernel.h
@@ -77,6 +77,11 @@ struct ptp_system_timestamp {
  *            nominal frequency in parts per million, but with a
  *            16 bit binary fractional field.
  *
+ * @getfine:  Reads the current frequency offset from the hardware clock.
+ *            parameter scaled_ppm: Requested frequency offset from
+ *            nominal frequency in parts per million, but with a
+ *            16 bit binary fractional field.
+ *
  * @adjphase:  Adjusts the phase offset of the hardware clock.
  *             parameter delta: Desired change in nanoseconds.
  *
@@ -168,6 +173,7 @@ struct ptp_clock_info {
 	int pps;
 	struct ptp_pin_desc *pin_config;
 	int (*adjfine)(struct ptp_clock_info *ptp, long scaled_ppm);
+	int (*getfine)(struct ptp_clock_info *ptp, long *scaled_ppm);
 	int (*adjphase)(struct ptp_clock_info *ptp, s32 phase);
 	int (*adjtime)(struct ptp_clock_info *ptp, s64 delta);
 	int (*gettime64)(struct ptp_clock_info *ptp, struct timespec64 *ts);
-- 
2.36.2


  reply	other threads:[~2022-12-02 20:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-02 20:15 [PATCH net-next 0/2] ptp: Introduce .getfine callback to ptp_clock_info Rahul Rameshbabu
2022-12-02 20:15 ` Rahul Rameshbabu [this message]
2022-12-02 20:15 ` [PATCH net-next 2/2] net/mlx5: Implement ptp_clock_info .getfine function Rahul Rameshbabu
2022-12-03 10:06   ` kernel test robot
2022-12-03 11:06   ` kernel test robot
2022-12-02 20:45 ` [PATCH net-next 0/2] ptp: Introduce .getfine callback to ptp_clock_info Richard Cochran
2022-12-02 22:11   ` Jacob Keller

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=20221202201528.26634-2-rrameshbabu@nvidia.com \
    --to=rrameshbabu@nvidia.com \
    --cc=ayal@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gal@nvidia.com \
    --cc=jacob.e.keller@intel.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=saeedm@nvidia.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).