Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 
0003 /* Driver for ETAS GmbH ES58X USB CAN(-FD) Bus Interfaces.
0004  *
0005  * File es581_4.h: Definitions and declarations specific to ETAS
0006  * ES581.4.
0007  *
0008  * Copyright (c) 2019 Robert Bosch Engineering and Business Solutions. All rights reserved.
0009  * Copyright (c) 2020 ETAS K.K.. All rights reserved.
0010  * Copyright (c) 2020, 2021 Vincent Mailhol <mailhol.vincent@wanadoo.fr>
0011  */
0012 
0013 #ifndef __ES581_4_H__
0014 #define __ES581_4_H__
0015 
0016 #include <linux/types.h>
0017 
0018 #define ES581_4_NUM_CAN_CH 2
0019 #define ES581_4_CHANNEL_IDX_OFFSET 1
0020 
0021 #define ES581_4_TX_BULK_MAX 25
0022 #define ES581_4_RX_BULK_MAX 30
0023 #define ES581_4_ECHO_BULK_MAX 30
0024 
0025 enum es581_4_cmd_type {
0026     ES581_4_CAN_COMMAND_TYPE = 0x45
0027 };
0028 
0029 enum es581_4_cmd_id {
0030     ES581_4_CMD_ID_OPEN_CHANNEL = 0x01,
0031     ES581_4_CMD_ID_CLOSE_CHANNEL = 0x02,
0032     ES581_4_CMD_ID_SET_BITTIMING = 0x03,
0033     ES581_4_CMD_ID_ENABLE_CHANNEL = 0x04,
0034     ES581_4_CMD_ID_TX_MSG = 0x05,
0035     ES581_4_CMD_ID_RX_MSG = 0x06,
0036     ES581_4_CMD_ID_RESET_RX = 0x0A,
0037     ES581_4_CMD_ID_RESET_TX = 0x0B,
0038     ES581_4_CMD_ID_DISABLE_CHANNEL = 0x0C,
0039     ES581_4_CMD_ID_TIMESTAMP = 0x0E,
0040     ES581_4_CMD_ID_RESET_DEVICE = 0x28,
0041     ES581_4_CMD_ID_ECHO = 0x71,
0042     ES581_4_CMD_ID_DEVICE_ERR = 0x72
0043 };
0044 
0045 enum es581_4_rx_type {
0046     ES581_4_RX_TYPE_MESSAGE = 1,
0047     ES581_4_RX_TYPE_ERROR = 3,
0048     ES581_4_RX_TYPE_EVENT = 4
0049 };
0050 
0051 /**
0052  * struct es581_4_tx_conf_msg - Channel configuration.
0053  * @bitrate: Bitrate.
0054  * @sample_point: Sample point is in percent [0..100].
0055  * @samples_per_bit: type enum es58x_samples_per_bit.
0056  * @bit_time: Number of time quanta in one bit.
0057  * @sjw: Synchronization Jump Width.
0058  * @sync_edge: type enum es58x_sync_edge.
0059  * @physical_layer: type enum es58x_physical_layer.
0060  * @echo_mode: type enum es58x_echo_mode.
0061  * @channel_no: Channel number, starting from 1. Not to be confused
0062  *  with channed_idx of the ES58X FD which starts from 0.
0063  */
0064 struct es581_4_tx_conf_msg {
0065     __le32 bitrate;
0066     __le32 sample_point;
0067     __le32 samples_per_bit;
0068     __le32 bit_time;
0069     __le32 sjw;
0070     __le32 sync_edge;
0071     __le32 physical_layer;
0072     __le32 echo_mode;
0073     u8 channel_no;
0074 } __packed;
0075 
0076 struct es581_4_tx_can_msg {
0077     __le32 can_id;
0078     __le32 packet_idx;
0079     __le16 flags;
0080     u8 channel_no;
0081     u8 dlc;
0082     u8 data[CAN_MAX_DLEN];
0083 } __packed;
0084 
0085 /* The ES581.4 allows bulk transfer.  */
0086 struct es581_4_bulk_tx_can_msg {
0087     u8 num_can_msg;
0088     /* Using type "u8[]" instead of "struct es581_4_tx_can_msg[]"
0089      * for tx_msg_buf because each member has a flexible size.
0090      */
0091     u8 tx_can_msg_buf[ES581_4_TX_BULK_MAX *
0092               sizeof(struct es581_4_tx_can_msg)];
0093 } __packed;
0094 
0095 struct es581_4_echo_msg {
0096     __le64 timestamp;
0097     __le32 packet_idx;
0098 } __packed;
0099 
0100 struct es581_4_bulk_echo_msg {
0101     u8 channel_no;
0102     struct es581_4_echo_msg echo_msg[ES581_4_ECHO_BULK_MAX];
0103 } __packed;
0104 
0105 /* Normal Rx CAN Message */
0106 struct es581_4_rx_can_msg {
0107     __le64 timestamp;
0108     u8 rx_type;     /* type enum es581_4_rx_type */
0109     u8 flags;       /* type enum es58x_flag */
0110     u8 channel_no;
0111     u8 dlc;
0112     __le32 can_id;
0113     u8 data[CAN_MAX_DLEN];
0114 } __packed;
0115 
0116 struct es581_4_rx_err_msg {
0117     __le64 timestamp;
0118     __le16 rx_type;     /* type enum es581_4_rx_type */
0119     __le16 flags;       /* type enum es58x_flag */
0120     u8 channel_no;
0121     u8 __padding[2];
0122     u8 dlc;
0123     __le32 tag;     /* Related to the CAN filtering. Unused in this module */
0124     __le32 can_id;
0125     __le32 error;       /* type enum es58x_error */
0126     __le32 destination; /* Unused in this module */
0127 } __packed;
0128 
0129 struct es581_4_rx_event_msg {
0130     __le64 timestamp;
0131     __le16 rx_type;     /* type enum es581_4_rx_type */
0132     u8 channel_no;
0133     u8 __padding;
0134     __le32 tag;     /* Related to the CAN filtering. Unused in this module */
0135     __le32 event;       /* type enum es58x_event */
0136     __le32 destination; /* Unused in this module */
0137 } __packed;
0138 
0139 struct es581_4_tx_ack_msg {
0140     __le16 tx_free_entries; /* Number of remaining free entries in the device TX queue */
0141     u8 channel_no;
0142     u8 rx_cmd_ret_u8;   /* type enum es58x_cmd_ret_code_u8 */
0143 } __packed;
0144 
0145 struct es581_4_rx_cmd_ret {
0146     __le32 rx_cmd_ret_le32;
0147     u8 channel_no;
0148     u8 __padding[3];
0149 } __packed;
0150 
0151 /**
0152  * struct es581_4_urb_cmd - Commands received from or sent to the
0153  *  ES581.4 device.
0154  * @SOF: Start of Frame.
0155  * @cmd_type: Command Type (type: enum es581_4_cmd_type). The CRC
0156  *  calculation starts at this position.
0157  * @cmd_id: Command ID (type: enum es581_4_cmd_id).
0158  * @msg_len: Length of the message, excluding CRC (i.e. length of the
0159  *  union).
0160  * @tx_conf_msg: Channel configuration.
0161  * @bulk_tx_can_msg: Tx messages.
0162  * @rx_can_msg: Array of Rx messages.
0163  * @bulk_echo_msg: Tx message being looped back.
0164  * @rx_err_msg: Error message.
0165  * @rx_event_msg: Event message.
0166  * @tx_ack_msg: Tx acknowledgment message.
0167  * @rx_cmd_ret: Command return code.
0168  * @timestamp: Timestamp reply.
0169  * @rx_cmd_ret_u8: Rx 8 bits return code (type: enum
0170  *  es58x_cmd_ret_code_u8).
0171  * @raw_msg: Message raw payload.
0172  * @reserved_for_crc16_do_not_use: The structure ends with a
0173  *  CRC16. Because the structures in above union are of variable
0174  *  lengths, we can not predict the offset of the CRC in
0175  *  advance. Use functions es58x_get_crc() and es58x_set_crc() to
0176  *  manipulate it.
0177  */
0178 struct es581_4_urb_cmd {
0179     __le16 SOF;
0180     u8 cmd_type;
0181     u8 cmd_id;
0182     __le16 msg_len;
0183 
0184     union {
0185         struct es581_4_tx_conf_msg tx_conf_msg;
0186         struct es581_4_bulk_tx_can_msg bulk_tx_can_msg;
0187         struct es581_4_rx_can_msg rx_can_msg[ES581_4_RX_BULK_MAX];
0188         struct es581_4_bulk_echo_msg bulk_echo_msg;
0189         struct es581_4_rx_err_msg rx_err_msg;
0190         struct es581_4_rx_event_msg rx_event_msg;
0191         struct es581_4_tx_ack_msg tx_ack_msg;
0192         struct es581_4_rx_cmd_ret rx_cmd_ret;
0193         __le64 timestamp;
0194         u8 rx_cmd_ret_u8;
0195         DECLARE_FLEX_ARRAY(u8, raw_msg);
0196     } __packed;
0197 
0198     __le16 reserved_for_crc16_do_not_use;
0199 } __packed;
0200 
0201 #define ES581_4_URB_CMD_HEADER_LEN (offsetof(struct es581_4_urb_cmd, raw_msg))
0202 #define ES581_4_TX_URB_CMD_MAX_LEN                  \
0203     ES58X_SIZEOF_URB_CMD(struct es581_4_urb_cmd, bulk_tx_can_msg)
0204 #define ES581_4_RX_URB_CMD_MAX_LEN                  \
0205     ES58X_SIZEOF_URB_CMD(struct es581_4_urb_cmd, rx_can_msg)
0206 
0207 #endif /* __ES581_4_H__ */