Skip to contentSkip to conversation

Introducing ETAS ES58X CAN USB interfaces

PATCH In review Vincent Mailhol 2 participants 6 messages Apr 10, 2021 – Apr 12, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v15 cover Introducing ETAS ES58X CAN USB interfaces

Here comes the 15th iteration of the patch. This new version addresses the comments received from Marc (thanks again for the review!) and simplify the device probing by using .driver_info.

** Changelog **

Changes in v15 (2021-04-10):
- Use of .driver_info to keep track of each device quirks (c.f. enum

    es58x_driver_info).
  - Replace es58x_netdev_queue_set_dql_min_limit() by
    netdev_queue_set_dql_min_limit() which was recently added in
    net-next.
  - es58x_start_xmit: remove the recursive call.
  - es58x_start_xmit: remove the memset zero of the urb
    transfer_buffer in es58x_xmit(). Adjust the
    es58{1_4,x_fd}_tx_can_msg() glue code accordingly to make sure
    that all relevant fields are correctly initialised.
  - es58x_start_xmit: directly update tx_head each time a packet is
    queued in can.echo_skb[].

- Remove es58x_set_bittiming() and es58x_set_data_bittiming(). The
bittiming is now set when opening the channel.
- Shutdown the channel when a bus off event occurs. Remove the
es58x_reset() function which is not needed anymore after this
change.
- Cleanup of the {net,}dev_dbg() calls to make the driver less
verbose.
- Modify es58x_open(), es58x_close() and es58x_probe() in order to
release driver resources as much as possible when all the network
interfaces of the device are down.
- Other trivial changes (c.f. below link for details)
Reference: https://lore.kernel.org/linux-can/[email protected]/T/#m8ca804e9f53584b79acd236602403d5b82db1e6c

Changes in v14 (2021-03-21):
- Rework the split into core support, es581_4, es58x_fd (cosmetic change) so that es581_4.h and es58x_fd.h headers can be added in one block.
- Add a fourth patch to introduce a helper function es58x_netdev_queue_set_dql_min_limit() to set up dql minimum limit (in parallel, I will try to have this merged in the network device header)
- Remove unused function es58x_add_skb_idx(): leftover from the old FIFO logic, should have been removed in v11.
- Fix memory leak in es58x_get_product_info(): buffer was not freed in case of error in usb_sting().
- s/loopback/echo and s/self reception/echo: in the driver the terms "loopback, self reception, and echo" were all used to designated the same thing. Renamed structures, variables and comments accordingly to make it more consistent.
- Remove CAN_CTRLMODE_LOOPBACK. The driver never supported this feature. It was added due to a confusion with the echo skb.
- Use the new can_free_echo_skb() which return the frame_len.
- Do the statistics handling in es58x_rx_err_msg() even if kalloc() fails.
- Replace array es58x_cmd_ret_desc[] by helper function

    es58x_cmd_ret_desc().

- Other trivial changes (c.f. below link for details)
Reference: https://lore.kernel.org/linux-can/[email protected]/T/#mbcace9c13b19a504cd28d81591f983b95eb66657

Changes in v13 (2021-03-19 by Marc Kleine-Budde):
- split the driver into 3 patches, so that it can be send via

    mailing lists (core support, es581_4, es58x_fd)

- Remove the dql.min_limit settings
- typo and kernel doc fixes
Reference: https://lore.kernel.org/linux-can/[email protected]/T/#t

Changes in v12 (2021-03-09):
- Rework the queue stop/wake management so that spinlocks are not
needed anymore.
- es58x_start_xmit(): check for valid SKB using
can_dropped_invalid_skb().
- Implemented TDC according to latest patches in linux-can-next.
Reference: https://lore.kernel.org/linux-can/[email protected]/T/#t

Changes in v11 (2021-01-23):
- Remove all WARN_ON() calls: these were use during development, relevant tests are done not to trigger these.
- es58x_start_xmit(): added net_ratelimit() condition to prevent spamming dmesg.
- add a new es58x_xmit_more() function and simplify the code of

    es58x_start_xmit().

- Removed functions {es581_4,es58x_fd}_print_conf() which were only there for debug.
- Additional comment for es58x_fd_param.bitrate_max.
- Make the device FIFO size a power of two and modify the echo_skb indexes logic to prevent the use of spinlocks.

Changes in v10 (2021-01-12):
- Rebased on linux-can-next/testing and modified according to latest
BQL patches.
Reference: https://lore.kernel.org/linux-can/[email protected]/T/#m5f99d4da8e8934a75f9481ecc3137b59f3762413
- Replaced __netdev_sent_queue() by netdev_sent_queue().

