All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] can: kvaser_usb: add retries/timeout to kvaser_usb_wait_msg()
@ 2014-04-10 19:44 Olivier Sobrie
  2014-04-10 19:44 ` [PATCH 2/3] can: kvaser_usb: add support for Kvaser Leaf v2 and usb mini PCIe Olivier Sobrie
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Olivier Sobrie @ 2014-04-10 19:44 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-can, Olivier Sobrie

On some Kvaser hardware, the firmware returns extra messages after the
request for card info. For instance on a Leaf Light v2:
  --> CMD_GET_CARD_INFO
  <-- CMD_USB_THROTTLE
  <-- CMD_GET_CARD_INFO2
  <-- CMD_GET_CARD_INFO_REQ
When it happens, the probing function fails because we only read
the first usb message.

To overcome this issue, we add a mechanism of retries to the
kvaser_usb_wait_msg() function.

I tested this patch with the following hardware:
 - Kvaser Leaf Light
 - Kvaser Leaf Light v2
 - Kvaser USBCan R

This patch is necessary for the Leaf Light v2 hardware.

Signed-off-by: Olivier Sobrie <olivier@sobrie.be>
---
 drivers/net/can/usb/kvaser_usb.c | 49 ++++++++++++++++++++++------------------
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index cc3df8a..cd5ec5b 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -380,38 +380,43 @@ static int kvaser_usb_wait_msg(const struct kvaser_usb *dev, u8 id,
 	void *buf;
 	int actual_len;
 	int err;
-	int pos = 0;
+	int pos;
+	unsigned long to = jiffies + msecs_to_jiffies(USB_RECV_TIMEOUT);
 
 	buf = kzalloc(RX_BUFFER_SIZE, GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;
 
-	err = usb_bulk_msg(dev->udev,
-			   usb_rcvbulkpipe(dev->udev,
-					   dev->bulk_in->bEndpointAddress),
-			   buf, RX_BUFFER_SIZE, &actual_len,
-			   USB_RECV_TIMEOUT);
-	if (err < 0)
-		goto end;
+	do {
+		err = usb_bulk_msg(dev->udev,
+				   usb_rcvbulkpipe(dev->udev,
+					dev->bulk_in->bEndpointAddress),
+				   buf, RX_BUFFER_SIZE, &actual_len,
+				   USB_RECV_TIMEOUT);
+		if (err < 0)
+			goto end;
 
-	while (pos <= actual_len - MSG_HEADER_LEN) {
-		tmp = buf + pos;
+		pos = 0;
+		while (pos <= actual_len - MSG_HEADER_LEN) {
+			tmp = buf + pos;
 
-		if (!tmp->len)
-			break;
+			if (!tmp->len)
+				break;
 
-		if (pos + tmp->len > actual_len) {
-			dev_err(dev->udev->dev.parent, "Format error\n");
-			break;
-		}
+			if (pos + tmp->len > actual_len) {
+				dev_err(dev->udev->dev.parent,
+					"Format error\n");
+				break;
+			}
 
-		if (tmp->id == id) {
-			memcpy(msg, tmp, tmp->len);
-			goto end;
-		}
+			if (tmp->id == id) {
+				memcpy(msg, tmp, tmp->len);
+				goto end;
+			}
 
-		pos += tmp->len;
-	}
+			pos += tmp->len;
+		}
+	} while (time_before(jiffies, to));
 
 	err = -EINVAL;
 
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] can: kvaser_usb: add support for Kvaser Leaf v2 and usb mini PCIe
  2014-04-10 19:44 [PATCH 1/3] can: kvaser_usb: add retries/timeout to kvaser_usb_wait_msg() Olivier Sobrie
@ 2014-04-10 19:44 ` Olivier Sobrie
  2014-04-10 19:44 ` [PATCH 3/3] can: usb: Kconfig: Improve help for CAN_KVASER_USB Olivier Sobrie
  2014-04-17 20:19 ` [PATCH 1/3] can: kvaser_usb: add retries/timeout to kvaser_usb_wait_msg() Marc Kleine-Budde
  2 siblings, 0 replies; 4+ messages in thread
From: Olivier Sobrie @ 2014-04-10 19:44 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-can, Olivier Sobrie

This patch adds support for the Kvaser Leaf v2 and Leaf usb mini
PCIe card.

Signed-off-by: Olivier Sobrie <olivier@sobrie.be>
---
 drivers/net/can/usb/kvaser_usb.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index cd5ec5b..d2826e8 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -54,6 +54,8 @@
 #define USB_OEM_MERCURY_PRODUCT_ID	34
 #define USB_OEM_LEAF_PRODUCT_ID		35
 #define USB_CAN_R_PRODUCT_ID		39
+#define USB_LEAF_LITE_V2_PRODUCT_ID	288
+#define USB_MINI_PCIE_HS_PRODUCT_ID	289
 
 /* USB devices features */
 #define KVASER_HAS_SILENT_MODE		BIT(0)
