Skip to content

Commit 3c1c185

Browse files
can: mcp251xfd: mcp251xfd_get_tef_len(): fix length calculation
Commit b8e0ddd ("can: mcp251xfd: tef: prepare to workaround broken TEF FIFO tail index erratum") introduced mcp251xfd_get_tef_len() to get the number of unhandled transmit events from the Transmit Event FIFO (TEF). As the TEF has no head pointer, the driver uses the TX FIFO's tail pointer instead, assuming that send frames are completed. However the check for the TEF being full was not correct. This leads to the driver stop working if the TEF is full. Fix the TEF full check by assuming that if, from the driver's point of view, there are no free TX buffers in the chip and the TX FIFO is empty, all messages must have been sent and the TEF must therefore be full. Reported-by: Sven Schuchmann <[email protected]> Closes: https://patch.msgid.link/FR3P281MB155216711EFF900AD9791B7ED9692@FR3P281MB1552.DEUP281.PROD.OUTLOOK.COM Fixes: b8e0ddd ("can: mcp251xfd: tef: prepare to workaround broken TEF FIFO tail index erratum") Tested-by: Sven Schuchmann <[email protected]> Cc: [email protected] Link: https://patch.msgid.link/20241104-mcp251xfd-fix-length-calculation-v3-1-608b6e7e2197@pengutronix.de Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent eb9a839 commit 3c1c185

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/net/can/spi/mcp251xfd/mcp251xfd-tef.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
#include "mcp251xfd.h"
1818

19-
static inline bool mcp251xfd_tx_fifo_sta_full(u32 fifo_sta)
19+
static inline bool mcp251xfd_tx_fifo_sta_empty(u32 fifo_sta)
2020
{
21-
return !(fifo_sta & MCP251XFD_REG_FIFOSTA_TFNRFNIF);
21+
return fifo_sta & MCP251XFD_REG_FIFOSTA_TFERFFIF;
2222
}
2323

2424
static inline int
@@ -122,7 +122,11 @@ mcp251xfd_get_tef_len(struct mcp251xfd_priv *priv, u8 *len_p)
122122
if (err)
123123
return err;
124124

125-
if (mcp251xfd_tx_fifo_sta_full(fifo_sta)) {
125+
/* If the chip says the TX-FIFO is empty, but there are no TX
126+
* buffers free in the ring, we assume all have been sent.
127+
*/
128+
if (mcp251xfd_tx_fifo_sta_empty(fifo_sta) &&
129+
mcp251xfd_get_tx_free(tx_ring) == 0) {
126130
*len_p = tx_ring->obj_num;
127131
return 0;
128132
}

0 commit comments

Comments
 (0)