Skip to contentSkip to conversation

linux-headers: add virtio_can.h

RFC In review Matias Ezequiel Vara Larsen 3 participants 4 messages Oct 31, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

RFC 1/2 linux-headers: add virtio_can.h

---
Note that virtio_can.h is not merged yet and it is part of the series
https://lore.kernel.org/all/aQJRnX7OpFRY%2F1+H@fedora/

---
 include/standard-headers/linux/virtio_can.h | 78 +++++++++++++++++++++
 1 file changed, 78 insertions(+)
 create mode 100644 include/standard-headers/linux/virtio_can.h
include/standard-headers/linux/virtio_can.h new file +78 -0
new file mode 100644
index 0000000000..6380ef7bce
@@ -0,0 +1,78 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (C) 2021-2023 OpenSynergy GmbH
+ * Copyright Red Hat, Inc. 2025
+ */
+#ifndef _LINUX_VIRTIO_VIRTIO_CAN_H
+#define _LINUX_VIRTIO_VIRTIO_CAN_H
+
+#include <standard-headers/linux/types.h>
+#include <standard-headers/linux/virtio_types.h>
+#include <standard-headers/linux/virtio_ids.h>
+#include <standard-headers/linux/virtio_config.h>
+
+/* Feature bit numbers */
+#define VIRTIO_CAN_F_CAN_CLASSIC        0
+#define VIRTIO_CAN_F_CAN_FD             1
+#define VIRTIO_CAN_F_RTR_FRAMES         2
+#define VIRTIO_CAN_F_LATE_TX_ACK        3
+
+/* CAN Result Types */
+#define VIRTIO_CAN_RESULT_OK            0
+#define VIRTIO_CAN_RESULT_NOT_OK        1
+
+/* CAN flags to determine type of CAN Id */
+#define VIRTIO_CAN_FLAGS_EXTENDED       0x8000
+#define VIRTIO_CAN_FLAGS_FD             0x4000
+#define VIRTIO_CAN_FLAGS_RTR            0x2000
+
+#define VIRTIO_CAN_MAX_DLEN    64 // this is like CANFD_MAX_DLEN
+
+struct virtio_can_config {
+#define VIRTIO_CAN_S_CTRL_BUSOFF (1u << 0) /* Controller BusOff */
+	/* CAN controller status */
+	__le16 status;
+};
+
+/* TX queue message types */
+struct virtio_can_tx_out {
+#define VIRTIO_CAN_TX                   0x0001
+	__le16 msg_type;
+	__le16 length; /* 0..8 CC, 0..64 CAN-FD, 0..2048 CAN-XL, 12 bits */
+	__u8 reserved_classic_dlc; /* If CAN classic length = 8 then DLC can be 8..15 */
+	__u8 padding;
+	__le16 reserved_xl_priority; /* May be needed for CAN XL priority */
+	__le32 flags;
+	__le32 can_id;
+	__u8 sdu[] __counted_by(length);
+};
+
+struct virtio_can_tx_in {
+	__u8 result;
+};
+
+/* RX queue message types */
+struct virtio_can_rx {
+#define VIRTIO_CAN_RX                   0x0101
+	__le16 msg_type;
+	__le16 length; /* 0..8 CC, 0..64 CAN-FD, 0..2048 CAN-XL, 12 bits */
+	__u8 reserved_classic_dlc; /* If CAN classic length = 8 then DLC can be 8..15 */
+	__u8 padding;
+	__le16 reserved_xl_priority; /* May be needed for CAN XL priority */
+	__le32 flags;
+	__le32 can_id;
+	__u8 sdu[] __counted_by(length);
+};
+
+/* Control queue message types */
+struct virtio_can_control_out {
+#define VIRTIO_CAN_SET_CTRL_MODE_START  0x0201
+#define VIRTIO_CAN_SET_CTRL_MODE_STOP   0x0202
+	__le16 msg_type;
+};
+
+struct virtio_can_control_in {
+	__u8 result;
+};
+
+#endif /* #ifndef _LINUX_VIRTIO_VIRTIO_CAN_H */
Signature · 1 line
2.42.0
#1 lore raw

RFC 2/2 Add vhost-user-can and vhost-user-can-pci devices

From: Timos Ampelikiotis <[email protected]>

