0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
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
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
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
0086 struct es581_4_bulk_tx_can_msg {
0087 u8 num_can_msg;
0088
0089
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
0106 struct es581_4_rx_can_msg {
0107 __le64 timestamp;
0108 u8 rx_type;
0109 u8 flags;
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;
0119 __le16 flags;
0120 u8 channel_no;
0121 u8 __padding[2];
0122 u8 dlc;
0123 __le32 tag;
0124 __le32 can_id;
0125 __le32 error;
0126 __le32 destination;
0127 } __packed;
0128
0129 struct es581_4_rx_event_msg {
0130 __le64 timestamp;
0131 __le16 rx_type;
0132 u8 channel_no;
0133 u8 __padding;
0134 __le32 tag;
0135 __le32 event;
0136 __le32 destination;
0137 } __packed;
0138
0139 struct es581_4_tx_ack_msg {
0140 __le16 tx_free_entries;
0141 u8 channel_no;
0142 u8 rx_cmd_ret_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
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
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