| 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
| 2 | /* |
| 3 | * Copyright (C) 2021-2023 OpenSynergy GmbH |
| 4 | * Copyright Red Hat, Inc. 2025 |
| 5 | */ |
| 6 | #ifndef _LINUX_VIRTIO_VIRTIO_CAN_H |
| 7 | #define _LINUX_VIRTIO_VIRTIO_CAN_H |
| 8 | |
| 9 | #include <linux/types.h> |
| 10 | #include <linux/virtio_types.h> |
| 11 | #include <linux/virtio_ids.h> |
| 12 | #include <linux/virtio_config.h> |
| 13 | |
| 14 | /* Feature bit numbers */ |
| 15 | #define VIRTIO_CAN_F_CAN_CLASSIC 0 |
| 16 | #define VIRTIO_CAN_F_CAN_FD 1 |
| 17 | #define VIRTIO_CAN_F_RTR_FRAMES 2 |
| 18 | #define VIRTIO_CAN_F_LATE_TX_ACK 3 |
| 19 | |
| 20 | /* CAN Result Types */ |
| 21 | #define VIRTIO_CAN_RESULT_OK 0 |
| 22 | #define VIRTIO_CAN_RESULT_NOT_OK 1 |
| 23 | |
| 24 | /* CAN flags to determine type of CAN Id */ |
| 25 | #define VIRTIO_CAN_FLAGS_EXTENDED 0x8000 |
| 26 | #define VIRTIO_CAN_FLAGS_FD 0x4000 |
| 27 | #define VIRTIO_CAN_FLAGS_RTR 0x2000 |
| 28 | |
| 29 | #define VIRTIO_CAN_MAX_DLEN 64 /* this is like CANFD_MAX_DLEN */ |
| 30 | |
| 31 | struct virtio_can_config { |
| 32 | #define VIRTIO_CAN_S_CTRL_BUSOFF (1u << 0) /* Controller BusOff */ |
| 33 | 	/* CAN controller status */ |
| 34 | 	__le16 status; |
| 35 | }; |
| 36 | |
| 37 | /* TX queue message types */ |
| 38 | struct virtio_can_tx_out { |
| 39 | #define VIRTIO_CAN_TX 0x0001 |
| 40 | 	__le16 msg_type; |
| 41 | 	__le16 length; /* 0..8 CC, 0..64 CAN-FD, 0..2048 CAN-XL, 12 bits */ |
| 42 | 	__u8 reserved_classic_dlc; /* If CAN classic length = 8 then DLC can be 8..15 */ |
| 43 | 	__u8 padding; |
| 44 | 	__le16 reserved_xl_priority; /* May be needed for CAN XL priority */ |
| 45 | 	__le32 flags; |
| 46 | 	__le32 can_id; |
| 47 | 	__u8 sdu[] __counted_by_le(length); |
| 48 | }; |
| 49 | |
| 50 | struct virtio_can_tx_in { |
| 51 | 	__u8 result; |
| 52 | }; |
| 53 | |
| 54 | /* RX queue message types */ |
| 55 | struct virtio_can_rx { |
| 56 | #define VIRTIO_CAN_RX 0x0101 |
| 57 | 	__le16 msg_type; |
| 58 | 	__le16 length; /* 0..8 CC, 0..64 CAN-FD, 0..2048 CAN-XL, 12 bits */ |
| 59 | 	__u8 reserved_classic_dlc; /* If CAN classic length = 8 then DLC can be 8..15 */ |
| 60 | 	__u8 padding; |
| 61 | 	__le16 reserved_xl_priority; /* May be needed for CAN XL priority */ |
| 62 | 	__le32 flags; |
| 63 | 	__le32 can_id; |
| 64 | 	__u8 sdu[] __counted_by_le(length); |
| 65 | }; |
| 66 | |
| 67 | /* Control queue message types */ |
| 68 | struct virtio_can_control_out { |
| 69 | #define VIRTIO_CAN_SET_CTRL_MODE_START 0x0201 |
| 70 | #define VIRTIO_CAN_SET_CTRL_MODE_STOP 0x0202 |
| 71 | 	__le16 msg_type; |
| 72 | }; |
| 73 | |
| 74 | struct virtio_can_control_in { |
| 75 | 	__u8 result; |
| 76 | }; |
| 77 | |
| 78 | #endif /* #ifndef _LINUX_VIRTIO_VIRTIO_CAN_H */ |