Skip to contentSkip to conversation

socketCAN mcp2515 - rx buffer overflow

DISCUSSION Gianluca 2 participants 3 messages Mar 8, 2012 CAN network drivers

lore
Share & tools
lore

Gianluca

author
#0 lore raw

Hi All,
I'm using an embedded Armadeus evaluation board - apf51 - with the mcp2515 CAN controller (via spi) and linux 2.6.38.8.
As a preliminar test I tried to dump all the traffic on our CANbus running at 500Kb/s.
Apparently, everything works fine, I can see messages being captured without problems.
But if I enable the error reporting I can see different ERRORFRAME messages to be reported ('rx buffer overflow').

This is how I configure the interface:

modprobe can
modprobe can_dev
modprobe can_raw
modprobe mcp251x
ip link set can0 up type can bitrate 500000
ip link set can0 txqueuelen 20

This is the operation detail:

$ ip -details -statistics link show can0
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 20
    link/can 
    can state ERROR-ACTIVE restart-ms 0 
    bitrate 500000 sample-point 0.875 
    tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
    mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
    clock 8000000
    re-started bus-errors arbit-lost error-warn error-pass bus-off
    0          0          0          0          0          0         
    RX: bytes  packets  errors  dropped overrun mcast   
    13086      2308     213     0       213     0      
    TX: bytes  packets  errors  dropped carrier collsns 
    0          0        0       0       0       0      

dmesg output:

can: controller area network core (rev 20090105 abi 8)
NET: Registered protocol family 29
CAN device driver interface
can: raw protocol (rev 20090105)
PM: Adding info for No Bus:can0
mcp251x spi1.0: probed
mcp251x spi1.0: CNF: 0x00 0xb5 0x01
PM: Adding info for No Bus:vcs3
PM: Adding info for No Bus:vcsa3
eth0: no IPv6 routers present

This is an example of candump results:

candump -ta -d -e any,0:0,#FFFFFFFF

 (125.351573)  can0     15004  [2] 00 00
 (126.193767)  can0    400060  [4] FF FF 00 00
 (126.194163)  can0    600060  [4] FF FF 00 00
 (126.194469)  can0  20000004  [8] 00 01 00 00 00 00 00 00   ERRORFRAME
        controller-problem{rx-overflow}
 (126.194743)  can0    E00060  [4] FF FF 00 00
 (126.195018)  can0   1200060  [4] FF FF 00 00
 (126.195323)  can0   1800060  [4] FF FF 00 00
 (126.195567)  can0  20000004  [8] 00 01 00 00 00 00 00 00   ERRORFRAME
        controller-problem{rx-overflow}
 (126.195842)  can0      5067  [6] 01 00 00 00 00 00
 (126.196086)  can0   1A00060  [4] FF FF 00 00
 (126.196361)  can0  20000004  [8] 00 01 00 00 00 00 00 00   ERRORFRAME
        controller-problem{rx-overflow}
 (126.196635)  can0    200060  [4] FF FF 00 00
 (126.196818)  can0      D067  [6] 01 00 00 00 00 00
 (126.197093)  can0      F066  [6] 01 00 00 00 00 00
 (126.197337)  can0  20000004  [8] 00 01 00 00 00 00 00 00   ERRORFRAME
        controller-problem{rx-overflow}
 (126.197673)  can0      7067  [6] 01 00 00 00 00 00
 (126.197978)  can0      B067  [6] 01 00 00 00 00 00
 (126.198253)  can0     19066  [6] 01 00 00 00 00 00
 (126.198558)  can0     1B066  [6] 01 00 00 00 00 00
 (126.198894)  can0     11066  [6] 01 00 00 00 00 00
 (126.199168)  can0      3067  [6] 01 00 00 00 00 00
 (126.199443)  can0  20000004  [8] 00 01 00 00 00 00 00 00   ERRORFRAME
        controller-problem{rx-overflow}
 (126.199718)  can0     17066  [6] 01 00 00 00 00 00
 (126.199931)  can0     1D066  [6] 01 00 00 00 00 00
 (126.200328)  can0     1F066  [6] 01 00 00 00 00 00

^C$

Increasing the buffer size was not possible:

$ candump -r 200000 -ta -d -e any,0:0,#FFFFFFFF
The socket receive buffer size was adjusted due to /proc/sys/net/core/rmem_max.
$ cat /proc/sys/net/core/rmem_max 
108544

Thanks in advance,
Gianluca

#1 lore raw
Quoted 3 lines · Gianluca

Hi All,
I'm using an embedded Armadeus evaluation board - apf51 - with the mcp2515 CAN controller (via spi) and linux 2.6.38.8.

Using an SPI attached CAN controller is a really bad choice. Try is upgrading to mx53, which has as far as I know one or even two internal flexcan cores, an option for you? Another option is to attach a local bus capable controller like the SJA1000 to your CPU, or use an USB dongle or a PCMCIA card.

The next thing is the SPI driver on the (mainline) mx51. If I remember correctly the mainline kernel doesn't support DMA for the SPI driver yet. I don't know if the freescale kernel does. Depending on your kernel version there are some knobs to tune the PIO SPI driver, mainly to increase the priority of the SPI task.

Last but not least, there is a not yet mainlined improved version of the mcp2515 driver around.

regards, Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
author
#2 lore raw
Quoted 12 lines · Marc Kleine-Budde <mkl <at> pengutronix.de> writes:

Using an SPI attached CAN controller is a really bad choice. Try is upgrading to mx53, which has as far as I know one or even two internal flexcan cores, an option for you? Another option is to attach a local bus capable controller like the SJA1000 to your CPU, or use an USB dongle or a PCMCIA card.

The next thing is the SPI driver on the (mainline) mx51. If I remember correctly the mainline kernel doesn't support DMA for the SPI driver yet. I don't know if the freescale kernel does. Depending on your kernel version there are some knobs to tune the PIO SPI driver, mainly to increase the priority of the SPI task.

Quoted 4 lines

Last but not least, there is a not yet mainlined improved version of the mcp2515 driver around.

regards, Marc

Ok, it does not sound to be stable and safe solution. Maybe using the SJA1000 would be a better choice for our project. Thanks for the help.

Gianluca