Skip to content

Commit 525904a

Browse files
Michael Changregkh
authored andcommitted
bnxt_en: Fix HWTSTAMP_FILTER_ALL packet timestamp logic
[ Upstream commit c13e268 ] When the chip is configured to timestamp all receive packets, the timestamp in the RX completion is only valid if the metadata present flag is not set for packets received on the wire. In addition, internal loopback packets will never have a valid timestamp and the timestamp field will always be zero. We must exclude any 0 value in the timestamp field because there is no way to determine if it is a loopback packet or not. Add a new function bnxt_rx_ts_valid() to check for all timestamp valid conditions. Fixes: 66ed81d ("bnxt_en: Enable packet timestamping for all RX packets") Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com> Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com> Signed-off-by: Michael Chan <michael.chan@broadcom.com> Link: https://lore.kernel.org/r/20231208001658.14230-5-michael.chan@broadcom.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ac61251 commit 525904a

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,21 @@ static void bnxt_deliver_skb(struct bnxt *bp, struct bnxt_napi *bnapi,
17961796
napi_gro_receive(&bnapi->napi, skb);
17971797
}
17981798

1799+
static bool bnxt_rx_ts_valid(struct bnxt *bp, u32 flags,
1800+
struct rx_cmp_ext *rxcmp1, u32 *cmpl_ts)
1801+
{
1802+
u32 ts = le32_to_cpu(rxcmp1->rx_cmp_timestamp);
1803+
1804+
if (BNXT_PTP_RX_TS_VALID(flags))
1805+
goto ts_valid;
1806+
if (!bp->ptp_all_rx_tstamp || !ts || !BNXT_ALL_RX_TS_VALID(flags))
1807+
return false;
1808+
1809+
ts_valid:
1810+
*cmpl_ts = ts;
1811+
return true;
1812+
}
1813+
17991814
/* returns the following:
18001815
* 1 - 1 packet successfully received
18011816
* 0 - successful TPA_START, packet not completed yet
@@ -1821,6 +1836,7 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
18211836
struct sk_buff *skb;
18221837
struct xdp_buff xdp;
18231838
u32 flags, misc;
1839+
u32 cmpl_ts;
18241840
void *data;
18251841
int rc = 0;
18261842

@@ -2043,10 +2059,8 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
20432059
}
20442060
}
20452061

2046-
if (unlikely((flags & RX_CMP_FLAGS_ITYPES_MASK) ==
2047-
RX_CMP_FLAGS_ITYPE_PTP_W_TS) || bp->ptp_all_rx_tstamp) {
2062+
if (bnxt_rx_ts_valid(bp, flags, rxcmp1, &cmpl_ts)) {
20482063
if (bp->flags & BNXT_FLAG_CHIP_P5) {
2049-
u32 cmpl_ts = le32_to_cpu(rxcmp1->rx_cmp_timestamp);
20502064
u64 ns, ts;
20512065

20522066
if (!bnxt_get_rx_ts_p5(bp, &ts, cmpl_ts)) {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ struct rx_cmp {
160160
#define RX_CMP_FLAGS_ERROR (1 << 6)
161161
#define RX_CMP_FLAGS_PLACEMENT (7 << 7)
162162
#define RX_CMP_FLAGS_RSS_VALID (1 << 10)
163-
#define RX_CMP_FLAGS_UNUSED (1 << 11)
163+
#define RX_CMP_FLAGS_PKT_METADATA_PRESENT (1 << 11)
164164
#define RX_CMP_FLAGS_ITYPES_SHIFT 12
165165
#define RX_CMP_FLAGS_ITYPES_MASK 0xf000
166166
#define RX_CMP_FLAGS_ITYPE_UNKNOWN (0 << 12)
@@ -187,6 +187,12 @@ struct rx_cmp {
187187
__le32 rx_cmp_rss_hash;
188188
};
189189

190+
#define BNXT_PTP_RX_TS_VALID(flags) \
191+
(((flags) & RX_CMP_FLAGS_ITYPES_MASK) == RX_CMP_FLAGS_ITYPE_PTP_W_TS)
192+
193+
#define BNXT_ALL_RX_TS_VALID(flags) \
194+
!((flags) & RX_CMP_FLAGS_PKT_METADATA_PRESENT)
195+
190196
#define RX_CMP_HASH_VALID(rxcmp) \
191197
((rxcmp)->rx_cmp_len_flags_type & cpu_to_le32(RX_CMP_FLAGS_RSS_VALID))
192198

0 commit comments

Comments
 (0)