[haiku-development] Re: Am I misunderstanding USB queue_bulk?

  • From: "Michael Lotz" <mmlr@xxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Mon, 07 Sep 2009 21:03:05

Hi again

> On Mon, Sep 07, 2009 at 03:53:12AM +0000, Michael Lotz wrote:
> > You do not need to split up anything. In fact you shouldn't. The 
> > packet 
> > size of the endpoint is purely informational for you. The stack (or 
> > the 
> > host controller depending on the model) will do the splitting up. 
> > You 
> > hand in the whole buffer with all the payload data you need to 
> > send.
> I don't believe this is quite correct in the case of USB-MIDI.  All 
> MIDI
> is passed to and from the device in 4-byte packets, only the last 
> three
> of which are the MIDI data.  The first byte of each packet has to be
> added (it isn't in the buffer passed from the MIDI driver) to 
> identify
> the contents.  So at the very least I have to build a new data buffer
> contailing a sequence of full packets.

I don't know about the MIDI specific packet notation. What I wrote is 
only about the USB max packet size which can be disregarded.

> Are you saying, though, that I can build that buffer essentially as 
> large
> as I like, distinct from the 'maximum packet size' (64 bytes) of the 
> device
> hardware itself?  I had already found that the receiving side can get 
> many
> 4-byte packets packed into a single return buffer, but this is always 
> less
> than the 64 limit (possibly because I put that limit in the device_
> info
> structure?!).  I was about to try packing the output side as well, so 
> I'll
> go ahead and do that (though large SysExs will always have to be 
> split).

Yes that's exactly what I am saying. Feel free to pack as much data 
into a buffer as you want (there's a certain limit, but you're unlikely 
to hit that). If the device sends more than one MIDI packet per 
incoming USB transfer, then I guess it will be fine if you do the same 
and pack more than one MIDI packet into the outgoing transfer as well. 
The packet size used for incoming transfers is really device specific. 
Some will send large buffers, some will limit them to the max packet 
size, some something completely different... If you scheduled the 
incoming transfer with a size of 64 bytes only, this would at least 
explain why you never got more than that at a time.

Why do large SysEx packets need to always be split? I cannot speak for 
the MIDI side of things, but from a purely USB standpoint of view this 
is not necessary. If the MIDI packets you are using have a limit there 
then that's something different of course, I wouldn't know.

> Ah, so it is a bit of a misnomer...  I assumed it would be a fifo.
> If I can pack the buffer, as you say it's not a real problem.

Well, the transfer is queued for execution. You can also queue more 
than one transfer to different endpoints on the same device or to 
different devices at the same time, so the queue notation does make 
sense (the transfers aren't necessarily completed in order though). It 
just means queuing at the level of different transfers, not at the 
level of data to or from a single endpoint.

Regards
Michael

Other related posts: