Skip to content

Commit 7f5515d

Browse files
Pavan Chebbidavem330
authored andcommitted
bnxt_en: Get the RX packet timestamp
If the RX packet is timestamped by the hardware, the RX completion record will contain the lower 32-bit of the timestamp. This needs to be combined with the upper 16-bit of the periodic timestamp that we get from the timer. The previous snapshot in ptp->old_timer is used to make sure that the snapshot is not ahead of the RX timestamp and we adjust for wrap-around if needed. v2: Make ptp->old_time read access safe on 32-bit CPUs. Reviewed-by: Edwin Peer <[email protected]> Signed-off-by: Pavan Chebbi <[email protected]> Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 390862f commit 7f5515d

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,9 +1709,9 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
17091709
u8 *data_ptr, agg_bufs, cmp_type;
17101710
dma_addr_t dma_addr;
17111711
struct sk_buff *skb;
1712+
u32 flags, misc;
17121713
void *data;
17131714
int rc = 0;
1714-
u32 misc;
17151715

17161716
rxcmp = (struct rx_cmp *)
17171717
&cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
@@ -1809,7 +1809,8 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
18091809
goto next_rx_no_len;
18101810
}
18111811

1812-
len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT;
1812+
flags = le32_to_cpu(rxcmp->rx_cmp_len_flags_type);
1813+
len = flags >> RX_CMP_LEN_SHIFT;
18131814
dma_addr = rx_buf->mapping;
18141815

18151816
if (bnxt_rx_xdp(bp, rxr, cons, data, &data_ptr, &len, event)) {
@@ -1886,6 +1887,24 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
18861887
}
18871888
}
18881889

1890+
if (unlikely((flags & RX_CMP_FLAGS_ITYPES_MASK) ==
1891+
RX_CMP_FLAGS_ITYPE_PTP_W_TS)) {
1892+
if (bp->flags & BNXT_FLAG_CHIP_P5) {
1893+
u32 cmpl_ts = le32_to_cpu(rxcmp1->rx_cmp_timestamp);
1894+
u64 ns, ts;
1895+
1896+
if (!bnxt_get_rx_ts_p5(bp, &ts, cmpl_ts)) {
1897+
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
1898+
1899+
spin_lock_bh(&ptp->ptp_lock);
1900+
ns = timecounter_cyc2time(&ptp->tc, ts);
1901+
spin_unlock_bh(&ptp->ptp_lock);
1902+
memset(skb_hwtstamps(skb), 0,
1903+
sizeof(*skb_hwtstamps(skb)));
1904+
skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(ns);
1905+
}
1906+
}
1907+
}
18891908
bnxt_deliver_skb(bp, bnapi, skb);
18901909
rc = 1;
18911910

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ struct rx_cmp {
159159
#define RX_CMP_FLAGS_RSS_VALID (1 << 10)
160160
#define RX_CMP_FLAGS_UNUSED (1 << 11)
161161
#define RX_CMP_FLAGS_ITYPES_SHIFT 12
162+
#define RX_CMP_FLAGS_ITYPES_MASK 0xf000
162163
#define RX_CMP_FLAGS_ITYPE_UNKNOWN (0 << 12)
163164
#define RX_CMP_FLAGS_ITYPE_IP (1 << 12)
164165
#define RX_CMP_FLAGS_ITYPE_TCP (2 << 12)
@@ -240,7 +241,7 @@ struct rx_cmp_ext {
240241
#define RX_CMPL_CFA_CODE_MASK (0xffff << 16)
241242
#define RX_CMPL_CFA_CODE_SFT 16
242243

243-
__le32 rx_cmp_unused3;
244+
__le32 rx_cmp_timestamp;
244245
};
245246

246247
#define RX_CMP_L2_ERRORS \

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,22 @@ static long bnxt_ptp_ts_aux_work(struct ptp_clock_info *ptp_info)
279279
return HZ;
280280
}
281281

282+
int bnxt_get_rx_ts_p5(struct bnxt *bp, u64 *ts, u32 pkt_ts)
283+
{
284+
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
285+
u64 time;
286+
287+
if (!ptp)
288+
return -ENODEV;
289+
290+
BNXT_READ_TIME64(ptp, time, ptp->old_time);
291+
*ts = (time & BNXT_HI_TIMER_MASK) | pkt_ts;
292+
if (pkt_ts < (time & BNXT_LO_TIMER_MASK))
293+
*ts += BNXT_LO_TIMER_MASK + 1;
294+
295+
return 0;
296+
}
297+
282298
void bnxt_ptp_start(struct bnxt *bp)
283299
{
284300
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,21 @@ struct bnxt_ptp_cfg {
5858
u32 refclk_mapped_regs[2];
5959
};
6060

61+
#if BITS_PER_LONG == 32
62+
#define BNXT_READ_TIME64(ptp, dst, src) \
63+
do { \
64+
spin_lock_bh(&(ptp)->ptp_lock); \
65+
(dst) = (src); \
66+
spin_unlock_bh(&(ptp)->ptp_lock); \
67+
} while (0)
68+
#else
69+
#define BNXT_READ_TIME64(ptp, dst, src) \
70+
((dst) = READ_ONCE(src))
71+
#endif
72+
6173
int bnxt_hwtstamp_set(struct net_device *dev, struct ifreq *ifr);
6274
int bnxt_hwtstamp_get(struct net_device *dev, struct ifreq *ifr);
75+
int bnxt_get_rx_ts_p5(struct bnxt *bp, u64 *ts, u32 pkt_ts);
6376
void bnxt_ptp_start(struct bnxt *bp);
6477
int bnxt_ptp_init(struct bnxt *bp);
6578
void bnxt_ptp_clear(struct bnxt *bp);

0 commit comments

Comments
 (0)