Skip to content

Commit 2fec510

Browse files
Ahmed S. Darwishmarckleinebudde
authored andcommitted
can: kvaser_usb: Read all messages in a bulk-in URB buffer
The Kvaser firmware can only read and write messages that are not crossing the USB endpoint's wMaxPacketSize boundary. While receiving commands from the CAN device, if the next command in the same URB buffer crossed that max packet size boundary, the firmware puts a zero-length placeholder command in its place then moves the real command to the next boundary mark. The driver did not recognize such behavior, leading to missing a good number of rx events during a heavy rx load session. Moreover, a tx URB context only gets freed upon receiving its respective tx ACK event. Over time, the free tx URB contexts pool gets depleted due to the missing ACK events. Consequently, the netif transmission queue gets __permanently__ stopped; no frames could be sent again except after restarting the CAN newtwork interface. Signed-off-by: Ahmed S. Darwish <ahmed.darwish@valeo.com> Cc: linux-stable <stable@vger.kernel.org> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent deb2701 commit 2fec510

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

‎drivers/net/can/usb/kvaser_usb.c‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* Copyright (C) 2015 Valeo S.A.
1515
*/
1616

17+
#include <linux/kernel.h>
1718
#include <linux/completion.h>
1819
#include <linux/module.h>
1920
#include <linux/netdevice.h>
@@ -584,8 +585,15 @@ static int kvaser_usb_wait_msg(const struct kvaser_usb *dev, u8 id,
584585
while (pos <= actual_len - MSG_HEADER_LEN) {
585586
tmp = buf + pos;
586587

587-
if (!tmp->len)
588-
break;
588+
/* Handle messages crossing the USB endpoint max packet
589+
* size boundary. Check kvaser_usb_read_bulk_callback()
590+
* for further details.
591+
*/
592+
if (tmp->len == 0) {
593+
pos = round_up(pos,
594+
dev->bulk_in->wMaxPacketSize);
595+
continue;
596+
}
589597

590598
if (pos + tmp->len > actual_len) {
591599
dev_err(dev->udev->dev.parent,
@@ -1316,16 +1324,26 @@ static void kvaser_usb_read_bulk_callback(struct urb *urb)
13161324
while (pos <= urb->actual_length - MSG_HEADER_LEN) {
13171325
msg = urb->transfer_buffer + pos;
13181326

1319-
if (!msg->len)
1320-
break;
1327+
/* The Kvaser firmware can only read and write messages that
1328+
* does not cross the USB's endpoint wMaxPacketSize boundary.
1329+
* If a follow-up command crosses such boundary, firmware puts
1330+
* a placeholder zero-length command in its place then aligns
1331+
* the real command to the next max packet size.
1332+
*
1333+
* Handle such cases or we're going to miss a significant
1334+
* number of events in case of a heavy rx load on the bus.
1335+
*/
1336+
if (msg->len == 0) {
1337+
pos = round_up(pos, dev->bulk_in->wMaxPacketSize);
1338+
continue;
1339+
}
13211340

13221341
if (pos + msg->len > urb->actual_length) {
13231342
dev_err(dev->udev->dev.parent, "Format error\n");
13241343
break;
13251344
}
13261345

13271346
kvaser_usb_handle_message(dev, msg);
1328-
13291347
pos += msg->len;
13301348
}
13311349

0 commit comments

Comments
 (0)