You were pretty much correct Randy.

Anyway, it's described in section 5.5.3 (although they confuse
bMaxPacketSize0 with wMaxPacketSize) of the USB v1.1 spec.

Here's a patch to add some comments to that effect, as well as remove the
maxpacketsize field from the usb_device structure (and minor associated
code) since it's not used anymore.

The patch is against 2.3.99-pre4-5.

JE

On Tue, Apr 11, 2000, Dunlap, Randy <[EMAIL PROTECTED]> wrote:
> OK, I stand corrected.  Thanks to both Nick and Johannes.
> 
> This is a case where some comments in the source code
> wouldn't hurt.  This is non-obvious IMO.
> 
> ~Randy
> 
> ___________________________________________________
> |Randy Dunlap     Intel Corp., DAL    Sr. SW Engr.|
> |randy.dunlap.at.intel.com            503-696-2055|
> |NOTE:  Any views presented here are mine alone   |
> |and may not represent the views of my employer.  |
> |_________________________________________________|
> 
> > -----Original Message-----
> > From: Johannes Erdfelt [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, April 11, 2000 9:00 AM
> > To: Nick Hibma
> > Cc: Dunlap, Randy; 'Karel Srsen'; [EMAIL PROTECTED];
> > '[EMAIL PROTECTED]'
> > Subject: Re: [linux-usb] RE: USB driver
> > 
> > 
> > Unfortunately this wasn't the case with me. I wrote the original patch
> > to do this (which is the correct thing to do according the USB spec).
> > 
> > The problem I was having was the device I was using didn't like it
> > sending 8 byte requests when the maximum packet size of the pipe was
> > larger. The device thought it was a short read and then terminated the
> > transfer, or more specifically, barf when it saw the next IN since it
> > was expecting a status packet.
> > 
> > Trying to read more data than there is descriptor data should be safe
> > since the last packet will be treated as a short read and the 
> > connection
> > will end per the spec.
> > 
> > Atleast, Windows tries to read too much and it works.
> > 
> > JE
> > 
> > On Tue, Apr 11, 2000, Nick Hibma <[EMAIL PROTECTED]> wrote:
> > > 
> > > Um, not quite. The reason that one reads the first 8 bytes 
> > first is that
> > > some devices go pop if you read let's say 128 bytes while 
> > there is only
> > > 18 bytes in descriptors.
> > > 
> > > Reading the first 8 bytes and then the the correct number of bytes
> > > avoids this problem.
> > > 
> > > Normally one would read the whole set of descriptors in one 
> > go with a
> > > read for 256 bytes or so and chunk it into 8 byte packets.
> > > 
> > > Nick
> > > 
> > > 
> > > On Tue, 11 Apr 2000, Dunlap, Randy wrote:
> > > 
> > > > Hi,
> > > > 
> > > > When usb_new_device() is called, the maxpacketsize for the
> > > > default control pipe is not known, so it's not safe to read more
> > > > than 8 bytes of the device descriptor.  Since bMaxPacketSize0
> > > > (max packet size for the default control pipe) is in this first
> > > > 8 bytes, the code can read this byte and use it for future
> > > > reads of the control pipe.  You can follow the code and see
> > > > that a few lines later it calls usb_get_device_descriptor().
> > > > This reads the entire descriptor.
> > > > 
> > > > This shouldn't cause any problem(s) with the device you
> > > > are working with if it's built properly.  If you see problems,
> > > > it could be a USB device silicon or firmware problem.
> > > > 
> > > > For future linux-usb discussions, please use the
> > > > [EMAIL PROTECTED] mailing list.
> > > > 
> > > > ~Randy
> > > > 
> > > > > -----Original Message-----
> > > > > From: Karel Srsen [mailto:[EMAIL PROTECTED]]
> > > > > 
> > > > > Hello,
> > > > > is there somebody who understands linux USB driver ?
> > > > > I have one question:
> > > > > there is following piece of code in drivers/usb/usb.c 
> > (2.3.50 kernel):
> > > > > 
> > > > > int usb_new_device(struct usb_device *dev)
> > > > > {
> > > > > ...
> > > > > ...
> > > > >         err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
> > > > > &dev->descriptor, 8);
> > > > >         if (err < 8) {
> > > > > ...
> > > > > ...
> > > > > }
> > > > > 
> > > > > that's nice but in fact USB device descriptor's length 
> > is not 8 bytes
> > > > > but 18 (0x12). Does it means that driver reads only 
> > leading 8 bytes
> > > > > instead of whole descriptor ? I thing it's wrong, isn't 
> > ? Can it cause
> > > > > any error ?
> > > > > 
> > > > > I haven't subscribed this mailing list. If you decide 
> > to answer, send
> > > > > reply to [EMAIL PROTECTED] please.
> > > > > 
> > > > >   Karel
> > > > 
> > > > 
> > > > 
> > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > 
> > > > 
> > > 
> > > --
> > > [EMAIL PROTECTED]
> > > [EMAIL PROTECTED]                                         
> >  USB project
> > > http://www.etla.net/~n_hibma/
> > > 
> > > 
> > > 
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> > 
> 
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [EMAIL PROTECTED]
> Please read the FAQ at http://www.tux.org/lkml/
> 
> 
--- linux-2.3.99-pre4-5.orig/include/linux/usb.h        Mon Apr 10 11:43:47 2000
+++ linux-2.3.99-pre4-5.patch/include/linux/usb.h       Tue Apr 11 11:30:31 2000
@@ -539,7 +539,6 @@
 
        atomic_t refcnt;                /* Reference count */
 
-       int maxpacketsize;              /* Maximum packet size; encoded as 0,1,2,3 = 
8,16,32,64 */
        unsigned int toggle[2];         /* one bit for each endpoint ([0] = IN, [1] = 
OUT) */
        unsigned int halted[2];         /* endpoint halts; one bit per endpoint # & 
direction; */
                                        /* [0] = IN, [1] = OUT */
@@ -686,7 +685,7 @@
 
 static inline unsigned int __create_pipe(struct usb_device *dev, unsigned int 
endpoint)
 {
-       return (dev->devnum << 8) | (endpoint << 15) | (dev->slow << 26) | 
dev->maxpacketsize;
+       return (dev->devnum << 8) | (endpoint << 15) | (dev->slow << 26);
 }
 
 static inline unsigned int __default_pipe(struct usb_device *dev)
--- linux-2.3.99-pre4-5.orig/drivers/usb/usb.c  Mon Apr 10 11:43:44 2000
+++ linux-2.3.99-pre4-5.patch/drivers/usb/usb.c Tue Apr 11 11:28:52 2000
@@ -1718,11 +1718,15 @@
 
        info("USB new device connect, assigned device number %d", dev->devnum);
  
-       dev->maxpacketsize = 0;         /* Default to 8 byte max packet size */
+       /* USB v1.1 5.5.3 */
+       /* We read the first 8 bytes from the device descriptor to get to */
+       /*  the bMaxPacketSize0 field. Then we set the maximum packet size */
+       /*  for the control pipe, and retrieve the rest */
        dev->epmaxpacketin [0] = 8;
        dev->epmaxpacketout[0] = 8;
 
-       /* We still haven't set the Address yet */
+       /* Even though we have assigned an address for the device, we */
+       /*  haven't told it what it's address is yet */
        addr = dev->devnum;
        dev->devnum = 0;
 
@@ -1738,12 +1742,6 @@
        }
        dev->epmaxpacketin [0] = dev->descriptor.bMaxPacketSize0;
        dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0;
-       switch (dev->descriptor.bMaxPacketSize0) {
-               case 8: dev->maxpacketsize = 0; break;
-               case 16: dev->maxpacketsize = 1; break;
-               case 32: dev->maxpacketsize = 2; break;
-               case 64: dev->maxpacketsize = 3; break;
-       }
 
        dev->devnum = addr;
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to