1 /* SPDX-License-Identifier: GPL-2.0 */
3 /* Driver for ETAS GmbH ES58X USB CAN(-FD) Bus Interfaces.
5 * File es581_4.h: Definitions and declarations specific to ETAS
8 * Copyright (c) 2019 Robert Bosch Engineering and Business Solutions. All rights reserved.
9 * Copyright (c) 2020 ETAS K.K.. All rights reserved.
10 * Copyright (c) 2020, 2021 Vincent Mailhol <mailhol.vincent@wanadoo.fr>
16 #include <linux/types.h>
18 #define ES581_4_NUM_CAN_CH 2
19 #define ES581_4_CHANNEL_IDX_OFFSET 1
21 #define ES581_4_TX_BULK_MAX 25
22 #define ES581_4_RX_BULK_MAX 30
23 #define ES581_4_ECHO_BULK_MAX 30
25 enum es581_4_cmd_type
{
26 ES581_4_CAN_COMMAND_TYPE
= 0x45
30 ES581_4_CMD_ID_OPEN_CHANNEL
= 0x01,
31 ES581_4_CMD_ID_CLOSE_CHANNEL
= 0x02,
32 ES581_4_CMD_ID_SET_BITTIMING
= 0x03,
33 ES581_4_CMD_ID_ENABLE_CHANNEL
= 0x04,
34 ES581_4_CMD_ID_TX_MSG
= 0x05,
35 ES581_4_CMD_ID_RX_MSG
= 0x06,
36 ES581_4_CMD_ID_RESET_RX
= 0x0A,
37 ES581_4_CMD_ID_RESET_TX
= 0x0B,
38 ES581_4_CMD_ID_DISABLE_CHANNEL
= 0x0C,
39 ES581_4_CMD_ID_TIMESTAMP
= 0x0E,
40 ES581_4_CMD_ID_RESET_DEVICE
= 0x28,
41 ES581_4_CMD_ID_ECHO
= 0x71,
42 ES581_4_CMD_ID_DEVICE_ERR
= 0x72
45 enum es581_4_rx_type
{
46 ES581_4_RX_TYPE_MESSAGE
= 1,
47 ES581_4_RX_TYPE_ERROR
= 3,
48 ES581_4_RX_TYPE_EVENT
= 4
52 * struct es581_4_tx_conf_msg - Channel configuration.
54 * @sample_point: Sample point is in percent [0..100].
55 * @samples_per_bit: type enum es58x_samples_per_bit.
56 * @bit_time: Number of time quanta in one bit.
57 * @sjw: Synchronization Jump Width.
58 * @sync_edge: type enum es58x_sync_edge.
59 * @physical_layer: type enum es58x_physical_layer.
60 * @echo_mode: type enum es58x_echo_mode.
61 * @channel_no: Channel number, starting from 1. Not to be confused
62 * with channed_idx of the ES58X FD which starts from 0.
64 struct es581_4_tx_conf_msg
{
67 __le32 samples_per_bit
;
71 __le32 physical_layer
;
76 struct es581_4_tx_can_msg
{
82 u8 data
[CAN_MAX_DLEN
];
85 /* The ES581.4 allows bulk transfer. */
86 struct es581_4_bulk_tx_can_msg
{
88 /* Using type "u8[]" instead of "struct es581_4_tx_can_msg[]"
89 * for tx_msg_buf because each member has a flexible size.
91 u8 tx_can_msg_buf
[ES581_4_TX_BULK_MAX
*
92 sizeof(struct es581_4_tx_can_msg
)];
95 struct es581_4_echo_msg
{
100 struct es581_4_bulk_echo_msg
{
102 struct es581_4_echo_msg echo_msg
[ES581_4_ECHO_BULK_MAX
];
105 /* Normal Rx CAN Message */
106 struct es581_4_rx_can_msg
{
108 u8 rx_type
; /* type enum es581_4_rx_type */
109 u8 flags
; /* type enum es58x_flag */
113 u8 data
[CAN_MAX_DLEN
];
116 struct es581_4_rx_err_msg
{
118 __le16 rx_type
; /* type enum es581_4_rx_type */
119 __le16 flags
; /* type enum es58x_flag */
123 __le32 tag
; /* Related to the CAN filtering. Unused in this module */
125 __le32 error
; /* type enum es58x_error */
126 __le32 destination
; /* Unused in this module */
129 struct es581_4_rx_event_msg
{
131 __le16 rx_type
; /* type enum es581_4_rx_type */
134 __le32 tag
; /* Related to the CAN filtering. Unused in this module */
135 __le32 event
; /* type enum es58x_event */
136 __le32 destination
; /* Unused in this module */
139 struct es581_4_tx_ack_msg
{
140 __le16 tx_free_entries
; /* Number of remaining free entries in the device TX queue */
142 u8 rx_cmd_ret_u8
; /* type enum es58x_cmd_ret_code_u8 */
145 struct es581_4_rx_cmd_ret
{
146 __le32 rx_cmd_ret_le32
;
152 * struct es581_4_urb_cmd - Commands received from or sent to the
154 * @SOF: Start of Frame.
155 * @cmd_type: Command Type (type: enum es581_4_cmd_type). The CRC
156 * calculation starts at this position.
157 * @cmd_id: Command ID (type: enum es581_4_cmd_id).
158 * @msg_len: Length of the message, excluding CRC (i.e. length of the
160 * @tx_conf_msg: Channel configuration.
161 * @bulk_tx_can_msg: Tx messages.
162 * @rx_can_msg: Array of Rx messages.
163 * @bulk_echo_msg: Tx message being looped back.
164 * @rx_err_msg: Error message.
165 * @rx_event_msg: Event message.
166 * @tx_ack_msg: Tx acknowledgment message.
167 * @rx_cmd_ret: Command return code.
168 * @timestamp: Timestamp reply.
169 * @rx_cmd_ret_u8: Rx 8 bits return code (type: enum
170 * es58x_cmd_ret_code_u8).
171 * @raw_msg: Message raw payload.
172 * @reserved_for_crc16_do_not_use: The structure ends with a
173 * CRC16. Because the structures in above union are of variable
174 * lengths, we can not predict the offset of the CRC in
175 * advance. Use functions es58x_get_crc() and es58x_set_crc() to
178 struct es581_4_urb_cmd
{
185 struct es581_4_tx_conf_msg tx_conf_msg
;
186 struct es581_4_bulk_tx_can_msg bulk_tx_can_msg
;
187 struct es581_4_rx_can_msg rx_can_msg
[ES581_4_RX_BULK_MAX
];
188 struct es581_4_bulk_echo_msg bulk_echo_msg
;
189 struct es581_4_rx_err_msg rx_err_msg
;
190 struct es581_4_rx_event_msg rx_event_msg
;
191 struct es581_4_tx_ack_msg tx_ack_msg
;
192 struct es581_4_rx_cmd_ret rx_cmd_ret
;
195 DECLARE_FLEX_ARRAY(u8
, raw_msg
);
198 __le16 reserved_for_crc16_do_not_use
;
201 #define ES581_4_URB_CMD_HEADER_LEN (offsetof(struct es581_4_urb_cmd, raw_msg))
202 #define ES581_4_TX_URB_CMD_MAX_LEN \
203 ES58X_SIZEOF_URB_CMD(struct es581_4_urb_cmd, bulk_tx_can_msg)
204 #define ES581_4_RX_URB_CMD_MAX_LEN \
205 ES58X_SIZEOF_URB_CMD(struct es581_4_urb_cmd, rx_can_msg)
207 #endif /* __ES581_4_H__ */