All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/16]  Add support for CPC-USB/FD CAN FD interface
@ 2020-11-12 18:03 Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 01/16] can: ems_usb: Fixed warnings and comments Gerhard Uttenthaler
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

These patches extend the ems_usb.c driver to support both devices, the
classic CAN CPC-USB/ARM7 and the CAN FD CPC-USB/FD. After fixing issues given
by checkpatch.pl and adding the CPC_ClearCmdQueue function all needed parts
to support CAN FD were added step by step. Also added is support for the
listen only mode for CPC-USB/ARM7 now.
The last patch enables the driver for CPC-USB/FD.

Gerhard Uttenthaler (16):
  can: ems_usb: Fixed warnings and comments
  can: ems_usb: Added CPC_ClearCmdQueue routine.
  can: ems_usb: Fixed non C99 style initialization
  can: ems_usb: Added CAN FD message representation
  can: ems_usb: Added CAN FD initialization struct
  can: ems_usb: Made RX_BUFFER_SIZE, ems_usb_write_mode and
    ems_usb_probe device dependent
  can: ems_usb: Added listen only mode for CPC-USB/ARM7
  can: ems_usb: Modified ems_usb_read_bulk_callback to handle also
    CPC-USB/FD
  can: ems_usb: Added CAN controller initialization for CAN FD
  can: ems_usb: Added receive routine for CAN FD messages
  can: ems_usb: Added ems_usb_write_mode_fd
  can: ems_usb: Fixed ems_usb_start_xmit for CAN FD
  can: ems_usb: Made CAN error reporting CAN controller dependent
  can: ems_usb: Made structs packed
  can: ems_usb: Added error reporting for CPC-USB/FD
  can: ems_usb: Enable CPC-USB/FD support

 drivers/net/can/usb/ems_usb.c | 858 +++++++++++++++++++++++++++-------
 1 file changed, 682 insertions(+), 176 deletions(-)

-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v2 01/16] can: ems_usb: Fixed warnings and comments
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 02/16] can: ems_usb: Added CPC_ClearCmdQueue routine Gerhard Uttenthaler
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

Issues given by checkpatch.pl were resolved and outdated comments fixed

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 74 ++++++++++++++---------------------
 1 file changed, 30 insertions(+), 44 deletions(-)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 4f52810bebf8..e943cd07c5f7 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -1,8 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
-/*
- * CAN driver for EMS Dr. Thomas Wuensche CPC-USB/ARM7
+/* CAN driver for EMS Dr. Thomas Wuensche CPC-USB/ARM7
  *
- * Copyright (C) 2004-2009 EMS Dr. Thomas Wuensche
+ * Copyright (C) 2004-2020 EMS Dr. Thomas Wuensche
  */
 #include <linux/signal.h>
 #include <linux/slab.h>
@@ -15,6 +14,7 @@
 #include <linux/can/error.h>
 
 MODULE_AUTHOR("Sebastian Haas <haas@ems-wuensche.com>");
+MODULE_AUTHOR("Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>");
 MODULE_DESCRIPTION("CAN driver for EMS Dr. Thomas Wuensche CAN/USB interfaces");
 MODULE_LICENSE("GPL v2");
 
@@ -55,7 +55,7 @@ MODULE_LICENSE("GPL v2");
 #define CPC_CMD_TYPE_CLEAR_MSG_QUEUE 8  /* clear CPC_MSG queue */
 #define CPC_CMD_TYPE_CLEAR_CMD_QUEUE 28 /* clear CPC_CMD queue */
 
-#define CPC_CC_TYPE_SJA1000 2 /* Philips basic CAN controller */
+#define CPC_CC_TYPE_SJA1000 2 /* NXP CAN controller */
 
 #define CPC_CAN_ECODE_ERRFRAME 0x01 /* Ecode type */
 
@@ -64,8 +64,7 @@ MODULE_LICENSE("GPL v2");
 #define CPC_OVR_EVENT_CANSTATE  0x02
 #define CPC_OVR_EVENT_BUSERROR  0x04
 
-/*
- * If the CAN controller lost a message we indicate it with the highest bit
+/* If the CAN controller lost a message we indicate it with the highest bit
  * set in the count field.
  */
 #define CPC_OVR_HW 0x80
@@ -98,8 +97,7 @@ MODULE_LICENSE("GPL v2");
 
 #define SJA1000_DEFAULT_OUTPUT_CONTROL 0xDA
 
-/*
- * The device actually uses a 16MHz clock to generate the CAN clock
+/* CPC-USB/ARM7 actually uses a 16MHz clock to generate the CAN clock
  * but it expects SJA1000 bit settings based on 8MHz (is internally
  * converted).
  */
@@ -108,8 +106,7 @@ MODULE_LICENSE("GPL v2");
 #define CPC_TX_QUEUE_TRIGGER_LOW	25
 #define CPC_TX_QUEUE_TRIGGER_HIGH	35
 
-/*
- * CAN-Message representation in a CPC_MSG. Message object type is
+/* CAN-Message representation in a CPC_MSG. Message object type is
  * CPC_MSG_TYPE_CAN_FRAME or CPC_MSG_TYPE_RTR_FRAME or
  * CPC_MSG_TYPE_EXT_CAN_FRAME or CPC_MSG_TYPE_EXT_RTR_FRAME.
  */
@@ -139,7 +136,6 @@ struct cpc_sja1000_params {
 struct cpc_can_params {
 	u8 cc_type;
 
-	/* Will support M16C CAN controller in the future */
 	union {
 		struct cpc_sja1000_params sja1000;
 	} cc_params;
@@ -177,8 +173,7 @@ struct cpc_can_error {
 	} cc;
 };
 
-/*
- * Structure containing RX/TX error counter. This structure is used to request
+/* Structure containing RX/TX error counter. This structure is used to request
  * the values of the CAN controllers TX and RX error counter.
  */
 struct cpc_can_err_counter {
@@ -206,8 +201,7 @@ struct __packed ems_cpc_msg {
 	} msg;
 };
 
-/*
- * Table of devices that work with this driver
+/* Table of devices that work with this driver
  * NOTE: This driver supports only CPC-USB/ARM7 (LPC2119) yet.
  */
 static struct usb_device_id ems_usb_table[] = {
@@ -302,7 +296,7 @@ static void ems_usb_rx_can_msg(struct ems_usb *dev, struct ems_cpc_msg *msg)
 	struct net_device_stats *stats = &dev->netdev->stats;
 
 	skb = alloc_can_skb(dev->netdev, &cf);
-	if (skb == NULL)
+	if (!skb)
 		return;
 
 	cf->can_id = le32_to_cpu(msg->msg.can_msg.id);
@@ -332,7 +326,7 @@ static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg)
 	struct net_device_stats *stats = &dev->netdev->stats;
 
 	skb = alloc_can_err_skb(dev->netdev, &cf);
-	if (skb == NULL)
+	if (!skb)
 		return;
 
 	if (msg->type == CPC_MSG_TYPE_CAN_STATE) {
@@ -400,8 +394,7 @@ static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg)
 	netif_rx(skb);
 }
 
-/*
- * callback for bulk IN urb
+/* Callback for bulk IN urb
  */
 static void ems_usb_read_bulk_callback(struct urb *urb)
 {
@@ -486,8 +479,7 @@ static void ems_usb_read_bulk_callback(struct urb *urb)
 			   "failed resubmitting read bulk urb: %d\n", retval);
 }
 
-/*
- * callback for bulk IN urb
+/* Callback for bulk IN urb
  */
 static void ems_usb_write_bulk_callback(struct urb *urb)
 {
@@ -495,15 +487,19 @@ static void ems_usb_write_bulk_callback(struct urb *urb)
 	struct ems_usb *dev;
 	struct net_device *netdev;
 
-	BUG_ON(!context);
-
-	dev = context->dev;
-	netdev = dev->netdev;
-
 	/* free up our allocated buffer */
 	usb_free_coherent(urb->dev, urb->transfer_buffer_length,
 			  urb->transfer_buffer, urb->transfer_dma);
 
+	if (!context) {
+		/* Should definitely not happen */
+		printk(KERN_ERR "%s with no context\n", __func__);
+		return;
+	}
+
+	dev = context->dev;
+	netdev = dev->netdev;
+
 	atomic_dec(&dev->active_tx_urbs);
 
 	if (!netif_device_present(netdev))
@@ -522,11 +518,9 @@ static void ems_usb_write_bulk_callback(struct urb *urb)
 
 	/* Release context */
 	context->echo_index = MAX_TX_URBS;
-
 }
 
-/*
- * Send the given CPC command synchronously
+/* Send the given CPC command synchronously
  */
 static int ems_usb_command_msg(struct ems_usb *dev, struct ems_cpc_msg *msg)
 {
@@ -545,8 +539,7 @@ static int ems_usb_command_msg(struct ems_usb *dev, struct ems_cpc_msg *msg)
 			    &actual_length, 1000);
 }
 
-/*
- * Change CAN controllers' mode register
+/* Change CAN controllers' mode register
  */
 static int ems_usb_write_mode(struct ems_usb *dev, u8 mode)
 {
@@ -555,8 +548,7 @@ static int ems_usb_write_mode(struct ems_usb *dev, u8 mode)
 	return ems_usb_command_msg(dev, &dev->active_params);
 }
 
-/*
- * Send a CPC_Control command to change behaviour when interface receives a CAN
+/* Send a CPC_Control command to change behaviour when interface receives a CAN
  * message, bus error or CAN state changed notifications.
  */
 static int ems_usb_control_cmd(struct ems_usb *dev, u8 val)
@@ -573,8 +565,7 @@ static int ems_usb_control_cmd(struct ems_usb *dev, u8 val)
 	return ems_usb_command_msg(dev, &cmd);
 }
 
-/*
- * Start interface
+/* Start interface
  */
 static int ems_usb_start(struct ems_usb *dev)
 {
@@ -718,7 +709,6 @@ static int ems_usb_open(struct net_device *netdev)
 		return err;
 	}
 
-
 	netif_start_queue(netdev);
 
 	return 0;
@@ -779,8 +769,7 @@ static netdev_tx_t ems_usb_start_xmit(struct sk_buff *skb, struct net_device *ne
 		}
 	}
 
