[haiku-bugs] Re: [Haiku] #9311: usb_midi fix to handle more "Class-Compliant" devices

  • From: "mmlr" <trac@xxxxxxxxxxxx>
  • Date: Wed, 09 Jan 2013 22:55:31 -0000

#9311: usb_midi fix to handle more "Class-Compliant" devices
---------------------------+-------------------------
   Reporter:  Pete         |      Owner:  mmlr
       Type:  bug          |     Status:  new
   Priority:  normal       |  Milestone:  R1
  Component:  Drivers/USB  |    Version:  R1/alpha4.1
 Resolution:               |   Keywords:
 Blocked By:               |   Blocking:
Has a Patch:  1            |   Platform:  All
---------------------------+-------------------------

Comment (by mmlr):

 Replying to [comment:4 phoudoin]:
 > I wonder if in fact the root issue is not deeper, in the USB stack
 itself. There is absolutely no reason to pass the bulk request with 2048
 size while the stack knows that this endpoint only support 4 bytes max per
 request.

 That is not how it works. The max packet size is just that, the maximum
 size of each packet. A request will be fulfilled using as many packets as
 is required to move the amount of data it is given. The stack splits these
 buffers correctly into multiple packets internally. It's an implementation
 detail if you will. It allows a device to work with a fixed and small
 amount of storage if needed.

 > Clamping it in usb_midi is one way, but maybe it's in the stack itself
 that it should be done. In particular because the USB stack's queue_bulk()
 never required to pass a buffer no bigger than the endpoint's max packet
 size...

 That is right, the queue_bulk() call does not have buffer size
 restrictions. The usb_disk driver does transfer large amounts of data
 using single calls to queue_bulk() for example, something that would
 otherwise be really impractical.

 The device classes usually have specifications that tell what kind of
 limit requests as a whole should have, or in what manner these should be
 communicated. Some have generic descriptors, some may use the max packet
 size, some use requests, others use higher level protocols to determine
 these limits.

 Looking at the specs the packet sizes aren't specified. Looking at the
 linux usb midi driver (http://lxr.linux.no/linux+v3.7.1/sound/usb/midi.c)
 they use the max packet size as the max transfer size by default. It is
 also clear from looking at this driver that there are quite a few broken
 devices and a lot of vendor specific protocols that are slightly
 different.

 So using the max packet size probably makes sense. Using such short
 requests does impact performance of course as the overhead per request is
 quite considerable. However devices that allow for larger buffers will
 probably advertise them and lessen this issue. It is not a big issue
 overall, as for example USB HID transfers are usually in the "couple of
 bytes" range as well (though these are usually not streaming either).

-- 
Ticket URL: <http://dev.haiku-os.org/ticket/9311#comment:5>
Haiku <http://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: