Repository navigation
Description
Describe the bug
I am using a Waveshare 2-CH CAN FD HAT Rev2.1 with a Raspberry Pi 5 running Raspberry Pi OS. I have connected the CAN hat to a microcontroller that echoes anything back that is sent on the CAN bus.
The issue I am experiencing, is that messages aren't being received by candump (and socket read() in C) immediately. They are only received after several minutes or after sending multiple messages repeatedly.
I believe the messages might be stuck in a buffer/queue somewhere, as the hardware timestamps (see candump output below) indicates that messages are received at the expected time (but still not output until later).
Steps to reproduce the behaviour
Add the following to /boot/firmware/config.txt:
dtparam=spi=on
dtoverlay=spi1-3cs
dtoverlay=mcp251xfd,spi0-0,interrupt=25
dtoverlay=mcp251xfd,spi1-0,interrupt=24
Enable can0 interface:
sudo ip link set can0 up type can bitrate 1000000 dbitrate 2000000 berr-reporting on fd on
Send FDCAN messages using cansend:
cansend can0 234##31122334455667788
The following is the output of candump -xHt z can0 when executing cansend 8 times:
(000.000000) can0 TX B E 234 [08] 11 22 33 44 55 66 77 88 <─┬─ output after cansend executed 2 times
(001.676943) can0 TX B E 234 [08] 11 22 33 44 55 66 77 88 <─┘
(003.222309) can0 TX B E 234 [08] 11 22 33 44 55 66 77 88 <─┬─ output after cansend executed 4 times
(004.647527) can0 TX B E 234 [08] 11 22 33 44 55 66 77 88 <─┘
(006.132512) can0 TX B E 234 [08] 11 22 33 44 55 66 77 88 <─┬─ output after cansend executed 6 times
(007.573627) can0 TX B E 234 [08] 11 22 33 44 55 66 77 88 <─┘
(000.000084) can0 RX B - 123 [08] 11 22 33 44 55 66 77 88 <─┬─ output after cansend executed 8 times
(001.677026) can0 RX B - 123 [08] 11 22 33 44 55 66 77 88 <─┤
(003.222393) can0 RX B - 123 [08] 11 22 33 44 55 66 77 88 <─┤
(004.647610) can0 RX B - 123 [08] 11 22 33 44 55 66 77 88 <─┤
(006.132595) can0 RX B - 123 [08] 11 22 33 44 55 66 77 88 <─┤
(007.573710) can0 RX B - 123 [08] 11 22 33 44 55 66 77 88 <─┤
(009.042939) can0 TX B E 234 [08] 11 22 33 44 55 66 77 88 <─┤
(009.043022) can0 RX B - 123 [08] 11 22 33 44 55 66 77 88 <─┤
(010.332677) can0 TX B E 234 [08] 11 22 33 44 55 66 77 88 <─┤
(010.332761) can0 RX B - 123 [08] 11 22 33 44 55 66 77 88 <─┘
The device with ID 0x234 is the Raspberry Pi, while the device with ID 0x123 is the microcontroller. I would expect to receive one line with TX followed by one line with RX for each time cansend is executed, but this is not case.
Device (s)
Raspberry Pi 5
System
$ cat /etc/rpi-issue
Raspberry Pi reference 2024-07-04
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 48efb5fc5485fafdc9de8ad481eb5c09e1182656, stage4
$ vcgencmd version
2024/09/23 14:02:56
Copyright (c) 2012 Broadcom
version 26826259 (release) (embedded)
$ uname -a
Linux rp5 6.6.54-v8-16k+ #1801 SMP PREEMPT Fri Oct 4 16:57:16 BST 2024 aarch64 GNU/Linux
Logs
$ sudo dmesg | grep -E "can|spi|mcp2"
[ 3.298649] spi_master spi0: will run message pump with realtime priority
[ 3.303718] mcp251xfd spi0.0 can0: MCP2518FD rev0.0 (-RX_INT -PLL -MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD o:40.00MHz c:40.00MHz m:20.00MHz rs:17.00MHz es:16.66MHz rf:17.00MHz ef:16.66MHz) successfully initialized.
[ 3.303954] spi_master spi1: will run message pump with realtime priority
[ 3.315472] mcp251xfd spi1.0 can1: MCP2518FD rev0.0 (-RX_INT -PLL -MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD o:40.00MHz c:40.00MHz m:20.00MHz rs:17.00MHz es:16.66MHz rf:17.00MHz ef:16.66MHz) successfully initialized.
[ 231.657637] can: controller area network core
[ 231.662426] can: raw protocol
$ ip -details link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
can <BERR-REPORTING,FD> state ERROR-WARNING (berr-counter tx 0 rx 102) restart-ms 0
bitrate 1000000 sample-point 0.750
tq 25 prop-seg 14 phase-seg1 15 phase-seg2 10 sjw 5 brp 1
mcp251xfd: tseg1 2..256 tseg2 1..128 sjw 1..128 brp 1..256 brp_inc 1
dbitrate 2000000 dsample-point 0.750
dtq 25 dprop-seg 7 dphase-seg1 7 dphase-seg2 5 dsjw 2 dbrp 1
mcp251xfd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..256 dbrp_inc 1
clock 40000000 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 parentbus spi parentdev spi0.0
Additional context
No response
Activity
vdh-robothania commentedon Oct 9, 2024
The issue is not present when using kernel 6.6.31. I haven't tried higher versions as I am experiencing the issue described in #6406
pelwell commentedon Oct 9, 2024
Try after
sudo rpi-update(but back up any important data first).vdh-robothania commentedon Oct 9, 2024
The issue is still present after doing
sudo rpi-update(it's using hash 73e104f32e69e17450c443ebdb8bc493c849c38d) and rebootingpelwell commentedon Oct 9, 2024
Thanks - it's probably another aspect of the recent batch of changes that led to neighbour issue #6406.
Do any messages appear in the kernel log at the same time as that delay?
vdh-robothania commentedon Oct 9, 2024
Using
sudo dmesg -w, no messages appear at the same time as the delaypelwell commentedon Oct 9, 2024
OK, so it's probably not the same as this related problem: #6406 (comment)
marckleinebudde commentedon Oct 9, 2024
Please compile https://github.com/linux-can/can-utils and run
sudo mcp251xfd-dump spi0.0after eachcansendand send me the output. Also include the output ofgrep spi /proc/interruptsafter each cansend.pelwell commentedon Oct 9, 2024
Compilation is really easy:
vdh-robothania commentedon Oct 9, 2024
output.zip
Here you go
marckleinebudde commentedon Oct 9, 2024
Have you configured RX or TX IRQ coalescing? Show me the output of
ethtool -g can0; ethtool -c can0;.vdh-robothania commentedon Oct 9, 2024
marckleinebudde commentedon Oct 9, 2024
The system behaves as configured. You get an RX-IRQ after 8 RX'ed frames:
You probably want to configure a timeout for the RX- and TX-IRQ, e.g. 10ms:
ethtool -C can0 rx-usecs-irq 10000 rx-frames-irq 8 tx-usecs-irq 10000 tx-frames-irq 2.vdh-robothania commentedon Oct 9, 2024
Thanks, that seems to be the issue. The values of
tx-frames-irqandrx-frames-irqis set to 1 at boot, but automatically changes to 2 and 8 when executingsudo ip link set can0 up type can bitrate 1000000 dbitrate 2000000 berr-reporting on fd on.I can set them back to 1 by setting the interface down, followed by
sudo ethtool -C can0 rx-frames-irq 1 tx-frames-irq 1andsudo ip link set can0 up type can bitrate 1000000 dbitrate 2000000 berr-reporting on fd on.I just find it strange that the values stay as they are the second time I enable the interface, while they change the first time.
marckleinebudde commentedon Oct 9, 2024
There is probably some 3rd program setting these values. You can add the following to the driver to generate a dump when someone sets the coalescing parameters. The stack strace should contain the program who called this.
pelwell commentedon Oct 9, 2024
Is that consistent with it being a configuration issue? Do older kernels ignore the configuration?
40 remaining items
can: mcp251xfd: mcp251xfd_ring_alloc(): fix coalescing configuration …
can: mcp251xfd: mcp251xfd_ring_alloc(): fix coalescing configuration …
can: mcp251xfd: mcp251xfd_ring_alloc(): fix coalescing configuration …
UPSTREAM: can: mcp251xfd: mcp251xfd_ring_alloc(): fix coalescing conf…
can: mcp251xfd: mcp251xfd_ring_alloc(): fix coalescing configuration …
can: mcp251xfd: mcp251xfd_ring_alloc(): fix coalescing configuration …
can: mcp251xfd: mcp251xfd_ring_alloc(): fix coalescing configuration …
can: mcp251xfd: mcp251xfd_ring_alloc(): fix coalescing configuration …
can: mcp251xfd: mcp251xfd_ring_alloc(): fix coalescing configuration …
can: mcp251xfd: mcp251xfd_ring_alloc(): fix coalescing configuration …
can: mcp251xfd: mcp251xfd_ring_alloc(): fix coalescing configuration …
can: mcp251xfd: mcp251xfd_ring_alloc(): fix coalescing configuration …
can: mcp251xfd: mcp251xfd_ring_alloc(): fix coalescing configuration …
can: mcp251xfd: mcp251xfd_ring_alloc(): fix coalescing configuration …
can: mcp251xfd: mcp251xfd_ring_alloc(): fix coalescing configuration …