linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
To: linux-can@vger.kernel.org
Cc: wg@grandegger.com, mkl@pengutronix.de,
	Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
Subject: [PATCH v2 02/16] can: ems_usb: Added CPC_ClearCmdQueue routine.
Date: Thu, 12 Nov 2020 19:03:32 +0100	[thread overview]
Message-ID: <20201112180346.29070-3-uttenthaler@ems-wuensche.com> (raw)
In-Reply-To: <20201112180346.29070-1-uttenthaler@ems-wuensche.com>

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

  parent reply	other threads:[~2020-11-12 18:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201112180346.29070-3-uttenthaler@ems-wuensche.com \
    --to=uttenthaler@ems-wuensche.com \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=wg@grandegger.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).