All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: [PATCH] Long USB transfers problem
Date: Sun, 24 Feb 2013 20:09:46 +0100	[thread overview]
Message-ID: <512A657A.5020307@gmail.com> (raw)
In-Reply-To: <1360624408.2624.88.camel@pracovna>


[-- Attachment #1.1: Type: text/plain, Size: 27 bytes --]

Please try attached patch

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: usb_packet.diff --]
[-- Type: text/x-diff; name="usb_packet.diff", Size: 8127 bytes --]

=== modified file 'grub-core/bus/usb/serial/ftdi.c'
--- grub-core/bus/usb/serial/ftdi.c	2013-02-01 20:49:29 +0000
+++ grub-core/bus/usb/serial/ftdi.c	2013-02-24 18:58:04 +0000
@@ -128,7 +128,7 @@
 
   real_config (port);
 
-  grub_usb_bulk_write (port->usbdev, port->out_endp->endp_addr, 1, &cc);
+  grub_usb_bulk_write (port->usbdev, port->out_endp, 1, &cc);
 }
 
 static grub_err_t

=== modified file 'grub-core/bus/usb/serial/pl2303.c'
--- grub-core/bus/usb/serial/pl2303.c	2013-02-01 20:49:29 +0000
+++ grub-core/bus/usb/serial/pl2303.c	2013-02-24 18:57:48 +0000
@@ -146,7 +146,7 @@
 
   real_config (port);
 
-  grub_usb_bulk_write (port->usbdev, port->out_endp->endp_addr, 1, &cc);
+  grub_usb_bulk_write (port->usbdev, port->out_endp, 1, &cc);
 }
 
 static grub_err_t

=== modified file 'grub-core/bus/usb/serial/usbdebug_late.c'
--- grub-core/bus/usb/serial/usbdebug_late.c	2013-02-01 20:49:29 +0000
+++ grub-core/bus/usb/serial/usbdebug_late.c	2013-02-24 18:57:54 +0000
@@ -41,7 +41,7 @@
 {
   char cc = c;
 
-  grub_usb_bulk_write (port->usbdev, port->out_endp->endp_addr, 1, &cc);
+  grub_usb_bulk_write (port->usbdev, port->out_endp, 1, &cc);
 }
 
 static grub_err_t

=== modified file 'grub-core/bus/usb/usbtrans.c'
--- grub-core/bus/usb/usbtrans.c	2013-01-20 21:45:53 +0000
+++ grub-core/bus/usb/usbtrans.c	2013-02-24 18:57:19 +0000
@@ -333,38 +333,27 @@
   return err;
 }
 
-grub_usb_err_t
-grub_usb_bulk_write (grub_usb_device_t dev,
-		     int endpoint, grub_size_t size, char *data)
-{
-  grub_size_t actual;
-  grub_usb_err_t err;
-
-  err = grub_usb_bulk_readwrite (dev, endpoint, size, data,
-				 GRUB_USB_TRANSFER_TYPE_OUT, 1000, &actual);
-  if (!err && actual != size)
-    err = GRUB_USB_ERR_DATA;
-  return err;
-}
-
-grub_usb_err_t
-grub_usb_bulk_read (grub_usb_device_t dev,
-		    int endpoint, grub_size_t size, char *data)
+static grub_usb_err_t
+grub_usb_bulk_readwrite_packetize (grub_usb_device_t dev,
+				   struct grub_usb_desc_endp *endpoint,
+				   grub_transfer_type_t type,
+				   grub_size_t size, char *data)
 {
   grub_size_t actual, transferred;
   grub_usb_err_t err;
   grub_size_t current_size, position;
+  grub_size_t max_packet = endpoint->maxpacket;
 
   for (position = 0, transferred = 0;
-       position < size; position += MAX_USB_TRANSFER_LEN)
+       position < size; position += max_packet)
     {
       current_size = size - position;
-      if (current_size >= MAX_USB_TRANSFER_LEN)
-	current_size = MAX_USB_TRANSFER_LEN;
-      err = grub_usb_bulk_readwrite (dev, endpoint, current_size,
-              &data[position], GRUB_USB_TRANSFER_TYPE_IN, 1000, &actual);
+      if (current_size >= max_packet)
+	current_size = max_packet;
+      err = grub_usb_bulk_readwrite (dev, endpoint->endp_addr, current_size,
+              &data[position], type, 1000, &actual);
       transferred += actual;
-      if (err || (current_size != actual) ) break;
+      if (err || (current_size != actual)) break;
     }
 
   if (!err && transferred != size)
@@ -373,6 +362,26 @@
 }
 
 grub_usb_err_t
