Commit c3d39612 authored by Marc Kleine-Budde's avatar Marc Kleine-Budde

Merge branch 'preparation-for-supporting-esd-CAN-USB-3'

Frank Jungclaus says:
====================
All following 5 patches must be seen as preparation for adding support
of the newly available esd CAN-USB/3 to esd_usb2.c.

After having gained some confidence and experience on sending patches
to linux-can@vger.kernel.org, I'll again submit the code changes for
CAN-USB/3 support as step #2.
====================

Link: https://lore.kernel.org/all/20220624190517.2299701-1-frank.jungclaus@esd.euSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parents ec30c109 ce87c0f1
...@@ -7406,6 +7406,13 @@ S: Maintained ...@@ -7406,6 +7406,13 @@ S: Maintained
F: include/linux/errseq.h F: include/linux/errseq.h
F: lib/errseq.c F: lib/errseq.c
ESD CAN/USB DRIVERS
M: Frank Jungclaus <frank.jungclaus@esd.eu>
R: socketcan@esd.eu
L: linux-can@vger.kernel.org
S: Maintained
F: drivers/net/can/usb/esd_usb.c
ET131X NETWORK DRIVER ET131X NETWORK DRIVER
M: Mark Einon <mark.einon@gmail.com> M: Mark Einon <mark.einon@gmail.com>
S: Odd Fixes S: Odd Fixes
......
...@@ -14,11 +14,18 @@ config CAN_EMS_USB ...@@ -14,11 +14,18 @@ config CAN_EMS_USB
This driver is for the one channel CPC-USB/ARM7 CAN/USB interface This driver is for the one channel CPC-USB/ARM7 CAN/USB interface
from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de). from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de).
config CAN_ESD_USB2 config CAN_ESD_USB
tristate "ESD USB/2 CAN/USB interface" tristate "esd electronics gmbh CAN/USB interfaces"
help help
This driver supports the CAN-USB/2 interface This driver adds supports for several CAN/USB interfaces
from esd electronic system design gmbh (http://www.esd.eu). from esd electronics gmbh (https://www.esd.eu).
The drivers supports the following devices:
- esd CAN-USB/2
- esd CAN-USB/Micro
To compile this driver as a module, choose M here: the module
will be called esd_usb.
config CAN_ETAS_ES58X config CAN_ETAS_ES58X
tristate "ETAS ES58X CAN/USB interfaces" tristate "ETAS ES58X CAN/USB interfaces"
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
obj-$(CONFIG_CAN_8DEV_USB) += usb_8dev.o obj-$(CONFIG_CAN_8DEV_USB) += usb_8dev.o
obj-$(CONFIG_CAN_EMS_USB) += ems_usb.o obj-$(CONFIG_CAN_EMS_USB) += ems_usb.o
obj-$(CONFIG_CAN_ESD_USB2) += esd_usb2.o obj-$(CONFIG_CAN_ESD_USB) += esd_usb.o
obj-$(CONFIG_CAN_ETAS_ES58X) += etas_es58x/ obj-$(CONFIG_CAN_ETAS_ES58X) += etas_es58x/
obj-$(CONFIG_CAN_GS_USB) += gs_usb.o obj-$(CONFIG_CAN_GS_USB) += gs_usb.o
obj-$(CONFIG_CAN_KVASER_USB) += kvaser_usb/ obj-$(CONFIG_CAN_KVASER_USB) += kvaser_usb/
......
// SPDX-License-Identifier: GPL-2.0-only // SPDX-License-Identifier: GPL-2.0-only
/* /*
* CAN driver for esd CAN-USB/2 and CAN-USB/Micro * CAN driver for esd electronics gmbh CAN-USB/2 and CAN-USB/Micro
* *
* Copyright (C) 2010-2012 Matthias Fuchs <matthias.fuchs@esd.eu>, esd gmbh * Copyright (C) 2010-2012 esd electronic system design gmbh, Matthias Fuchs <socketcan@esd.eu>
* Copyright (C) 2022 esd electronics gmbh, Frank Jungclaus <frank.jungclaus@esd.eu>
*/ */
#include <linux/signal.h> #include <linux/signal.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -14,20 +15,24 @@ ...@@ -14,20 +15,24 @@
#include <linux/can/dev.h> #include <linux/can/dev.h>
#include <linux/can/error.h> #include <linux/can/error.h>
MODULE_AUTHOR("Matthias Fuchs <matthias.fuchs@esd.eu>"); MODULE_AUTHOR("Matthias Fuchs <socketcan@esd.eu>");
MODULE_DESCRIPTION("CAN driver for esd CAN-USB/2 and CAN-USB/Micro interfaces"); MODULE_AUTHOR("Frank Jungclaus <frank.jungclaus@esd.eu>");
MODULE_DESCRIPTION("CAN driver for esd electronics gmbh CAN-USB/2 and CAN-USB/Micro interfaces");
MODULE_LICENSE("GPL v2"); MODULE_LICENSE("GPL v2");
/* Define these values to match your devices */ /* USB vendor and product ID */
#define USB_ESDGMBH_VENDOR_ID 0x0ab4 #define USB_ESDGMBH_VENDOR_ID 0x0ab4
#define USB_CANUSB2_PRODUCT_ID 0x0010 #define USB_CANUSB2_PRODUCT_ID 0x0010
#define USB_CANUSBM_PRODUCT_ID 0x0011 #define USB_CANUSBM_PRODUCT_ID 0x0011
/* CAN controller clock frequencies */
#define ESD_USB2_CAN_CLOCK 60000000 #define ESD_USB2_CAN_CLOCK 60000000
#define ESD_USBM_CAN_CLOCK 36000000 #define ESD_USBM_CAN_CLOCK 36000000
#define ESD_USB2_MAX_NETS 2
/* USB2 commands */ /* Maximum number of CAN nets */
#define ESD_USB_MAX_NETS 2
/* USB commands */
#define CMD_VERSION 1 /* also used for VERSION_REPLY */ #define CMD_VERSION 1 /* also used for VERSION_REPLY */
#define CMD_CAN_RX 2 /* device to host only */ #define CMD_CAN_RX 2 /* device to host only */
#define CMD_CAN_TX 3 /* also used for TX_DONE */ #define CMD_CAN_TX 3 /* also used for TX_DONE */
...@@ -43,13 +48,15 @@ MODULE_LICENSE("GPL v2"); ...@@ -43,13 +48,15 @@ MODULE_LICENSE("GPL v2");
#define ESD_EVENT 0x40000000 #define ESD_EVENT 0x40000000
#define ESD_IDMASK 0x1fffffff #define ESD_IDMASK 0x1fffffff
/* esd CAN event ids used by this driver */ /* esd CAN event ids */
#define ESD_EV_CAN_ERROR_EXT 2 #define ESD_EV_CAN_ERROR_EXT 2 /* CAN controller specific diagnostic data */
/* baudrate message flags */ /* baudrate message flags */
#define ESD_USB2_UBR 0x80000000 #define ESD_USB_UBR 0x80000000
#define ESD_USB2_LOM 0x40000000 #define ESD_USB_LOM 0x40000000
#define ESD_USB2_NO_BAUDRATE 0x7fffffff #define ESD_USB_NO_BAUDRATE 0x7fffffff
/* bit timing CAN-USB/2 */
#define ESD_USB2_TSEG1_MIN 1 #define ESD_USB2_TSEG1_MIN 1
#define ESD_USB2_TSEG1_MAX 16 #define ESD_USB2_TSEG1_MAX 16
#define ESD_USB2_TSEG1_SHIFT 16 #define ESD_USB2_TSEG1_SHIFT 16
...@@ -68,7 +75,7 @@ MODULE_LICENSE("GPL v2"); ...@@ -68,7 +75,7 @@ MODULE_LICENSE("GPL v2");
#define ESD_ID_ENABLE 0x80 #define ESD_ID_ENABLE 0x80
#define ESD_MAX_ID_SEGMENT 64 #define ESD_MAX_ID_SEGMENT 64
/* SJA1000 ECC register (emulated by usb2 firmware) */ /* SJA1000 ECC register (emulated by usb firmware) */
#define SJA1000_ECC_SEG 0x1F #define SJA1000_ECC_SEG 0x1F
#define SJA1000_ECC_DIR 0x20 #define SJA1000_ECC_DIR 0x20
#define SJA1000_ECC_ERR 0x06 #define SJA1000_ECC_ERR 0x06
...@@ -158,7 +165,7 @@ struct set_baudrate_msg { ...@@ -158,7 +165,7 @@ struct set_baudrate_msg {
}; };
/* Main message type used between library and application */ /* Main message type used between library and application */
struct __attribute__ ((packed)) esd_usb2_msg { struct __packed esd_usb_msg {
union { union {
struct header_msg hdr; struct header_msg hdr;
struct version_msg version; struct version_msg version;
...@@ -171,23 +178,23 @@ struct __attribute__ ((packed)) esd_usb2_msg { ...@@ -171,23 +178,23 @@ struct __attribute__ ((packed)) esd_usb2_msg {
} msg; } msg;
}; };
static struct usb_device_id esd_usb2_table[] = { static struct usb_device_id esd_usb_table[] = {
{USB_DEVICE(USB_ESDGMBH_VENDOR_ID, USB_CANUSB2_PRODUCT_ID)}, {USB_DEVICE(USB_ESDGMBH_VENDOR_ID, USB_CANUSB2_PRODUCT_ID)},
{USB_DEVICE(USB_ESDGMBH_VENDOR_ID, USB_CANUSBM_PRODUCT_ID)}, {USB_DEVICE(USB_ESDGMBH_VENDOR_ID, USB_CANUSBM_PRODUCT_ID)},
{} {}
}; };
MODULE_DEVICE_TABLE(usb, esd_usb2_table); MODULE_DEVICE_TABLE(usb, esd_usb_table);
struct esd_usb2_net_priv; struct esd_usb_net_priv;
struct esd_tx_urb_context { struct esd_tx_urb_context {
struct esd_usb2_net_priv *priv; struct esd_usb_net_priv *priv;
u32 echo_index; u32 echo_index;
}; };
struct esd_usb2 { struct esd_usb {
struct usb_device *udev; struct usb_device *udev;
struct esd_usb2_net_priv *nets[ESD_USB2_MAX_NETS]; struct esd_usb_net_priv *nets[ESD_USB_MAX_NETS];
struct usb_anchor rx_submitted; struct usb_anchor rx_submitted;
...@@ -198,22 +205,22 @@ struct esd_usb2 { ...@@ -198,22 +205,22 @@ struct esd_usb2 {
dma_addr_t rxbuf_dma[MAX_RX_URBS]; dma_addr_t rxbuf_dma[MAX_RX_URBS];
}; };
struct esd_usb2_net_priv { struct esd_usb_net_priv {
struct can_priv can; /* must be the first member */ struct can_priv can; /* must be the first member */
atomic_t active_tx_jobs; atomic_t active_tx_jobs;
struct usb_anchor tx_submitted; struct usb_anchor tx_submitted;
struct esd_tx_urb_context tx_contexts[MAX_TX_URBS]; struct esd_tx_urb_context tx_contexts[MAX_TX_URBS];
struct esd_usb2 *usb2; struct esd_usb *usb;
struct net_device *netdev; struct net_device *netdev;
int index; int index;
u8 old_state; u8 old_state;
struct can_berr_counter bec; struct can_berr_counter bec;
}; };
static void esd_usb2_rx_event(struct esd_usb2_net_priv *priv, static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
struct esd_usb2_msg *msg) struct esd_usb_msg *msg)
{ {
struct net_device_stats *stats = &priv->netdev->stats; struct net_device_stats *stats = &priv->netdev->stats;
struct can_frame *cf; struct can_frame *cf;
...@@ -296,8 +303,8 @@ static void esd_usb2_rx_event(struct esd_usb2_net_priv *priv, ...@@ -296,8 +303,8 @@ static void esd_usb2_rx_event(struct esd_usb2_net_priv *priv,
} }
} }
static void esd_usb2_rx_can_msg(struct esd_usb2_net_priv *priv, static void esd_usb_rx_can_msg(struct esd_usb_net_priv *priv,
struct esd_usb2_msg *msg) struct esd_usb_msg *msg)
{ {
struct net_device_stats *stats = &priv->netdev->stats; struct net_device_stats *stats = &priv->netdev->stats;
struct can_frame *cf; struct can_frame *cf;
...@@ -311,7 +318,7 @@ static void esd_usb2_rx_can_msg(struct esd_usb2_net_priv *priv, ...@@ -311,7 +318,7 @@ static void esd_usb2_rx_can_msg(struct esd_usb2_net_priv *priv,
id = le32_to_cpu(msg->msg.rx.id); id = le32_to_cpu(msg->msg.rx.id);
if (id & ESD_EVENT) { if (id & ESD_EVENT) {
esd_usb2_rx_event(priv, msg); esd_usb_rx_event(priv, msg);
} else { } else {
skb = alloc_can_skb(priv->netdev, &cf); skb = alloc_can_skb(priv->netdev, &cf);
if (skb == NULL) { if (skb == NULL) {
...@@ -338,12 +345,10 @@ static void esd_usb2_rx_can_msg(struct esd_usb2_net_priv *priv, ...@@ -338,12 +345,10 @@ static void esd_usb2_rx_can_msg(struct esd_usb2_net_priv *priv,
netif_rx(skb); netif_rx(skb);
} }
return;
} }
static void esd_usb2_tx_done_msg(struct esd_usb2_net_priv *priv, static void esd_usb_tx_done_msg(struct esd_usb_net_priv *priv,
struct esd_usb2_msg *msg) struct esd_usb_msg *msg)
{ {
struct net_device_stats *stats = &priv->netdev->stats; struct net_device_stats *stats = &priv->netdev->stats;
struct net_device *netdev = priv->netdev; struct net_device *netdev = priv->netdev;
...@@ -370,9 +375,9 @@ static void esd_usb2_tx_done_msg(struct esd_usb2_net_priv *priv, ...@@ -370,9 +375,9 @@ static void esd_usb2_tx_done_msg(struct esd_usb2_net_priv *priv,
netif_wake_queue(netdev); netif_wake_queue(netdev);
} }
static void esd_usb2_read_bulk_callback(struct urb *urb) static void esd_usb_read_bulk_callback(struct urb *urb)
{ {
struct esd_usb2 *dev = urb->context; struct esd_usb *dev = urb->context;
int retval; int retval;
int pos = 0; int pos = 0;
int i; int i;
...@@ -394,9 +399,9 @@ static void esd_usb2_read_bulk_callback(struct urb *urb) ...@@ -394,9 +399,9 @@ static void esd_usb2_read_bulk_callback(struct urb *urb)
} }
while (pos < urb->actual_length) { while (pos < urb->actual_length) {
struct esd_usb2_msg *msg; struct esd_usb_msg *msg;
msg = (struct esd_usb2_msg *)(urb->transfer_buffer + pos); msg = (struct esd_usb_msg *)(urb->transfer_buffer + pos);
switch (msg->msg.hdr.cmd) { switch (msg->msg.hdr.cmd) {
case CMD_CAN_RX: case CMD_CAN_RX:
...@@ -405,7 +410,7 @@ static void esd_usb2_read_bulk_callback(struct urb *urb) ...@@ -405,7 +410,7 @@ static void esd_usb2_read_bulk_callback(struct urb *urb)
break; break;
} }
esd_usb2_rx_can_msg(dev->nets[msg->msg.rx.net], msg); esd_usb_rx_can_msg(dev->nets[msg->msg.rx.net], msg);
break; break;
case CMD_CAN_TX: case CMD_CAN_TX:
...@@ -414,7 +419,7 @@ static void esd_usb2_read_bulk_callback(struct urb *urb) ...@@ -414,7 +419,7 @@ static void esd_usb2_read_bulk_callback(struct urb *urb)
break; break;
} }
esd_usb2_tx_done_msg(dev->nets[msg->msg.txdone.net], esd_usb_tx_done_msg(dev->nets[msg->msg.txdone.net],
msg); msg);
break; break;
} }
...@@ -430,7 +435,7 @@ static void esd_usb2_read_bulk_callback(struct urb *urb) ...@@ -430,7 +435,7 @@ static void esd_usb2_read_bulk_callback(struct urb *urb)
resubmit_urb: resubmit_urb:
usb_fill_bulk_urb(urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), usb_fill_bulk_urb(urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
urb->transfer_buffer, RX_BUFFER_SIZE, urb->transfer_buffer, RX_BUFFER_SIZE,
esd_usb2_read_bulk_callback, dev); esd_usb_read_bulk_callback, dev);
retval = usb_submit_urb(urb, GFP_ATOMIC); retval = usb_submit_urb(urb, GFP_ATOMIC);
if (retval == -ENODEV) { if (retval == -ENODEV) {
...@@ -442,19 +447,15 @@ static void esd_usb2_read_bulk_callback(struct urb *urb) ...@@ -442,19 +447,15 @@ static void esd_usb2_read_bulk_callback(struct urb *urb)
dev_err(dev->udev->dev.parent, dev_err(dev->udev->dev.parent,
"failed resubmitting read bulk urb: %d\n", retval); "failed resubmitting read bulk urb: %d\n", retval);
} }
return;
} }
/* /* callback for bulk IN urb */
* callback for bulk IN urb static void esd_usb_write_bulk_callback(struct urb *urb)
*/
static void esd_usb2_write_bulk_callback(struct urb *urb)
{ {
struct esd_tx_urb_context *context = urb->context; struct esd_tx_urb_context *context = urb->context;
struct esd_usb2_net_priv *priv; struct esd_usb_net_priv *priv;
struct net_device *netdev; struct net_device *netdev;
size_t size = sizeof(struct esd_usb2_msg); size_t size = sizeof(struct esd_usb_msg);
WARN_ON(!context); WARN_ON(!context);
...@@ -478,7 +479,7 @@ static ssize_t firmware_show(struct device *d, ...@@ -478,7 +479,7 @@ static ssize_t firmware_show(struct device *d,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct usb_interface *intf = to_usb_interface(d); struct usb_interface *intf = to_usb_interface(d);
struct esd_usb2 *dev = usb_get_intfdata(intf); struct esd_usb *dev = usb_get_intfdata(intf);
return sprintf(buf, "%d.%d.%d\n", return sprintf(buf, "%d.%d.%d\n",
(dev->version >> 12) & 0xf, (dev->version >> 12) & 0xf,
...@@ -491,7 +492,7 @@ static ssize_t hardware_show(struct device *d, ...@@ -491,7 +492,7 @@ static ssize_t hardware_show(struct device *d,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct usb_interface *intf = to_usb_interface(d); struct usb_interface *intf = to_usb_interface(d);
struct esd_usb2 *dev = usb_get_intfdata(intf); struct esd_usb *dev = usb_get_intfdata(intf);
return sprintf(buf, "%d.%d.%d\n", return sprintf(buf, "%d.%d.%d\n",
(dev->version >> 28) & 0xf, (dev->version >> 28) & 0xf,
...@@ -504,13 +505,13 @@ static ssize_t nets_show(struct device *d, ...@@ -504,13 +505,13 @@ static ssize_t nets_show(struct device *d,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct usb_interface *intf = to_usb_interface(d); struct usb_interface *intf = to_usb_interface(d);
struct esd_usb2 *dev = usb_get_intfdata(intf); struct esd_usb *dev = usb_get_intfdata(intf);
return sprintf(buf, "%d", dev->net_count); return sprintf(buf, "%d", dev->net_count);
} }
static DEVICE_ATTR_RO(nets); static DEVICE_ATTR_RO(nets);
static int esd_usb2_send_msg(struct esd_usb2 *dev, struct esd_usb2_msg *msg) static int esd_usb_send_msg(struct esd_usb *dev, struct esd_usb_msg *msg)
{ {
int actual_length; int actual_length;
...@@ -522,8 +523,8 @@ static int esd_usb2_send_msg(struct esd_usb2 *dev, struct esd_usb2_msg *msg) ...@@ -522,8 +523,8 @@ static int esd_usb2_send_msg(struct esd_usb2 *dev, struct esd_usb2_msg *msg)
1000); 1000);
} }
static int esd_usb2_wait_msg(struct esd_usb2 *dev, static int esd_usb_wait_msg(struct esd_usb *dev,
struct esd_usb2_msg *msg) struct esd_usb_msg *msg)
{ {
int actual_length; int actual_length;
...@@ -535,7 +536,7 @@ static int esd_usb2_wait_msg(struct esd_usb2 *dev, ...@@ -535,7 +536,7 @@ static int esd_usb2_wait_msg(struct esd_usb2 *dev,
1000); 1000);
} }
static int esd_usb2_setup_rx_urbs(struct esd_usb2 *dev) static int esd_usb_setup_rx_urbs(struct esd_usb *dev)
{ {
int i, err = 0; int i, err = 0;
...@@ -568,7 +569,7 @@ static int esd_usb2_setup_rx_urbs(struct esd_usb2 *dev) ...@@ -568,7 +569,7 @@ static int esd_usb2_setup_rx_urbs(struct esd_usb2 *dev)
usb_fill_bulk_urb(urb, dev->udev, usb_fill_bulk_urb(urb, dev->udev,
usb_rcvbulkpipe(dev->udev, 1), usb_rcvbulkpipe(dev->udev, 1),
buf, RX_BUFFER_SIZE, buf, RX_BUFFER_SIZE,
esd_usb2_read_bulk_callback, dev); esd_usb_read_bulk_callback, dev);
urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
usb_anchor_urb(urb, &dev->rx_submitted); usb_anchor_urb(urb, &dev->rx_submitted);
...@@ -606,14 +607,12 @@ static int esd_usb2_setup_rx_urbs(struct esd_usb2 *dev) ...@@ -606,14 +607,12 @@ static int esd_usb2_setup_rx_urbs(struct esd_usb2 *dev)
return 0; return 0;
} }
/* /* Start interface */
* Start interface static int esd_usb_start(struct esd_usb_net_priv *priv)
*/
static int esd_usb2_start(struct esd_usb2_net_priv *priv)
{ {
struct esd_usb2 *dev = priv->usb2; struct esd_usb *dev = priv->usb;
struct net_device *netdev = priv->netdev; struct net_device *netdev = priv->netdev;
struct esd_usb2_msg *msg; struct esd_usb_msg *msg;
int err, i; int err, i;
msg = kmalloc(sizeof(*msg), GFP_KERNEL); msg = kmalloc(sizeof(*msg), GFP_KERNEL);
...@@ -622,8 +621,7 @@ static int esd_usb2_start(struct esd_usb2_net_priv *priv) ...@@ -622,8 +621,7 @@ static int esd_usb2_start(struct esd_usb2_net_priv *priv)
goto out; goto out;
} }
/* /* Enable all IDs
* Enable all IDs
* The IDADD message takes up to 64 32 bit bitmasks (2048 bits). * The IDADD message takes up to 64 32 bit bitmasks (2048 bits).
* Each bit represents one 11 bit CAN identifier. A set bit * Each bit represents one 11 bit CAN identifier. A set bit
* enables reception of the corresponding CAN identifier. A cleared * enables reception of the corresponding CAN identifier. A cleared
...@@ -644,11 +642,11 @@ static int esd_usb2_start(struct esd_usb2_net_priv *priv) ...@@ -644,11 +642,11 @@ static int esd_usb2_start(struct esd_usb2_net_priv *priv)
/* enable 29bit extended IDs */ /* enable 29bit extended IDs */
msg->msg.filter.mask[ESD_MAX_ID_SEGMENT] = cpu_to_le32(0x00000001); msg->msg.filter.mask[ESD_MAX_ID_SEGMENT] = cpu_to_le32(0x00000001);
err = esd_usb2_send_msg(dev, msg); err = esd_usb_send_msg(dev, msg);
if (err) if (err)
goto out; goto out;
err = esd_usb2_setup_rx_urbs(dev); err = esd_usb_setup_rx_urbs(dev);
if (err) if (err)
goto out; goto out;
...@@ -664,9 +662,9 @@ static int esd_usb2_start(struct esd_usb2_net_priv *priv) ...@@ -664,9 +662,9 @@ static int esd_usb2_start(struct esd_usb2_net_priv *priv)
return err; return err;
} }
static void unlink_all_urbs(struct esd_usb2 *dev) static void unlink_all_urbs(struct esd_usb *dev)
{ {
struct esd_usb2_net_priv *priv; struct esd_usb_net_priv *priv;
int i, j; int i, j;
usb_kill_anchored_urbs(&dev->rx_submitted); usb_kill_anchored_urbs(&dev->rx_submitted);
...@@ -687,9 +685,9 @@ static void unlink_all_urbs(struct esd_usb2 *dev) ...@@ -687,9 +685,9 @@ static void unlink_all_urbs(struct esd_usb2 *dev)
} }
} }
static int esd_usb2_open(struct net_device *netdev) static int esd_usb_open(struct net_device *netdev)
{ {
struct esd_usb2_net_priv *priv = netdev_priv(netdev); struct esd_usb_net_priv *priv = netdev_priv(netdev);
int err; int err;
/* common open */ /* common open */
...@@ -698,7 +696,7 @@ static int esd_usb2_open(struct net_device *netdev) ...@@ -698,7 +696,7 @@ static int esd_usb2_open(struct net_device *netdev)
return err; return err;
/* finally start device */ /* finally start device */
err = esd_usb2_start(priv); err = esd_usb_start(priv);
if (err) { if (err) {
netdev_warn(netdev, "couldn't start device: %d\n", err); netdev_warn(netdev, "couldn't start device: %d\n", err);
close_candev(netdev); close_candev(netdev);
...@@ -710,20 +708,20 @@ static int esd_usb2_open(struct net_device *netdev) ...@@ -710,20 +708,20 @@ static int esd_usb2_open(struct net_device *netdev)
return 0; return 0;
} }
static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb, static netdev_tx_t esd_usb_start_xmit(struct sk_buff *skb,
struct net_device *netdev) struct net_device *netdev)
{ {
struct esd_usb2_net_priv *priv = netdev_priv(netdev); struct esd_usb_net_priv *priv = netdev_priv(netdev);
struct esd_usb2 *dev = priv->usb2; struct esd_usb *dev = priv->usb;
struct esd_tx_urb_context *context = NULL; struct esd_tx_urb_context *context = NULL;
struct net_device_stats *stats = &netdev->stats; struct net_device_stats *stats = &netdev->stats;
struct can_frame *cf = (struct can_frame *)skb->data; struct can_frame *cf = (struct can_frame *)skb->data;
struct esd_usb2_msg *msg; struct esd_usb_msg *msg;
struct urb *urb; struct urb *urb;
u8 *buf; u8 *buf;
int i, err; int i, err;
int ret = NETDEV_TX_OK; int ret = NETDEV_TX_OK;
size_t size = sizeof(struct esd_usb2_msg); size_t size = sizeof(struct esd_usb_msg);
if (can_dropped_invalid_skb(netdev, skb)) if (can_dropped_invalid_skb(netdev, skb))
return NETDEV_TX_OK; return NETDEV_TX_OK;
...@@ -745,7 +743,7 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb, ...@@ -745,7 +743,7 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb,
goto nobufmem; goto nobufmem;
} }
msg = (struct esd_usb2_msg *)buf; msg = (struct esd_usb_msg *)buf;
msg->msg.hdr.len = 3; /* minimal length */ msg->msg.hdr.len = 3; /* minimal length */
msg->msg.hdr.cmd = CMD_CAN_TX; msg->msg.hdr.cmd = CMD_CAN_TX;
...@@ -771,9 +769,7 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb, ...@@ -771,9 +769,7 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb,
} }
} }
/* /* This may never happen */
* This may never happen.
*/
if (!context) { if (!context) {
netdev_warn(netdev, "couldn't find free context\n"); netdev_warn(netdev, "couldn't find free context\n");
ret = NETDEV_TX_BUSY; ret = NETDEV_TX_BUSY;
...@@ -788,7 +784,7 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb, ...@@ -788,7 +784,7 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb,
usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, 2), buf, usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, 2), buf,
msg->msg.hdr.len << 2, msg->msg.hdr.len << 2,
esd_usb2_write_bulk_callback, context); esd_usb_write_bulk_callback, context);
urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
...@@ -821,8 +817,7 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb, ...@@ -821,8 +817,7 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb,
netif_trans_update(netdev); netif_trans_update(netdev);
/* /* Release our reference to this URB, the USB core will eventually free
* Release our reference to this URB, the USB core will eventually free
* it entirely. * it entirely.
*/ */
usb_free_urb(urb); usb_free_urb(urb);
...@@ -839,24 +834,24 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb, ...@@ -839,24 +834,24 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb,
return ret; return ret;
} }
static int esd_usb2_close(struct net_device *netdev) static int esd_usb_close(struct net_device *netdev)
{ {
struct esd_usb2_net_priv *priv = netdev_priv(netdev); struct esd_usb_net_priv *priv = netdev_priv(netdev);
struct esd_usb2_msg *msg; struct esd_usb_msg *msg;
int i; int i;
msg = kmalloc(sizeof(*msg), GFP_KERNEL); msg = kmalloc(sizeof(*msg), GFP_KERNEL);
if (!msg) if (!msg)
return -ENOMEM; return -ENOMEM;
/* Disable all IDs (see esd_usb2_start()) */ /* Disable all IDs (see esd_usb_start()) */
msg->msg.hdr.cmd = CMD_IDADD; msg->msg.hdr.cmd = CMD_IDADD;
msg->msg.hdr.len = 2 + ESD_MAX_ID_SEGMENT; msg->msg.hdr.len = 2 + ESD_MAX_ID_SEGMENT;
msg->msg.filter.net = priv->index; msg->msg.filter.net = priv->index;
msg->msg.filter.option = ESD_ID_ENABLE; /* start with segment 0 */ msg->msg.filter.option = ESD_ID_ENABLE; /* start with segment 0 */
for (i = 0; i <= ESD_MAX_ID_SEGMENT; i++) for (i = 0; i <= ESD_MAX_ID_SEGMENT; i++)
msg->msg.filter.mask[i] = 0; msg->msg.filter.mask[i] = 0;
if (esd_usb2_send_msg(priv->usb2, msg) < 0) if (esd_usb_send_msg(priv->usb, msg) < 0)
netdev_err(netdev, "sending idadd message failed\n"); netdev_err(netdev, "sending idadd message failed\n");
/* set CAN controller to reset mode */ /* set CAN controller to reset mode */
...@@ -864,8 +859,8 @@ static int esd_usb2_close(struct net_device *netdev) ...@@ -864,8 +859,8 @@ static int esd_usb2_close(struct net_device *netdev)
msg->msg.hdr.cmd = CMD_SETBAUD; msg->msg.hdr.cmd = CMD_SETBAUD;
msg->msg.setbaud.net = priv->index; msg->msg.setbaud.net = priv->index;
msg->msg.setbaud.rsvd = 0; msg->msg.setbaud.rsvd = 0;
msg->msg.setbaud.baud = cpu_to_le32(ESD_USB2_NO_BAUDRATE); msg->msg.setbaud.baud = cpu_to_le32(ESD_USB_NO_BAUDRATE);
if (esd_usb2_send_msg(priv->usb2, msg) < 0) if (esd_usb_send_msg(priv->usb, msg) < 0)
netdev_err(netdev, "sending setbaud message failed\n"); netdev_err(netdev, "sending setbaud message failed\n");
priv->can.state = CAN_STATE_STOPPED; priv->can.state = CAN_STATE_STOPPED;
...@@ -879,10 +874,10 @@ static int esd_usb2_close(struct net_device *netdev) ...@@ -879,10 +874,10 @@ static int esd_usb2_close(struct net_device *netdev)
return 0; return 0;
} }
static const struct net_device_ops esd_usb2_netdev_ops = { static const struct net_device_ops esd_usb_netdev_ops = {
.ndo_open = esd_usb2_open, .ndo_open = esd_usb_open,
.ndo_stop = esd_usb2_close, .ndo_stop = esd_usb_close,
.ndo_start_xmit = esd_usb2_start_xmit, .ndo_start_xmit = esd_usb_start_xmit,
.ndo_change_mtu = can_change_mtu, .ndo_change_mtu = can_change_mtu,
}; };
...@@ -900,20 +895,20 @@ static const struct can_bittiming_const esd_usb2_bittiming_const = { ...@@ -900,20 +895,20 @@ static const struct can_bittiming_const esd_usb2_bittiming_const = {
static int esd_usb2_set_bittiming(struct net_device *netdev) static int esd_usb2_set_bittiming(struct net_device *netdev)
{ {
struct esd_usb2_net_priv *priv = netdev_priv(netdev); struct esd_usb_net_priv *priv = netdev_priv(netdev);
struct can_bittiming *bt = &priv->can.bittiming; struct can_bittiming *bt = &priv->can.bittiming;
struct esd_usb2_msg *msg; struct esd_usb_msg *msg;
int err; int err;
u32 canbtr; u32 canbtr;
int sjw_shift; int sjw_shift;
canbtr = ESD_USB2_UBR; canbtr = ESD_USB_UBR;
if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
canbtr |= ESD_USB2_LOM; canbtr |= ESD_USB_LOM;
canbtr |= (bt->brp - 1) & (ESD_USB2_BRP_MAX - 1); canbtr |= (bt->brp - 1) & (ESD_USB2_BRP_MAX - 1);
if (le16_to_cpu(priv->usb2->udev->descriptor.idProduct) == if (le16_to_cpu(priv->usb->udev->descriptor.idProduct) ==
USB_CANUSBM_PRODUCT_ID) USB_CANUSBM_PRODUCT_ID)
sjw_shift = ESD_USBM_SJW_SHIFT; sjw_shift = ESD_USBM_SJW_SHIFT;
else else
...@@ -941,16 +936,16 @@ static int esd_usb2_set_bittiming(struct net_device *netdev) ...@@ -941,16 +936,16 @@ static int esd_usb2_set_bittiming(struct net_device *netdev)
netdev_info(netdev, "setting BTR=%#x\n", canbtr); netdev_info(netdev, "setting BTR=%#x\n", canbtr);
err = esd_usb2_send_msg(priv->usb2, msg); err = esd_usb_send_msg(priv->usb, msg);
kfree(msg); kfree(msg);
return err; return err;
} }
static int esd_usb2_get_berr_counter(const struct net_device *netdev, static int esd_usb_get_berr_counter(const struct net_device *netdev,
struct can_berr_counter *bec) struct can_berr_counter *bec)
{ {
struct esd_usb2_net_priv *priv = netdev_priv(netdev); struct esd_usb_net_priv *priv = netdev_priv(netdev);
bec->txerr = priv->bec.txerr; bec->txerr = priv->bec.txerr;
bec->rxerr = priv->bec.rxerr; bec->rxerr = priv->bec.rxerr;
...@@ -958,7 +953,7 @@ static int esd_usb2_get_berr_counter(const struct net_device *netdev, ...@@ -958,7 +953,7 @@ static int esd_usb2_get_berr_counter(const struct net_device *netdev,
return 0; return 0;
} }
static int esd_usb2_set_mode(struct net_device *netdev, enum can_mode mode) static int esd_usb_set_mode(struct net_device *netdev, enum can_mode mode)
{ {
switch (mode) { switch (mode) {
case CAN_MODE_START: case CAN_MODE_START:
...@@ -972,11 +967,11 @@ static int esd_usb2_set_mode(struct net_device *netdev, enum can_mode mode) ...@@ -972,11 +967,11 @@ static int esd_usb2_set_mode(struct net_device *netdev, enum can_mode mode)
return 0; return 0;
} }
static int esd_usb2_probe_one_net(struct usb_interface *intf, int index) static int esd_usb_probe_one_net(struct usb_interface *intf, int index)
{ {
struct esd_usb2 *dev = usb_get_intfdata(intf); struct esd_usb *dev = usb_get_intfdata(intf);
struct net_device *netdev; struct net_device *netdev;
struct esd_usb2_net_priv *priv; struct esd_usb_net_priv *priv;
int err = 0; int err = 0;
int i; int i;
...@@ -995,7 +990,7 @@ static int esd_usb2_probe_one_net(struct usb_interface *intf, int index) ...@@ -995,7 +990,7 @@ static int esd_usb2_probe_one_net(struct usb_interface *intf, int index)
for (i = 0; i < MAX_TX_URBS; i++) for (i = 0; i < MAX_TX_URBS; i++)
priv->tx_contexts[i].echo_index = MAX_TX_URBS; priv->tx_contexts[i].echo_index = MAX_TX_URBS;
priv->usb2 = dev; priv->usb = dev;
priv->netdev = netdev; priv->netdev = netdev;
priv->index = index; priv->index = index;
...@@ -1013,12 +1008,12 @@ static int esd_usb2_probe_one_net(struct usb_interface *intf, int index) ...@@ -1013,12 +1008,12 @@ static int esd_usb2_probe_one_net(struct usb_interface *intf, int index)
priv->can.bittiming_const = &esd_usb2_bittiming_const; priv->can.bittiming_const = &esd_usb2_bittiming_const;
priv->can.do_set_bittiming = esd_usb2_set_bittiming; priv->can.do_set_bittiming = esd_usb2_set_bittiming;
priv->can.do_set_mode = esd_usb2_set_mode; priv->can.do_set_mode = esd_usb_set_mode;
priv->can.do_get_berr_counter = esd_usb2_get_berr_counter; priv->can.do_get_berr_counter = esd_usb_get_berr_counter;
netdev->flags |= IFF_ECHO; /* we support local echo */ netdev->flags |= IFF_ECHO; /* we support local echo */
netdev->netdev_ops = &esd_usb2_netdev_ops; netdev->netdev_ops = &esd_usb_netdev_ops;
SET_NETDEV_DEV(netdev, &intf->dev); SET_NETDEV_DEV(netdev, &intf->dev);
netdev->dev_id = index; netdev->dev_id = index;
...@@ -1038,17 +1033,16 @@ static int esd_usb2_probe_one_net(struct usb_interface *intf, int index) ...@@ -1038,17 +1033,16 @@ static int esd_usb2_probe_one_net(struct usb_interface *intf, int index)
return err; return err;
} }
/* /* probe function for new USB devices
* probe function for new USB2 devices
* *
* check version information and number of available * check version information and number of available
* CAN interfaces * CAN interfaces
*/ */
static int esd_usb2_probe(struct usb_interface *intf, static int esd_usb_probe(struct usb_interface *intf,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
struct esd_usb2 *dev; struct esd_usb *dev;
struct esd_usb2_msg *msg; struct esd_usb_msg *msg;
int i, err; int i, err;
dev = kzalloc(sizeof(*dev), GFP_KERNEL); dev = kzalloc(sizeof(*dev), GFP_KERNEL);
...@@ -1076,13 +1070,13 @@ static int esd_usb2_probe(struct usb_interface *intf, ...@@ -1076,13 +1070,13 @@ static int esd_usb2_probe(struct usb_interface *intf,
msg->msg.version.flags = 0; msg->msg.version.flags = 0;
msg->msg.version.drv_version = 0; msg->msg.version.drv_version = 0;
err = esd_usb2_send_msg(dev, msg); err = esd_usb_send_msg(dev, msg);
if (err < 0) { if (err < 0) {
dev_err(&intf->dev, "sending version message failed\n"); dev_err(&intf->dev, "sending version message failed\n");
goto free_msg; goto free_msg;
} }
err = esd_usb2_wait_msg(dev, msg); err = esd_usb_wait_msg(dev, msg);
if (err < 0) { if (err < 0) {
dev_err(&intf->dev, "no version message answer\n"); dev_err(&intf->dev, "no version message answer\n");
goto free_msg; goto free_msg;
...@@ -1105,7 +1099,7 @@ static int esd_usb2_probe(struct usb_interface *intf, ...@@ -1105,7 +1099,7 @@ static int esd_usb2_probe(struct usb_interface *intf,
/* do per device probing */ /* do per device probing */
for (i = 0; i < dev->net_count; i++) for (i = 0; i < dev->net_count; i++)
esd_usb2_probe_one_net(intf, i); esd_usb_probe_one_net(intf, i);
free_msg: free_msg:
kfree(msg); kfree(msg);
...@@ -1115,12 +1109,10 @@ static int esd_usb2_probe(struct usb_interface *intf, ...@@ -1115,12 +1109,10 @@ static int esd_usb2_probe(struct usb_interface *intf,
return err; return err;
} }
/* /* called by the usb core when the device is removed from the system */
* called by the usb core when the device is removed from the system static void esd_usb_disconnect(struct usb_interface *intf)
*/
static void esd_usb2_disconnect(struct usb_interface *intf)
{ {
struct esd_usb2 *dev = usb_get_intfdata(intf); struct esd_usb *dev = usb_get_intfdata(intf);
struct net_device *netdev; struct net_device *netdev;
int i; int i;
...@@ -1144,11 +1136,11 @@ static void esd_usb2_disconnect(struct usb_interface *intf) ...@@ -1144,11 +1136,11 @@ static void esd_usb2_disconnect(struct usb_interface *intf)
} }
/* usb specific object needed to register this driver with the usb subsystem */ /* usb specific object needed to register this driver with the usb subsystem */
static struct usb_driver esd_usb2_driver = { static struct usb_driver esd_usb_driver = {
.name = "esd_usb2", .name = "esd_usb",
.probe = esd_usb2_probe, .probe = esd_usb_probe,
.disconnect = esd_usb2_disconnect, .disconnect = esd_usb_disconnect,
.id_table = esd_usb2_table, .id_table = esd_usb_table,
}; };
module_usb_driver(esd_usb2_driver); module_usb_driver(esd_usb_driver);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment