Skip to content

Commit 9911674

Browse files
committed
Merge branch 'ptp-ns_to_timespec64'
Richard Cochran says: ==================== ptp: remove open coded ns_to_timespec64 and reverse This patch series is a follow up to the recent timespec64 work for the PTP Hardware Clock drivers. Arnd noticed that drivers are using open coded implementations of ns_to_timespec64 and timespec64_to_ns. This series replaces the open coded logic with the helper functions. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents f6a69a8 + 0704fae commit 9911674

File tree

11 files changed

+20
-47
lines changed

11 files changed

+20
-47
lines changed

drivers/net/ethernet/adi/bfin_mac.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,6 @@ static int bfin_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
986986
static int bfin_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
987987
{
988988
u64 ns;
989-
u32 remainder;
990989
unsigned long flags;
991990
struct bfin_mac_local *lp =
992991
container_of(ptp, struct bfin_mac_local, caps);
@@ -997,8 +996,8 @@ static int bfin_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
997996

998997
spin_unlock_irqrestore(&lp->phc_lock, flags);
999998

1000-
ts->tv_sec = div_u64_rem(ns, 1000000000, &remainder);
1001-
ts->tv_nsec = remainder;
999+
*ts = ns_to_timespec64(ns);
1000+
10021001
return 0;
10031002
}
10041003

@@ -1010,8 +1009,7 @@ static int bfin_ptp_settime(struct ptp_clock_info *ptp,
10101009
struct bfin_mac_local *lp =
10111010
container_of(ptp, struct bfin_mac_local, caps);
10121011

1013-
ns = ts->tv_sec * 1000000000ULL;
1014-
ns += ts->tv_nsec;
1012+
ns = timespec64_to_ns(ts);
10151013

10161014
spin_lock_irqsave(&lp->phc_lock, flags);
10171015

drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13290,14 +13290,12 @@ static int bnx2x_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
1329013290
{
1329113291
struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
1329213292
u64 ns;
13293-
u32 remainder;
1329413293

1329513294
ns = timecounter_read(&bp->timecounter);
1329613295

1329713296
DP(BNX2X_MSG_PTP, "PTP gettime called, ns = %llu\n", ns);
1329813297

13299-
ts->tv_sec = div_u64_rem(ns, 1000000000ULL, &remainder);
13300-
ts->tv_nsec = remainder;
13298+
*ts = ns_to_timespec64(ns);
1330113299

1330213300
return 0;
1330313301
}
@@ -13308,8 +13306,7 @@ static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
1330813306
struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
1330913307
u64 ns;
1331013308

13311-
ns = ts->tv_sec * 1000000000ULL;
13312-
ns += ts->tv_nsec;
13309+
ns = timespec64_to_ns(ts);
1331313310

1331413311
DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
1331513312

drivers/net/ethernet/broadcom/tg3.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6220,16 +6220,14 @@ static int tg3_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
62206220
static int tg3_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
62216221
{
62226222
u64 ns;
6223-
u32 remainder;
62246223
struct tg3 *tp = container_of(ptp, struct tg3, ptp_info);
62256224

62266225
tg3_full_lock(tp, 0);
62276226
ns = tg3_refclk_read(tp);
62286227
ns += tp->ptp_adjust;
62296228
tg3_full_unlock(tp);
62306229

6231-
ts->tv_sec = div_u64_rem(ns, 1000000000, &remainder);
6232-
ts->tv_nsec = remainder;
6230+
*ts = ns_to_timespec64(ns);
62336231

62346232
return 0;
62356233
}

drivers/net/ethernet/freescale/fec_ptp.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,13 @@ static int fec_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
395395
struct fec_enet_private *adapter =
396396
container_of(ptp, struct fec_enet_private, ptp_caps);
397397
u64 ns;
398-
u32 remainder;
399398
unsigned long flags;
400399

401400
spin_lock_irqsave(&adapter->tmreg_lock, flags);
402401
ns = timecounter_read(&adapter->tc);
403402
spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
404403

405-
ts->tv_sec = div_u64_rem(ns, 1000000000ULL, &remainder);
406-
ts->tv_nsec = remainder;
404+
*ts = ns_to_timespec64(ns);
407405

408406
return 0;
409407
}
@@ -433,8 +431,7 @@ static int fec_ptp_settime(struct ptp_clock_info *ptp,
433431
return -EINVAL;
434432
}
435433

436-
ns = ts->tv_sec * 1000000000ULL;
437-
ns += ts->tv_nsec;
434+
ns = timespec64_to_ns(ts);
438435
/* Get the timer value based on timestamp.
439436
* Update the counter with the masked value.
440437
*/

