libpayload: Make USB transfer functions return amount of bytes

The USB bulk and control transfer functions in libpayload currently
always return 0 for success and 1 for all errors. This is sufficient for
current use cases (essentially just mass storage), but other classes
(like certain Ethernet adapters) need to be able to tell if a transfer
reached the intended amount of bytes, or if it fell short.

This patch slightly changes that USB API to return -1 on errors, and the
amount of transferred bytes on successes. All drivers in the current
libpayload mainline are modified to conform to the new error detection
model. Any third party users of this API will need to adapt their
if (...<controller>->bulk/control(...)) checks to
if (...<controller>->bulk/control(...) < 0) as well.

The host controller drivers for OHCI and EHCI correctly implement the
new behavior. UHCI and the XHCI stub just comply with the new API by
returning 0 or -1, but do not actually count the returned bytes.

Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/48308
Reviewed-by: Gabe Black <gabeblack@chromium.org>
Reviewed-by: Stefan Reinauer <reinauer@google.com>
Tested-by: Gabe Black <gabeblack@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>

Updated the patch to support XHCI as well.

Change-Id: Ic2ea2810c5edb992cbe185bc9711d2f8f557cae6
(cherry picked from commit e39e2d84762a3804653d950a228ed2269c651458)
Signed-off-by: Isaac Christensen <isaac.christensen@se-eng.com>
Reviewed-on: http://review.coreboot.org/6390
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Reviewed-by: Patrick Georgi <patrick@georgi-clan.de>
This commit is contained in:
Julius Werner
2013-02-21 13:41:40 -08:00
committed by Isaac Christensen
parent 0f0c720621
commit e9738dbe2b
7 changed files with 91 additions and 67 deletions

View File

@ -184,7 +184,7 @@ reset_transport (usbdev_t *dev)
dr.wLength = 0;
/* if any of these fails, detach device, as we are lost */
if (dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0) ||
if (dev->controller->control (dev, OUT, sizeof (dr), &dr, 0, 0) < 0 ||
clear_stall (MSC_INST (dev)->bulk_in) ||
clear_stall (MSC_INST (dev)->bulk_out)) {
usb_debug ("Detaching unresponsive device.\n");
@ -211,9 +211,8 @@ get_max_luns (usbdev_t *dev)
dr.wValue = 0;
dr.wIndex = 0;
dr.wLength = 1;
if (dev->controller->control (dev, IN, sizeof (dr), &dr, 1, &luns)) {
if (dev->controller->control (dev, IN, sizeof (dr), &dr, 1, &luns) < 0)
luns = 0; // assume only 1 lun if req fails
}
return luns;
}
@ -239,10 +238,10 @@ wrap_cbw (cbw_t *cbw, int datalen, cbw_direction dir, const u8 *cmd,
static int
get_csw (endpoint_t *ep, csw_t *csw)
{
if (ep->dev->controller->bulk (ep, sizeof (csw_t), (u8 *) csw, 1)) {
if (ep->dev->controller->bulk (ep, sizeof (csw_t), (u8 *) csw, 1) < 0) {
clear_stall (ep);
if (ep->dev->controller->bulk
(ep, sizeof (csw_t), (u8 *) csw, 1)) {
(ep, sizeof (csw_t), (u8 *) csw, 1) < 0) {
return reset_transport (ep->dev);
}
}
@ -265,17 +264,17 @@ execute_command (usbdev_t *dev, cbw_direction dir, const u8 *cb, int cblen,
}
wrap_cbw (&cbw, buflen, dir, cb, cblen);
if (dev->controller->
bulk (MSC_INST (dev)->bulk_out, sizeof (cbw), (u8 *) &cbw, 0)) {
bulk (MSC_INST (dev)->bulk_out, sizeof (cbw), (u8 *) &cbw, 0) < 0) {
return reset_transport (dev);
}
if (buflen > 0) {
if (dir == cbw_direction_data_in) {
if (dev->controller->
bulk (MSC_INST (dev)->bulk_in, buflen, buf, 0))
bulk (MSC_INST (dev)->bulk_in, buflen, buf, 0) < 0)
clear_stall (MSC_INST (dev)->bulk_in);
} else {
if (dev->controller->
bulk (MSC_INST (dev)->bulk_out, buflen, buf, 0))
bulk (MSC_INST (dev)->bulk_out, buflen, buf, 0) < 0)
clear_stall (MSC_INST (dev)->bulk_out);
}
}