1 // SPDX-License-Identifier: GPL-2.0-only
2 /* CAN driver for Geschwister Schneider USB/CAN devices
3 * and bytewerk.org candleLight USB CAN interfaces.
5 * Copyright (C) 2013-2016 Geschwister Schneider Technologie-,
6 * Entwicklungs- und Vertriebs UG (Haftungsbeschränkt).
7 * Copyright (C) 2016 Hubert Denkmair
10 * Many thanks to all socketcan devs!
13 #include <linux/bitfield.h>
14 #include <linux/clocksource.h>
15 #include <linux/ethtool.h>
16 #include <linux/init.h>
17 #include <linux/module.h>
18 #include <linux/netdevice.h>
19 #include <linux/signal.h>
20 #include <linux/timecounter.h>
21 #include <linux/units.h>
22 #include <linux/usb.h>
23 #include <linux/workqueue.h>
25 #include <linux/can.h>
26 #include <linux/can/dev.h>
27 #include <linux/can/error.h>
28 #include <linux/can/rx-offload.h>
30 /* Device specific constants */
31 #define USB_GS_USB_1_VENDOR_ID 0x1d50
32 #define USB_GS_USB_1_PRODUCT_ID 0x606f
34 #define USB_CANDLELIGHT_VENDOR_ID 0x1209
35 #define USB_CANDLELIGHT_PRODUCT_ID 0x2323
37 #define USB_CES_CANEXT_FD_VENDOR_ID 0x1cd2
38 #define USB_CES_CANEXT_FD_PRODUCT_ID 0x606f
40 #define USB_ABE_CANDEBUGGER_FD_VENDOR_ID 0x16d0
41 #define USB_ABE_CANDEBUGGER_FD_PRODUCT_ID 0x10b8
43 #define USB_XYLANTA_SAINT3_VENDOR_ID 0x16d0
44 #define USB_XYLANTA_SAINT3_PRODUCT_ID 0x0f30
46 #define GS_USB_ENDPOINT_IN 1
47 #define GS_USB_ENDPOINT_OUT 2
49 /* Timestamp 32 bit timer runs at 1 MHz (1 µs tick). Worker accounts
50 * for timer overflow (will be after ~71 minutes)
52 #define GS_USB_TIMESTAMP_TIMER_HZ (1 * HZ_PER_MHZ)
53 #define GS_USB_TIMESTAMP_WORK_DELAY_SEC 1800
54 static_assert(GS_USB_TIMESTAMP_WORK_DELAY_SEC <
55 CYCLECOUNTER_MASK(32) / GS_USB_TIMESTAMP_TIMER_HZ / 2);
57 /* Device specific constants */
59 GS_USB_BREQ_HOST_FORMAT = 0,
60 GS_USB_BREQ_BITTIMING,
64 GS_USB_BREQ_DEVICE_CONFIG,
65 GS_USB_BREQ_TIMESTAMP,
67 GS_USB_BREQ_GET_USER_ID,
68 GS_USB_BREQ_QUIRK_CANTACT_PRO_DATA_BITTIMING = GS_USB_BREQ_GET_USER_ID,
69 GS_USB_BREQ_SET_USER_ID,
70 GS_USB_BREQ_DATA_BITTIMING,
71 GS_USB_BREQ_BT_CONST_EXT,
72 GS_USB_BREQ_SET_TERMINATION,
73 GS_USB_BREQ_GET_TERMINATION,
74 GS_USB_BREQ_GET_STATE,
78 /* reset a channel. turns it off */
79 GS_CAN_MODE_RESET = 0,
80 /* starts a channel */
85 GS_CAN_STATE_ERROR_ACTIVE = 0,
86 GS_CAN_STATE_ERROR_WARNING,
87 GS_CAN_STATE_ERROR_PASSIVE,
93 enum gs_can_identify_mode {
94 GS_CAN_IDENTIFY_OFF = 0,
98 enum gs_can_termination_state {
99 GS_CAN_TERMINATION_STATE_OFF = 0,
100 GS_CAN_TERMINATION_STATE_ON
103 #define GS_USB_TERMINATION_DISABLED CAN_TERMINATION_DISABLED
104 #define GS_USB_TERMINATION_ENABLED 120
106 /* data types passed between host and device */
108 /* The firmware on the original USB2CAN by Geschwister Schneider
109 * Technologie Entwicklungs- und Vertriebs UG exchanges all data
110 * between the host and the device in host byte order. This is done
111 * with the struct gs_host_config::byte_order member, which is sent
112 * first to indicate the desired byte order.
114 * The widely used open source firmware candleLight doesn't support
115 * this feature and exchanges the data in little endian byte order.
117 struct gs_host_config {
121 struct gs_device_config {
130 #define GS_CAN_MODE_NORMAL 0
131 #define GS_CAN_MODE_LISTEN_ONLY BIT(0)
132 #define GS_CAN_MODE_LOOP_BACK BIT(1)
133 #define GS_CAN_MODE_TRIPLE_SAMPLE BIT(2)
134 #define GS_CAN_MODE_ONE_SHOT BIT(3)
135 #define GS_CAN_MODE_HW_TIMESTAMP BIT(4)
136 /* GS_CAN_FEATURE_IDENTIFY BIT(5) */
137 /* GS_CAN_FEATURE_USER_ID BIT(6) */
138 #define GS_CAN_MODE_PAD_PKTS_TO_MAX_PKT_SIZE BIT(7)
139 #define GS_CAN_MODE_FD BIT(8)
140 /* GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX BIT(9) */
141 /* GS_CAN_FEATURE_BT_CONST_EXT BIT(10) */
142 /* GS_CAN_FEATURE_TERMINATION BIT(11) */
143 #define GS_CAN_MODE_BERR_REPORTING BIT(12)
144 /* GS_CAN_FEATURE_GET_STATE BIT(13) */
146 struct gs_device_mode {
151 struct gs_device_state {
157 struct gs_device_bittiming {
165 struct gs_identify_mode {
169 struct gs_device_termination_state {
173 #define GS_CAN_FEATURE_LISTEN_ONLY BIT(0)
174 #define GS_CAN_FEATURE_LOOP_BACK BIT(1)
175 #define GS_CAN_FEATURE_TRIPLE_SAMPLE BIT(2)
176 #define GS_CAN_FEATURE_ONE_SHOT BIT(3)
177 #define GS_CAN_FEATURE_HW_TIMESTAMP BIT(4)
178 #define GS_CAN_FEATURE_IDENTIFY BIT(5)
179 #define GS_CAN_FEATURE_USER_ID BIT(6)
180 #define GS_CAN_FEATURE_PAD_PKTS_TO_MAX_PKT_SIZE BIT(7)
181 #define GS_CAN_FEATURE_FD BIT(8)
182 #define GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX BIT(9)
183 #define GS_CAN_FEATURE_BT_CONST_EXT BIT(10)
184 #define GS_CAN_FEATURE_TERMINATION BIT(11)
185 #define GS_CAN_FEATURE_BERR_REPORTING BIT(12)
186 #define GS_CAN_FEATURE_GET_STATE BIT(13)
187 #define GS_CAN_FEATURE_MASK GENMASK(13, 0)
189 /* internal quirks - keep in GS_CAN_FEATURE space for now */
191 /* CANtact Pro original firmware:
192 * BREQ DATA_BITTIMING overlaps with GET_USER_ID
194 #define GS_CAN_FEATURE_QUIRK_BREQ_CANTACT_PRO BIT(31)
196 struct gs_device_bt_const {
209 struct gs_device_bt_const_extended {
231 #define GS_CAN_FLAG_OVERFLOW BIT(0)
232 #define GS_CAN_FLAG_FD BIT(1)
233 #define GS_CAN_FLAG_BRS BIT(2)
234 #define GS_CAN_FLAG_ESI BIT(3)
240 struct classic_can_ts {
245 struct classic_can_quirk {
264 struct gs_host_frame {
274 DECLARE_FLEX_ARRAY(struct classic_can, classic_can);
275 DECLARE_FLEX_ARRAY(struct classic_can_ts, classic_can_ts);
276 DECLARE_FLEX_ARRAY(struct classic_can_quirk, classic_can_quirk);
277 DECLARE_FLEX_ARRAY(struct canfd, canfd);
278 DECLARE_FLEX_ARRAY(struct canfd_ts, canfd_ts);
279 DECLARE_FLEX_ARRAY(struct canfd_quirk, canfd_quirk);
282 /* The GS USB devices make use of the same flags and masks as in
283 * linux/can.h and linux/can/error.h, and no additional mapping is necessary.
286 /* Only send a max of GS_MAX_TX_URBS frames per channel at a time. */
287 #define GS_MAX_TX_URBS 10
288 /* Only launch a max of GS_MAX_RX_URBS usb requests at a time. */
289 #define GS_MAX_RX_URBS 30
290 #define GS_NAPI_WEIGHT 32
292 /* Maximum number of interfaces the driver supports per device.
293 * Current hardware only supports 3 interfaces. The future may vary.
295 #define GS_MAX_INTF 3
297 struct gs_tx_context {
299 unsigned int echo_id;
303 struct can_priv can; /* must be the first member */
305 struct can_rx_offload offload;
306 struct gs_usb *parent;
308 struct net_device *netdev;
309 struct usb_device *udev;
311 struct can_bittiming_const bt_const, data_bt_const;
312 unsigned int channel; /* channel number */
315 unsigned int hf_size_tx;
317 /* This lock prevents a race condition between xmit and receive. */
318 spinlock_t tx_ctx_lock;
319 struct gs_tx_context tx_context[GS_MAX_TX_URBS];
321 struct usb_anchor tx_submitted;
322 atomic_t active_tx_urbs;
325 /* usb interface struct */
327 struct gs_can *canch[GS_MAX_INTF];
328 struct usb_anchor rx_submitted;
329 struct usb_device *udev;
331 /* time counter for hardware timestamps */
332 struct cyclecounter cc;
333 struct timecounter tc;
334 spinlock_t tc_lock; /* spinlock to guard access tc->cycle_last */
335 struct delayed_work timestamp;
337 unsigned int hf_size_rx;
341 /* 'allocate' a tx context.
342 * returns a valid tx context or NULL if there is no space.
344 static struct gs_tx_context *gs_alloc_tx_context(struct gs_can *dev)
349 spin_lock_irqsave(&dev->tx_ctx_lock, flags);
351 for (; i < GS_MAX_TX_URBS; i++) {
352 if (dev->tx_context[i].echo_id == GS_MAX_TX_URBS) {
353 dev->tx_context[i].echo_id = i;
354 spin_unlock_irqrestore(&dev->tx_ctx_lock, flags);
355 return &dev->tx_context[i];
359 spin_unlock_irqrestore(&dev->tx_ctx_lock, flags);
363 /* releases a tx context
365 static void gs_free_tx_context(struct gs_tx_context *txc)
367 txc->echo_id = GS_MAX_TX_URBS;
370 /* Get a tx context by id.
372 static struct gs_tx_context *gs_get_tx_context(struct gs_can *dev,
377 if (id < GS_MAX_TX_URBS) {
378 spin_lock_irqsave(&dev->tx_ctx_lock, flags);
379 if (dev->tx_context[id].echo_id == id) {
380 spin_unlock_irqrestore(&dev->tx_ctx_lock, flags);
381 return &dev->tx_context[id];
383 spin_unlock_irqrestore(&dev->tx_ctx_lock, flags);
388 static int gs_cmd_reset(struct gs_can *dev)
390 struct gs_device_mode dm = {
391 .mode = cpu_to_le32(GS_CAN_MODE_RESET),
394 return usb_control_msg_send(dev->udev, 0, GS_USB_BREQ_MODE,
395 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
396 dev->channel, 0, &dm, sizeof(dm), 1000,
400 static inline int gs_usb_get_timestamp(const struct gs_usb *parent,
406 rc = usb_control_msg_recv(parent->udev, 0, GS_USB_BREQ_TIMESTAMP,
407 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
409 ×tamp, sizeof(timestamp),
410 USB_CTRL_GET_TIMEOUT,
415 *timestamp_p = le32_to_cpu(timestamp);
420 static u64 gs_usb_timestamp_read(const struct cyclecounter *cc) __must_hold(&dev->tc_lock)
422 struct gs_usb *parent = container_of(cc, struct gs_usb, cc);
426 lockdep_assert_held(&parent->tc_lock);
428 /* drop lock for synchronous USB transfer */
429 spin_unlock_bh(&parent->tc_lock);
430 err = gs_usb_get_timestamp(parent, ×tamp);
431 spin_lock_bh(&parent->tc_lock);
433 dev_err(&parent->udev->dev,
434 "Error %d while reading timestamp. HW timestamps may be inaccurate.",
440 static void gs_usb_timestamp_work(struct work_struct *work)
442 struct delayed_work *delayed_work = to_delayed_work(work);
443 struct gs_usb *parent;
445 parent = container_of(delayed_work, struct gs_usb, timestamp);
446 spin_lock_bh(&parent->tc_lock);
447 timecounter_read(&parent->tc);
448 spin_unlock_bh(&parent->tc_lock);
450 schedule_delayed_work(&parent->timestamp,
451 GS_USB_TIMESTAMP_WORK_DELAY_SEC * HZ);
454 static void gs_usb_skb_set_timestamp(struct gs_can *dev,
455 struct sk_buff *skb, u32 timestamp)
457 struct skb_shared_hwtstamps *hwtstamps = skb_hwtstamps(skb);
458 struct gs_usb *parent = dev->parent;
461 spin_lock_bh(&parent->tc_lock);
462 ns = timecounter_cyc2time(&parent->tc, timestamp);
463 spin_unlock_bh(&parent->tc_lock);
465 hwtstamps->hwtstamp = ns_to_ktime(ns);
468 static void gs_usb_timestamp_init(struct gs_usb *parent)
470 struct cyclecounter *cc = &parent->cc;
472 cc->read = gs_usb_timestamp_read;
473 cc->mask = CYCLECOUNTER_MASK(32);
474 cc->shift = 32 - bits_per(NSEC_PER_SEC / GS_USB_TIMESTAMP_TIMER_HZ);
475 cc->mult = clocksource_hz2mult(GS_USB_TIMESTAMP_TIMER_HZ, cc->shift);
477 spin_lock_init(&parent->tc_lock);
478 spin_lock_bh(&parent->tc_lock);
479 timecounter_init(&parent->tc, &parent->cc, ktime_get_real_ns());
480 spin_unlock_bh(&parent->tc_lock);
482 INIT_DELAYED_WORK(&parent->timestamp, gs_usb_timestamp_work);
483 schedule_delayed_work(&parent->timestamp,
484 GS_USB_TIMESTAMP_WORK_DELAY_SEC * HZ);
487 static void gs_usb_timestamp_stop(struct gs_usb *parent)
489 cancel_delayed_work_sync(&parent->timestamp);
492 static void gs_update_state(struct gs_can *dev, struct can_frame *cf)
494 struct can_device_stats *can_stats = &dev->can.can_stats;
496 if (cf->can_id & CAN_ERR_RESTARTED) {
497 dev->can.state = CAN_STATE_ERROR_ACTIVE;
498 can_stats->restarts++;
499 } else if (cf->can_id & CAN_ERR_BUSOFF) {
500 dev->can.state = CAN_STATE_BUS_OFF;
501 can_stats->bus_off++;
502 } else if (cf->can_id & CAN_ERR_CRTL) {
503 if ((cf->data[1] & CAN_ERR_CRTL_TX_WARNING) ||
504 (cf->data[1] & CAN_ERR_CRTL_RX_WARNING)) {
505 dev->can.state = CAN_STATE_ERROR_WARNING;
506 can_stats->error_warning++;
507 } else if ((cf->data[1] & CAN_ERR_CRTL_TX_PASSIVE) ||
508 (cf->data[1] & CAN_ERR_CRTL_RX_PASSIVE)) {
509 dev->can.state = CAN_STATE_ERROR_PASSIVE;
510 can_stats->error_passive++;
512 dev->can.state = CAN_STATE_ERROR_ACTIVE;
517 static u32 gs_usb_set_timestamp(struct gs_can *dev, struct sk_buff *skb,
518 const struct gs_host_frame *hf)
522 if (hf->flags & GS_CAN_FLAG_FD)
523 timestamp = le32_to_cpu(hf->canfd_ts->timestamp_us);
525 timestamp = le32_to_cpu(hf->classic_can_ts->timestamp_us);
528 gs_usb_skb_set_timestamp(dev, skb, timestamp);
533 static void gs_usb_rx_offload(struct gs_can *dev, struct sk_buff *skb,
534 const struct gs_host_frame *hf)
536 struct can_rx_offload *offload = &dev->offload;
539 if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP) {
540 const u32 ts = gs_usb_set_timestamp(dev, skb, hf);
542 rc = can_rx_offload_queue_timestamp(offload, skb, ts);
544 rc = can_rx_offload_queue_tail(offload, skb);
548 dev->netdev->stats.rx_fifo_errors++;
552 gs_usb_get_echo_skb(struct gs_can *dev, struct sk_buff *skb,
553 const struct gs_host_frame *hf)
555 struct can_rx_offload *offload = &dev->offload;
556 const u32 echo_id = hf->echo_id;
559 if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP) {
560 const u32 ts = gs_usb_set_timestamp(dev, skb, hf);
562 len = can_rx_offload_get_echo_skb_queue_timestamp(offload, echo_id,
565 len = can_rx_offload_get_echo_skb_queue_tail(offload, echo_id,
572 static void gs_usb_receive_bulk_callback(struct urb *urb)
574 struct gs_usb *parent = urb->context;
576 struct net_device *netdev;
578 struct net_device_stats *stats;
579 struct gs_host_frame *hf = urb->transfer_buffer;
580 struct gs_tx_context *txc;
581 struct can_frame *cf;
582 struct canfd_frame *cfd;
587 switch (urb->status) {
588 case 0: /* success */
594 /* do not resubmit aborted urbs. eg: when device goes down */
598 /* device reports out of range channel id */
599 if (hf->channel >= GS_MAX_INTF)
602 dev = parent->canch[hf->channel];
604 netdev = dev->netdev;
605 stats = &netdev->stats;
607 if (!netif_device_present(netdev))
610 if (!netif_running(netdev))
613 if (hf->echo_id == -1) { /* normal rx */
614 if (hf->flags & GS_CAN_FLAG_FD) {
615 skb = alloc_canfd_skb(netdev, &cfd);
619 cfd->can_id = le32_to_cpu(hf->can_id);
620 cfd->len = can_fd_dlc2len(hf->can_dlc);
621 if (hf->flags & GS_CAN_FLAG_BRS)
622 cfd->flags |= CANFD_BRS;
623 if (hf->flags & GS_CAN_FLAG_ESI)
624 cfd->flags |= CANFD_ESI;
626 memcpy(cfd->data, hf->canfd->data, cfd->len);
628 skb = alloc_can_skb(netdev, &cf);
632 cf->can_id = le32_to_cpu(hf->can_id);
633 can_frame_set_cc_len(cf, hf->can_dlc, dev->can.ctrlmode);
635 memcpy(cf->data, hf->classic_can->data, 8);
637 /* ERROR frames tell us information about the controller */
638 if (le32_to_cpu(hf->can_id) & CAN_ERR_FLAG)
639 gs_update_state(dev, cf);
642 gs_usb_rx_offload(dev, skb, hf);
643 } else { /* echo_id == hf->echo_id */
644 if (hf->echo_id >= GS_MAX_TX_URBS) {
646 "Unexpected out of range echo id %u\n",
651 txc = gs_get_tx_context(dev, hf->echo_id);
653 /* bad devices send bad echo_ids. */
656 "Unexpected unused echo id %u\n",
661 skb = dev->can.echo_skb[hf->echo_id];
663 stats->tx_bytes += gs_usb_get_echo_skb(dev, skb, hf);
664 gs_free_tx_context(txc);
666 atomic_dec(&dev->active_tx_urbs);
668 netif_wake_queue(netdev);
671 if (hf->flags & GS_CAN_FLAG_OVERFLOW) {
672 stats->rx_over_errors++;
675 skb = alloc_can_err_skb(netdev, &cf);
679 cf->can_id |= CAN_ERR_CRTL;
680 cf->len = CAN_ERR_DLC;
681 cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
683 gs_usb_rx_offload(dev, skb, hf);
686 can_rx_offload_irq_finish(&dev->offload);
689 usb_fill_bulk_urb(urb, parent->udev,
690 usb_rcvbulkpipe(parent->udev, GS_USB_ENDPOINT_IN),
691 hf, dev->parent->hf_size_rx,
692 gs_usb_receive_bulk_callback, parent);
694 rc = usb_submit_urb(urb, GFP_ATOMIC);
696 /* USB failure take down all interfaces */
699 for (rc = 0; rc < GS_MAX_INTF; rc++) {
700 if (parent->canch[rc])
701 netif_device_detach(parent->canch[rc]->netdev);
706 static int gs_usb_set_bittiming(struct net_device *netdev)
708 struct gs_can *dev = netdev_priv(netdev);
709 struct can_bittiming *bt = &dev->can.bittiming;
710 struct gs_device_bittiming dbt = {
711 .prop_seg = cpu_to_le32(bt->prop_seg),
712 .phase_seg1 = cpu_to_le32(bt->phase_seg1),
713 .phase_seg2 = cpu_to_le32(bt->phase_seg2),
714 .sjw = cpu_to_le32(bt->sjw),
715 .brp = cpu_to_le32(bt->brp),
718 /* request bit timings */
719 return usb_control_msg_send(dev->udev, 0, GS_USB_BREQ_BITTIMING,
720 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
721 dev->channel, 0, &dbt, sizeof(dbt), 1000,
725 static int gs_usb_set_data_bittiming(struct net_device *netdev)
727 struct gs_can *dev = netdev_priv(netdev);
728 struct can_bittiming *bt = &dev->can.data_bittiming;
729 struct gs_device_bittiming dbt = {
730 .prop_seg = cpu_to_le32(bt->prop_seg),
731 .phase_seg1 = cpu_to_le32(bt->phase_seg1),
732 .phase_seg2 = cpu_to_le32(bt->phase_seg2),
733 .sjw = cpu_to_le32(bt->sjw),
734 .brp = cpu_to_le32(bt->brp),
736 u8 request = GS_USB_BREQ_DATA_BITTIMING;
738 if (dev->feature & GS_CAN_FEATURE_QUIRK_BREQ_CANTACT_PRO)
739 request = GS_USB_BREQ_QUIRK_CANTACT_PRO_DATA_BITTIMING;
741 /* request data bit timings */
742 return usb_control_msg_send(dev->udev, 0, request,
743 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
744 dev->channel, 0, &dbt, sizeof(dbt), 1000,
748 static void gs_usb_xmit_callback(struct urb *urb)
750 struct gs_tx_context *txc = urb->context;
751 struct gs_can *dev = txc->dev;
752 struct net_device *netdev = dev->netdev;
755 netdev_info(netdev, "usb xmit fail %u\n", txc->echo_id);
758 static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb,
759 struct net_device *netdev)
761 struct gs_can *dev = netdev_priv(netdev);
762 struct net_device_stats *stats = &dev->netdev->stats;
764 struct gs_host_frame *hf;
765 struct can_frame *cf;
766 struct canfd_frame *cfd;
769 struct gs_tx_context *txc;
771 if (can_dev_dropped_skb(netdev, skb))
774 /* find an empty context to keep track of transmission */
775 txc = gs_alloc_tx_context(dev);
777 return NETDEV_TX_BUSY;
779 /* create a URB, and a buffer for it */
780 urb = usb_alloc_urb(0, GFP_ATOMIC);
784 hf = kmalloc(dev->hf_size_tx, GFP_ATOMIC);
790 if (idx >= GS_MAX_TX_URBS) {
791 netdev_err(netdev, "Invalid tx context %u\n", idx);
796 hf->channel = dev->channel;
800 if (can_is_canfd_skb(skb)) {
801 cfd = (struct canfd_frame *)skb->data;
803 hf->can_id = cpu_to_le32(cfd->can_id);
804 hf->can_dlc = can_fd_len2dlc(cfd->len);
805 hf->flags |= GS_CAN_FLAG_FD;
806 if (cfd->flags & CANFD_BRS)
807 hf->flags |= GS_CAN_FLAG_BRS;
808 if (cfd->flags & CANFD_ESI)
809 hf->flags |= GS_CAN_FLAG_ESI;
811 memcpy(hf->canfd->data, cfd->data, cfd->len);
813 cf = (struct can_frame *)skb->data;
815 hf->can_id = cpu_to_le32(cf->can_id);
816 hf->can_dlc = can_get_cc_dlc(cf, dev->can.ctrlmode);
818 memcpy(hf->classic_can->data, cf->data, cf->len);
821 usb_fill_bulk_urb(urb, dev->udev,
822 usb_sndbulkpipe(dev->udev, GS_USB_ENDPOINT_OUT),
824 gs_usb_xmit_callback, txc);
826 urb->transfer_flags |= URB_FREE_BUFFER;
827 usb_anchor_urb(urb, &dev->tx_submitted);
829 can_put_echo_skb(skb, netdev, idx, 0);
831 atomic_inc(&dev->active_tx_urbs);
833 rc = usb_submit_urb(urb, GFP_ATOMIC);
834 if (unlikely(rc)) { /* usb send failed */
835 atomic_dec(&dev->active_tx_urbs);
837 can_free_echo_skb(netdev, idx, NULL);
838 gs_free_tx_context(txc);
840 usb_unanchor_urb(urb);
843 netif_device_detach(netdev);
845 netdev_err(netdev, "usb_submit failed (err=%d)\n", rc);
849 /* Slow down tx path */
850 if (atomic_read(&dev->active_tx_urbs) >= GS_MAX_TX_URBS)
851 netif_stop_queue(netdev);
854 /* let usb core take care of this urb */
865 gs_free_tx_context(txc);
871 static int gs_can_open(struct net_device *netdev)
873 struct gs_can *dev = netdev_priv(netdev);
874 struct gs_usb *parent = dev->parent;
875 struct gs_device_mode dm = {
876 .mode = cpu_to_le32(GS_CAN_MODE_START),
878 struct gs_host_frame *hf;
879 struct urb *urb = NULL;
884 rc = open_candev(netdev);
888 ctrlmode = dev->can.ctrlmode;
889 if (ctrlmode & CAN_CTRLMODE_FD) {
890 if (dev->feature & GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX)
891 dev->hf_size_tx = struct_size(hf, canfd_quirk, 1);
893 dev->hf_size_tx = struct_size(hf, canfd, 1);
895 if (dev->feature & GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX)
896 dev->hf_size_tx = struct_size(hf, classic_can_quirk, 1);
898 dev->hf_size_tx = struct_size(hf, classic_can, 1);
901 can_rx_offload_enable(&dev->offload);
903 if (!parent->active_channels) {
904 if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
905 gs_usb_timestamp_init(parent);
907 for (i = 0; i < GS_MAX_RX_URBS; i++) {
911 urb = usb_alloc_urb(0, GFP_KERNEL);
914 goto out_usb_kill_anchored_urbs;
917 /* alloc rx buffer */
918 buf = kmalloc(dev->parent->hf_size_rx,
922 goto out_usb_free_urb;
925 /* fill, anchor, and submit rx urb */
926 usb_fill_bulk_urb(urb,
928 usb_rcvbulkpipe(dev->udev,
931 dev->parent->hf_size_rx,
932 gs_usb_receive_bulk_callback, parent);
933 urb->transfer_flags |= URB_FREE_BUFFER;
935 usb_anchor_urb(urb, &parent->rx_submitted);
937 rc = usb_submit_urb(urb, GFP_KERNEL);
940 netif_device_detach(dev->netdev);
943 "usb_submit_urb() failed, error %pe\n",
946 goto out_usb_unanchor_urb;
950 * USB core will take care of freeing it
957 if (ctrlmode & CAN_CTRLMODE_LOOPBACK)
958 flags |= GS_CAN_MODE_LOOP_BACK;
960 if (ctrlmode & CAN_CTRLMODE_LISTENONLY)
961 flags |= GS_CAN_MODE_LISTEN_ONLY;
963 if (ctrlmode & CAN_CTRLMODE_3_SAMPLES)
964 flags |= GS_CAN_MODE_TRIPLE_SAMPLE;
966 if (ctrlmode & CAN_CTRLMODE_ONE_SHOT)
967 flags |= GS_CAN_MODE_ONE_SHOT;
969 if (ctrlmode & CAN_CTRLMODE_BERR_REPORTING)
970 flags |= GS_CAN_MODE_BERR_REPORTING;
972 if (ctrlmode & CAN_CTRLMODE_FD)
973 flags |= GS_CAN_MODE_FD;
975 /* if hardware supports timestamps, enable it */
976 if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
977 flags |= GS_CAN_MODE_HW_TIMESTAMP;
979 /* finally start device */
980 dev->can.state = CAN_STATE_ERROR_ACTIVE;
981 dm.flags = cpu_to_le32(flags);
982 rc = usb_control_msg_send(dev->udev, 0, GS_USB_BREQ_MODE,
983 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
984 dev->channel, 0, &dm, sizeof(dm), 1000,
987 netdev_err(netdev, "Couldn't start device (err=%d)\n", rc);
988 dev->can.state = CAN_STATE_STOPPED;
990 goto out_usb_kill_anchored_urbs;
993 parent->active_channels++;
994 if (!(dev->can.ctrlmode & CAN_CTRLMODE_LISTENONLY))
995 netif_start_queue(netdev);
999 out_usb_unanchor_urb:
1000 usb_unanchor_urb(urb);
1003 out_usb_kill_anchored_urbs:
1004 if (!parent->active_channels) {
1005 usb_kill_anchored_urbs(&dev->tx_submitted);
1007 if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
1008 gs_usb_timestamp_stop(parent);
1011 can_rx_offload_disable(&dev->offload);
1012 close_candev(netdev);
1017 static int gs_usb_get_state(const struct net_device *netdev,
1018 struct can_berr_counter *bec,
1019 enum can_state *state)
1021 struct gs_can *dev = netdev_priv(netdev);
1022 struct gs_device_state ds;
1025 rc = usb_control_msg_recv(dev->udev, 0, GS_USB_BREQ_GET_STATE,
1026 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1029 USB_CTRL_GET_TIMEOUT,
1034 if (le32_to_cpu(ds.state) >= CAN_STATE_MAX)
1037 *state = le32_to_cpu(ds.state);
1038 bec->txerr = le32_to_cpu(ds.txerr);
1039 bec->rxerr = le32_to_cpu(ds.rxerr);
1044 static int gs_usb_can_get_berr_counter(const struct net_device *netdev,
1045 struct can_berr_counter *bec)
1047 enum can_state state;
1049 return gs_usb_get_state(netdev, bec, &state);
1052 static int gs_can_close(struct net_device *netdev)
1055 struct gs_can *dev = netdev_priv(netdev);
1056 struct gs_usb *parent = dev->parent;
1058 netif_stop_queue(netdev);
1061 parent->active_channels--;
1062 if (!parent->active_channels) {
1063 usb_kill_anchored_urbs(&parent->rx_submitted);
1065 if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
1066 gs_usb_timestamp_stop(parent);
1069 /* Stop sending URBs */
1070 usb_kill_anchored_urbs(&dev->tx_submitted);
1071 atomic_set(&dev->active_tx_urbs, 0);
1073 dev->can.state = CAN_STATE_STOPPED;
1075 /* reset the device */
1078 /* reset tx contexts */
1079 for (rc = 0; rc < GS_MAX_TX_URBS; rc++) {
1080 dev->tx_context[rc].dev = dev;
1081 dev->tx_context[rc].echo_id = GS_MAX_TX_URBS;
1084 can_rx_offload_disable(&dev->offload);
1086 /* close the netdev */
1087 close_candev(netdev);
1092 static int gs_can_eth_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
1094 const struct gs_can *dev = netdev_priv(netdev);
1096 if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
1097 return can_eth_ioctl_hwts(netdev, ifr, cmd);
1102 static const struct net_device_ops gs_usb_netdev_ops = {
1103 .ndo_open = gs_can_open,
1104 .ndo_stop = gs_can_close,
1105 .ndo_start_xmit = gs_can_start_xmit,
1106 .ndo_change_mtu = can_change_mtu,
1107 .ndo_eth_ioctl = gs_can_eth_ioctl,
1110 static int gs_usb_set_identify(struct net_device *netdev, bool do_identify)
1112 struct gs_can *dev = netdev_priv(netdev);
1113 struct gs_identify_mode imode;
1116 imode.mode = cpu_to_le32(GS_CAN_IDENTIFY_ON);
1118 imode.mode = cpu_to_le32(GS_CAN_IDENTIFY_OFF);
1120 return usb_control_msg_send(dev->udev, 0, GS_USB_BREQ_IDENTIFY,
1121 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1122 dev->channel, 0, &imode, sizeof(imode), 100,
1126 /* blink LED's for finding the this interface */
1127 static int gs_usb_set_phys_id(struct net_device *netdev,
1128 enum ethtool_phys_id_state state)
1130 const struct gs_can *dev = netdev_priv(netdev);
1133 if (!(dev->feature & GS_CAN_FEATURE_IDENTIFY))
1137 case ETHTOOL_ID_ACTIVE:
1138 rc = gs_usb_set_identify(netdev, GS_CAN_IDENTIFY_ON);
1140 case ETHTOOL_ID_INACTIVE:
1141 rc = gs_usb_set_identify(netdev, GS_CAN_IDENTIFY_OFF);
1150 static int gs_usb_get_ts_info(struct net_device *netdev,
1151 struct kernel_ethtool_ts_info *info)
1153 struct gs_can *dev = netdev_priv(netdev);
1155 /* report if device supports HW timestamps */
1156 if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
1157 return can_ethtool_op_get_ts_info_hwts(netdev, info);
1159 return ethtool_op_get_ts_info(netdev, info);
1162 static const struct ethtool_ops gs_usb_ethtool_ops = {
1163 .set_phys_id = gs_usb_set_phys_id,
1164 .get_ts_info = gs_usb_get_ts_info,
1167 static int gs_usb_get_termination(struct net_device *netdev, u16 *term)
1169 struct gs_can *dev = netdev_priv(netdev);
1170 struct gs_device_termination_state term_state;
1173 rc = usb_control_msg_recv(dev->udev, 0, GS_USB_BREQ_GET_TERMINATION,
1174 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1176 &term_state, sizeof(term_state), 1000,
1181 if (term_state.state == cpu_to_le32(GS_CAN_TERMINATION_STATE_ON))
1182 *term = GS_USB_TERMINATION_ENABLED;
1184 *term = GS_USB_TERMINATION_DISABLED;
1189 static int gs_usb_set_termination(struct net_device *netdev, u16 term)
1191 struct gs_can *dev = netdev_priv(netdev);
1192 struct gs_device_termination_state term_state;
1194 if (term == GS_USB_TERMINATION_ENABLED)
1195 term_state.state = cpu_to_le32(GS_CAN_TERMINATION_STATE_ON);
1197 term_state.state = cpu_to_le32(GS_CAN_TERMINATION_STATE_OFF);
1199 return usb_control_msg_send(dev->udev, 0, GS_USB_BREQ_SET_TERMINATION,
1200 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1202 &term_state, sizeof(term_state), 1000,
1206 static const u16 gs_usb_termination_const[] = {
1207 GS_USB_TERMINATION_DISABLED,
1208 GS_USB_TERMINATION_ENABLED
1211 static struct gs_can *gs_make_candev(unsigned int channel,
1212 struct usb_interface *intf,
1213 struct gs_device_config *dconf)
1216 struct net_device *netdev;
1218 struct gs_device_bt_const_extended bt_const_extended;
1219 struct gs_device_bt_const bt_const;
1222 /* fetch bit timing constants */
1223 rc = usb_control_msg_recv(interface_to_usbdev(intf), 0,
1224 GS_USB_BREQ_BT_CONST,
1225 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1226 channel, 0, &bt_const, sizeof(bt_const), 1000,
1231 "Couldn't get bit timing const for channel %d (%pe)\n",
1232 channel, ERR_PTR(rc));
1237 netdev = alloc_candev(sizeof(struct gs_can), GS_MAX_TX_URBS);
1239 dev_err(&intf->dev, "Couldn't allocate candev\n");
1240 return ERR_PTR(-ENOMEM);
1243 dev = netdev_priv(netdev);
1245 netdev->netdev_ops = &gs_usb_netdev_ops;
1246 netdev->ethtool_ops = &gs_usb_ethtool_ops;
1248 netdev->flags |= IFF_ECHO; /* we support full roundtrip echo */
1249 netdev->dev_id = channel;
1252 strcpy(dev->bt_const.name, KBUILD_MODNAME);
1253 dev->bt_const.tseg1_min = le32_to_cpu(bt_const.tseg1_min);
1254 dev->bt_const.tseg1_max = le32_to_cpu(bt_const.tseg1_max);
1255 dev->bt_const.tseg2_min = le32_to_cpu(bt_const.tseg2_min);
1256 dev->bt_const.tseg2_max = le32_to_cpu(bt_const.tseg2_max);
1257 dev->bt_const.sjw_max = le32_to_cpu(bt_const.sjw_max);
1258 dev->bt_const.brp_min = le32_to_cpu(bt_const.brp_min);
1259 dev->bt_const.brp_max = le32_to_cpu(bt_const.brp_max);
1260 dev->bt_const.brp_inc = le32_to_cpu(bt_const.brp_inc);
1262 dev->udev = interface_to_usbdev(intf);
1263 dev->netdev = netdev;
1264 dev->channel = channel;
1266 init_usb_anchor(&dev->tx_submitted);
1267 atomic_set(&dev->active_tx_urbs, 0);
1268 spin_lock_init(&dev->tx_ctx_lock);
1269 for (rc = 0; rc < GS_MAX_TX_URBS; rc++) {
1270 dev->tx_context[rc].dev = dev;
1271 dev->tx_context[rc].echo_id = GS_MAX_TX_URBS;
1275 dev->can.state = CAN_STATE_STOPPED;
1276 dev->can.clock.freq = le32_to_cpu(bt_const.fclk_can);
1277 dev->can.bittiming_const = &dev->bt_const;
1278 dev->can.do_set_bittiming = gs_usb_set_bittiming;
1280 dev->can.ctrlmode_supported = CAN_CTRLMODE_CC_LEN8_DLC;
1282 feature = le32_to_cpu(bt_const.feature);
1283 dev->feature = FIELD_GET(GS_CAN_FEATURE_MASK, feature);
1284 if (feature & GS_CAN_FEATURE_LISTEN_ONLY)
1285 dev->can.ctrlmode_supported |= CAN_CTRLMODE_LISTENONLY;
1287 if (feature & GS_CAN_FEATURE_LOOP_BACK)
1288 dev->can.ctrlmode_supported |= CAN_CTRLMODE_LOOPBACK;
1290 if (feature & GS_CAN_FEATURE_TRIPLE_SAMPLE)
1291 dev->can.ctrlmode_supported |= CAN_CTRLMODE_3_SAMPLES;
1293 if (feature & GS_CAN_FEATURE_ONE_SHOT)
1294 dev->can.ctrlmode_supported |= CAN_CTRLMODE_ONE_SHOT;
1296 if (feature & GS_CAN_FEATURE_FD) {
1297 dev->can.ctrlmode_supported |= CAN_CTRLMODE_FD;
1298 /* The data bit timing will be overwritten, if
1299 * GS_CAN_FEATURE_BT_CONST_EXT is set.
1301 dev->can.data_bittiming_const = &dev->bt_const;
1302 dev->can.do_set_data_bittiming = gs_usb_set_data_bittiming;
1305 if (feature & GS_CAN_FEATURE_TERMINATION) {
1306 rc = gs_usb_get_termination(netdev, &dev->can.termination);
1308 dev->feature &= ~GS_CAN_FEATURE_TERMINATION;
1310 dev_info(&intf->dev,
1311 "Disabling termination support for channel %d (%pe)\n",
1312 channel, ERR_PTR(rc));
1314 dev->can.termination_const = gs_usb_termination_const;
1315 dev->can.termination_const_cnt = ARRAY_SIZE(gs_usb_termination_const);
1316 dev->can.do_set_termination = gs_usb_set_termination;
1320 if (feature & GS_CAN_FEATURE_BERR_REPORTING)
1321 dev->can.ctrlmode_supported |= CAN_CTRLMODE_BERR_REPORTING;
1323 if (feature & GS_CAN_FEATURE_GET_STATE)
1324 dev->can.do_get_berr_counter = gs_usb_can_get_berr_counter;
1326 /* The CANtact Pro from LinkLayer Labs is based on the
1327 * LPC54616 µC, which is affected by the NXP LPC USB transfer
1328 * erratum. However, the current firmware (version 2) doesn't
1329 * set the GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX bit. Set the
1330 * feature GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX to workaround
1333 * For the GS_USB_BREQ_DATA_BITTIMING USB control message the
1334 * CANtact Pro firmware uses a request value, which is already
1335 * used by the candleLight firmware for a different purpose
1336 * (GS_USB_BREQ_GET_USER_ID). Set the feature
1337 * GS_CAN_FEATURE_QUIRK_BREQ_CANTACT_PRO to workaround this
1340 if (dev->udev->descriptor.idVendor == cpu_to_le16(USB_GS_USB_1_VENDOR_ID) &&
1341 dev->udev->descriptor.idProduct == cpu_to_le16(USB_GS_USB_1_PRODUCT_ID) &&
1342 dev->udev->manufacturer && dev->udev->product &&
1343 !strcmp(dev->udev->manufacturer, "LinkLayer Labs") &&
1344 !strcmp(dev->udev->product, "CANtact Pro") &&
1345 (le32_to_cpu(dconf->sw_version) <= 2))
1346 dev->feature |= GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX |
1347 GS_CAN_FEATURE_QUIRK_BREQ_CANTACT_PRO;
1349 /* GS_CAN_FEATURE_IDENTIFY is only supported for sw_version > 1 */
1350 if (!(le32_to_cpu(dconf->sw_version) > 1 &&
1351 feature & GS_CAN_FEATURE_IDENTIFY))
1352 dev->feature &= ~GS_CAN_FEATURE_IDENTIFY;
1354 /* fetch extended bit timing constants if device has feature
1355 * GS_CAN_FEATURE_FD and GS_CAN_FEATURE_BT_CONST_EXT
1357 if (feature & GS_CAN_FEATURE_FD &&
1358 feature & GS_CAN_FEATURE_BT_CONST_EXT) {
1359 rc = usb_control_msg_recv(interface_to_usbdev(intf), 0,
1360 GS_USB_BREQ_BT_CONST_EXT,
1361 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1362 channel, 0, &bt_const_extended,
1363 sizeof(bt_const_extended),
1367 "Couldn't get extended bit timing const for channel %d (%pe)\n",
1368 channel, ERR_PTR(rc));
1369 goto out_free_candev;
1372 strcpy(dev->data_bt_const.name, KBUILD_MODNAME);
1373 dev->data_bt_const.tseg1_min = le32_to_cpu(bt_const_extended.dtseg1_min);
1374 dev->data_bt_const.tseg1_max = le32_to_cpu(bt_const_extended.dtseg1_max);
1375 dev->data_bt_const.tseg2_min = le32_to_cpu(bt_const_extended.dtseg2_min);
1376 dev->data_bt_const.tseg2_max = le32_to_cpu(bt_const_extended.dtseg2_max);
1377 dev->data_bt_const.sjw_max = le32_to_cpu(bt_const_extended.dsjw_max);
1378 dev->data_bt_const.brp_min = le32_to_cpu(bt_const_extended.dbrp_min);
1379 dev->data_bt_const.brp_max = le32_to_cpu(bt_const_extended.dbrp_max);
1380 dev->data_bt_const.brp_inc = le32_to_cpu(bt_const_extended.dbrp_inc);
1382 dev->can.data_bittiming_const = &dev->data_bt_const;
1385 can_rx_offload_add_manual(netdev, &dev->offload, GS_NAPI_WEIGHT);
1386 SET_NETDEV_DEV(netdev, &intf->dev);
1388 rc = register_candev(dev->netdev);
1391 "Couldn't register candev for channel %d (%pe)\n",
1392 channel, ERR_PTR(rc));
1393 goto out_can_rx_offload_del;
1398 out_can_rx_offload_del:
1399 can_rx_offload_del(&dev->offload);
1401 free_candev(dev->netdev);
1405 static void gs_destroy_candev(struct gs_can *dev)
1407 unregister_candev(dev->netdev);
1408 can_rx_offload_del(&dev->offload);
1409 free_candev(dev->netdev);
1412 static int gs_usb_probe(struct usb_interface *intf,
1413 const struct usb_device_id *id)
1415 struct usb_device *udev = interface_to_usbdev(intf);
1416 struct gs_host_frame *hf;
1417 struct gs_usb *parent;
1418 struct gs_host_config hconf = {
1419 .byte_order = cpu_to_le32(0x0000beef),
1421 struct gs_device_config dconf;
1422 unsigned int icount, i;
1425 /* send host config */
1426 rc = usb_control_msg_send(udev, 0,
1427 GS_USB_BREQ_HOST_FORMAT,
1428 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1429 1, intf->cur_altsetting->desc.bInterfaceNumber,
1430 &hconf, sizeof(hconf), 1000,
1433 dev_err(&intf->dev, "Couldn't send data format (err=%d)\n", rc);
1437 /* read device config */
1438 rc = usb_control_msg_recv(udev, 0,
1439 GS_USB_BREQ_DEVICE_CONFIG,
1440 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1441 1, intf->cur_altsetting->desc.bInterfaceNumber,
1442 &dconf, sizeof(dconf), 1000,
1445 dev_err(&intf->dev, "Couldn't get device config: (err=%d)\n",
1450 icount = dconf.icount + 1;
1451 dev_info(&intf->dev, "Configuring for %u interfaces\n", icount);
1453 if (icount > GS_MAX_INTF) {
1455 "Driver cannot handle more that %u CAN interfaces\n",
1460 parent = kzalloc(sizeof(*parent), GFP_KERNEL);
1464 init_usb_anchor(&parent->rx_submitted);
1466 usb_set_intfdata(intf, parent);
1467 parent->udev = udev;
1469 for (i = 0; i < icount; i++) {
1470 unsigned int hf_size_rx = 0;
1472 parent->canch[i] = gs_make_candev(i, intf, &dconf);
1473 if (IS_ERR_OR_NULL(parent->canch[i])) {
1474 /* save error code to return later */
1475 rc = PTR_ERR(parent->canch[i]);
1477 /* on failure destroy previously created candevs */
1479 for (i = 0; i < icount; i++)
1480 gs_destroy_candev(parent->canch[i]);
1482 usb_kill_anchored_urbs(&parent->rx_submitted);
1486 parent->canch[i]->parent = parent;
1488 /* set RX packet size based on FD and if hardware
1489 * timestamps are supported.
1491 if (parent->canch[i]->can.ctrlmode_supported & CAN_CTRLMODE_FD) {
1492 if (parent->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
1493 hf_size_rx = struct_size(hf, canfd_ts, 1);
1495 hf_size_rx = struct_size(hf, canfd, 1);
1497 if (parent->canch[i]->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
1498 hf_size_rx = struct_size(hf, classic_can_ts, 1);
1500 hf_size_rx = struct_size(hf, classic_can, 1);
1502 parent->hf_size_rx = max(parent->hf_size_rx, hf_size_rx);
1508 static void gs_usb_disconnect(struct usb_interface *intf)
1510 struct gs_usb *parent = usb_get_intfdata(intf);
1513 usb_set_intfdata(intf, NULL);
1516 dev_err(&intf->dev, "Disconnect (nodata)\n");
1520 for (i = 0; i < GS_MAX_INTF; i++)
1521 if (parent->canch[i])
1522 gs_destroy_candev(parent->canch[i]);
1527 static const struct usb_device_id gs_usb_table[] = {
1528 { USB_DEVICE_INTERFACE_NUMBER(USB_GS_USB_1_VENDOR_ID,
1529 USB_GS_USB_1_PRODUCT_ID, 0) },
1530 { USB_DEVICE_INTERFACE_NUMBER(USB_CANDLELIGHT_VENDOR_ID,
1531 USB_CANDLELIGHT_PRODUCT_ID, 0) },
1532 { USB_DEVICE_INTERFACE_NUMBER(USB_CES_CANEXT_FD_VENDOR_ID,
1533 USB_CES_CANEXT_FD_PRODUCT_ID, 0) },
1534 { USB_DEVICE_INTERFACE_NUMBER(USB_ABE_CANDEBUGGER_FD_VENDOR_ID,
1535 USB_ABE_CANDEBUGGER_FD_PRODUCT_ID, 0) },
1536 { USB_DEVICE_INTERFACE_NUMBER(USB_XYLANTA_SAINT3_VENDOR_ID,
1537 USB_XYLANTA_SAINT3_PRODUCT_ID, 0) },
1538 {} /* Terminating entry */
1541 MODULE_DEVICE_TABLE(usb, gs_usb_table);
1543 static struct usb_driver gs_usb_driver = {
1544 .name = KBUILD_MODNAME,
1545 .probe = gs_usb_probe,
1546 .disconnect = gs_usb_disconnect,
1547 .id_table = gs_usb_table,
1550 module_usb_driver(gs_usb_driver);
1554 "Socket CAN device driver for Geschwister Schneider Technologie-, "
1555 "Entwicklungs- und Vertriebs UG. USB2.0 to CAN interfaces\n"
1556 "and bytewerk.org candleLight USB CAN interfaces.");
1557 MODULE_LICENSE("GPL v2");