Skip to content

Commit aa524b6

Browse files
jacob-kellerJeff Kirsher
authored andcommitted
e1000e: don't modify SYSTIM registers during SIOCSHWTSTAMP ioctl
The e1000e_config_hwtstamp function was incorrectly resetting the SYSTIM registers every time the ioctl was being run. If you happened to be running ptp4l and lost the PTP connect (removing cable, or blocking the UDP traffic for example), then ptp4l will eventually perform a restart which involves re-requesting timestamp settings. In e1000e this has the unfortunate and incorrect result of resetting SYSTIME to the kernel time. Since kernel time is usually in UTC, and PTP time is in TAI, this results in the leap second being re-applied. Fix this by extracting the SYSTIME reset out into its own function, e1000e_ptp_reset, which we call during reset to restore the hardware registers. This function will (a) restart the timecounter based on the new system time, (b) restore the previous PPB setting, and (c) restore the previous hwtstamp settings. In order to perform (b), I had to modify the adjfreq ptp function pointer to store the old delta each time it is called. This also has the side effect of restoring the correct base timinca register correctly. The driver does not need to explicitly zero the ptp_delta variable since the entire adapter structure comes zero-initialized. Reported-by: Brian Walsh <[email protected]> Signed-off-by: Jacob Keller <[email protected]> Tested-by: Brian Walsh <[email protected]> Tested-by: Aaron Brown <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent e10715d commit aa524b6

File tree

3 files changed

+55
-16
lines changed

3 files changed

+55
-16
lines changed

drivers/net/ethernet/intel/e1000e/e1000.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ struct e1000_adapter {
347347
struct ptp_clock *ptp_clock;
348348
struct ptp_clock_info ptp_clock_info;
349349
struct pm_qos_request pm_qos_req;
350+
s32 ptp_delta;
350351

351352
u16 eee_advert;
352353
};

drivers/net/ethernet/intel/e1000e/netdev.c

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3580,7 +3580,6 @@ static int e1000e_config_hwtstamp(struct e1000_adapter *adapter,
35803580
bool is_l4 = false;
35813581
bool is_l2 = false;
35823582
u32 regval;
3583-
s32 ret_val;
35843583

35853584
if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
35863585
return -EINVAL;
@@ -3719,16 +3718,6 @@ static int e1000e_config_hwtstamp(struct e1000_adapter *adapter,
37193718
er32(RXSTMPH);
37203719
er32(TXSTMPH);
37213720

3722-
/* Get and set the System Time Register SYSTIM base frequency */
3723-
ret_val = e1000e_get_base_timinca(adapter, &regval);
3724-
if (ret_val)
3725-
return ret_val;
3726-
ew32(TIMINCA, regval);
3727-
3728-
/* reset the ns time counter */
3729-
timecounter_init(&adapter->tc, &adapter->cc,
3730-
ktime_to_ns(ktime_get_real()));
3731-
37323721
return 0;
37333722
}
37343723

@@ -3884,6 +3873,53 @@ static void e1000_flush_desc_rings(struct e1000_adapter *adapter)
38843873
e1000_flush_rx_ring(adapter);
38853874
}
38863875

3876+
/**
3877+
* e1000e_systim_reset - reset the timesync registers after a hardware reset
3878+
* @adapter: board private structure
3879+
*
3880+
* When the MAC is reset, all hardware bits for timesync will be reset to the
3881+
* default values. This function will restore the settings last in place.
3882+
* Since the clock SYSTIME registers are reset, we will simply restore the
3883+
* cyclecounter to the kernel real clock time.
3884+
**/
3885+
static void e1000e_systim_reset(struct e1000_adapter *adapter)
3886+
{
3887+
struct ptp_clock_info *info = &adapter->ptp_clock_info;
3888+
struct e1000_hw *hw = &adapter->hw;
3889+
unsigned long flags;
3890+
u32 timinca;
3891+
s32 ret_val;
3892+
3893+
if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
3894+
return;
3895+
3896+
if (info->adjfreq) {
3897+
/* restore the previous ptp frequency delta */
3898+
ret_val = info->adjfreq(info, adapter->ptp_delta);
3899+
} else {
3900+
/* set the default base frequency if no adjustment possible */
3901+
ret_val = e1000e_get_base_timinca(adapter, &timinca);
3902+
if (!ret_val)
3903+
ew32(TIMINCA, timinca);
3904+
}
3905+
3906+
if (ret_val) {
3907+
dev_warn(&adapter->pdev->dev,
3908+
"Failed to restore TIMINCA clock rate delta: %d\n",
3909+
ret_val);
3910+
return;
3911+
}
3912+
3913+
/* reset the systim ns time counter */
3914+
spin_lock_irqsave(&adapter->systim_lock, flags);
3915+
timecounter_init(&adapter->tc, &adapter->cc,
3916+
ktime_to_ns(ktime_get_real()));
3917+
spin_unlock_irqrestore(&adapter->systim_lock, flags);
3918+
3919+
/* restore the previous hwtstamp configuration settings */
3920+
e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config);
3921+
}
3922+
38873923
/**
38883924
* e1000e_reset - bring the hardware into a known good state
38893925
*
@@ -4063,8 +4099,8 @@ void e1000e_reset(struct e1000_adapter *adapter)
40634099

40644100
e1000e_reset_adaptive(hw);
40654101

4066-
/* initialize systim and reset the ns time counter */
4067-
e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config);
4102+
/* restore systim and hwtstamp settings */
4103+
e1000e_systim_reset(adapter);
40684104

40694105
/* Set EEE advertisement as appropriate */
40704106
if (adapter->flags2 & FLAG2_HAS_EEE) {
@@ -7239,6 +7275,9 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
72397275
adapter->eeprom_vers = 0;
72407276
}
72417277

7278+
/* init PTP hardware clock */
7279+
e1000e_ptp_init(adapter);
7280+
72427281
/* reset the hardware with the new settings */
72437282
e1000e_reset(adapter);
72447283

@@ -7257,9 +7296,6 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
72577296
/* carrier off reporting is important to ethtool even BEFORE open */
72587297
netif_carrier_off(netdev);
72597298

7260-
/* init PTP hardware clock */
7261-
e1000e_ptp_init(adapter);
7262-
72637299
e1000_print_device_info(adapter);
72647300

72657301
if (pci_dev_run_wake(pdev))

drivers/net/ethernet/intel/e1000e/ptp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ static int e1000e_phc_adjfreq(struct ptp_clock_info *ptp, s32 delta)
7979

8080
ew32(TIMINCA, timinca);
8181

82+
adapter->ptp_delta = delta;
83+
8284
spin_unlock_irqrestore(&adapter->systim_lock, flags);
8385

8486
return 0;

0 commit comments

Comments
 (0)