1 // SPDX-License-Identifier: GPL-2.0-only
2 /* SocketCAN driver for Microchip CAN BUS Analyzer Tool
4 * Copyright (C) 2017 Mobica Limited
6 * This driver is inspired by the 4.6.2 version of net/can/usb/usb_8dev.c
9 #include <asm/unaligned.h>
10 #include <linux/can.h>
11 #include <linux/can/dev.h>
12 #include <linux/can/error.h>
13 #include <linux/ethtool.h>
14 #include <linux/module.h>
15 #include <linux/netdevice.h>
16 #include <linux/signal.h>
17 #include <linux/slab.h>
18 #include <linux/usb.h>
20 /* vendor and product id */
21 #define MCBA_MODULE_NAME "mcba_usb"
22 #define MCBA_VENDOR_ID 0x04d8
23 #define MCBA_PRODUCT_ID 0x0a30
25 /* driver constants */
26 #define MCBA_MAX_RX_URBS 20
27 #define MCBA_MAX_TX_URBS 20
28 #define MCBA_CTX_FREE MCBA_MAX_TX_URBS
30 /* RX buffer must be bigger than msg size since at the
31 * beginning USB messages are stacked.
33 #define MCBA_USB_RX_BUFF_SIZE 64
34 #define MCBA_USB_TX_BUFF_SIZE (sizeof(struct mcba_usb_msg))
36 /* Microchip command id */
37 #define MBCA_CMD_RECEIVE_MESSAGE 0xE3
38 #define MBCA_CMD_I_AM_ALIVE_FROM_CAN 0xF5
39 #define MBCA_CMD_I_AM_ALIVE_FROM_USB 0xF7
40 #define MBCA_CMD_CHANGE_BIT_RATE 0xA1
41 #define MBCA_CMD_TRANSMIT_MESSAGE_EV 0xA3
42 #define MBCA_CMD_SETUP_TERMINATION_RESISTANCE 0xA8
43 #define MBCA_CMD_READ_FW_VERSION 0xA9
44 #define MBCA_CMD_NOTHING_TO_SEND 0xFF
45 #define MBCA_CMD_TRANSMIT_MESSAGE_RSP 0xE2
47 #define MCBA_VER_REQ_USB 1
48 #define MCBA_VER_REQ_CAN 2
50 /* Drive the CAN_RES signal LOW "0" to activate R24 and R25 */
51 #define MCBA_VER_TERMINATION_ON 0
52 #define MCBA_VER_TERMINATION_OFF 1
54 #define MCBA_SIDL_EXID_MASK 0x8
55 #define MCBA_DLC_MASK 0xf
56 #define MCBA_DLC_RTR_MASK 0x40
58 #define MCBA_CAN_STATE_WRN_TH 95
59 #define MCBA_CAN_STATE_ERR_PSV_TH 127
61 #define MCBA_TERMINATION_DISABLED CAN_TERMINATION_DISABLED
62 #define MCBA_TERMINATION_ENABLED 120
65 struct mcba_priv *priv;
70 /* Structure to hold all of our device specific stuff */
72 struct can_priv can; /* must be the first member */
73 struct sk_buff *echo_skb[MCBA_MAX_TX_URBS];
74 struct mcba_usb_ctx tx_context[MCBA_MAX_TX_URBS];
75 struct usb_device *udev;
76 struct net_device *netdev;
77 struct usb_anchor tx_submitted;
78 struct usb_anchor rx_submitted;
79 struct can_berr_counter bec;
80 bool usb_ka_first_pass;
81 bool can_ka_first_pass;
83 atomic_t free_ctx_cnt;
84 void *rxbuf[MCBA_MAX_RX_URBS];
85 dma_addr_t rxbuf_dma[MCBA_MAX_RX_URBS];
91 struct __packed mcba_usb_msg_can {
102 struct __packed mcba_usb_msg {
107 struct __packed mcba_usb_msg_ka_usb {
109 u8 termination_state;
115 struct __packed mcba_usb_msg_ka_can {
132 struct __packed mcba_usb_msg_change_bitrate {
138 struct __packed mcba_usb_msg_termination {
144 struct __packed mcba_usb_msg_fw_ver {
150 static const struct usb_device_id mcba_usb_table[] = {
151 { USB_DEVICE(MCBA_VENDOR_ID, MCBA_PRODUCT_ID) },
152 {} /* Terminating entry */
155 MODULE_DEVICE_TABLE(usb, mcba_usb_table);
157 static const u16 mcba_termination[] = { MCBA_TERMINATION_DISABLED,
158 MCBA_TERMINATION_ENABLED };
160 static const u32 mcba_bitrate[] = { 20000, 33333, 50000, 80000, 83333,
161 100000, 125000, 150000, 175000, 200000,
162 225000, 250000, 275000, 300000, 500000,
163 625000, 800000, 1000000 };
165 static inline void mcba_init_ctx(struct mcba_priv *priv)
169 for (i = 0; i < MCBA_MAX_TX_URBS; i++) {
170 priv->tx_context[i].ndx = MCBA_CTX_FREE;
171 priv->tx_context[i].priv = priv;
174 atomic_set(&priv->free_ctx_cnt, ARRAY_SIZE(priv->tx_context));
177 static inline struct mcba_usb_ctx *mcba_usb_get_free_ctx(struct mcba_priv *priv,
178 struct can_frame *cf)
181 struct mcba_usb_ctx *ctx = NULL;
183 for (i = 0; i < MCBA_MAX_TX_URBS; i++) {
184 if (priv->tx_context[i].ndx == MCBA_CTX_FREE) {
185 ctx = &priv->tx_context[i];
193 atomic_dec(&priv->free_ctx_cnt);
198 if (!atomic_read(&priv->free_ctx_cnt))
199 /* That was the last free ctx. Slow down tx path */
200 netif_stop_queue(priv->netdev);
205 /* mcba_usb_free_ctx and mcba_usb_get_free_ctx are executed by different
206 * threads. The order of execution in below function is important.
208 static inline void mcba_usb_free_ctx(struct mcba_usb_ctx *ctx)
210 /* Increase number of free ctxs before freeing ctx */
211 atomic_inc(&ctx->priv->free_ctx_cnt);
213 ctx->ndx = MCBA_CTX_FREE;
215 /* Wake up the queue once ctx is marked free */
216 netif_wake_queue(ctx->priv->netdev);
219 static void mcba_usb_write_bulk_callback(struct urb *urb)
221 struct mcba_usb_ctx *ctx = urb->context;
222 struct net_device *netdev;
226 netdev = ctx->priv->netdev;
228 /* free up our allocated buffer */
229 usb_free_coherent(urb->dev, urb->transfer_buffer_length,
230 urb->transfer_buffer, urb->transfer_dma);
233 if (!netif_device_present(netdev))
236 netdev->stats.tx_packets++;
237 netdev->stats.tx_bytes += can_get_echo_skb(netdev, ctx->ndx,
242 netdev_info(netdev, "Tx URB aborted (%d)\n", urb->status);
244 /* Release the context */
245 mcba_usb_free_ctx(ctx);
248 /* Send data to device */
249 static netdev_tx_t mcba_usb_xmit(struct mcba_priv *priv,
250 struct mcba_usb_msg *usb_msg,
251 struct mcba_usb_ctx *ctx)
257 /* create a URB, and a buffer for it, and copy the data to the URB */
258 urb = usb_alloc_urb(0, GFP_ATOMIC);
262 buf = usb_alloc_coherent(priv->udev, MCBA_USB_TX_BUFF_SIZE, GFP_ATOMIC,
269 memcpy(buf, usb_msg, MCBA_USB_TX_BUFF_SIZE);
271 usb_fill_bulk_urb(urb, priv->udev, priv->tx_pipe, buf, MCBA_USB_TX_BUFF_SIZE,
272 mcba_usb_write_bulk_callback, ctx);
274 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
275 usb_anchor_urb(urb, &priv->tx_submitted);
277 err = usb_submit_urb(urb, GFP_ATOMIC);
281 /* Release our reference to this URB, the USB core will eventually free
289 usb_unanchor_urb(urb);
290 usb_free_coherent(priv->udev, MCBA_USB_TX_BUFF_SIZE, buf,
294 netif_device_detach(priv->netdev);
296 netdev_warn(priv->netdev, "failed tx_urb %d\n", err);
304 /* Send data to device */
305 static netdev_tx_t mcba_usb_start_xmit(struct sk_buff *skb,
306 struct net_device *netdev)
308 struct mcba_priv *priv = netdev_priv(netdev);
309 struct can_frame *cf = (struct can_frame *)skb->data;
310 struct mcba_usb_ctx *ctx = NULL;
311 struct net_device_stats *stats = &priv->netdev->stats;
314 struct mcba_usb_msg_can usb_msg = {
315 .cmd_id = MBCA_CMD_TRANSMIT_MESSAGE_EV
318 if (can_dev_dropped_skb(netdev, skb))
321 ctx = mcba_usb_get_free_ctx(priv, cf);
323 return NETDEV_TX_BUSY;
325 if (cf->can_id & CAN_EFF_FLAG) {
326 /* SIDH | SIDL | EIDH | EIDL
327 * 28 - 21 | 20 19 18 x x x 17 16 | 15 - 8 | 7 - 0
329 sid = MCBA_SIDL_EXID_MASK;
330 /* store 28-18 bits */
331 sid |= (cf->can_id & 0x1ffc0000) >> 13;
332 /* store 17-16 bits */
333 sid |= (cf->can_id & 0x30000) >> 16;
334 put_unaligned_be16(sid, &usb_msg.sid);
336 /* store 15-0 bits */
337 put_unaligned_be16(cf->can_id & 0xffff, &usb_msg.eid);
340 * 10 - 3 | 2 1 0 x x x x x
342 put_unaligned_be16((cf->can_id & CAN_SFF_MASK) << 5,
347 usb_msg.dlc = cf->len;
349 memcpy(usb_msg.data, cf->data, usb_msg.dlc);
351 if (cf->can_id & CAN_RTR_FLAG)
352 usb_msg.dlc |= MCBA_DLC_RTR_MASK;
354 can_put_echo_skb(skb, priv->netdev, ctx->ndx, 0);
356 err = mcba_usb_xmit(priv, (struct mcba_usb_msg *)&usb_msg, ctx);
363 can_free_echo_skb(priv->netdev, ctx->ndx, NULL);
364 mcba_usb_free_ctx(ctx);
370 /* Send cmd to device */
371 static void mcba_usb_xmit_cmd(struct mcba_priv *priv,
372 struct mcba_usb_msg *usb_msg)
374 struct mcba_usb_ctx *ctx = NULL;
377 ctx = mcba_usb_get_free_ctx(priv, NULL);
379 netdev_err(priv->netdev,
380 "Lack of free ctx. Sending (%d) cmd aborted",
386 err = mcba_usb_xmit(priv, usb_msg, ctx);
388 netdev_err(priv->netdev, "Failed to send cmd (%d)",
392 static void mcba_usb_xmit_change_bitrate(struct mcba_priv *priv, u16 bitrate)
394 struct mcba_usb_msg_change_bitrate usb_msg = {
395 .cmd_id = MBCA_CMD_CHANGE_BIT_RATE
398 put_unaligned_be16(bitrate, &usb_msg.bitrate);
400 mcba_usb_xmit_cmd(priv, (struct mcba_usb_msg *)&usb_msg);
403 static void mcba_usb_xmit_read_fw_ver(struct mcba_priv *priv, u8 pic)
405 struct mcba_usb_msg_fw_ver usb_msg = {
406 .cmd_id = MBCA_CMD_READ_FW_VERSION,
410 mcba_usb_xmit_cmd(priv, (struct mcba_usb_msg *)&usb_msg);
413 static void mcba_usb_process_can(struct mcba_priv *priv,
414 struct mcba_usb_msg_can *msg)
416 struct can_frame *cf;
418 struct net_device_stats *stats = &priv->netdev->stats;
421 skb = alloc_can_skb(priv->netdev, &cf);
425 sid = get_unaligned_be16(&msg->sid);
427 if (sid & MCBA_SIDL_EXID_MASK) {
428 /* SIDH | SIDL | EIDH | EIDL
429 * 28 - 21 | 20 19 18 x x x 17 16 | 15 - 8 | 7 - 0
431 cf->can_id = CAN_EFF_FLAG;
433 /* store 28-18 bits */
434 cf->can_id |= (sid & 0xffe0) << 13;
435 /* store 17-16 bits */
436 cf->can_id |= (sid & 3) << 16;
437 /* store 15-0 bits */
438 cf->can_id |= get_unaligned_be16(&msg->eid);
441 * 10 - 3 | 2 1 0 x x x x x
443 cf->can_id = (sid & 0xffe0) >> 5;
446 cf->len = can_cc_dlc2len(msg->dlc & MCBA_DLC_MASK);
448 if (msg->dlc & MCBA_DLC_RTR_MASK) {
449 cf->can_id |= CAN_RTR_FLAG;
451 memcpy(cf->data, msg->data, cf->len);
453 stats->rx_bytes += cf->len;
460 static void mcba_usb_process_ka_usb(struct mcba_priv *priv,
461 struct mcba_usb_msg_ka_usb *msg)
463 if (unlikely(priv->usb_ka_first_pass)) {
464 netdev_info(priv->netdev, "PIC USB version %u.%u\n",
465 msg->soft_ver_major, msg->soft_ver_minor);
467 priv->usb_ka_first_pass = false;
470 if (msg->termination_state == MCBA_VER_TERMINATION_ON)
471 priv->can.termination = MCBA_TERMINATION_ENABLED;
473 priv->can.termination = MCBA_TERMINATION_DISABLED;
476 static u32 convert_can2host_bitrate(struct mcba_usb_msg_ka_can *msg)
478 const u32 bitrate = get_unaligned_be16(&msg->can_bitrate);
480 if ((bitrate == 33) || (bitrate == 83))
481 return bitrate * 1000 + 333;
483 return bitrate * 1000;
486 static void mcba_usb_process_ka_can(struct mcba_priv *priv,
487 struct mcba_usb_msg_ka_can *msg)
489 if (unlikely(priv->can_ka_first_pass)) {
490 netdev_info(priv->netdev, "PIC CAN version %u.%u\n",
491 msg->soft_ver_major, msg->soft_ver_minor);
493 priv->can_ka_first_pass = false;
496 if (unlikely(priv->can_speed_check)) {
497 const u32 bitrate = convert_can2host_bitrate(msg);
499 priv->can_speed_check = false;
501 if (bitrate != priv->can.bittiming.bitrate)
504 "Wrong bitrate reported by the device (%u). Expected %u",
505 bitrate, priv->can.bittiming.bitrate);
508 priv->bec.txerr = msg->tx_err_cnt;
509 priv->bec.rxerr = msg->rx_err_cnt;
512 priv->can.state = CAN_STATE_BUS_OFF;
514 else if ((priv->bec.txerr > MCBA_CAN_STATE_ERR_PSV_TH) ||
515 (priv->bec.rxerr > MCBA_CAN_STATE_ERR_PSV_TH))
516 priv->can.state = CAN_STATE_ERROR_PASSIVE;
518 else if ((priv->bec.txerr > MCBA_CAN_STATE_WRN_TH) ||
519 (priv->bec.rxerr > MCBA_CAN_STATE_WRN_TH))
520 priv->can.state = CAN_STATE_ERROR_WARNING;
523 static void mcba_usb_process_rx(struct mcba_priv *priv,
524 struct mcba_usb_msg *msg)
526 switch (msg->cmd_id) {
527 case MBCA_CMD_I_AM_ALIVE_FROM_CAN:
528 mcba_usb_process_ka_can(priv,
529 (struct mcba_usb_msg_ka_can *)msg);
532 case MBCA_CMD_I_AM_ALIVE_FROM_USB:
533 mcba_usb_process_ka_usb(priv,
534 (struct mcba_usb_msg_ka_usb *)msg);
537 case MBCA_CMD_RECEIVE_MESSAGE:
538 mcba_usb_process_can(priv, (struct mcba_usb_msg_can *)msg);
541 case MBCA_CMD_NOTHING_TO_SEND:
542 /* Side effect of communication between PIC_USB and PIC_CAN.
543 * PIC_CAN is telling us that it has nothing to send
547 case MBCA_CMD_TRANSMIT_MESSAGE_RSP:
548 /* Transmission response from the device containing timestamp */
552 netdev_warn(priv->netdev, "Unsupported msg (0x%X)",
558 /* Callback for reading data from device
560 * Check urb status, call read function and resubmit urb read operation.
562 static void mcba_usb_read_bulk_callback(struct urb *urb)
564 struct mcba_priv *priv = urb->context;
565 struct net_device *netdev;
569 netdev = priv->netdev;
571 if (!netif_device_present(netdev))
574 switch (urb->status) {
575 case 0: /* success */
585 netdev_info(netdev, "Rx URB aborted (%d)\n", urb->status);
590 while (pos < urb->actual_length) {
591 struct mcba_usb_msg *msg;
593 if (pos + sizeof(struct mcba_usb_msg) > urb->actual_length) {
594 netdev_err(priv->netdev, "format error\n");
598 msg = (struct mcba_usb_msg *)(urb->transfer_buffer + pos);
599 mcba_usb_process_rx(priv, msg);
601 pos += sizeof(struct mcba_usb_msg);
606 usb_fill_bulk_urb(urb, priv->udev,
608 urb->transfer_buffer, MCBA_USB_RX_BUFF_SIZE,
609 mcba_usb_read_bulk_callback, priv);
611 retval = usb_submit_urb(urb, GFP_ATOMIC);
613 if (retval == -ENODEV)
614 netif_device_detach(netdev);
616 netdev_err(netdev, "failed resubmitting read bulk urb: %d\n",
620 /* Start USB device */
621 static int mcba_usb_start(struct mcba_priv *priv)
623 struct net_device *netdev = priv->netdev;
628 for (i = 0; i < MCBA_MAX_RX_URBS; i++) {
629 struct urb *urb = NULL;
633 /* create a URB, and a buffer for it */
634 urb = usb_alloc_urb(0, GFP_KERNEL);
640 buf = usb_alloc_coherent(priv->udev, MCBA_USB_RX_BUFF_SIZE,
641 GFP_KERNEL, &buf_dma);
643 netdev_err(netdev, "No memory left for USB buffer\n");
649 urb->transfer_dma = buf_dma;
651 usb_fill_bulk_urb(urb, priv->udev,
653 buf, MCBA_USB_RX_BUFF_SIZE,
654 mcba_usb_read_bulk_callback, priv);
655 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
656 usb_anchor_urb(urb, &priv->rx_submitted);
658 err = usb_submit_urb(urb, GFP_KERNEL);
660 usb_unanchor_urb(urb);
661 usb_free_coherent(priv->udev, MCBA_USB_RX_BUFF_SIZE,
667 priv->rxbuf[i] = buf;
668 priv->rxbuf_dma[i] = buf_dma;
670 /* Drop reference, USB core will take care of freeing it */
674 /* Did we submit any URBs */
676 netdev_warn(netdev, "couldn't setup read URBs\n");
680 /* Warn if we've couldn't transmit all the URBs */
681 if (i < MCBA_MAX_RX_URBS)
682 netdev_warn(netdev, "rx performance may be slow\n");
684 mcba_usb_xmit_read_fw_ver(priv, MCBA_VER_REQ_USB);
685 mcba_usb_xmit_read_fw_ver(priv, MCBA_VER_REQ_CAN);
690 /* Open USB device */
691 static int mcba_usb_open(struct net_device *netdev)
693 struct mcba_priv *priv = netdev_priv(netdev);
697 err = open_candev(netdev);
701 priv->can_speed_check = true;
702 priv->can.state = CAN_STATE_ERROR_ACTIVE;
704 netif_start_queue(netdev);
709 static void mcba_urb_unlink(struct mcba_priv *priv)
713 usb_kill_anchored_urbs(&priv->rx_submitted);
715 for (i = 0; i < MCBA_MAX_RX_URBS; ++i)
716 usb_free_coherent(priv->udev, MCBA_USB_RX_BUFF_SIZE,
717 priv->rxbuf[i], priv->rxbuf_dma[i]);
719 usb_kill_anchored_urbs(&priv->tx_submitted);
722 /* Close USB device */
723 static int mcba_usb_close(struct net_device *netdev)
725 struct mcba_priv *priv = netdev_priv(netdev);
727 priv->can.state = CAN_STATE_STOPPED;
729 netif_stop_queue(netdev);
732 mcba_urb_unlink(priv);
734 close_candev(netdev);
739 /* Set network device mode
741 * Maybe we should leave this function empty, because the device
742 * set mode variable with open command.
744 static int mcba_net_set_mode(struct net_device *netdev, enum can_mode mode)
749 static int mcba_net_get_berr_counter(const struct net_device *netdev,
750 struct can_berr_counter *bec)
752 struct mcba_priv *priv = netdev_priv(netdev);
754 bec->txerr = priv->bec.txerr;
755 bec->rxerr = priv->bec.rxerr;
760 static const struct net_device_ops mcba_netdev_ops = {
761 .ndo_open = mcba_usb_open,
762 .ndo_stop = mcba_usb_close,
763 .ndo_start_xmit = mcba_usb_start_xmit,
766 static const struct ethtool_ops mcba_ethtool_ops = {
767 .get_ts_info = ethtool_op_get_ts_info,
770 /* Microchip CANBUS has hardcoded bittiming values by default.
771 * This function sends request via USB to change the speed and align bittiming
772 * values for presentation purposes only
774 static int mcba_net_set_bittiming(struct net_device *netdev)
776 struct mcba_priv *priv = netdev_priv(netdev);
777 const u16 bitrate_kbps = priv->can.bittiming.bitrate / 1000;
779 mcba_usb_xmit_change_bitrate(priv, bitrate_kbps);
784 static int mcba_set_termination(struct net_device *netdev, u16 term)
786 struct mcba_priv *priv = netdev_priv(netdev);
787 struct mcba_usb_msg_termination usb_msg = {
788 .cmd_id = MBCA_CMD_SETUP_TERMINATION_RESISTANCE
791 if (term == MCBA_TERMINATION_ENABLED)
792 usb_msg.termination = MCBA_VER_TERMINATION_ON;
794 usb_msg.termination = MCBA_VER_TERMINATION_OFF;
796 mcba_usb_xmit_cmd(priv, (struct mcba_usb_msg *)&usb_msg);
801 static int mcba_usb_probe(struct usb_interface *intf,
802 const struct usb_device_id *id)
804 struct net_device *netdev;
805 struct mcba_priv *priv;
807 struct usb_device *usbdev = interface_to_usbdev(intf);
808 struct usb_endpoint_descriptor *in, *out;
810 err = usb_find_common_endpoints(intf->cur_altsetting, &in, &out, NULL, NULL);
812 dev_err(&intf->dev, "Can't find endpoints\n");
816 netdev = alloc_candev(sizeof(struct mcba_priv), MCBA_MAX_TX_URBS);
818 dev_err(&intf->dev, "Couldn't alloc candev\n");
822 priv = netdev_priv(netdev);
825 priv->netdev = netdev;
826 priv->usb_ka_first_pass = true;
827 priv->can_ka_first_pass = true;
828 priv->can_speed_check = false;
830 init_usb_anchor(&priv->rx_submitted);
831 init_usb_anchor(&priv->tx_submitted);
833 usb_set_intfdata(intf, priv);
835 /* Init CAN device */
836 priv->can.state = CAN_STATE_STOPPED;
837 priv->can.termination_const = mcba_termination;
838 priv->can.termination_const_cnt = ARRAY_SIZE(mcba_termination);
839 priv->can.bitrate_const = mcba_bitrate;
840 priv->can.bitrate_const_cnt = ARRAY_SIZE(mcba_bitrate);
842 priv->can.do_set_termination = mcba_set_termination;
843 priv->can.do_set_mode = mcba_net_set_mode;
844 priv->can.do_get_berr_counter = mcba_net_get_berr_counter;
845 priv->can.do_set_bittiming = mcba_net_set_bittiming;
847 netdev->netdev_ops = &mcba_netdev_ops;
848 netdev->ethtool_ops = &mcba_ethtool_ops;
850 netdev->flags |= IFF_ECHO; /* we support local echo */
852 SET_NETDEV_DEV(netdev, &intf->dev);
854 err = register_candev(netdev);
856 netdev_err(netdev, "couldn't register CAN device: %d\n", err);
858 goto cleanup_free_candev;
861 priv->rx_pipe = usb_rcvbulkpipe(priv->udev, in->bEndpointAddress);
862 priv->tx_pipe = usb_sndbulkpipe(priv->udev, out->bEndpointAddress);
864 /* Start USB dev only if we have successfully registered CAN device */
865 err = mcba_usb_start(priv);
868 netif_device_detach(priv->netdev);
870 netdev_warn(netdev, "couldn't start device: %d\n", err);
872 goto cleanup_unregister_candev;
875 dev_info(&intf->dev, "Microchip CAN BUS Analyzer connected\n");
879 cleanup_unregister_candev:
880 unregister_candev(priv->netdev);
888 /* Called by the usb core when driver is unloaded or device is removed */
889 static void mcba_usb_disconnect(struct usb_interface *intf)
891 struct mcba_priv *priv = usb_get_intfdata(intf);
893 usb_set_intfdata(intf, NULL);
895 netdev_info(priv->netdev, "device disconnected\n");
897 unregister_candev(priv->netdev);
898 mcba_urb_unlink(priv);
899 free_candev(priv->netdev);
902 static struct usb_driver mcba_usb_driver = {
903 .name = MCBA_MODULE_NAME,
904 .probe = mcba_usb_probe,
905 .disconnect = mcba_usb_disconnect,
906 .id_table = mcba_usb_table,
909 module_usb_driver(mcba_usb_driver);
912 MODULE_DESCRIPTION("SocketCAN driver for Microchip CAN BUS Analyzer Tool");
913 MODULE_LICENSE("GPL v2");