drivers/net/ethernet/freescale/gianfar_ptp.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ static int ptp_gianfar_gettime(struct ptp_clock_info *ptp,
326326
struct timespec64 *ts)
327327
{
328328
u64 ns;
329-
u32 remainder;
330329
unsigned long flags;
331330
struct etsects *etsects = container_of(ptp, struct etsects, caps);
332331

@@ -336,8 +335,8 @@ static int ptp_gianfar_gettime(struct ptp_clock_info *ptp,
336335

337336
spin_unlock_irqrestore(&etsects->lock, flags);
338337

339-
ts->tv_sec = div_u64_rem(ns, 1000000000, &remainder);
340-
ts->tv_nsec = remainder;
338+
*ts = ns_to_timespec64(ns);
339+
341340
return 0;
342341
}
343342

@@ -348,8 +347,7 @@ static int ptp_gianfar_settime(struct ptp_clock_info *ptp,
348347
unsigned long flags;
349348
struct etsects *etsects = container_of(ptp, struct etsects, caps);
350349

351-
ns = ts->tv_sec * 1000000000ULL;
352-
ns += ts->tv_nsec;
350+
ns = timespec64_to_ns(ts);
353351

354352
spin_lock_irqsave(&etsects->lock, flags);
355353

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,13 @@ static int e1000e_phc_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
111111
struct e1000_adapter *adapter = container_of(ptp, struct e1000_adapter,
112112
ptp_clock_info);
113113
unsigned long flags;
114-
u32 remainder;
115114
u64 ns;
116115

117116
spin_lock_irqsave(&adapter->systim_lock, flags);
118117
ns = timecounter_read(&adapter->tc);
119118
spin_unlock_irqrestore(&adapter->systim_lock, flags);
120119

121-
ts->tv_sec = div_u64_rem(ns, NSEC_PER_SEC, &remainder);
122-
ts->tv_nsec = remainder;
120+
*ts = ns_to_timespec64(ns);
123121

124122
return 0;
125123
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,14 @@ static int igb_ptp_gettime_82576(struct ptp_clock_info *ptp,
290290
ptp_caps);
291291
unsigned long flags;
292292
u64 ns;
293-
u32 remainder;
294293

295294
spin_lock_irqsave(&igb->tmreg_lock, flags);
296295

297296
ns = timecounter_read(&igb->tc);
298297

299298
spin_unlock_irqrestore(&igb->tmreg_lock, flags);
300299

301-
ts->tv_sec = div_u64_rem(ns, 1000000000, &remainder);
302-
ts->tv_nsec = remainder;
300+
*ts = ns_to_timespec64(ns);
303301

304302
return 0;
305303
}
@@ -328,8 +326,7 @@ static int igb_ptp_settime_82576(struct ptp_clock_info *ptp,
328326
unsigned long flags;
329327
u64 ns;
330328

331-
ns = ts->tv_sec * 1000000000ULL;
332-
ns += ts->tv_nsec;
329+
ns = timespec64_to_ns(ts);
333330

334331
spin_lock_irqsave(&igb->tmreg_lock, flags);
335332

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,13 @@ static int ixgbe_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
284284
struct ixgbe_adapter *adapter =
285285
container_of(ptp, struct ixgbe_adapter, ptp_caps);
286286
u64 ns;
287-
u32 remainder;
288287
unsigned long flags;
289288

290289
spin_lock_irqsave(&adapter->tmreg_lock, flags);
291290
ns = timecounter_read(&adapter->tc);
292291
spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
293292

294-
ts->tv_sec = div_u64_rem(ns, 1000000000ULL, &remainder);
295-
ts->tv_nsec = remainder;
293+
*ts = ns_to_timespec64(ns);
296294

297295
return 0;
298296
}
@@ -313,8 +311,7 @@ static int ixgbe_ptp_settime(struct ptp_clock_info *ptp,
313311
u64 ns;
314312
unsigned long flags;
315313

316-
ns = ts->tv_sec * 1000000000ULL;
317-
ns += ts->tv_nsec;
314+
ns = timespec64_to_ns(ts);
318315

319316
/* reset the timecounter */
320317
spin_lock_irqsave(&adapter->tmreg_lock, flags);

drivers/net/ethernet/mellanox/mlx4/en_clock.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,13 @@ static int mlx4_en_phc_gettime(struct ptp_clock_info *ptp,
170170
struct mlx4_en_dev *mdev = container_of(ptp, struct mlx4_en_dev,
171171
ptp_clock_info);
172172
unsigned long flags;
173-
u32 remainder;
174173
u64 ns;
175174

176175
write_lock_irqsave(&mdev->clock_lock, flags);
177176
ns = timecounter_read(&mdev->clock);
178177
write_unlock_irqrestore(&mdev->clock_lock, flags);
179178

180-
ts->tv_sec = div_u64_rem(ns, NSEC_PER_SEC, &remainder);
181-
ts->tv_nsec = remainder;
179+
*ts = ns_to_timespec64(ns);
182180

183181
return 0;
184182
}

drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,14 @@ static int stmmac_get_time(struct ptp_clock_info *ptp, struct timespec64 *ts)
111111
container_of(ptp, struct stmmac_priv, ptp_clock_ops);
112112
unsigned long flags;
113113
u64 ns;
114-
u32 reminder;
115114

116115
spin_lock_irqsave(&priv->ptp_lock, flags);
117116

118117
ns = priv->hw->ptp->get_systime(priv->ioaddr);
119118

120119
spin_unlock_irqrestore(&priv->ptp_lock, flags);
121120

122-
ts->tv_sec = div_u64_rem(ns, 1000000000ULL, &reminder);
123-
ts->tv_nsec = reminder;
121+
*ts = ns_to_timespec64(ns);
124122

125123
return 0;
126124
}

0 commit comments

Comments
 (0)