* [PATCH net 0/1] pull-request: can 2026-12-02
@ 2026-12-02 16:59 Marc Kleine-Budde
2026-12-02 16:59 ` [PATCH net] can: mcp251x: deliver the TX echo before RX frames of the same pass Marc Kleine-Budde
0 siblings, 1 reply; 3+ messages in thread
From: Marc Kleine-Budde @ 2026-12-02 16:59 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, linux-can, kernel, Vincent Mailhol
Hello netdev-team,
this is a pull request of 1 patch for net/main.
Nguyen Cong Thanh's patch corrects the order of the RX and TX
completion, which is critical in CAN networks. This effectively
fixes the CAN-ISO-TP protocol when used in conjunction with an
STM32 bootloader peer.
regards,
Marc
===
The following changes since commit c1c39137dcc3134010566ff29a81c93124efa539:
net: don't leave napi->timer queued when deleting a napi (2026-12-02 17:35:50 +0100)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git tags/linux-can-fixes-for-7.4-20261202
for you to fetch changes up to 73d308830c6f624695c4a69991e01605d8ce4205:
can: mcp251x: deliver the TX echo before RX frames of the same pass (2026-12-02 17:51:42 +0100)
----------------------------------------------------------------
linux-can-fixes-for-7.4-20261202
----------------------------------------------------------------
Nguyen Cong Thanh (1):
can: mcp251x: deliver the TX echo before RX frames of the same pass
drivers/net/can/spi/mcp251x.c | 36 ++++++++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 8 deletions(-)
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH net] can: mcp251x: deliver the TX echo before RX frames of the same pass
2026-12-02 16:59 [PATCH net 0/1] pull-request: can 2026-12-02 Marc Kleine-Budde
@ 2026-12-02 16:59 ` Marc Kleine-Budde
2026-12-03 10:20 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 3+ messages in thread
From: Marc Kleine-Budde @ 2026-12-02 16:59 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-can, kernel, Vincent Mailhol,
Nguyen Cong Thanh, stable, Marc Kleine-Budde
From: Nguyen Cong Thanh <congthanh.ml.2509@gmail.com>
mcp251x_can_ist() hands the frames of both receive buffers to the stack
first and returns the echo of a completed transmission only at the end
of the pass. When our frame has completed and the peer's reply is
already in a receive buffer, the reply reaches the stack before the echo
of the frame it answers. The handler returned the echo first until
commit bf66f3736a94 ("can: mcp251x: Move to threaded interrupts instead
of workqueues.") moved the receive buffers to the front of the loop.
Since commit 4b7fe92c0690 ("can: isotp: add local echo tx processing for
consecutive frames") can-isotp enters ISOTP_WAIT_FC only on the echo of
the last consecutive frame of a block, and isotp_rcv_fc() ignores a flow
control frame that arrives while the sender is still in ISOTP_SENDING.
With a non-zero block size and a peer that answers quickly, the transfer
stalls:
bus mcp251x_can_ist() can-isotp
CF 8 sent (TXIF)
FC in RXB0 (RX0IF)
read CANINTF
RX0: FC to the stack -> SENDING, FC ignored
TX: echo to the stack -> WAIT_FC
FC timeout after 1 s
Seen with an MCP2515 (SPI at 1 MHz, CAN at 500 kbit/s) on an RK3566
board talking to an STM32 bootloader that answers each block of
consecutive frames with a flow control frame (BS 8, STmin 5 ms). In
candump on the gateway the flow control frame came 0.27 ms before the
echo and the UDS download timed out. With this change, in the gateway's
candump captures of 25 downloads, all 5225 flow control frames sent
after a full block came after the echo of the frame they answer.
Return the echo whenever TXIF has been seen, before the receive buffers
that follow: at the start of the pass, and again after the CANINTF
re-read that follows RXB0, before RXB1. In the second case the frame in
RXB0 was there before our frame completed and still goes first, while a
reply that rolled over into RXB1 now comes after the echo. The MCP251x
has no RX timestamps, so the bus order of a completed transmission and
a frame received around the same time is unknown either way. A reply
can only come after our frame; the cost is that an unrelated frame
received just before it may now be delivered after the echo. The TX
block at the end of the pass only wakes the queue.
As a side effect, the echo of a completed frame is now also returned
when the pass ends in bus-off with restart-ms 0, where the loop used to
break out before the TX block.
Fixes: bf66f3736a94 ("can: mcp251x: Move to threaded interrupts instead of workqueues.")
Cc: stable@vger.kernel.org
Signed-off-by: Nguyen Cong Thanh <congthanh.ml.2509@gmail.com>
Link: https://patch.msgid.link/20261128054815.1586-1-congthanh.ml.2509@gmail.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/spi/mcp251x.c | 36 +++++++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 8 deletions(-)
diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c
index 0d0190ae094a..0acdab0cd0af 100644
--- a/drivers/net/can/spi/mcp251x.c
+++ b/drivers/net/can/spi/mcp251x.c
@@ -1067,6 +1067,18 @@ static void mcp251x_restart_work_handler(struct work_struct *ws)
mutex_unlock(&priv->mcp_lock);
}
+static void mcp251x_tx_echo(struct mcp251x_priv *priv)
+{
+ struct net_device *net = priv->net;
+
+ if (!priv->tx_busy)
+ return;
+
+ net->stats.tx_packets++;
+ net->stats.tx_bytes += can_get_echo_skb(net, 0, NULL);
+ priv->tx_busy = false;
+}
+
static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
{
struct mcp251x_priv *priv = dev_id;
@@ -1082,6 +1094,14 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
mcp251x_read_2regs(spi, CANINTF, &intf, &eflag);
+ /* Return the echo of a completed transmission before the
+ * frames received in this pass. Without RX timestamps their
+ * bus order is unknown, but a reply to our frame, such as an
+ * ISO-TP flow control frame, can only follow it.
+ */
+ if (intf & CANINTF_TX)
+ mcp251x_tx_echo(priv);
+
/* receive buffer 0 */
if (intf & CANINTF_RX0IF) {
mcp251x_hw_rx(spi, 0);
@@ -1105,6 +1125,12 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
}
}
+ /* Our frame may have completed while RXB0 was read, with the
+ * reply rolled over into RXB1.
+ */
+ if (intf & CANINTF_TX)
+ mcp251x_tx_echo(priv);
+
/* receive buffer 1 */
if (intf & CANINTF_RX1IF) {
mcp251x_hw_rx(spi, 1);
@@ -1196,15 +1222,9 @@ static irqreturn_t mcp251x_can_ist(int irq, void *dev_id)
if (intf == 0)
break;
- if (intf & CANINTF_TX) {
- if (priv->tx_busy) {
- net->stats.tx_packets++;
- net->stats.tx_bytes += can_get_echo_skb(net, 0,
- NULL);
- priv->tx_busy = false;
- }
+ /* the echo has already been returned above */
+ if (intf & CANINTF_TX)
netif_wake_queue(net);
- }
}
mutex_unlock(&priv->mcp_lock);
return IRQ_HANDLED;
base-commit: c1c39137dcc3134010566ff29a81c93124efa539
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] can: mcp251x: deliver the TX echo before RX frames of the same pass
2026-12-02 16:59 ` [PATCH net] can: mcp251x: deliver the TX echo before RX frames of the same pass Marc Kleine-Budde
@ 2026-12-03 10:20 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-12-03 10:20 UTC (permalink / raw)
To: Marc Kleine-Budde
Cc: netdev, davem, kuba, linux-can, kernel, mailhol,
congthanh.ml.2509, stable
Hello:
This patch was applied to netdev/net.git (main)
by Marc Kleine-Budde <mkl@pengutronix.de>:
On Wed, 2 Dec 2026 17:59:06 +0100 you wrote:
> From: Nguyen Cong Thanh <congthanh.ml.2509@gmail.com>
>
> mcp251x_can_ist() hands the frames of both receive buffers to the stack
> first and returns the echo of a completed transmission only at the end
> of the pass. When our frame has completed and the peer's reply is
> already in a receive buffer, the reply reaches the stack before the echo
> of the frame it answers. The handler returned the echo first until
> commit bf66f3736a94 ("can: mcp251x: Move to threaded interrupts instead
> of workqueues.") moved the receive buffers to the front of the loop.
>
> [...]
Here is the summary with links:
- [net] can: mcp251x: deliver the TX echo before RX frames of the same pass
https://git.kernel.org/netdev/net/c/73d308830c6f
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-03 10:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 16:59 [PATCH net 0/1] pull-request: can 2026-12-02 Marc Kleine-Budde
2026-12-02 16:59 ` [PATCH net] can: mcp251x: deliver the TX echo before RX frames of the same pass Marc Kleine-Budde
2026-12-03 10:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox