Allow exposing the ptp_clock_info of the ptp_mock to the external drivers. Convert spinlocks to SLIS to allow gettime to be called from the netdevsim. This is a prerequisite for implementing ptp support on netdevsim. Co-developed-by: Milena Olech Signed-off-by: Milena Olech Signed-off-by: Maciek Machnikowski --- 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..8e48317b1 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_irqsave(&phc->lock); timecounter_read(&phc->tc); phc->cc.mult = MOCK_PHC_CC_MULT + adj; - spin_unlock(&phc->lock); + spin_unlock_irqsave(&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_irqsave(&phc->lock); timecounter_adjtime(&phc->tc, delta); - spin_unlock(&phc->lock); + spin_unlock_irqsave(&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_irqsave(&phc->lock); timecounter_init(&phc->tc, &phc->cc, ns); - spin_unlock(&phc->lock); + spin_unlock_irqsave(&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_irqsave(&phc->lock); ns = timecounter_read(&phc->tc); - spin_unlock(&phc->lock); + spin_unlock_irqsave(&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