+grub_usb_bulk_read (grub_usb_device_t dev,
+		    struct grub_usb_desc_endp *endpoint,
+		    grub_size_t size, char *data)
+{
+  return grub_usb_bulk_readwrite_packetize (dev, endpoint,
+					    GRUB_USB_TRANSFER_TYPE_IN,
+					    size, data);
+}
+
+grub_usb_err_t
+grub_usb_bulk_write (grub_usb_device_t dev,
+		     struct grub_usb_desc_endp *endpoint,
+		     grub_size_t size, char *data)
+{
+  return grub_usb_bulk_readwrite_packetize (dev, endpoint,
+					    GRUB_USB_TRANSFER_TYPE_OUT,
+					    size, data);
+}
+
+grub_usb_err_t
 grub_usb_check_transfer (grub_usb_transfer_t transfer, grub_size_t *actual)
 {
   grub_usb_err_t err;

=== modified file 'grub-core/disk/usbms.c'
--- grub-core/disk/usbms.c	2013-01-20 15:52:15 +0000
+++ grub-core/disk/usbms.c	2013-02-24 18:56:43 +0000
@@ -326,7 +326,7 @@
 
   /* Write the request.
    * XXX: Error recovery is maybe still not fully correct. */
-  err = grub_usb_bulk_write (dev->dev, dev->out->endp_addr,
+  err = grub_usb_bulk_write (dev->dev, dev->out,
 			     sizeof (cbw), (char *) &cbw);
   if (err)
     {
@@ -341,7 +341,7 @@
   /* Read/write the data, (maybe) according to specification.  */
   if (size && (read_write == 0))
     {
-      err = grub_usb_bulk_read (dev->dev, dev->in->endp_addr, size, buf);
+      err = grub_usb_bulk_read (dev->dev, dev->in, size, buf);
       grub_dprintf ("usb", "read: %d %d\n", err, GRUB_USB_ERR_STALL); 
       if (err)
         {
@@ -362,7 +362,7 @@
     }
   else if (size)
     {
-      err = grub_usb_bulk_write (dev->dev, dev->out->endp_addr, size, buf);
+      err = grub_usb_bulk_write (dev->dev, dev->out, size, buf);
       grub_dprintf ("usb", "write: %d %d\n", err, GRUB_USB_ERR_STALL);
       grub_dprintf ("usb", "First 16 bytes of sent data:\n %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
   	buf[ 0], buf[ 1], buf[ 2], buf[ 3],
@@ -388,12 +388,12 @@
 
   /* Read the status - (maybe) according to specification.  */
 CheckCSW:
-  errCSW = grub_usb_bulk_read (dev->dev, dev->in->endp_addr,
+  errCSW = grub_usb_bulk_read (dev->dev, dev->in,
 		    sizeof (status), (char *) &status);
   if (errCSW)
     {
       grub_usb_clear_halt (dev->dev, dev->in->endp_addr);
-      errCSW = grub_usb_bulk_read (dev->dev, dev->in->endp_addr,
+      errCSW = grub_usb_bulk_read (dev->dev, dev->in,
 			        sizeof (status), (char *) &status);
       if (errCSW)
         { /* Bulk-only reset device. */
@@ -476,7 +476,7 @@
       else if (dev->protocol == GRUB_USBMS_PROTOCOL_CBI)
         {
           /* Try to get status from interrupt pipe */
-          err = grub_usb_bulk_read (dev->dev, dev->intrpt->endp_addr,
+          err = grub_usb_bulk_read (dev->dev, dev->intrpt,
                                     2, (char*)&status);
           grub_dprintf ("usb", "CBI cmdcb setup status: err=%d, status=0x%x\n", err, status);
         }
@@ -487,7 +487,7 @@
   /* Read/write the data, (maybe) according to specification.  */
   if (size && (read_write == 0))
     {
-      err = grub_usb_bulk_read (dev->dev, dev->in->endp_addr, size, buf);
+      err = grub_usb_bulk_read (dev->dev, dev->in, size, buf);
       grub_dprintf ("usb", "read: %d\n", err); 
       if (err)
         {
@@ -498,7 +498,7 @@
     }
   else if (size)
     {
-      err = grub_usb_bulk_write (dev->dev, dev->out->endp_addr, size, buf);
+      err = grub_usb_bulk_write (dev->dev, dev->out, size, buf);
       grub_dprintf ("usb", "write: %d\n", err);
       if (err)
         {
@@ -517,7 +517,7 @@
    * (we do not it yet) - ? */
   if (dev->protocol == GRUB_USBMS_PROTOCOL_CBI)
     { /* Check status in interrupt pipe */
-      err = grub_usb_bulk_read (dev->dev, dev->intrpt->endp_addr,
+      err = grub_usb_bulk_read (dev->dev, dev->intrpt,
                                 2, (char*)&status);
       grub_dprintf ("usb", "read status: %d\n", err);
       if (err)

=== modified file 'include/grub/usb.h'
--- include/grub/usb.h	2013-01-21 21:02:24 +0000
+++ include/grub/usb.h	2013-02-24 18:47:19 +0000
@@ -87,10 +87,12 @@
 
 grub_usb_err_t
 grub_usb_bulk_read (grub_usb_device_t dev,
-		    int endpoint, grub_size_t size, char *data);
+		    struct grub_usb_desc_endp *endpoint,
+		    grub_size_t size, char *data);
 grub_usb_err_t
 grub_usb_bulk_write (grub_usb_device_t dev,
-		     int endpoint, grub_size_t size, char *data);
+		     struct grub_usb_desc_endp *endpoint,
+		     grub_size_t size, char *data);
 
 grub_usb_err_t
 grub_usb_root_hub (grub_usb_controller_t controller);

=== modified file 'include/grub/usbtrans.h'
--- include/grub/usbtrans.h	2013-01-20 21:45:53 +0000
+++ include/grub/usbtrans.h	2013-02-24 18:48:55 +0000
@@ -19,8 +19,6 @@
 #ifndef	GRUB_USBTRANS_H
 #define	GRUB_USBTRANS_H	1
 
-#define MAX_USB_TRANSFER_LEN 0x0800
-
 typedef enum
   {
     GRUB_USB_TRANSFER_TYPE_IN,


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

  parent reply	other threads:[~2013-02-24 19:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-01 22:46 [PATCH] Long USB transfers problem Aleš Nesrsta
2012-12-10 10:57 ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-12-10 17:49   ` Aleš Nesrsta
2012-12-10 20:33     ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-12-11 20:40       ` Aleš Nesrsta
2013-01-20 21:46 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-02-11 23:13   ` Aleš Nesrsta
2013-02-24 18:37     ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-02-24 19:09     ` Vladimir 'φ-coder/phcoder' Serbinenko [this message]
2013-02-24 19:25     ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-03-07 19:19       ` Aleš Nesrsta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=512A657A.5020307@gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.