Add vhost-user-can device, which has been tested with latest vhost-device-can (see
https://github.com/rust-vmm/vhost-device/tree/main/vhost-device-can) and the virtio-can driver v6 (see
https://lore.kernel.org/all/aQJRnX7OpFRY%2F1+H@fedora/).

---
 hw/net/Kconfig                  |  5 +++
 hw/net/can/meson.build          |  3 ++
 hw/net/can/vhost-user-can-pci.c | 69 +++++++++++++++++++++++++++++++++
 hw/net/can/vhost-user-can.c     | 65 +++++++++++++++++++++++++++++++
 include/hw/net/vhost-user-can.h | 26 +++++++++++++
 5 files changed, 168 insertions(+)
 create mode 100644 hw/net/can/vhost-user-can-pci.c
 create mode 100644 hw/net/can/vhost-user-can.c
 create mode 100644 include/hw/net/vhost-user-can.h
hw/net/Kconfig +5 -0
index 2b513d6895..c6fe5b4376 100644
@@ -160,3 +160,8 @@ config CAN_CTUCANFD_PCI
     default y if PCI_DEVICES
     depends on PCI && CAN_CTUCANFD
     select CAN_BUS
+
+config VHOST_USER_CAN
+    bool
+    default y
+    depends on VIRTIO && VHOST_USER
hw/net/can/meson.build +3 -0
index 7382344628..1796a89820 100644
@@ -4,5 +4,8 @@ system_ss.add(when: 'CONFIG_CAN_PCI', if_true: files('can_pcm3680_pci.c'))
 system_ss.add(when: 'CONFIG_CAN_PCI', if_true: files('can_mioe3680_pci.c'))
 system_ss.add(when: 'CONFIG_CAN_CTUCANFD', if_true: files('ctucan_core.c'))
 system_ss.add(when: 'CONFIG_CAN_CTUCANFD_PCI', if_true: files('ctucan_pci.c'))
+system_ss.add(when: 'CONFIG_VHOST_USER_CAN', if_true: files('vhost-user-can.c'))
+system_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_CAN'],
+                      if_true: files('vhost-user-can-pci.c'))
 system_ss.add(when: 'CONFIG_XLNX_ZYNQMP', if_true: files('xlnx-zynqmp-can.c'))
 system_ss.add(when: 'CONFIG_XLNX_VERSAL', if_true: files('xlnx-versal-canfd.c'))
hw/net/can/vhost-user-can-pci.c new file +69 -0

69 lines not on this page · raw message

hw/net/can/vhost-user-can.c new file +65 -0

65 lines not on this page · raw message

include/hw/net/vhost-user-can.h new file +26 -0
new file mode 100644
index 0000000000..38bc261ce7
@@ -0,0 +1,26 @@
+/*
+ * Vhost-user Can virtio device
+ *
+ * Copyright (c) 2024 Timos Ampelikiotis <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef QEMU_VHOST_USER_CAN_H
+#define QEMU_VHOST_USER_CAN_H
+
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/vhost.h"
+#include "hw/virtio/vhost-user.h"
+#include "hw/virtio/vhost-user-base.h"
+
+#define TYPE_VHOST_USER_CAN "vhost-user-can"
+OBJECT_DECLARE_SIMPLE_TYPE(VHostUserCan, VHOST_USER_CAN)
+
+struct VHostUserCan {
+    /*< private >*/
+    VHostUserBase parent;
+    /*< public >*/
+};
+
+#endif /* QEMU_VHOST_USER_CAN_H */
Signature · 1 line
2.42.0
#2 lore raw
In reply to Matias Ezequiel Vara Larsen
Quoted 5 lines · Matias Ezequiel Vara Larsen

---
Note that virtio_can.h is not merged yet and it is part of the series
https://lore.kernel.org/all/aQJRnX7OpFRY%2F1+H@fedora/

Hi Matias,

As far as I know, standard-headers must be updated with ./scripts/update-linux-headers.sh, so unless exceptions can be it'll have to wait until the kernel patch is merged for this to be accepted.

Quoted 93 lines
---
 include/standard-headers/linux/virtio_can.h | 78 +++++++++++++++++++++
 1 file changed, 78 insertions(+)
 create mode 100644 include/standard-headers/linux/virtio_can.h