Changes in v9 (2021-01-09):
- es58x_start_xmit(): do not use skb anymore after the call of can_put_echo_skb(). Rationale: can_put_echo_skb() calls skb_clone() and thus the original skb gets consumed (i.e. use after free issue).
- es58x_start_xmit(): Add a "drop_skb" label to free the skb when errors occur.

Changes in v8 (2021-01-04):
- The driver requires CRC16. Modified Kconfig accordingly.

Changes in v7 (2020-11-17):
- Fix compilation issue if CONFIG_BQL is not set.
Reference: https://lkml.org/lkml/2020/11/15/163

Changes in v6 (2020-11-15):
- Rebase the patch on the testing branch of linux-can-next.
- Rename the helper functions according latest changes

    (e.g. can_cc_get_len() -> can_cc_dlc2len())
  - Fix comments of enum es58x_physical_layer and enum
    es58x_sync_edge.

Changes in v5 (2020-11-07):
- Add support for DLC greater than 8.
- All other patches from the previous series were either accepted or dismissed. As such, this is not a series any more but a single patch.

Changes in v4 (2020-10-17):
- Remove struct es58x_abstracted_can_frame.
- Fix formatting (spaces, comment style).
- Transform macros into static inline functions when possible.
- Fix the ctrlmode_supported flags in es581_4.c and removed misleading comments in enum es58x_samples_per_bit.
- Rename enums according to the type.
- Remove function es58x_can_put_echo_skb().
Reference: https://lkml.org/lkml/2020/10/10/53

Changes in v3 (2020-10-03):
- Remove all the calls to likely() and unlikely().
Reference: https://lkml.org/lkml/2020/9/30/995

Changes in v2 (2020-09-30):
- Fixed -W1 warnings (v1 was tested with GCC -WExtra but not with -W1).

v1 (2020-09-27):
- First release

Vincent Mailhol (3):
can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces
can: etas_es58x: add support for ETAS ES581.4 CAN USB interface
can: etas_es58x: add support for the ETAS ES58X_FD CAN USB interfaces

 drivers/net/can/usb/Kconfig                 |   10 +
 drivers/net/can/usb/Makefile                |    1 +
 drivers/net/can/usb/etas_es58x/Makefile     |    3 +
 drivers/net/can/usb/etas_es58x/es581_4.c    |  507 ++++
 drivers/net/can/usb/etas_es58x/es581_4.h    |  207 ++
 drivers/net/can/usb/etas_es58x/es58x_core.c | 2301 +++++++++++++++++++
 drivers/net/can/usb/etas_es58x/es58x_core.h |  700 ++++++
 drivers/net/can/usb/etas_es58x/es58x_fd.c   |  562 +++++
 drivers/net/can/usb/etas_es58x/es58x_fd.h   |  243 ++
 9 files changed, 4534 insertions(+)
 create mode 100644 drivers/net/can/usb/etas_es58x/Makefile
 create mode 100644 drivers/net/can/usb/etas_es58x/es581_4.c
 create mode 100644 drivers/net/can/usb/etas_es58x/es581_4.h
 create mode 100644 drivers/net/can/usb/etas_es58x/es58x_core.c
 create mode 100644 drivers/net/can/usb/etas_es58x/es58x_core.h
 create mode 100644 drivers/net/can/usb/etas_es58x/es58x_fd.c
 create mode 100644 drivers/net/can/usb/etas_es58x/es58x_fd.h
Signature · 1 line
2.26.3
#1 lore raw

PATCH v15 1/3 can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces

This patch adds the core support for various USB CAN interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php). The next patches add the glue code drivers for the individual interfaces.

---
 drivers/net/can/usb/Kconfig                 |   10 +
 drivers/net/can/usb/Makefile                |    1 +
 drivers/net/can/usb/etas_es58x/Makefile     |    3 +
 drivers/net/can/usb/etas_es58x/es58x_core.c | 2281 +++++++++++++++++++
 drivers/net/can/usb/etas_es58x/es58x_core.h |  693 ++++++
 5 files changed, 2988 insertions(+)
 create mode 100644 drivers/net/can/usb/etas_es58x/Makefile
 create mode 100644 drivers/net/can/usb/etas_es58x/es58x_core.c
 create mode 100644 drivers/net/can/usb/etas_es58x/es58x_core.h
