From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380182; b=cxkKhgAlOU0ngLUpq6FZY5VyE40vWkhcgLqjuKO9FnDfqudO/xkmpIpMe855e+DSxR3L nRAhOtIuuGSp6V5VLxZibK0JVrYLmnoa8g0ACaTBj/QmLIMUOrKvlrijCHxEUX47tCXdQ t3dTuwKItML+3F7rVSJ9Hp/BGUaPqaOx5uaEiUmT1Qzt0vkFV1yqNKAG8m3arsbePzOQb iuCAQ5YjORSQtOJZ/sMSFbyaAQ3e3pU1u0zMpWtyicoTOZHVtBZdujrLyzk+l7bYpYoWm p4L6GovpLZMto6+QQxpbgX4kYjzxoT3ydseh8A2CGlfh/2JkkNbmwP6mR9OnNzhSBIg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380182; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=aGPK0USs1ivgLonORlvoN/symPVv+dW5saTeDdgAxww=; b=P/3V2iC84SS2TiqOpKnnJlP4lYObK36qDXFnN7c6wzhc7gHxM1djCrvfYJQwqGkQHAWW Uj+HyJcee/hceJ0s4EEvK5yCkmNwQzptFaXFEOsc/LsiMFmIB2ftABFkhoBKlmhozVkv5 8PsXFW6ykpProUEor4L6Ya6ETFhvXoIcAg5YZjHaCeWSnnp+wVBox4jagpveDOrDJlUoO ltEJ0i/5/D5ouhvc51f2zQVpWzGY4jQwFqby4l15JmkoDKargPMGD8bj4JrCZ0kNvEaKN xKtEDmURC7Yp/tLVEVVUO4x+J27hyH855k578TtFu6+cuu1wzMW6cqd8GZBMnAap9zA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=vJLedgX3; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F576606A32D; Fri, 4 Dec 2026 10:29:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=vJLedgX3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92B121F000CE; Fri, 4 Dec 2026 10:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380182; bh=aGPK0USs1ivgLonORlvoN/symPVv+dW5saTeDdgAxww=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vJLedgX33QAVo0jq7NfSBKFC9RE5UakXd+xojp7iweAH2iiIDY8qg/gPSoaJpxs2W 8tYxXHrSRhfDElZ3Blcs/r11/qSazBPkJwlImS2p7DT4IJYLROBOrzm6DQUyb7iX6g BjeAe9S6YvKmRe1kqOhJGzsPjf/qMcl1NDxquIkI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexander Duyck , Jakub Kicinski , Sasha Levin Subject: [PATCH 7.3 135/742] fbnic: Wait for in-flight PTP timestamps before treating Tx as idle Date: Fri, 4 Dec 2026 18:59:59 +0900 Message-ID: <20261204100638.713489493@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexander Duyck [ Upstream commit 6ada0c2769666140dff8e808ff21e8f9544ddc99 ] The fbnic_wait_all_queues_idle function treats the Tx path as idle once the QM idle registers report every queue idle. Those registers do not cover the TMI completion path, so they can report idle while a PTP timestamp request is still outstanding in the MAC or queued in the TMI completion FIFO. The check can then pass without a flush, and the completion arrives after the rings have been flushed, where the fbnic_clean_tsq function either reports "Tx timestamp without matching packet" or, if the interface has come back up and a new timestamped frame is already waiting, matches the stale completion to that frame and hands an SO_TIMESTAMPING user the wrong Tx timestamp. After a forced flush it can also turn FBNIC_TMI_DROP_CTRL_CMPL_DIS back off before the queued completions have drained, as the completion FIFO is only drained while that bit is set. Split the Tx wait out into the fbnic_wait_tx_idle function and have its idle check require the TCE PTP in-flight count to read zero in addition to the QM idle registers. The count tracks each timestamp request from when its frame enters the TCE until its completion leaves the TMI completion FIFO, so the Tx path is only treated as idle once none are outstanding, and a forced flush keeps the completion disable set until they have drained. The Rx wait still checks only the QM idle registers. The count is printed with the other Tx idle registers on failure. Waiting on the in-flight count means the Tx idle check can now keep reading the full set of QM idle registers for the whole timeout, and the poll timeout only counts the delay between polls, not the time spent in the register reads. Raise the delay between polls of the Tx and Rx waits from 2us to 20us so the PCIe read latency stays a small part of each interval and the 500ms timeout stays close to wall time. Define the register inside the TCE CSR section and move FBNIC_CSR_END_TCE to the last register of the TCE block (0x040B4, TCE_SPARE2 in the CSR map), so that the ethtool register dump covers it. The section previously ended at 0x04050, short of the TXB, PTP and TCAM status registers. Per the CSR map, every register in the added range is read-only or read/write, so reading them for the dump has no side effects. A device that has dropped off the bus, or whose CSR access the driver has disabled after a failed read, reads all ones. The QM idle bits treat that as idle, and so does the in-flight check: the count is bounded by the timestamp requests the Tx path can hold and can never reach all ones, so teardown of a lost device, or during DPC recovery, does not wait out the idle timeouts. The issue was found by code review and confirmed against the RTL. Fixes: ad3d9f8bc66c ("eth: fbnic: add TX packets timestamping support") Fixes: 7d4568edce74 ("fbnic: Disable PTP completions during the Tx force-flush") Signed-off-by: Alexander Duyck Link: https://patch.msgid.link/179460248693.8819.282933709034208845.stgit@ahduyck-xeon-server.home.arpa Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/meta/fbnic/fbnic_csr.h | 3 +- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 73 ++++++++++++++++---- 2 files changed, 62 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_csr.h b/drivers/net/ethernet/meta/fbnic/fbnic_csr.h index 85ad53829bef8..d65dfb1d73329 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_csr.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_csr.h @@ -440,7 +440,8 @@ enum { #define FBNIC_TCE_TXB_NTWRK_DWRR_CTRL_EXT \ 0x0404E /* 0x10138 */ #define FBNIC_TCE_TXB_BMC_DWRR_CTRL_EXT 0x0404F /* 0x1013c */ -#define FBNIC_CSR_END_TCE 0x04050 /* CSR section delimiter */ +#define FBNIC_TCE_PTP_INFLIGHT 0x040A7 /* 0x1029c */ +#define FBNIC_CSR_END_TCE 0x040B4 /* CSR section delimiter */ /* TCE RAM registers */ #define FBNIC_CSR_START_TCE_RAM 0x04200 /* CSR section delimiter */ diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c index c869b88db81ac..17d75ec6e3342 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c @@ -2358,38 +2358,85 @@ static void fbnic_idle_dump(struct fbnic_dev *fbd, fbnic_rd32(fbd, regs[i].reg_base + j)); } -int fbnic_wait_all_queues_idle(struct fbnic_dev *fbd, bool may_fail) +/* The poll timeout only accounts for the delay between polls, not for + * the time spent in the poll itself, and each poll is a series of + * non-posted PCIe register reads that take on the order of a + * microsecond each. Space the polls out so that the reads stay a small + * part of each interval and the timeout stays close to wall time. + */ +#define FBNIC_IDLE_POLL_US 20 +#define FBNIC_IDLE_TIMEOUT_US 500000 + +static bool fbnic_tx_idle(struct fbnic_dev *fbd, + const struct fbnic_idle_regs *regs, + unsigned int nregs) +{ + u32 inflight; + + if (!fbnic_all_idle(fbd, regs, nregs)) + return false; + + /* The QM idle bits do not cover the TMI completion path, so a + * timestamp request can still be waiting on its completion. The + * count is bounded by the timestamp requests the Tx path can hold, + * so all ones is a failed read, as for the idle bits, not a count. + */ + inflight = fbnic_rd32(fbd, FBNIC_TCE_PTP_INFLIGHT); + + return !inflight || !~inflight; +} + +static int fbnic_wait_tx_idle(struct fbnic_dev *fbd) { static const struct fbnic_idle_regs tx[] = { { FBNIC_QM_TWQ_IDLE(0), FBNIC_QM_TWQ_IDLE_CNT, }, { FBNIC_QM_TQS_IDLE(0), FBNIC_QM_TQS_IDLE_CNT, }, { FBNIC_QM_TDE_IDLE(0), FBNIC_QM_TDE_IDLE_CNT, }, { FBNIC_QM_TCQ_IDLE(0), FBNIC_QM_TCQ_IDLE_CNT, }, - }, rx[] = { - { FBNIC_QM_HPQ_IDLE(0), FBNIC_QM_HPQ_IDLE_CNT, }, - { FBNIC_QM_PPQ_IDLE(0), FBNIC_QM_PPQ_IDLE_CNT, }, - { FBNIC_QM_RCQ_IDLE(0), FBNIC_QM_RCQ_IDLE_CNT, }, }; bool idle; int err; - err = read_poll_timeout_atomic(fbnic_all_idle, idle, idle, 2, 500000, - false, fbd, tx, ARRAY_SIZE(tx)); + err = read_poll_timeout_atomic(fbnic_tx_idle, idle, idle, + FBNIC_IDLE_POLL_US, + FBNIC_IDLE_TIMEOUT_US, false, + fbd, tx, ARRAY_SIZE(tx)); if (err == -ETIMEDOUT) { fbnic_tx_flush(fbd); - err = read_poll_timeout_atomic(fbnic_all_idle, idle, idle, - 2, 500000, false, + err = read_poll_timeout_atomic(fbnic_tx_idle, idle, idle, + FBNIC_IDLE_POLL_US, + FBNIC_IDLE_TIMEOUT_US, false, fbd, tx, ARRAY_SIZE(tx)); fbnic_tx_flush_off(fbd); } if (err) { fbnic_idle_dump(fbd, tx, ARRAY_SIZE(tx), "Tx", err); - if (may_fail) - return err; + netdev_err(fbd->netdev, "0x%04x: %08x\n", + FBNIC_TCE_PTP_INFLIGHT, + fbnic_rd32(fbd, FBNIC_TCE_PTP_INFLIGHT)); } - err = read_poll_timeout_atomic(fbnic_all_idle, idle, idle, 2, 500000, - false, fbd, rx, ARRAY_SIZE(rx)); + return err; +} + +int fbnic_wait_all_queues_idle(struct fbnic_dev *fbd, bool may_fail) +{ + static const struct fbnic_idle_regs rx[] = { + { FBNIC_QM_HPQ_IDLE(0), FBNIC_QM_HPQ_IDLE_CNT, }, + { FBNIC_QM_PPQ_IDLE(0), FBNIC_QM_PPQ_IDLE_CNT, }, + { FBNIC_QM_RCQ_IDLE(0), FBNIC_QM_RCQ_IDLE_CNT, }, + }; + bool idle; + int err; + + err = fbnic_wait_tx_idle(fbd); + if (err && may_fail) + return err; + + err = read_poll_timeout_atomic(fbnic_all_idle, idle, idle, + FBNIC_IDLE_POLL_US, + FBNIC_IDLE_TIMEOUT_US, false, + fbd, rx, ARRAY_SIZE(rx)); if (err) fbnic_idle_dump(fbd, rx, ARRAY_SIZE(rx), "Rx", err); return err; -- 2.53.0