Skip to contentSkip to conversation

Introducing ETAS ES58X CAN USB interfaces

PATCH RESEND New Vincent Mailhol 2 participants 6 messages Mar 9, 2021

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

v12 cover Introducing ETAS ES58X CAN USB interfaces

*Reason for resend:* the patch does not reach the linux-can mailing list because it is over the 100000 characters limit. Adding [email protected] in CC so that people who are not in CC can get it from the general mailing list instead.

Here comes the twelfth iteration of the ETAS es58x usb driver. The major difference from previous version is the total removal of spinlocks. Aside of that, I also implemented the TDC accordingly to the patch series which I submitted here two weeks ago.

This patch series is based on linux-can-next/testing. It requires the latest patches in that branch to compile.

Crossing fingers, hoping that we are now close to a release.

Thank you in advance for your review and for your time!

Yours sincerely,
Vincent

Vincent Mailhol (1):
can: usb: etas_es58X: add support for ETAS ES58X 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    |  525 ++++
 drivers/net/can/usb/etas_es58x/es581_4.h    |  208 ++
 drivers/net/can/usb/etas_es58x/es58x_core.c | 2404 +++++++++++++++++++
 drivers/net/can/usb/etas_es58x/es58x_core.h |  690 ++++++
 drivers/net/can/usb/etas_es58x/es58x_fd.c   |  600 +++++
 drivers/net/can/usb/etas_es58x/es58x_fd.h   |  243 ++
 9 files changed, 4684 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.2
#1 lore raw

PATCH RESEND v12 1/1 can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces

This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).

---
 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    |  525 ++++
 drivers/net/can/usb/etas_es58x/es581_4.h    |  208 ++
 drivers/net/can/usb/etas_es58x/es58x_core.c | 2404 +++++++++++++++++++
 drivers/net/can/usb/etas_es58x/es58x_core.h |  690 ++++++
 drivers/net/can/usb/etas_es58x/es58x_fd.c   |  600 +++++
 drivers/net/can/usb/etas_es58x/es58x_fd.h   |  243 ++
 9 files changed, 4684 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
drivers/net/can/usb/Kconfig +10 -0
index c1e5d5b570b6..978746ce8873 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..a129b4aa0215
@@ -0,0 +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 es58x_fd.o
drivers/net/can/usb/etas_es58x/es581_4.c new file +525 -0

525 lines not on this page · raw message

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

208 lines not on this page · raw message

drivers/net/can/usb/etas_es58x/es58x_core.c new file +2404 -0

2,241 lines not on this page · raw message

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

690 lines not on this page · raw message

drivers/net/can/usb/etas_es58x/es58x_fd.c new file +600 -0

600 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

The rest of this diff is not shown. View the raw message.

base-commit: e627e562c8d764a426b99a47b42d4e9f394f23bc
prerequisite-patch-id: 0ce44c0600bff103810eb09cdcd42285c85d365c
prerequisite-patch-id: d5ae23ff6cf14d07ea646d33f9f0ecf3a6f9e7e1
prerequisite-patch-id: 38fd449c0a0bc7c8346f25567e974edbd5243606
prerequisite-patch-id: f40a6871ffc879f75586ba04b3056ec0b5d8590a
prerequisite-patch-id: f3244bc526a5131c9b6b689dfc1b758126a0a99f
prerequisite-patch-id: 9a1a7334fd4c337d7fc9af5c89db128a54ec9c8d
prerequisite-patch-id: a2a2a06a29ac02e4796bf8bb8bebe04aa968113e
prerequisite-patch-id: 3381611eb10fd16725435b7dcce288c16d2fcb28
prerequisite-patch-id: f01462cc6867bb197ea80f3c6a14f0c28828550d
prerequisite-patch-id: fbcf50987c0bf12599657af5ea4b8f1b72cd4dae
prerequisite-patch-id: 27f813c54fcb64781e729f30beba394cb6324101
prerequisite-patch-id: f9996d1fb2545c8b0ee39afd2db6dca0b659e811
prerequisite-patch-id: 03759de4308f541a3cd3c9eb89c4ac1bcd6c36a0
prerequisite-patch-id: 91dfc83cc1eab008eef5658a638a970be13a6d4d
prerequisite-patch-id: 6f8fc8b8d9f794bc3e039a15d5d0f752c7044f65
prerequisite-patch-id: 607cb1c602ec6ce3f36ed573e6a4c23471da934d
prerequisite-patch-id: a5060baf10c13d07812b04a059dcd0108c144dd2
prerequisite-patch-id: 946baf14dd974293570f1f2e2c8aa81780b0b22e
prerequisite-patch-id: d2db79eff80fb8aa8728a1df5adf292bdc988953
prerequisite-patch-id: cd7663a0f2c16b829eb5116d4353a20867b32c4e
prerequisite-patch-id: 99606eec325782fb50338ca09a8c08ad79832e36
prerequisite-patch-id: 09e03c5f5daf820f5337bb9340071c41f60ea6fb
prerequisite-patch-id: 5f004d320a3121d2b999b6b3088671f670370d59
prerequisite-patch-id: ceb46ad3d3d00b333ebae335762ff4f01601adb5
prerequisite-patch-id: 94e90c8ddb8696e3cc469388e27a3c142fe07b23

