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
Subject: [PATCH v2 net-next 1/3] ptp_mock: Expose ptp_clock_info to external drivers
Date: Sun, 22 Feb 2026 10:41:08 +0100 [thread overview]
Message-ID: <20260222094110.127927-2-maciek@machnikowski.net> (raw)
In-Reply-To: <20260222094110.127927-1-maciek@machnikowski.net>
Allow exposing the ptp_clock_info of the ptp_mock to the external drivers.
Convert spinlocks to SLBH to allow gettime to be called from the netdevsim.
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>
Signed-off-by: Maciek Machnikowski <maciek@machnikowski.net>
---
drivers/ptp/ptp_mock.c | 22 ++++++++++++++--------
include/linux/ptp_mock.h | 5 +++++
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/drivers/ptp/ptp_mock.c b/drivers/ptp/ptp_mock.c
index bbd14ce24..84cfee4aa 100644
--- a/drivers/ptp/ptp_mock.c
+++ b/drivers/ptp/ptp_mock.c
@@ -54,10 +54,10 @@ static int mock_phc_adjfine(struct ptp_clock_info *info, long scaled_ppm)
adj = (s64)scaled_ppm << MOCK_PHC_FADJ_SHIFT;
adj = div_s64(adj, MOCK_PHC_FADJ_DENOMINATOR);
- spin_lock(&phc->lock);
+ spin_lock_bh(&phc->lock);
timecounter_read(&phc->tc);
phc->cc.mult = MOCK_PHC_CC_MULT + adj;
- spin_unlock(&phc->lock);
+ spin_unlock_bh(&phc->lock);
return 0;
}
@@ -66,9 +66,9 @@ static int mock_phc_adjtime(struct ptp_clock_info *info, s64 delta)
{
struct mock_phc *phc = info_to_phc(info);
- spin_lock(&phc->lock);
+ spin_lock_bh(&phc->lock);
timecounter_adjtime(&phc->tc, delta);
- spin_unlock(&phc->lock);
+ spin_unlock_bh(&phc->lock);
return 0;
}
@@ -79,9 +79,9 @@ static int mock_phc_settime64(struct ptp_clock_info *info,
struct mock_phc *phc = info_to_phc(info);
u64 ns = timespec64_to_ns(ts);
- spin_lock(&phc->lock);
+ spin_lock_bh(&phc->lock);
timecounter_init(&phc->tc, &phc->cc, ns);
- spin_unlock(&phc->lock);
+ spin_unlock_bh(&phc->lock);
return 0;
}
@@ -91,9 +91,9 @@ static int mock_phc_gettime64(struct ptp_clock_info *info, struct timespec64 *ts
struct mock_phc *phc = info_to_phc(info);
u64 ns;
- spin_lock(&phc->lock);
+ spin_lock_bh(&phc->lock);
ns = timecounter_read(&phc->tc);
- spin_unlock(&phc->lock);
+ spin_unlock_bh(&phc->lock);
*ts = ns_to_timespec64(ns);
@@ -171,5 +171,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 72eb40103..e33188dec 100644
--- a/include/linux/ptp_mock.h
+++ b/include/linux/ptp_mock.h
@@ -16,6 +16,7 @@ struct mock_phc;
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 +34,10 @@ 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.53.0
next prev parent reply other threads:[~2026-02-23 12:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-22 9:41 [PATCH v2 net-next 0/3] Implement PTP support in netdevsim Maciek Machnikowski
2026-02-22 9:41 ` Maciek Machnikowski [this message]
2026-02-23 16:36 ` [PATCH v2 net-next 1/3] ptp_mock: Expose ptp_clock_info to external drivers Jakub Kicinski
2026-02-22 9:41 ` [PATCH v2 net-next 2/3] netdevsim: Implement basic ptp support Maciek Machnikowski
2026-02-22 9:41 ` [PATCH v2 net-next 3/3] selftests:net: Implement ptp4l sync test using netdevsim Maciek Machnikowski
2026-02-24 10:54 ` Simon Horman
2026-02-25 10:08 ` 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=20260222094110.127927-2-maciek@machnikowski.net \
--to=maciek@machnikowski.net \
--cc=andrew@lunn.ch \
--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