Re: [PATCH v7] usb_8dev: Add support for USB2CAN interface from 8 devices

2012-12-14 Thread Marc Kleine-Budde
On 12/13/2012 07:40 PM, Bernd Krumboeck wrote:
 Add device driver for USB2CAN interface from 8 devices 
 (http://www.8devices.com).
 
 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 krumbo...@universalnet.at

Looks good to me. Minor style issue inline. Please provide a
documentation for the sysfs entries and place it under:
Documentation/ABI/testing/sysfs-platform.

I'd like to have a final Ack from Wolfgang regarding the error handling.

regards,
Marc
 ---
  drivers/net/can/usb/Kconfig|6 +
  drivers/net/can/usb/Makefile   |1 +
  drivers/net/can/usb/usb_8dev.c | 1094 
 
  3 files changed, 1101 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 000..d9c681b
 --- /dev/null
 +++ b/drivers/net/can/usb/usb_8dev.c
 @@ -0,0 +1,1094 @@
 +/*
 + * CAN driver for 8 devices USB2CAN converter
 + *
 + * Copyright (C) 2012 Bernd Krumboeck (krumbo...@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 (i...@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   3200
 +#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_LOOPBACK0x02
 +#define USB_8DEV_DISABLE_AUTO_RESTRANS   0x04
 +#define USB_8DEV_STATUS_FRAME0x08
 +
 +/* commands */
 +enum usb_8dev_cmd {
 + USB_8DEV_RESET = 1,
 + USB_8DEV_OPEN,
 + USB_8DEV_CLOSE,
 + 

Re: [PATCH v7] usb_8dev: Add support for USB2CAN interface from 8 devices

2012-12-14 Thread Wolfgang Grandegger
On 12/13/2012 07:40 PM, Bernd Krumboeck wrote:
 Add device driver for USB2CAN interface from 8 devices 
 (http://www.8devices.com).
 
 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 krumbo...@universalnet.at
 ---
  drivers/net/can/usb/Kconfig|6 +
  drivers/net/can/usb/Makefile   |1 +
  drivers/net/can/usb/usb_8dev.c | 1094 
 
  3 files changed, 1101 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 000..d9c681b
 --- /dev/null
 +++ b/drivers/net/can/usb/usb_8dev.c
...
 +/* 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_BIT;

For the time being please use here:

cf-data[2] |= CAN_ERR_PROT_UNSPEC;
cf-data[3] |= CAN_ERR_PROT_LOC_CRC_SEQ |
   CAN_ERR_PROT_LOC_CRC_DEL;


That's a weak point. A CAN_ERR_PROT_CRC is missing. Unfortunately, all
bits in data[3] are already used. Anyway, I'm going to look for a
consistent solution ASAP.

 + 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;
 +

Re: [PATCH v7] usb_8dev: Add support for USB2CAN interface from 8 devices

2012-12-14 Thread Bernd Krumböck
Hello Marc!

 Looks good to me. Minor style issue inline. Please provide a
 documentation for the sysfs entries and place it under:
 Documentation/ABI/testing/sysfs-platform.

Should I change the sysfs path to /sys/devices/platform/usb_8dev? At the
moment the path is /sys/bus/usb/devices/busnum:devnum.

regards,
Bernd

--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v7] usb_8dev: Add support for USB2CAN interface from 8 devices

2012-12-14 Thread Marc Kleine-Budde
On 12/14/2012 07:22 PM, Bernd Krumböck wrote:
 Hello Marc!
 
 Looks good to me. Minor style issue inline. Please provide a
 documentation for the sysfs entries and place it under:
 Documentation/ABI/testing/sysfs-platform.
 
 Should I change the sysfs path to /sys/devices/platform/usb_8dev? At the
 moment the path is /sys/bus/usb/devices/busnum:devnum.

Sorry, my fault. I copied the sysfs path from the at91 driver, which is
a platform, not a USB driver. There are several usb descriptions under
Documentation/ABI/testing/ see which way to describe your device fits best.

Marc
-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


[PATCH v7] usb_8dev: Add support for USB2CAN interface from 8 devices

2012-12-13 Thread Bernd Krumboeck
Add device driver for USB2CAN interface from 8 devices 
(http://www.8devices.com).

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 krumbo...@universalnet.at
---
 drivers/net/can/usb/Kconfig|6 +
 drivers/net/can/usb/Makefile   |1 +
 drivers/net/can/usb/usb_8dev.c | 1094 
 3 files changed, 1101 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 000..d9c681b
--- /dev/null
+++ b/drivers/net/can/usb/usb_8dev.c
@@ -0,0 +1,1094 @@
+/*
+ * CAN driver for 8 devices USB2CAN converter
+ *
+ * Copyright (C) 2012 Bernd Krumboeck (krumbo...@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 (i...@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_URBS10
+#define MAX_TX_URBS10
+#define RX_BUFFER_SIZE 64
+
+/* vendor and product id */
+#define USB_8DEV_VENDOR_ID 0x0483
+#define USB_8DEV_PRODUCT_ID0x1234
+
+/* 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 3200
+#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_SILENT0x01
+#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