Re: Question r/e zero byte bulk transfer on musb gadget (causes kernel panic)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 1 Nov 2014, Breton M. Saunders wrote:

> > This is required behavior, for example, during the data phase of a
> > bulk-only mass-storage transfer.  The specification states that under
> > certain circumstances, the device _must_ send a zero-length packet on
> > its bulk-IN endpoint.
> 
> Hi Alan - thanks for that.  Can I ask: have you got a reference for 
> that?  It will help when I arrive back in the office on Monday.
> I've briefly skimmed the usb mass storage bulk only document (from 1999) 
> and am looking at usb-msc-0.2.pdf now; but am not finding details on 
> zero-length transfers on bulk.

So on careful investigation, it turns out I misspoke.

In the 1.0 revision of the Bulk-Only Transport specification (the 
filename is probably something like usbmassbulk_10.pdf), the discussion 
of case 4 in section 6.7.2 says:

	If the device actually transfers less data than the host
	indicated, then:
		The device may end the transfer with a short packet.
		The device shall STALL the Bulk-In pipe.

Thus, if the device chooses to end the transfer with a short packet,
the packet may need to have length 0 (for case 4).  But the device
isn't required to do this, whereas it _is_ required to STALL the
bulk-IN pipe.

Ironically, many devices in the real world _do_ send a short packet and 
_don't_ send a STALL.

Regardless, the principle is clear: Devices _should_ be able to send 
0-length packets on bulk endpoints.  See the discussion of short 
packets in sections 5.3.2 and 5.8.3 of the USB-2.0 spec.

> I admit to being unfamiliar with usb mass storage; my work has primarily 
> been on HID and custom bulk protocols.
> 
> I was coming at this from the user side of the problem where what I was 
> (incorrectly) doing was:
>    write(fd, buffer, 0);
> where buffer is a valid virtual address, and fd is an open file 
> descriptor on a bulk-in endpoint.
> 
> If I read man 2 write (ubuntu 14.04) I find that the return code for 
> write is undefined for a non-regular file _and_ a count value of zero.  
> At present I've seen fit to just return -EIO (from gadgetfs) on writes 
> of zero bytes to a non-control endpoint - however, I'm still trying to 
> ascertain whether this behavior is correct or not.

gadgetfs is a whole separate story.  Nevertheless, I'm pretty sure 
that it's supposed to return 0 for such a write, unless something goes 
wrong.

> A document stating that zero length bulk transfers could allow me to get 
> permission to investigate the problem further down the chain - into musb.

If there is a problem, it undoubtedly lies in the musb driver.  There
has been a fair amount of discussion on the mailing list recently about
about how that driver should handle 0-length packets (although the
discussion was concerned with control transfers, not bulk).

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux