From owner-svn-src-head@FreeBSD.ORG Sat Dec 1 22:13:39 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 1E0B645A; Sat, 1 Dec 2012 22:13:39 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id F27348FC12; Sat, 1 Dec 2012 22:13:38 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qB1MDc0P006371; Sat, 1 Dec 2012 22:13:38 GMT (envelope-from hselasky@svn.freebsd.org) Received: (from hselasky@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qB1MDcWA006369; Sat, 1 Dec 2012 22:13:38 GMT (envelope-from hselasky@svn.freebsd.org) Message-Id: <201212012213.qB1MDcWA006369@svn.freebsd.org> From: Hans Petter Selasky Date: Sat, 1 Dec 2012 22:13:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r243780 - head/sys/dev/usb/controller X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Dec 2012 22:13:39 -0000 Author: hselasky Date: Sat Dec 1 22:13:38 2012 New Revision: 243780 URL: http://svnweb.freebsd.org/changeset/base/243780 Log: - Add support for Etron EJ168 USB 3.0 Host Controllers. This brand of controllers expects that the number of contexts specified in the input slot context points to an active endpoint context, else it refuses to operate. - Ring the correct doorbell when streams mode is used. - Wrap one or two long lines. Tested by: Markus Pfeiffer (DragonFlyBSD) MFC after: 1 week Modified: head/sys/dev/usb/controller/xhci.c head/sys/dev/usb/controller/xhci.h Modified: head/sys/dev/usb/controller/xhci.c ============================================================================== --- head/sys/dev/usb/controller/xhci.c Sat Dec 1 21:26:46 2012 (r243779) +++ head/sys/dev/usb/controller/xhci.c Sat Dec 1 22:13:38 2012 (r243780) @@ -2045,7 +2045,9 @@ xhci_configure_mask(struct usb_device *u struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); struct usb_page_search buf_inp; struct xhci_input_dev_ctx *pinp; + uint32_t temp; uint8_t index; + uint8_t x; index = udev->controller_slot_id; @@ -2060,6 +2062,24 @@ xhci_configure_mask(struct usb_device *u } else { xhci_ctx_set_le32(sc, &pinp->ctx_input.dwInCtx0, 0); xhci_ctx_set_le32(sc, &pinp->ctx_input.dwInCtx1, mask); + + /* find most significant set bit */ + for (x = 31; x != 1; x--) { + if (mask & (1 << x)) + break; + } + + /* adjust */ + x--; + + /* figure out maximum */ + if (x > sc->sc_hw.devs[index].context_num) { + sc->sc_hw.devs[index].context_num = x; + temp = xhci_ctx_get_le32(sc, &pinp->ctx_slot.dwSctx0); + temp &= ~XHCI_SCTX_0_CTX_NUM_SET(31); + temp |= XHCI_SCTX_0_CTX_NUM_SET(x + 1); + xhci_ctx_set_le32(sc, &pinp->ctx_slot.dwSctx0, temp); + } } return (0); } @@ -2311,16 +2331,9 @@ xhci_configure_device(struct usb_device DPRINTF("Route=0x%08x\n", route); - temp = XHCI_SCTX_0_ROUTE_SET(route); - - switch (sc->sc_hw.devs[index].state) { - case XHCI_ST_CONFIGURED: - temp |= XHCI_SCTX_0_CTX_NUM_SET(XHCI_MAX_ENDPOINTS - 1); - break; - default: - temp |= XHCI_SCTX_0_CTX_NUM_SET(1); - break; - } + temp = XHCI_SCTX_0_ROUTE_SET(route) | + XHCI_SCTX_0_CTX_NUM_SET( + sc->sc_hw.devs[index].context_num + 1); switch (udev->speed) { case USB_SPEED_LOW: @@ -2464,8 +2477,9 @@ xhci_alloc_device_ext(struct usb_device 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)) + sizeof(struct xhci_input_dev_ctx), XHCI_PAGE_SIZE)) { goto error; + } pc = &sc->sc_hw.devs[index].endpoint_pc; pg = &sc->sc_hw.devs[index].endpoint_pg; @@ -2473,15 +2487,18 @@ xhci_alloc_device_ext(struct usb_device /* 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_endpoint_trbs), XHCI_PAGE_SIZE)) + if (usb_pc_alloc_mem(pc, pg, + sizeof(struct xhci_dev_endpoint_trbs), XHCI_PAGE_SIZE)) { goto error; + } /* initialise all endpoint LINK TRBs */ for (i = 0; i != XHCI_MAX_ENDPOINTS; i++) { /* lookup endpoint TRB ring */ - usbd_get_page(pc, (uintptr_t)&((struct xhci_dev_endpoint_trbs *)0)->trb[i][0], &buf_ep); + usbd_get_page(pc, (uintptr_t)& + ((struct xhci_dev_endpoint_trbs *)0)->trb[i][0], &buf_ep); /* get TRB pointer */ trb = buf_ep.buffer; @@ -2568,8 +2585,10 @@ xhci_endpoint_doorbell(struct usb_xfer * epno = XHCI_EPNO2EPID(epno); index = xfer->xroot->udev->controller_slot_id; - if (xfer->xroot->udev->flags.self_suspended == 0) - XWRITE4(sc, door, XHCI_DOORBELL(index), epno | XHCI_DB_SID_SET(0)); + if (xfer->xroot->udev->flags.self_suspended == 0) { + XWRITE4(sc, door, XHCI_DOORBELL(index), + epno | XHCI_DB_SID_SET(xfer->stream_id)); + } } static void @@ -3584,7 +3603,7 @@ xhci_configure_reset_endpoint(struct usb * endpoint context state diagram in the XHCI specification: */ - xhci_configure_mask(udev, 1U << epno, 0); + xhci_configure_mask(udev, (1U << epno) | 1U, 0); err = xhci_cmd_evaluate_ctx(sc, buf_inp.physaddr, index); @@ -3858,6 +3877,7 @@ xhci_device_resume(struct usb_device *ud struct xhci_softc *sc = XHCI_BUS2SC(udev->bus); uint8_t index; uint8_t n; + uint8_t p; DPRINTF("\n"); @@ -3873,8 +3893,12 @@ xhci_device_resume(struct usb_device *ud USB_BUS_LOCK(udev->bus); - for (n = 1; n != XHCI_MAX_ENDPOINTS; n++) - XWRITE4(sc, door, XHCI_DOORBELL(index), n | XHCI_DB_SID_SET(0)); + for (n = 1; n != XHCI_MAX_ENDPOINTS; n++) { + for (p = 0; p != XHCI_MAX_STREAMS; p++) { + XWRITE4(sc, door, XHCI_DOORBELL(index), + n | XHCI_DB_SID_SET(p)); + } + } USB_BUS_UNLOCK(udev->bus); @@ -3948,8 +3972,12 @@ xhci_device_state_change(struct usb_devi if (sc->sc_hw.devs[index].state == XHCI_ST_DEFAULT) break; + /* set default state */ sc->sc_hw.devs[index].state = XHCI_ST_DEFAULT; + /* reset number of contexts */ + sc->sc_hw.devs[index].context_num = 0; + err = xhci_cmd_reset_dev(sc, index); if (err != 0) { @@ -3976,11 +4004,15 @@ xhci_device_state_change(struct usb_devi if (sc->sc_hw.devs[index].state == XHCI_ST_CONFIGURED) break; + /* set configured state */ sc->sc_hw.devs[index].state = XHCI_ST_CONFIGURED; + /* reset number of contexts */ + sc->sc_hw.devs[index].context_num = 0; + usbd_get_page(&sc->sc_hw.devs[index].input_pc, 0, &buf_inp); - xhci_configure_mask(udev, 1, 0); + xhci_configure_mask(udev, 3, 0); err = xhci_configure_device(udev); if (err != 0) { Modified: head/sys/dev/usb/controller/xhci.h ============================================================================== --- head/sys/dev/usb/controller/xhci.h Sat Dec 1 21:26:46 2012 (r243779) +++ head/sys/dev/usb/controller/xhci.h Sat Dec 1 22:13:38 2012 (r243780) @@ -394,7 +394,7 @@ struct xhci_hw_dev { uint8_t state; uint8_t nports; uint8_t tt; - uint8_t reserved; + uint8_t context_num; }; struct xhci_hw_softc {