Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PCI CAN cards for QEMU: Kvaser and CTU CAN FD #15161

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Documentation/components/drivers/special/pci/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,50 @@ Supported devices:

- Intel I225LM
- Intel I226V

Kvaser PCI CAN card
-------------------

At the moment the card only works with QEMU.

The driver supports both SocketCAN interface and character driver.

The driver requires, ``vcan`` to run on the host:

.. code:: shell

sudo ip link add dev can0 type vcan
sudo ip link set can0 up

An example command to run the driver on ``x86_64`` looks like this:

.. code:: shell

qemu-system-x86_64 -m 2G -cpu host -enable-kvm -kernel nuttx \
-nographic -serial mon:stdio -object can-bus,id=canbus0 \
-object can-host-socketcan,id=canhost0,if=can0,canbus=canbus0 \
-device kvaser_pci,canbus=canbus0


CTUCANFD PCI CAN card
---------------------

At the moment the card only works with QEMU.

The driver supports both SocketCAN interface and character driver.

The driver requires, ``vcan`` to run on the host:

.. code:: shell

sudo ip link add dev can0 type vcan
sudo ip link set can0 up

An example command to run the driver on ``x86_64`` looks like this:

.. code:: shell

qemu-system-x86_64 -m 2G -cpu host -enable-kvm -kernel nuttx \
-nographic -serial mon:stdio -object can-bus,id=canbus0-bus \
-object can-host-socketcan,if=can0,canbus=canbus0-bus,id=canbus0-socketcan \
-device ctucan_pci,canbus0=canbus0-bus,canbus1=canbus0-bus
18 changes: 14 additions & 4 deletions drivers/can/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,22 @@
#
# ##############################################################################

set(SRCS)

if(CONFIG_CAN)
set(SRCS can.c can_sender.c)
endif()

if(CONFIG_CAN_MCP2515)
list(APPEND SRCS mcp2515.c)
endif()

if(CONFIG_CAN_MCP2515)
list(APPEND SRCS mcp2515.c)
endif()
if(CONFIG_CAN_KVASER)
list(APPEND SRCS kvaser_pci.c)
endif()

target_sources(drivers PRIVATE ${SRCS})
if(CONFIG_CAN_CTUCANFD)
list(APPEND SRCS ctucanfd_pci.c)
endif()

target_sources(drivers PRIVATE ${SRCS})
67 changes: 65 additions & 2 deletions drivers/can/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ config ARCH_HAVE_CAN_ERRORS
bool
default n

menuconfig CAN
bool "CAN Driver Support"
menu "CAN Driver Support"

config CAN
bool "CAN Character Driver Support"
default n
---help---
This selection enables building of the "upper-half" CAN driver.
Expand Down Expand Up @@ -267,3 +269,64 @@ config CAN_SJA1000_DEBUG
endif # CAN_SJA1000

endif # CAN

config CAN_KVASER
bool "Kvaser PCI CAN card"
default n
depends on PCI
---help---
Enable driver support for Kvase PCI CAN card.
NOTE: for now works only with QEMU

if CAN_KVASER

choice
prompt "Kvaser PCI CAN device type"
default CAN_KVASER_CHARDEV if CAN
default CAN_KVASER_SOCKET if NET_CAN

config CAN_KVASER_CHARDEV
bool "Kvaser PCI can device as chardev"
depends on CAN
select ARCH_HAVE_CAN_ERRORS

config CAN_KVASER_SOCKET
bool "Kvaser PCI can device as socketCAN"
depends on NET_CAN
select NET_CAN_HAVE_ERRORS

endchoice # "Kvaser PCI CAN device type"

endif # CAN_KVASER

config CAN_CTUCANFD
bool "CTUCANFD PCI CAN card"
default n
depends on PCI
---help---
Enable driver support for CTU CAN FD PCI card.
NOTE: for now works only with QEMU

if CAN_CTUCANFD

choice
prompt "CTU CAN FD PCI CAN device type"
default CAN_CTUCANFD_CHARDEV if CAN
default CAN_CTUCANFD_SOCKET if NET_CAN

config CAN_CTUCANFD_CHARDEV
bool "CTU CAN FD PCI can device as chardev"
depends on CAN
select ARCH_HAVE_CAN_ERRORS

config CAN_CTUCANFD_SOCKET
bool "CTU CAN FD PCI can device as socketCAN"
depends on NET_CAN
select NET_CAN_HAVE_ERRORS
select NET_CAN_HAVE_CANFD

endchoice # "CTU CAN FD PCI CAN device type"

endif # CAN_CTUCANFD

endmenu # CAN Driver Support
11 changes: 9 additions & 2 deletions drivers/can/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
# Don't build anything if there is no CAN support

ifeq ($(CONFIG_CAN),y)

CSRCS += can.c can_sender.c
endif

ifeq ($(CONFIG_CAN_MCP2515),y)
CSRCS += mcp2515.c
Expand All @@ -34,9 +34,16 @@ ifeq ($(CONFIG_CAN_SJA1000),y)
CSRCS += sja1000.c
endif

ifeq ($(CONFIG_CAN_KVASER),y)
CSRCS += kvaser_pci.c
endif

ifeq ($(CONFIG_CAN_CTUCANFD),y)
CSRCS += ctucanfd_pci.c
endif

# Include CAN device driver build support

DEPPATH += --dep-path can
VPATH += :can
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)drivers$(DELIM)can
endif
Loading
Loading