Signature · 1 line
2.26.2

Part of the diff is not shown here. View the raw message.

#2 lore raw

Re: [RESEND v12] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces

Hi Vincent,

Quoted 2 lines · Vincent Mailhol

This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).

...

Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +0 -0
new file mode 100644
index 000000000000..31f907a7b75f

...

Quoted 6 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +6 -0
+/**
+ * es58x_add_skb_idx() - Increment an index of the loopback FIFO.
+ * @priv: ES58X private parameters related to the network device.
+ * @idx: address of the index to be incremented.
+ * @a: the increment. Must be positive and less or equal to
+ *	@priv->can.echo_skb_max.

drivers/net/can/usb/etas_es58x/es58x_core.c line 295

Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +10 -0
+ *
+ * Do a modulus addition: set *@idx to (*@idx + @a) %
+ * @priv->can.echo_skb_max.
+ *
+ * Rationale: the modulus operator % takes a decent amount of CPU
+ * cycles (c.f. other division functions such as
+ * include/linux/math64.h:iter_div_u64_rem()).
+ */
+static __always_inline void es58x_add_skb_idx(struct es58x_priv *priv,
+					      u16 *idx, u16 a)

Never used?

...

Quoted 18 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +18 -0
+/**
+ * es58x_get_product_info() - Get the product information and print them.
+ * @es58x_dev: ES58X device.
+ *
+ * Do a synchronous call to get the product information.
+ *
+ * Return: zero on success, errno when any error occurs.
+ */
+static int es58x_get_product_info(struct es58x_device *es58x_dev)
+{
+	struct usb_device *udev = es58x_dev->udev;
+	const int es58x_prod_info_idx = 6;
+	/* Empirical tests show a prod_info length of maximum 83,
+	 * below should be more than enough.
+	 */
+	const size_t prod_info_len = 127;
+	char *prod_info;
+	int ret;

drivers/net/can/usb/etas_es58x/es58x_core.c line 2191

Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +10 -0
+
+	prod_info = kmalloc(prod_info_len, GFP_KERNEL);
+	if (!prod_info)
+		return -ENOMEM;
+
+	ret = usb_string(udev, es58x_prod_info_idx, prod_info, prod_info_len);
+	if (ret < 0) {
+		dev_err(es58x_dev->dev,
+			"%s: Could not read the product info: %pe\n",
+			__func__, ERR_PTR(ret));

Missing free

drivers/net/can/usb/etas_es58x/es58x_core.c line 2202

Quoted 11 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +11 -0
+		return ret;
+	} else if (ret >= prod_info_len - 1) {
+		dev_warn(es58x_dev->dev,
+			 "%s: Buffer is too small, result might be truncated\n",
+			 __func__);
+	}
+	dev_info(es58x_dev->dev, "Product info: %s\n", prod_info);
+	kfree(prod_info);
+
+	return 0;
+}

Regards,
jimmy

#3 lore raw

Re: [RESEND v12] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces

Quoted 23 lines · Jimmy Assarsson

Hi Vincent,

Quoted 2 lines · Vincent Mailhol

This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).

...

Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +0 -0
new file mode 100644
index 000000000000..31f907a7b75f

...

Quoted 10 lines

+/**
+ * es58x_add_skb_idx() - Increment an index of the loopback FIFO.
+ * @priv: ES58X private parameters related to the network device.
+ * @idx: address of the index to be incremented.
+ * @a: the increment. Must be positive and less or equal to
+ * @priv->can.echo_skb_max.
+ *
+ * Do a modulus addition: set *@idx to (*@idx + @a) %
+ * @priv->can.echo_skb_max.
+ *

Quoted 8 lines

drivers/net/can/usb/etas_es58x/es58x_core.c line 295

Quoted 6 lines

+ * Rationale: the modulus operator % takes a decent amount of CPU
+ * cycles (c.f. other division functions such as
+ * include/linux/math64.h:iter_div_u64_rem()).
+ */

drivers/net/can/usb/etas_es58x/es58x_core.c new file +2 -0
+static __always_inline void es58x_add_skb_idx(struct es58x_priv *priv,
+                                           u16 *idx, u16 a)

