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/can/led.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 #define MCBA_SIDL_EXID_MASK 0x8
51 #define MCBA_DLC_MASK 0xf
52 #define MCBA_DLC_RTR_MASK 0x40
54 #define MCBA_CAN_STATE_WRN_TH 95
55 #define MCBA_CAN_STATE_ERR_PSV_TH 127
57 #define MCBA_TERMINATION_DISABLED CAN_TERMINATION_DISABLED
58 #define MCBA_TERMINATION_ENABLED 120
61 struct mcba_priv *priv;
66 /* Structure to hold all of our device specific stuff */
68 struct can_priv can; /* must be the first member */
69 struct sk_buff *echo_skb[MCBA_MAX_TX_URBS];
70 struct mcba_usb_ctx tx_context[MCBA_MAX_TX_URBS];
71 struct usb_device *udev;
72 struct net_device *netdev;
73 struct usb_anchor tx_submitted;
74 struct usb_anchor rx_submitted;
75 struct can_berr_counter bec;
76 bool usb_ka_first_pass;
77 bool can_ka_first_pass;
79 atomic_t free_ctx_cnt;
80 void *rxbuf[MCBA_MAX_RX_URBS];
81 dma_addr_t rxbuf_dma[MCBA_MAX_RX_URBS];
87 struct __packed mcba_usb_msg_can {
98 struct __packed mcba_usb_msg {
103 struct __packed mcba_usb_msg_ka_usb {
105 u8 termination_state;
111 struct __packed mcba_usb_msg_ka_can {
128 struct __packed mcba_usb_msg_change_bitrate {
134 struct __packed mcba_usb_msg_termination {
140 struct __packed mcba_usb_msg_fw_ver {
146 static const struct usb_device_id mcba_usb_table[] = {
147 { USB_DEVICE(MCBA_VENDOR_ID, MCBA_PRODUCT_ID) },
148 {} /* Terminating entry */
151 MODULE_DEVICE_TABLE(usb, mcba_usb_table);
153 static const u16 mcba_termination[] = { MCBA_TERMINATION_DISABLED,
154 MCBA_TERMINATION_ENABLED };
156 static const u32 mcba_bitrate[] = { 20000, 33333, 50000, 80000, 83333,
157 100000, 125000, 150000, 175000, 200000,
158 225000, 250000, 275000, 300000, 500000,
159 625000, 800000, 1000000 };
161 static inline void mcba_init_ctx(struct mcba_priv *priv)
165 for (i = 0; i < MCBA_MAX_TX_URBS; i++) {
166 priv->tx_context[i].ndx = MCBA_CTX_FREE;
167 priv->tx_context[i].priv = priv;
170 atomic_set(&priv->free_ctx_cnt, ARRAY_SIZE(priv->tx_context));
173 static inline struct mcba_usb_ctx *mcba_usb_get_free_ctx(struct mcba_priv *priv,
174 struct can_frame *cf)
177 struct mcba_usb_ctx *ctx = NULL;
179 for (i = 0; i < MCBA_MAX_TX_URBS; i++) {
180 if (priv->tx_context[i].ndx == MCBA_CTX_FREE) {
181 ctx = &priv->tx_context[i];
189 atomic_dec(&priv->free_ctx_cnt);
194 if (!atomic_read(&priv->free_ctx_cnt))
195 /* That was the last free ctx. Slow down tx path */
196 netif_stop_queue(priv->netdev);
201 /* mcba_usb_free_ctx and mcba_usb_get_free_ctx are executed by different
202 * threads. The order of execution in below function is important.
204 static inline void mcba_usb_free_ctx(struct mcba_usb_ctx *ctx)
206 /* Increase number of free ctxs before freeing ctx */
207 atomic_inc(&ctx->priv->free_ctx_cnt);
209 ctx->ndx = MCBA_CTX_FREE;
211 /* Wake up the queue once ctx is marked free */
212 netif_wake_queue(ctx->priv->netdev);
215 static void mcba_usb_write_bulk_callback(struct urb *urb)
217 struct mcba_usb_ctx *ctx = urb->context;
218 struct net_device *netdev;
222 netdev = ctx->priv->netdev;
224 /* free up our allocated buffer */
225 usb_free_coherent(urb->dev, urb->transfer_buffer_length,
226 urb->transfer_buffer, urb->transfer_dma);
229 if (!netif_device_present(netdev))
232 netdev->stats.tx_packets++;
233 netdev->stats.tx_bytes += can_get_echo_skb(netdev, ctx->ndx,
236 can_led_event(netdev, CAN_LED_EVENT_TX);
240 netdev_info(netdev, "Tx URB aborted (%d)\n", urb->status);
242 /* Release the context */
243 mcba_usb_free_ctx(ctx);
246 /* Send data to device */
247 static netdev_tx_t mcba_usb_xmit(struct mcba_priv *priv,
248 struct mcba_usb_msg *usb_msg,
249 struct mcba_usb_ctx *ctx)
255 /* create a URB, and a buffer for it, and copy the data to the URB */
256 urb = usb_alloc_urb(0, GFP_ATOMIC);
260 buf = usb_alloc_coherent(priv->udev, MCBA_USB_TX_BUFF_SIZE, GFP_ATOMIC,
267 memcpy(buf, usb_msg, MCBA_USB_TX_BUFF_SIZE);
269 usb_fill_bulk_urb(urb, priv->udev, priv->tx_pipe, buf, MCBA_USB_TX_BUFF_SIZE,
270 mcba_usb_write_bulk_callback, ctx);
272 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
273 usb_anchor_urb(urb, &priv->tx_submitted);
275 err = usb_submit_urb(urb, GFP_ATOMIC);
279 /* Release our reference to this URB, the USB core will eventually free
287 usb_unanchor_urb(urb);
288 usb_free_coherent(priv->udev, MCBA_USB_TX_BUFF_SIZE, buf,
292 netif_device_detach(priv->netdev);
294 netdev_warn(priv->netdev, "failed tx_urb %d\n", err);
302 /* Send data to device */
303 static netdev_tx_t mcba_usb_start_xmit(struct sk_buff *skb,
304 struct net_device *netdev)
306 struct mcba_priv *priv = netdev_priv(netdev);
307 struct can_frame *cf = (struct can_frame *)skb->data;
308 struct mcba_usb_ctx *ctx = NULL;
309 struct net_device_stats *stats = &priv->netdev->stats;
312 struct mcba_usb_msg_can usb_msg = {
313 .cmd_id = MBCA_CMD_TRANSMIT_MESSAGE_EV
316 if (can_dropped_invalid_skb(netdev, skb))
319 ctx = mcba_usb_get_free_ctx(priv, cf);
321 return NETDEV_TX_BUSY;
323 if (cf->can_id & CAN_EFF_FLAG) {
324 /* SIDH | SIDL | EIDH | EIDL
325 * 28 - 21 | 20 19 18 x x x 17 16 | 15 - 8 | 7 - 0
327 sid = MCBA_SIDL_EXID_MASK;
328 /* store 28-18 bits */
329 sid |= (cf->can_id & 0x1ffc0000) >> 13;
330 /* store 17-16 bits */
331 sid |= (cf->can_id & 0x30000) >> 16;
332 put_unaligned_be16(sid, &usb_msg.sid);
334 /* store 15-0 bits */
335 put_unaligned_be16(cf->can_id & 0xffff, &usb_msg.eid);
338 * 10 - 3 | 2 1 0 x x x x x
340 put_unaligned_be16((cf->can_id & CAN_SFF_MASK) << 5,
345 usb_msg.dlc = cf->len;
347 memcpy(usb_msg.data, cf->data, usb_msg.dlc);
349 if (cf->can_id & CAN_RTR_FLAG)
350 usb_msg.dlc |= MCBA_DLC_RTR_MASK;
352 can_put_echo_skb(skb, priv->netdev, ctx->ndx, 0);
354 err = mcba_usb_xmit(priv, (struct mcba_usb_msg *)&usb_msg, ctx);
361 can_free_echo_skb(priv->netdev, ctx->ndx, NULL);
362 mcba_usb_free_ctx(ctx);
368 /* Send cmd to device */
369 static void mcba_usb_xmit_cmd(struct mcba_priv *priv,
370 struct mcba_usb_msg *usb_msg)
372 struct mcba_usb_ctx *ctx = NULL;
375 ctx = mcba_usb_get_free_ctx(priv, NULL);
377 netdev_err(priv->netdev,
378 "Lack of free ctx. Sending (%d) cmd aborted",
384 err = mcba_usb_xmit(priv, usb_msg, ctx);
386 netdev_err(priv->netdev, "Failed to send cmd (%d)",
390 static void mcba_usb_xmit_change_bitrate(struct mcba_priv *priv, u16 bitrate)
392 struct mcba_usb_msg_change_bitrate usb_msg = {
393 .cmd_id = MBCA_CMD_CHANGE_BIT_RATE
396 put_unaligned_be16(bitrate, &usb_msg.bitrate);
398 mcba_usb_xmit_cmd(priv, (struct mcba_usb_msg *)&usb_msg);
401 static void mcba_usb_xmit_read_fw_ver(struct mcba_priv *priv, u8 pic)
403 struct mcba_usb_msg_fw_ver usb_msg = {
404 .cmd_id = MBCA_CMD_READ_FW_VERSION,
408 mcba_usb_xmit_cmd(priv, (struct mcba_usb_msg *)&usb_msg);
411 static void mcba_usb_process_can(struct mcba_priv *priv,
412 struct mcba_usb_msg_can *msg)
414 struct can_frame *cf;
416 struct net_device_stats *stats = &priv->netdev->stats;
419 skb = alloc_can_skb(priv->netdev, &cf);
423 sid = get_unaligned_be16(&msg->sid);
425 if (sid & MCBA_SIDL_EXID_MASK) {
426 /* SIDH | SIDL | EIDH | EIDL
427 * 28 - 21 | 20 19 18 x x x 17 16 | 15 - 8 | 7 - 0
429 cf->can_id = CAN_EFF_FLAG;
431 /* store 28-18 bits */
432 cf->can_id |= (sid & 0xffe0) << 13;
433 /* store 17-16 bits */
434 cf->can_id |= (sid & 3) << 16;
435 /* store 15-0 bits */
436 cf->can_id |= get_unaligned_be16(&msg->eid);
439 * 10 - 3 | 2 1 0 x x x x x
441 cf->can_id = (sid & 0xffe0) >> 5;
444 cf->len = can_cc_dlc2len(msg->dlc & MCBA_DLC_MASK);
446 if (msg->dlc & MCBA_DLC_RTR_MASK) {
447 cf->can_id |= CAN_RTR_FLAG;
449 memcpy(cf->data, msg->data, cf->len);
451 stats->rx_bytes += cf->len;
455 can_led_event(priv->netdev, CAN_LED_EVENT_RX);
459 static void mcba_usb_process_ka_usb(struct mcba_priv *priv,
460 struct mcba_usb_msg_ka_usb *msg)
462 if (unlikely(priv->usb_ka_first_pass)) {
463 netdev_info(priv->netdev, "PIC USB version %u.%u\n",
464 msg->soft_ver_major, msg->soft_ver_minor);
466 priv->usb_ka_first_pass = false;
469 if (msg->termination_state)
470 priv->can.termination = MCBA_TERMINATION_ENABLED;
472 priv->can.termination = MCBA_TERMINATION_DISABLED;
475 static u32 convert_can2host_bitrate(struct mcba_usb_msg_ka_can *msg)
477 const u32 bitrate = get_unaligned_be16(&msg->can_bitrate);
479 if ((bitrate == 33) || (bitrate == 83))
480 return bitrate * 1000 + 333;
482 return bitrate * 1000;
485 static void mcba_usb_process_ka_can(struct mcba_priv *priv,
486 struct mcba_usb_msg_ka_can *msg)
488 if (unlikely(priv->can_ka_first_pass)) {
489 netdev_info(priv->netdev, "PIC CAN version %u.%u\n",
490 msg->soft_ver_major, msg->soft_ver_minor);
492 priv->can_ka_first_pass = false;
495 if (unlikely(priv->can_speed_check)) {
496 const u32 bitrate = convert_can2host_bitrate(msg);
498 priv->can_speed_check = false;
500 if (bitrate != priv->can.bittiming.bitrate)
503 "Wrong bitrate reported by the device (%u). Expected %u",
504 bitrate, priv->can.bittiming.bitrate);
507 priv->bec.txerr = msg->tx_err_cnt;
508 priv->bec.rxerr = msg->rx_err_cnt;
511 priv->can.state = CAN_STATE_BUS_OFF;
513 else if ((priv->bec.txerr > MCBA_CAN_STATE_ERR_PSV_TH) ||
514 (priv->bec.rxerr > MCBA_CAN_STATE_ERR_PSV_TH))
515 priv->can.state = CAN_STATE_ERROR_PASSIVE;
517 else if ((priv->bec.txerr > MCBA_CAN_STATE_WRN_TH) ||
518 (priv->bec.rxerr > MCBA_CAN_STATE_WRN_TH))
519 priv->can.state = CAN_STATE_ERROR_WARNING;
522 static void mcba_usb_process_rx(struct mcba_priv *priv,
523 struct mcba_usb_msg *msg)
525 switch (msg->cmd_id) {
526 case MBCA_CMD_I_AM_ALIVE_FROM_CAN:
527 mcba_usb_process_ka_can(priv,
528 (struct mcba_usb_msg_ka_can *)msg);
531 case MBCA_CMD_I_AM_ALIVE_FROM_USB:
532 mcba_usb_process_ka_usb(priv,
533 (struct mcba_usb_msg_ka_usb *)msg);
536 case MBCA_CMD_RECEIVE_MESSAGE:
537 mcba_usb_process_can(priv, (struct mcba_usb_msg_can *)msg);
540 case MBCA_CMD_NOTHING_TO_SEND:
541 /* Side effect of communication between PIC_USB and PIC_CAN.
542 * PIC_CAN is telling us that it has nothing to send
546 case MBCA_CMD_TRANSMIT_MESSAGE_RSP:
547 /* Transmission response from the device containing timestamp */
551 netdev_warn(priv->netdev, "Unsupported msg (0x%X)",
557 /* Callback for reading data from device
559 * Check urb status, call read function and resubmit urb read operation.
561 static void mcba_usb_read_bulk_callback(struct urb *urb)
563 struct mcba_priv *priv = urb->context;
564 struct net_device *netdev;
568 netdev = priv->netdev;
570 if (!netif_device_present(netdev))
573 switch (urb->status) {
574 case 0: /* success */
584 netdev_info(netdev, "Rx URB aborted (%d)\n", urb->status);
589 while (pos < urb->actual_length) {
590 struct mcba_usb_msg *msg;
592 if (pos + sizeof(struct mcba_usb_msg) > urb->actual_length) {
593 netdev_err(priv->netdev, "format error\n");
597 msg = (struct mcba_usb_msg *)(urb->transfer_buffer + pos);
598 mcba_usb_process_rx(priv, msg);
600 pos += sizeof(struct mcba_usb_msg);
605 usb_fill_bulk_urb(urb, priv->udev,
607 urb->transfer_buffer, MCBA_USB_RX_BUFF_SIZE,
608 mcba_usb_read_bulk_callback, priv);
610 retval = usb_submit_urb(urb, GFP_ATOMIC);
612 if (retval == -ENODEV)
613 netif_device_detach(netdev);
615 netdev_err(netdev, "failed resubmitting read bulk urb: %d\n",
619 /* Start USB device */
620 static int mcba_usb_start(struct mcba_priv *priv)
622 struct net_device *netdev = priv->netdev;
627 for (i = 0; i < MCBA_MAX_RX_URBS; i++) {
628 struct urb *urb = NULL;
632 /* create a URB, and a buffer for it */
633 urb = usb_alloc_urb(0, GFP_KERNEL);
639 buf = usb_alloc_coherent(priv->udev, MCBA_USB_RX_BUFF_SIZE,
640 GFP_KERNEL, &buf_dma);
642 netdev_err(netdev, "No memory left for USB buffer\n");
648 urb->transfer_dma = buf_dma;
650 usb_fill_bulk_urb(urb, priv->udev,
652 buf, MCBA_USB_RX_BUFF_SIZE,
653 mcba_usb_read_bulk_callback, priv);
654 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
655 usb_anchor_urb(urb, &priv->rx_submitted);
657 err = usb_submit_urb(urb, GFP_KERNEL);
659 usb_unanchor_urb(urb);
660 usb_free_coherent(priv->udev, MCBA_USB_RX_BUFF_SIZE,
666 priv->rxbuf[i] = buf;
667 priv->rxbuf_dma[i] = buf_dma;
669 /* Drop reference, USB core will take care of freeing it */
673 /* Did we submit any URBs */
675 netdev_warn(netdev, "couldn't setup read URBs\n");
679 /* Warn if we've couldn't transmit all the URBs */
680 if (i < MCBA_MAX_RX_URBS)
681 netdev_warn(netdev, "rx performance may be slow\n");
683 mcba_usb_xmit_read_fw_ver(priv, MCBA_VER_REQ_USB);
684 mcba_usb_xmit_read_fw_ver(priv, MCBA_VER_REQ_CAN);
689 /* Open USB device */
690 static int mcba_usb_open(struct net_device *netdev)
692 struct mcba_priv *priv = netdev_priv(netdev);
696 err = open_candev(netdev);
700 priv->can_speed_check = true;
701 priv->can.state = CAN_STATE_ERROR_ACTIVE;
703 can_led_event(netdev, CAN_LED_EVENT_OPEN);
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);
735 can_led_event(netdev, CAN_LED_EVENT_STOP);
740 /* Set network device mode
742 * Maybe we should leave this function empty, because the device
743 * set mode variable with open command.
745 static int mcba_net_set_mode(struct net_device *netdev, enum can_mode mode)
750 static int mcba_net_get_berr_counter(const struct net_device *netdev,
751 struct can_berr_counter *bec)
753 struct mcba_priv *priv = netdev_priv(netdev);
755 bec->txerr = priv->bec.txerr;
756 bec->rxerr = priv->bec.rxerr;
761 static const struct net_device_ops mcba_netdev_ops = {
762 .ndo_open = mcba_usb_open,
763 .ndo_stop = mcba_usb_close,
764 .ndo_start_xmit = mcba_usb_start_xmit,
767 /* Microchip CANBUS has hardcoded bittiming values by default.
768 * This function sends request via USB to change the speed and align bittiming
769 * values for presentation purposes only
771 static int mcba_net_set_bittiming(struct net_device *netdev)
773 struct mcba_priv *priv = netdev_priv(netdev);
774 const u16 bitrate_kbps = priv->can.bittiming.bitrate / 1000;
776 mcba_usb_xmit_change_bitrate(priv, bitrate_kbps);
781 static int mcba_set_termination(struct net_device *netdev, u16 term)
783 struct mcba_priv *priv = netdev_priv(netdev);
784 struct mcba_usb_msg_termination usb_msg = {
785 .cmd_id = MBCA_CMD_SETUP_TERMINATION_RESISTANCE
788 if (term == MCBA_TERMINATION_ENABLED)
789 usb_msg.termination = 1;
791 usb_msg.termination = 0;
793 mcba_usb_xmit_cmd(priv, (struct mcba_usb_msg *)&usb_msg);
798 static int mcba_usb_probe(struct usb_interface *intf,
799 const struct usb_device_id *id)
801 struct net_device *netdev;
802 struct mcba_priv *priv;
804 struct usb_device *usbdev = interface_to_usbdev(intf);
805 struct usb_endpoint_descriptor *in, *out;
807 err = usb_find_common_endpoints(intf->cur_altsetting, &in, &out, NULL, NULL);
809 dev_err(&intf->dev, "Can't find endpoints\n");
813 netdev = alloc_candev(sizeof(struct mcba_priv), MCBA_MAX_TX_URBS);
815 dev_err(&intf->dev, "Couldn't alloc candev\n");
819 priv = netdev_priv(netdev);
822 priv->netdev = netdev;
823 priv->usb_ka_first_pass = true;
824 priv->can_ka_first_pass = true;
825 priv->can_speed_check = false;
827 init_usb_anchor(&priv->rx_submitted);
828 init_usb_anchor(&priv->tx_submitted);
830 usb_set_intfdata(intf, priv);
832 /* Init CAN device */
833 priv->can.state = CAN_STATE_STOPPED;
834 priv->can.termination_const = mcba_termination;
835 priv->can.termination_const_cnt = ARRAY_SIZE(mcba_termination);
836 priv->can.bitrate_const = mcba_bitrate;
837 priv->can.bitrate_const_cnt = ARRAY_SIZE(mcba_bitrate);
839 priv->can.do_set_termination = mcba_set_termination;
840 priv->can.do_set_mode = mcba_net_set_mode;
841 priv->can.do_get_berr_counter = mcba_net_get_berr_counter;
842 priv->can.do_set_bittiming = mcba_net_set_bittiming;
844 netdev->netdev_ops = &mcba_netdev_ops;
846 netdev->flags |= IFF_ECHO; /* we support local echo */
848 SET_NETDEV_DEV(netdev, &intf->dev);
850 err = register_candev(netdev);
852 netdev_err(netdev, "couldn't register CAN device: %d\n", err);
854 goto cleanup_free_candev;
857 priv->rx_pipe = usb_rcvbulkpipe(priv->udev, in->bEndpointAddress);
858 priv->tx_pipe = usb_sndbulkpipe(priv->udev, out->bEndpointAddress);
860 devm_can_led_init(netdev);
862 /* Start USB dev only if we have successfully registered CAN device */
863 err = mcba_usb_start(priv);
866 netif_device_detach(priv->netdev);
868 netdev_warn(netdev, "couldn't start device: %d\n", err);
870 goto cleanup_unregister_candev;
873 dev_info(&intf->dev, "Microchip CAN BUS Analyzer connected\n");
877 cleanup_unregister_candev:
878 unregister_candev(priv->netdev);
886 /* Called by the usb core when driver is unloaded or device is removed */
887 static void mcba_usb_disconnect(struct usb_interface *intf)
889 struct mcba_priv *priv = usb_get_intfdata(intf);
891 usb_set_intfdata(intf, NULL);
893 netdev_info(priv->netdev, "device disconnected\n");
895 unregister_candev(priv->netdev);
896 mcba_urb_unlink(priv);
897 free_candev(priv->netdev);
900 static struct usb_driver mcba_usb_driver = {
901 .name = MCBA_MODULE_NAME,
902 .probe = mcba_usb_probe,
903 .disconnect = mcba_usb_disconnect,
904 .id_table = mcba_usb_table,
907 module_usb_driver(mcba_usb_driver);
909 MODULE_AUTHOR("Remigiusz Kołłątaj <remigiusz.kollataj@mobica.com>");
910 MODULE_DESCRIPTION("SocketCAN driver for Microchip CAN BUS Analyzer Tool");
911 MODULE_LICENSE("GPL v2");