* [PATCH v9] usb_8dev: Add support for USB2CAN interface from 8 devices
@ 2012-12-16 7:01 Bernd Krumboeck
[not found] ` <1355641315-15739-1-git-send-email-krumboeck-Hi41barv6paIERSsAYjmKA@public.gmane.org>
0 siblings, 1 reply; 14+ messages in thread
From: Bernd Krumboeck @ 2012-12-16 7:01 UTC (permalink / raw)
To: linux-can; +Cc: linux-usb, info, gediminas, Bernd Krumboeck
Add device driver for USB2CAN interface from "8 devices" (http://www.8devices.com).
changes since v8:
* remove all sysfs files
changes since v7:
* add sysfs documentation
* fix minor styling issue
* fixed can state for passive mode
* changed handling for crc errors
changes since v6:
* changed some variable types to big endian equivalent
* small cleanups
changes since v5:
* unlock mutex on error
changes since v4:
* removed FSF address
* renamed struct usb_8dev
* removed unused variable free_slots
* replaced some _to_cpu functions with pointer equivalent
* fix return value for usb_8dev_set_mode
* handle can errors with separate function
* fix overrun error handling
* rewrite error handling for usb_8dev_start_xmit
* fix urb submit in usb_8dev_start
* various small fixes
Signed-off-by: Bernd Krumboeck <krumboeck@universalnet.at>
Acked-by: Wolfgang Grandegger <wg@grandegger.com>
---
drivers/net/can/usb/Kconfig | 6 +
drivers/net/can/usb/Makefile | 1 +
drivers/net/can/usb/usb_8dev.c | 1034 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 1041 insertions(+)
create mode 100644 drivers/net/can/usb/usb_8dev.c
diff --git a/drivers/net/can/usb/Kconfig b/drivers/net/can/usb/Kconfig
index a4e4bee..2162233 100644
--- a/drivers/net/can/usb/Kconfig
+++ b/drivers/net/can/usb/Kconfig
@@ -48,4 +48,10 @@ config CAN_PEAK_USB
This driver supports the PCAN-USB and PCAN-USB Pro adapters
from PEAK-System Technik (http://www.peak-system.com).
+config CAN_8DEV_USB
+ tristate "8 devices USB2CAN interface"
+ ---help---
+ This driver supports the USB2CAN interface
+ from 8 devices (http://www.8devices.com).
+
endmenu
diff --git a/drivers/net/can/usb/Makefile b/drivers/net/can/usb/Makefile
index 80a2ee4..becef46 100644
--- a/drivers/net/can/usb/Makefile
+++ b/drivers/net/can/usb/Makefile
@@ -6,5 +6,6 @@ obj-$(CONFIG_CAN_EMS_USB) += ems_usb.o
obj-$(CONFIG_CAN_ESD_USB2) += esd_usb2.o
obj-$(CONFIG_CAN_KVASER_USB) += kvaser_usb.o
obj-$(CONFIG_CAN_PEAK_USB) += peak_usb/
+obj-$(CONFIG_CAN_8DEV_USB) += usb_8dev.o
ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
diff --git a/drivers/net/can/usb/usb_8dev.c b/drivers/net/can/usb/usb_8dev.c
new file mode 100644
index 0000000..660b4f87
--- /dev/null
+++ b/drivers/net/can/usb/usb_8dev.c
@@ -0,0 +1,1034 @@
+/*
+ * CAN driver for "8 devices" USB2CAN converter
+ *
+ * Copyright (C) 2012 Bernd Krumboeck (krumboeck@universalnet.at)
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program.
+ *
+ * This driver is inspired by the 3.2.0 version of drivers/net/can/usb/ems_usb.c
+ * and drivers/net/can/usb/esd_usb2.c
+ *
+ * Many thanks to Gerhard Bertelsmann (info@gerhard-bertelsmann.de)
+ * for testing and fixing this driver. Also many thanks to "8 devices",
+ * who were very cooperative and answered my questions.
+ */
+
+#include <linux/init.h>
+#include <linux/signal.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/usb.h>
+
+#include <linux/can.h>
+#include <linux/can/dev.h>
+#include <linux/can/error.h>
+
+/* driver constants */
+#define MAX_RX_URBS 10
+#define MAX_TX_URBS 10
+#define RX_BUFFER_SIZE 64
+
+/* vendor and product id */
+#define USB_8DEV_VENDOR_ID 0x0483
+#define USB_8DEV_PRODUCT_ID 0x1234
+
+/* endpoints */
+enum usb_8dev_endpoint {
+ USB_8DEV_ENDP_DATA_RX = 1,
+ USB_8DEV_ENDP_DATA_TX,
+ USB_8DEV_ENDP_CMD_RX,
+ USB_8DEV_ENDP_CMD_TX
+};
+
+/* bittiming constants */
+#define USB_8DEV_ABP_CLOCK 32000000
+#define USB_8DEV_BAUD_MANUAL 0x09
+#define USB_8DEV_TSEG1_MIN 1
+#define USB_8DEV_TSEG1_MAX 16
+#define USB_8DEV_TSEG2_MIN 1
+#define USB_8DEV_TSEG2_MAX 8
+#define USB_8DEV_SJW_MAX 4
+#define USB_8DEV_BRP_MIN 1
+#define USB_8DEV_BRP_MAX 1024
+#define USB_8DEV_BRP_INC 1
+
+/* setup flags */
+#define USB_8DEV_SILENT 0x01
+#define USB_8DEV_LOOPBACK 0x02
+#define USB_8DEV_DISABLE_AUTO_RESTRANS 0x04
+#define USB_8DEV_STATUS_FRAME 0x08
+
+/* commands */
+enum usb_8dev_cmd {
+ USB_8DEV_RESET = 1,
+ USB_8DEV_OPEN,
+ USB_8DEV_CLOSE,
+ USB_8DEV_SET_SPEED,
+ USB_8DEV_SET_MASK_FILTER,
+ USB_8DEV_GET_STATUS,
+ USB_8DEV_GET_STATISTICS,
+ USB_8DEV_GET_SERIAL,
+ USB_8DEV_GET_SOFTW_VER,
+ USB_8DEV_GET_HARDW_VER,
+ USB_8DEV_RESET_TIMESTAMP,
+ USB_8DEV_GET_SOFTW_HARDW_VER
+};
+
+#define USB_8DEV_CMD_START 0x11
+#define USB_8DEV_CMD_END 0x22
+
+#define USB_8DEV_CMD_SUCCESS 0
+#define USB_8DEV_CMD_ERROR 255
+
+#define USB_8DEV_CMD_TIMEOUT 1000
+
+/* frames */
+#define USB_8DEV_DATA_START 0x55
+#define USB_8DEV_DATA_END 0xAA
+
+#define USB_8DEV_TYPE_CAN_FRAME 0
+#define USB_8DEV_TYPE_ERROR_FRAME 3
+
+#define USB_8DEV_EXTID 0x01
+#define USB_8DEV_RTR 0x02
+#define USB_8DEV_ERR_FLAG 0x04
+
+/* status */
+#define USB_8DEV_STATUSMSG_OK 0x00 /* Normal condition. */
+#define USB_8DEV_STATUSMSG_OVERRUN 0x01 /* Overrun occured when sending */
+#define USB_8DEV_STATUSMSG_BUSLIGHT 0x02 /* Error counter has reached 96 */
+#define USB_8DEV_STATUSMSG_BUSHEAVY 0x03 /* Error count. has reached 128 */
+#define USB_8DEV_STATUSMSG_BUSOFF 0x04 /* Device is in BUSOFF */
+#define USB_8DEV_STATUSMSG_STUFF 0x20 /* Stuff Error */
+#define USB_8DEV_STATUSMSG_FORM 0x21 /* Form Error */
+#define USB_8DEV_STATUSMSG_ACK 0x23 /* Ack Error */
+#define USB_8DEV_STATUSMSG_BIT0 0x24 /* Bit1 Error */
+#define USB_8DEV_STATUSMSG_BIT1 0x25 /* Bit0 Error */
+#define USB_8DEV_STATUSMSG_CRC 0x26 /* CRC Error */
+
+#define USB_8DEV_RP_MASK 0x7F /* Mask for Receive Error Bit */
+
+
+/* table of devices that work with this driver */
+static const struct usb_device_id usb_8dev_table[] = {
+ { USB_DEVICE(USB_8DEV_VENDOR_ID, USB_8DEV_PRODUCT_ID) },
+ { } /* Terminating entry */
+};
+
+MODULE_DEVICE_TABLE(usb, usb_8dev_table);
+
+struct usb_8dev_tx_urb_context {
+ struct usb_8dev_priv *priv;
+
+ u32 echo_index;
+ u8 dlc;
+};
+
+/* Structure to hold all of our device specific stuff */
+struct usb_8dev_priv {
+ struct can_priv can; /* must be the first member */
+
+ struct sk_buff *echo_skb[MAX_TX_URBS];
+
+ struct usb_device *udev;
+ struct net_device *netdev;
+
+ atomic_t active_tx_urbs;
+ struct usb_anchor tx_submitted;
+ struct usb_8dev_tx_urb_context tx_contexts[MAX_TX_URBS];
+
+ struct usb_anchor rx_submitted;
+
+ struct can_berr_counter bec;
+
+ u8 *cmd_msg_buffer;
+
+ struct mutex usb_8dev_cmd_lock;
+
+};
+
+/* tx frame */
+struct __packed usb_8dev_tx_msg {
+ u8 begin;
+ u8 flags; /* RTR and EXT_ID flag */
+ __be32 id; /* upper 3 bits not used */
+ u8 dlc; /* data length code 0-8 bytes */
+ u8 data[8]; /* 64-bit data */
+ u8 end;
+};
+
+/* rx frame */
+struct __packed usb_8dev_rx_msg {
+ u8 begin;
+ u8 type; /* frame type */
+ u8 flags; /* RTR and EXT_ID flag */
+ __be32 id; /* upper 3 bits not used */
+ u8 dlc; /* data length code 0-8 bytes */
+ u8 data[8]; /* 64-bit data */
+ __be32 timestamp; /* 32-bit timestamp */
+ u8 end;
+};
+
+/* command frame */
+struct __packed usb_8dev_cmd_msg {
+ u8 begin;
+ u8 channel; /* unkown - always 0 */
+ u8 command; /* command to execute */
+ u8 opt1; /* optional parameter / return value */
+ u8 opt2; /* optional parameter 2 */
+ u8 data[10]; /* optional parameter and data */
+ u8 end;
+};
+
+static int usb_8dev_send_cmd_msg(struct usb_8dev_priv *priv, u8 *msg, int size)
+{
+ int actual_length;
+
+ return usb_bulk_msg(priv->udev,
+ usb_sndbulkpipe(priv->udev, USB_8DEV_ENDP_CMD_TX),
+ msg, size, &actual_length, USB_8DEV_CMD_TIMEOUT);
+}
+
+static int usb_8dev_wait_cmd_msg(struct usb_8dev_priv *priv, u8 *msg, int size,
+ int *actual_length)
+{
+ return usb_bulk_msg(priv->udev,
+ usb_rcvbulkpipe(priv->udev, USB_8DEV_ENDP_CMD_RX),
+ msg, size, actual_length, USB_8DEV_CMD_TIMEOUT);
+}
+
+/*
+ * Send command to device and receive result.
+ * Command was successful when opt1 = 0.
+ */
+static int usb_8dev_send_cmd(struct usb_8dev_priv *priv,
+ struct usb_8dev_cmd_msg *out,
+ struct usb_8dev_cmd_msg *in)
+{
+ int err;
+ int num_bytes_read;
+ struct net_device *netdev;
+
+ netdev = priv->netdev;
+
+ out->begin = USB_8DEV_CMD_START;
+ out->end = USB_8DEV_CMD_END;
+
+ mutex_lock(&priv->usb_8dev_cmd_lock);
+
+ memcpy(priv->cmd_msg_buffer, out,
+ sizeof(struct usb_8dev_cmd_msg));
+
+ err = usb_8dev_send_cmd_msg(priv, priv->cmd_msg_buffer,
+ sizeof(struct usb_8dev_cmd_msg));
+ if (err < 0) {
+ netdev_err(netdev, "sending command message failed\n");
+ goto failed;
+ }
+
+ err = usb_8dev_wait_cmd_msg(priv, priv->cmd_msg_buffer,
+ sizeof(struct usb_8dev_cmd_msg),
+ &num_bytes_read);
+ if (err < 0) {
+ netdev_err(netdev, "no command message answer\n");
+ goto failed;
+ }
+
+ memcpy(in, priv->cmd_msg_buffer, sizeof(struct usb_8dev_cmd_msg));
+
+ if (in->begin != USB_8DEV_CMD_START || in->end != USB_8DEV_CMD_END ||
+ num_bytes_read != 16 || in->opt1 != 0)
+ err = -EPROTO;
+
+failed:
+ mutex_unlock(&priv->usb_8dev_cmd_lock);
+ return err;
+}
+
+/* Send open command to device */
+static int usb_8dev_cmd_open(struct usb_8dev_priv *priv)
+{
+ struct can_bittiming *bt = &priv->can.bittiming;
+ struct usb_8dev_cmd_msg outmsg;
+ struct usb_8dev_cmd_msg inmsg;
+ u32 ctrlmode = priv->can.ctrlmode;
+ u32 flags = USB_8DEV_STATUS_FRAME;
+ __be32 beflags;
+ __be16 bebrp;
+
+ memset(&outmsg, 0, sizeof(outmsg));
+ outmsg.command = USB_8DEV_OPEN;
+ outmsg.opt1 = USB_8DEV_BAUD_MANUAL;
+ outmsg.data[0] = bt->prop_seg + bt->phase_seg1;
+ outmsg.data[1] = bt->phase_seg2;
+ outmsg.data[2] = bt->sjw;
+
+ /* BRP */
+ bebrp = cpu_to_be16((u16)bt->brp);
+ memcpy(&outmsg.data[3], &bebrp, sizeof(bebrp));
+
+ /* flags */
+ if (ctrlmode & CAN_CTRLMODE_LOOPBACK)
+ flags |= USB_8DEV_LOOPBACK;
+ if (ctrlmode & CAN_CTRLMODE_LISTENONLY)
+ flags |= USB_8DEV_SILENT;
+ if (ctrlmode & CAN_CTRLMODE_ONE_SHOT)
+ flags |= USB_8DEV_DISABLE_AUTO_RESTRANS;
+
+ beflags = cpu_to_be32(flags);
+ memcpy(&outmsg.data[5], &beflags, sizeof(beflags));
+
+ return usb_8dev_send_cmd(priv, &outmsg, &inmsg);
+}
+
+/* Send close command to device */
+static int usb_8dev_cmd_close(struct usb_8dev_priv *priv)
+{
+ struct usb_8dev_cmd_msg inmsg;
+ struct usb_8dev_cmd_msg outmsg = {
+ .channel = 0,
+ .command = USB_8DEV_CLOSE,
+ .opt1 = 0,
+ .opt2 = 0
+ };
+
+ return usb_8dev_send_cmd(priv, &outmsg, &inmsg);
+}
+
+/* Get firmware and hardware version */
+static int usb_8dev_cmd_version(struct usb_8dev_priv *priv, u32 *res)
+{
+ struct usb_8dev_cmd_msg inmsg;
+ struct usb_8dev_cmd_msg outmsg = {
+ .channel = 0,
+ .command = USB_8DEV_GET_SOFTW_HARDW_VER,
+ .opt1 = 0,
+ .opt2 = 0
+ };
+
+ int err = usb_8dev_send_cmd(priv, &outmsg, &inmsg);
+ if (err)
+ return err;
+
+ *res = be32_to_cpup((__be32 *)inmsg.data);
+
+ return err;
+}
+
+/*
+ * Set network device mode
+ *
+ * Maybe we should leave this function empty, because the device
+ * set mode variable with open command.
+ */
+static int usb_8dev_set_mode(struct net_device *netdev, enum can_mode mode)
+{
+ struct usb_8dev_priv *priv = netdev_priv(netdev);
+ int err = 0;
+
+ switch (mode) {
+ case CAN_MODE_START:
+ err = usb_8dev_cmd_open(priv);
+ if (err)
+ netdev_warn(netdev, "couldn't start device");
+ break;
+
+ default:
+ return -EOPNOTSUPP;
+ }
+
+ return err;
+}
+
+/* Read error/status frames */
+static void usb_8dev_rx_err_msg(struct usb_8dev_priv *priv,
+ struct usb_8dev_rx_msg *msg)
+{
+ struct can_frame *cf;
+ struct sk_buff *skb;
+ struct net_device_stats *stats = &priv->netdev->stats;
+
+ /*
+ * Error message:
+ * byte 0: Status
+ * byte 1: bit 7: Receive Passive
+ * byte 1: bit 0-6: Receive Error Counter
+ * byte 2: Transmit Error Counter
+ * byte 3: Always 0 (maybe reserved for future use)
+ */
+
+ u8 state = msg->data[0];
+ u8 rxerr = msg->data[1] & USB_8DEV_RP_MASK;
+ u8 txerr = msg->data[2];
+ int rx_errors = 0;
+ int tx_errors = 0;
+
+ skb = alloc_can_err_skb(priv->netdev, &cf);
+ if (!skb)
+ return;
+
+ switch (state) {
+ case USB_8DEV_STATUSMSG_OK:
+ priv->can.state = CAN_STATE_ERROR_ACTIVE;
+ cf->can_id |= CAN_ERR_PROT;
+ cf->data[2] = CAN_ERR_PROT_ACTIVE;
+ break;
+ case USB_8DEV_STATUSMSG_BUSOFF:
+ priv->can.state = CAN_STATE_BUS_OFF;
+ cf->can_id |= CAN_ERR_BUSOFF;
+ can_bus_off(priv->netdev);
+ break;
+ case USB_8DEV_STATUSMSG_OVERRUN:
+ case USB_8DEV_STATUSMSG_BUSLIGHT:
+ case USB_8DEV_STATUSMSG_BUSHEAVY:
+ cf->can_id |= CAN_ERR_CRTL;
+ break;
+ default:
+ priv->can.state = CAN_STATE_ERROR_WARNING;
+ cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
+ priv->can.can_stats.bus_error++;
+ break;
+ }
+
+ switch (state) {
+ case USB_8DEV_STATUSMSG_ACK:
+ cf->can_id |= CAN_ERR_ACK;
+ tx_errors = 1;
+ break;
+ case USB_8DEV_STATUSMSG_CRC:
+ cf->data[2] |= CAN_ERR_PROT_UNSPEC;
+ cf->data[3] |= CAN_ERR_PROT_LOC_CRC_SEQ |
+ CAN_ERR_PROT_LOC_CRC_DEL;
+ rx_errors = 1;
+ break;
+ case USB_8DEV_STATUSMSG_BIT0:
+ cf->data[2] |= CAN_ERR_PROT_BIT0;
+ tx_errors = 1;
+ break;
+ case USB_8DEV_STATUSMSG_BIT1:
+ cf->data[2] |= CAN_ERR_PROT_BIT1;
+ tx_errors = 1;
+ break;
+ case USB_8DEV_STATUSMSG_FORM:
+ cf->data[2] |= CAN_ERR_PROT_FORM;
+ rx_errors = 1;
+ break;
+ case USB_8DEV_STATUSMSG_STUFF:
+ cf->data[2] |= CAN_ERR_PROT_STUFF;
+ rx_errors = 1;
+ break;
+ case USB_8DEV_STATUSMSG_OVERRUN:
+ cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
+ stats->rx_over_errors++;
+ rx_errors = 1;
+ break;
+ case USB_8DEV_STATUSMSG_BUSLIGHT:
+ priv->can.state = CAN_STATE_ERROR_WARNING;
+ cf->data[1] = (txerr > rxerr) ?
+ CAN_ERR_CRTL_TX_WARNING :
+ CAN_ERR_CRTL_RX_WARNING;
+ priv->can.can_stats.error_warning++;
+ break;
+ case USB_8DEV_STATUSMSG_BUSHEAVY:
+ priv->can.state = CAN_STATE_ERROR_PASSIVE;
+ cf->data[1] = (txerr > rxerr) ?
+ CAN_ERR_CRTL_TX_PASSIVE :
+ CAN_ERR_CRTL_RX_PASSIVE;
+ priv->can.can_stats.error_passive++;
+ break;
+ default:
+ netdev_warn(priv->netdev,
+ "Unknown status/error message (%d)\n", state);
+ break;
+ }
+
+ if (tx_errors) {
+ cf->data[2] |= CAN_ERR_PROT_TX;
+ stats->tx_errors++;
+ }
+
+ if (rx_errors)
+ stats->rx_errors++;
+
+ cf->data[6] = txerr;
+ cf->data[7] = rxerr;
+
+ priv->bec.txerr = txerr;
+ priv->bec.rxerr = rxerr;
+
+ netif_rx(skb);
+
+ stats->rx_packets++;
+ stats->rx_bytes += cf->can_dlc;
+}
+
+/* Read data and status frames */
+static void usb_8dev_rx_can_msg(struct usb_8dev_priv *priv,
+ struct usb_8dev_rx_msg *msg)
+{
+ struct can_frame *cf;
+ struct sk_buff *skb;
+ struct net_device_stats *stats = &priv->netdev->stats;
+
+ if (msg->type == USB_8DEV_TYPE_ERROR_FRAME &&
+ msg->flags == USB_8DEV_ERR_FLAG) {
+ usb_8dev_rx_err_msg(priv, msg);
+ } else if (msg->type == USB_8DEV_TYPE_CAN_FRAME) {
+ skb = alloc_can_skb(priv->netdev, &cf);
+ if (!skb)
+ return;
+
+ cf->can_id = be32_to_cpu(msg->id);
+ cf->can_dlc = get_can_dlc(msg->dlc & 0xF);
+
+ if (msg->flags & USB_8DEV_EXTID)
+ cf->can_id |= CAN_EFF_FLAG;
+
+ if (msg->flags & USB_8DEV_RTR)
+ cf->can_id |= CAN_RTR_FLAG;
+ else
+ memcpy(cf->data, msg->data, cf->can_dlc);
+
+ netif_rx(skb);
+
+ stats->rx_packets++;
+ stats->rx_bytes += cf->can_dlc;
+ } else {
+ netdev_warn(priv->netdev, "frame type %d unknown",
+ msg->type);
+ }
+
+}
+
+/*
+ * Callback for reading data from device
+ *
+ * Check urb status, call read function and resubmit urb read operation.
+ */
+static void usb_8dev_read_bulk_callback(struct urb *urb)
+{
+ struct usb_8dev_priv *priv = urb->context;
+ struct net_device *netdev;
+ int retval;
+ int pos = 0;
+
+ netdev = priv->netdev;
+
+ if (!netif_device_present(netdev))
+ return;
+
+ switch (urb->status) {
+ case 0: /* success */
+ break;
+
+ case -ENOENT:
+ case -ESHUTDOWN:
+ return;
+
+ default:
+ netdev_info(netdev, "Rx URB aborted (%d)\n",
+ urb->status);
+ goto resubmit_urb;
+ }
+
+ while (pos < urb->actual_length) {
+ struct usb_8dev_rx_msg *msg;
+
+ if (pos + sizeof(struct usb_8dev_rx_msg) > urb->actual_length) {
+ netdev_err(priv->netdev, "format error\n");
+ break;
+ }
+
+ msg = (struct usb_8dev_rx_msg *)(urb->transfer_buffer + pos);
+ usb_8dev_rx_can_msg(priv, msg);
+
+ pos += sizeof(struct usb_8dev_rx_msg);
+ }
+
+resubmit_urb:
+ usb_fill_bulk_urb(urb, priv->udev,
+ usb_rcvbulkpipe(priv->udev, USB_8DEV_ENDP_DATA_RX),
+ urb->transfer_buffer, RX_BUFFER_SIZE,
+ usb_8dev_read_bulk_callback, priv);
+
+ retval = usb_submit_urb(urb, GFP_ATOMIC);
+
+ if (retval == -ENODEV)
+ netif_device_detach(netdev);
+ else if (retval)
+ netdev_err(netdev,
+ "failed resubmitting read bulk urb: %d\n", retval);
+}
+
+/*
+ * Callback handler for write operations
+ *
+ * Free allocated buffers, check transmit status and
+ * calculate statistic.
+ */
+static void usb_8dev_write_bulk_callback(struct urb *urb)
+{
+ struct usb_8dev_tx_urb_context *context = urb->context;
+ struct usb_8dev_priv *priv;
+ struct net_device *netdev;
+
+ BUG_ON(!context);
+
+ priv = context->priv;
+ netdev = priv->netdev;
+
+ /* free up our allocated buffer */
+ usb_free_coherent(urb->dev, urb->transfer_buffer_length,
+ urb->transfer_buffer, urb->transfer_dma);
+
+ atomic_dec(&priv->active_tx_urbs);
+
+ if (!netif_device_present(netdev))
+ return;
+
+ if (urb->status)
+ netdev_info(netdev, "Tx URB aborted (%d)\n",
+ urb->status);
+
+ netdev->stats.tx_packets++;
+ netdev->stats.tx_bytes += context->dlc;
+
+ can_get_echo_skb(netdev, context->echo_index);
+
+ /* Release context */
+ context->echo_index = MAX_TX_URBS;
+
+ netif_wake_queue(netdev);
+}
+
+/* Send data to device */
+static netdev_tx_t usb_8dev_start_xmit(struct sk_buff *skb,
+ struct net_device *netdev)
+{
+ struct usb_8dev_priv *priv = netdev_priv(netdev);
+ struct net_device_stats *stats = &netdev->stats;
+ struct can_frame *cf = (struct can_frame *) skb->data;
+ struct usb_8dev_tx_msg *msg;
+ struct urb *urb;
+ struct usb_8dev_tx_urb_context *context = NULL;
+ u8 *buf;
+ int i, err;
+ size_t size = sizeof(struct usb_8dev_tx_msg);
+
+ if (can_dropped_invalid_skb(netdev, skb))
+ return NETDEV_TX_OK;
+
+ /* create a URB, and a buffer for it, and copy the data to the URB */
+ urb = usb_alloc_urb(0, GFP_ATOMIC);
+ if (!urb) {
+ netdev_err(netdev, "No memory left for URBs\n");
+ goto nomem;
+ }
+
+ buf = usb_alloc_coherent(priv->udev, size, GFP_ATOMIC,
+ &urb->transfer_dma);
+ if (!buf) {
+ netdev_err(netdev, "No memory left for USB buffer\n");
+ goto nomembuf;
+ }
+
+ memset(buf, 0, size);
+
+ msg = (struct usb_8dev_tx_msg *)buf;
+ msg->begin = USB_8DEV_DATA_START;
+ msg->flags = 0x00;
+
+ if (cf->can_id & CAN_RTR_FLAG)
+ msg->flags |= USB_8DEV_RTR;
+
+ if (cf->can_id & CAN_EFF_FLAG)
+ msg->flags |= USB_8DEV_EXTID;
+
+ msg->id = cpu_to_be32(cf->can_id & CAN_ERR_MASK);
+ msg->dlc = cf->can_dlc;
+ memcpy(msg->data, cf->data, cf->can_dlc);
+ msg->end = USB_8DEV_DATA_END;
+
+ for (i = 0; i < MAX_TX_URBS; i++) {
+ if (priv->tx_contexts[i].echo_index == MAX_TX_URBS) {
+ context = &priv->tx_contexts[i];
+ break;
+ }
+ }
+
+ /*
+ * May never happen! When this happens we'd more URBs in flight as
+ * allowed (MAX_TX_URBS).
+ */
+ if (!context)
+ goto nofreecontext;
+
+ context->priv = priv;
+ context->echo_index = i;
+ context->dlc = cf->can_dlc;
+
+ usb_fill_bulk_urb(urb, priv->udev,
+ usb_sndbulkpipe(priv->udev, USB_8DEV_ENDP_DATA_TX),
+ buf, size, usb_8dev_write_bulk_callback, context);
+ urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+ usb_anchor_urb(urb, &priv->tx_submitted);
+
+ can_put_echo_skb(skb, netdev, context->echo_index);
+
+ atomic_inc(&priv->active_tx_urbs);
+
+ err = usb_submit_urb(urb, GFP_ATOMIC);
+ if (unlikely(err))
+ goto failed;
+ else if (atomic_read(&priv->active_tx_urbs) >= MAX_TX_URBS)
+ /* Slow down tx path */
+ netif_stop_queue(netdev);
+
+ /*
+ * Release our reference to this URB, the USB core will eventually free
+ * it entirely.
+ */
+ usb_free_urb(urb);
+
+ return NETDEV_TX_OK;
+
+nofreecontext:
+ usb_unanchor_urb(urb);
+ usb_free_coherent(priv->udev, size, buf, urb->transfer_dma);
+
+ netdev_warn(netdev, "couldn't find free context");
+
+ return NETDEV_TX_BUSY;
+
+failed:
+ can_free_echo_skb(netdev, context->echo_index);
+
+ usb_unanchor_urb(urb);
+ usb_free_coherent(priv->udev, size, buf, urb->transfer_dma);
+
+ atomic_dec(&priv->active_tx_urbs);
+
+ if (err == -ENODEV)
+ netif_device_detach(netdev);
+ else
+ netdev_warn(netdev, "failed tx_urb %d\n", err);
+
+nomembuf:
+ usb_free_urb(urb);
+
+nomem:
+ dev_kfree_skb(skb);
+ stats->tx_dropped++;
+
+ return NETDEV_TX_OK;
+}
+
+static int usb_8dev_get_berr_counter(const struct net_device *netdev,
+ struct can_berr_counter *bec)
+{
+ struct usb_8dev_priv *priv = netdev_priv(netdev);
+
+ bec->txerr = priv->bec.txerr;
+ bec->rxerr = priv->bec.rxerr;
+
+ return 0;
+}
+
+/* Start USB device */
+static int usb_8dev_start(struct usb_8dev_priv *priv)
+{
+ struct net_device *netdev = priv->netdev;
+ int err, i;
+
+ for (i = 0; i < MAX_RX_URBS; i++) {
+ struct urb *urb = NULL;
+ u8 *buf;
+
+ /* create a URB, and a buffer for it */
+ urb = usb_alloc_urb(0, GFP_KERNEL);
+ if (!urb) {
+ netdev_err(netdev, "No memory left for URBs\n");
+ err = -ENOMEM;
+ break;
+ }
+
+ buf = usb_alloc_coherent(priv->udev, RX_BUFFER_SIZE, GFP_KERNEL,
+ &urb->transfer_dma);
+ if (!buf) {
+ netdev_err(netdev, "No memory left for USB buffer\n");
+ usb_free_urb(urb);
+ err = -ENOMEM;
+ break;
+ }
+
+ usb_fill_bulk_urb(urb, priv->udev,
+ usb_rcvbulkpipe(priv->udev,
+ USB_8DEV_ENDP_DATA_RX),
+ buf, RX_BUFFER_SIZE,
+ usb_8dev_read_bulk_callback, priv);
+ urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+ usb_anchor_urb(urb, &priv->rx_submitted);
+
+ err = usb_submit_urb(urb, GFP_KERNEL);
+ if (err) {
+ usb_unanchor_urb(urb);
+ usb_free_coherent(priv->udev, RX_BUFFER_SIZE, buf,
+ urb->transfer_dma);
+ break;
+ }
+
+ /* Drop reference, USB core will take care of freeing it */
+ usb_free_urb(urb);
+ }
+
+ /* Did we submit any URBs */
+ if (i == 0) {
+ netdev_warn(netdev, "couldn't setup read URBs\n");
+ return err;
+ }
+
+ /* Warn if we've couldn't transmit all the URBs */
+ if (i < MAX_RX_URBS)
+ netdev_warn(netdev, "rx performance may be slow\n");
+
+ err = usb_8dev_cmd_open(priv);
+ if (err)
+ goto failed;
+
+ priv->can.state = CAN_STATE_ERROR_ACTIVE;
+
+ return 0;
+
+failed:
+ if (err == -ENODEV)
+ netif_device_detach(priv->netdev);
+
+ netdev_warn(netdev, "couldn't submit control: %d\n", err);
+
+ return err;
+}
+
+/* Open USB device */
+static int usb_8dev_open(struct net_device *netdev)
+{
+ struct usb_8dev_priv *priv = netdev_priv(netdev);
+ int err;
+
+ /* common open */
+ err = open_candev(netdev);
+ if (err)
+ return err;
+
+ /* finally start device */
+ err = usb_8dev_start(priv);
+ if (err) {
+ if (err == -ENODEV)
+ netif_device_detach(priv->netdev);
+
+ netdev_warn(netdev, "couldn't start device: %d\n",
+ err);
+
+ close_candev(netdev);
+
+ return err;
+ }
+
+ netif_start_queue(netdev);
+
+ return 0;
+}
+
+static void unlink_all_urbs(struct usb_8dev_priv *priv)
+{
+ int i;
+
+ usb_kill_anchored_urbs(&priv->rx_submitted);
+
+ usb_kill_anchored_urbs(&priv->tx_submitted);
+ atomic_set(&priv->active_tx_urbs, 0);
+
+ for (i = 0; i < MAX_TX_URBS; i++)
+ priv->tx_contexts[i].echo_index = MAX_TX_URBS;
+}
+
+/* Close USB device */
+static int usb_8dev_close(struct net_device *netdev)
+{
+ struct usb_8dev_priv *priv = netdev_priv(netdev);
+ int err = 0;
+
+ /* Send CLOSE command to CAN controller */
+ err = usb_8dev_cmd_close(priv);
+ if (err)
+ netdev_warn(netdev, "couldn't stop device");
+
+ priv->can.state = CAN_STATE_STOPPED;
+
+ netif_stop_queue(netdev);
+
+ /* Stop polling */
+ unlink_all_urbs(priv);
+
+ close_candev(netdev);
+
+ return err;
+}
+
+static const struct net_device_ops usb_8dev_netdev_ops = {
+ .ndo_open = usb_8dev_open,
+ .ndo_stop = usb_8dev_close,
+ .ndo_start_xmit = usb_8dev_start_xmit,
+};
+
+static const struct can_bittiming_const usb_8dev_bittiming_const = {
+ .name = "usb_8dev",
+ .tseg1_min = USB_8DEV_TSEG1_MIN,
+ .tseg1_max = USB_8DEV_TSEG1_MAX,
+ .tseg2_min = USB_8DEV_TSEG2_MIN,
+ .tseg2_max = USB_8DEV_TSEG2_MAX,
+ .sjw_max = USB_8DEV_SJW_MAX,
+ .brp_min = USB_8DEV_BRP_MIN,
+ .brp_max = USB_8DEV_BRP_MAX,
+ .brp_inc = USB_8DEV_BRP_INC,
+};
+
+/*
+ * Probe USB device
+ *
+ * Check device and firmware.
+ * Set supported modes and bittiming constants.
+ * Allocate some memory.
+ */
+static int usb_8dev_probe(struct usb_interface *intf,
+ const struct usb_device_id *id)
+{
+ struct net_device *netdev;
+ struct usb_8dev_priv *priv;
+ int i, err = -ENOMEM;
+ u32 version;
+ char buf[18];
+ struct usb_device *usbdev = interface_to_usbdev(intf);
+
+ /* product id looks strange, better we also check iProduct string */
+ if (usb_string(usbdev, usbdev->descriptor.iProduct, buf,
+ sizeof(buf)) > 0 && strcmp(buf, "USB2CAN converter")) {
+ dev_info(&usbdev->dev, "ignoring: not an USB2CAN converter\n");
+ return -ENODEV;
+ }
+
+ netdev = alloc_candev(sizeof(struct usb_8dev_priv), MAX_TX_URBS);
+ if (!netdev) {
+ dev_err(&intf->dev, "Couldn't alloc candev\n");
+ return -ENOMEM;
+ }
+
+ priv = netdev_priv(netdev);
+
+ priv->udev = usbdev;
+ priv->netdev = netdev;
+
+ priv->can.state = CAN_STATE_STOPPED;
+ priv->can.clock.freq = USB_8DEV_ABP_CLOCK;
+ priv->can.bittiming_const = &usb_8dev_bittiming_const;
+ priv->can.do_set_mode = usb_8dev_set_mode;
+ priv->can.do_get_berr_counter = usb_8dev_get_berr_counter;
+ priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK |
+ CAN_CTRLMODE_LISTENONLY |
+ CAN_CTRLMODE_ONE_SHOT;
+
+ netdev->netdev_ops = &usb_8dev_netdev_ops;
+
+ netdev->flags |= IFF_ECHO; /* we support local echo */
+
+ init_usb_anchor(&priv->rx_submitted);
+
+ init_usb_anchor(&priv->tx_submitted);
+ atomic_set(&priv->active_tx_urbs, 0);
+
+ for (i = 0; i < MAX_TX_URBS; i++)
+ priv->tx_contexts[i].echo_index = MAX_TX_URBS;
+
+ priv->cmd_msg_buffer = kzalloc(sizeof(struct usb_8dev_cmd_msg),
+ GFP_KERNEL);
+ if (!priv->cmd_msg_buffer) {
+ netdev_err(netdev, "Couldn't alloc Tx buffer\n");
+ goto cleanup_candev;
+ }
+
+ usb_set_intfdata(intf, priv);
+
+ SET_NETDEV_DEV(netdev, &intf->dev);
+
+ mutex_init(&priv->usb_8dev_cmd_lock);
+
+ err = register_candev(netdev);
+ if (err) {
+ netdev_err(netdev,
+ "couldn't register CAN device: %d\n", err);
+ goto cleanup_cmd_msg_buffer;
+ }
+
+ err = usb_8dev_cmd_version(priv, &version);
+ if (err) {
+ netdev_err(netdev, "can't get firmware version\n");
+ goto cleanup_cmd_msg_buffer;
+ } else {
+ netdev_info(netdev,
+ "firmware: %d.%d, hardware: %d.%d\n",
+ (version>>24) & 0xff, (version>>16) & 0xff,
+ (version>>8) & 0xff, version & 0xff);
+ }
+
+ return 0;
+
+cleanup_cmd_msg_buffer:
+ kfree(priv->cmd_msg_buffer);
+
+cleanup_candev:
+ free_candev(netdev);
+
+ return err;
+
+}
+
+/* Called by the usb core when driver is unloaded or device is removed */
+static void usb_8dev_disconnect(struct usb_interface *intf)
+{
+ struct usb_8dev_priv *priv = usb_get_intfdata(intf);
+
+ usb_set_intfdata(intf, NULL);
+
+ if (priv) {
+ netdev_info(priv->netdev, "device disconnected\n");
+
+ unregister_netdev(priv->netdev);
+ free_candev(priv->netdev);
+
+ unlink_all_urbs(priv);
+ }
+
+}
+
+static struct usb_driver usb_8dev_driver = {
+ .name = "usb_8dev",
+ .probe = usb_8dev_probe,
+ .disconnect = usb_8dev_disconnect,
+ .id_table = usb_8dev_table,
+};
+
+module_usb_driver(usb_8dev_driver);
+
+MODULE_AUTHOR("Bernd Krumboeck <krumboeck@universalnet.at>");
+MODULE_DESCRIPTION("CAN driver for 8 devices USB2CAN interfaces");
+MODULE_LICENSE("GPL v2");
--
1.7.10.4
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v9] usb_8dev: Add support for USB2CAN interface from 8 devices
@ 2013-01-18 14:31 "Bernd Krumböck"
2013-01-18 19:47 ` Oliver Hartkopp
0 siblings, 1 reply; 14+ messages in thread
From: "Bernd Krumböck" @ 2013-01-18 14:31 UTC (permalink / raw)
To: Oliver Hartkopp; +Cc: linux-can@vger.kernel.org, linux-usb, info, gediminas
> On 16.01.2013 09:07, "Bernd Krumböck" wrote:
>
>> Hi Oliver!
>>
>>> When detaching the device from the CAN bus when sending/receiving CAN
traffic
>>> i got these dmesg infos:
>>>
>>> [ 960.047130] usb_8dev 2-1.4:1.0 can2: Unknown status/error message (0)
>>> [ 976.544343] usb_8dev 2-1.4:1.0 can2: Unknown status/error message (0)
>>>
>>
>> Sorry, I can't do this sort of tests myself, because my second can device
>> is an expensive device, without developer/test mode. ;-)
>>
>> Gerd helped me with the can tests so far. (Thank you!)
>>
>> The messages you see mean "Normal condition" and shouldn't be
displayed. I'll fix them in the next version.
>>
>
>
> Here some more dmesg outputs:
>
> [ 308.198354] ems_pcmcia 0.0 can0: setting BTR0=0x00 BTR1=0x14
> [ 315.208555] can: raw protocol (rev 20120528)
> [ 328.579107] usb 2-1.2: new full-speed USB device number 6 using ehci-pci
> [ 328.673540] usb 2-1.2: New USB device found, idVendor=0483,
> idProduct=1234
> [ 328.673548] usb 2-1.2: New USB device strings: Mfr=1, Product=2,
SerialNumber=3
> [ 328.673553] usb 2-1.2: Product: USB2CAN converter
> [ 328.673557] usb 2-1.2: Manufacturer: edevices
> [ 328.673561] usb 2-1.2: SerialNumber: ED000212
> [ 328.708127] usb_8dev 2-1.2:1.0 can2: firmware: 1.4, hardware: 255.255
[ 328.708209] usbcore: registered new interface driver usb_8dev [
432.319047] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0) [
439.522380] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0) [
449.324727] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0) [
574.442663] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0) [
639.810998] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (39)
<------------- CAN plug out / plug in ?
>
> I correctly get an error message frame which is displayed by candump
can2,0~0,#FFFFFFFF -e
> Very nice.
>
> But i think there's no additional kernel message needed for that.
It's a bug. Will be fixed in the next version.
>
> [ 640.066949] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 643.669320] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 645.703327] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 659.652396] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 667.130633] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 682.904587] usb_8dev 2-1.2:1.0 can2: Unknown status/error message
(39) <------------- CAN plug out / plug in ?
> [ 683.115139] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 692.402507] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 754.103247] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 813.887344] usb 2-1.4: new full-speed USB device number 7 using
ehci-pci <------------- USB plug in of PEAK adapter
> [ 813.985254] usb 2-1.4: New USB device found, idVendor=0c72,
> idProduct=000c
> [ 813.985258] usb 2-1.4: New USB device strings: Mfr=0, Product=3,
SerialNumber=0
> [ 813.985261] usb 2-1.4: Product: VER1:PEAK
> [ 813.985261] VER2:02.8.01
> [ 813.985261] DAT :06.05.2004
> [ 813.985261] TIME:09:35:37
> [ 813.985261] ...
> [ 814.007847] peak_usb 2-1.4:1.0: PEAK-System PCAN-USB adapter hwrev 28
serial FFFFFFFF (1 channel)
> [ 814.008347] peak_usb 2-1.4:1.0 can3: attached to PCAN-USB channel 0
(device 37)
> [ 814.008400] usbcore: registered new interface driver peak_usb [
836.196103] peak_usb 2-1.4:1.0 can3: setting BTR0=0x00 BTR1=0x14 [
858.676730] usb_8dev 2-1.2:1.0 can2: couldn't find free context
<------------- some 100% load tests
> [ 900.211646] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 1007.075674] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 1007.083660] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 1012.947678] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 1012.947684] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 3542.360315] usb_8dev 2-1.2:1.0 can2: couldn't find free context [
3775.350727] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0) [
4019.272711] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0) [
4019.276510] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0) [
4034.787824] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0) [
4036.305381] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0) [
4043.180064] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (39)
<------------- CAN plug out / plug in ?
> [ 4063.727159] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 4063.730771] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 4084.564526] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 4084.566509] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 4090.721503] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 4090.730468] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 4135.224318] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> <------------- USB plug out
> [ 4135.224560] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 4135.224780] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 4135.225035] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 4135.225281] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 4135.225530] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
>
> (..)
>
> [ 4135.449143] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 4135.449163] usb 2-1.2: USB disconnect, device number 6
> [ 4135.449406] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 4135.450149] usb_8dev 2-1.2:1.0 can2: device disconnected
> [ 4135.450223] usb_8dev 2-1.2:1.0 can2: sending command message failed [
4135.450226] usb_8dev 2-1.2:1.0 can2: couldn't stop device
> [ 4509.018148] usb 2-1.2: new full-speed USB device number 8 using
ehci-pci <------------- USB plug in
> [ 4509.090027] usb 2-1.2: device descriptor read/64, error -32
> [ 4509.265758] usb 2-1.2: device descriptor read/64, error -32
> [ 4509.441420] usb 2-1.2: new full-speed USB device number 9 using ehci-pci
> [ 4509.535892] usb 2-1.2: New USB device found, idVendor=0483,
> idProduct=1234
> [ 4509.535900] usb 2-1.2: New USB device strings: Mfr=1, Product=2,
SerialNumber=3
> [ 4509.535905] usb 2-1.2: Product: USB2CAN converter
> [ 4509.535909] usb 2-1.2: Manufacturer: edevices
> [ 4509.535913] usb 2-1.2: SerialNumber: ED000212
> [ 4509.538736] usb_8dev 2-1.2:1.0 can2: firmware: 1.4, hardware: 255.255
[ 5043.232674] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> <------------- USB plug out
> [ 5043.232920] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 5043.233168] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 5043.233422] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 5043.233672] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
>
> (..)
>
> [ 5043.450557] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 5043.450820] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 5043.451067] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 5043.451331] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 5043.451562] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 5043.451958] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 5043.452068] usb 2-1.2: USB disconnect, device number 9 <-------------
ha ha ha - correct but pretty late %-]
> [ 5043.452166] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
> [ 5043.452368] usb_8dev 2-1.2:1.0 can2: device disconnected
> [ 5043.452388] usb_8dev 2-1.2:1.0 can2: sending command message failed [
5043.452391] usb_8dev 2-1.2:1.0 can2: couldn't stop device
> [ 5045.693712] usb 2-1.2: new full-speed USB device number 10 using
ehci-pci <------------- USB plug in - fast reconnect
> [ 5045.765625] usb 2-1.2: device descriptor read/64, error -32
> [ 5045.941158] usb 2-1.2: device descriptor read/64, error -32
> [ 5046.116888] usb 2-1.2: new full-speed USB device number 11 using
ehci-pci
> [ 5046.211472] usb 2-1.2: New USB device found, idVendor=0483,
> idProduct=1234
> [ 5046.211480] usb 2-1.2: New USB device strings: Mfr=1, Product=2,
SerialNumber=3
> [ 5046.211485] usb 2-1.2: Product: USB2CAN converter
> [ 5046.211489] usb 2-1.2: Manufacturer: edevices
> [ 5046.211493] usb 2-1.2: SerialNumber: ED000212
> [ 5046.214561] usb_8dev 2-1.2:1.0 can2: firmware: 1.4, hardware: 255.255
[ 5079.471265] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 5094.652853] usb_8dev 2-1.2:1.0 can2: Unknown status/error message (0)
[ 5188.280220] usb_8dev 2-1.2:1.0 can2: couldn't find free context
<------------- some 100% load tests
> [ 5349.301144] usb_8dev 2-1.2:1.0 can2: couldn't find free context [
5508.561402] usb_8dev 2-1.2:1.0 can2: couldn't find free context [
5755.661129] usb_8dev 2-1.2:1.0 can2: couldn't find free context [
5786.781054] usb_8dev 2-1.2:1.0 can2: couldn't find free context
<------------- (..)
> [ 5822.180928] usb_8dev 2-1.2:1.0 can2: couldn't find free context [
5827.850885] usb_8dev 2-1.2:1.0 can2: couldn't find free context [
5891.685618] usb_8dev 2-1.2:1.0 can2: couldn't find free context [
5930.230438] usb_8dev 2-1.2:1.0 can2: couldn't find free context
<------------- some 100% load tests
> [ 5941.577933] peak_usb 2-1.4:1.0 can3: Rx urb aborted (-32)
> [ 5941.743693] usb 2-1.2: USB disconnect, device number 11
> [ 5941.744096] usb_8dev 2-1.2:1.0 can2: device disconnected
> [ 5941.744121] usb_8dev 2-1.2:1.0 can2: sending command message failed [
5941.744124] usb_8dev 2-1.2:1.0 can2: couldn't stop device
How did you do this test?
>
> Finally disconnecting the USB and the CAN bus - even under moderate CAN
traffic conditions genereates this output.
>
> FYI: My laptop never crashed during these tests :-)
I will try a newer kernel next time.
> I forgot to check the other USB CAN adapters for comparison.
> Will do tomorrow.
>
> Regards,
> Oliver
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v9] usb_8dev: Add support for USB2CAN interface from 8 devices
2013-01-18 14:31 "Bernd Krumböck"
@ 2013-01-18 19:47 ` Oliver Hartkopp
0 siblings, 0 replies; 14+ messages in thread
From: Oliver Hartkopp @ 2013-01-18 19:47 UTC (permalink / raw)
To: Bernd Krumböck; +Cc: linux-can@vger.kernel.org, linux-usb, info, gediminas
On 18.01.2013 15:31, "Bernd Krumböck" wrote:
>> [ 5941.577933] peak_usb 2-1.4:1.0 can3: Rx urb aborted (-32)
>> [ 5941.743693] usb 2-1.2: USB disconnect, device number 11
>> [ 5941.744096] usb_8dev 2-1.2:1.0 can2: device disconnected
>> [ 5941.744121] usb_8dev 2-1.2:1.0 can2: sending command message failed [
> 5941.744124] usb_8dev 2-1.2:1.0 can2: couldn't stop device
>
> How did you do this test?
>
- plug in USB
- ip link set can2 type can bitrate 1000000 restart-ms 100
- ifconfig can2 up
- plug out USB
leads to
(..)
[ 347.106542] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
[ 347.106802] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
[ 347.107057] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
[ 347.107308] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
[ 347.107541] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
[ 347.107790] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
[ 347.108049] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
[ 347.108289] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
[ 347.108539] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
[ 347.108794] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
[ 347.108939] usb 2-1.2: USB disconnect, device number 6
[ 347.109022] usb_8dev 2-1.2:1.0 can2: Rx URB aborted (-32)
[ 347.111677] usb_8dev 2-1.2:1.0 can2: device disconnected
[ 347.111863] usb_8dev 2-1.2:1.0 can2: sending command message failed
[ 347.111868] usb_8dev 2-1.2:1.0 can2: couldn't stop device
Regards,
Oliver
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2013-01-19 6:36 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-16 7:01 [PATCH v9] usb_8dev: Add support for USB2CAN interface from 8 devices Bernd Krumboeck
[not found] ` <1355641315-15739-1-git-send-email-krumboeck-Hi41barv6paIERSsAYjmKA@public.gmane.org>
2013-01-14 20:59 ` Oliver Hartkopp
2013-01-15 20:23 ` Marc Kleine-Budde
[not found] ` <50F5BAB3.3090902-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-01-15 20:30 ` Oliver Hartkopp
2013-01-15 20:40 ` Marc Kleine-Budde
[not found] ` <50F471AC.50902-fJ+pQTUTwRTk1uMJSBkQmQ@public.gmane.org>
2013-01-15 22:05 ` "Bernd Krumböck"
[not found] ` <ae58b62ae76e6261e66774c458012a87.squirrel-2RFepEojUI0eLjVtqu/qlogRFKwBiOYo@public.gmane.org>
2013-01-16 6:13 ` Oliver Hartkopp
2013-01-16 7:51 ` "Bernd Krumböck"
2013-01-16 8:07 ` "Bernd Krumböck"
2013-01-17 21:16 ` Oliver Hartkopp
2013-01-18 19:55 ` Oliver Hartkopp
2013-01-19 6:36 ` "Bernd Krumböck"
-- strict thread matches above, loose matches on Subject: below --
2013-01-18 14:31 "Bernd Krumböck"
2013-01-18 19:47 ` Oliver Hartkopp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).