drivers/net/can/usb/Kconfig +10 -0
index 538f4d9adb91..3deb9f1cd292 100644
@@ -20,6 +20,16 @@ config CAN_ESD_USB2
 	  This driver supports the CAN-USB/2 interface
 	  from esd electronic system design gmbh (http://www.esd.eu).
 
+config CAN_ETAS_ES58X
+	tristate "ETAS ES58X CAN/USB interfaces"
+	select CRC16
+	help
+	  This driver supports the ES581.4, ES582.1 and ES584.1 interfaces
+	  from ETAS GmbH (https://www.etas.com/en/products/es58x.php).
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called etas_es58x.
+
 config CAN_GS_USB
 	tristate "Geschwister Schneider UG interfaces"
 	help
drivers/net/can/usb/Makefile +1 -0
index aa0f17c0b2ed..748cf31a0d53 100644
@@ -6,6 +6,7 @@
 obj-$(CONFIG_CAN_8DEV_USB) += usb_8dev.o
 obj-$(CONFIG_CAN_EMS_USB) += ems_usb.o
 obj-$(CONFIG_CAN_ESD_USB2) += esd_usb2.o
+obj-$(CONFIG_CAN_ETAS_ES58X) += etas_es58x/
 obj-$(CONFIG_CAN_GS_USB) += gs_usb.o
 obj-$(CONFIG_CAN_KVASER_USB) += kvaser_usb/
 obj-$(CONFIG_CAN_MCBA_USB) += mcba_usb.o
drivers/net/can/usb/etas_es58x/Makefile new file +3 -0
new file mode 100644
index 000000000000..60a1ac935a69
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_CAN_ETAS_ES58X) += etas_es58x.o
+etas_es58x-y = es58x_core.o
drivers/net/can/usb/etas_es58x/es58x_core.c new file +2281 -0

2,281 lines not on this page · raw message

drivers/net/can/usb/etas_es58x/es58x_core.h new file +693 -0

693 lines not on this page · raw message

Signature · 1 line
2.26.3
#2 lore raw

PATCH v15 2/3 can: etas_es58x: add support for ETAS ES581.4 CAN USB interface

In reply to Vincent Mailhol

This patch adds support for the ES581.4 interface from ETAS GmbH (https://www.etas.com/en/products/es58x.php).

---
 drivers/net/can/usb/etas_es58x/Makefile     |   2 +-
 drivers/net/can/usb/etas_es58x/es581_4.c    | 507 ++++++++++++++++++++
 drivers/net/can/usb/etas_es58x/es581_4.h    | 207 ++++++++
 drivers/net/can/usb/etas_es58x/es58x_core.c |   9 +-
 drivers/net/can/usb/etas_es58x/es58x_core.h |   5 +-
 5 files changed, 726 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/can/usb/etas_es58x/es581_4.c
 create mode 100644 drivers/net/can/usb/etas_es58x/es581_4.h
drivers/net/can/usb/etas_es58x/Makefile +1 -1
index 60a1ac935a69..e4753ec9cb60 100644
@@ -1,3 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_CAN_ETAS_ES58X) += etas_es58x.o
-etas_es58x-y = es58x_core.o
+etas_es58x-y = es58x_core.o es581_4.o
drivers/net/can/usb/etas_es58x/es581_4.c new file +507 -0

507 lines not on this page · raw message

drivers/net/can/usb/etas_es58x/es581_4.h new file +207 -0

207 lines not on this page · raw message

drivers/net/can/usb/etas_es58x/es58x_core.c +7 -2
index b53563d5c542..cc003c62bee2 100644
@@ -27,10 +27,15 @@ MODULE_LICENSE("GPL v2");
 
 #define ES58X_MODULE_NAME "etas_es58x"
 #define ES58X_VENDOR_ID 0x108C
+#define ES581_4_PRODUCT_ID 0x0159
 
 /* Table of devices which work with this driver. */
 static const struct usb_device_id es58x_id_table[] = {
 	{
+		/* ETAS GmbH ES581.4 USB dual-channel CAN Bus Interface module. */
+		USB_DEVICE(ES58X_VENDOR_ID, ES581_4_PRODUCT_ID),
+		.driver_info = ES58X_DUAL_CHANNEL
+	}, {
 		/* Terminating entry */
 	}
 };
@@ -2162,8 +2167,8 @@ static int es58x_init_es58x_dev(struct usb_interface *intf,
 		return -ENODEV;
 		/* Place holder for es58x_fd glue code. */
 	} else {
-		return -ENODEV;
-		/* Place holder for es581_4 glue code. */
+		param = &es581_4_param;
+		ops = &es581_4_ops;
 	}
 
 	es58x_dev = kzalloc(es58x_sizeof_es58x_device(param), GFP_KERNEL);
drivers/net/can/usb/etas_es58x/es58x_core.h +4 -1
index ccced39d5d81..0e7a7dcc48d4 100644
@@ -18,11 +18,13 @@
 #include <linux/can.h>
 #include <linux/can/dev.h>
 
+#include "es581_4.h"
+
 /* Driver constants */
 #define ES58X_RX_URBS_MAX 5	/* Empirical value */
 #define ES58X_TX_URBS_MAX 6	/* Empirical value */
 
-#define ES58X_MAX(param) 0
+#define ES58X_MAX(param) (ES581_4_##param)
 #define ES58X_TX_BULK_MAX ES58X_MAX(TX_BULK_MAX)
 #define ES58X_RX_BULK_MAX ES58X_MAX(RX_BULK_MAX)
 #define ES58X_ECHO_BULK_MAX ES58X_MAX(ECHO_BULK_MAX)
@@ -210,6 +212,7 @@ enum es58x_ret_type {
 };
 
 union es58x_urb_cmd {
+	struct es581_4_urb_cmd es581_4_urb_cmd;
 	struct {		/* Common header parts of all variants */
 		__le16 sof;
 		u8 cmd_type;
Signature · 1 line
2.26.3
#3 lore raw

PATCH v15 3/3 can: etas_es58x: add support for the ETAS ES58X_FD CAN USB interfaces

In reply to Vincent Mailhol

This patch add support for the ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).

---
 drivers/net/can/usb/etas_es58x/Makefile     |   2 +-
 drivers/net/can/usb/etas_es58x/es58x_core.c |  19 +-
 drivers/net/can/usb/etas_es58x/es58x_core.h |   6 +-
 drivers/net/can/usb/etas_es58x/es58x_fd.c   | 562 ++++++++++++++++++++
 drivers/net/can/usb/etas_es58x/es58x_fd.h   | 243 +++++++++
 5 files changed, 828 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/can/usb/etas_es58x/es58x_fd.c
 create mode 100644 drivers/net/can/usb/etas_es58x/es58x_fd.h
drivers/net/can/usb/etas_es58x/Makefile +1 -1
index e4753ec9cb60..a129b4aa0215 100644
@@ -1,3 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_CAN_ETAS_ES58X) += etas_es58x.o
-etas_es58x-y = es58x_core.o es581_4.o
+etas_es58x-y = es58x_core.o es581_4.o es58x_fd.o
drivers/net/can/usb/etas_es58x/es58x_core.c +17 -2
index cc003c62bee2..35ba8af89b2e 100644
@@ -28,6 +28,11 @@ MODULE_LICENSE("GPL v2");
 #define ES58X_MODULE_NAME "etas_es58x"
 #define ES58X_VENDOR_ID 0x108C
 #define ES581_4_PRODUCT_ID 0x0159
+#define ES582_1_PRODUCT_ID 0x0168
+#define ES584_1_PRODUCT_ID 0x0169
+
+/* ES58X FD has some interface protocols unsupported by this driver. */
+#define ES58X_FD_INTERFACE_PROTOCOL 0
 
 /* Table of devices which work with this driver. */
 static const struct usb_device_id es58x_id_table[] = {
@@ -35,6 +40,16 @@ static const struct usb_device_id es58x_id_table[] = {
 		/* ETAS GmbH ES581.4 USB dual-channel CAN Bus Interface module. */
 		USB_DEVICE(ES58X_VENDOR_ID, ES581_4_PRODUCT_ID),
 		.driver_info = ES58X_DUAL_CHANNEL
+	}, {
+		/* ETAS GmbH ES582.1 USB dual-channel CAN FD Bus Interface module. */
+		USB_DEVICE_INTERFACE_PROTOCOL(ES58X_VENDOR_ID, ES582_1_PRODUCT_ID,
+					      ES58X_FD_INTERFACE_PROTOCOL),
+		.driver_info = ES58X_DUAL_CHANNEL | ES58X_FD_FAMILY
+	}, {
+		/* ETAS GmbH ES584.1 USB single-channel CAN FD Bus Interface module. */
+		USB_DEVICE_INTERFACE_PROTOCOL(ES58X_VENDOR_ID, ES584_1_PRODUCT_ID,
+					      ES58X_FD_INTERFACE_PROTOCOL),
+		.driver_info = ES58X_FD_FAMILY
 	}, {
 		/* Terminating entry */
 	}
@@ -2164,8 +2179,8 @@ static int es58x_init_es58x_dev(struct usb_interface *intf,
 		return ret;
 
 	if (driver_info & ES58X_FD_FAMILY) {
-		return -ENODEV;
-		/* Place holder for es58x_fd glue code. */
+		param = &es58x_fd_param;
+		ops = &es58x_fd_ops;
 	} else {
 		param = &es581_4_param;
 		ops = &es581_4_ops;
drivers/net/can/usb/etas_es58x/es58x_core.h +5 -1
index 0e7a7dcc48d4..5f4e7dc5be35 100644
@@ -19,12 +19,15 @@
 #include <linux/can/dev.h>
 
 #include "es581_4.h"
+#include "es58x_fd.h"
 
 /* Driver constants */
 #define ES58X_RX_URBS_MAX 5	/* Empirical value */
 #define ES58X_TX_URBS_MAX 6	/* Empirical value */
 
-#define ES58X_MAX(param) (ES581_4_##param)
+#define ES58X_MAX(param)				\
+	(ES581_4_##param > ES58X_FD_##param ?		\
+		ES581_4_##param : ES58X_FD_##param)
 #define ES58X_TX_BULK_MAX ES58X_MAX(TX_BULK_MAX)
 #define ES58X_RX_BULK_MAX ES58X_MAX(RX_BULK_MAX)
 #define ES58X_ECHO_BULK_MAX ES58X_MAX(ECHO_BULK_MAX)
@@ -213,6 +216,7 @@ enum es58x_ret_type {
 
 union es58x_urb_cmd {
 	struct es581_4_urb_cmd es581_4_urb_cmd;
+	struct es58x_fd_urb_cmd es58x_fd_urb_cmd;
 	struct {		/* Common header parts of all variants */
 		__le16 sof;
 		u8 cmd_type;
drivers/net/can/usb/etas_es58x/es58x_fd.c new file +562 -0

562 lines not on this page · raw message

drivers/net/can/usb/etas_es58x/es58x_fd.h new file +243 -0

243 lines not on this page · raw message

Signature · 1 line
2.26.3
#4 lore raw
In reply to Vincent Mailhol
Quoted 3 lines · Vincent Mailhol

Here comes the 15th iteration of the patch. This new version addresses the comments received from Marc (thanks again for the review!) and simplify the device probing by using .driver_info.

drivers/net/can/usb/etas_es58x/es58x_core.c +1 -1
index 35ba8af89b2e..7222b3b6ca46 100644
@@ -1096,7 +1096,7 @@ static void es58x_increment_rx_errors(struct es58x_device *es58x_dev)
  *     be aligned.
  *
  * Sends the URB command to the device specific function. Manages the
- * errors throwed back by those functions.
+ * errors thrown back by those functions.
  */
 static void es58x_handle_urb_cmd(struct es58x_device *es58x_dev,
                                 const union es58x_urb_cmd *urb_cmd)

I have applied to linux-can-next/testing with the above spell fix. Thanks for the steady work on this and all the other features.

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |
#5 lore raw

Hi Marc,

Quoted 19 lines · Marc Kleine-Budde
Quoted 3 lines · Vincent Mailhol

Here comes the 15th iteration of the patch. This new version addresses the comments received from Marc (thanks again for the review!) and simplify the device probing by using .driver_info.

drivers/net/can/usb/etas_es58x/es58x_core.c +1 -1
index 35ba8af89b2e..7222b3b6ca46 100644
@@ -1096,7 +1096,7 @@ static void es58x_increment_rx_errors(struct es58x_device *es58x_dev)
  *     be aligned.
  *
  * Sends the URB command to the device specific function. Manages the
- * errors throwed back by those functions.
+ * errors thrown back by those functions.
  */
 static void es58x_handle_urb_cmd(struct es58x_device *es58x_dev,
                                 const union es58x_urb_cmd *urb_cmd)
Quoted 2 lines

I have applied to linux-can-next/testing with the above spell fix. Thanks for the steady work on this and all the other features.

Thanks to you too! This, together with the other features is my very first open source contribution. I learned a lot from you, Oliver and the others from the mailing list. It was a nice experience.

That said, you will eventually hear from me again on the TDC netlink interface (and probably other topics as well).

Yours sincerely,
Vincent