[PATCH v2 02/16] can: ems_usb: Added CPC_ClearCmdQueue routine.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxx>
---
 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



[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux