linux/drivers/net/can
Marc Kleine-Budde 2f4320f9f8 can: mcp251xfd: mcp251xfd_get_tef_len(): work around erratum DS80000789E 6.
commit 30447a1bc0 upstream.

Commit b8e0ddd36c ("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 index, the driver uses the TX-FIFO's tail index
instead, assuming that send frames are completed.

When calculating the number of unhandled TEF events, that commit
didn't take mcp2518fd erratum DS80000789E 6. into account. According
to that erratum, the FIFOCI bits of a FIFOSTA register, here the
TX-FIFO tail index might be corrupted.

However here it seems the bit indicating that the TX-FIFO is
empty (MCP251XFD_REG_FIFOSTA_TFERFFIF) is not correct while the
TX-FIFO tail index is.

Assume that the TX-FIFO is indeed empty if:
- Chip's head and tail index are equal (len == 0).
- The TX-FIFO is less than half full.
  (The TX-FIFO empty case has already been checked at the
   beginning of this function.)
- No free buffers in the TX ring.

If the TX-FIFO is assumed to be empty, assume that the TEF is full and
return the number of elements in the TX-FIFO (which equals the number
of TEF elements).

If these assumptions are false, the driver might read to many objects
from the TEF. mcp251xfd_handle_tefif_one() checks the sequence numbers
and will refuse to process old events.

Reported-by: Renjaya Raga Zenta <renjaya.zenta@formulatrix.com>
Closes: https://patch.msgid.link/CAJ7t6HgaeQ3a_OtfszezU=zB-FqiZXqrnATJ3UujNoQJJf7GgA@mail.gmail.com
Fixes: b8e0ddd36c ("can: mcp251xfd: tef: prepare to workaround broken TEF FIFO tail index erratum")
Tested-by: Renjaya Raga Zenta <renjaya.zenta@formulatrix.com>
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20241126-mcp251xfd-fix-length-calculation-v2-1-c2ed516ed6ba@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2024-12-14 20:03:21 +01:00
..
c_can can: c_can: c_can_handle_bus_err(): update statistics if skb allocation fails 2024-12-14 20:03:01 +01:00
cc770 can: {cc770,sja1000}_isa: allow building on x86_64 2024-11-04 17:46:06 +01:00
ctucanfd can: Switch back to struct platform_driver::remove() 2024-09-11 09:37:16 +02:00
dev can: dev: can_set_termination(): allow sleeping GPIOs 2024-12-14 20:03:21 +01:00
esd can: esd_402_pci: Add support for one-shot mode 2024-08-05 17:32:00 +02:00
flexcan can: Switch back to struct platform_driver::remove() 2024-09-11 09:37:16 +02:00
ifi_canfd can: ifi_canfd: ifi_canfd_handle_lec_err(): fix {rx,tx}_errors statistics 2024-12-14 20:03:01 +01:00
m_can can: m_can: m_can_handle_lec_err(): fix {rx,tx}_errors statistics 2024-12-14 20:03:01 +01:00
mscan can: Switch back to struct platform_driver::remove() 2024-09-11 09:37:16 +02:00
peak_canfd can: peak_canfd: Remove setting of RX software timestamp 2024-09-03 15:17:47 -07:00
rcar can: Switch back to struct platform_driver::remove() 2024-09-11 09:37:16 +02:00
rockchip can: rockchip_canfd: Drop obsolete dependency on COMPILE_TEST 2024-11-04 18:01:06 +01:00
sja1000 can: sja1000: sja1000_err(): fix {rx,tx}_errors statistics 2024-12-14 20:03:02 +01:00
slcan tty: use u8 for flags 2023-08-11 21:12:45 +02:00
softing can: Switch back to struct platform_driver::remove() 2024-09-11 09:37:16 +02:00
spi can: mcp251xfd: mcp251xfd_get_tef_len(): work around erratum DS80000789E 6. 2024-12-14 20:03:21 +01:00
usb can: f81604: f81604_handle_can_bus_errors(): fix {rx,tx}_errors statistics 2024-12-14 20:03:02 +01:00
at91_can.c can: Switch back to struct platform_driver::remove() 2024-09-11 09:37:16 +02:00
bxcan.c can: Switch back to struct platform_driver::remove() 2024-09-11 09:37:16 +02:00
can327.c tty: use u8 for flags 2023-08-11 21:12:45 +02:00
grcan.c can: Switch back to struct platform_driver::remove() 2024-09-11 09:37:16 +02:00
janz-ican3.c can: Switch back to struct platform_driver::remove() 2024-09-11 09:37:16 +02:00
Kconfig can: rockchip_canfd: add driver for Rockchip CAN-FD controller 2024-09-04 14:41:51 +02:00
kvaser_pciefd.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2024-09-15 09:13:19 -07:00
Makefile can: rockchip_canfd: add driver for Rockchip CAN-FD controller 2024-09-04 14:41:51 +02:00
sun4i_can.c can: sun4i_can: sun4i_can_err(): fix {rx,tx}_errors statistics 2024-12-14 20:03:02 +01:00
ti_hecc.c can: Switch back to struct platform_driver::remove() 2024-09-11 09:37:16 +02:00
vcan.c net: annotate writes on dev->mtu from ndo_change_mtu() 2024-05-07 16:19:14 -07:00
vxcan.c net: annotate writes on dev->mtu from ndo_change_mtu() 2024-05-07 16:19:14 -07:00
xilinx_can.c can: Switch back to struct platform_driver::remove() 2024-09-11 09:37:16 +02:00