From patchwork Tue Dec 5 23:44:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 13480876 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="M8H3jtUv" Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7250518F for ; Tue, 5 Dec 2023 15:44:32 -0800 (PST) Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3b8b0b75445so2985857b6e.1 for ; Tue, 05 Dec 2023 15:44:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1701819872; x=1702424672; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=hW8MgRradIV0Ywg57qCnG0TDgOYGr7awXQnEN+WL/k4=; b=M8H3jtUvpwHrAPQ6yAXjXgQkrpLTQVclZh87aIJN1ixy5lel1swBmfGl5Xs+qGLJ6o p4dYH4hxlPqUrGnbDRNr4g2oWzP6ol+BMgX3pGQ2+/EkG4dZ/fdI1iFsfrTZJcfHV6Vm 3kYhPjNVNIhSK/lT09BJFI4uevS2z/eCh9CWA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701819872; x=1702424672; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hW8MgRradIV0Ywg57qCnG0TDgOYGr7awXQnEN+WL/k4=; b=FTlrpvlHBstBxN2znOu50+AAVyGY/DXoDKnVxuS0cGc8HXDp8XRh6Cvq1N+kfoykt1 WuHGC1YU2A6quBZohM3r+cDjAW0eF4pWPNMkdAdeDpau+W3ZyXPJPoaDSbEiaFgkpyeV +uqP7mrHdet8ZI8/7ls5rCeYctZbzdmvQmOBQkOFwOBiAuPY6+DkqfzV1tyDzwLiPBMX T4kCe3SBkVs2kuP6dYmcoRnZAbUUdPlvmEqf3wHVX7lIE5OBrRyO4/MpJtJmj1gR+WW4 TNLAqoPUnvKBAwz/qectMZDCqg0yfDeZ9u070I43d9o4Glg/+nmvOF8RpaYZgE7UkBpa HC3g== X-Gm-Message-State: AOJu0Yy07wIQ05EYI1TTr8Z/bRQtqDdNpPmdlcTdt4M1KSR2i5crOV94 oONIO0De4vHH7uGhfLerzJnT1Q== X-Google-Smtp-Source: AGHT+IEIk4lcAK1oYzKM3DrZrBmVkMQ4k7v4goz89KJtd5rcw7kK0t/c6G4cl7W5r5qlu+Dk6pmGmQ== X-Received: by 2002:a05:6808:1401:b0:3b5:6599:ce4c with SMTP id w1-20020a056808140100b003b56599ce4cmr56161oiv.57.1701819871547; Tue, 05 Dec 2023 15:44:31 -0800 (PST) Received: from lvnvda5233.lvn.broadcom.net ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id y15-20020a37e30f000000b007788bb0ab8esm5450429qki.19.2023.12.05.15.44.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Dec 2023 15:44:30 -0800 (PST) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, gospo@broadcom.com, Andy Gospodarek , Pavan Chebbi Subject: [PATCH net 4/4] bnxt_en: Fix HWTSTAMP_FILTER_ALL packet timestamp logic Date: Tue, 5 Dec 2023 15:44:04 -0800 Message-Id: <20231205234404.17501-5-michael.chan@broadcom.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20231205234404.17501-1-michael.chan@broadcom.com> References: <20231205234404.17501-1-michael.chan@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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: 66ed81dcedc6 ("bnxt_en: Enable packet timestamping for all RX packets") Reviewed-by: Andy Gospodarek Reviewed-by: Pavan Chebbi Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 20 +++++++++++++++++--- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 8 +++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 16b7cf6b01a4..55ac281a9b06 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -1759,6 +1759,21 @@ static void bnxt_deliver_skb(struct bnxt *bp, struct bnxt_napi *bnapi, napi_gro_receive(&bnapi->napi, skb); } +static bool bnxt_rx_ts_valid(struct bnxt *bp, u32 flags, + struct rx_cmp_ext *rxcmp1, u32 *cmpl_ts) +{ + u32 ts = le32_to_cpu(rxcmp1->rx_cmp_timestamp); + + if (BNXT_PTP_RX_TS_VALID(flags)) + goto ts_valid; + if (!bp->ptp_all_rx_tstamp || !ts || !BNXT_ALL_RX_TS_VALID(flags)) + return false; + +ts_valid: + *cmpl_ts = ts; + return true; +} + /* returns the following: * 1 - 1 packet successfully received * 0 - successful TPA_START, packet not completed yet @@ -1784,6 +1799,7 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, struct sk_buff *skb; struct xdp_buff xdp; u32 flags, misc; + u32 cmpl_ts; void *data; int rc = 0; @@ -2006,10 +2022,8 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, } } - if (unlikely((flags & RX_CMP_FLAGS_ITYPES_MASK) == - RX_CMP_FLAGS_ITYPE_PTP_W_TS) || bp->ptp_all_rx_tstamp) { + if (bnxt_rx_ts_valid(bp, flags, rxcmp1, &cmpl_ts)) { if (bp->flags & BNXT_FLAG_CHIP_P5) { - u32 cmpl_ts = le32_to_cpu(rxcmp1->rx_cmp_timestamp); u64 ns, ts; if (!bnxt_get_rx_ts_p5(bp, &ts, cmpl_ts)) { diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.h b/drivers/net/ethernet/broadcom/bnxt/bnxt.h index e702dbc3e6b1..5b570058e1c9 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.h +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.h @@ -161,7 +161,7 @@ struct rx_cmp { #define RX_CMP_FLAGS_ERROR (1 << 6) #define RX_CMP_FLAGS_PLACEMENT (7 << 7) #define RX_CMP_FLAGS_RSS_VALID (1 << 10) - #define RX_CMP_FLAGS_UNUSED (1 << 11) + #define RX_CMP_FLAGS_PKT_METADATA_PRESENT (1 << 11) #define RX_CMP_FLAGS_ITYPES_SHIFT 12 #define RX_CMP_FLAGS_ITYPES_MASK 0xf000 #define RX_CMP_FLAGS_ITYPE_UNKNOWN (0 << 12) @@ -188,6 +188,12 @@ struct rx_cmp { __le32 rx_cmp_rss_hash; }; +#define BNXT_PTP_RX_TS_VALID(flags) \ + (((flags) & RX_CMP_FLAGS_ITYPES_MASK) == RX_CMP_FLAGS_ITYPE_PTP_W_TS) + +#define BNXT_ALL_RX_TS_VALID(flags) \ + !((flags) & RX_CMP_FLAGS_PKT_METADATA_PRESENT) + #define RX_CMP_HASH_VALID(rxcmp) \ ((rxcmp)->rx_cmp_len_flags_type & cpu_to_le32(RX_CMP_FLAGS_RSS_VALID))