Commit 40c9b079 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by David S. Miller

net: igb: avoid using timespec

We want to deprecate the use of 'struct timespec' on 32-bit
architectures, as it is will overflow in 2038. The igb
driver uses it to read the current time, and can simply
be changed to use ktime_get_real_ts64() instead.

Because of hardware limitations, there is still an overflow
in year 2106, which we cannot really avoid, but this documents
the overflow.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Cc: intel-wired-lan@lists.osuosl.org
Reviewed-by: default avatarRichard Cochran <richardcochran@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0a624155
...@@ -444,8 +444,8 @@ struct igb_adapter { ...@@ -444,8 +444,8 @@ struct igb_adapter {
struct ptp_pin_desc sdp_config[IGB_N_SDP]; struct ptp_pin_desc sdp_config[IGB_N_SDP];
struct { struct {
struct timespec start; struct timespec64 start;
struct timespec period; struct timespec64 period;
} perout[IGB_N_PEROUT]; } perout[IGB_N_PEROUT];
char fw_version[32]; char fw_version[32];
......
...@@ -5392,7 +5392,7 @@ static void igb_tsync_interrupt(struct igb_adapter *adapter) ...@@ -5392,7 +5392,7 @@ static void igb_tsync_interrupt(struct igb_adapter *adapter)
{ {
struct e1000_hw *hw = &adapter->hw; struct e1000_hw *hw = &adapter->hw;
struct ptp_clock_event event; struct ptp_clock_event event;
struct timespec ts; struct timespec64 ts;
u32 ack = 0, tsauxc, sec, nsec, tsicr = rd32(E1000_TSICR); u32 ack = 0, tsauxc, sec, nsec, tsicr = rd32(E1000_TSICR);
if (tsicr & TSINTR_SYS_WRAP) { if (tsicr & TSINTR_SYS_WRAP) {
...@@ -5412,10 +5412,11 @@ static void igb_tsync_interrupt(struct igb_adapter *adapter) ...@@ -5412,10 +5412,11 @@ static void igb_tsync_interrupt(struct igb_adapter *adapter)
if (tsicr & TSINTR_TT0) { if (tsicr & TSINTR_TT0) {
spin_lock(&adapter->tmreg_lock); spin_lock(&adapter->tmreg_lock);
ts = timespec_add(adapter->perout[0].start, ts = timespec64_add(adapter->perout[0].start,
adapter->perout[0].period); adapter->perout[0].period);
/* u32 conversion of tv_sec is safe until y2106 */
wr32(E1000_TRGTTIML0, ts.tv_nsec); wr32(E1000_TRGTTIML0, ts.tv_nsec);
wr32(E1000_TRGTTIMH0, ts.tv_sec); wr32(E1000_TRGTTIMH0, (u32)ts.tv_sec);
tsauxc = rd32(E1000_TSAUXC); tsauxc = rd32(E1000_TSAUXC);
tsauxc |= TSAUXC_EN_TT0; tsauxc |= TSAUXC_EN_TT0;
wr32(E1000_TSAUXC, tsauxc); wr32(E1000_TSAUXC, tsauxc);
...@@ -5426,10 +5427,10 @@ static void igb_tsync_interrupt(struct igb_adapter *adapter) ...@@ -5426,10 +5427,10 @@ static void igb_tsync_interrupt(struct igb_adapter *adapter)
if (tsicr & TSINTR_TT1) { if (tsicr & TSINTR_TT1) {
spin_lock(&adapter->tmreg_lock); spin_lock(&adapter->tmreg_lock);
ts = timespec_add(adapter->perout[1].start, ts = timespec64_add(adapter->perout[1].start,
adapter->perout[1].period); adapter->perout[1].period);
wr32(E1000_TRGTTIML1, ts.tv_nsec); wr32(E1000_TRGTTIML1, ts.tv_nsec);
wr32(E1000_TRGTTIMH1, ts.tv_sec); wr32(E1000_TRGTTIMH1, (u32)ts.tv_sec);
tsauxc = rd32(E1000_TSAUXC); tsauxc = rd32(E1000_TSAUXC);
tsauxc |= TSAUXC_EN_TT1; tsauxc |= TSAUXC_EN_TT1;
wr32(E1000_TSAUXC, tsauxc); wr32(E1000_TSAUXC, tsauxc);
......
...@@ -143,7 +143,7 @@ static void igb_ptp_write_i210(struct igb_adapter *adapter, ...@@ -143,7 +143,7 @@ static void igb_ptp_write_i210(struct igb_adapter *adapter,
* sub-nanosecond resolution. * sub-nanosecond resolution.
*/ */
wr32(E1000_SYSTIML, ts->tv_nsec); wr32(E1000_SYSTIML, ts->tv_nsec);
wr32(E1000_SYSTIMH, ts->tv_sec); wr32(E1000_SYSTIMH, (u32)ts->tv_sec);
} }
/** /**
...@@ -479,7 +479,7 @@ static int igb_ptp_feature_enable_i210(struct ptp_clock_info *ptp, ...@@ -479,7 +479,7 @@ static int igb_ptp_feature_enable_i210(struct ptp_clock_info *ptp,
struct e1000_hw *hw = &igb->hw; struct e1000_hw *hw = &igb->hw;
u32 tsauxc, tsim, tsauxc_mask, tsim_mask, trgttiml, trgttimh, freqout; u32 tsauxc, tsim, tsauxc_mask, tsim_mask, trgttiml, trgttimh, freqout;
unsigned long flags; unsigned long flags;
struct timespec ts; struct timespec64 ts;
int use_freq = 0, pin = -1; int use_freq = 0, pin = -1;
s64 ns; s64 ns;
...@@ -523,14 +523,14 @@ static int igb_ptp_feature_enable_i210(struct ptp_clock_info *ptp, ...@@ -523,14 +523,14 @@ static int igb_ptp_feature_enable_i210(struct ptp_clock_info *ptp,
} }
ts.tv_sec = rq->perout.period.sec; ts.tv_sec = rq->perout.period.sec;
ts.tv_nsec = rq->perout.period.nsec; ts.tv_nsec = rq->perout.period.nsec;
ns = timespec_to_ns(&ts); ns = timespec64_to_ns(&ts);
ns = ns >> 1; ns = ns >> 1;
if (on && ns <= 70000000LL) { if (on && ns <= 70000000LL) {
if (ns < 8LL) if (ns < 8LL)
return -EINVAL; return -EINVAL;
use_freq = 1; use_freq = 1;
} }
ts = ns_to_timespec(ns); ts = ns_to_timespec64(ns);
if (rq->perout.index == 1) { if (rq->perout.index == 1) {
if (use_freq) { if (use_freq) {
tsauxc_mask = TSAUXC_EN_CLK1 | TSAUXC_ST1; tsauxc_mask = TSAUXC_EN_CLK1 | TSAUXC_ST1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment