Skip to content

Commit cff8ba2

Browse files
mlichvardavem330
authored andcommitted
igb: extend PTP gettime function to read system clock
This adds support for the PTP_SYS_OFFSET_EXTENDED ioctl. Cc: Richard Cochran <richardcochran@gmail.com> Cc: Jacob Keller <jacob.e.keller@intel.com> Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com> Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com> Acked-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 98942d7 commit cff8ba2

File tree

1 file changed

+55
-10
lines changed

1 file changed

+55
-10
lines changed

drivers/net/ethernet/intel/igb/igb_ptp.c

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,53 @@ static int igb_ptp_adjtime_i210(struct ptp_clock_info *ptp, s64 delta)
275275
return 0;
276276
}
277277

278-
static int igb_ptp_gettime_82576(struct ptp_clock_info *ptp,
279-
struct timespec64 *ts)
278+
static int igb_ptp_gettimex_82576(struct ptp_clock_info *ptp,
279+
struct timespec64 *ts,
280+
struct ptp_system_timestamp *sts)
280281
{
281282
struct igb_adapter *igb = container_of(ptp, struct igb_adapter,
282283
ptp_caps);
284+
struct e1000_hw *hw = &igb->hw;
283285
unsigned long flags;
286+
u32 lo, hi;
284287
u64 ns;
285288

286289
spin_lock_irqsave(&igb->tmreg_lock, flags);
287290

288-
ns = timecounter_read(&igb->tc);
291+
ptp_read_system_prets(sts);
292+
lo = rd32(E1000_SYSTIML);
293+
ptp_read_system_postts(sts);
294+
hi = rd32(E1000_SYSTIMH);
295+
296+
ns = timecounter_cyc2time(&igb->tc, ((u64)hi << 32) | lo);
297+
298+
spin_unlock_irqrestore(&igb->tmreg_lock, flags);
299+
300+
*ts = ns_to_timespec64(ns);
301+
302+
return 0;
303+
}
304+
305+
static int igb_ptp_gettimex_82580(struct ptp_clock_info *ptp,
306+
struct timespec64 *ts,
307+
struct ptp_system_timestamp *sts)
308+
{
309+
struct igb_adapter *igb = container_of(ptp, struct igb_adapter,
310+
ptp_caps);
311+
struct e1000_hw *hw = &igb->hw;
312+
unsigned long flags;
313+
u32 lo, hi;
314+
u64 ns;
315+
316+
spin_lock_irqsave(&igb->tmreg_lock, flags);
317+
318+
ptp_read_system_prets(sts);
319+
rd32(E1000_SYSTIMR);
320+
ptp_read_system_postts(sts);
321+
lo = rd32(E1000_SYSTIML);
322+
hi = rd32(E1000_SYSTIMH);
323+
324+
ns = timecounter_cyc2time(&igb->tc, ((u64)hi << 32) | lo);
289325

290326
spin_unlock_irqrestore(&igb->tmreg_lock, flags);
291327

@@ -294,16 +330,22 @@ static int igb_ptp_gettime_82576(struct ptp_clock_info *ptp,
294330
return 0;
295331
}
296332

297-
static int igb_ptp_gettime_i210(struct ptp_clock_info *ptp,
298-
struct timespec64 *ts)
333+
static int igb_ptp_gettimex_i210(struct ptp_clock_info *ptp,
334+
struct timespec64 *ts,
335+
struct ptp_system_timestamp *sts)
299336
{
300337
struct igb_adapter *igb = container_of(ptp, struct igb_adapter,
301338
ptp_caps);
339+
struct e1000_hw *hw = &igb->hw;
302340
unsigned long flags;
303341

304342
spin_lock_irqsave(&igb->tmreg_lock, flags);
305343

306-
igb_ptp_read_i210(igb, ts);
344+
ptp_read_system_prets(sts);
345+
rd32(E1000_SYSTIMR);
346+
ptp_read_system_postts(sts);
347+
ts->tv_nsec = rd32(E1000_SYSTIML);
348+
ts->tv_sec = rd32(E1000_SYSTIMH);
307349

308350
spin_unlock_irqrestore(&igb->tmreg_lock, flags);
309351

@@ -656,9 +698,12 @@ static void igb_ptp_overflow_check(struct work_struct *work)
656698
struct igb_adapter *igb =
657699
container_of(work, struct igb_adapter, ptp_overflow_work.work);
658700
struct timespec64 ts;
701+
u64 ns;
659702

660-
igb->ptp_caps.gettime64(&igb->ptp_caps, &ts);
703+
/* Update the timecounter */
704+
ns = timecounter_read(&igb->tc);
661705

706+
ts = ns_to_timespec64(ns);
662707
pr_debug("igb overflow check at %lld.%09lu\n",
663708
(long long) ts.tv_sec, ts.tv_nsec);
664709

@@ -1124,7 +1169,7 @@ void igb_ptp_init(struct igb_adapter *adapter)
11241169
adapter->ptp_caps.pps = 0;
11251170
adapter->ptp_caps.adjfreq = igb_ptp_adjfreq_82576;
11261171
adapter->ptp_caps.adjtime = igb_ptp_adjtime_82576;
1127-
adapter->ptp_caps.gettime64 = igb_ptp_gettime_82576;
1172+
adapter->ptp_caps.gettimex64 = igb_ptp_gettimex_82576;
11281173
adapter->ptp_caps.settime64 = igb_ptp_settime_82576;
11291174
adapter->ptp_caps.enable = igb_ptp_feature_enable;
11301175
adapter->cc.read = igb_ptp_read_82576;
@@ -1143,7 +1188,7 @@ void igb_ptp_init(struct igb_adapter *adapter)
11431188
adapter->ptp_caps.pps = 0;
11441189
adapter->ptp_caps.adjfine = igb_ptp_adjfine_82580;
11451190
adapter->ptp_caps.adjtime = igb_ptp_adjtime_82576;
1146-
adapter->ptp_caps.gettime64 = igb_ptp_gettime_82576;
1191+
adapter->ptp_caps.gettimex64 = igb_ptp_gettimex_82580;
11471192
adapter->ptp_caps.settime64 = igb_ptp_settime_82576;
11481193
adapter->ptp_caps.enable = igb_ptp_feature_enable;
11491194
adapter->cc.read = igb_ptp_read_82580;
@@ -1171,7 +1216,7 @@ void igb_ptp_init(struct igb_adapter *adapter)
11711216
adapter->ptp_caps.pin_config = adapter->sdp_config;
11721217
adapter->ptp_caps.adjfine = igb_ptp_adjfine_82580;
11731218
adapter->ptp_caps.adjtime = igb_ptp_adjtime_i210;
1174-
adapter->ptp_caps.gettime64 = igb_ptp_gettime_i210;
1219+
adapter->ptp_caps.gettimex64 = igb_ptp_gettimex_i210;
11751220
adapter->ptp_caps.settime64 = igb_ptp_settime_i210;
11761221
adapter->ptp_caps.enable = igb_ptp_feature_enable_i210;
11771222
adapter->ptp_caps.verify = igb_ptp_verify_pin;

0 commit comments

Comments
 (0)