master
h 78 lines 2.26 KB
Raw
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 "standard-headers/linux/types.h"
10 #include "standard-headers/linux/virtio_types.h"
11 #include "standard-headers/linux/virtio_ids.h"
12 #include "standard-headers/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 uint16_t status;
35 };
36
37 /* TX queue message types */
38 struct virtio_can_tx_out {
39 #define VIRTIO_CAN_TX 0x0001
40 uint16_t msg_type;
41 uint16_t length; /* 0..8 CC, 0..64 CAN-FD, 0..2048 CAN-XL, 12 bits */
42 uint8_t reserved_classic_dlc; /* If CAN classic length = 8 then DLC can be 8..15 */
43 uint8_t padding;
44 uint16_t reserved_xl_priority; /* May be needed for CAN XL priority */
45 uint32_t flags;
46 uint32_t can_id;
47 uint8_t sdu[] __counted_by_le(length);
48 };
49
50 struct virtio_can_tx_in {
51 uint8_t result;
52 };
53
54 /* RX queue message types */
55 struct virtio_can_rx {
56 #define VIRTIO_CAN_RX 0x0101
57 uint16_t msg_type;
58 uint16_t length; /* 0..8 CC, 0..64 CAN-FD, 0..2048 CAN-XL, 12 bits */
59 uint8_t reserved_classic_dlc; /* If CAN classic length = 8 then DLC can be 8..15 */
60 uint8_t padding;
61 uint16_t reserved_xl_priority; /* May be needed for CAN XL priority */
62 uint32_t flags;
63 uint32_t can_id;
64 uint8_t 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 uint16_t msg_type;
72 };
73
74 struct virtio_can_control_in {
75 uint8_t result;
76 };
77
78 #endif /* #ifndef _LINUX_VIRTIO_VIRTIO_CAN_H */