-	/*
-	 * May never happen! When this happens we'd more URBs in flight as
+	/* May never happen! When this happens we'd more URBs in flight as
 	 * allowed (MAX_TX_URBS).
 	 */
 	if (!context) {
@@ -832,8 +821,7 @@ static netdev_tx_t ems_usb_start_xmit(struct sk_buff *skb, struct net_device *ne
 		}
 	}
 
-	/*
-	 * Release our reference to this URB, the USB core will eventually free
+	/* Release our reference to this URB, the USB core will eventually free
 	 * it entirely.
 	 */
 	usb_free_urb(urb);
@@ -954,8 +942,7 @@ static void init_params_sja1000(struct ems_cpc_msg *msg)
 	sja1000->mode = SJA1000_MOD_RM;
 }
 
-/*
- * probe function for new CPC-USB devices
+/* probe function for new CPC-USB devices
  */
 static int ems_usb_probe(struct usb_interface *intf,
 			 const struct usb_device_id *id)
@@ -1042,8 +1029,7 @@ static int ems_usb_probe(struct usb_interface *intf,
 	return err;
 }
 
-/*
- * called by the usb core when the device is removed from the system
+/* Called by the usb core when the device is removed from the system
  */
 static void ems_usb_disconnect(struct usb_interface *intf)
 {
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 02/16] can: ems_usb: Added CPC_ClearCmdQueue routine.
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 01/16] can: ems_usb: Fixed warnings and comments Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 03/16] can: ems_usb: Fixed non C99 style initialization Gerhard Uttenthaler
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

If the command queue in the interface is flooded with messages which cannot
successfully be sent to the bus an initialization command would have to
wait to be executed.

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index e943cd07c5f7..a70bda631e4e 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -565,6 +565,21 @@ static int ems_usb_control_cmd(struct ems_usb *dev, u8 val)
 	return ems_usb_command_msg(dev, &cmd);
 }
 
+/* Send a CPC_ClearCmdQueue command
+ */
+static int ems_usb_clear_cmd_queue(struct ems_usb *dev)
+{
+	struct ems_cpc_msg cmd = {
+		.type = CPC_CMD_TYPE_CLEAR_CMD_QUEUE,
+		.length = CPC_MSG_HEADER_LEN,
+		.msgid = 0,
+		.ts_sec = 0,
+		.ts_nsec = 0
+	};
+
+	return ems_usb_command_msg(dev, &cmd);
+}
+
 /* Start interface
  */
 static int ems_usb_start(struct ems_usb *dev)
@@ -897,6 +912,7 @@ static int ems_usb_set_bittiming(struct net_device *netdev)
 	struct ems_usb *dev = netdev_priv(netdev);
 	struct can_bittiming *bt = &dev->can.bittiming;
 	u8 btr0, btr1;
+	int err;
 
 	btr0 = ((bt->brp - 1) & 0x3f) | (((bt->sjw - 1) & 0x3) << 6);
 	btr1 = ((bt->prop_seg + bt->phase_seg1 - 1) & 0xf) |
@@ -904,6 +920,13 @@ static int ems_usb_set_bittiming(struct net_device *netdev)
 	if (dev->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
 		btr1 |= 0x80;
 
+	/* If the command queue in the device is full with incoming commands
+	 * a reinitialization would not be possible before the queue is cleared.
+	 */
+	err = ems_usb_clear_cmd_queue(dev);
+	if (err)
+		return err;
+
 	netdev_info(netdev, "setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1);
 
 	dev->active_params.msg.can_params.cc_params.sja1000.btr0 = btr0;
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 03/16] can: ems_usb: Fixed non C99 style initialization
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 01/16] can: ems_usb: Fixed warnings and comments Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 02/16] can: ems_usb: Added CPC_ClearCmdQueue routine Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 04/16] can: ems_usb: Added CAN FD message representation Gerhard Uttenthaler
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

A non C99 style struct initialization was fixed

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index a70bda631e4e..a9819287e6a7 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -553,12 +553,13 @@ static int ems_usb_write_mode(struct ems_usb *dev, u8 mode)
  */
 static int ems_usb_control_cmd(struct ems_usb *dev, u8 val)
 {
-	struct ems_cpc_msg cmd;
-
-	cmd.type = CPC_CMD_TYPE_CONTROL;
-	cmd.length = CPC_MSG_HEADER_LEN + 1;
-
-	cmd.msgid = 0;
+	struct ems_cpc_msg cmd = {
+		.type = CPC_CMD_TYPE_CONTROL,
+		.length = CPC_MSG_HEADER_LEN + 1,
+		.msgid = 0,
+		.ts_sec = 0,
+		.ts_nsec = 0
+	};
 
 	cmd.msg.generic[0] = val;
 
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 04/16] can: ems_usb: Added CAN FD message representation
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
                   ` (2 preceding siblings ...)
  2020-11-12 18:03 ` [PATCH v2 03/16] can: ems_usb: Fixed non C99 style initialization Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 05/16] can: ems_usb: Added CAN FD initialization struct Gerhard Uttenthaler
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

cpc_canfd_msg struct is added, needed flags are given and the size of 
ems_cpc_msg is adjusted

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index a9819287e6a7..e75fdd457919 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -116,6 +116,27 @@ struct cpc_can_msg {
 	u8 msg[8];
 };
 
+/* CAN FD message representation in a CPC_MSG.
+ * Message object type is CPC_MSG_T_CANFD.
+ */
+struct __packed cpc_canfd_msg {
+	__le32 id;
+	u8  length;
+	u8  flags;
+	u8  msg[64];
+};
+
+/* This defines are used with the flags variable
+ * within the struct cpc_canfd_msg. A cpc_canfd_msg
+ * can also be used to send a classic CAN frame including
+ * RTR frames when CPC_FDFLAG_NONCANFD_MSG is set.
+ */
+#define CPC_FDFLAG_ESI          BIT(3)
+#define CPC_FDFLAG_RTR          BIT(4)
+#define CPC_FDFLAG_NONCANFD_MSG BIT(5)
+#define CPC_FDFLAG_BRS          BIT(6)
+#define CPC_FDFLAG_XTD          BIT(7)
+
 /* Representation of the CAN parameters for the SJA1000 controller */
 struct cpc_sja1000_params {
 	u8 mode;
@@ -190,8 +211,9 @@ struct __packed ems_cpc_msg {
 	__le32 ts_nsec;	/* timestamp in nano seconds */
 
 	union {
-		u8 generic[64];
+		u8 generic[70];
 		struct cpc_can_msg can_msg;
+		struct cpc_canfd_msg canfd_msg;
 		struct cpc_can_params can_params;
 		struct cpc_confirm confirmation;
 		struct cpc_overrun overrun;
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 05/16] can: ems_usb: Added CAN FD initialization struct
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
                   ` (3 preceding siblings ...)
  2020-11-12 18:03 ` [PATCH v2 04/16] can: ems_usb: Added CAN FD message representation Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 06/16] can: ems_usb: Made RX_BUFFER_SIZE, ems_usb_write_mode and ems_usb_probe device dependent Gerhard Uttenthaler
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

cpc_generic_can_params is used to initialize the CPC-USB/FD in a CAN
controller independent way

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index e75fdd457919..cb7a002e8627 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -153,12 +153,40 @@ struct cpc_sja1000_params {
 	u8 outp_contr;
 };
 
+#define CPC_GENERICCONF_FD          BIT(0)
+#define CPC_GENERICCONF_FD_BOSCH    BIT(1)
+#define CPC_GENERICCONF_LISTEN_ONLY BIT(2)
+#define CPC_GENERICCONF_SINGLE_SHOT BIT(3)
+#define CPC_GENERICCONF_RESET_MODE  BIT(4)
+
+#define CPC_USB_RESET_MODE 0x00
+#define CPC_USB_RUN_MODE   0x01
+
+struct __packed cpc_generic_can_params {
+	__le32 config; /* config sets CAN initialization parameters like LOM */
+	__le32 can_clk;
+	struct {
+		__le16 tseg1;  /* Time segment 1 (before sample point) */
+		__le16 tseg2;  /* Time segment 2 (after sample point) */
+		__le16 brp;    /* Baud rate rate prescaler */
+		__le16 sjw;    /* (Re)synchronization jump width */
+	} nominal_bitrate;
+	struct {
+		__le16 tseg1;  /* Time segment 1 (before sample point) */
+		__le16 tseg2;  /* Time segment 2 (after sample point) */
+		__le16 brp;    /* Baud rate prescaler */
+		__le16 sjw;    /* (Re)synchronization jump width */
+	} data_bitrate;
+	__le32 reserved[5];    /* Set to 0. Reserved for future use */
+};
+
 /* CAN params message representation */
-struct cpc_can_params {
+struct __packed cpc_can_params {
 	u8 cc_type;
 
 	union {
 		struct cpc_sja1000_params sja1000;
+		struct cpc_generic_can_params generic;
 	} cc_params;
 };
 
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 06/16] can: ems_usb: Made RX_BUFFER_SIZE, ems_usb_write_mode and ems_usb_probe device dependent
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
                   ` (4 preceding siblings ...)
  2020-11-12 18:03 ` [PATCH v2 05/16] can: ems_usb: Added CAN FD initialization struct Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 07/16] can: ems_usb: Added listen only mode for CPC-USB/ARM7 Gerhard Uttenthaler
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

