1 // SPDX-License-Identifier: GPL-2.0 2 3 /* Driver for ETAS GmbH ES58X USB CAN(-FD) Bus Interfaces. 4 * 5 * File es58x_fd.c: Adds support to ETAS ES582.1 and ES584.1 (naming 6 * convention: we use the term "ES58X FD" when referring to those two 7 * variants together). 8 * 9 * Copyright (c) 2019 Robert Bosch Engineering and Business Solutions. All rights reserved. 10 * Copyright (c) 2020 ETAS K.K.. All rights reserved. 11 * Copyright (c) 2020, 2021 Vincent Mailhol <mailhol.vincent@wanadoo.fr> 12 */ 13 14 #include <linux/kernel.h> 15 #include <asm/unaligned.h> 16 17 #include "es58x_core.h" 18 #include "es58x_fd.h" 19 20 /** 21 * es58x_fd_sizeof_rx_tx_msg() - Calculate the actual length of the 22 * structure of a rx or tx message. 23 * @msg: message of variable length, must have a dlc and a len fields. 24 * 25 * Even if RTR frames have actually no payload, the ES58X devices 26 * still expect it. Must be a macro in order to accept several types 27 * (struct es58x_fd_tx_can_msg and struct es58x_fd_rx_can_msg) as an 28 * input. 29 * 30 * Return: length of the message. 31 */ 32 #define es58x_fd_sizeof_rx_tx_msg(msg) \ 33 ({ \ 34 typeof(msg) __msg = (msg); \ 35 size_t __msg_len; \ 36 \ 37 if (__msg.flags & ES58X_FLAG_FD_DATA) \ 38 __msg_len = canfd_sanitize_len(__msg.len); \ 39 else \ 40 __msg_len = can_cc_dlc2len(__msg.dlc); \ 41 \ 42 offsetof(typeof(__msg), data[__msg_len]); \ 43 }) 44 45 static enum es58x_fd_cmd_type es58x_fd_cmd_type(struct net_device *netdev) 46 { 47 u32 ctrlmode = es58x_priv(netdev)->can.ctrlmode; 48 49 if (ctrlmode & (CAN_CTRLMODE_FD | CAN_CTRLMODE_FD_NON_ISO)) 50 return ES58X_FD_CMD_TYPE_CANFD; 51 else 52 return ES58X_FD_CMD_TYPE_CAN; 53 } 54 55 static u16 es58x_fd_get_msg_len(const union es58x_urb_cmd *urb_cmd) 56 { 57 return get_unaligned_le16(&urb_cmd->es58x_fd_urb_cmd.msg_len); 58 } 59 60 static int es58x_fd_echo_msg(struct net_device *netdev, 61 const struct es58x_fd_urb_cmd *es58x_fd_urb_cmd) 62 { 63 struct es58x_priv *priv = es58x_priv(netdev); 64 const struct es58x_fd_echo_msg *echo_msg; 65 struct es58x_device *es58x_dev = priv->es58x_dev; 66 u64 *tstamps = es58x_dev->timestamps; 67 u16 msg_len = get_unaligned_le16(&es58x_fd_urb_cmd->msg_len); 68 int i, num_element; 69 u32 rcv_packet_idx; 70 71 const u32 mask = GENMASK(31, sizeof(echo_msg->packet_idx) * 8); 72 73 num_element = es58x_msg_num_element(es58x_dev->dev, 74 es58x_fd_urb_cmd->echo_msg, 75 msg_len); 76 if (num_element < 0) 77 return num_element; 78 echo_msg = es58x_fd_urb_cmd->echo_msg; 79 80 rcv_packet_idx = (priv->tx_tail & mask) | echo_msg[0].packet_idx; 81 for (i = 0; i < num_element; i++) { 82 if ((u8)rcv_packet_idx != echo_msg[i].packet_idx) { 83 netdev_err(netdev, "Packet idx jumped from %u to %u\n", 84 (u8)rcv_packet_idx - 1, 85 echo_msg[i].packet_idx); 86 return -EBADMSG; 87 } 88 89 tstamps[i] = get_unaligned_le64(&echo_msg[i].timestamp); 90 rcv_packet_idx++; 91 } 92 93 return es58x_can_get_echo_skb(netdev, priv->tx_tail, tstamps, num_element); 94 } 95 96 static int es58x_fd_rx_can_msg(struct net_device *netdev, 97 const struct es58x_fd_urb_cmd *es58x_fd_urb_cmd) 98 { 99 struct es58x_device *es58x_dev = es58x_priv(netdev)->es58x_dev; 100 const u8 *rx_can_msg_buf = es58x_fd_urb_cmd->rx_can_msg_buf; 101 u16 rx_can_msg_buf_len = get_unaligned_le16(&es58x_fd_urb_cmd->msg_len); 102 int pkts, ret; 103 104 ret = es58x_check_msg_max_len(es58x_dev->dev, 105 es58x_fd_urb_cmd->rx_can_msg_buf, 106 rx_can_msg_buf_len); 107 if (ret) 108 return ret; 109 110 for (pkts = 0; rx_can_msg_buf_len > 0; pkts++) { 111 const struct es58x_fd_rx_can_msg *rx_can_msg = 112 (const struct es58x_fd_rx_can_msg *)rx_can_msg_buf; 113 bool is_can_fd = !!(rx_can_msg->flags & ES58X_FLAG_FD_DATA); 114 /* rx_can_msg_len is the length of the rx_can_msg 115 * buffer. Not to be confused with rx_can_msg->len 116 * which is the length of the CAN payload 117 * rx_can_msg->data. 118 */ 119 u16 rx_can_msg_len = es58x_fd_sizeof_rx_tx_msg(*rx_can_msg); 120 121 if (rx_can_msg_len > rx_can_msg_buf_len) { 122 netdev_err(netdev, 123 "%s: Expected a rx_can_msg of size %d but only %d bytes are left in rx_can_msg_buf\n", 124 __func__, 125 rx_can_msg_len, rx_can_msg_buf_len); 126 return -EMSGSIZE; 127 } 128 if (rx_can_msg->len > CANFD_MAX_DLEN) { 129 netdev_err(netdev, 130 "%s: Data length is %d but maximum should be %d\n", 131 __func__, rx_can_msg->len, CANFD_MAX_DLEN); 132 return -EMSGSIZE; 133 } 134 135 if (netif_running(netdev)) { 136 u64 tstamp = get_unaligned_le64(&rx_can_msg->timestamp); 137 canid_t can_id = get_unaligned_le32(&rx_can_msg->can_id); 138 u8 dlc; 139 140 if (is_can_fd) 141 dlc = can_fd_len2dlc(rx_can_msg->len); 142 else 143 dlc = rx_can_msg->dlc; 144 145 ret = es58x_rx_can_msg(netdev, tstamp, rx_can_msg->data, 146 can_id, rx_can_msg->flags, dlc); 147 if (ret) 148 break; 149 } 150 151 rx_can_msg_buf_len -= rx_can_msg_len; 152 rx_can_msg_buf += rx_can_msg_len; 153 } 154 155 if (!netif_running(netdev)) { 156 if (net_ratelimit()) 157 netdev_info(netdev, 158 "%s: %s is down, dropping %d rx packets\n", 159 __func__, netdev->name, pkts); 160 netdev->stats.rx_dropped += pkts; 161 } 162 163 return ret; 164 } 165 166 static int es58x_fd_rx_event_msg(struct net_device *netdev, 167 const struct es58x_fd_urb_cmd *es58x_fd_urb_cmd) 168 { 169 struct es58x_device *es58x_dev = es58x_priv(netdev)->es58x_dev; 170 u16 msg_len = get_unaligned_le16(&es58x_fd_urb_cmd->msg_len); 171 const struct es58x_fd_rx_event_msg *rx_event_msg; 172 int ret; 173 174 ret = es58x_check_msg_len(es58x_dev->dev, *rx_event_msg, msg_len); 175 if (ret) 176 return ret; 177 178 rx_event_msg = &es58x_fd_urb_cmd->rx_event_msg; 179 180 return es58x_rx_err_msg(netdev, rx_event_msg->error_code, 181 rx_event_msg->event_code, 182 get_unaligned_le64(&rx_event_msg->timestamp)); 183 } 184 185 static int es58x_fd_rx_cmd_ret_u32(struct net_device *netdev, 186 const struct es58x_fd_urb_cmd *es58x_fd_urb_cmd, 187 enum es58x_ret_type cmd_ret_type) 188 { 189 struct es58x_device *es58x_dev = es58x_priv(netdev)->es58x_dev; 190 u16 msg_len = get_unaligned_le16(&es58x_fd_urb_cmd->msg_len); 191 int ret; 192 193 ret = es58x_check_msg_len(es58x_dev->dev, 194 es58x_fd_urb_cmd->rx_cmd_ret_le32, msg_len); 195 if (ret) 196 return ret; 197 198 return es58x_rx_cmd_ret_u32(netdev, cmd_ret_type, 199 get_unaligned_le32(&es58x_fd_urb_cmd->rx_cmd_ret_le32)); 200 } 201 202 static int es58x_fd_tx_ack_msg(struct net_device *netdev, 203 const struct es58x_fd_urb_cmd *es58x_fd_urb_cmd) 204 { 205 struct es58x_device *es58x_dev = es58x_priv(netdev)->es58x_dev; 206 const struct es58x_fd_tx_ack_msg *tx_ack_msg; 207 u16 msg_len = get_unaligned_le16(&es58x_fd_urb_cmd->msg_len); 208 int ret; 209 210 tx_ack_msg = &es58x_fd_urb_cmd->tx_ack_msg; 211 ret = es58x_check_msg_len(es58x_dev->dev, *tx_ack_msg, msg_len); 212 if (ret) 213 return ret; 214 215 return es58x_tx_ack_msg(netdev, 216 get_unaligned_le16(&tx_ack_msg->tx_free_entries), 217 get_unaligned_le32(&tx_ack_msg->rx_cmd_ret_le32)); 218 } 219 220 static int es58x_fd_can_cmd_id(struct es58x_device *es58x_dev, 221 const struct es58x_fd_urb_cmd *es58x_fd_urb_cmd) 222 { 223 struct net_device *netdev; 224 int ret; 225 226 ret = es58x_get_netdev(es58x_dev, es58x_fd_urb_cmd->channel_idx, 227 ES58X_FD_CHANNEL_IDX_OFFSET, &netdev); 228 if (ret) 229 return ret; 230 231 switch ((enum es58x_fd_can_cmd_id)es58x_fd_urb_cmd->cmd_id) { 232 case ES58X_FD_CAN_CMD_ID_ENABLE_CHANNEL: 233 return es58x_fd_rx_cmd_ret_u32(netdev, es58x_fd_urb_cmd, 234 ES58X_RET_TYPE_ENABLE_CHANNEL); 235 236 case ES58X_FD_CAN_CMD_ID_DISABLE_CHANNEL: 237 return es58x_fd_rx_cmd_ret_u32(netdev, es58x_fd_urb_cmd, 238 ES58X_RET_TYPE_DISABLE_CHANNEL); 239 240 case ES58X_FD_CAN_CMD_ID_TX_MSG: 241 return es58x_fd_tx_ack_msg(netdev, es58x_fd_urb_cmd); 242 243 case ES58X_FD_CAN_CMD_ID_ECHO_MSG: 244 return es58x_fd_echo_msg(netdev, es58x_fd_urb_cmd); 245 246 case ES58X_FD_CAN_CMD_ID_RX_MSG: 247 return es58x_fd_rx_can_msg(netdev, es58x_fd_urb_cmd); 248 249 case ES58X_FD_CAN_CMD_ID_RESET_RX: 250 return es58x_fd_rx_cmd_ret_u32(netdev, es58x_fd_urb_cmd, 251 ES58X_RET_TYPE_RESET_RX); 252 253 case ES58X_FD_CAN_CMD_ID_RESET_TX: 254 return es58x_fd_rx_cmd_ret_u32(netdev, es58x_fd_urb_cmd, 255 ES58X_RET_TYPE_RESET_TX); 256 257 case ES58X_FD_CAN_CMD_ID_ERROR_OR_EVENT_MSG: 258 return es58x_fd_rx_event_msg(netdev, es58x_fd_urb_cmd); 259 260 default: 261 return -EBADRQC; 262 } 263 } 264 265 static int es58x_fd_device_cmd_id(struct es58x_device *es58x_dev, 266 const struct es58x_fd_urb_cmd *es58x_fd_urb_cmd) 267 { 268 u16 msg_len = get_unaligned_le16(&es58x_fd_urb_cmd->msg_len); 269 int ret; 270 271 switch ((enum es58x_fd_dev_cmd_id)es58x_fd_urb_cmd->cmd_id) { 272 case ES58X_FD_DEV_CMD_ID_TIMESTAMP: 273 ret = es58x_check_msg_len(es58x_dev->dev, 274 es58x_fd_urb_cmd->timestamp, msg_len); 275 if (ret) 276 return ret; 277 es58x_rx_timestamp(es58x_dev, 278 get_unaligned_le64(&es58x_fd_urb_cmd->timestamp)); 279 return 0; 280 281 default: 282 return -EBADRQC; 283 } 284 } 285 286 static int es58x_fd_handle_urb_cmd(struct es58x_device *es58x_dev, 287 const union es58x_urb_cmd *urb_cmd) 288 { 289 const struct es58x_fd_urb_cmd *es58x_fd_urb_cmd; 290 int ret; 291 292 es58x_fd_urb_cmd = &urb_cmd->es58x_fd_urb_cmd; 293 294 switch ((enum es58x_fd_cmd_type)es58x_fd_urb_cmd->cmd_type) { 295 case ES58X_FD_CMD_TYPE_CAN: 296 case ES58X_FD_CMD_TYPE_CANFD: 297 ret = es58x_fd_can_cmd_id(es58x_dev, es58x_fd_urb_cmd); 298 break; 299 300 case ES58X_FD_CMD_TYPE_DEVICE: 301 ret = es58x_fd_device_cmd_id(es58x_dev, es58x_fd_urb_cmd); 302 break; 303 304 default: 305 ret = -EBADRQC; 306 break; 307 } 308 309 if (ret == -EBADRQC) 310 dev_err(es58x_dev->dev, 311 "%s: Unknown command type (0x%02X) and command ID (0x%02X) combination\n", 312 __func__, es58x_fd_urb_cmd->cmd_type, 313 es58x_fd_urb_cmd->cmd_id); 314 315 return ret; 316 } 317 318 static void es58x_fd_fill_urb_header(union es58x_urb_cmd *urb_cmd, u8 cmd_type, 319 u8 cmd_id, u8 channel_idx, u16 msg_len) 320 { 321 struct es58x_fd_urb_cmd *es58x_fd_urb_cmd = &urb_cmd->es58x_fd_urb_cmd; 322 323 es58x_fd_urb_cmd->SOF = cpu_to_le16(es58x_fd_param.tx_start_of_frame); 324 es58x_fd_urb_cmd->cmd_type = cmd_type; 325 es58x_fd_urb_cmd->cmd_id = cmd_id; 326 es58x_fd_urb_cmd->channel_idx = channel_idx; 327 es58x_fd_urb_cmd->msg_len = cpu_to_le16(msg_len); 328 } 329 330 static int es58x_fd_tx_can_msg(struct es58x_priv *priv, 331 const struct sk_buff *skb) 332 { 333 struct es58x_device *es58x_dev = priv->es58x_dev; 334 union es58x_urb_cmd *urb_cmd = priv->tx_urb->transfer_buffer; 335 struct es58x_fd_urb_cmd *es58x_fd_urb_cmd = &urb_cmd->es58x_fd_urb_cmd; 336 struct can_frame *cf = (struct can_frame *)skb->data; 337 struct es58x_fd_tx_can_msg *tx_can_msg; 338 bool is_fd = can_is_canfd_skb(skb); 339 u16 msg_len; 340 int ret; 341 342 if (priv->tx_can_msg_cnt == 0) { 343 msg_len = 0; 344 es58x_fd_fill_urb_header(urb_cmd, 345 is_fd ? ES58X_FD_CMD_TYPE_CANFD 346 : ES58X_FD_CMD_TYPE_CAN, 347 ES58X_FD_CAN_CMD_ID_TX_MSG_NO_ACK, 348 priv->channel_idx, msg_len); 349 } else { 350 msg_len = es58x_fd_get_msg_len(urb_cmd); 351 } 352 353 ret = es58x_check_msg_max_len(es58x_dev->dev, 354 es58x_fd_urb_cmd->tx_can_msg_buf, 355 msg_len + sizeof(*tx_can_msg)); 356 if (ret) 357 return ret; 358 359 /* Fill message contents. */ 360 tx_can_msg = (typeof(tx_can_msg))&es58x_fd_urb_cmd->raw_msg[msg_len]; 361 tx_can_msg->packet_idx = (u8)priv->tx_head; 362 put_unaligned_le32(es58x_get_raw_can_id(cf), &tx_can_msg->can_id); 363 tx_can_msg->flags = (u8)es58x_get_flags(skb); 364 if (is_fd) 365 tx_can_msg->len = cf->len; 366 else 367 tx_can_msg->dlc = can_get_cc_dlc(cf, priv->can.ctrlmode); 368 memcpy(tx_can_msg->data, cf->data, cf->len); 369 370 /* Calculate new sizes */ 371 msg_len += es58x_fd_sizeof_rx_tx_msg(*tx_can_msg); 372 priv->tx_urb->transfer_buffer_length = es58x_get_urb_cmd_len(es58x_dev, 373 msg_len); 374 put_unaligned_le16(msg_len, &es58x_fd_urb_cmd->msg_len); 375 376 return 0; 377 } 378 379 static void es58x_fd_convert_bittiming(struct es58x_fd_bittiming *es58x_fd_bt, 380 struct can_bittiming *bt) 381 { 382 /* The actual value set in the hardware registers is one less 383 * than the functional value. 384 */ 385 const int offset = 1; 386 387 es58x_fd_bt->bitrate = cpu_to_le32(bt->bitrate); 388 es58x_fd_bt->tseg1 = 389 cpu_to_le16(bt->prop_seg + bt->phase_seg1 - offset); 390 es58x_fd_bt->tseg2 = cpu_to_le16(bt->phase_seg2 - offset); 391 es58x_fd_bt->brp = cpu_to_le16(bt->brp - offset); 392 es58x_fd_bt->sjw = cpu_to_le16(bt->sjw - offset); 393 } 394 395 static int es58x_fd_enable_channel(struct es58x_priv *priv) 396 { 397 struct es58x_device *es58x_dev = priv->es58x_dev; 398 struct net_device *netdev = es58x_dev->netdev[priv->channel_idx]; 399 struct es58x_fd_tx_conf_msg tx_conf_msg = { 0 }; 400 u32 ctrlmode; 401 size_t conf_len = 0; 402 403 es58x_fd_convert_bittiming(&tx_conf_msg.nominal_bittiming, 404 &priv->can.bittiming); 405 ctrlmode = priv->can.ctrlmode; 406 407 if (ctrlmode & CAN_CTRLMODE_3_SAMPLES) 408 tx_conf_msg.samples_per_bit = ES58X_SAMPLES_PER_BIT_THREE; 409 else 410 tx_conf_msg.samples_per_bit = ES58X_SAMPLES_PER_BIT_ONE; 411 tx_conf_msg.sync_edge = ES58X_SYNC_EDGE_SINGLE; 412 tx_conf_msg.physical_layer = ES58X_PHYSICAL_LAYER_HIGH_SPEED; 413 tx_conf_msg.echo_mode = ES58X_ECHO_ON; 414 if (ctrlmode & CAN_CTRLMODE_LISTENONLY) 415 tx_conf_msg.ctrlmode |= ES58X_FD_CTRLMODE_PASSIVE; 416 else 417 tx_conf_msg.ctrlmode |= ES58X_FD_CTRLMODE_ACTIVE; 418 419 if (ctrlmode & CAN_CTRLMODE_FD_NON_ISO) { 420 tx_conf_msg.ctrlmode |= ES58X_FD_CTRLMODE_FD_NON_ISO; 421 tx_conf_msg.canfd_enabled = 1; 422 } else if (ctrlmode & CAN_CTRLMODE_FD) { 423 tx_conf_msg.ctrlmode |= ES58X_FD_CTRLMODE_FD; 424 tx_conf_msg.canfd_enabled = 1; 425 } 426 427 if (tx_conf_msg.canfd_enabled) { 428 es58x_fd_convert_bittiming(&tx_conf_msg.data_bittiming, 429 &priv->can.data_bittiming); 430 431 if (priv->can.tdc.tdco) { 432 tx_conf_msg.tdc_enabled = 1; 433 tx_conf_msg.tdco = cpu_to_le16(priv->can.tdc.tdco); 434 tx_conf_msg.tdcf = cpu_to_le16(priv->can.tdc.tdcf); 435 } 436 437 conf_len = ES58X_FD_CANFD_CONF_LEN; 438 } else { 439 conf_len = ES58X_FD_CAN_CONF_LEN; 440 } 441 442 return es58x_send_msg(es58x_dev, es58x_fd_cmd_type(netdev), 443 ES58X_FD_CAN_CMD_ID_ENABLE_CHANNEL, 444 &tx_conf_msg, conf_len, priv->channel_idx); 445 } 446 447 static int es58x_fd_disable_channel(struct es58x_priv *priv) 448 { 449 /* The type (ES58X_FD_CMD_TYPE_CAN or ES58X_FD_CMD_TYPE_CANFD) does 450 * not matter here. 451 */ 452 return es58x_send_msg(priv->es58x_dev, ES58X_FD_CMD_TYPE_CAN, 453 ES58X_FD_CAN_CMD_ID_DISABLE_CHANNEL, 454 ES58X_EMPTY_MSG, 0, priv->channel_idx); 455 } 456 457 static int es58x_fd_get_timestamp(struct es58x_device *es58x_dev) 458 { 459 return es58x_send_msg(es58x_dev, ES58X_FD_CMD_TYPE_DEVICE, 460 ES58X_FD_DEV_CMD_ID_TIMESTAMP, ES58X_EMPTY_MSG, 461 0, ES58X_CHANNEL_IDX_NA); 462 } 463 464 /* Nominal bittiming constants for ES582.1 and ES584.1 as specified in 465 * the microcontroller datasheet: "SAM E70/S70/V70/V71 Family" section 466 * 49.6.8 "MCAN Nominal Bit Timing and Prescaler Register" from 467 * Microchip. 468 * 469 * The values from the specification are the hardware register 470 * values. To convert them to the functional values, all ranges were 471 * incremented by 1 (e.g. range [0..n-1] changed to [1..n]). 472 */ 473 static const struct can_bittiming_const es58x_fd_nom_bittiming_const = { 474 .name = "ES582.1/ES584.1", 475 .tseg1_min = 2, 476 .tseg1_max = 256, 477 .tseg2_min = 2, 478 .tseg2_max = 128, 479 .sjw_max = 128, 480 .brp_min = 1, 481 .brp_max = 512, 482 .brp_inc = 1 483 }; 484 485 /* Data bittiming constants for ES582.1 and ES584.1 as specified in 486 * the microcontroller datasheet: "SAM E70/S70/V70/V71 Family" section 487 * 49.6.4 "MCAN Data Bit Timing and Prescaler Register" from 488 * Microchip. 489 */ 490 static const struct can_bittiming_const es58x_fd_data_bittiming_const = { 491 .name = "ES582.1/ES584.1", 492 .tseg1_min = 2, 493 .tseg1_max = 32, 494 .tseg2_min = 1, 495 .tseg2_max = 16, 496 .sjw_max = 8, 497 .brp_min = 1, 498 .brp_max = 32, 499 .brp_inc = 1 500 }; 501 502 /* Transmission Delay Compensation constants for ES582.1 and ES584.1 503 * as specified in the microcontroller datasheet: "SAM E70/S70/V70/V71 504 * Family" section 49.6.15 "MCAN Transmitter Delay Compensation 505 * Register" from Microchip. 506 */ 507 static const struct can_tdc_const es58x_tdc_const = { 508 .tdcv_max = 0, /* Manual mode not supported. */ 509 .tdco_max = 127, 510 .tdcf_max = 127 511 }; 512 513 const struct es58x_parameters es58x_fd_param = { 514 .bittiming_const = &es58x_fd_nom_bittiming_const, 515 .data_bittiming_const = &es58x_fd_data_bittiming_const, 516 .tdc_const = &es58x_tdc_const, 517 /* The devices use NXP TJA1044G transievers which guarantee 518 * the timing for data rates up to 5 Mbps. Bitrates up to 8 519 * Mbps work in an optimal environment but are not recommended 520 * for production environment. 521 */ 522 .bitrate_max = 8 * CAN_MBPS, 523 .clock = {.freq = 80 * CAN_MHZ}, 524 .ctrlmode_supported = CAN_CTRLMODE_LOOPBACK | CAN_CTRLMODE_LISTENONLY | 525 CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_FD | CAN_CTRLMODE_FD_NON_ISO | 526 CAN_CTRLMODE_CC_LEN8_DLC, 527 .tx_start_of_frame = 0xCEFA, /* FACE in little endian */ 528 .rx_start_of_frame = 0xFECA, /* CAFE in little endian */ 529 .tx_urb_cmd_max_len = ES58X_FD_TX_URB_CMD_MAX_LEN, 530 .rx_urb_cmd_max_len = ES58X_FD_RX_URB_CMD_MAX_LEN, 531 /* Size of internal device TX queue is 500. 532 * 533 * However, when reaching value around 278, the device's busy 534 * LED turns on and thus maximum value of 500 is never reached 535 * in practice. Also, when this value is too high, some error 536 * on the echo_msg were witnessed when the device is 537 * recovering from bus off. 538 * 539 * For above reasons, a value that would prevent the device 540 * from becoming busy was chosen. In practice, BQL would 541 * prevent the value from even getting closer to below 542 * maximum, so no impact on performance was measured. 543 */ 544 .fifo_mask = 255, /* echo_skb_max = 256 */ 545 .dql_min_limit = CAN_FRAME_LEN_MAX * 15, /* Empirical value. */ 546 .tx_bulk_max = ES58X_FD_TX_BULK_MAX, 547 .urb_cmd_header_len = ES58X_FD_URB_CMD_HEADER_LEN, 548 .rx_urb_max = ES58X_RX_URBS_MAX, 549 .tx_urb_max = ES58X_TX_URBS_MAX 550 }; 551 552 const struct es58x_operators es58x_fd_ops = { 553 .get_msg_len = es58x_fd_get_msg_len, 554 .handle_urb_cmd = es58x_fd_handle_urb_cmd, 555 .fill_urb_header = es58x_fd_fill_urb_header, 556 .tx_can_msg = es58x_fd_tx_can_msg, 557 .enable_channel = es58x_fd_enable_channel, 558 .disable_channel = es58x_fd_disable_channel, 559 .reset_device = NULL, /* Not implemented in the device firmware. */ 560 .get_timestamp = es58x_fd_get_timestamp 561 }; 562