include/standard-headers/linux/virtio_can.h new file +78 -1
new file mode 100644
index 0000000000..6380ef7bce
@@ -0,0 +1,78 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright (C) 2021-2023 OpenSynergy GmbH
+ * Copyright Red Hat, Inc. 2025
+ */
+#ifndef _LINUX_VIRTIO_VIRTIO_CAN_H
+#define _LINUX_VIRTIO_VIRTIO_CAN_H
+
+#include <standard-headers/linux/types.h>
+#include <standard-headers/linux/virtio_types.h>
+#include <standard-headers/linux/virtio_ids.h>
+#include <standard-headers/linux/virtio_config.h>
+
+/* Feature bit numbers */
+#define VIRTIO_CAN_F_CAN_CLASSIC        0
+#define VIRTIO_CAN_F_CAN_FD             1
+#define VIRTIO_CAN_F_RTR_FRAMES         2
+#define VIRTIO_CAN_F_LATE_TX_ACK        3
+
+/* CAN Result Types */
+#define VIRTIO_CAN_RESULT_OK            0
+#define VIRTIO_CAN_RESULT_NOT_OK        1
+
+/* CAN flags to determine type of CAN Id */
+#define VIRTIO_CAN_FLAGS_EXTENDED       0x8000
+#define VIRTIO_CAN_FLAGS_FD             0x4000
+#define VIRTIO_CAN_FLAGS_RTR            0x2000
+
+#define VIRTIO_CAN_MAX_DLEN    64 // this is like CANFD_MAX_DLEN
+
+struct virtio_can_config {
+#define VIRTIO_CAN_S_CTRL_BUSOFF (1u << 0) /* Controller BusOff */
+       /* CAN controller status */
+       __le16 status;
+};
+
+/* TX queue message types */
+struct virtio_can_tx_out {
+#define VIRTIO_CAN_TX                   0x0001
+       __le16 msg_type;
+       __le16 length; /* 0..8 CC, 0..64 CAN-FD, 0..2048 CAN-XL, 12 bits */
+       __u8 reserved_classic_dlc; /* If CAN classic length = 8 then DLC can be 8..15 */
+       __u8 padding;
+       __le16 reserved_xl_priority; /* May be needed for CAN XL priority */
+       __le32 flags;
+       __le32 can_id;
+       __u8 sdu[] __counted_by(length);
+};
+
+struct virtio_can_tx_in {
+       __u8 result;
+};
+
+/* RX queue message types */
+struct virtio_can_rx {
+#define VIRTIO_CAN_RX                   0x0101
+       __le16 msg_type;
+       __le16 length; /* 0..8 CC, 0..64 CAN-FD, 0..2048 CAN-XL, 12 bits */
+       __u8 reserved_classic_dlc; /* If CAN classic length = 8 then DLC can be 8..15 */
+       __u8 padding;
+       __le16 reserved_xl_priority; /* May be needed for CAN XL priority */
+       __le32 flags;
+       __le32 can_id;
+       __u8 sdu[] __counted_by(length);
+};
+
+/* Control queue message types */
+struct virtio_can_control_out {
+#define VIRTIO_CAN_SET_CTRL_MODE_START  0x0201
+#define VIRTIO_CAN_SET_CTRL_MODE_STOP   0x0202
+       __le16 msg_type;
+};
+
+struct virtio_can_control_in {
+       __u8 result;
+};
+
+#endif /* #ifndef _LINUX_VIRTIO_VIRTIO_CAN_H */
--

2.42.0

#3 lore raw
Quoted 8 lines · Albert Esteve
Quoted 5 lines · Matias Ezequiel Vara Larsen

---
Note that virtio_can.h is not merged yet and it is part of the series
https://lore.kernel.org/all/aQJRnX7OpFRY%2F1+H@fedora/

Quoted 5 lines

Hi Matias,

As far as I know, standard-headers must be updated with ./scripts/update-linux-headers.sh, so unless exceptions can be it'll have to wait until the kernel patch is merged for this to be accepted.

It's fine to have it as a placeholder patch for review (this series is marked as RFC anyway) -- I'd recommend to put "Placeholder for headers update, do not merge" more prominently in there, though.