Skip to content

Commit 390862f

Browse files
Pavan Chebbidavem330
authored andcommitted
bnxt_en: Get the full 48-bit hardware timestamp periodically
From the bnxt_timer(), read the 48-bit hardware running clock periodically and store it in ptp->current_time. The previous snapshot of the clock will be stored in ptp->old_time. The old_time snapshot will be used in the next patches to compute the RX packet timestamps. v2: Use .do_aux_work() to read the timer periodically. Reviewed-by: Edwin Peer <edwin.peer@broadcom.com> Signed-off-by: Pavan Chebbi <pavan.chebbi@broadcom.com> Signed-off-by: Michael Chan <michael.chan@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 118612d commit 390862f

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10075,6 +10075,7 @@ static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
1007510075
}
1007610076
}
1007710077

10078+
bnxt_ptp_start(bp);
1007810079
rc = bnxt_init_nic(bp, irq_re_init);
1007910080
if (rc) {
1008010081
netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);

drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ static u64 bnxt_refclk_read(struct bnxt *bp, struct ptp_system_timestamp *sts)
4545
return ns;
4646
}
4747

48+
static void bnxt_ptp_get_current_time(struct bnxt *bp)
49+
{
50+
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
51+
52+
if (!ptp)
53+
return;
54+
spin_lock_bh(&ptp->ptp_lock);
55+
WRITE_ONCE(ptp->old_time, ptp->current_time);
56+
ptp->current_time = bnxt_refclk_read(bp, NULL);
57+
spin_unlock_bh(&ptp->ptp_lock);
58+
}
59+
4860
static int bnxt_ptp_gettimex(struct ptp_clock_info *ptp_info,
4961
struct timespec64 *ts,
5062
struct ptp_system_timestamp *sts)
@@ -257,6 +269,32 @@ static u64 bnxt_cc_read(const struct cyclecounter *cc)
257269
return bnxt_refclk_read(ptp->bp, NULL);
258270
}
259271

272+
static long bnxt_ptp_ts_aux_work(struct ptp_clock_info *ptp_info)
273+
{
274+
struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg,
275+
ptp_info);
276+
struct bnxt *bp = ptp->bp;
277+
278+
bnxt_ptp_get_current_time(bp);
279+
return HZ;
280+
}
281+
282+
void bnxt_ptp_start(struct bnxt *bp)
283+
{
284+
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
285+
286+
if (!ptp)
287+
return;
288+
289+
if (bp->flags & BNXT_FLAG_CHIP_P5) {
290+
spin_lock_bh(&ptp->ptp_lock);
291+
ptp->current_time = bnxt_refclk_read(bp, NULL);
292+
WRITE_ONCE(ptp->old_time, ptp->current_time);
293+
spin_unlock_bh(&ptp->ptp_lock);
294+
ptp_schedule_worker(ptp->ptp_clock, 0);
295+
}
296+
}
297+
260298
static const struct ptp_clock_info bnxt_ptp_caps = {
261299
.owner = THIS_MODULE,
262300
.name = "bnxt clock",
@@ -268,6 +306,7 @@ static const struct ptp_clock_info bnxt_ptp_caps = {
268306
.pps = 0,
269307
.adjfreq = bnxt_ptp_adjfreq,
270308
.adjtime = bnxt_ptp_adjtime,
309+
.do_aux_work = bnxt_ptp_ts_aux_work,
271310
.gettimex64 = bnxt_ptp_gettimex,
272311
.settime64 = bnxt_ptp_settime,
273312
.enable = bnxt_ptp_enable,

drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct bnxt_ptp_cfg {
6060

6161
int bnxt_hwtstamp_set(struct net_device *dev, struct ifreq *ifr);
6262
int bnxt_hwtstamp_get(struct net_device *dev, struct ifreq *ifr);
63+
void bnxt_ptp_start(struct bnxt *bp);
6364
int bnxt_ptp_init(struct bnxt *bp);
6465
void bnxt_ptp_clear(struct bnxt *bp);
6566
#endif

0 commit comments

Comments
 (0)