Hi, On Saturday 11 December 2010 02:08:37 Dwight Schauer wrote: > I'm with Texas Instruments and I'm trying to get our USB3 host > controller working with FreeBSD 8.2-BETA1 >
> > However, nothing happens when I attach a mass storage device to the > Texas Instruments USB3 host controller. > > Any advice is welcome. > The mode your XHCI controller is using is currently not supported. Please try the attached patch and report back. --HPS
==== Patch <xhci_context.patch> level 1 Source: [No source] Target: ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f:/head/sys/dev/usb/controller:215649 [mirrored] [updated] (svn+ssh://hsela...@svn.freebsd.org/base) Log: - Add support for 64-byte contexts to XHCI driver. - Remove some dead code. - Fixed one instance of missing endian conversion. MFC after: 3 days Approved by: thompsa (mentor) === xhci.c ================================================================== --- xhci.c (revision 215649) +++ xhci.c (patch xhci_context.patch level 1) @@ -134,6 +134,10 @@ static usb_error_t xhci_cmd_evaluate_ctx(struct xhci_softc *, uint64_t, uint8_t); static void xhci_endpoint_doorbell(struct usb_xfer *); +static void xhci_ctx_set_le32(struct xhci_softc *sc, volatile uint32_t *ptr, uint32_t val); +static uint32_t xhci_ctx_get_le32(struct xhci_softc *sc, volatile uint32_t *ptr); +static void xhci_ctx_set_le64(struct xhci_softc *sc, volatile uint64_t *ptr, uint64_t val); +static uint64_t xhci_ctx_get_le64(struct xhci_softc *sc, volatile uint64_t *ptr); extern struct usb_bus_methods xhci_bus_methods; @@ -148,26 +152,26 @@ } static void -xhci_dump_endpoint(struct xhci_endp_ctx *pep) +xhci_dump_endpoint(struct xhci_softc *sc, struct xhci_endp_ctx *pep) { DPRINTFN(5, "pep = %p\n", pep); - DPRINTFN(5, "dwEpCtx0=0x%08x\n", pep->dwEpCtx0); - DPRINTFN(5, "dwEpCtx1=0x%08x\n", pep->dwEpCtx1); - DPRINTFN(5, "qwEpCtx2=0x%016llx\n", (long long)pep->qwEpCtx2); - DPRINTFN(5, "dwEpCtx4=0x%08x\n", pep->dwEpCtx4); - DPRINTFN(5, "dwEpCtx5=0x%08x\n", pep->dwEpCtx5); - DPRINTFN(5, "dwEpCtx6=0x%08x\n", pep->dwEpCtx6); - DPRINTFN(5, "dwEpCtx7=0x%08x\n", pep->dwEpCtx7); + DPRINTFN(5, "dwEpCtx0=0x%08x\n", xhci_ctx_get_le32(sc, &pep->dwEpCtx0)); + DPRINTFN(5, "dwEpCtx1=0x%08x\n", xhci_ctx_get_le32(sc, &pep->dwEpCtx1)); + DPRINTFN(5, "qwEpCtx2=0x%016llx\n", (long long)xhci_ctx_get_le64(sc, &pep->qwEpCtx2)); + DPRINTFN(5, "dwEpCtx4=0x%08x\n", xhci_ctx_get_le32(sc, &pep->dwEpCtx4)); + DPRINTFN(5, "dwEpCtx5=0x%08x\n", xhci_ctx_get_le32(sc, &pep->dwEpCtx5)); + DPRINTFN(5, "dwEpCtx6=0x%08x\n", xhci_ctx_get_le32(sc, &pep->dwEpCtx6)); + DPRINTFN(5, "dwEpCtx7=0x%08x\n", xhci_ctx_get_le32(sc, &pep->dwEpCtx7)); } static void -xhci_dump_device(struct xhci_slot_ctx *psl) +xhci_dump_device(struct xhci_softc *sc, struct xhci_slot_ctx *psl) { DPRINTFN(5, "psl = %p\n", psl); - DPRINTFN(5, "dwSctx0=0x%08x\n", psl->dwSctx0); - DPRINTFN(5, "dwSctx1=0x%08x\n", psl->dwSctx1); - DPRINTFN(5, "dwSctx2=0x%08x\n", psl->dwSctx2); - DPRINTFN(5, "dwSctx3=0x%08x\n", psl->dwSctx3); + DPRINTFN(5, "dwSctx0=0x%08x\n", xhci_ctx_get_le32(sc, &psl->dwSctx0)); + DPRINTFN(5, "dwSctx1=0x%08x\n", xhci_ctx_get_le32(sc, &psl->dwSctx1)); + DPRINTFN(5, "dwSctx2=0x%08x\n", xhci_ctx_get_le32(sc, &psl->dwSctx2)); + DPRINTFN(5, "dwSctx3=0x%08x\n", xhci_ctx_get_le32(sc, &psl->dwSctx3)); } #endif @@ -189,6 +193,60 @@ } } +static void +xhci_ctx_set_le32(struct xhci_softc *sc, volatile uint32_t *ptr, uint32_t val) +{ + if (sc->sc_ctx_is_64_byte) { + uint32_t offset; + /* exploit the fact that our structures are XHCI_PAGE_SIZE aligned */ + offset = ((uintptr_t)ptr) & (XHCI_PAGE_SIZE - 1); + offset &= ~31U; /* all contexts are initially 32-bytes */ + ptr = (volatile uint32_t *)(((volatile uint8_t *)ptr) + offset); + } + *ptr = htole32(val); +} + +static uint32_t +xhci_ctx_get_le32(struct xhci_softc *sc, volatile uint32_t *ptr) +{ + if (sc->sc_ctx_is_64_byte) { + uint32_t offset; + /* exploit the fact that our structures are XHCI_PAGE_SIZE aligned */ + offset = ((uintptr_t)ptr) & (XHCI_PAGE_SIZE - 1); + offset &= ~31U; /* all contexts are initially 32-bytes */ + ptr = (volatile uint32_t *)(((volatile uint8_t *)ptr) + offset); + } + return (le32toh(*ptr)); +} + +static void +xhci_ctx_set_le64(struct xhci_softc *sc, volatile uint64_t *ptr, uint64_t val) +{ + if (sc->sc_ctx_is_64_byte) { + uint32_t offset; + /* exploit the fact that our structures are XHCI_PAGE_SIZE aligned */ + offset = ((uintptr_t)ptr) & (XHCI_PAGE_SIZE - 1); + offset &= ~31U; /* all contexts are initially 32-bytes */ + ptr = (volatile uint64_t *)(((volatile uint8_t *)ptr) + offset); + } + *ptr = htole64(val); +} + +#ifdef USB_DEBUG +static uint64_t +xhci_ctx_get_le64(struct xhci_softc *sc, volatile uint64_t *ptr) +{ + if (sc->sc_ctx_is_64_byte) { + uint32_t offset; + /* exploit the fact that our structures are XHCI_PAGE_SIZE aligned */ + offset = ((uintptr_t)ptr) & (XHCI_PAGE_SIZE - 1); + offset &= ~31U; /* all contexts are initially 32-bytes */ + ptr = (volatile uint64_t *)(((volatile uint8_t *)ptr) + offset); + } + return (le64toh(*ptr)); +} +#endif + usb_error_t xhci_start_controller(struct xhci_softc *sc) { @@ -222,9 +280,11 @@ DPRINTF("HCS0 = 0x%08x\n", temp); if (XHCI_HCS0_CSZ(temp)) { - device_printf(sc->sc_bus.parent, "Driver does not " - "support 64-byte contexts."); - return (USB_ERR_IOERROR); + sc->sc_ctx_is_64_byte = 1; + device_printf(sc->sc_bus.parent, "64 byte context size.\n"); + } else { + sc->sc_ctx_is_64_byte = 0; + device_printf(sc->sc_bus.parent, "32 byte context size.\n"); } /* Reset controller */ @@ -1127,6 +1187,7 @@ struct xhci_hw_dev *hdev; struct xhci_dev_ctx *pdev; struct xhci_endpoint_ext *pepext; + uint32_t temp; uint16_t mps; usb_error_t err; uint8_t index; @@ -1204,8 +1265,10 @@ usbd_get_page(&hdev->device_pc, 0, &buf_dev); pdev = buf_dev.buffer; usb_pc_cpu_invalidate(&hdev->device_pc); - udev->address = XHCI_SCTX_3_DEV_ADDR_GET(pdev->ctx_slot.dwSctx3); + temp = xhci_ctx_get_le32(sc, &pdev->ctx_slot.dwSctx3); + udev->address = XHCI_SCTX_3_DEV_ADDR_GET(temp); + /* update device state to new value */ if (address != 0) @@ -1964,11 +2027,11 @@ if (drop) { mask &= XHCI_INCTX_NON_CTRL_MASK; - pinp->ctx_input.dwInCtx0 = htole32(mask); - pinp->ctx_input.dwInCtx1 = 0; + xhci_ctx_set_le32(sc, &pinp->ctx_input.dwInCtx0, mask); + xhci_ctx_set_le32(sc, &pinp->ctx_input.dwInCtx1, 0); } else { - pinp->ctx_input.dwInCtx0 = 0; - pinp->ctx_input.dwInCtx1 = htole32(mask); + xhci_ctx_set_le32(sc, &pinp->ctx_input.dwInCtx0, 0); + xhci_ctx_set_le32(sc, &pinp->ctx_input.dwInCtx1, mask); } return (0); } @@ -2050,7 +2113,7 @@ break; } - pinp->ctx_ep[epno - 1].dwEpCtx0 = htole32(temp); + xhci_ctx_set_le32(sc, &pinp->ctx_ep[epno - 1].dwEpCtx0, temp); temp = XHCI_EPCTX_1_HID_SET(0) | @@ -2081,11 +2144,11 @@ if (epno & 1) temp |= XHCI_EPCTX_1_EPTYPE_SET(4); - pinp->ctx_ep[epno - 1].dwEpCtx1 = htole32(temp); + xhci_ctx_set_le32(sc, &pinp->ctx_ep[epno - 1].dwEpCtx1, temp); ring_addr |= XHCI_EPCTX_2_DCS_SET(1); - pinp->ctx_ep[epno - 1].qwEpCtx2 = htole64(ring_addr); + xhci_ctx_set_le64(sc, &pinp->ctx_ep[epno - 1].qwEpCtx2, ring_addr); switch (edesc->bmAttributes & UE_XFERTYPE) { case UE_INTERRUPT: @@ -2102,10 +2165,10 @@ break; } - pinp->ctx_ep[epno - 1].dwEpCtx4 = htole32(temp); + xhci_ctx_set_le32(sc, &pinp->ctx_ep[epno - 1].dwEpCtx4, temp); #ifdef USB_DEBUG - xhci_dump_endpoint(&pinp->ctx_ep[epno - 1]); + xhci_dump_endpoint(sc, &pinp->ctx_ep[epno - 1]); #endif usb_pc_cpu_flush(&sc->sc_hw.devs[index].input_pc); @@ -2138,12 +2201,9 @@ xhci_configure_device(struct usb_device *udev) { struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); - struct usb_page_search buf_dev; struct usb_page_search buf_inp; - struct usb_page_cache *pcdev; struct usb_page_cache *pcinp; struct xhci_input_dev_ctx *pinp; - struct xhci_dev_ctx *pdev; struct usb_device *hubdev; uint32_t temp; uint32_t route; @@ -2155,13 +2215,10 @@ DPRINTF("index=%u\n", index); - pcdev = &sc->sc_hw.devs[index].device_pc; pcinp = &sc->sc_hw.devs[index].input_pc; - usbd_get_page(pcdev, 0, &buf_dev); usbd_get_page(pcinp, 0, &buf_inp); - pdev = buf_dev.buffer; pinp = buf_inp.buffer; rh_port = 0; @@ -2232,7 +2289,7 @@ #endif } - pinp->ctx_slot.dwSctx0 = htole32(temp); + xhci_ctx_set_le32(sc, &pinp->ctx_slot.dwSctx0, temp); temp = XHCI_SCTX_1_RH_PORT_SET(rh_port); @@ -2258,7 +2315,7 @@ break; } - pinp->ctx_slot.dwSctx1 = htole32(temp); + xhci_ctx_set_le32(sc, &pinp->ctx_slot.dwSctx1, temp); temp = XHCI_SCTX_2_IRQ_TARGET_SET(0); @@ -2282,15 +2339,15 @@ break; } - pinp->ctx_slot.dwSctx2 = htole32(temp); + xhci_ctx_set_le32(sc, &pinp->ctx_slot.dwSctx2, temp); temp = XHCI_SCTX_3_DEV_ADDR_SET(udev->address) | XHCI_SCTX_3_SLOT_STATE_SET(0); - pinp->ctx_slot.dwSctx3 = htole32(temp); + xhci_ctx_set_le32(sc, &pinp->ctx_slot.dwSctx3, temp); #ifdef USB_DEBUG - xhci_dump_device(&pinp->ctx_slot); + xhci_dump_device(sc, &pinp->ctx_slot); #endif usb_pc_cpu_flush(pcinp); @@ -2318,7 +2375,9 @@ /* need to initialize the page cache */ pc->tag_parent = sc->sc_bus.dma_parent_tag; - if (usb_pc_alloc_mem(pc, pg, sizeof(struct xhci_dev_ctx), XHCI_PAGE_SIZE)) + if (usb_pc_alloc_mem(pc, pg, sc->sc_ctx_is_64_byte ? + (2 * sizeof(struct xhci_dev_ctx)) : + sizeof(struct xhci_dev_ctx), XHCI_PAGE_SIZE)) goto error; usbd_get_page(pc, 0, &buf_dev); @@ -2329,7 +2388,9 @@ /* need to initialize the page cache */ pc->tag_parent = sc->sc_bus.dma_parent_tag; - if (usb_pc_alloc_mem(pc, pg, sizeof(struct xhci_input_dev_ctx), XHCI_PAGE_SIZE)) + if (usb_pc_alloc_mem(pc, pg, sc->sc_ctx_is_64_byte ? + (2 * sizeof(struct xhci_input_dev_ctx)) : + sizeof(struct xhci_input_dev_ctx), XHCI_PAGE_SIZE)) goto error; pc = &sc->sc_hw.devs[index].endpoint_pc; @@ -3348,13 +3409,10 @@ xhci_configure_reset_endpoint(struct usb_xfer *xfer) { struct xhci_softc *sc = XHCI_BUS2SC(xfer->xroot->bus); - struct usb_page_search buf_dev; struct usb_page_search buf_inp; struct usb_device *udev; struct xhci_endpoint_ext *pepext; struct usb_endpoint_descriptor *edesc; - struct xhci_dev_ctx *pdctx; - struct usb_page_cache *pcdev; struct usb_page_cache *pcinp; usb_error_t err; uint8_t index; @@ -3366,14 +3424,10 @@ udev = xfer->xroot->udev; index = udev->controller_slot_id; - pcdev = &sc->sc_hw.devs[index].device_pc; pcinp = &sc->sc_hw.devs[index].input_pc; - usbd_get_page(pcdev, 0, &buf_dev); usbd_get_page(pcinp, 0, &buf_inp); - pdctx = buf_dev.buffer; - edesc = xfer->endpoint->edesc; epno = edesc->bEndpointAddress; === xhci.h ================================================================== --- xhci.h (revision 215649) +++ xhci.h (patch xhci_context.patch level 1) @@ -477,6 +477,9 @@ uint8_t sc_conf; uint8_t sc_hub_idata[2]; + /* size of context */ + uint8_t sc_ctx_is_64_byte; + /* vendor string for root HUB */ char sc_vendor[16]; };
_______________________________________________ freebsd-usb@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-usb To unsubscribe, send any mail to "freebsd-usb-unsubscr...@freebsd.org"