Skip to content

Commit 018ed23

Browse files
mlichvardavem330
authored andcommitted
ixgbe: 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 cff8ba2 commit 018ed23

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -443,22 +443,52 @@ static int ixgbe_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
443443
}
444444

445445
/**
446-
* ixgbe_ptp_gettime
446+
* ixgbe_ptp_gettimex
447447
* @ptp: the ptp clock structure
448-
* @ts: timespec structure to hold the current time value
448+
* @ts: timespec to hold the PHC timestamp
449+
* @sts: structure to hold the system time before and after reading the PHC
449450
*
450451
* read the timecounter and return the correct value on ns,
451452
* after converting it into a struct timespec.
452453
*/
453-
static int ixgbe_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
454+
static int ixgbe_ptp_gettimex(struct ptp_clock_info *ptp,
455+
struct timespec64 *ts,
456+
struct ptp_system_timestamp *sts)
454457
{
455458
struct ixgbe_adapter *adapter =
456459
container_of(ptp, struct ixgbe_adapter, ptp_caps);
460+
struct ixgbe_hw *hw = &adapter->hw;
457461
unsigned long flags;
458-
u64 ns;
462+
u64 ns, stamp;
459463

460464
spin_lock_irqsave(&adapter->tmreg_lock, flags);
461-
ns = timecounter_read(&adapter->hw_tc);
465+
466+
switch (adapter->hw.mac.type) {
467+
case ixgbe_mac_X550:
468+
case ixgbe_mac_X550EM_x:
469+
case ixgbe_mac_x550em_a:
470+
/* Upper 32 bits represent billions of cycles, lower 32 bits
471+
* represent cycles. However, we use timespec64_to_ns for the
472+
* correct math even though the units haven't been corrected
473+
* yet.
474+
*/
475+
ptp_read_system_prets(sts);
476+
IXGBE_READ_REG(hw, IXGBE_SYSTIMR);
477+
ptp_read_system_postts(sts);
478+
ts->tv_nsec = IXGBE_READ_REG(hw, IXGBE_SYSTIML);
479+
ts->tv_sec = IXGBE_READ_REG(hw, IXGBE_SYSTIMH);
480+
stamp = timespec64_to_ns(ts);
481+
break;
482+
default:
483+
ptp_read_system_prets(sts);
484+
stamp = IXGBE_READ_REG(hw, IXGBE_SYSTIML);
485+
ptp_read_system_postts(sts);
486+
stamp |= (u64)IXGBE_READ_REG(hw, IXGBE_SYSTIMH) << 32;
487+
break;
488+
}
489+
490+
ns = timecounter_cyc2time(&adapter->hw_tc, stamp);
491+
462492
spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
463493

464494
*ts = ns_to_timespec64(ns);
@@ -567,10 +597,14 @@ void ixgbe_ptp_overflow_check(struct ixgbe_adapter *adapter)
567597
{
568598
bool timeout = time_is_before_jiffies(adapter->last_overflow_check +
569599
IXGBE_OVERFLOW_PERIOD);
570-
struct timespec64 ts;
600+
unsigned long flags;
571601

572602
if (timeout) {
573-
ixgbe_ptp_gettime(&adapter->ptp_caps, &ts);
603+
/* Update the timecounter */
604+
spin_lock_irqsave(&adapter->tmreg_lock, flags);
605+
timecounter_read(&adapter->hw_tc);
606+
spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
607+
574608
adapter->last_overflow_check = jiffies;
575609
}
576610
}
@@ -1216,7 +1250,7 @@ static long ixgbe_ptp_create_clock(struct ixgbe_adapter *adapter)
12161250
adapter->ptp_caps.pps = 1;
12171251
adapter->ptp_caps.adjfreq = ixgbe_ptp_adjfreq_82599;
12181252
adapter->ptp_caps.adjtime = ixgbe_ptp_adjtime;
1219-
adapter->ptp_caps.gettime64 = ixgbe_ptp_gettime;
1253+
adapter->ptp_caps.gettimex64 = ixgbe_ptp_gettimex;
12201254
adapter->ptp_caps.settime64 = ixgbe_ptp_settime;
12211255
adapter->ptp_caps.enable = ixgbe_ptp_feature_enable;
12221256
adapter->ptp_setup_sdp = ixgbe_ptp_setup_sdp_x540;
@@ -1233,7 +1267,7 @@ static long ixgbe_ptp_create_clock(struct ixgbe_adapter *adapter)
12331267
adapter->ptp_caps.pps = 0;
12341268
adapter->ptp_caps.adjfreq = ixgbe_ptp_adjfreq_82599;
12351269
adapter->ptp_caps.adjtime = ixgbe_ptp_adjtime;
1236-
adapter->ptp_caps.gettime64 = ixgbe_ptp_gettime;
1270+
adapter->ptp_caps.gettimex64 = ixgbe_ptp_gettimex;
12371271
adapter->ptp_caps.settime64 = ixgbe_ptp_settime;
12381272
adapter->ptp_caps.enable = ixgbe_ptp_feature_enable;
12391273
break;
@@ -1249,7 +1283,7 @@ static long ixgbe_ptp_create_clock(struct ixgbe_adapter *adapter)
12491283
adapter->ptp_caps.pps = 0;
12501284
adapter->ptp_caps.adjfreq = ixgbe_ptp_adjfreq_X550;
12511285
adapter->ptp_caps.adjtime = ixgbe_ptp_adjtime;
1252-
adapter->ptp_caps.gettime64 = ixgbe_ptp_gettime;
1286+
adapter->ptp_caps.gettimex64 = ixgbe_ptp_gettimex;
12531287
adapter->ptp_caps.settime64 = ixgbe_ptp_settime;
12541288
adapter->ptp_caps.enable = ixgbe_ptp_feature_enable;
12551289
adapter->ptp_setup_sdp = NULL;

0 commit comments

Comments
 (0)