Never used?

Indeed, this is a leftover. Should have been removed in v11 when I made the device FIFO size a power of two.
I was not warned by the compiler, probably because this is an inline function.

Quoted 23 lines

...

Quoted 22 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +22 -0
+/**
+ * es58x_get_product_info() - Get the product information and print them.
+ * @es58x_dev: ES58X device.
+ *
+ * Do a synchronous call to get the product information.
+ *
+ * Return: zero on success, errno when any error occurs.
+ */
+static int es58x_get_product_info(struct es58x_device *es58x_dev)
+{
+     struct usb_device *udev = es58x_dev->udev;
+     const int es58x_prod_info_idx = 6;
+     /* Empirical tests show a prod_info length of maximum 83,
+      * below should be more than enough.
+      */
+     const size_t prod_info_len = 127;
+     char *prod_info;
+     int ret;
+
+     prod_info = kmalloc(prod_info_len, GFP_KERNEL);
+     if (!prod_info)
+             return -ENOMEM;
Quoted 8 lines

drivers/net/can/usb/etas_es58x/es58x_core.c line 2191

Quoted 6 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +6 -0
+
+     ret = usb_string(udev, es58x_prod_info_idx, prod_info, prod_info_len);
+     if (ret < 0) {
+             dev_err(es58x_dev->dev,
+                     "%s: Could not read the product info: %pe\n",
+                     __func__, ERR_PTR(ret));

Missing free

Absolutely!

Quoted 11 lines

drivers/net/can/usb/etas_es58x/es58x_core.c line 2202

Quoted 11 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +11 -0
+             return ret;
+     } else if (ret >= prod_info_len - 1) {
+             dev_warn(es58x_dev->dev,
+                      "%s: Buffer is too small, result might be truncated\n",
+                      __func__);
+     }
+     dev_info(es58x_dev->dev, "Product info: %s\n", prod_info);
+     kfree(prod_info);
+
+     return 0;
+}

Thanks for the two findings, both will be fixed in v13.

Yours sincerely,
Vincent

#4 lore raw

Re: [RESEND v12] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces

Quoted 72 lines · Vincent MAILHOL
Quoted 23 lines · Jimmy Assarsson

Hi Vincent,

Quoted 2 lines · Vincent Mailhol

This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).

...

Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +0 -0
new file mode 100644
index 000000000000..31f907a7b75f

...

Quoted 10 lines

+/**
+ * es58x_add_skb_idx() - Increment an index of the loopback FIFO.
+ * @priv: ES58X private parameters related to the network device.
+ * @idx: address of the index to be incremented.
+ * @a: the increment. Must be positive and less or equal to
+ * @priv->can.echo_skb_max.
+ *
+ * Do a modulus addition: set *@idx to (*@idx + @a) %
+ * @priv->can.echo_skb_max.
+ *

Quoted 8 lines

drivers/net/can/usb/etas_es58x/es58x_core.c line 295

Quoted 6 lines

+ * Rationale: the modulus operator % takes a decent amount of CPU
+ * cycles (c.f. other division functions such as
+ * include/linux/math64.h:iter_div_u64_rem()).
+ */

drivers/net/can/usb/etas_es58x/es58x_core.c new file +2 -0
+static __always_inline void es58x_add_skb_idx(struct es58x_priv *priv,
+                                           u16 *idx, u16 a)

Never used?

Indeed, this is a leftover. Should have been removed in v11 when I made the device FIFO size a power of two.
I was not warned by the compiler, probably because this is an inline function.

Quoted 23 lines

...

Quoted 22 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +22 -0
+/**
+ * es58x_get_product_info() - Get the product information and print them.
+ * @es58x_dev: ES58X device.
+ *
+ * Do a synchronous call to get the product information.
+ *
+ * Return: zero on success, errno when any error occurs.
+ */
+static int es58x_get_product_info(struct es58x_device *es58x_dev)
+{
+     struct usb_device *udev = es58x_dev->udev;
+     const int es58x_prod_info_idx = 6;
+     /* Empirical tests show a prod_info length of maximum 83,
+      * below should be more than enough.
+      */
+     const size_t prod_info_len = 127;
+     char *prod_info;
+     int ret;
+
+     prod_info = kmalloc(prod_info_len, GFP_KERNEL);
+     if (!prod_info)
+             return -ENOMEM;
Quoted 8 lines

drivers/net/can/usb/etas_es58x/es58x_core.c line 2191

Quoted 6 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +6 -0
+
+     ret = usb_string(udev, es58x_prod_info_idx, prod_info, prod_info_len);
+     if (ret < 0) {
+             dev_err(es58x_dev->dev,
+                     "%s: Could not read the product info: %pe\n",
+                     __func__, ERR_PTR(ret));

Missing free

Absolutely!

Quoted 13 lines
Quoted 11 lines

drivers/net/can/usb/etas_es58x/es58x_core.c line 2202

Quoted 11 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +11 -0
+             return ret;
+     } else if (ret >= prod_info_len - 1) {
+             dev_warn(es58x_dev->dev,
+                      "%s: Buffer is too small, result might be truncated\n",
+                      __func__);
+     }
+     dev_info(es58x_dev->dev, "Product info: %s\n", prod_info);
+     kfree(prod_info);
+
+     return 0;
+}

