| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#ifndef __ES58X_FD_H__ |
| 15 |
#define __ES58X_FD_H__ |
| 16 |
|
| 17 |
#include <linux/types.h> |
| 18 |
|
| 19 |
#define ES582_1_NUM_CAN_CH 2 |
| 20 |
#define ES584_1_NUM_CAN_CH 1 |
| 21 |
#define ES58X_FD_NUM_CAN_CH 2 |
| 22 |
#define ES58X_FD_CHANNEL_IDX_OFFSET 0 |
| 23 |
|
| 24 |
#define ES58X_FD_TX_BULK_MAX 100 |
| 25 |
#define ES58X_FD_RX_BULK_MAX 100 |
| 26 |
#define ES58X_FD_ECHO_BULK_MAX 100 |
| 27 |
|
| 28 |
enum es58x_fd_cmd_type { |
| 29 |
ES58X_FD_CMD_TYPE_CAN = 0x03, |
| 30 |
ES58X_FD_CMD_TYPE_CANFD = 0x04, |
| 31 |
ES58X_FD_CMD_TYPE_DEVICE = 0xFF |
| 32 |
}; |
| 33 |
|
| 34 |
|
| 35 |
enum es58x_fd_can_cmd_id { |
| 36 |
ES58X_FD_CAN_CMD_ID_ENABLE_CHANNEL = 0x01, |
| 37 |
ES58X_FD_CAN_CMD_ID_DISABLE_CHANNEL = 0x02, |
| 38 |
ES58X_FD_CAN_CMD_ID_TX_MSG = 0x05, |
| 39 |
ES58X_FD_CAN_CMD_ID_ECHO_MSG = 0x07, |
| 40 |
ES58X_FD_CAN_CMD_ID_RX_MSG = 0x10, |
| 41 |
ES58X_FD_CAN_CMD_ID_ERROR_OR_EVENT_MSG = 0x11, |
| 42 |
ES58X_FD_CAN_CMD_ID_RESET_RX = 0x20, |
| 43 |
ES58X_FD_CAN_CMD_ID_RESET_TX = 0x21, |
| 44 |
ES58X_FD_CAN_CMD_ID_TX_MSG_NO_ACK = 0x55 |
| 45 |
}; |
| 46 |
|
| 47 |
|
| 48 |
enum es58x_fd_dev_cmd_id { |
| 49 |
ES58X_FD_DEV_CMD_ID_GETTIMETICKS = 0x01, |
| 50 |
ES58X_FD_DEV_CMD_ID_TIMESTAMP = 0x02 |
| 51 |
}; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
enum es58x_fd_ctrlmode { |
| 73 |
ES58X_FD_CTRLMODE_ACTIVE = 0, |
| 74 |
ES58X_FD_CTRLMODE_PASSIVE = BIT(0), |
| 75 |
ES58X_FD_CTRLMODE_FD = BIT(4), |
| 76 |
ES58X_FD_CTRLMODE_FD_NON_ISO = BIT(5), |
| 77 |
ES58X_FD_CTRLMODE_DISABLE_PROTOCOL_EXCEPTION_HANDLING = BIT(6), |
| 78 |
ES58X_FD_CTRLMODE_EDGE_FILTER_DURING_BUS_INTEGRATION = BIT(7) |
| 79 |
}; |
| 80 |
|
| 81 |
struct es58x_fd_bittiming { |
| 82 |
__le32 bitrate; |
| 83 |
__le16 tseg1; |
| 84 |
__le16 tseg2; |
| 85 |
__le16 brp; |
| 86 |
__le16 sjw; |
| 87 |
} __packed; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
struct es58x_fd_tx_conf_msg { |
| 109 |
struct es58x_fd_bittiming nominal_bittiming; |
| 110 |
u8 samples_per_bit; |
| 111 |
u8 sync_edge; |
| 112 |
u8 physical_layer; |
| 113 |
u8 echo_mode; |
| 114 |
u8 ctrlmode; |
| 115 |
u8 canfd_enabled; |
| 116 |
struct es58x_fd_bittiming data_bittiming; |
| 117 |
u8 tdc_enabled; |
| 118 |
__le16 tdco; |
| 119 |
__le16 tdcf; |
| 120 |
} __packed; |
| 121 |
|
| 122 |
#define ES58X_FD_CAN_CONF_LEN \ |
| 123 |
(offsetof(struct es58x_fd_tx_conf_msg, canfd_enabled)) |
| 124 |
#define ES58X_FD_CANFD_CONF_LEN (sizeof(struct es58x_fd_tx_conf_msg)) |
| 125 |
|
| 126 |
struct es58x_fd_tx_can_msg { |
| 127 |
u8 packet_idx; |
| 128 |
__le32 can_id; |
| 129 |
u8 flags; |
| 130 |
union { |
| 131 |
u8 dlc; |
| 132 |
u8 len; |
| 133 |
} __packed; |
| 134 |
u8 data[CANFD_MAX_DLEN]; |
| 135 |
} __packed; |
| 136 |
|
| 137 |
#define ES58X_FD_CAN_TX_LEN \ |
| 138 |
(offsetof(struct es58x_fd_tx_can_msg, data[CAN_MAX_DLEN])) |
| 139 |
#define ES58X_FD_CANFD_TX_LEN (sizeof(struct es58x_fd_tx_can_msg)) |
| 140 |
|
| 141 |
struct es58x_fd_rx_can_msg { |
| 142 |
__le64 timestamp; |
| 143 |
__le32 can_id; |
| 144 |
u8 flags; |
| 145 |
union { |
| 146 |
u8 dlc; |
| 147 |
u8 len; |
| 148 |
} __packed; |
| 149 |
u8 data[CANFD_MAX_DLEN]; |
| 150 |
} __packed; |
| 151 |
|
| 152 |
#define ES58X_FD_CAN_RX_LEN \ |
| 153 |
(offsetof(struct es58x_fd_rx_can_msg, data[CAN_MAX_DLEN])) |
| 154 |
#define ES58X_FD_CANFD_RX_LEN (sizeof(struct es58x_fd_rx_can_msg)) |
| 155 |
|
| 156 |
struct es58x_fd_echo_msg { |
| 157 |
__le64 timestamp; |
| 158 |
u8 packet_idx; |
| 159 |
} __packed; |
| 160 |
|
| 161 |
struct es58x_fd_rx_event_msg { |
| 162 |
__le64 timestamp; |
| 163 |
__le32 can_id; |
| 164 |
u8 flags; |
| 165 |
u8 error_type; |
| 166 |
u8 error_code; |
| 167 |
u8 event_code; |
| 168 |
} __packed; |
| 169 |
|
| 170 |
struct es58x_fd_tx_ack_msg { |
| 171 |
__le32 rx_cmd_ret_le32; |
| 172 |
__le16 tx_free_entries; |
| 173 |
} __packed; |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
struct es58x_fd_urb_cmd { |
| 207 |
__le16 SOF; |
| 208 |
u8 cmd_type; |
| 209 |
u8 cmd_id; |
| 210 |
u8 channel_idx; |
| 211 |
__le16 msg_len; |
| 212 |
|
| 213 |
union { |
| 214 |
struct es58x_fd_tx_conf_msg tx_conf_msg; |
| 215 |
u8 tx_can_msg_buf[ES58X_FD_TX_BULK_MAX * ES58X_FD_CANFD_TX_LEN]; |
| 216 |
u8 rx_can_msg_buf[ES58X_FD_RX_BULK_MAX * ES58X_FD_CANFD_RX_LEN]; |
| 217 |
struct es58x_fd_echo_msg echo_msg[ES58X_FD_ECHO_BULK_MAX]; |
| 218 |
struct es58x_fd_rx_event_msg rx_event_msg; |
| 219 |
struct es58x_fd_tx_ack_msg tx_ack_msg; |
| 220 |
__le64 timestamp; |
| 221 |
__le32 rx_cmd_ret_le32; |
| 222 |
DECLARE_FLEX_ARRAY(u8, raw_msg); |
| 223 |
} __packed; |
| 224 |
|
| 225 |
__le16 reserved_for_crc16_do_not_use; |
| 226 |
} __packed; |
| 227 |
|
| 228 |
#define ES58X_FD_URB_CMD_HEADER_LEN (offsetof(struct es58x_fd_urb_cmd, raw_msg)) |
| 229 |
#define ES58X_FD_TX_URB_CMD_MAX_LEN \ |
| 230 |
ES58X_SIZEOF_URB_CMD(struct es58x_fd_urb_cmd, tx_can_msg_buf) |
| 231 |
#define ES58X_FD_RX_URB_CMD_MAX_LEN \ |
| 232 |
ES58X_SIZEOF_URB_CMD(struct es58x_fd_urb_cmd, rx_can_msg_buf) |
| 233 |
|
| 234 |
#endif |