diff options
Diffstat (limited to 'include/linux/can.h')
-rw-r--r-- | include/linux/can.h | 70 |
1 files changed, 61 insertions, 9 deletions
diff --git a/include/linux/can.h b/include/linux/can.h index 9a19bcb3eeaf..018055efc034 100644 --- a/include/linux/can.h +++ b/include/linux/can.h | |||
@@ -21,7 +21,7 @@ | |||
21 | /* special address description flags for the CAN_ID */ | 21 | /* special address description flags for the CAN_ID */ |
22 | #define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */ | 22 | #define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */ |
23 | #define CAN_RTR_FLAG 0x40000000U /* remote transmission request */ | 23 | #define CAN_RTR_FLAG 0x40000000U /* remote transmission request */ |
24 | #define CAN_ERR_FLAG 0x20000000U /* error frame */ | 24 | #define CAN_ERR_FLAG 0x20000000U /* error message frame */ |
25 | 25 | ||
26 | /* valid bits in CAN ID for frame formats */ | 26 | /* valid bits in CAN ID for frame formats */ |
27 | #define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */ | 27 | #define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */ |
@@ -32,32 +32,84 @@ | |||
32 | * Controller Area Network Identifier structure | 32 | * Controller Area Network Identifier structure |
33 | * | 33 | * |
34 | * bit 0-28 : CAN identifier (11/29 bit) | 34 | * bit 0-28 : CAN identifier (11/29 bit) |
35 | * bit 29 : error frame flag (0 = data frame, 1 = error frame) | 35 | * bit 29 : error message frame flag (0 = data frame, 1 = error message) |
36 | * bit 30 : remote transmission request flag (1 = rtr frame) | 36 | * bit 30 : remote transmission request flag (1 = rtr frame) |
37 | * bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit) | 37 | * bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit) |
38 | */ | 38 | */ |
39 | typedef __u32 canid_t; | 39 | typedef __u32 canid_t; |
40 | 40 | ||
41 | #define CAN_SFF_ID_BITS 11 | ||
42 | #define CAN_EFF_ID_BITS 29 | ||
43 | |||
41 | /* | 44 | /* |
42 | * Controller Area Network Error Frame Mask structure | 45 | * Controller Area Network Error Message Frame Mask structure |
43 | * | 46 | * |
44 | * bit 0-28 : error class mask (see include/linux/can/error.h) | 47 | * bit 0-28 : error class mask (see include/linux/can/error.h) |
45 | * bit 29-31 : set to zero | 48 | * bit 29-31 : set to zero |
46 | */ | 49 | */ |
47 | typedef __u32 can_err_mask_t; | 50 | typedef __u32 can_err_mask_t; |
48 | 51 | ||
52 | /* CAN payload length and DLC definitions according to ISO 11898-1 */ | ||
53 | #define CAN_MAX_DLC 8 | ||
54 | #define CAN_MAX_DLEN 8 | ||
55 | |||
56 | /* CAN FD payload length and DLC definitions according to ISO 11898-7 */ | ||
57 | #define CANFD_MAX_DLC 15 | ||
58 | #define CANFD_MAX_DLEN 64 | ||
59 | |||
49 | /** | 60 | /** |
50 | * struct can_frame - basic CAN frame structure | 61 | * struct can_frame - basic CAN frame structure |
51 | * @can_id: the CAN ID of the frame and CAN_*_FLAG flags, see above. | 62 | * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition |
52 | * @can_dlc: the data length field of the CAN frame | 63 | * @can_dlc: frame payload length in byte (0 .. 8) aka data length code |
53 | * @data: the CAN frame payload. | 64 | * N.B. the DLC field from ISO 11898-1 Chapter 8.4.2.3 has a 1:1 |
65 | * mapping of the 'data length code' to the real payload length | ||
66 | * @data: CAN frame payload (up to 8 byte) | ||
54 | */ | 67 | */ |
55 | struct can_frame { | 68 | struct can_frame { |
56 | canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ | 69 | canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ |
57 | __u8 can_dlc; /* data length code: 0 .. 8 */ | 70 | __u8 can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */ |
58 | __u8 data[8] __attribute__((aligned(8))); | 71 | __u8 data[CAN_MAX_DLEN] __attribute__((aligned(8))); |
72 | }; | ||
73 | |||
74 | /* | ||
75 | * defined bits for canfd_frame.flags | ||
76 | * | ||
77 | * As the default for CAN FD should be to support the high data rate in the | ||
78 | * payload section of the frame (HDR) and to support up to 64 byte in the | ||
79 | * data section (EDL) the bits are only set in the non-default case. | ||
80 | * Btw. as long as there's no real implementation for CAN FD network driver | ||
81 | * these bits are only preliminary. | ||
82 | * | ||
83 | * RX: NOHDR/NOEDL - info about received CAN FD frame | ||
84 | * ESI - bit from originating CAN controller | ||
85 | * TX: NOHDR/NOEDL - control per-frame settings if supported by CAN controller | ||
86 | * ESI - bit is set by local CAN controller | ||
87 | */ | ||
88 | #define CANFD_NOHDR 0x01 /* frame without high data rate */ | ||
89 | #define CANFD_NOEDL 0x02 /* frame without extended data length */ | ||
90 | #define CANFD_ESI 0x04 /* error state indicator */ | ||
91 | |||
92 | /** | ||
93 | * struct canfd_frame - CAN flexible data rate frame structure | ||
94 | * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition | ||
95 | * @len: frame payload length in byte (0 .. CANFD_MAX_DLEN) | ||
96 | * @flags: additional flags for CAN FD | ||
97 | * @__res0: reserved / padding | ||
98 | * @__res1: reserved / padding | ||
99 | * @data: CAN FD frame payload (up to CANFD_MAX_DLEN byte) | ||
100 | */ | ||
101 | struct canfd_frame { | ||
102 | canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ | ||
103 | __u8 len; /* frame payload length in byte */ | ||
104 | __u8 flags; /* additional flags for CAN FD */ | ||
105 | __u8 __res0; /* reserved / padding */ | ||
106 | __u8 __res1; /* reserved / padding */ | ||
107 | __u8 data[CANFD_MAX_DLEN] __attribute__((aligned(8))); | ||
59 | }; | 108 | }; |
60 | 109 | ||
110 | #define CAN_MTU (sizeof(struct can_frame)) | ||
111 | #define CANFD_MTU (sizeof(struct canfd_frame)) | ||
112 | |||
61 | /* particular protocols of the protocol family PF_CAN */ | 113 | /* particular protocols of the protocol family PF_CAN */ |
62 | #define CAN_RAW 1 /* RAW sockets */ | 114 | #define CAN_RAW 1 /* RAW sockets */ |
63 | #define CAN_BCM 2 /* Broadcast Manager */ | 115 | #define CAN_BCM 2 /* Broadcast Manager */ |
@@ -97,7 +149,7 @@ struct sockaddr_can { | |||
97 | * <received_can_id> & mask == can_id & mask | 149 | * <received_can_id> & mask == can_id & mask |
98 | * | 150 | * |
99 | * The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can | 151 | * The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can |
100 | * filter for error frames (CAN_ERR_FLAG bit set in mask). | 152 | * filter for error message frames (CAN_ERR_FLAG bit set in mask). |
101 | */ | 153 | */ |
102 | struct can_filter { | 154 | struct can_filter { |
103 | canid_t can_id; | 155 | canid_t can_id; |