Skip to content

mcp251xfd: candump not receiving messages immediately #6407

Closed

Description

@vdh-robothania

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

  1. vdh-robothania commented on Oct 9, 2024

    @vdh-robothania
    Author

    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

  2. pelwell commented on Oct 9, 2024

    @pelwell
    Contributor

    Try after sudo rpi-update (but back up any important data first).

  3. vdh-robothania commented on Oct 9, 2024

    @vdh-robothania
    Author

    The issue is still present after doing sudo rpi-update (it's using hash 73e104f32e69e17450c443ebdb8bc493c849c38d) and rebooting

  4. pelwell commented on Oct 9, 2024

    @pelwell
    Contributor

    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?

  5. vdh-robothania commented on Oct 9, 2024

    @vdh-robothania
    Author

    Using sudo dmesg -w, no messages appear at the same time as the delay

  6. pelwell commented on Oct 9, 2024

    @pelwell
    Contributor

    OK, so it's probably not the same as this related problem: #6406 (comment)

  7. marckleinebudde commented on Oct 9, 2024

    @marckleinebudde
    Contributor

    Please compile https://github.com/linux-can/can-utils and run sudo mcp251xfd-dump spi0.0 after each cansend and send me the output. Also include the output of grep spi /proc/interrupts after each cansend.

  8. pelwell commented on Oct 9, 2024

    @pelwell
    Contributor

    Compilation is really easy:

    git clone https://github.com/linux-can/can-utils.git
    make -C can-utils
    sudo make -C can-utils install
    
  9. vdh-robothania commented on Oct 9, 2024

    @vdh-robothania
    Author

    output.zip

    Here you go

  10. marckleinebudde commented on Oct 9, 2024

    @marckleinebudde
    Contributor

    Have you configured RX or TX IRQ coalescing? Show me the output of ethtool -g can0; ethtool -c can0;.

  11. vdh-robothania commented on Oct 9, 2024

    @vdh-robothania
    Author
    Ring parameters for can0:
    Pre-set maximums:
    RX:             24
    RX Mini:        n/a
    RX Jumbo:       n/a
    TX:             8
    Current hardware settings:
    RX:             20
    RX Mini:        n/a
    RX Jumbo:       n/a
    TX:             4
    RX Buf Len:             n/a
    CQE Size:               n/a
    TX Push:        off
    TCP data split: n/a
    Coalesce parameters for can0:
    Adaptive RX: n/a  TX: n/a
    stats-block-usecs: n/a
    sample-interval: n/a
    pkt-rate-low: n/a
    pkt-rate-high: n/a
    
    rx-usecs: n/a
    rx-frames: n/a
    rx-usecs-irq: 0
    rx-frames-irq: 8
    
    tx-usecs: n/a
    tx-frames: n/a
    tx-usecs-irq: 0
    tx-frames-irq: 2
    
    rx-usecs-low: n/a
    rx-frame-low: n/a
    tx-usecs-low: n/a
    tx-frame-low: n/a
    
    rx-usecs-high: n/a
    rx-frame-high: n/a
    tx-usecs-high: n/a
    tx-frame-high: n/a
    
    CQE mode RX: n/a  TX: n/a
    
  12. marckleinebudde commented on Oct 9, 2024

    @marckleinebudde
    Contributor

    The system behaves as configured. You get an RX-IRQ after 8 RX'ed frames:

    rx-frames-irq: 8
    

    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.

  13. vdh-robothania commented on Oct 9, 2024

    @vdh-robothania
    Author

    Thanks, that seems to be the issue. The values of tx-frames-irq and rx-frames-irq is set to 1 at boot, but automatically changes to 2 and 8 when executing sudo 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 1 and sudo 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.

  14. marckleinebudde commented on Oct 9, 2024

    @marckleinebudde
    Contributor

    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.

    --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-ethtool.c
    +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-ethtool.c
    @@ -96,6 +96,8 @@ static int mcp251xfd_ring_set_coalesce(struct net_device *ndev,
             };
             struct can_ram_layout layout;
     
    +        dump_stack();
    +
             can_ram_get_layout(&layout, &mcp251xfd_ram_config, &ring, ec, fd_mode);
     
             if ((layout.rx_coalesce != priv->rx_obj_num_coalesce_irq ||
  15. pelwell commented on Oct 9, 2024

    @pelwell
    Contributor

    The issue is not present when using kernel 6.6.31

    Is that consistent with it being a configuration issue? Do older kernels ignore the configuration?

  16. 40 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions