aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/can/usb/kvaser_usb.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/can/usb/kvaser_usb.c')
-rw-r--r--drivers/net/can/usb/kvaser_usb.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index d986fe83c40d..a316fa4b91ab 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -14,6 +14,7 @@
14 * Copyright (C) 2015 Valeo S.A. 14 * Copyright (C) 2015 Valeo S.A.
15 */ 15 */
16 16
17#include <linux/kernel.h>
17#include <linux/completion.h> 18#include <linux/completion.h>
18#include <linux/module.h> 19#include <linux/module.h>
19#include <linux/netdevice.h> 20#include <linux/netdevice.h>
@@ -584,8 +585,15 @@ static int kvaser_usb_wait_msg(const struct kvaser_usb *dev, u8 id,
584 while (pos <= actual_len - MSG_HEADER_LEN) { 585 while (pos <= actual_len - MSG_HEADER_LEN) {
585 tmp = buf + pos; 586 tmp = buf + pos;
586 587
587 if (!tmp->len) 588 /* Handle messages crossing the USB endpoint max packet
588 break; 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 }
589 597
590 if (pos + tmp->len > actual_len) { 598 if (pos + tmp->len > actual_len) {
591 dev_err(dev->udev->dev.parent, 599 dev_err(dev->udev->dev.parent,
@@ -1316,8 +1324,19 @@ static void kvaser_usb_read_bulk_callback(struct urb *urb)
1316 while (pos <= urb->actual_length - MSG_HEADER_LEN) { 1324 while (pos <= urb->actual_length - MSG_HEADER_LEN) {
1317 msg = urb->transfer_buffer + pos; 1325 msg = urb->transfer_buffer + pos;
1318 1326
1319 if (!msg->len) 1327 /* The Kvaser firmware can only read and write messages that
1320 break; 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 }
1321 1340
1322 if (pos + msg->len > urb->actual_length) { 1341 if (pos + msg->len > urb->actual_length) {
1323 dev_err(dev->udev->dev.parent, "Format error\n"); 1342 dev_err(dev->udev->dev.parent, "Format error\n");
@@ -1325,7 +1344,6 @@ static void kvaser_usb_read_bulk_callback(struct urb *urb)
1325 } 1344 }
1326 1345
1327 kvaser_usb_handle_message(dev, msg); 1346 kvaser_usb_handle_message(dev, msg);
1328
1329 pos += msg->len; 1347 pos += msg->len;
1330 } 1348 }
1331 1349