Nico Huber (nico.huber@secunet.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/1081
-gerrit
commit 405fa269240133fc6fdbc8ee6976e923fc68642b Author: Nico Huber nico.huber@secunet.com Date: Wed May 23 09:21:54 2012 +0200
libpayload: Add support for split transactions in EHCI
With split transactions, the EHCI host controller can handle full- and low-speed devices on hubs in high-speed mode. This adds support for split transactions for control and bulk transfers.
Change-Id: I30fa1ce25757f33b1e6ed34207949c9255f05d49 Signed-off-by: Nico Huber nico.huber@secunet.com --- payloads/libpayload/drivers/usb/ehci.c | 49 ++++++++++++++++++++++- payloads/libpayload/drivers/usb/ehci_private.h | 2 + payloads/libpayload/drivers/usb/usb.c | 12 ++--- payloads/libpayload/include/usb/usb.h | 2 - 4 files changed, 53 insertions(+), 12 deletions(-)
diff --git a/payloads/libpayload/drivers/usb/ehci.c b/payloads/libpayload/drivers/usb/ehci.c index cd1e867..e1b28bc 100644 --- a/payloads/libpayload/drivers/usb/ehci.c +++ b/payloads/libpayload/drivers/usb/ehci.c @@ -61,6 +61,30 @@ static void ehci_shutdown (hci_t *controller)
enum { EHCI_OUT=0, EHCI_IN=1, EHCI_SETUP=2 };
+/* + * returns the address of the closest USB2.0 hub, which is responsible for + * split transactions, along with the number of the used downstream port + */ +static int closest_usb2_hub(const usbdev_t *dev, int *const addr, int *const port) +{ + const usbdev_t *usb1dev; + do { + usb1dev = dev; + if ((dev->hub > 0) && (dev->hub < 128)) + dev = dev->controller->devices[dev->hub]; + else + dev = NULL; + } while (dev && (dev->speed < 2)); + if (dev) { + *addr = usb1dev->hub; + *port = usb1dev->port; + return 0; + } else { + debug("ehci: Couldn't find closest USB2.0 hub.\n"); + return 1; + } +} + /* returns handled bytes. assumes that the fields it writes are empty on entry */ static int fill_td(qtd_t *td, void* data, int datalen) { @@ -199,6 +223,13 @@ static int ehci_bulk (endpoint_t *ep, int size, u8 *data, int finalize) int endp = ep->endpoint & 0xf; int pid = (ep->direction==IN)?EHCI_IN:EHCI_OUT;
+ int hubaddr = 0, hubport = 0; + if (ep->dev->speed < 2) { + /* we need a split transaction */ + if (closest_usb2_hub(ep->dev, &hubaddr, &hubport)) + return 1; + } + qtd_t *head = memalign(32, sizeof(qtd_t)); qtd_t *cur = head; while (1) { @@ -232,7 +263,9 @@ static int ehci_bulk (endpoint_t *ep, int size, u8 *data, int finalize) (1 << QH_RECLAIM_HEAD_SHIFT) | (ep->maxpacketsize << QH_MPS_SHIFT) | (0 << QH_NAK_CNT_SHIFT); - qh->epcaps = 3 << QH_PIPE_MULTIPLIER_SHIFT; + qh->epcaps = (3 << QH_PIPE_MULTIPLIER_SHIFT) | + (hubport << QH_PORT_NUMBER_SHIFT) | + (hubaddr << QH_HUB_ADDRESS_SHIFT);
qh->td.next_qtd = virt_to_phys(head); qh->td.token |= (ep->toggle?QTD_TOGGLE_DATA1:0); @@ -257,6 +290,14 @@ static int ehci_control (usbdev_t *dev, direction_t dir, int drlen, void *devreq int mlen = dev->endpoints[0].maxpacketsize; int result = 0;
+ int hubaddr = 0, hubport = 0, non_hs_ctrl_ep = 0; + if (dev->speed < 2) { + /* we need a split transaction */ + if (closest_usb2_hub(dev, &hubaddr, &hubport)) + return 1; + non_hs_ctrl_ep = 1; + } + /* create qTDs */ qtd_t *head = memalign(32, sizeof(qtd_t)); qtd_t *cur = head; @@ -311,9 +352,11 @@ static int ehci_control (usbdev_t *dev, direction_t dir, int drlen, void *devreq (1 << QH_DTC_SHIFT) | /* ctrl transfers are special: take toggle bit from TD */ (1 << QH_RECLAIM_HEAD_SHIFT) | (mlen << QH_MPS_SHIFT) | - (0 << QH_NON_HS_CTRL_EP_SHIFT) | /* no non-HS device support yet */ + (non_hs_ctrl_ep << QH_NON_HS_CTRL_EP_SHIFT) | (0 << QH_NAK_CNT_SHIFT); - qh->epcaps = 3 << QH_PIPE_MULTIPLIER_SHIFT; + qh->epcaps = (3 << QH_PIPE_MULTIPLIER_SHIFT) | + (hubport << QH_PORT_NUMBER_SHIFT) | + (hubaddr << QH_HUB_ADDRESS_SHIFT); qh->td.next_qtd = virt_to_phys(head);
result = ehci_process_async_schedule( diff --git a/payloads/libpayload/drivers/usb/ehci_private.h b/payloads/libpayload/drivers/usb/ehci_private.h index 8ac15b3..29595f8 100644 --- a/payloads/libpayload/drivers/usb/ehci_private.h +++ b/payloads/libpayload/drivers/usb/ehci_private.h @@ -116,6 +116,8 @@ typedef volatile struct { #define QH_NON_HS_CTRL_EP_SHIFT 27 #define QH_NAK_CNT_SHIFT 28 u32 epcaps; +#define QH_HUB_ADDRESS_SHIFT 16 +#define QH_PORT_NUMBER_SHIFT 23 #define QH_PIPE_MULTIPLIER_SHIFT 30 volatile u32 current_td_ptr; volatile qtd_t td; diff --git a/payloads/libpayload/drivers/usb/usb.c b/payloads/libpayload/drivers/usb/usb.c index 1e8f248..07735a2 100644 --- a/payloads/libpayload/drivers/usb/usb.c +++ b/payloads/libpayload/drivers/usb/usb.c @@ -245,8 +245,8 @@ get_free_address (hci_t *controller) return -1; // no free address }
-int -set_address (hci_t *controller, int speed) +static int +set_address (hci_t *controller, int speed, int hubport, int hubaddr) { int adr = get_free_address (controller); // address to set dev_req_t dr; @@ -266,6 +266,8 @@ set_address (hci_t *controller, int speed) usbdev_t *dev = controller->devices[adr]; // dummy values for registering the address dev->address = 0; + dev->hub = hubaddr; + dev->port = hubport; dev->speed = speed; dev->endpoints[0].dev = dev; dev->endpoints[0].endpoint = 0; @@ -469,14 +471,10 @@ usb_attach_device(hci_t *controller, int hubaddress, int port, int speed) { static const char* speeds[] = { "full", "low", "high" }; debug ("%sspeed device\n", (speed <= 2) ? speeds[speed] : "invalid value - no"); - int newdev = set_address (controller, speed); + int newdev = set_address (controller, speed, port, hubaddress); if (newdev == -1) return -1; usbdev_t *newdev_t = controller->devices[newdev]; - - newdev_t->address = newdev; - newdev_t->hub = hubaddress; - newdev_t->port = port; // determine responsible driver - current done in set_address newdev_t->init (newdev_t); return newdev; diff --git a/payloads/libpayload/include/usb/usb.h b/payloads/libpayload/include/usb/usb.h index 05ced49..ee9c50b 100644 --- a/payloads/libpayload/include/usb/usb.h +++ b/payloads/libpayload/include/usb/usb.h @@ -223,8 +223,6 @@ void usb_hub_init (usbdev_t *dev); void usb_hid_init (usbdev_t *dev); void usb_msc_init (usbdev_t *dev);
-int set_address (hci_t *controller, int speed); - u8 *get_descriptor (usbdev_t *dev, unsigned char bmRequestType, int descType, int descIdx, int langID);