Linux CAN driver
Introduction
This page gives an overview of Axi Can/ CANPS/ Axi CAN FD/ CANFD PS driver which is available as part of the xilinx Linux distribution or Open source linux as
drivers/net/can/xilinx_can.c
This information corresponds to the CAN driver that is the main branch of the Git tree.
This driver supports both ZYNQ CANPS IP and Soft IP axi_can and axi_canfd.
drivers/net/can/xilinx_can.c
This information corresponds to the CAN driver that is the main branch of the Git tree.
This driver supports both ZYNQ CANPS IP and Soft IP axi_can and axi_canfd.
This driver supports both ZYNQMP CANPS IP and Soft IP axi_can and axi_canfd.
This driver supports both Versal CANFD PS IP and Soft IP axi_can and axi_canfd.
This driver defines the architecture and features of the Xilinx CAN controller core.
The driver is available at,
https://github.com/Xilinx/linux-xlnx/blob/master/drivers/net/can/xilinx_can.c
the this driver.
CAN:
Attached the Cross compiled can-utils for the Microblaze and ARM(Cortexa9) architectures.
Microblaze Cross compiled CAN utils:
ARM(ZYNQ) cortexa9 Cross compiled CAN utils:
A53 Cross compiled CAN utils:
CANFD:
Xilinx CANFD hw supports this. The same linux can driver support this can fd feature
But to test this CANFD Support need to download canutils
from https://github.com/linux-can/can-utils
Microblaze Cross compiled CANUtils
ARM(ZYNQ) cortexa9 Cross compiled CAN utils:
To run CAN, use the below command:
1. Set bit-timing
Can supports bitrates upto 1Mb/s. Xilinx CAN h/w and driver supports these bit rates
Note: Triple sampling is not supported by Xilinx CAN H/W.
$ ./ip link set can0 type can bitrate 200000
or
$ ./canconfig can0 bitrate 200000
2. Bring up the device
$ ./ip link set can0 up
or
$ ./canconfig can0 start
3. Bring down the device
$ ./ip link set can0 down
or
$ ./canconfig can0 stop
4. Transmit and receive packets with standard id number
$ ./cansend can0 -i 0x14 <bytes>
$ ./candump can0
5. Transmit and receive packets with extended id number (--loop argument here)
$ ./cansend can0 -i 0x333 <bytes>
$ ./candump can0
6. Loopback mode
$ ./canconfig can0 ctrlmode loopback on
7. Checking link state (checking bitrate/errors/packets)
$ ./ip -d -s link show can0
8. Checking net device state
$ ifconfig can0
9. Getting statistics via proc
$ cat /proc/net/can/stats
10. Socket CAN core uses several filter lists to deliver received CAN frames to CAN protocol modules. These
receive lists, their filters and the count of filter matches can be checked in the appropriate receive list. All entries contain the
device and a protocol module identifier:
$ cat /proc/net/can/rcvlist_all
rcvlist_all - list for unfiltered entries (no filter operations)
rcvlist_eff - list for single extended frame (EFF) entries
rcvlist_err - list for error message frames masks
rcvlist_fil - list for mask/value filters
rcvlist_inv - list for mask/value filters (inverse semantic)
rcvlist_sff - list for single standard frame (SFF) entries
To run CANFD, use the below command:
1. Set bit-timing
Canfd supports two bitrates, one for Arbitration phase and other for Data phase. Xilinx CANFD h/w and driver supports these bit rates
$ ./ip link set can0 type can bitrate 125000 dbitrate 8000000 fd on
2. Bring up the device
$ ./ip link set can0 up
3. Bring down the device
$ ./ip link set can0 down
4. Transmit and receive canfd packets with standard id number
$ ./cansend can0 213##<bytes>
$ ./candump can0
5. Transmit and receive can packets with same controller, since canfd supports backward can also
$ ./cansend can0 123#<bytes>
$ ./candump can0
6. Loopback mode
$ ./ip link set can0 type can bitrate 125000 dbitrate 8000000 fd on looopback on
7. Checking link state (checking bitrate/errors/packets)
$ ./ip -d link show can0
8. Checking net device state
$ ifconfig can0
Binding Tests:
Microblaze:
a. correct binding with
XILINX_CAN e0008000.ps7-can: phy mem:0xe0008000..0xe0008fff
XILINX_CAN e0008000.ps7-can: reg_base=0xf0062000 irq=60 clock=23809523, tx fifo depth:64
b. Incorrect binding - tests suppose to fail
I. missing clocks
II. missing clock-names
III. missing register
IV. missing interrupt parent
V. missing interrupts number
Zynq:
a. correct binding with
b. Incorrect binding - tests suppose to fail (done on dummy nodes)
I. missing clocks
II. missing clock-names
III. missing register
IV. missing interrupt parent
V. missing interrupts number
This driver defines the architecture and features of the Xilinx CAN controller core.
HW/IP Features
CAN
- Conforms to the ISO 11898 -1, CAN 2.0A, and CAN2.0B standards
- Supports Industrial (I) and Extended TemperatureRange (Q) grade device support
- Supports both standard (11-bit identifier) andextended (29-bit identifier) frames
- Supports up to 1 Mbps
- Transmit message FIFO with a user-configurable depth of up to 64 messages
- Transmit prioritization through one High-Priority Transmit buffer
- Automatic re-transmission on errors or arbitration loss
- Receive message FIFO with a user- configurable depth of up to 64 messages
- Acceptance filtering (through a user-configurable number) of up to four acceptance filters
- Sleep Mode with automatic walk-up
- Loop Back Mode for diagnostic applications
- Maskable Error and Status Interrupts
- Readable Error Counters
CANFD
- Designed to ISO 11898-1/2015 specification
- Supports both CAN and CAN FD frames
- Supports the CAN FD frame format specified in the ISO 11898:2015 specification
- Supports up to 64 byte CAN FD frames
- Supports flexible data rates up to 8 Mb/s
- Supports nominal data rates up to 1 Mb/s
- Up to three data bit transmitter delay compensation
- TX and RX mailbox buffers with configurable depth
- Two 64-deep RX FIFOs with 32 ID Filter-Mask pairs
- Message with lowest ID transmitted first
- Supports TX message cancellation
- Separate error logging for fast data rate
- Timestamp for transmitted and received messages
- Supports transmit event FIFO
- Supports the following modes:
- Disable Auto-Retransmission (DAR) mode
- Snoop (Bus Monitoring) mode
- Sleep mode with Wake-Up Interrupt
- Internal Loopback mode
- Bus-Off Recovery mode - Auto-Recovery - User intervention for Auto-Recovery
- Disable Protocol Exception Event mode
Features supported in driver
- Conforms to the ISO 11898 -1, CAN 2.0A, and CAN2.0B standards
- Supports Industrial (I) and Extended TemperatureRange (Q) grade device support
- Supports both standard (11-bit identifier) andextended (29-bit identifier) frames
- Supports normal bit rates up to 1 Mbps and flexible bit rates up to 8Mbps
- Transmit message FIFO with a user-configurable depth of up to 64 messages
- Transmit prioritization through one High-Priority Transmit buffer
- Automatic re-transmission on errors or arbitration loss
- Receive message FIFO with a user- configurable depth of up to 64 messages
- Loop Back Mode for diagnostic applications
- Maskable Error and Status Interrupts
- Readable Error Counters
Missing features, Known Issues and Limitations
- Frame work won't support Acceptance filters
- Frame work won't support water marking
- Frame work won't support Multiple RX buffers
Kernel Configuration
Xilinx CAN drivers is not enabled in the current default kernel configuration. The following steps may be used to enable the driver in the kernel configuration.The driver is available at,
https://github.com/Xilinx/linux-xlnx/blob/master/drivers/net/can/xilinx_can.c
Device Tree
For More details about the device tree bindings doc please refer to the Documentation/devicetree/bindings/net/can/xilinx_can.txt fileFor Zynq CANPS Dts file: zynq_can_0: can@e0008000 { compatible = "xlnx,zynq-can-1.0"; clocks = <&clkc 19>, <&clkc 36>; clock-names = "can_clk", "pclk"; reg = <0xe0008000 0x1000>; interrupts = <0 28 4>; interrupt-parent = <&intc>; tx-fifo-depth = <0x40>; rx-fifo-depth = <0x40>; }; For Axi CAN Dts file: axi_can_0: axi-can@40000000 { compatible = "xlnx,axi-can-1.00.a"; clocks = <&clkc 0>, <&clkc 1>; clock-names = "can_clk","s_axi_aclk" ; reg = <0x40000000 0x10000>; interrupt-parent = <&intc>; interrupts = <0 59 1>; tx-fifo-depth = <0x40>; rx-fifo-depth = <0x40>; }; For CAN FD 1.0: axi_can_0: axi-can@40000000 { compatible = "xlnx-canfd-1.0"; clocks = <&clkc 0>, <&clkc 1>; clock-names = "can_clk","s_axi_aclk" ; reg = <0x40000000 0x10000>; interrupt-parent = <&intc>; interrupts = <0 59 1>; tx-fifo-depth = <0x40>; rx-fifo-depth = <0x40>; }; For CAN FD 2.0: axi_can_0: canfd@80000000 { clock-names "can_clk", "can_clk_x2", "s_axi_aclk"; clocks <0x18 0x19 0x0 0x3 0x47>; compatible "xlnx,canfd-2.0"; interrupt-names "ip2bus_intrevent"; interrupt-parent <0x4>; interrupts <0x0 0x59 0x4>; reg <0x0 0x80000000 0x0 0x10000>; rx-fifo-depth <0x20>; tx-mailbox-count <0x20>; }; Note: There is no software difference between AXI CANFD and CANFD PS. So compatible "xlnx,canfd-2.0" will work for both.
Test Procedure
CAN Driver Testing from user space
In order to test Xilinx CAN driver there is user space utilities called can-utils available for the user and user need to cross compile those utilities in order to testthe this driver.
CAN:
Attached the Cross compiled can-utils for the Microblaze and ARM(Cortexa9) architectures.
Microblaze Cross compiled CAN utils:
ARM(ZYNQ) cortexa9 Cross compiled CAN utils:
A53 Cross compiled CAN utils:
CANFD:
Xilinx CANFD hw supports this. The same linux can driver support this can fd feature
But to test this CANFD Support need to download canutils
from https://github.com/linux-can/can-utils
Microblaze Cross compiled CANUtils
ARM(ZYNQ) cortexa9 Cross compiled CAN utils:
To run CAN, use the below command:
1. Set bit-timing
Can supports bitrates upto 1Mb/s. Xilinx CAN h/w and driver supports these bit rates
Note: Triple sampling is not supported by Xilinx CAN H/W.
$ ./ip link set can0 type can bitrate 200000
or
$ ./canconfig can0 bitrate 200000
2. Bring up the device
$ ./ip link set can0 up
or
$ ./canconfig can0 start
3. Bring down the device
$ ./ip link set can0 down
or
$ ./canconfig can0 stop
4. Transmit and receive packets with standard id number
$ ./cansend can0 -i 0x14 <bytes>
$ ./candump can0
5. Transmit and receive packets with extended id number (--loop argument here)
$ ./cansend can0 -i 0x333 <bytes>
$ ./candump can0
6. Loopback mode
$ ./canconfig can0 ctrlmode loopback on
7. Checking link state (checking bitrate/errors/packets)
$ ./ip -d -s link show can0
8. Checking net device state
$ ifconfig can0
9. Getting statistics via proc
$ cat /proc/net/can/stats
10. Socket CAN core uses several filter lists to deliver received CAN frames to CAN protocol modules. These
receive lists, their filters and the count of filter matches can be checked in the appropriate receive list. All entries contain the
device and a protocol module identifier:
$ cat /proc/net/can/rcvlist_all
rcvlist_all - list for unfiltered entries (no filter operations)
rcvlist_eff - list for single extended frame (EFF) entries
rcvlist_err - list for error message frames masks
rcvlist_fil - list for mask/value filters
rcvlist_inv - list for mask/value filters (inverse semantic)
rcvlist_sff - list for single standard frame (SFF) entries
To run CANFD, use the below command:
1. Set bit-timing
Canfd supports two bitrates, one for Arbitration phase and other for Data phase. Xilinx CANFD h/w and driver supports these bit rates
$ ./ip link set can0 type can bitrate 125000 dbitrate 8000000 fd on
2. Bring up the device
$ ./ip link set can0 up
3. Bring down the device
$ ./ip link set can0 down
4. Transmit and receive canfd packets with standard id number
$ ./cansend can0 213##<bytes>
$ ./candump can0
5. Transmit and receive can packets with same controller, since canfd supports backward can also
$ ./cansend can0 123#<bytes>
$ ./candump can0
6. Loopback mode
$ ./ip link set can0 type can bitrate 125000 dbitrate 8000000 fd on looopback on
7. Checking link state (checking bitrate/errors/packets)
$ ./ip -d link show can0
8. Checking net device state
$ ifconfig can0
Binding Tests:
Microblaze:
a. correct binding with
XILINX_CAN e0008000.ps7-can: phy mem:0xe0008000..0xe0008fff
XILINX_CAN e0008000.ps7-can: reg_base=0xf0062000 irq=60 clock=23809523, tx fifo depth:64
b. Incorrect binding - tests suppose to fail
I. missing clocks
II. missing clock-names
III. missing register
IV. missing interrupt parent
V. missing interrupts number
Zynq:
a. correct binding with
b. Incorrect binding - tests suppose to fail (done on dummy nodes)
I. missing clocks
II. missing clock-names
III. missing register
IV. missing interrupt parent
V. missing interrupts number
Expected Output
root@Xilinx-ZC702-2013:~# canconfig can3 ctrlmode loopback on can3 ctrlmode: loopback[ON], listen-only[OFF], tripple-sampling[OFF],one-shot[OFF], berr-reporting[OFF] root@Xilinx-ZC702-2013:~# cancon root@Xilinx-ZC702-2013:~# canconfig can3 bitrate 500000 XILINX_CAN e0008000.ps7-can can3: bitrate error 0.7% can3 bitrate: 496031, sample-point: 0.666 root@Xilinx-ZC702-2013:~# canconfig can3 start can3 state: ERROR-ACTIVE root@Xilinx-ZC702-2013:~# cansend can3 -i 0x77 0x33 0x88 0x33 0x88 0x33 0x88 0x33 interface = can3, family = 29, type = 3, proto = 1 root@Xilinx-ZC702-2013:~# ip -d -s link show can3 5: can3: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10 link/can promiscuity 0 can <LOOPBACK> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 bitrate 496031 sample-point 0.666 tq 672 prop-seg 0 phase-seg1 1 phase-seg2 1 sjw 1 XILINX_CAN: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..256 brp-inc 1 clock 23809523 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 7 1 0 0 0 0 TX: bytes packets errors dropped carrier collsns 7 1 0 0 0 0 root@Xilinx-ZC702-2013:~# cansend can3 -i 0x33 0x88 0x33 0x88 0x33 0x99 0x33 0x88 0x88 interface = can3, family = 29, type = 3, proto = 1 root@Xilinx-ZC702-2013:~# ip -d -s link show can3 5: can3: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10 link/can promiscuity 0 can <LOOPBACK> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 bitrate 496031 sample-point 0.666 tq 672 prop-seg 0 phase-seg1 1 phase-seg2 1 sjw 1 XILINX_CAN: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..256 brp-inc 1 clock 23809523 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 15 2 0 0 0 0 TX: bytes packets errors dropped carrier collsns 15 2 0 0 0 0 root@Xilinx-ZC702-2013:~# cansen root@Xilinx-ZC702-2013:~# cansend can3 -i 0x88 0x33 0x88 0x33 0x88 x0x33 0x88 0x33 0x88 --loop=10 interface = can3, family = 29, type = 3, proto = 1 root@Xilinx-ZC702-2013:~# ip -d -s link show can3 5: can3: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10 link/can promiscuity 0 can <LOOPBACK> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 bitrate 496031 sample-point 0.666 tq 672 prop-seg 0 phase-seg1 1 phase-seg2 1 sjw 1 XILINX_CAN: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..256 brp-inc 1 clock 23809523 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 95 12 0 0 0 0 TX: bytes packets errors dropped carrier collsns 95 12 0 0 0 0 root@Xilinx-ZC702-2013:~#
Mainline status
This driver is currently in sync with mainline kernel driver.Change Log
2024.2
- Summary
- can: xilinx_can: Document driver description to list all supported IPs
- Commits
- Summary
2024.1
2023.2
2023.1
- Summary
- can: xilinx_can: Revert "can: xilinx_can: Limit CANFD brp to 2"
- Commits
- Summary
Related Links
© Copyright 2019 - 2022 Xilinx Inc. Privacy Policy