Skip to content

Commit 9c8090e

Browse files
Ahmed S. Darwishsashalevin
authored andcommitted
can: kvaser_usb: Read all messages in a bulk-in URB buffer
[ Upstream commit 2fec510 ] 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> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
1 parent 9baee04 commit 9c8090e

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
@@ -12,6 +12,7 @@
1212
* Copyright (C) 2012 Olivier Sobrie <olivier@sobrie.be>
1313
*/
1414

15+
#include <linux/kernel.h>
1516
#include <linux/completion.h>
1617
#include <linux/module.h>
1718
#include <linux/netdevice.h>
@@ -403,8 +404,15 @@ static int kvaser_usb_wait_msg(const struct kvaser_usb *dev, u8 id,
403404
while (pos <= actual_len - MSG_HEADER_LEN) {
404405
tmp = buf + pos;
405406

406-
if (!tmp->len)
407-
break;
407+
/* Handle messages crossing the USB endpoint max packet
408+
* size boundary. Check kvaser_usb_read_bulk_callback()
409+
* for further details.
410+
*/
411+
if (tmp->len == 0) {
412+
pos = round_up(pos,
413+
dev->bulk_in->wMaxPacketSize);
414+
continue;
415+
}
408416

409417
if (pos + tmp->len > actual_len) {
410418
dev_err(dev->udev->dev.parent,
@@ -983,16 +991,26 @@ static void kvaser_usb_read_bulk_callback(struct urb *urb)
983991
while (pos <= urb->actual_length - MSG_HEADER_LEN) {
984992
msg = urb->transfer_buffer + pos;
985993

986-
if (!msg->len)
987-
break;
994+
/* The Kvaser firmware can only read and write messages that
995+
* does not cross the USB's endpoint wMaxPacketSize boundary.
996+
* If a follow-up command crosses such boundary, firmware puts
997+
* a placeholder zero-length command in its place then aligns
998+
* the real command to the next max packet size.
999+
*
1000+
* Handle such cases or we're going to miss a significant
1001+
* number of events in case of a heavy rx load on the bus.
1002+
*/
1003+
if (msg->len == 0) {
1004+
pos = round_up(pos, dev->bulk_in->wMaxPacketSize);
1005+
continue;
1006+
}
9881007

9891008
if (pos + msg->len > urb->actual_length) {
9901009
dev_err(dev->udev->dev.parent, "Format error\n");
9911010
break;
9921011
}
9931012

9941013
kvaser_usb_handle_message(dev, msg);
995-
9961014
pos += msg->len;
9971015
}
9981016

0 commit comments

Comments
 (0)