Lines Matching +full:usb +full:- +full:version

1 // SPDX-License-Identifier: GPL-2.0-only
3 * CAN driver for esd electronics gmbh CAN-USB/2, CAN-USB/3 and CAN-USB/Micro
5 * Copyright (C) 2010-2012 esd electronic system design gmbh, Matthias Fuchs <socketcan@esd.eu>
6 * Copyright (C) 2022-2024 esd electronics gmbh, Frank Jungclaus <frank.jungclaus@esd.eu>
18 #include <linux/usb.h>
22 MODULE_DESCRIPTION("CAN driver for esd electronics gmbh CAN-USB/2, CAN-USB/3 and CAN-USB/Micro inte…
25 /* USB vendor and product ID */
39 /* USB commands */
47 /* esd CAN message flags - dlc field */
53 /* esd CAN message flags - id field */
66 /* bit timing esd CAN-USB */
80 /* SJA1000 ECC register (emulated by usb firmware) */
99 /* Modes for CAN-USB/3, to be used for esd_usb_3_set_baudrate_msg_x.mode */
107 /* Flags for CAN-USB/3, to be used for esd_usb_3_set_baudrate_msg_x.flags */
133 __le32 version; member
196 /* CAN-USB/3 baudrate configuration, used for nominal as well as for data bit rate */
198 __le16 brp; /* bit rate pre-scaler */
204 /* In principle, the esd CAN-USB/3 supports Transmitter Delay Compensation (TDC),
219 /* Extended version of the above set_baudrate_msg for a CAN-USB/3
243 struct esd_usb_version_msg version; member
259 MODULE_DEVICE_TABLE(usb, esd_usb_table);
275 u32 version; member
288 struct esd_usb *usb; member
298 struct net_device_stats *stats = &priv->netdev->stats; in esd_usb_rx_event()
301 u32 id = le32_to_cpu(msg->rx.id) & ESD_USB_IDMASK; in esd_usb_rx_event()
304 u8 state = msg->rx.ev_can_err_ext.status; in esd_usb_rx_event()
305 u8 ecc = msg->rx.ev_can_err_ext.ecc; in esd_usb_rx_event()
307 priv->bec.rxerr = msg->rx.ev_can_err_ext.rec; in esd_usb_rx_event()
308 priv->bec.txerr = msg->rx.ev_can_err_ext.tec; in esd_usb_rx_event()
310 netdev_dbg(priv->netdev, in esd_usb_rx_event()
312 msg->rx.dlc, state, ecc, in esd_usb_rx_event()
313 priv->bec.rxerr, priv->bec.txerr); in esd_usb_rx_event()
315 /* if berr-reporting is off, only pass through on state change ... */ in esd_usb_rx_event()
316 if (!(priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) && in esd_usb_rx_event()
317 state == priv->old_state) in esd_usb_rx_event()
320 skb = alloc_can_err_skb(priv->netdev, &cf); in esd_usb_rx_event()
322 stats->rx_dropped++; in esd_usb_rx_event()
324 if (state != priv->old_state) { in esd_usb_rx_event()
328 priv->old_state = state; in esd_usb_rx_event()
333 can_bus_off(priv->netdev); in esd_usb_rx_event()
343 priv->bec.txerr = 0; in esd_usb_rx_event()
344 priv->bec.rxerr = 0; in esd_usb_rx_event()
348 if (new_state != priv->can.state) { in esd_usb_rx_event()
349 tx_state = (priv->bec.txerr >= priv->bec.rxerr) ? new_state : 0; in esd_usb_rx_event()
350 rx_state = (priv->bec.txerr <= priv->bec.rxerr) ? new_state : 0; in esd_usb_rx_event()
351 can_change_state(priv->netdev, cf, in esd_usb_rx_event()
355 priv->can.can_stats.bus_error++; in esd_usb_rx_event()
356 stats->rx_errors++; in esd_usb_rx_event()
358 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; in esd_usb_rx_event()
362 cf->data[2] |= CAN_ERR_PROT_BIT; in esd_usb_rx_event()
365 cf->data[2] |= CAN_ERR_PROT_FORM; in esd_usb_rx_event()
368 cf->data[2] |= CAN_ERR_PROT_STUFF; in esd_usb_rx_event()
376 cf->data[2] |= CAN_ERR_PROT_TX; in esd_usb_rx_event()
379 cf->data[3] = ecc & ESD_USB_SJA1000_ECC_SEG; in esd_usb_rx_event()
383 cf->can_id |= CAN_ERR_CNT; in esd_usb_rx_event()
384 cf->data[6] = priv->bec.txerr; in esd_usb_rx_event()
385 cf->data[7] = priv->bec.rxerr; in esd_usb_rx_event()
395 struct net_device_stats *stats = &priv->netdev->stats; in esd_usb_rx_can_msg()
402 if (!netif_device_present(priv->netdev)) in esd_usb_rx_can_msg()
405 id = le32_to_cpu(msg->rx.id); in esd_usb_rx_can_msg()
410 if (msg->rx.dlc & ESD_USB_FD) { in esd_usb_rx_can_msg()
411 skb = alloc_canfd_skb(priv->netdev, &cfd); in esd_usb_rx_can_msg()
413 skb = alloc_can_skb(priv->netdev, &cf); in esd_usb_rx_can_msg()
418 stats->rx_dropped++; in esd_usb_rx_can_msg()
422 cfd->can_id = id & ESD_USB_IDMASK; in esd_usb_rx_can_msg()
424 if (msg->rx.dlc & ESD_USB_FD) { in esd_usb_rx_can_msg()
426 cfd->len = can_fd_dlc2len(msg->rx.dlc); in esd_usb_rx_can_msg()
427 len = cfd->len; in esd_usb_rx_can_msg()
428 if ((msg->rx.dlc & ESD_USB_NO_BRS) == 0) in esd_usb_rx_can_msg()
429 cfd->flags |= CANFD_BRS; in esd_usb_rx_can_msg()
430 if (msg->rx.dlc & ESD_USB_ESI) in esd_usb_rx_can_msg()
431 cfd->flags |= CANFD_ESI; in esd_usb_rx_can_msg()
433 can_frame_set_cc_len(cf, msg->rx.dlc & ~ESD_USB_RTR, priv->can.ctrlmode); in esd_usb_rx_can_msg()
434 len = cf->len; in esd_usb_rx_can_msg()
435 if (msg->rx.dlc & ESD_USB_RTR) { in esd_usb_rx_can_msg()
436 cf->can_id |= CAN_RTR_FLAG; in esd_usb_rx_can_msg()
442 cfd->can_id |= CAN_EFF_FLAG; in esd_usb_rx_can_msg()
444 memcpy(cfd->data, msg->rx.data_fd, len); in esd_usb_rx_can_msg()
445 stats->rx_bytes += len; in esd_usb_rx_can_msg()
446 stats->rx_packets++; in esd_usb_rx_can_msg()
455 struct net_device_stats *stats = &priv->netdev->stats; in esd_usb_tx_done_msg()
456 struct net_device *netdev = priv->netdev; in esd_usb_tx_done_msg()
462 context = &priv->tx_contexts[msg->txdone.hnd & (ESD_USB_MAX_TX_URBS - 1)]; in esd_usb_tx_done_msg()
464 if (!msg->txdone.status) { in esd_usb_tx_done_msg()
465 stats->tx_packets++; in esd_usb_tx_done_msg()
466 stats->tx_bytes += can_get_echo_skb(netdev, context->echo_index, in esd_usb_tx_done_msg()
469 stats->tx_errors++; in esd_usb_tx_done_msg()
470 can_free_echo_skb(netdev, context->echo_index, NULL); in esd_usb_tx_done_msg()
474 context->echo_index = ESD_USB_MAX_TX_URBS; in esd_usb_tx_done_msg()
475 atomic_dec(&priv->active_tx_jobs); in esd_usb_tx_done_msg()
482 struct esd_usb *dev = urb->context; in esd_usb_read_bulk_callback()
487 switch (urb->status) { in esd_usb_read_bulk_callback()
491 case -ENOENT: in esd_usb_read_bulk_callback()
492 case -EPIPE: in esd_usb_read_bulk_callback()
493 case -EPROTO: in esd_usb_read_bulk_callback()
494 case -ESHUTDOWN: in esd_usb_read_bulk_callback()
498 dev_info(dev->udev->dev.parent, in esd_usb_read_bulk_callback()
499 "Rx URB aborted (%d)\n", urb->status); in esd_usb_read_bulk_callback()
503 while (pos < urb->actual_length) { in esd_usb_read_bulk_callback()
506 msg = (union esd_usb_msg *)(urb->transfer_buffer + pos); in esd_usb_read_bulk_callback()
508 switch (msg->hdr.cmd) { in esd_usb_read_bulk_callback()
510 if (msg->rx.net >= dev->net_count) { in esd_usb_read_bulk_callback()
511 dev_err(dev->udev->dev.parent, "format error\n"); in esd_usb_read_bulk_callback()
515 esd_usb_rx_can_msg(dev->nets[msg->rx.net], msg); in esd_usb_read_bulk_callback()
519 if (msg->txdone.net >= dev->net_count) { in esd_usb_read_bulk_callback()
520 dev_err(dev->udev->dev.parent, "format error\n"); in esd_usb_read_bulk_callback()
524 esd_usb_tx_done_msg(dev->nets[msg->txdone.net], in esd_usb_read_bulk_callback()
529 pos += msg->hdr.len * sizeof(u32); /* convert to # of bytes */ in esd_usb_read_bulk_callback()
531 if (pos > urb->actual_length) { in esd_usb_read_bulk_callback()
532 dev_err(dev->udev->dev.parent, "format error\n"); in esd_usb_read_bulk_callback()
538 usb_fill_bulk_urb(urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), in esd_usb_read_bulk_callback()
539 urb->transfer_buffer, ESD_USB_RX_BUFFER_SIZE, in esd_usb_read_bulk_callback()
543 if (retval == -ENODEV) { in esd_usb_read_bulk_callback()
544 for (i = 0; i < dev->net_count; i++) { in esd_usb_read_bulk_callback()
545 if (dev->nets[i]) in esd_usb_read_bulk_callback()
546 netif_device_detach(dev->nets[i]->netdev); in esd_usb_read_bulk_callback()
549 dev_err(dev->udev->dev.parent, in esd_usb_read_bulk_callback()
557 struct esd_tx_urb_context *context = urb->context; in esd_usb_write_bulk_callback()
564 priv = context->priv; in esd_usb_write_bulk_callback()
565 netdev = priv->netdev; in esd_usb_write_bulk_callback()
568 usb_free_coherent(urb->dev, size, in esd_usb_write_bulk_callback()
569 urb->transfer_buffer, urb->transfer_dma); in esd_usb_write_bulk_callback()
574 if (urb->status) in esd_usb_write_bulk_callback()
575 netdev_info(netdev, "Tx URB aborted (%d)\n", urb->status); in esd_usb_write_bulk_callback()
587 (dev->version >> 12) & 0xf, in firmware_show()
588 (dev->version >> 8) & 0xf, in firmware_show()
589 dev->version & 0xff); in firmware_show()
600 (dev->version >> 28) & 0xf, in hardware_show()
601 (dev->version >> 24) & 0xf, in hardware_show()
602 (dev->version >> 16) & 0xff); in hardware_show()
612 return sprintf(buf, "%d", dev->net_count); in nets_show()
620 return usb_bulk_msg(dev->udev, in esd_usb_send_msg()
621 usb_sndbulkpipe(dev->udev, 2), in esd_usb_send_msg()
623 msg->hdr.len * sizeof(u32), /* convert to # of bytes */ in esd_usb_send_msg()
633 return usb_bulk_msg(dev->udev, in esd_usb_wait_msg()
634 usb_rcvbulkpipe(dev->udev, 1), in esd_usb_wait_msg()
645 if (dev->rxinitdone) in esd_usb_setup_rx_urbs()
656 err = -ENOMEM; in esd_usb_setup_rx_urbs()
660 buf = usb_alloc_coherent(dev->udev, ESD_USB_RX_BUFFER_SIZE, GFP_KERNEL, in esd_usb_setup_rx_urbs()
663 dev_warn(dev->udev->dev.parent, in esd_usb_setup_rx_urbs()
664 "No memory left for USB buffer\n"); in esd_usb_setup_rx_urbs()
665 err = -ENOMEM; in esd_usb_setup_rx_urbs()
669 urb->transfer_dma = buf_dma; in esd_usb_setup_rx_urbs()
671 usb_fill_bulk_urb(urb, dev->udev, in esd_usb_setup_rx_urbs()
672 usb_rcvbulkpipe(dev->udev, 1), in esd_usb_setup_rx_urbs()
675 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in esd_usb_setup_rx_urbs()
676 usb_anchor_urb(urb, &dev->rx_submitted); in esd_usb_setup_rx_urbs()
681 usb_free_coherent(dev->udev, ESD_USB_RX_BUFFER_SIZE, buf, in esd_usb_setup_rx_urbs()
682 urb->transfer_dma); in esd_usb_setup_rx_urbs()
686 dev->rxbuf[i] = buf; in esd_usb_setup_rx_urbs()
687 dev->rxbuf_dma[i] = buf_dma; in esd_usb_setup_rx_urbs()
690 /* Drop reference, USB core will take care of freeing it */ in esd_usb_setup_rx_urbs()
698 dev_err(dev->udev->dev.parent, "couldn't setup read URBs\n"); in esd_usb_setup_rx_urbs()
704 dev_warn(dev->udev->dev.parent, in esd_usb_setup_rx_urbs()
708 dev->rxinitdone = 1; in esd_usb_setup_rx_urbs()
715 struct esd_usb *dev = priv->usb; in esd_usb_start()
716 struct net_device *netdev = priv->netdev; in esd_usb_start()
722 err = -ENOMEM; in esd_usb_start()
738 msg->hdr.cmd = ESD_USB_CMD_IDADD; in esd_usb_start()
739 msg->hdr.len = sizeof(struct esd_usb_id_filter_msg) / sizeof(u32); /* # of 32bit words */ in esd_usb_start()
740 msg->filter.net = priv->index; in esd_usb_start()
741 msg->filter.option = ESD_USB_ID_ENABLE; /* start with segment 0 */ in esd_usb_start()
743 msg->filter.mask[i] = cpu_to_le32(GENMASK(31, 0)); in esd_usb_start()
745 msg->filter.mask[ESD_USB_MAX_ID_SEGMENT] = cpu_to_le32(BIT(0)); in esd_usb_start()
755 priv->can.state = CAN_STATE_ERROR_ACTIVE; in esd_usb_start()
758 if (err == -ENODEV) in esd_usb_start()
772 usb_kill_anchored_urbs(&dev->rx_submitted); in unlink_all_urbs()
775 usb_free_coherent(dev->udev, ESD_USB_RX_BUFFER_SIZE, in unlink_all_urbs()
776 dev->rxbuf[i], dev->rxbuf_dma[i]); in unlink_all_urbs()
778 for (i = 0; i < dev->net_count; i++) { in unlink_all_urbs()
779 priv = dev->nets[i]; in unlink_all_urbs()
781 usb_kill_anchored_urbs(&priv->tx_submitted); in unlink_all_urbs()
782 atomic_set(&priv->active_tx_jobs, 0); in unlink_all_urbs()
785 priv->tx_contexts[j].echo_index = ESD_USB_MAX_TX_URBS; in unlink_all_urbs()
817 struct esd_usb *dev = priv->usb; in esd_usb_start_xmit()
819 struct net_device_stats *stats = &netdev->stats; in esd_usb_start_xmit()
820 struct canfd_frame *cfd = (struct canfd_frame *)skb->data; in esd_usb_start_xmit()
834 stats->tx_dropped++; in esd_usb_start_xmit()
839 buf = usb_alloc_coherent(dev->udev, size, GFP_ATOMIC, in esd_usb_start_xmit()
840 &urb->transfer_dma); in esd_usb_start_xmit()
842 netdev_err(netdev, "No memory left for USB buffer\n"); in esd_usb_start_xmit()
843 stats->tx_dropped++; in esd_usb_start_xmit()
851 msg->hdr.len = offsetof(struct esd_usb_tx_msg, data) / sizeof(u32); in esd_usb_start_xmit()
852 msg->hdr.cmd = ESD_USB_CMD_CAN_TX; in esd_usb_start_xmit()
853 msg->tx.net = priv->index; in esd_usb_start_xmit()
856 msg->tx.dlc = can_fd_len2dlc(cfd->len); in esd_usb_start_xmit()
857 msg->tx.dlc |= ESD_USB_FD; in esd_usb_start_xmit()
859 if ((cfd->flags & CANFD_BRS) == 0) in esd_usb_start_xmit()
860 msg->tx.dlc |= ESD_USB_NO_BRS; in esd_usb_start_xmit()
862 msg->tx.dlc = can_get_cc_dlc((struct can_frame *)cfd, priv->can.ctrlmode); in esd_usb_start_xmit()
864 if (cfd->can_id & CAN_RTR_FLAG) in esd_usb_start_xmit()
865 msg->tx.dlc |= ESD_USB_RTR; in esd_usb_start_xmit()
868 msg->tx.id = cpu_to_le32(cfd->can_id & CAN_ERR_MASK); in esd_usb_start_xmit()
870 if (cfd->can_id & CAN_EFF_FLAG) in esd_usb_start_xmit()
871 msg->tx.id |= cpu_to_le32(ESD_USB_EXTID); in esd_usb_start_xmit()
873 memcpy(msg->tx.data_fd, cfd->data, cfd->len); in esd_usb_start_xmit()
876 msg->hdr.len += DIV_ROUND_UP(cfd->len, sizeof(u32)); in esd_usb_start_xmit()
879 if (priv->tx_contexts[i].echo_index == ESD_USB_MAX_TX_URBS) { in esd_usb_start_xmit()
880 context = &priv->tx_contexts[i]; in esd_usb_start_xmit()
892 context->priv = priv; in esd_usb_start_xmit()
893 context->echo_index = i; in esd_usb_start_xmit()
895 /* hnd must not be 0 - MSB is stripped in txdone handling */ in esd_usb_start_xmit()
896 msg->tx.hnd = BIT(31) | i; /* returned in TX done message */ in esd_usb_start_xmit()
898 usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, 2), buf, in esd_usb_start_xmit()
899 msg->hdr.len * sizeof(u32), /* convert to # of bytes */ in esd_usb_start_xmit()
902 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in esd_usb_start_xmit()
904 usb_anchor_urb(urb, &priv->tx_submitted); in esd_usb_start_xmit()
906 can_put_echo_skb(skb, netdev, context->echo_index, 0); in esd_usb_start_xmit()
908 atomic_inc(&priv->active_tx_jobs); in esd_usb_start_xmit()
911 if (atomic_read(&priv->active_tx_jobs) >= ESD_USB_MAX_TX_URBS) in esd_usb_start_xmit()
916 can_free_echo_skb(netdev, context->echo_index, NULL); in esd_usb_start_xmit()
918 atomic_dec(&priv->active_tx_jobs); in esd_usb_start_xmit()
921 stats->tx_dropped++; in esd_usb_start_xmit()
923 if (err == -ENODEV) in esd_usb_start_xmit()
933 /* Release our reference to this URB, the USB core will eventually free in esd_usb_start_xmit()
941 usb_free_coherent(dev->udev, size, buf, urb->transfer_dma); in esd_usb_start_xmit()
958 return -ENOMEM; in esd_usb_close()
961 msg->hdr.cmd = ESD_USB_CMD_IDADD; in esd_usb_close()
962 msg->hdr.len = sizeof(struct esd_usb_id_filter_msg) / sizeof(u32);/* # of 32bit words */ in esd_usb_close()
963 msg->filter.net = priv->index; in esd_usb_close()
964 msg->filter.option = ESD_USB_ID_ENABLE; /* start with segment 0 */ in esd_usb_close()
966 msg->filter.mask[i] = 0; in esd_usb_close()
967 if (esd_usb_send_msg(priv->usb, msg) < 0) in esd_usb_close()
971 msg->hdr.len = sizeof(struct esd_usb_set_baudrate_msg) / sizeof(u32); /* # of 32bit words */ in esd_usb_close()
972 msg->hdr.cmd = ESD_USB_CMD_SETBAUD; in esd_usb_close()
973 msg->setbaud.net = priv->index; in esd_usb_close()
974 msg->setbaud.rsvd = 0; in esd_usb_close()
975 msg->setbaud.baud = cpu_to_le32(ESD_USB_NO_BAUDRATE); in esd_usb_close()
976 if (esd_usb_send_msg(priv->usb, msg) < 0) in esd_usb_close()
979 priv->can.state = CAN_STATE_STOPPED; in esd_usb_close()
1017 struct can_bittiming *bt = &priv->can.bittiming; in esd_usb_2_set_bittiming()
1024 if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) in esd_usb_2_set_bittiming()
1027 canbtr |= (bt->brp - 1) & (btc->brp_max - 1); in esd_usb_2_set_bittiming()
1029 if (le16_to_cpu(priv->usb->udev->descriptor.idProduct) == in esd_usb_2_set_bittiming()
1035 canbtr |= ((bt->sjw - 1) & (btc->sjw_max - 1)) in esd_usb_2_set_bittiming()
1037 canbtr |= ((bt->prop_seg + bt->phase_seg1 - 1) in esd_usb_2_set_bittiming()
1038 & (btc->tseg1_max - 1)) in esd_usb_2_set_bittiming()
1040 canbtr |= ((bt->phase_seg2 - 1) & (btc->tseg2_max - 1)) in esd_usb_2_set_bittiming()
1042 if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) in esd_usb_2_set_bittiming()
1047 return -ENOMEM; in esd_usb_2_set_bittiming()
1049 msg->hdr.len = sizeof(struct esd_usb_set_baudrate_msg) / sizeof(u32); /* # of 32bit words */ in esd_usb_2_set_bittiming()
1050 msg->hdr.cmd = ESD_USB_CMD_SETBAUD; in esd_usb_2_set_bittiming()
1051 msg->setbaud.net = priv->index; in esd_usb_2_set_bittiming()
1052 msg->setbaud.rsvd = 0; in esd_usb_2_set_bittiming()
1053 msg->setbaud.baud = cpu_to_le32(canbtr); in esd_usb_2_set_bittiming()
1057 err = esd_usb_send_msg(priv->usb, msg); in esd_usb_2_set_bittiming()
1064 * Microchip SAM E70/S70/V70/V71, Data Sheet, Rev. G - 07/2022
1080 * Microchip SAM E70/S70/V70/V71, Data Sheet, Rev. G - 07/2022
1100 struct can_bittiming *nom_bt = &priv->can.bittiming; in esd_usb_3_set_bittiming()
1101 struct can_bittiming *data_bt = &priv->can.data_bittiming; in esd_usb_3_set_bittiming()
1109 return -ENOMEM; in esd_usb_3_set_bittiming()
1111 baud_x = &msg->setbaud_x; in esd_usb_3_set_bittiming()
1113 /* Canonical is the most reasonable mode for SocketCAN on CAN-USB/3 ... */ in esd_usb_3_set_bittiming()
1114 baud_x->mode = cpu_to_le16(ESD_USB_3_BAUDRATE_MODE_BTR_CANONICAL); in esd_usb_3_set_bittiming()
1116 if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) in esd_usb_3_set_bittiming()
1119 baud_x->nom.brp = cpu_to_le16(nom_bt->brp & (nom_btc->brp_max - 1)); in esd_usb_3_set_bittiming()
1120 baud_x->nom.sjw = cpu_to_le16(nom_bt->sjw & (nom_btc->sjw_max - 1)); in esd_usb_3_set_bittiming()
1121 baud_x->nom.tseg1 = cpu_to_le16((nom_bt->prop_seg + nom_bt->phase_seg1) in esd_usb_3_set_bittiming()
1122 & (nom_btc->tseg1_max - 1)); in esd_usb_3_set_bittiming()
1123 baud_x->nom.tseg2 = cpu_to_le16(nom_bt->phase_seg2 & (nom_btc->tseg2_max - 1)); in esd_usb_3_set_bittiming()
1125 if (priv->can.ctrlmode & CAN_CTRLMODE_FD) { in esd_usb_3_set_bittiming()
1126 baud_x->data.brp = cpu_to_le16(data_bt->brp & (data_btc->brp_max - 1)); in esd_usb_3_set_bittiming()
1127 baud_x->data.sjw = cpu_to_le16(data_bt->sjw & (data_btc->sjw_max - 1)); in esd_usb_3_set_bittiming()
1128 baud_x->data.tseg1 = cpu_to_le16((data_bt->prop_seg + data_bt->phase_seg1) in esd_usb_3_set_bittiming()
1129 & (data_btc->tseg1_max - 1)); in esd_usb_3_set_bittiming()
1130 baud_x->data.tseg2 = cpu_to_le16(data_bt->phase_seg2 & (data_btc->tseg2_max - 1)); in esd_usb_3_set_bittiming()
1135 baud_x->tdc.tdc_mode = ESD_USB_3_TDC_MODE_AUTO; in esd_usb_3_set_bittiming()
1136 baud_x->tdc.ssp_offset = 0; in esd_usb_3_set_bittiming()
1137 baud_x->tdc.ssp_shift = 0; in esd_usb_3_set_bittiming()
1138 baud_x->tdc.tdc_filter = 0; in esd_usb_3_set_bittiming()
1140 baud_x->flags = cpu_to_le16(flags); in esd_usb_3_set_bittiming()
1141 baud_x->net = priv->index; in esd_usb_3_set_bittiming()
1142 baud_x->rsvd = 0; in esd_usb_3_set_bittiming()
1145 msg->hdr.len = sizeof(struct esd_usb_3_set_baudrate_msg_x) / sizeof(u32); in esd_usb_3_set_bittiming()
1146 msg->hdr.cmd = ESD_USB_CMD_SETBAUD; in esd_usb_3_set_bittiming()
1149 "ctrlmode=%#x/%#x, esd-net=%u, esd-mode=%#x, esd-flags=%#x\n", in esd_usb_3_set_bittiming()
1150 priv->can.ctrlmode, priv->can.ctrlmode_supported, in esd_usb_3_set_bittiming()
1151 priv->index, le16_to_cpu(baud_x->mode), flags); in esd_usb_3_set_bittiming()
1153 err = esd_usb_send_msg(priv->usb, msg); in esd_usb_3_set_bittiming()
1164 bec->txerr = priv->bec.txerr; in esd_usb_get_berr_counter()
1165 bec->rxerr = priv->bec.rxerr; in esd_usb_get_berr_counter()
1178 return -EOPNOTSUPP; in esd_usb_set_mode()
1194 dev_err(&intf->dev, "couldn't alloc candev\n"); in esd_usb_probe_one_net()
1195 err = -ENOMEM; in esd_usb_probe_one_net()
1201 init_usb_anchor(&priv->tx_submitted); in esd_usb_probe_one_net()
1202 atomic_set(&priv->active_tx_jobs, 0); in esd_usb_probe_one_net()
1205 priv->tx_contexts[i].echo_index = ESD_USB_MAX_TX_URBS; in esd_usb_probe_one_net()
1207 priv->usb = dev; in esd_usb_probe_one_net()
1208 priv->netdev = netdev; in esd_usb_probe_one_net()
1209 priv->index = index; in esd_usb_probe_one_net()
1211 priv->can.state = CAN_STATE_STOPPED; in esd_usb_probe_one_net()
1212 priv->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY | in esd_usb_probe_one_net()
1216 switch (le16_to_cpu(dev->udev->descriptor.idProduct)) { in esd_usb_probe_one_net()
1218 priv->can.clock.freq = ESD_USB_3_CAN_CLOCK; in esd_usb_probe_one_net()
1219 priv->can.ctrlmode_supported |= CAN_CTRLMODE_FD; in esd_usb_probe_one_net()
1220 priv->can.bittiming_const = &esd_usb_3_nom_bittiming_const; in esd_usb_probe_one_net()
1221 priv->can.data_bittiming_const = &esd_usb_3_data_bittiming_const; in esd_usb_probe_one_net()
1222 priv->can.do_set_bittiming = esd_usb_3_set_bittiming; in esd_usb_probe_one_net()
1223 priv->can.do_set_data_bittiming = esd_usb_3_set_bittiming; in esd_usb_probe_one_net()
1227 priv->can.clock.freq = ESD_USB_M_CAN_CLOCK; in esd_usb_probe_one_net()
1228 priv->can.bittiming_const = &esd_usb_2_bittiming_const; in esd_usb_probe_one_net()
1229 priv->can.do_set_bittiming = esd_usb_2_set_bittiming; in esd_usb_probe_one_net()
1234 priv->can.clock.freq = ESD_USB_2_CAN_CLOCK; in esd_usb_probe_one_net()
1235 priv->can.ctrlmode_supported |= CAN_CTRLMODE_3_SAMPLES; in esd_usb_probe_one_net()
1236 priv->can.bittiming_const = &esd_usb_2_bittiming_const; in esd_usb_probe_one_net()
1237 priv->can.do_set_bittiming = esd_usb_2_set_bittiming; in esd_usb_probe_one_net()
1241 priv->can.do_set_mode = esd_usb_set_mode; in esd_usb_probe_one_net()
1242 priv->can.do_get_berr_counter = esd_usb_get_berr_counter; in esd_usb_probe_one_net()
1244 netdev->flags |= IFF_ECHO; /* we support local echo */ in esd_usb_probe_one_net()
1246 netdev->netdev_ops = &esd_usb_netdev_ops; in esd_usb_probe_one_net()
1247 netdev->ethtool_ops = &esd_usb_ethtool_ops; in esd_usb_probe_one_net()
1249 SET_NETDEV_DEV(netdev, &intf->dev); in esd_usb_probe_one_net()
1250 netdev->dev_id = index; in esd_usb_probe_one_net()
1254 dev_err(&intf->dev, "couldn't register CAN device: %d\n", err); in esd_usb_probe_one_net()
1256 err = -ENOMEM; in esd_usb_probe_one_net()
1260 dev->nets[index] = priv; in esd_usb_probe_one_net()
1261 netdev_info(netdev, "device %s registered\n", netdev->name); in esd_usb_probe_one_net()
1267 /* probe function for new USB devices
1269 * check version information and number of available
1281 err = -ENOMEM; in esd_usb_probe()
1285 dev->udev = interface_to_usbdev(intf); in esd_usb_probe()
1287 init_usb_anchor(&dev->rx_submitted); in esd_usb_probe()
1293 err = -ENOMEM; in esd_usb_probe()
1298 msg->hdr.cmd = ESD_USB_CMD_VERSION; in esd_usb_probe()
1299 msg->hdr.len = sizeof(struct esd_usb_version_msg) / sizeof(u32); /* # of 32bit words */ in esd_usb_probe()
1300 msg->version.rsvd = 0; in esd_usb_probe()
1301 msg->version.flags = 0; in esd_usb_probe()
1302 msg->version.drv_version = 0; in esd_usb_probe()
1306 dev_err(&intf->dev, "sending version message failed\n"); in esd_usb_probe()
1312 dev_err(&intf->dev, "no version message answer\n"); in esd_usb_probe()
1316 dev->net_count = (int)msg->version_reply.nets; in esd_usb_probe()
1317 dev->version = le32_to_cpu(msg->version_reply.version); in esd_usb_probe()
1319 if (device_create_file(&intf->dev, &dev_attr_firmware)) in esd_usb_probe()
1320 dev_err(&intf->dev, in esd_usb_probe()
1323 if (device_create_file(&intf->dev, &dev_attr_hardware)) in esd_usb_probe()
1324 dev_err(&intf->dev, in esd_usb_probe()
1327 if (device_create_file(&intf->dev, &dev_attr_nets)) in esd_usb_probe()
1328 dev_err(&intf->dev, in esd_usb_probe()
1332 for (i = 0; i < dev->net_count; i++) in esd_usb_probe()
1343 /* called by the usb core when the device is removed from the system */
1350 device_remove_file(&intf->dev, &dev_attr_firmware); in esd_usb_disconnect()
1351 device_remove_file(&intf->dev, &dev_attr_hardware); in esd_usb_disconnect()
1352 device_remove_file(&intf->dev, &dev_attr_nets); in esd_usb_disconnect()
1357 for (i = 0; i < dev->net_count; i++) { in esd_usb_disconnect()
1358 if (dev->nets[i]) { in esd_usb_disconnect()
1359 netdev = dev->nets[i]->netdev; in esd_usb_disconnect()
1369 /* usb specific object needed to register this driver with the usb subsystem */