@@ -357,6 +359,8 @@ static const struct usb_device_id kvaser_usb_table[] = {
 		.driver_info = KVASER_HAS_TXRX_ERRORS },
 	{ USB_DEVICE(KVASER_VENDOR_ID, USB_CAN_R_PRODUCT_ID),
 		.driver_info = KVASER_HAS_TXRX_ERRORS },
+	{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_LITE_V2_PRODUCT_ID) },
+	{ USB_DEVICE(KVASER_VENDOR_ID, USB_MINI_PCIE_HS_PRODUCT_ID) },
 	{ }
 };
 MODULE_DEVICE_TABLE(usb, kvaser_usb_table);
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] can: usb: Kconfig: Improve help for CAN_KVASER_USB
  2014-04-10 19:44 [PATCH 1/3] can: kvaser_usb: add retries/timeout to kvaser_usb_wait_msg() Olivier Sobrie
  2014-04-10 19:44 ` [PATCH 2/3] can: kvaser_usb: add support for Kvaser Leaf v2 and usb mini PCIe Olivier Sobrie
@ 2014-04-10 19:44 ` Olivier Sobrie
  2014-04-17 20:19 ` [PATCH 1/3] can: kvaser_usb: add retries/timeout to kvaser_usb_wait_msg() Marc Kleine-Budde
  2 siblings, 0 replies; 4+ messages in thread
From: Olivier Sobrie @ 2014-04-10 19:44 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-can, Olivier Sobrie

Add two new USB devices supported by the driver and fix bad
english.

Signed-off-by: Olivier Sobrie <olivier@sobrie.be>
---
 drivers/net/can/usb/Kconfig | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/Kconfig b/drivers/net/can/usb/Kconfig
index fc96a3d..0b918eb 100644
--- a/drivers/net/can/usb/Kconfig
+++ b/drivers/net/can/usb/Kconfig
@@ -19,7 +19,7 @@ config CAN_KVASER_USB
 	  This driver adds support for Kvaser CAN/USB devices like Kvaser
 	  Leaf Light.
 
-	  The driver gives support for the following devices:
+	  The driver provides support for the following devices:
 	    - Kvaser Leaf Light
 	    - Kvaser Leaf Professional HS
 	    - Kvaser Leaf SemiPro HS
@@ -36,6 +36,8 @@ config CAN_KVASER_USB
 	    - Kvaser Leaf Light "China"
 	    - Kvaser BlackBird SemiPro
 	    - Kvaser USBcan R
+	    - Kvaser Leaf Light v2
+	    - Kvaser Mini PCI Express HS
 
 	  If unsure, say N.
 
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] can: kvaser_usb: add retries/timeout to kvaser_usb_wait_msg()
  2014-04-10 19:44 [PATCH 1/3] can: kvaser_usb: add retries/timeout to kvaser_usb_wait_msg() Olivier Sobrie
  2014-04-10 19:44 ` [PATCH 2/3] can: kvaser_usb: add support for Kvaser Leaf v2 and usb mini PCIe Olivier Sobrie
  2014-04-10 19:44 ` [PATCH 3/3] can: usb: Kconfig: Improve help for CAN_KVASER_USB Olivier Sobrie
@ 2014-04-17 20:19 ` Marc Kleine-Budde
  2 siblings, 0 replies; 4+ messages in thread
From: Marc Kleine-Budde @ 2014-04-17 20:19 UTC (permalink / raw)
  To: Olivier Sobrie; +Cc: linux-can

[-- Attachment #1: Type: text/plain, Size: 1068 bytes --]

On 04/10/2014 09:44 PM, Olivier Sobrie wrote:
> On some Kvaser hardware, the firmware returns extra messages after the
> request for card info. For instance on a Leaf Light v2:
>   --> CMD_GET_CARD_INFO
>   <-- CMD_USB_THROTTLE
>   <-- CMD_GET_CARD_INFO2
>   <-- CMD_GET_CARD_INFO_REQ
> When it happens, the probing function fails because we only read
> the first usb message.
> 
> To overcome this issue, we add a mechanism of retries to the
> kvaser_usb_wait_msg() function.
> 
> I tested this patch with the following hardware:
>  - Kvaser Leaf Light
>  - Kvaser Leaf Light v2
>  - Kvaser USBCan R
> 
> This patch is necessary for the Leaf Light v2 hardware.
> 
> Signed-off-by: Olivier Sobrie <olivier@sobrie.be>

Applied all 3 to net-next/master

Thanks,
Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 242 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-04-17 20:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-10 19:44 [PATCH 1/3] can: kvaser_usb: add retries/timeout to kvaser_usb_wait_msg() Olivier Sobrie
2014-04-10 19:44 ` [PATCH 2/3] can: kvaser_usb: add support for Kvaser Leaf v2 and usb mini PCIe Olivier Sobrie
2014-04-10 19:44 ` [PATCH 3/3] can: usb: Kconfig: Improve help for CAN_KVASER_USB Olivier Sobrie
2014-04-17 20:19 ` [PATCH 1/3] can: kvaser_usb: add retries/timeout to kvaser_usb_wait_msg() Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.