RX_BUFFER_SIZE, ems_usb_write_mode and the device probe function in the
present version of the driver are fixed for CPC-USB/ARM7. This is made
device depended with this patch

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 69 ++++++++++++++++++++++++-----------
 1 file changed, 48 insertions(+), 21 deletions(-)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index cb7a002e8627..3eb3698d5ae6 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -261,9 +261,9 @@ static struct usb_device_id ems_usb_table[] = {
 
 MODULE_DEVICE_TABLE(usb, ems_usb_table);
 
-#define RX_BUFFER_SIZE      64
 #define CPC_HEADER_SIZE     4
 #define INTR_IN_BUFFER_SIZE 4
+#define CPC_USB_ARM7_RX_BUFFER_SIZE 64
 
 #define MAX_RX_URBS 10
 #define MAX_TX_URBS 10
@@ -285,6 +285,8 @@ struct ems_usb {
 	struct usb_device *udev;
 	struct net_device *netdev;
 
+	u32 bulk_rd_buf_size;
+
 	atomic_t active_tx_urbs;
 	struct usb_anchor tx_submitted;
 	struct ems_tx_urb_context tx_contexts[MAX_TX_URBS];
@@ -298,6 +300,8 @@ struct ems_usb {
 	u8 *intr_in_buffer;
 	unsigned int free_slots; /* remember number of available slots */
 
+	int (*ems_usb_write_mode)(struct ems_usb *dev, u32 mode);
+
 	struct ems_cpc_msg active_params; /* active controller parameters */
 };
 
@@ -517,7 +521,7 @@ static void ems_usb_read_bulk_callback(struct urb *urb)
 
 resubmit_urb:
 	usb_fill_bulk_urb(urb, dev->udev, usb_rcvbulkpipe(dev->udev, 2),
-			  urb->transfer_buffer, RX_BUFFER_SIZE,
+			  urb->transfer_buffer, dev->bulk_rd_buf_size,
 			  ems_usb_read_bulk_callback, dev);
 
 	retval = usb_submit_urb(urb, GFP_ATOMIC);
@@ -591,9 +595,18 @@ static int ems_usb_command_msg(struct ems_usb *dev, struct ems_cpc_msg *msg)
 
 /* Change CAN controllers' mode register
  */
-static int ems_usb_write_mode(struct ems_usb *dev, u8 mode)
+static int ems_usb_write_mode_arm7(struct ems_usb *dev, u32 mode)
 {
-	dev->active_params.msg.can_params.cc_params.sja1000.mode = mode;
+	struct cpc_sja1000_params *sja1000 =
+		&dev->active_params.msg.can_params.cc_params.sja1000;
+
+	if (mode == CPC_USB_RESET_MODE)
+		sja1000->mode |= SJA1000_MOD_RM;
+	else if (mode == CPC_USB_RUN_MODE)
+		sja1000->mode &= ~SJA1000_MOD_RM;
+
+	else
+		return -EINVAL;
 
 	return ems_usb_command_msg(dev, &dev->active_params);
 }
@@ -652,7 +665,7 @@ static int ems_usb_start(struct ems_usb *dev)
 			break;
 		}
 
-		buf = usb_alloc_coherent(dev->udev, RX_BUFFER_SIZE, GFP_KERNEL,
+		buf = usb_alloc_coherent(dev->udev, dev->bulk_rd_buf_size, GFP_KERNEL,
 					 &urb->transfer_dma);
 		if (!buf) {
 			netdev_err(netdev, "No memory left for USB buffer\n");
@@ -662,7 +675,7 @@ static int ems_usb_start(struct ems_usb *dev)
 		}
 
 		usb_fill_bulk_urb(urb, dev->udev, usb_rcvbulkpipe(dev->udev, 2),
-				  buf, RX_BUFFER_SIZE,
+				  buf, dev->bulk_rd_buf_size,
 				  ems_usb_read_bulk_callback, dev);
 		urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
 		usb_anchor_urb(urb, &dev->rx_submitted);
@@ -670,7 +683,7 @@ static int ems_usb_start(struct ems_usb *dev)
 		err = usb_submit_urb(urb, GFP_KERNEL);
 		if (err) {
 			usb_unanchor_urb(urb);
-			usb_free_coherent(dev->udev, RX_BUFFER_SIZE, buf,
+			usb_free_coherent(dev->udev, dev->bulk_rd_buf_size, buf,
 					  urb->transfer_dma);
 			usb_free_urb(urb);
 			break;
@@ -719,7 +732,7 @@ static int ems_usb_start(struct ems_usb *dev)
 	if (err)
 		goto failed;
 
-	err = ems_usb_write_mode(dev, SJA1000_MOD_NORMAL);
+	err = dev->can.do_set_mode(netdev, CAN_MODE_START);
 	if (err)
 		goto failed;
 
@@ -753,7 +766,7 @@ static int ems_usb_open(struct net_device *netdev)
 	struct ems_usb *dev = netdev_priv(netdev);
 	int err;
 
-	err = ems_usb_write_mode(dev, SJA1000_MOD_RM);
+	err = dev->ems_usb_write_mode(dev, CPC_USB_RESET_MODE);
 	if (err)
 		return err;
 
@@ -801,7 +814,10 @@ static netdev_tx_t ems_usb_start_xmit(struct sk_buff *skb, struct net_device *ne
 	if (!urb)
 		goto nomem;
 
-	buf = usb_alloc_coherent(dev->udev, size, GFP_ATOMIC, &urb->transfer_dma);
+	buf = usb_alloc_coherent(dev->udev,
+				 size,
+				 GFP_ATOMIC,
+				 &urb->transfer_dma);
 	if (!buf) {
 		netdev_err(netdev, "No memory left for USB buffer\n");
 		usb_free_urb(urb);
@@ -911,7 +927,7 @@ static int ems_usb_close(struct net_device *netdev)
 	netif_stop_queue(netdev);
 
 	/* Set CAN controller to reset mode */
-	if (ems_usb_write_mode(dev, SJA1000_MOD_RM))
+	if (dev->ems_usb_write_mode(dev, CPC_USB_RESET_MODE))
 		netdev_warn(netdev, "couldn't stop device");
 
 	close_candev(netdev);
@@ -926,7 +942,7 @@ static const struct net_device_ops ems_usb_netdev_ops = {
 	.ndo_change_mtu = can_change_mtu,
 };
 
-static const struct can_bittiming_const ems_usb_bittiming_const = {
+static const struct can_bittiming_const ems_usb_bittiming_const_arm7 = {
 	.name = "ems_usb",
 	.tseg1_min = 1,
 	.tseg1_max = 16,
@@ -944,7 +960,7 @@ static int ems_usb_set_mode(struct net_device *netdev, enum can_mode mode)
 
 	switch (mode) {
 	case CAN_MODE_START:
-		if (ems_usb_write_mode(dev, SJA1000_MOD_NORMAL))
+		if (dev->ems_usb_write_mode(dev, CPC_USB_RUN_MODE))
 			netdev_warn(netdev, "couldn't start device");
 
 		if (netif_queue_stopped(netdev))
@@ -958,7 +974,7 @@ static int ems_usb_set_mode(struct net_device *netdev, enum can_mode mode)
 	return 0;
 }
 
-static int ems_usb_set_bittiming(struct net_device *netdev)
+static int ems_usb_set_bittiming_arm7(struct net_device *netdev)
 {
 	struct ems_usb *dev = netdev_priv(netdev);
 	struct can_bittiming *bt = &dev->can.bittiming;
@@ -1037,11 +1053,24 @@ static int ems_usb_probe(struct usb_interface *intf,
 	dev->netdev = netdev;
 
 	dev->can.state = CAN_STATE_STOPPED;
-	dev->can.clock.freq = EMS_USB_ARM7_CLOCK;
-	dev->can.bittiming_const = &ems_usb_bittiming_const;
-	dev->can.do_set_bittiming = ems_usb_set_bittiming;
-	dev->can.do_set_mode = ems_usb_set_mode;
-	dev->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES;
+
+	/* Select CPC-USB/ARM7 or CPC-USB/FD */
+	switch (le16_to_cpu(dev->udev->descriptor.idProduct)) {
+	case USB_CPCUSB_ARM7_PRODUCT_ID:
+		dev->can.clock.freq = EMS_USB_ARM7_CLOCK;
+		dev->can.bittiming_const = &ems_usb_bittiming_const_arm7;
+		dev->can.do_set_bittiming = ems_usb_set_bittiming_arm7;
+		dev->can.do_set_mode = ems_usb_set_mode;
+		dev->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES;
+		init_params_sja1000(&dev->active_params);
+		dev->ems_usb_write_mode = ems_usb_write_mode_arm7;
+		dev->bulk_rd_buf_size = CPC_USB_ARM7_RX_BUFFER_SIZE;
+	break;
+
+	default:
+		err = -ENODEV;
+		goto cleanup_candev;
+	}
 
 	netdev->netdev_ops = &ems_usb_netdev_ops;
 
@@ -1072,8 +1101,6 @@ static int ems_usb_probe(struct usb_interface *intf,
 
 	SET_NETDEV_DEV(netdev, &intf->dev);
 
-	init_params_sja1000(&dev->active_params);
-
 	err = ems_usb_command_msg(dev, &dev->active_params);
 	if (err) {
 		netdev_err(netdev, "couldn't initialize controller: %d\n", err);
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 07/16] can: ems_usb: Added listen only mode for CPC-USB/ARM7
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
                   ` (5 preceding siblings ...)
  2020-11-12 18:03 ` [PATCH v2 06/16] can: ems_usb: Made RX_BUFFER_SIZE, ems_usb_write_mode and ems_usb_probe device dependent Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 08/16] can: ems_usb: Modified ems_usb_read_bulk_callback to handle also CPC-USB/FD Gerhard Uttenthaler
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

Added support for listen only mode for CPC-USB/ARM7

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 3eb3698d5ae6..0e8d1b75ef8d 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -81,6 +81,7 @@ MODULE_LICENSE("GPL v2");
 /* Mode register NXP LPC2119/SJA1000 CAN Controller */
 #define SJA1000_MOD_NORMAL 0x00
 #define SJA1000_MOD_RM     0x01
+#define SJA1000_MOD_LOM    0x02
 
 /* ECC register NXP LPC2119/SJA1000 CAN Controller */
 #define SJA1000_ECC_SEG   0x1F
@@ -600,13 +601,23 @@ static int ems_usb_write_mode_arm7(struct ems_usb *dev, u32 mode)
 	struct cpc_sja1000_params *sja1000 =
 		&dev->active_params.msg.can_params.cc_params.sja1000;
 
-	if (mode == CPC_USB_RESET_MODE)
+	if (mode == CPC_USB_RESET_MODE) {
 		sja1000->mode |= SJA1000_MOD_RM;
-	else if (mode == CPC_USB_RUN_MODE)
+	} else if (mode == CPC_USB_RUN_MODE) {
 		sja1000->mode &= ~SJA1000_MOD_RM;
 
-	else
+		if (dev->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
+			sja1000->mode |= SJA1000_MOD_LOM;
+		else
+			sja1000->mode &= ~SJA1000_MOD_LOM;
+
+		if (dev->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
+			sja1000->btr1 |= 0x80;
+		else
+			sja1000->btr1 &= ~0x80;
+	} else {
 		return -EINVAL;
+	}
 
 	return ems_usb_command_msg(dev, &dev->active_params);
 }
@@ -978,14 +989,13 @@ static int ems_usb_set_bittiming_arm7(struct net_device *netdev)
 {
 	struct ems_usb *dev = netdev_priv(netdev);
 	struct can_bittiming *bt = &dev->can.bittiming;
-	u8 btr0, btr1;
+	struct cpc_sja1000_params *sja1000 =
+		&dev->active_params.msg.can_params.cc_params.sja1000;
 	int err;
 
-	btr0 = ((bt->brp - 1) & 0x3f) | (((bt->sjw - 1) & 0x3) << 6);
-	btr1 = ((bt->prop_seg + bt->phase_seg1 - 1) & 0xf) |
+	sja1000->btr0 = ((bt->brp - 1) & 0x3f) | (((bt->sjw - 1) & 0x3) << 6);
+	sja1000->btr1 = ((bt->prop_seg + bt->phase_seg1 - 1) & 0xf) |
 		(((bt->phase_seg2 - 1) & 0x7) << 4);
-	if (dev->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
-		btr1 |= 0x80;
 
 	/* If the command queue in the device is full with incoming commands
 	 * a reinitialization would not be possible before the queue is cleared.
@@ -994,10 +1004,8 @@ static int ems_usb_set_bittiming_arm7(struct net_device *netdev)
 	if (err)
 		return err;
 
-	netdev_info(netdev, "setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1);
-
-	dev->active_params.msg.can_params.cc_params.sja1000.btr0 = btr0;
-	dev->active_params.msg.can_params.cc_params.sja1000.btr1 = btr1;
+	netdev_info(netdev, "Setting BTR0=0x%02x BTR1=0x%02x\n", sja1000->btr0,
+		    sja1000->btr1);
 
 	return ems_usb_command_msg(dev, &dev->active_params);
 }
@@ -1061,7 +1069,8 @@ static int ems_usb_probe(struct usb_interface *intf,
 		dev->can.bittiming_const = &ems_usb_bittiming_const_arm7;
 		dev->can.do_set_bittiming = ems_usb_set_bittiming_arm7;
 		dev->can.do_set_mode = ems_usb_set_mode;
-		dev->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES;
+		dev->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES |
+					      CAN_CTRLMODE_LISTENONLY;
 		init_params_sja1000(&dev->active_params);
 		dev->ems_usb_write_mode = ems_usb_write_mode_arm7;
 		dev->bulk_rd_buf_size = CPC_USB_ARM7_RX_BUFFER_SIZE;
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 08/16] can: ems_usb: Modified ems_usb_read_bulk_callback to handle also CPC-USB/FD
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
                   ` (6 preceding siblings ...)
  2020-11-12 18:03 ` [PATCH v2 07/16] can: ems_usb: Added listen only mode for CPC-USB/ARM7 Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 09/16] can: ems_usb: Added CAN controller initialization for CAN FD Gerhard Uttenthaler
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

The ems_usb_read_bulk_callback of the drivers present version uses a
byte in the beginning of the received bulk buffer to check how many 
messages come from the interface. This is not possible with CPC-USB/FD
and hence changed in a way to satisfy both types of interface.

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 91 +++++++++++++++++++----------------
 1 file changed, 50 insertions(+), 41 deletions(-)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 0e8d1b75ef8d..41f9fb126e0a 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -456,6 +456,7 @@ static void ems_usb_read_bulk_callback(struct urb *urb)
 	struct ems_usb *dev = urb->context;
 	struct net_device *netdev;
 	int retval;
+	u32 length, start;
 
 	netdev = dev->netdev;
 
@@ -474,50 +475,58 @@ static void ems_usb_read_bulk_callback(struct urb *urb)
 		goto resubmit_urb;
 	}
 
-	if (urb->actual_length > CPC_HEADER_SIZE) {
+	length = urb->actual_length;
+	start = CPC_HEADER_SIZE;
+
+	while (length >= CPC_MSG_HEADER_LEN) {
 		struct ems_cpc_msg *msg;
 		u8 *ibuf = urb->transfer_buffer;
-		u8 msg_count, start;
-
-		msg_count = ibuf[0] & ~0x80;
-
-		start = CPC_HEADER_SIZE;
-
-		while (msg_count) {
-			msg = (struct ems_cpc_msg *)&ibuf[start];
-
-			switch (msg->type) {
-			case CPC_MSG_TYPE_CAN_STATE:
-				/* Process CAN state changes */
-				ems_usb_rx_err(dev, msg);
-				break;
-
-			case CPC_MSG_TYPE_CAN_FRAME:
-			case CPC_MSG_TYPE_EXT_CAN_FRAME:
-			case CPC_MSG_TYPE_RTR_FRAME:
-			case CPC_MSG_TYPE_EXT_RTR_FRAME:
-				ems_usb_rx_can_msg(dev, msg);
-				break;
-
-			case CPC_MSG_TYPE_CAN_FRAME_ERROR:
-				/* Process errorframe */
-				ems_usb_rx_err(dev, msg);
-				break;
-
-			case CPC_MSG_TYPE_OVERRUN:
-				/* Message lost while receiving */
-				ems_usb_rx_err(dev, msg);
-				break;
-			}
-
-			start += CPC_MSG_HEADER_LEN + msg->length;
-			msg_count--;
-
-			if (start > urb->transfer_buffer_length) {
-				netdev_err(netdev, "format error\n");
-				break;
-			}
+		u32 read_count;
+
+		msg = (struct ems_cpc_msg *)&ibuf[start];
+
+		/* We should leave if length is smaller than
+		 * length indicated by payload
+		 */
+		if (length < CPC_MSG_HEADER_LEN + msg->length) {
+			netdev_err(netdev, "format error\n");
+			break;
+		}
+
+		switch (msg->type) {
+		case CPC_MSG_TYPE_CAN_STATE:
+			/* Process CAN state changes */
+			ems_usb_rx_err(dev, msg);
+			break;
+
+		case CPC_MSG_TYPE_CAN_FRAME:
+		case CPC_MSG_TYPE_EXT_CAN_FRAME:
+		case CPC_MSG_TYPE_RTR_FRAME:
+		case CPC_MSG_TYPE_EXT_RTR_FRAME:
+			ems_usb_rx_can_msg(dev, msg);
+			break;
+
+		case CPC_MSG_TYPE_CAN_FRAME_ERROR:
+			/* Process errorframe */
+			ems_usb_rx_err(dev, msg);
+			break;
+
+		case CPC_MSG_TYPE_OVERRUN:
+			/* Message lost while receiving */
+			ems_usb_rx_err(dev, msg);
+			break;
 		}
+
+		read_count = CPC_MSG_HEADER_LEN + msg->length;
+		start += read_count;
+
+		if (start > urb->transfer_buffer_length) {
+			netdev_err(netdev, "format error\n");
+			break;
+		}
+
+		if (read_count <= length)
+			length -= read_count;
 	}
 
 resubmit_urb:
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 09/16] can: ems_usb: Added CAN controller initialization for CAN FD
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
                   ` (7 preceding siblings ...)
  2020-11-12 18:03 ` [PATCH v2 08/16] can: ems_usb: Modified ems_usb_read_bulk_callback to handle also CPC-USB/FD Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 10/16] can: ems_usb: Added receive routine for CAN FD messages Gerhard Uttenthaler
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

This patch added initialization code for CPC-USB/FD 

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 136 ++++++++++++++++++++++++++++++++++
 1 file changed, 136 insertions(+)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 41f9fb126e0a..96012052a375 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -56,6 +56,7 @@ MODULE_LICENSE("GPL v2");
 #define CPC_CMD_TYPE_CLEAR_CMD_QUEUE 28 /* clear CPC_CMD queue */
 
 #define CPC_CC_TYPE_SJA1000 2 /* NXP CAN controller */
+#define CPC_CC_TYPE_GENERIC 6 /* GENERIC CAN controller */
 
 #define CPC_CAN_ECODE_ERRFRAME 0x01 /* Ecode type */
 
@@ -77,6 +78,7 @@ MODULE_LICENSE("GPL v2");
 #define USB_CPCUSB_VENDOR_ID 0x12D6
 
 #define USB_CPCUSB_ARM7_PRODUCT_ID 0x0444
+#define USB_CPCUSB_FD_PRODUCT_ID   0x0544
 
 /* Mode register NXP LPC2119/SJA1000 CAN Controller */
 #define SJA1000_MOD_NORMAL 0x00
@@ -104,6 +106,17 @@ MODULE_LICENSE("GPL v2");
  */
 #define EMS_USB_ARM7_CLOCK 8000000
 
+/* CPC-USB/FD supports the following CAN clocks
+ */
+#define EMS_USB_FD_8MHZ   8000000
+#define EMS_USB_FD_16MHZ 16000000
+#define EMS_USB_FD_20MHZ 20000000
+#define EMS_USB_FD_24MHZ 24000000
+#define EMS_USB_FD_32MHZ 32000000
+#define EMS_USB_FD_40MHZ 40000000
+#define EMS_USB_FD_80MHZ 80000000
+#define EMS_USB_FD_CLOCK EMS_USB_FD_40MHZ
+
 #define CPC_TX_QUEUE_TRIGGER_LOW	25
 #define CPC_TX_QUEUE_TRIGGER_HIGH	35
 
@@ -265,6 +278,7 @@ MODULE_DEVICE_TABLE(usb, ems_usb_table);
 #define CPC_HEADER_SIZE     4
 #define INTR_IN_BUFFER_SIZE 4
 #define CPC_USB_ARM7_RX_BUFFER_SIZE 64
+#define CPC_USB_FD_RX_BUFFER_SIZE 512
 
 #define MAX_RX_URBS 10
 #define MAX_TX_URBS 10
@@ -974,6 +988,30 @@ static const struct can_bittiming_const ems_usb_bittiming_const_arm7 = {
 	.brp_inc = 1,
 };
 
+static const struct can_bittiming_const ems_usb_bittiming_const_generic = {
+	.name = "ems_usb_fd",
+	.tseg1_min = 1,
+	.tseg1_max = 256,
+	.tseg2_min = 1,
+	.tseg2_max = 128,
+	.sjw_max = 128,
+	.brp_min = 1,
+	.brp_max = 512,
+	.brp_inc = 1,
+};
+
+static const struct can_bittiming_const ems_usb_bittiming_const_generic_data = {
+	.name = "ems_usb_fd",
+	.tseg1_min = 1,
+	.tseg1_max = 16,
+	.tseg2_min = 1,
+	.tseg2_max = 16,
+	.sjw_max = 16,
+	.brp_min = 1,
+	.brp_max = 32,
+	.brp_inc = 1,
+};
+
 static int ems_usb_set_mode(struct net_device *netdev, enum can_mode mode)
 {
 	struct ems_usb *dev = netdev_priv(netdev);
@@ -1019,6 +1057,69 @@ static int ems_usb_set_bittiming_arm7(struct net_device *netdev)
 	return ems_usb_command_msg(dev, &dev->active_params);
 }
 
+static int ems_usb_set_bittiming_generic(struct net_device *netdev)
+{
+	struct ems_usb *dev = netdev_priv(netdev);
+	struct can_bittiming *bt = &dev->can.bittiming;
+	struct cpc_generic_can_params *gcp =
+		&dev->active_params.msg.can_params.cc_params.generic;
+	int err;
+
+	gcp->config = 0;
+	gcp->can_clk = cpu_to_le32(dev->can.clock.freq);
+
+	gcp->nominal_bitrate.tseg1 = cpu_to_le16(bt->prop_seg + bt->phase_seg1);
+	gcp->nominal_bitrate.tseg2 = cpu_to_le16(bt->phase_seg2);
+	gcp->nominal_bitrate.brp = cpu_to_le16(bt->brp);
+	gcp->nominal_bitrate.sjw = cpu_to_le16(bt->sjw);
+
+	err = ems_usb_clear_cmd_queue(dev);
+	if (err)
+		return err;
+
+	netdev_dbg(netdev, "Set nominal bitrate: CAN Clock: %uMHz, Tseg1: %u, Tseg2: %u, BRP: %u, SJW: %u\n",
+		   le32_to_cpu(gcp->can_clk) / 1000000,
+		   gcp->nominal_bitrate.tseg1,
+		   gcp->nominal_bitrate.tseg2,
+		   gcp->nominal_bitrate.brp,
+		   gcp->nominal_bitrate.sjw);
+
+	return ems_usb_command_msg(dev, &dev->active_params);
+}
+
+static int ems_usb_set_bittiming_generic_data(struct net_device *netdev)
+{
+	struct ems_usb *dev = netdev_priv(netdev);
+	struct can_bittiming *bt = &dev->can.data_bittiming;
+	struct cpc_generic_can_params *gcp =
+		&dev->active_params.msg.can_params.cc_params.generic;
+	int err;
+
+	if (!(dev->can.ctrlmode & CAN_CTRLMODE_FD))
+		return 0;
+	gcp->config |= cpu_to_le32(CPC_GENERICCONF_FD);
+
+	if (dev->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO)
+		gcp->config |= cpu_to_le32(CPC_GENERICCONF_FD_BOSCH);
+
+	gcp->data_bitrate.tseg1 = cpu_to_le16(bt->prop_seg + bt->phase_seg1);
+	gcp->data_bitrate.tseg2 = cpu_to_le16(bt->phase_seg2);
+	gcp->data_bitrate.brp = cpu_to_le16(bt->brp);
+	gcp->data_bitrate.sjw = cpu_to_le16(bt->sjw);
+
+	err = ems_usb_clear_cmd_queue(dev);
+	if (err)
+		return err;
+
+	netdev_dbg(netdev, "Set data bitrate: Tseg1: %u, Tseg2: %u, BRP: %u, SJW: %u\n",
+		   gcp->data_bitrate.tseg1,
+		   gcp->data_bitrate.tseg2,
+		   gcp->data_bitrate.brp,
+		   gcp->data_bitrate.sjw);
+
+	return ems_usb_command_msg(dev, &dev->active_params);
+}
+
 static void init_params_sja1000(struct ems_cpc_msg *msg)
 {
 	struct cpc_sja1000_params *sja1000 =
@@ -1027,6 +1128,8 @@ static void init_params_sja1000(struct ems_cpc_msg *msg)
 	msg->type = CPC_CMD_TYPE_CAN_PARAMS;
 	msg->length = sizeof(struct cpc_can_params);
 	msg->msgid = 0;
+	msg->ts_sec = 0;
+	msg->ts_nsec = 0;
 
 	msg->msg.can_params.cc_type = CPC_CC_TYPE_SJA1000;
 
@@ -1049,6 +1152,24 @@ static void init_params_sja1000(struct ems_cpc_msg *msg)
 	sja1000->mode = SJA1000_MOD_RM;
 }
 
+static void init_params_generic(struct ems_cpc_msg *msg)
+{
+	struct cpc_generic_can_params *gcp =
+		&msg->msg.can_params.cc_params.generic;
+
+	msg->type = CPC_CMD_TYPE_CAN_PARAMS;
+	msg->length = sizeof(struct cpc_can_params);
+	msg->msgid = 0;
+	msg->ts_sec = 0;
+	msg->ts_nsec = 0;
+
+	memset((u8 *)gcp, 0, sizeof(struct cpc_generic_can_params));
+	msg->msg.can_params.cc_type = CPC_CC_TYPE_GENERIC;
+
+	gcp->config = cpu_to_le32(CPC_GENERICCONF_RESET_MODE);
+	gcp->can_clk = cpu_to_le32(EMS_USB_FD_CLOCK);
+}
+
 /* probe function for new CPC-USB devices
  */
 static int ems_usb_probe(struct usb_interface *intf,
@@ -1085,6 +1206,21 @@ static int ems_usb_probe(struct usb_interface *intf,
 		dev->bulk_rd_buf_size = CPC_USB_ARM7_RX_BUFFER_SIZE;
 	break;
 
+	case USB_CPCUSB_FD_PRODUCT_ID:
+		dev->can.clock.freq = EMS_USB_FD_CLOCK;
+		dev->can.bittiming_const = &ems_usb_bittiming_const_generic;
+		dev->can.data_bittiming_const = &ems_usb_bittiming_const_generic_data;
+		dev->can.do_set_bittiming = ems_usb_set_bittiming_generic;
+		dev->can.do_set_data_bittiming = ems_usb_set_bittiming_generic_data;
+		dev->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY |
+					      CAN_CTRLMODE_ONE_SHOT |
+					      CAN_CTRLMODE_BERR_REPORTING |
+					      CAN_CTRLMODE_FD |
+					      CAN_CTRLMODE_FD_NON_ISO;
+		init_params_generic(&dev->active_params);
+		dev->bulk_rd_buf_size = CPC_USB_FD_RX_BUFFER_SIZE;
+	break;
+
 	default:
 		err = -ENODEV;
 		goto cleanup_candev;
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 10/16] can: ems_usb: Added receive routine for CAN FD messages
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
                   ` (8 preceding siblings ...)
  2020-11-12 18:03 ` [PATCH v2 09/16] can: ems_usb: Added CAN controller initialization for CAN FD Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 11/16] can: ems_usb: Added ems_usb_write_mode_fd Gerhard Uttenthaler
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

Added ems_usb_rx_canfd_msg routine for CAN FD frame reception

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 44 +++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 96012052a375..8ada663350fa 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -40,6 +40,7 @@ MODULE_LICENSE("GPL v2");
 #define CPC_MSG_TYPE_OVERRUN         21 /* overrun events */
 #define CPC_MSG_TYPE_CAN_FRAME_ERROR 23 /* detected bus errors */
 #define CPC_MSG_TYPE_ERR_COUNTER     25 /* RX/TX error counter */
+#define CPC_MSG_TYPE_CANFD_FRAME     26 /* CAN FD frame */
 
 /* Messages from the PC to the CPC interface  */
 #define CPC_CMD_TYPE_CAN_FRAME     1   /* CAN data frame */
@@ -388,6 +389,45 @@ static void ems_usb_rx_can_msg(struct ems_usb *dev, struct ems_cpc_msg *msg)
 	netif_rx(skb);
 }
 
+static void ems_usb_rx_canfd_msg(struct ems_usb *dev, struct ems_cpc_msg *msg)
+{
+	struct cpc_canfd_msg *fd_msg = &msg->msg.canfd_msg;
+
+	/* Although the CPC_FDFLAG_NONCANFD_MSG flag
+	 * should not be set with a received message,
+	 * it seems better to have checked it anyway.
+	 */
+	if (!(fd_msg->flags & CPC_FDFLAG_NONCANFD_MSG)) {
+		/* CAN FD frame */
+		struct canfd_frame *cfd;
+		struct sk_buff *skb;
+		struct net_device_stats *stats = &dev->netdev->stats;
+
+		skb = alloc_canfd_skb(dev->netdev, &cfd);
+		if (!skb)
+			return;
+
+		cfd->can_id = le32_to_cpu(fd_msg->id);
+		cfd->len = fd_msg->length;
+
+		memcpy(cfd->data, fd_msg->msg, cfd->len);
+
+		cfd->flags = 0;
+		if (fd_msg->flags & CPC_FDFLAG_BRS)
+			cfd->flags |= CANFD_BRS;
+
+		if (fd_msg->flags & CPC_FDFLAG_ESI)
+			cfd->flags |= CANFD_ESI;
+
+		if (fd_msg->flags & CPC_FDFLAG_XTD)
+			cfd->can_id |= CAN_EFF_FLAG;
+
+		stats->rx_packets++;
+		stats->rx_bytes += cfd->len;
+		netif_rx(skb);
+	}
+}
+
 static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg)
 {
 	struct can_frame *cf;
@@ -520,6 +560,10 @@ static void ems_usb_read_bulk_callback(struct urb *urb)
 			ems_usb_rx_can_msg(dev, msg);
 			break;
 
+		case CPC_MSG_TYPE_CANFD_FRAME:
+			ems_usb_rx_canfd_msg(dev, msg);
+			break;
+
 		case CPC_MSG_TYPE_CAN_FRAME_ERROR:
 			/* Process errorframe */
 			ems_usb_rx_err(dev, msg);
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 11/16] can: ems_usb: Added ems_usb_write_mode_fd
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
                   ` (9 preceding siblings ...)
  2020-11-12 18:03 ` [PATCH v2 10/16] can: ems_usb: Added receive routine for CAN FD messages Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 12/16] can: ems_usb: Fixed ems_usb_start_xmit for CAN FD Gerhard Uttenthaler
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

This patch enables the supported CAN controller modes for CPC-USB/FD

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 8ada663350fa..6d8f733c6c7f 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -689,6 +689,32 @@ static int ems_usb_write_mode_arm7(struct ems_usb *dev, u32 mode)
 	return ems_usb_command_msg(dev, &dev->active_params);
 }
 
+static int ems_usb_write_mode_fd(struct ems_usb *dev, u32 mode)
+{
+	struct cpc_generic_can_params *gcp =
+		&dev->active_params.msg.can_params.cc_params.generic;
+
+	if (mode == CPC_USB_RESET_MODE) {
+		gcp->config |= cpu_to_le32(CPC_GENERICCONF_RESET_MODE);
+	} else if (mode == CPC_USB_RUN_MODE) {
+		gcp->config &= cpu_to_le32(~CPC_GENERICCONF_RESET_MODE);
+
+		if (dev->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
+			gcp->config |= cpu_to_le32(CPC_GENERICCONF_LISTEN_ONLY);
+		else
+			gcp->config &= cpu_to_le32(~CPC_GENERICCONF_LISTEN_ONLY);
+
+		if (dev->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT)
+			gcp->config |= cpu_to_le32(CPC_GENERICCONF_SINGLE_SHOT);
+		else
+			gcp->config &= cpu_to_le32(~CPC_GENERICCONF_SINGLE_SHOT);
+	} else {
+		return -EINVAL;
+	}
+
+	return ems_usb_command_msg(dev, &dev->active_params);
+}
+
 /* Send a CPC_Control command to change behaviour when interface receives a CAN
  * message, bus error or CAN state changed notifications.
  */
@@ -1256,12 +1282,14 @@ static int ems_usb_probe(struct usb_interface *intf,
 		dev->can.data_bittiming_const = &ems_usb_bittiming_const_generic_data;
 		dev->can.do_set_bittiming = ems_usb_set_bittiming_generic;
 		dev->can.do_set_data_bittiming = ems_usb_set_bittiming_generic_data;
+		dev->can.do_set_mode = ems_usb_set_mode;
 		dev->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY |
 					      CAN_CTRLMODE_ONE_SHOT |
 					      CAN_CTRLMODE_BERR_REPORTING |
 					      CAN_CTRLMODE_FD |
 					      CAN_CTRLMODE_FD_NON_ISO;
 		init_params_generic(&dev->active_params);
+		dev->ems_usb_write_mode = ems_usb_write_mode_fd;
 		dev->bulk_rd_buf_size = CPC_USB_FD_RX_BUFFER_SIZE;
 	break;
 
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 12/16] can: ems_usb: Fixed ems_usb_start_xmit for CAN FD
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
                   ` (10 preceding siblings ...)
  2020-11-12 18:03 ` [PATCH v2 11/16] can: ems_usb: Added ems_usb_write_mode_fd Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 13/16] can: ems_usb: Made CAN error reporting CAN controller dependent Gerhard Uttenthaler
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

Added code to let ems_usb_start_xmit handle CAN FD messages

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 143 ++++++++++++++++++++++++++--------
 1 file changed, 109 insertions(+), 34 deletions(-)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 6d8f733c6c7f..76d25ab5804b 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -50,6 +50,7 @@ MODULE_LICENSE("GPL v2");
 #define CPC_CMD_TYPE_CAN_STATE     14  /* CAN state message */
 #define CPC_CMD_TYPE_EXT_CAN_FRAME 15  /* Extended CAN data frame */
 #define CPC_CMD_TYPE_EXT_RTR_FRAME 16  /* Extended CAN remote frame */
+#define CPC_CMD_TYPE_CANFD_FRAME   26  /* CAN FD frame */
 #define CPC_CMD_TYPE_CAN_EXIT      200 /* exit the CAN */
 
 #define CPC_CMD_TYPE_INQ_ERR_COUNTER 25 /* request the CAN error counters */
@@ -74,6 +75,7 @@ MODULE_LICENSE("GPL v2");
 /* Size of the "struct ems_cpc_msg" without the union */
 #define CPC_MSG_HEADER_LEN   11
 #define CPC_CAN_MSG_MIN_SIZE 5
+#define CPC_CANFD_MSG_MIN_SIZE 6
 
 /* Define these values to match your devices */
 #define USB_CPCUSB_VENDOR_ID 0x12D6
@@ -902,50 +904,123 @@ static netdev_tx_t ems_usb_start_xmit(struct sk_buff *skb, struct net_device *ne
 	struct ems_usb *dev = netdev_priv(netdev);
 	struct ems_tx_urb_context *context = NULL;
 	struct net_device_stats *stats = &netdev->stats;
-	struct can_frame *cf = (struct can_frame *)skb->data;
 	struct ems_cpc_msg *msg;
 	struct urb *urb;
-	u8 *buf;
+
 	int i, err;
-	size_t size = CPC_HEADER_SIZE + CPC_MSG_HEADER_LEN
-			+ sizeof(struct cpc_can_msg);
+	u8 dlc;
+
+	u8 *buf;
+	size_t buf_size;
+	size_t buf_len = CPC_HEADER_SIZE + CPC_MSG_HEADER_LEN;
 
 	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)
-		goto nomem;
-
-	buf = usb_alloc_coherent(dev->udev,
-				 size,
-				 GFP_ATOMIC,
-				 &urb->transfer_dma);
-	if (!buf) {
-		netdev_err(netdev, "No memory left for USB buffer\n");
-		usb_free_urb(urb);
-		goto nomem;
-	}
+	if (can_is_canfd_skb(skb)) {
+		struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
+		struct cpc_canfd_msg *fd_msg;
+
+		buf_size = CPC_HEADER_SIZE +
+			   CPC_MSG_HEADER_LEN +
+			   sizeof(struct cpc_canfd_msg);
+
+		/* Create an URB and a buffer big enough for
+		 * all message lengths, copy the data to the URB
+		 */
+		urb = usb_alloc_urb(0, GFP_ATOMIC);
+		if (!urb)
+			goto nomem;
+
+		buf = usb_alloc_coherent(dev->udev,
+					 buf_size,
+					 GFP_ATOMIC,
+					 &urb->transfer_dma);
+		if (!buf) {
+			netdev_err(netdev, "No memory left for USB buffer\n");
+			usb_free_urb(urb);
+			goto nomem;
+		}
+		/* Clear first 4 bytes */
+		*(u32 *)buf = 0;
+
+		msg = (struct ems_cpc_msg *)&buf[CPC_HEADER_SIZE];
+		fd_msg = &msg->msg.canfd_msg;
+
+		msg->type = CPC_CMD_TYPE_CANFD_FRAME;
+
+		fd_msg->id = cpu_to_le32(cfd->can_id & CAN_ERR_MASK);
+		dlc = cfd->len;
+		fd_msg->length = dlc;
+		fd_msg->flags = 0;
 
-	msg = (struct ems_cpc_msg *)&buf[CPC_HEADER_SIZE];
+		if (cfd->can_id & CAN_EFF_FLAG)
+			fd_msg->flags |= CPC_FDFLAG_XTD;
 
-	msg->msg.can_msg.id = cpu_to_le32(cf->can_id & CAN_ERR_MASK);
-	msg->msg.can_msg.length = cf->can_dlc;
+		if (cfd->flags & CANFD_BRS)
+			fd_msg->flags |= CPC_FDFLAG_BRS;
 
-	if (cf->can_id & CAN_RTR_FLAG) {
-		msg->type = cf->can_id & CAN_EFF_FLAG ?
-			CPC_CMD_TYPE_EXT_RTR_FRAME : CPC_CMD_TYPE_RTR_FRAME;
+		if (cfd->flags & CANFD_ESI)
+			fd_msg->flags |= CPC_FDFLAG_ESI;
 
-		msg->length = CPC_CAN_MSG_MIN_SIZE;
+		memcpy(fd_msg->msg, cfd->data, dlc);
+
+		msg->length = CPC_CANFD_MSG_MIN_SIZE + dlc;
+		/* Send only significant bytes of buffer */
+		buf_len += msg->length;
 	} else {
-		msg->type = cf->can_id & CAN_EFF_FLAG ?
-			CPC_CMD_TYPE_EXT_CAN_FRAME : CPC_CMD_TYPE_CAN_FRAME;
+		struct can_frame *cf = (struct can_frame *)skb->data;
+		struct cpc_can_msg *can_msg;
 
-		for (i = 0; i < cf->can_dlc; i++)
-			msg->msg.can_msg.msg[i] = cf->data[i];
+		buf_size = CPC_HEADER_SIZE +
+			   CPC_MSG_HEADER_LEN +
+			   sizeof(struct cpc_can_msg);
+
+		/* Create an URB and a buffer big enough for
+		 * all message lengths, copy the data to the URB
+		 */
+		urb = usb_alloc_urb(0, GFP_ATOMIC);
+		if (!urb)
+			goto nomem;
+
+		buf = usb_alloc_coherent(dev->udev,
+					 buf_size,
+					 GFP_ATOMIC,
+					 &urb->transfer_dma);
+		if (!buf) {
+			netdev_err(netdev, "No memory left for USB buffer\n");
+			usb_free_urb(urb);
+			goto nomem;
+		}
+		/* Clear first 4 bytes */
+		*(u32 *)buf = 0;
+
+		msg = (struct ems_cpc_msg *)&buf[CPC_HEADER_SIZE];
+		can_msg = &msg->msg.can_msg;
+
+		can_msg->id = cpu_to_le32(cf->can_id & CAN_ERR_MASK);
+		dlc = cf->can_dlc;
+		can_msg->length = dlc;
+
+		if (cf->can_id & CAN_RTR_FLAG) {
+			msg->type = cf->can_id & CAN_EFF_FLAG ?
+				CPC_CMD_TYPE_EXT_RTR_FRAME :
+				CPC_CMD_TYPE_RTR_FRAME;
+
+			msg->length = CPC_CAN_MSG_MIN_SIZE;
+		} else {
+			msg->type = cf->can_id & CAN_EFF_FLAG ?
+				CPC_CMD_TYPE_EXT_CAN_FRAME :
+				CPC_CMD_TYPE_CAN_FRAME;
+
+			for (i = 0; i < dlc; i++)
+				can_msg->msg[i] = cf->data[i];
+
+			msg->length = CPC_CAN_MSG_MIN_SIZE + dlc;
+		}
 
-		msg->length = CPC_CAN_MSG_MIN_SIZE + cf->can_dlc;
+		/* Send only significant bytes of buffer */
+		buf_len += msg->length;
 	}
 
 	for (i = 0; i < MAX_TX_URBS; i++) {
@@ -959,7 +1034,7 @@ static netdev_tx_t ems_usb_start_xmit(struct sk_buff *skb, struct net_device *ne
 	 * allowed (MAX_TX_URBS).
 	 */
 	if (!context) {
-		usb_free_coherent(dev->udev, size, buf, urb->transfer_dma);
+		usb_free_coherent(dev->udev, buf_size, buf, urb->transfer_dma);
 		usb_free_urb(urb);
 
 		netdev_warn(netdev, "couldn't find free context\n");
@@ -969,10 +1044,10 @@ static netdev_tx_t ems_usb_start_xmit(struct sk_buff *skb, struct net_device *ne
 
 	context->dev = dev;
 	context->echo_index = i;
-	context->dlc = cf->can_dlc;
+	context->dlc = dlc;
 
 	usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, 2), buf,
-			  size, ems_usb_write_bulk_callback, context);
+			  buf_len, ems_usb_write_bulk_callback, context);
 	urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
 	usb_anchor_urb(urb, &dev->tx_submitted);
 
@@ -985,7 +1060,7 @@ static netdev_tx_t ems_usb_start_xmit(struct sk_buff *skb, struct net_device *ne
 		can_free_echo_skb(netdev, context->echo_index);
 
 		usb_unanchor_urb(urb);
-		usb_free_coherent(dev->udev, size, buf, urb->transfer_dma);
+		usb_free_coherent(dev->udev, buf_size, buf, urb->transfer_dma);
 		dev_kfree_skb(skb);
 
 		atomic_dec(&dev->active_tx_urbs);
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 13/16] can: ems_usb: Made CAN error reporting CAN controller dependent
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
                   ` (11 preceding siblings ...)
  2020-11-12 18:03 ` [PATCH v2 12/16] can: ems_usb: Fixed ems_usb_start_xmit for CAN FD Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 14/16] can: ems_usb: Made structs packed Gerhard Uttenthaler
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

This patch ensures that errors reported by CPC-USB/ARM7 are handled correctly.

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 84 ++++++++++++++++++++---------------
 1 file changed, 48 insertions(+), 36 deletions(-)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 76d25ab5804b..693ef333ceab 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -57,8 +57,13 @@ MODULE_LICENSE("GPL v2");
 #define CPC_CMD_TYPE_CLEAR_MSG_QUEUE 8  /* clear CPC_MSG queue */
 #define CPC_CMD_TYPE_CLEAR_CMD_QUEUE 28 /* clear CPC_CMD queue */
 
-#define CPC_CC_TYPE_SJA1000 2 /* NXP CAN controller */
-#define CPC_CC_TYPE_GENERIC 6 /* GENERIC CAN controller */
+/* CPC-USB/ARM7 */
+#define CPC_CC_TYPE_SJA1000 2
+
+/* CPC-USB/FD
+ * Initialization is done with a generic CAN controller representation
+ */
+#define CPC_CC_TYPE_GENERIC 6
 
 #define CPC_CAN_ECODE_ERRFRAME 0x01 /* Ecode type */
 
@@ -440,6 +445,9 @@ static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg)
 	if (!skb)
 		return;
 
+	/* The CPC_MSG_TYPE_CAN_STATE works for both
+	 * CPC-USB/ARM7 and CPC-USB/FD
+	 */
 	if (msg->type == CPC_MSG_TYPE_CAN_STATE) {
 		u8 state = msg->msg.can_state;
 
@@ -457,40 +465,44 @@ static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg)
 			dev->can.can_stats.error_passive++;
 		}
 	} else if (msg->type == CPC_MSG_TYPE_CAN_FRAME_ERROR) {
-		u8 ecc = msg->msg.error.cc.regs.sja1000.ecc;
-		u8 txerr = msg->msg.error.cc.regs.sja1000.txerr;
-		u8 rxerr = msg->msg.error.cc.regs.sja1000.rxerr;
-
-		/* bus error interrupt */
-		dev->can.can_stats.bus_error++;
-		stats->rx_errors++;
-
-		cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
-
-		switch (ecc & SJA1000_ECC_MASK) {
-		case SJA1000_ECC_BIT:
-			cf->data[2] |= CAN_ERR_PROT_BIT;
-			break;
-		case SJA1000_ECC_FORM:
-			cf->data[2] |= CAN_ERR_PROT_FORM;
-			break;
-		case SJA1000_ECC_STUFF:
-			cf->data[2] |= CAN_ERR_PROT_STUFF;
-			break;
-		default:
-			cf->data[3] = ecc & SJA1000_ECC_SEG;
-			break;
-		}
-
-		/* Error occurred during transmission? */
-		if ((ecc & SJA1000_ECC_DIR) == 0)
-			cf->data[2] |= CAN_ERR_PROT_TX;
-
-		if (dev->can.state == CAN_STATE_ERROR_WARNING ||
-		    dev->can.state == CAN_STATE_ERROR_PASSIVE) {
-			cf->can_id |= CAN_ERR_CRTL;
-			cf->data[1] = (txerr > rxerr) ?
-			    CAN_ERR_CRTL_TX_PASSIVE : CAN_ERR_CRTL_RX_PASSIVE;
+		/* CPC-USB/ARM7 */
+		if (msg->msg.error.cc.cc_type == CPC_CC_TYPE_SJA1000) {
+			u8 ecc = msg->msg.error.cc.regs.sja1000.ecc;
+			u8 txerr = msg->msg.error.cc.regs.sja1000.txerr;
+			u8 rxerr = msg->msg.error.cc.regs.sja1000.rxerr;
+
+			/* bus error interrupt */
+			dev->can.can_stats.bus_error++;
+			stats->rx_errors++;
+
+			cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
+
+			switch (ecc & SJA1000_ECC_MASK) {
+			case SJA1000_ECC_BIT:
+				cf->data[2] |= CAN_ERR_PROT_BIT;
+				break;
+			case SJA1000_ECC_FORM:
+				cf->data[2] |= CAN_ERR_PROT_FORM;
+				break;
+			case SJA1000_ECC_STUFF:
+				cf->data[2] |= CAN_ERR_PROT_STUFF;
+				break;
+			default:
+				cf->data[3] = ecc & SJA1000_ECC_SEG;
+				break;
+			}
+
+			/* Error occurred during transmission? */
+			if ((ecc & SJA1000_ECC_DIR) == 0)
+				cf->data[2] |= CAN_ERR_PROT_TX;
+
+			if (dev->can.state == CAN_STATE_ERROR_WARNING ||
+			    dev->can.state == CAN_STATE_ERROR_PASSIVE) {
+				cf->can_id |= CAN_ERR_CRTL;
+				cf->data[1] = (txerr > rxerr) ?
+					       CAN_ERR_CRTL_TX_PASSIVE :
+					       CAN_ERR_CRTL_RX_PASSIVE;
+			}
 		}
 	} else if (msg->type == CPC_MSG_TYPE_OVERRUN) {
 		cf->can_id |= CAN_ERR_CRTL;
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 14/16] can: ems_usb: Made structs packed
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
                   ` (12 preceding siblings ...)
  2020-11-12 18:03 ` [PATCH v2 13/16] can: ems_usb: Made CAN error reporting CAN controller dependent Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 15/16] can: ems_usb: Added error reporting for CPC-USB/FD Gerhard Uttenthaler
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

Both devices expect everything from the host as packed

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 693ef333ceab..677ed4bc47b9 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -132,7 +132,7 @@ MODULE_LICENSE("GPL v2");
  * CPC_MSG_TYPE_CAN_FRAME or CPC_MSG_TYPE_RTR_FRAME or
  * CPC_MSG_TYPE_EXT_CAN_FRAME or CPC_MSG_TYPE_EXT_RTR_FRAME.
  */
-struct cpc_can_msg {
+struct __packed cpc_can_msg {
 	__le32 id;
 	u8 length;
 	u8 msg[8];
@@ -160,7 +160,7 @@ struct __packed cpc_canfd_msg {
 #define CPC_FDFLAG_XTD          BIT(7)
 
 /* Representation of the CAN parameters for the SJA1000 controller */
-struct cpc_sja1000_params {
+struct __packed cpc_sja1000_params {
 	u8 mode;
 	u8 acc_code0;
 	u8 acc_code1;
@@ -218,20 +218,20 @@ struct cpc_confirm {
 };
 
 /* Structure for overrun conditions */
-struct cpc_overrun {
+struct __packed cpc_overrun {
 	u8 event;
 	u8 count;
 };
 
 /* SJA1000 CAN errors (compatible to NXP LPC2119) */
-struct cpc_sja1000_can_error {
+struct __packed cpc_sja1000_can_error {
 	u8 ecc;
 	u8 rxerr;
 	u8 txerr;
 };
 
 /* structure for CAN error conditions */
-struct cpc_can_error {
+struct __packed cpc_can_error {
 	u8 ecode;
 
 	struct {
@@ -247,7 +247,7 @@ struct cpc_can_error {
 /* Structure containing RX/TX error counter. This structure is used to request
  * the values of the CAN controllers TX and RX error counter.
  */
-struct cpc_can_err_counter {
+struct __packed cpc_can_err_counter {
 	u8 rx;
 	u8 tx;
 };
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 15/16] can: ems_usb: Added error reporting for CPC-USB/FD
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
                   ` (13 preceding siblings ...)
  2020-11-12 18:03 ` [PATCH v2 14/16] can: ems_usb: Made structs packed Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-12 18:03 ` [PATCH v2 16/16] can: ems_usb: Enable CPC-USB/FD support Gerhard Uttenthaler
  2020-11-26 17:49 ` [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

Added struct and defines to handle errors reported from CPC-USB/FD
accordingly. Added needed code for that purpose

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 105 ++++++++++++++++++++++++++++++++++
 1 file changed, 105 insertions(+)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 677ed4bc47b9..b94364d8f390 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -62,7 +62,9 @@ MODULE_LICENSE("GPL v2");
 
 /* CPC-USB/FD
  * Initialization is done with a generic CAN controller representation
+ * However error reporting brings two registers of the used controller type
  */
+#define CPC_CC_TYPE_LPC546XX 5
 #define CPC_CC_TYPE_GENERIC 6
 
 #define CPC_CAN_ECODE_ERRFRAME 0x01 /* Ecode type */
@@ -108,6 +110,25 @@ MODULE_LICENSE("GPL v2");
 
 #define SJA1000_DEFAULT_OUTPUT_CONTROL 0xDA
 
+/* CPC-USB/FD PSR */
+#define CPCFD_LEC_MASK  0x07
+#define CPCFD_LEC_STUFF 0x01
+#define CPCFD_LEC_FORM  0x02
+#define CPCFD_LEC_ACK   0x03
+#define CPCFD_LEC_BIT1  0x04
+#define CPCFD_LEC_BIT0  0x05
+#define CPCFD_LEC_CRC   0x06
+
+#define CPCFD_ERR_EP BIT(5)
+#define CPCFD_ERR_EW BIT(6)
+#define CPCFD_ERR_BO BIT(7)
+
+#define CPCFD_ACT_MASK 0x18
+#define CPCFD_ACT_SYNC 0x00
+#define CPCFD_ACT_IDLE 0x08
+#define CPCFD_ACT_RX   0x10
+#define CPCFD_ACT_TX   0x18
+
 /* CPC-USB/ARM7 actually uses a 16MHz clock to generate the CAN clock
  * but it expects SJA1000 bit settings based on 8MHz (is internally
  * converted).
@@ -230,6 +251,11 @@ struct __packed cpc_sja1000_can_error {
 	u8 txerr;
 };
 
+struct __packed cpc_lpc546xx_can_error {
+	__le32 psr; /* protocol status register */
+	__le32 ecr; /* error counter register */
+};
+
 /* structure for CAN error conditions */
 struct __packed cpc_can_error {
 	u8 ecode;
@@ -240,6 +266,7 @@ struct __packed cpc_can_error {
 		/* Other controllers may also provide error code capture regs */
 		union {
 			struct cpc_sja1000_can_error sja1000;
+			struct cpc_lpc546xx_can_error lpc546xx;
 		} regs;
 	} cc;
 };
@@ -504,6 +531,84 @@ static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg)
 					       CAN_ERR_CRTL_RX_PASSIVE;
 			}
 		}
+		/* CPC-USB/FD */
+		else if (msg->msg.error.cc.cc_type == CPC_CC_TYPE_LPC546XX) {
+			struct net_device *netdev = dev->netdev;
+			u32 psr = le32_to_cpu(msg->msg.error.cc.regs.lpc546xx.psr);
+			u8 txerr = le32_to_cpu(msg->msg.error.cc.regs.lpc546xx.ecr);
+			u8 rxerr = le32_to_cpu(msg->msg.error.cc.regs.lpc546xx.ecr) >> 8;
+
+			/* bus error interrupt */
+			dev->can.can_stats.bus_error++;
+
+			cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
+
+			switch (psr & CPCFD_LEC_MASK) {
+			case CPCFD_LEC_STUFF:
+				netdev_dbg(netdev, "stuff error\n");
+				cf->data[2] |= CAN_ERR_PROT_STUFF;
+				break;
+			case CPCFD_LEC_FORM:
+				netdev_dbg(netdev, "form error\n");
+				cf->data[2] |= CAN_ERR_PROT_FORM;
+				break;
+			case CPCFD_LEC_ACK:
+				netdev_dbg(netdev, "ack error\n");
+				cf->data[3] = CAN_ERR_PROT_LOC_ACK;
+				break;
+			case CPCFD_LEC_BIT1:
+				netdev_dbg(netdev, "bit1 error\n");
+				cf->data[2] |= CAN_ERR_PROT_BIT1;
+				break;
+			case CPCFD_LEC_BIT0:
+				netdev_dbg(netdev, "bit0 error\n");
+				cf->data[2] |= CAN_ERR_PROT_BIT0;
+				break;
+			case CPCFD_LEC_CRC:
+				netdev_dbg(netdev, "CRC error\n");
+				cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ;
+				break;
+			default:
+				break;
+			}
+
+			/* Let activity flags decide direction */
+			switch (psr & CPCFD_ACT_MASK) {
+			case CPCFD_ACT_SYNC:
+				/* fallthrough */
+			case CPCFD_ACT_IDLE:
+				/* fallthrough */
+			case CPCFD_ACT_RX:
+				stats->rx_errors++;
+				break;
+			case CPCFD_ACT_TX:
+				stats->tx_errors++;
+				break;
+			}
+
+			/* Error warning status */
+			if (psr & CPCFD_ERR_EW) {
+				cf->data[1] = (txerr > rxerr) ?
+					CAN_ERR_CRTL_TX_WARNING :
+					CAN_ERR_CRTL_RX_WARNING;
+				cf->can_id |= CAN_ERR_CRTL;
+			}
+
+			/* Error passive status */
+			if (psr & CPCFD_ERR_EP) {
+				cf->data[1] |= (txerr > rxerr) ?
+					CAN_ERR_CRTL_TX_PASSIVE :
+					CAN_ERR_CRTL_RX_PASSIVE;
+				cf->can_id |= CAN_ERR_CRTL;
+			}
+
+			/* Error bus off status */
+			if (psr & CPCFD_ERR_BO)
+				cf->can_id |= CAN_ERR_BUSOFF;
+
+			cf->data[6] = txerr;
+			cf->data[7] = rxerr;
+		}
 	} else if (msg->type == CPC_MSG_TYPE_OVERRUN) {
 		cf->can_id |= CAN_ERR_CRTL;
 		cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 16/16] can: ems_usb: Enable CPC-USB/FD support
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
                   ` (14 preceding siblings ...)
  2020-11-12 18:03 ` [PATCH v2 15/16] can: ems_usb: Added error reporting for CPC-USB/FD Gerhard Uttenthaler
@ 2020-11-12 18:03 ` Gerhard Uttenthaler
  2020-11-26 17:49 ` [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-12 18:03 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, Gerhard Uttenthaler

By adding the device product id to the device table CPC-USB/FD is 
supported

Signed-off-by: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
---
 drivers/net/can/usb/ems_usb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index b94364d8f390..36faec167cbb 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -301,10 +301,11 @@ struct __packed ems_cpc_msg {
 };
 
 /* Table of devices that work with this driver
- * NOTE: This driver supports only CPC-USB/ARM7 (LPC2119) yet.
+ * This driver supports CPC-USB/ARM7 and CPC-USB/FD
  */
 static struct usb_device_id ems_usb_table[] = {
 	{USB_DEVICE(USB_CPCUSB_VENDOR_ID, USB_CPCUSB_ARM7_PRODUCT_ID)},
+	{USB_DEVICE(USB_CPCUSB_VENDOR_ID, USB_CPCUSB_FD_PRODUCT_ID)},
 	{} /* Terminating entry */
 };
 
-- 
2.26.2

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface
  2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
                   ` (15 preceding siblings ...)
  2020-11-12 18:03 ` [PATCH v2 16/16] can: ems_usb: Enable CPC-USB/FD support Gerhard Uttenthaler
@ 2020-11-26 17:49 ` Gerhard Uttenthaler
  16 siblings, 0 replies; 18+ messages in thread
From: Gerhard Uttenthaler @ 2020-11-26 17:49 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl

Kind Ping...

Regards
Gerhard

Am 12.11.20 um 19:03 schrieb Gerhard Uttenthaler:
> These patches extend the ems_usb.c driver to support both devices, the
> classic CAN CPC-USB/ARM7 and the CAN FD CPC-USB/FD. After fixing issues given
> by checkpatch.pl and adding the CPC_ClearCmdQueue function all needed parts
> to support CAN FD were added step by step. Also added is support for the
> listen only mode for CPC-USB/ARM7 now.
> The last patch enables the driver for CPC-USB/FD.
> 
> Gerhard Uttenthaler (16):
>   can: ems_usb: Fixed warnings and comments
>   can: ems_usb: Added CPC_ClearCmdQueue routine.
>   can: ems_usb: Fixed non C99 style initialization
>   can: ems_usb: Added CAN FD message representation
>   can: ems_usb: Added CAN FD initialization struct
>   can: ems_usb: Made RX_BUFFER_SIZE, ems_usb_write_mode and
>     ems_usb_probe device dependent
>   can: ems_usb: Added listen only mode for CPC-USB/ARM7
>   can: ems_usb: Modified ems_usb_read_bulk_callback to handle also
>     CPC-USB/FD
>   can: ems_usb: Added CAN controller initialization for CAN FD
>   can: ems_usb: Added receive routine for CAN FD messages
>   can: ems_usb: Added ems_usb_write_mode_fd
>   can: ems_usb: Fixed ems_usb_start_xmit for CAN FD
>   can: ems_usb: Made CAN error reporting CAN controller dependent
>   can: ems_usb: Made structs packed
>   can: ems_usb: Added error reporting for CPC-USB/FD
>   can: ems_usb: Enable CPC-USB/FD support
> 
>  drivers/net/can/usb/ems_usb.c | 858 +++++++++++++++++++++++++++-------
>  1 file changed, 682 insertions(+), 176 deletions(-)
> 

-- 
Mit freundlichen Gruessen / Best Regards
Gerhard Uttenthaler

-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HR Ingolstadt, HRA 170106

Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2020-11-26 17:49 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-12 18:03 [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 01/16] can: ems_usb: Fixed warnings and comments Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 02/16] can: ems_usb: Added CPC_ClearCmdQueue routine Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 03/16] can: ems_usb: Fixed non C99 style initialization Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 04/16] can: ems_usb: Added CAN FD message representation Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 05/16] can: ems_usb: Added CAN FD initialization struct Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 06/16] can: ems_usb: Made RX_BUFFER_SIZE, ems_usb_write_mode and ems_usb_probe device dependent Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 07/16] can: ems_usb: Added listen only mode for CPC-USB/ARM7 Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 08/16] can: ems_usb: Modified ems_usb_read_bulk_callback to handle also CPC-USB/FD Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 09/16] can: ems_usb: Added CAN controller initialization for CAN FD Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 10/16] can: ems_usb: Added receive routine for CAN FD messages Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 11/16] can: ems_usb: Added ems_usb_write_mode_fd Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 12/16] can: ems_usb: Fixed ems_usb_start_xmit for CAN FD Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 13/16] can: ems_usb: Made CAN error reporting CAN controller dependent Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 14/16] can: ems_usb: Made structs packed Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 15/16] can: ems_usb: Added error reporting for CPC-USB/FD Gerhard Uttenthaler
2020-11-12 18:03 ` [PATCH v2 16/16] can: ems_usb: Enable CPC-USB/FD support Gerhard Uttenthaler
2020-11-26 17:49 ` [PATCH v2 00/16] Add support for CPC-USB/FD CAN FD interface Gerhard Uttenthaler

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.