From: Maciek Machnikowski <maciek@machnikowski.net>
To: netdev@vger.kernel.org
Cc: kuba@kernel.org, maciek@machnikowski.net,
richardcochran@gmail.com, milena.olech@intel.com,
willemdebruijn.kernel@gmail.com, andrew@lunn.ch,
vadim.fedorenko@linux.dev, horms@kernel.org,
almasrymina@google.com
Subject: [PATCH v12 net-next 1/3] ptp_mock: Expose ptp_clock_info to external drivers
Date: Sun, 8 Nov 2026 21:15:01 +0100 [thread overview]
Message-ID: <20261108201503.85000-2-maciek@machnikowski.net> (raw)
In-Reply-To: <20261108201503.85000-1-maciek@machnikowski.net>
Allow exposing the ptp_clock_info of the ptp_mock to the external drivers.
Use spin_lock_irqsave() in the PHC callbacks to allow gettime to be called
from the netdevsim transmit path.
This is a prerequisite for implementing ptp support on netdevsim.
Co-developed-by: Milena Olech <milena.olech@intel.com>
Signed-off-by: Milena Olech <milena.olech@intel.com>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Reviewed-by: Mina Almasry <almasrymina@google.com>
Signed-off-by: Maciek Machnikowski <maciek@machnikowski.net>
---
drivers/ptp/ptp_mock.c | 26 ++++++++++++++++++--------
include/linux/ptp_mock.h | 7 +++++++
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/drivers/ptp/ptp_mock.c b/drivers/ptp/ptp_mock.c
index 4d66b6147121..7a4e5f3274a6 100644
--- a/drivers/ptp/ptp_mock.c
+++ b/drivers/ptp/ptp_mock.c
@@ -49,15 +49,16 @@ static u64 mock_phc_cc_read(struct cyclecounter *cc)
static int mock_phc_adjfine(struct ptp_clock_info *info, long scaled_ppm)
{
struct mock_phc *phc = info_to_phc(info);
+ unsigned long flags;
s64 adj;
adj = (s64)scaled_ppm << MOCK_PHC_FADJ_SHIFT;
adj = div_s64(adj, MOCK_PHC_FADJ_DENOMINATOR);
- spin_lock(&phc->lock);
+ spin_lock_irqsave(&phc->lock, flags);
timecounter_read(&phc->tc);
phc->cc.mult = MOCK_PHC_CC_MULT + adj;
- spin_unlock(&phc->lock);
+ spin_unlock_irqrestore(&phc->lock, flags);
return 0;
}
@@ -65,10 +66,11 @@ static int mock_phc_adjfine(struct ptp_clock_info *info, long scaled_ppm)
static int mock_phc_adjtime(struct ptp_clock_info *info, s64 delta)
{
struct mock_phc *phc = info_to_phc(info);
+ unsigned long flags;
- spin_lock(&phc->lock);
+ spin_lock_irqsave(&phc->lock, flags);
timecounter_adjtime(&phc->tc, delta);
- spin_unlock(&phc->lock);
+ spin_unlock_irqrestore(&phc->lock, flags);
return 0;
}
@@ -78,10 +80,11 @@ static int mock_phc_settime64(struct ptp_clock_info *info,
{
struct mock_phc *phc = info_to_phc(info);
u64 ns = timespec64_to_ns(ts);
+ unsigned long flags;
- spin_lock(&phc->lock);
+ spin_lock_irqsave(&phc->lock, flags);
timecounter_init(&phc->tc, &phc->cc, ns);
- spin_unlock(&phc->lock);
+ spin_unlock_irqrestore(&phc->lock, flags);
return 0;
}
@@ -89,11 +92,12 @@ static int mock_phc_settime64(struct ptp_clock_info *info,
static int mock_phc_gettime64(struct ptp_clock_info *info, struct timespec64 *ts)
{
struct mock_phc *phc = info_to_phc(info);
+ unsigned long flags;
u64 ns;
- spin_lock(&phc->lock);
+ spin_lock_irqsave(&phc->lock, flags);
ns = timecounter_read(&phc->tc);
- spin_unlock(&phc->lock);
+ spin_unlock_irqrestore(&phc->lock, flags);
*ts = ns_to_timespec64(ns);
@@ -171,5 +175,11 @@ void mock_phc_destroy(struct mock_phc *phc)
}
EXPORT_SYMBOL_GPL(mock_phc_destroy);
+struct ptp_clock_info *mock_phc_get_ptp_info(struct mock_phc *phc)
+{
+ return &phc->info;
+}
+EXPORT_SYMBOL_GPL(mock_phc_get_ptp_info);
+
MODULE_DESCRIPTION("Mock-up PTP Hardware Clock driver");
MODULE_LICENSE("GPL");
diff --git a/include/linux/ptp_mock.h b/include/linux/ptp_mock.h
index 72eb401034d9..8f5d248db65c 100644
--- a/include/linux/ptp_mock.h
+++ b/include/linux/ptp_mock.h
@@ -10,12 +10,14 @@
struct device;
struct mock_phc;
+struct ptp_clock_info;
#if IS_ENABLED(CONFIG_PTP_1588_CLOCK_MOCK)
struct mock_phc *mock_phc_create(struct device *dev);
void mock_phc_destroy(struct mock_phc *phc);
int mock_phc_index(struct mock_phc *phc);
+struct ptp_clock_info *mock_phc_get_ptp_info(struct mock_phc *phc);
#else
@@ -33,6 +35,11 @@ static inline int mock_phc_index(struct mock_phc *phc)
return -1;
}
+static inline struct ptp_clock_info *mock_phc_get_ptp_info(struct mock_phc *phc)
+{
+ return NULL;
+}
+
#endif
#endif /* _PTP_MOCK_H_ */
--
2.56.0
next prev parent reply other threads:[~2026-11-08 20:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-08 20:15 [PATCH v12 net-next 0/3] Implement PTP support in netdevsim Maciek Machnikowski
2026-11-08 20:15 ` Maciek Machnikowski [this message]
2026-11-08 20:15 ` [PATCH v12 net-next 2/3] netdevsim: Implement basic ptp support Maciek Machnikowski
2026-11-09 12:42 ` Vadim Fedorenko
2026-11-09 20:28 ` netdev-bot+sashiko
2026-11-10 20:46 ` Maciek Machnikowski
2026-11-12 0:12 ` Jakub Kicinski
2026-11-12 0:11 ` Jakub Kicinski
2026-11-08 20:15 ` [PATCH v12 net-next 3/3] selftests: drivers/net: Implement ptp4l sync test using netdevsim Maciek Machnikowski
2026-11-09 3:24 ` Hangbin Liu
2026-11-09 12:42 ` Vadim Fedorenko
2026-11-09 20:28 ` netdev-bot+sashiko
2026-11-10 20:44 ` Maciek Machnikowski
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=20261108201503.85000-2-maciek@machnikowski.net \
--to=maciek@machnikowski.net \
--cc=almasrymina@google.com \
--cc=andrew@lunn.ch \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=milena.olech@intel.com \
--cc=netdev@vger.kernel.org \
--cc=richardcochran@gmail.com \
--cc=vadim.fedorenko@linux.dev \
--cc=willemdebruijn.kernel@gmail.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