Thanks for the two findings, both will be fixed in v13.

Out of curiosity, did you find the two issues throughout a code review or did you use any kind of static analysis tool?

#5 lore raw

Re: [RESEND v12] can: usb: etas_es58X: add support for ETAS ES58X CAN USB interfaces

Quoted 88 lines · Vincent MAILHOL
Quoted 72 lines · Vincent MAILHOL
Quoted 23 lines · Jimmy Assarsson

Hi Vincent,

Quoted 2 lines · Vincent Mailhol

This driver supports the ES581.4, ES582.1 and ES584.1 interfaces from ETAS GmbH (https://www.etas.com/en/products/es58x.php).

...

Quoted 5 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +0 -0
new file mode 100644
index 000000000000..31f907a7b75f

...

Quoted 10 lines

+/**
+ * es58x_add_skb_idx() - Increment an index of the loopback FIFO.
+ * @priv: ES58X private parameters related to the network device.
+ * @idx: address of the index to be incremented.
+ * @a: the increment. Must be positive and less or equal to
+ * @priv->can.echo_skb_max.
+ *
+ * Do a modulus addition: set *@idx to (*@idx + @a) %
+ * @priv->can.echo_skb_max.
+ *

Quoted 8 lines

drivers/net/can/usb/etas_es58x/es58x_core.c line 295

Quoted 6 lines

+ * Rationale: the modulus operator % takes a decent amount of CPU
+ * cycles (c.f. other division functions such as
+ * include/linux/math64.h:iter_div_u64_rem()).
+ */

drivers/net/can/usb/etas_es58x/es58x_core.c new file +2 -0
+static __always_inline void es58x_add_skb_idx(struct es58x_priv *priv,
+                                           u16 *idx, u16 a)

Never used?

Indeed, this is a leftover. Should have been removed in v11 when I made the device FIFO size a power of two.
I was not warned by the compiler, probably because this is an inline function.

Quoted 23 lines

...

Quoted 22 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +22 -0
+/**
+ * es58x_get_product_info() - Get the product information and print them.
+ * @es58x_dev: ES58X device.
+ *
+ * Do a synchronous call to get the product information.
+ *
+ * Return: zero on success, errno when any error occurs.
+ */
+static int es58x_get_product_info(struct es58x_device *es58x_dev)
+{
+     struct usb_device *udev = es58x_dev->udev;
+     const int es58x_prod_info_idx = 6;
+     /* Empirical tests show a prod_info length of maximum 83,
+      * below should be more than enough.
+      */
+     const size_t prod_info_len = 127;
+     char *prod_info;
+     int ret;
+
+     prod_info = kmalloc(prod_info_len, GFP_KERNEL);
+     if (!prod_info)
+             return -ENOMEM;
Quoted 8 lines

drivers/net/can/usb/etas_es58x/es58x_core.c line 2191

Quoted 6 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +6 -0
+
+     ret = usb_string(udev, es58x_prod_info_idx, prod_info, prod_info_len);
+     if (ret < 0) {
+             dev_err(es58x_dev->dev,
+                     "%s: Could not read the product info: %pe\n",
+                     __func__, ERR_PTR(ret));

Missing free

Absolutely!

Quoted 13 lines
Quoted 11 lines

drivers/net/can/usb/etas_es58x/es58x_core.c line 2202

Quoted 11 lines
drivers/net/can/usb/etas_es58x/es58x_core.c new file +11 -0
+             return ret;
+     } else if (ret >= prod_info_len - 1) {
+             dev_warn(es58x_dev->dev,
+                      "%s: Buffer is too small, result might be truncated\n",
+                      __func__);
+     }
+     dev_info(es58x_dev->dev, "Product info: %s\n", prod_info);
+     kfree(prod_info);
+
+     return 0;
+}

Thanks for the two findings, both will be fixed in v13.

Quoted 2 lines

Out of curiosity, did you find the two issues throughout a code review or did you use any kind of static analysis tool?

Code review.