tech-kern archive

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

Re: Patch: xhci controller driver improvements



On 08/12/14 07:45, Takahiro HAYASHI wrote:
Please send diff :)

Wait for a while plz.

lessprf.diff
  replaces most of device_printf.
  I define new macros DPRINTD and DPRINTDF. former prints
  args with device_xname(sc->sc_dev), latter prints args
  with device name and function name.

I'll dump my local misc patches too.

usb3.diff
  tries to make usb stack recognize super speed and
  make usbdevs(8) print super speed.
  This patch also adds XHCI_DEBUG flag to opt_usb.h.

lockmore.diff
  adds lock with sc_intr_lock to xhci_intr and xhci_poll.

lsmps.diff
  makes use 8 as wMaxPacketSize for LS when addressing device.
  http://mail-index.netbsd.org/source-changes/2013/03/20/msg042367.html


Thanks,
--
t-hash


--- xhci.c.orig 2014-08-12 09:00:14.000000000 +0900
+++ xhci.c      2014-08-12 09:03:53.000000000 +0900
@@ -59,9 +59,24 @@ __KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.2
 int xhcidebug = 0;
 #define DPRINTF(x)     do { if (xhcidebug) printf x; } while(0)
 #define DPRINTFN(n,x)  do { if (xhcidebug>(n)) printf x; } while (0)
+#define DPRINTD(n,fmt,...)     do {                            \
+       if (xhcidebug > (n)) {                                  \
+               printf("%s: " fmt,                              \
+                   device_xname(sc->sc_dev),## __VA_ARGS__);   \
+       }                                                       \
+    } while (0/*CONSTCOND*/)
+#define DPRINTDF(n,fmt,...)    do {                            \
+       if (xhcidebug > (n)) {                                  \
+               printf("%s: %s: " fmt,                          \
+                   device_xname(sc->sc_dev),                   \
+                   __FUNCTION__,## __VA_ARGS__);               \
+       }                                                       \
+    } while (0/*CONSTCOND*/)
 #else
 #define DPRINTF(x)
 #define DPRINTFN(n,x)
+#define DPRINTD(...) ((void)0)
+#define DPRINTDF(...) ((void)0)
 #endif
 
 #define XHCI_DCI_SLOT 0
@@ -857,7 +872,7 @@ xhci_intr(void *v)
        if (sc == NULL || sc->sc_dying || !device_has_power(sc->sc_dev))
                return 0;
 
-       DPRINTF(("%s: %s\n", __func__, device_xname(sc->sc_dev)));
+       DPRINTDF(16, "\n");
 
        /* If we get an interrupt while polling, then just ignore it. */
        if (sc->sc_bus.use_polling) {
@@ -917,13 +932,18 @@ xhci_configure_endpoint(usbd_pipe_handle
        usbd_status err;
        uint32_t *cp;
 
-       device_printf(sc->sc_dev, "%s dci %u (0x%x)\n", __func__, dci,
-           pipe->endpoint->edesc->bEndpointAddress);
+       DPRINTDF(0, "dci %u (0x%x (addr %u dir %s) xtype %u)\n",
+           dci, pipe->endpoint->edesc->bEndpointAddress,
+           UE_GET_ADDR(ed->bEndpointAddress),
+           UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN ? "in" : "out",
+           UE_GET_XFERTYPE(ed->bmAttributes)
+       );
 
        /* XXX ensure input context is available? */
 
        memset(xhci_slot_get_icv(sc, xs, 0), 0, sc->sc_pgsz);
 
+       /* set up initial input control context */
        cp = xhci_slot_get_icv(sc, xs, XHCI_ICI_INPUT_CONTROL);
        cp[0] = htole32(0);
        cp[1] = htole32(XHCI_INCTX_1_ADD_MASK(dci));
@@ -998,8 +1018,9 @@ xhci_reset_endpoint(usbd_pipe_handle pip
        struct xhci_trb trb;
        usbd_status err;
 
-       device_printf(sc->sc_dev, "%s\n", __func__);
+       DPRINTDF(0, "\n");
 
+       /* XXX byte order */
        trb.trb_0 = 0;
        trb.trb_2 = 0;
        trb.trb_3 = XHCI_TRB_3_SLOT_SET(xs->xs_idx) |
@@ -1021,8 +1042,9 @@ xhci_stop_endpoint(usbd_pipe_handle pipe
        usbd_status err;
        const u_int dci = xhci_ep_get_dci(pipe->endpoint->edesc);
 
-       device_printf(sc->sc_dev, "%s\n", __func__);
+       DPRINTDF(0, "\n");
 
+       /* XXX byte order */
        trb.trb_0 = 0;
        trb.trb_2 = 0;
        trb.trb_3 = XHCI_TRB_3_SLOT_SET(xs->xs_idx) |
@@ -1045,7 +1067,7 @@ xhci_set_dequeue(usbd_pipe_handle pipe)
        struct xhci_trb trb;
        usbd_status err;
 
-       device_printf(sc->sc_dev, "%s\n", __func__);
+       DPRINTDF(0, "\n");
 
        memset(xr->xr_trb, 0, xr->xr_ntrb * XHCI_TRB_SIZE);
        usb_syncmem(&xr->xr_dma, 0, xr->xr_ntrb * XHCI_TRB_SIZE,
@@ -1074,10 +1096,8 @@ xhci_open(usbd_pipe_handle pipe)
        const int8_t addr = dev->address;
        const uint8_t xfertype = UE_GET_XFERTYPE(ed->bmAttributes);
 
-       DPRINTF(("%s\n", __func__));
-       DPRINTF(("addr %d\n", addr));
-       device_printf(sc->sc_dev, "%s addr %d depth %d port %d speed %d\n",
-           __func__, addr, dev->depth, dev->powersrc->portno, dev->speed);
+       DPRINTDF(0, "addr %d depth %d port %d speed %d\n",
+           addr, dev->depth, dev->powersrc->portno, dev->speed);
 
        if (sc->sc_dying)
                return USBD_IOERROR;
@@ -1132,7 +1152,7 @@ xhci_rhpsc(struct xhci_softc * const sc,
        usbd_xfer_handle const xfer = sc->sc_intrxfer;
        uint8_t *p;
 
-       device_printf(sc->sc_dev, "port %u status change\n", port);
+       DPRINTD(0, "port %u status change\n", port);
 
        if (xfer == NULL)
                return;
@@ -1143,7 +1163,7 @@ xhci_rhpsc(struct xhci_softc * const sc,
 
        port -= sc->sc_hs_port_start;
        port += 1;
-       device_printf(sc->sc_dev, "hs port %u status change\n", port);
+       DPRINTD(0, "hs port %u status change\n", port);
 
        p = KERNADDR(&xfer->dmabuf, 0);
        memset(p, 0, xfer->length);
@@ -1159,16 +1179,15 @@ xhci_handle_event(struct xhci_softc * co
        uint64_t trb_0;
        uint32_t trb_2, trb_3;
 
-       DPRINTF(("%s: %s\n", __func__, device_xname(sc->sc_dev)));
+       DPRINTDF(16, "\n");
 
        trb_0 = le64toh(trb->trb_0);
        trb_2 = le32toh(trb->trb_2);
        trb_3 = le32toh(trb->trb_3);
 
 #if 0
-       device_printf(sc->sc_dev,
-           "event: %p 0x%016"PRIx64" 0x%08"PRIx32" 0x%08"PRIx32"\n", trb,
-           trb_0, trb_2, trb_3);
+       DPRINTD("event: %p 0x%016"PRIx64" 0x%08"PRIx32" 0x%08"PRIx32"\n",
+           trb, trb_0, trb_2, trb_3);
 #endif
 
        switch (XHCI_TRB_3_TYPE_GET(trb_3)){
@@ -1194,12 +1213,12 @@ xhci_handle_event(struct xhci_softc * co
                }
                xfer = &xx->xx_xfer;
 #if 0
-               device_printf(sc->sc_dev, "%s xfer %p\n", __func__, xfer);
+               DPRINTDF(0, "xfer %p\n", xfer);
 #endif
 
                if ((trb_3 & XHCI_TRB_3_ED_BIT) != 0) {
 #if 0
-                       device_printf(sc->sc_dev, "transfer event data: "
+                       DPRINTD(0, "transfer event data: "
                            "0x%016"PRIx64" 0x%08"PRIx32" %02x\n",
                            trb_0, XHCI_TRB_2_REM_GET(trb_2),
                            XHCI_TRB_2_ERROR_GET(trb_2));
@@ -1245,13 +1264,13 @@ xhci_handle_event(struct xhci_softc * co
                        sc->sc_result_trb.trb_3 = trb_3;
                        if (XHCI_TRB_2_ERROR_GET(trb_2) !=
                            XHCI_TRB_ERROR_SUCCESS) {
-                               device_printf(sc->sc_dev, "command completion "
+                               DPRINTD(0, "command completion "
                                    "failure: 0x%016"PRIx64" 0x%08"PRIx32" "
                                    "0x%08"PRIx32"\n", trb_0, trb_2, trb_3);
                        }
                        cv_signal(&sc->sc_command_cv);
                } else {
-                       device_printf(sc->sc_dev, "event: %p 0x%016"PRIx64" "
+                       DPRINTD(0, "event: %p 0x%016"PRIx64" "
                            "0x%08"PRIx32" 0x%08"PRIx32"\n", trb, trb_0,
                            trb_2, trb_3);
                }
@@ -1273,11 +1292,11 @@ xhci_softintr(void *v)
        struct xhci_trb *trb;
        int i, j, k;
 
-       DPRINTF(("%s: %s\n", __func__, device_xname(sc->sc_dev)));
-
        i = er->xr_ep;
        j = er->xr_cs;
 
+       DPRINTDF(16, "i=%d j=%d\n", i, j);
+
        while (1) {
                usb_syncmem(&er->xr_dma, XHCI_TRB_SIZE * i, XHCI_TRB_SIZE,
                    BUS_DMASYNC_POSTREAD);
@@ -1302,7 +1321,7 @@ xhci_softintr(void *v)
        xhci_rt_write_8(sc, XHCI_ERDP(0), xhci_ring_trbp(er, er->xr_ep) |
            XHCI_ERDP_LO_BUSY);
 
-       DPRINTF(("%s: %s ends\n", __func__, device_xname(sc->sc_dev)));
+       DPRINTDF(16, "ends\n");
 
        return;
 }
@@ -1312,7 +1331,7 @@ xhci_poll(struct usbd_bus *bus)
 {
        struct xhci_softc * const sc = bus->hci_private;
 
-       DPRINTF(("%s: %s\n", __func__, device_xname(sc->sc_dev)));
+       DPRINTDF(0, "\n");
 
        xhci_intr1(sc);
 
@@ -1325,7 +1344,7 @@ xhci_allocm(struct usbd_bus *bus, usb_dm
        struct xhci_softc * const sc = bus->hci_private;
        usbd_status err;
 
-       DPRINTF(("%s\n", __func__));
+       DPRINTDF(16, "\n");
 
        err = usb_allocmem_flags(&sc->sc_bus, size, 0, dma, 0);
 #if 0
@@ -1334,8 +1353,7 @@ xhci_allocm(struct usbd_bus *bus, usb_dm
 #endif
 #ifdef XHCI_DEBUG
        if (err)
-               device_printf(sc->sc_dev, "xhci_allocm: usb_allocmem()=%d\n",
-                   err);
+               DPRINTDF(0, "usb_allocmem()=%d\n", err);
 #endif
 
        return err;
@@ -1346,7 +1364,7 @@ xhci_freem(struct usbd_bus *bus, usb_dma
 {
        struct xhci_softc * const sc = bus->hci_private;
 
-//     DPRINTF(("%s\n", __func__));
+//     DPRINTDF(16, "\n");
 
 #if 0
        if (dma->block->flags & USB_DMA_RESERVE) {
@@ -1363,7 +1381,7 @@ xhci_allocx(struct usbd_bus *bus)
        struct xhci_softc * const sc = bus->hci_private;
        usbd_xfer_handle xfer;
 
-//     DPRINTF(("%s\n", __func__));
+//     DPRINTDF(16, "\n");
 
        xfer = pool_cache_get(sc->sc_xferpool, PR_NOWAIT);
        if (xfer != NULL) {
@@ -1381,12 +1399,12 @@ xhci_freex(struct usbd_bus *bus, usbd_xf
 {
        struct xhci_softc * const sc = bus->hci_private;
 
-//     DPRINTF(("%s\n", __func__));
+//     DPRINTDF(16, "\n");
 
 #ifdef DIAGNOSTIC
        if (xfer->busy_free != XFER_BUSY) {
-               device_printf(sc->sc_dev, "xhci_freex: xfer=%p "
-                   "not busy, 0x%08x\n", xfer, xfer->busy_free);
+               DPRINTDF(-1, "xfer=%p not busy, 0x%08x\n",
+                   xfer, xfer->busy_free);
        }
        xfer->busy_free = XFER_FREE;
 #endif
@@ -1419,6 +1437,8 @@ xhci_new_device(device_t parent, usbd_bu
        uint8_t slot;
        uint8_t addr;
 
+       DPRINTDF(1, "bus=%p port=%d depth=%d speed=%d up %p upport %d\n",
+                bus, port, depth, speed, up, up->portno);
        dev = malloc(sizeof *dev, M_USB, M_NOWAIT|M_ZERO);
        if (dev == NULL)
                return USBD_NOMEM;
@@ -1440,8 +1460,6 @@ xhci_new_device(device_t parent, usbd_bu
        /* doesn't matter, just don't let it uninitialized */
        dev->def_ep.datatoggle = 0;
 
-       device_printf(sc->sc_dev, "%s up %p portno %d\n", __func__, up,
-           up->portno);
 
        dev->quirks = &usbd_no_quirk;
        dev->address = 0;
@@ -1456,9 +1474,9 @@ xhci_new_device(device_t parent, usbd_bu
        for (adev = dev, hub = dev;
            hub != NULL;
            adev = hub, hub = hub->myhub) {
-               device_printf(sc->sc_dev, "%s hub %p\n", __func__, hub);
+               DPRINTDF(0, "hub %p\n", hub);
        }
-       device_printf(sc->sc_dev, "%s hub %p\n", __func__, hub);
+       DPRINTDF(0, "hub %p\n", hub);
 
        if (hub != NULL) {
                for (int p = 0; p < hub->hub->hubdesc.bNbrPorts; p++) {
@@ -1474,7 +1492,7 @@ xhci_new_device(device_t parent, usbd_bu
        } else {
                rhport += sc->sc_hs_port_start - 1;
        }
-       device_printf(sc->sc_dev, "%s rhport %d\n", __func__, rhport);
+       DPRINTDF(0, "rhport %d\n", rhport);
 
        dev->speed = speed;
        dev->langid = USBD_NOLANG;
@@ -1511,8 +1529,7 @@ xhci_new_device(device_t parent, usbd_bu
                cp = xhci_slot_get_dcv(sc, xs, XHCI_DCI_SLOT);
                //hexdump("slot context", cp, sc->sc_ctxsz);
                addr = XHCI_SCTX_3_DEV_ADDR_GET(cp[3]);
-               device_printf(sc->sc_dev, "%s device address %u\n",
-                   __func__, addr);
+               DPRINTDF(0, "device address %u\n", addr);
                /* XXX ensure we know when the hardware does something
                   we can't yet cope with */
                KASSERT(addr >= 1 && addr <= 127);
@@ -1531,8 +1548,7 @@ xhci_new_device(device_t parent, usbd_bu
                else
                        USETW(dev->def_ep_desc.wMaxPacketSize,
                            dd->bMaxPacketSize);
-               device_printf(sc->sc_dev, "%s bMaxPacketSize %u\n", __func__,
-                   dd->bMaxPacketSize);
+               DPRINTDF(0, "bMaxPacketSize %u\n", dd->bMaxPacketSize);
                xhci_update_ep0_mps(sc, xs,
                    UGETW(dev->def_ep_desc.wMaxPacketSize));
                err = usbd_reload_device_desc(dev);
@@ -1555,7 +1571,7 @@ xhci_new_device(device_t parent, usbd_bu
 
        if ((depth == 0) && (port == 0)) {
                usbd_attach_roothub(parent, dev);
-               device_printf(sc->sc_dev, "root_hub %p\n", bus->root_hub);
+               DPRINTD(-1, "root_hub %p\n", bus->root_hub);
                return USBD_NORMAL_COMPLETION;
        }
 
@@ -1613,17 +1629,18 @@ xhci_ring_put(struct xhci_softc * const 
 
        for (i = 0; i < ntrbs; i++) {
 #if 0
-               device_printf(sc->sc_dev, "%s %p %p %zu "
-                   "%016"PRIx64" %08"PRIx32" %08"PRIx32"\n", __func__, xr,
+               /* XXX byte order */
+               DPRINTDF(0, "%p %p %zu "
+                   "%016"PRIx64" %08"PRIx32" %08"PRIx32"\n", xr,
                    trbs, i, trbs[i].trb_0, trbs[i].trb_2, trbs[i].trb_3);
 #endif
+               /* XXX byte order */
                KASSERT(XHCI_TRB_3_TYPE_GET(trbs[i].trb_3) !=
                    XHCI_TRB_TYPE_LINK);
        }
 
 #if 0
-       device_printf(sc->sc_dev, "%s %p xr_ep 0x%x xr_cs %u\n", __func__,
-           xr, xr->xr_ep, xr->xr_cs);
+       DPRINTDF(0, "%p xr_ep 0x%x xr_cs %u\n", xr, xr->xr_ep, xr->xr_cs);
 #endif
 
        ri = xr->xr_ep;
@@ -1705,8 +1722,7 @@ xhci_ring_put(struct xhci_softc * const 
        xr->xr_cs = cs;
 
 #if 0
-       device_printf(sc->sc_dev, "%s %p xr_ep 0x%x xr_cs %u\n", __func__,
-           xr, xr->xr_ep, xr->xr_cs);
+       DPRINTDF(0, "%p xr_ep 0x%x xr_cs %u\n", xr, xr->xr_ep, xr->xr_cs);
 #endif
 }
 
@@ -1717,8 +1733,7 @@ xhci_do_command(struct xhci_softc * cons
        struct xhci_ring * const cr = &sc->sc_cr;
        usbd_status err;
 
-       device_printf(sc->sc_dev, "%s input: "
-           "0x%016"PRIx64" 0x%08"PRIx32" 0x%08"PRIx32"\n", __func__,
+       DPRINTDF(1, "input: 0x%016"PRIx64" 0x%08"PRIx32" 0x%08"PRIx32"\n",
            trb->trb_0, trb->trb_2, trb->trb_3);
 
        mutex_enter(&sc->sc_lock);
@@ -1742,8 +1757,7 @@ xhci_do_command(struct xhci_softc * cons
        trb->trb_2 = sc->sc_result_trb.trb_2;
        trb->trb_3 = sc->sc_result_trb.trb_3;
 
-       device_printf(sc->sc_dev, "%s output: "
-           "0x%016"PRIx64" 0x%08"PRIx32" 0x%08"PRIx32"\n", __func__,
+       DPRINTDF(1, "output: 0x%016"PRIx64" 0x%08"PRIx32" 0x%08"PRIx32"\n",
            trb->trb_0, trb->trb_2, trb->trb_3);
 
        switch (XHCI_TRB_2_ERROR_GET(trb->trb_2)) {
@@ -1810,7 +1824,7 @@ xhci_update_ep0_mps(struct xhci_softc * 
        usbd_status err;
        uint32_t * cp;
 
-       device_printf(sc->sc_dev, "%s\n", __func__);
+       DPRINTDF(0, "\n");
 
        cp = xhci_slot_get_icv(sc, xs, XHCI_ICI_INPUT_CONTROL);
        cp[0] = htole32(0);
@@ -1839,7 +1853,7 @@ xhci_set_dcba(struct xhci_softc * const 
 {
        uint64_t * const dcbaa = KERNADDR(&sc->sc_dcbaa_dma, 0);
 
-       device_printf(sc->sc_dev, "dcbaa %p dc %016"PRIx64" slot %d\n",
+       DPRINTD(0, "dcbaa: va %p pa %016"PRIx64" slot %d\n",
            &dcbaa[si], dcba, si);
 
        dcbaa[si] = htole64(dcba);
@@ -1858,6 +1872,8 @@ xhci_init_slot(struct xhci_softc * const
        uint32_t mps;
        uint32_t xspeed;
 
+       DPRINTDF(1, "slot %u depth %d speed %d port %d rhport %d\n",
+           slot, depth, speed, port, rhport);
        switch (speed) {
        case USB_SPEED_LOW:
                xspeed = 2;
@@ -1876,8 +1892,7 @@ xhci_init_slot(struct xhci_softc * const
                mps = USB_3_MAX_CTRL_PACKET;
                break;
        default:
-               device_printf(sc->sc_dev, "%s: impossible speed: %x",
-                   __func__, speed);
+               DPRINTDF(-1, "impossible speed 0x%x\n", speed);
                return USBD_INVAL;
        }
 
@@ -1905,7 +1920,7 @@ xhci_init_slot(struct xhci_softc * const
                err = xhci_ring_init(sc, &xs->xs_ep[dci].xe_tr,
                    XHCI_TRANSFER_RING_TRBS, XHCI_TRB_ALIGN);
                if (err) {
-                       device_printf(sc->sc_dev, "ring init failure\n");
+                       DPRINTD(-1, "ring init failure\n");
                        return err;
                }
        }
@@ -2051,7 +2066,7 @@ xhci_root_ctrl_transfer(usbd_xfer_handle
        struct xhci_softc * const sc = xfer->pipe->device->bus->hci_private;
        usbd_status err;
 
-       DPRINTF(("%s\n", __func__));
+       DPRINTDF(16, "\n");
 
        /* Insert last in queue. */
        mutex_enter(&sc->sc_lock);
@@ -2078,7 +2093,7 @@ xhci_root_ctrl_start(usbd_xfer_handle xf
        int port, i;
        uint32_t v;
 
-       DPRINTF(("%s\n", __func__));
+       DPRINTDF(16, "\n");
 
        if (sc->sc_dying)
                return USBD_IOERROR;
@@ -2092,8 +2107,8 @@ xhci_root_ctrl_start(usbd_xfer_handle xf
        if (len != 0)
                buf = KERNADDR(&xfer->dmabuf, 0);
 
-       DPRINTF(("root req: %02x %02x %04x %04x %04x\n", req->bmRequestType,
-           req->bRequest, value, index, len));
+       DPRINTD(1, "root req: %02x %02x %04x %04x %04x\n", req->bmRequestType,
+           req->bRequest, value, index, len);
 
 #define C(x,y) ((x) | ((y) << 8))
        switch(C(req->bRequest, req->bmRequestType)) {
@@ -2300,8 +2315,8 @@ xhci_root_ctrl_start(usbd_xfer_handle xf
                }
                v = xhci_op_read_4(sc, XHCI_PORTSC(sc->sc_hs_port_start - 1 +
                    index));
-               DPRINTF(("%s READ_CLASS_OTHER GET_STATUS PORTSC %d (%d) %08x\n",
-                   __func__, index, sc->sc_hs_port_start - 1 + index, v));
+               DPRINTDF(0, "READ_CLASS_OTHER GET_STATUS PORTSC %d (%d) %08x\n",
+                   index, sc->sc_hs_port_start - 1 + index, v);
                switch (XHCI_PS_SPEED_GET(v)) {
                case 1:
                        i = UPS_FULL_SPEED;
@@ -2412,7 +2426,7 @@ xhci_root_ctrl_abort(usbd_xfer_handle xf
 static void
 xhci_root_ctrl_close(usbd_pipe_handle pipe)
 {
-       DPRINTF(("%s\n", __func__));
+       DPRINTFN(1, ("%s\n", __func__));
        /* Nothing to do. */
 }
 
@@ -2527,10 +2541,10 @@ xhci_device_ctrl_start(usbd_xfer_handle 
        uint32_t control;
        u_int i;
 
-       DPRINTF(("%s\n", __func__));
-       DPRINTF(("req: %02x %02x %04x %04x %04x\n", req->bmRequestType,
+       DPRINTDF(16, "\n");
+       DPRINTD(1, "req: %02x %02x %04x %04x %04x\n", req->bmRequestType,
            req->bRequest, UGETW(req->wValue), UGETW(req->wIndex),
-           UGETW(req->wLength)));
+           UGETW(req->wLength));
 
        /* XXX */
        if (tr->is_halted) {
@@ -2603,7 +2617,7 @@ no_data:
        }
 
        if (sc->sc_bus.use_polling) {
-               device_printf(sc->sc_dev, "%s polling\n", __func__);
+               DPRINTDF(0, "polling\n");
                //xhci_waitintr(sc, xfer);
        }
 
@@ -2613,7 +2627,7 @@ no_data:
 static void
 xhci_device_ctrl_done(usbd_xfer_handle xfer)
 {
-       DPRINTF(("%s\n", __func__));
+       DPRINTFN(16, ("%s\n", __func__));
 
        callout_stop(&xfer->timeout_handle); /* XXX wrong place */
 
@@ -2622,13 +2636,16 @@ xhci_device_ctrl_done(usbd_xfer_handle x
 static void
 xhci_device_ctrl_abort(usbd_xfer_handle xfer)
 {
-       DPRINTF(("%s\n", __func__));
+#if defined(DIAGNOSTIC) || defined(XHCI_DEBUG)
+       struct xhci_softc * const sc = xfer->pipe->device->bus->hci_private;
+#endif
+       DPRINTDF(16, "\n");
 }
 
 static void
 xhci_device_ctrl_close(usbd_pipe_handle pipe)
 {
-       DPRINTF(("%s\n", __func__));
+       DPRINTFN(16, ("%s\n", __func__));
 }
 
 /* ----------------- */
@@ -2643,6 +2660,8 @@ xhci_device_bulk_transfer(usbd_xfer_hand
        struct xhci_softc * const sc = xfer->pipe->device->bus->hci_private;
        usbd_status err;
 
+       DPRINTDF(16, "\n");
+
        /* Insert last in queue. */
        mutex_enter(&sc->sc_lock);
        err = usb_insert_transfer(xfer);
@@ -2672,10 +2691,7 @@ xhci_device_bulk_start(usbd_xfer_handle 
        uint32_t control;
        u_int i = 0;
 
-#if 0
-       device_printf(sc->sc_dev, "%s %p slot %u dci %u\n", __func__, xfer,
-           xs->xs_idx, dci);
-#endif
+       DPRINTDF(16, "%p slot %u dci %u\n", xfer, xs->xs_idx, dci);
 
        if (sc->sc_dying)
                return USBD_IOERROR;
@@ -2709,7 +2725,7 @@ xhci_device_bulk_start(usbd_xfer_handle 
        xhci_db_write_4(sc, XHCI_DOORBELL(xs->xs_idx), dci);
 
        if (sc->sc_bus.use_polling) {
-               device_printf(sc->sc_dev, "%s polling\n", __func__);
+               DPRINTDF(0, "polling\n");
                //xhci_waitintr(sc, xfer);
        }
 
@@ -2719,18 +2735,15 @@ xhci_device_bulk_start(usbd_xfer_handle 
 static void
 xhci_device_bulk_done(usbd_xfer_handle xfer)
 {
-       //struct xhci_softc * const sc = xfer->pipe->device->bus->hci_private;
-       //struct xhci_slot * const xs = xfer->pipe->device->hci_private;
-       //const u_int dci = xhci_ep_get_dci(xfer->pipe->endpoint->edesc);
+#ifdef XHCI_DEBUG
+       struct xhci_softc * const sc = xfer->pipe->device->bus->hci_private;
+       struct xhci_slot * const xs = xfer->pipe->device->hci_private;
+       const u_int dci = xhci_ep_get_dci(xfer->pipe->endpoint->edesc);
+#endif
        const u_int endpt = xfer->pipe->endpoint->edesc->bEndpointAddress;
        const bool isread = UE_GET_DIR(endpt) == UE_DIR_IN;
 
-       DPRINTF(("%s\n", __func__));
-
-#if 0
-       device_printf(sc->sc_dev, "%s %p slot %u dci %u\n", __func__, xfer,
-           xs->xs_idx, dci);
-#endif
+       DPRINTDF(16, "%p slot %u dci %u\n", xfer, xs->xs_idx, dci);
 
        callout_stop(&xfer->timeout_handle); /* XXX wrong place */
 
@@ -2743,13 +2756,21 @@ xhci_device_bulk_done(usbd_xfer_handle x
 static void
 xhci_device_bulk_abort(usbd_xfer_handle xfer)
 {
-       DPRINTF(("%s\n", __func__));
+#if defined(DIAGNOSTIC) || defined(XHCI_DEBUG)
+       struct xhci_softc * const sc = xfer->pipe->device->bus->hci_private;
+#endif
+       DPRINTDF(16, "\n");
+
+       KASSERT(mutex_owned(&sc->sc_lock));
 }
 
 static void
 xhci_device_bulk_close(usbd_pipe_handle pipe)
 {
-       DPRINTF(("%s\n", __func__));
+#ifdef XHCI_DEBUG
+       struct xhci_softc * const sc = pipe->device->bus->hci_private;
+#endif
+       DPRINTDF(16, "\n");
 }
 
 /* --------------- */
@@ -2790,10 +2811,7 @@ xhci_device_intr_start(usbd_xfer_handle 
        uint32_t control;
        u_int i = 0;
 
-#if 0
-       device_printf(sc->sc_dev, "%s %p slot %u dci %u\n", __func__, xfer,
-           xs->xs_idx, dci);
-#endif
+       DPRINTDF(16, "%p slot %u dci %u\n", xfer, xs->xs_idx, dci);
 
        if (sc->sc_dying)
                return USBD_IOERROR;
@@ -2816,9 +2834,7 @@ xhci_device_intr_start(usbd_xfer_handle 
        xhci_db_write_4(sc, XHCI_DOORBELL(xs->xs_idx), dci);
 
        if (sc->sc_bus.use_polling) {
-#ifdef XHCI_DEBUG
-               device_printf(sc->sc_dev, "%s polling\n", __func__);
-#endif
+               DPRINTDF(0, "polling\n");
                //xhci_waitintr(sc, xfer);
        }
 
@@ -2836,12 +2852,8 @@ xhci_device_intr_done(usbd_xfer_handle x
 #endif
        const u_int endpt = xfer->pipe->endpoint->edesc->bEndpointAddress;
        const bool isread = UE_GET_DIR(endpt) == UE_DIR_IN;
-       DPRINTF(("%s\n", __func__));
 
-#ifdef XHCI_DEBUG
-       device_printf(sc->sc_dev, "%s %p slot %u dci %u\n", __func__, xfer,
-           xs->xs_idx, dci);
-#endif
+       DPRINTDF(16, "%p slot %u dci %u\n", xfer, xs->xs_idx, dci);
 
        KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
 
@@ -2868,10 +2880,9 @@ static void
 xhci_device_intr_abort(usbd_xfer_handle xfer)
 {
        struct xhci_softc * const sc = xfer->pipe->device->bus->hci_private;
-       DPRINTF(("%s\n", __func__));
+       DPRINTDF(16, "%p\n", xfer);
 
        KASSERT(mutex_owned(&sc->sc_lock));
-       device_printf(sc->sc_dev, "%s %p\n", __func__, xfer);
        KASSERT(xfer->pipe->intrxfer == xfer);
        xfer->status = USBD_CANCELLED;
        usb_transfer_complete(xfer);
@@ -2881,8 +2892,7 @@ static void
 xhci_device_intr_close(usbd_pipe_handle pipe)
 {
        struct xhci_softc * const sc = pipe->device->bus->hci_private;
-       DPRINTF(("%s\n", __func__));
-       device_printf(sc->sc_dev, "%s %p\n", __func__, pipe);
+       DPRINTDF(1, "pipe %p\n", pipe);
        xhci_unconfigure_endpoint(pipe);
 }
 
Index: src/sys/dev/usb/files.usb
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/files.usb,v
retrieving revision 1.132
diff -u -p -r1.132 files.usb
--- src/sys/dev/usb/files.usb   5 Apr 2014 23:47:26 -0000       1.132
+++ src/sys/dev/usb/files.usb   12 Aug 2014 00:20:52 -0000
@@ -6,7 +6,7 @@
 
 defflag        USBVERBOSE
 defflag        opt_usb.h       USB_FRAG_DMA_WORKAROUND
-defflag        opt_usb.h       EHCI_DEBUG OHCI_DEBUG UHCI_DEBUG UHUB_DEBUG 
USB_DEBUG
+defflag        opt_usb.h       EHCI_DEBUG OHCI_DEBUG UHCI_DEBUG UHUB_DEBUG 
USB_DEBUG XHCI_DEBUG
 
 defflag        opt_umodem.h    UMODEM_DEBUG
 defflag        opt_uvideo.h    UVIDEO_DEBUG
Index: src/sys/dev/usb/uhub.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/uhub.c,v
retrieving revision 1.124
diff -u -p -r1.124 uhub.c
--- src/sys/dev/usb/uhub.c      15 Sep 2013 15:33:47 -0000      1.124
+++ src/sys/dev/usb/uhub.c      12 Aug 2014 00:20:53 -0000
@@ -540,7 +540,9 @@ uhub_explore(usbd_device_handle dev)
                }
 
                /* Figure out device speed */
-               if (status & UPS_HIGH_SPEED)
+               if (status & UPS_SUPER_SPEED)
+                       speed = USB_SPEED_SUPER;
+               else if (status & UPS_HIGH_SPEED)
                        speed = USB_SPEED_HIGH;
                else if (status & UPS_LOW_SPEED)
                        speed = USB_SPEED_LOW;
Index: src/sys/dev/usb/usb.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/usb.c,v
retrieving revision 1.154
diff -u -p -r1.154 usb.c
--- src/sys/dev/usb/usb.c       25 Jul 2014 08:10:39 -0000      1.154
+++ src/sys/dev/usb/usb.c       12 Aug 2014 00:20:54 -0000
@@ -203,6 +203,7 @@ usb_attach(device_t parent, device_t sel
        case USBREV_1_0:
        case USBREV_1_1:
        case USBREV_2_0:
+       case USBREV_3_0:
                break;
        default:
                aprint_error(", not supported\n");
@@ -285,6 +286,9 @@ usb_doattach(device_t self)
        case USBREV_2_0:
                speed = USB_SPEED_HIGH;
                break;
+       case USBREV_3_0:
+               speed = USB_SPEED_SUPER;
+               break;
        default:
                panic("usb_doattach");
        }
Index: src/sys/dev/usb/usb.h
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/usb.h,v
retrieving revision 1.106
diff -u -p -r1.106 usb.h
--- src/sys/dev/usb/usb.h       1 Nov 2013 14:32:54 -0000       1.106
+++ src/sys/dev/usb/usb.h       12 Aug 2014 00:20:54 -0000
@@ -60,6 +60,7 @@ MALLOC_DECLARE(M_USBHC);
 #define AUE_DEBUG 1
 #define AUVITEK_I2C_DEBUG 1
 #define AXE_DEBUG 1
+#define AXEN_DEBUG 1
 #define CUE_DEBUG 1
 #define DWC2_DEBUG 1
 #define EHCI_DEBUG 1
@@ -125,6 +126,7 @@ MALLOC_DECLARE(M_USBHC);
 #define UVSCOM_DEBUG 1
 #define UYUREX_DEBUG 1
 #define UZCOM_DEBUG 1
+#define XHCI_DEBUG 1
 #define ZYD_DEBUG 1
 #define Static
 #else
@@ -497,6 +499,7 @@ typedef struct {
 #define UPS_FULL_SPEED                 0x0000  /* for completeness */
 #define UPS_LOW_SPEED                  0x0200
 #define UPS_HIGH_SPEED                 0x0400
+#define UPS_SUPER_SPEED                0x0600
 #define UPS_PORT_TEST                  0x0800
 #define UPS_PORT_INDICATOR             0x1000
        uWord           wPortChange;
Index: src/sys/dev/usb/usbdivar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/usbdivar.h,v
retrieving revision 1.107
diff -u -p -r1.107 usbdivar.h
--- src/sys/dev/usb/usbdivar.h  3 Oct 2013 19:04:00 -0000       1.107
+++ src/sys/dev/usb/usbdivar.h  12 Aug 2014 00:20:54 -0000
@@ -164,7 +164,8 @@ struct usbd_bus {
 #define USBREV_1_0     2
 #define USBREV_1_1     3
 #define USBREV_2_0     4
-#define USBREV_STR { "unknown", "pre 1.0", "1.0", "1.1", "2.0" }
+#define USBREV_3_0     5
+#define USBREV_STR { "unknown", "pre 1.0", "1.0", "1.1", "2.0", "3.0" }
 
        void                   *soft; /* soft interrupt cookie */
        bus_dma_tag_t           dmatag; /* DMA tag */
Index: src/usr.sbin/usbdevs/usbdevs.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/usbdevs/usbdevs.c,v
retrieving revision 1.30
diff -u -p -r1.30 usbdevs.c
--- src/usr.sbin/usbdevs/usbdevs.c      14 Sep 2013 14:07:56 -0000      1.30
+++ src/usr.sbin/usbdevs/usbdevs.c      8 Jun 2014 17:29:02 -0000
@@ -98,6 +98,7 @@ usbdev(int f, int a, int rec)
        struct usb_device_info di;
        int e, p, i;
 
+       memset(&di, 0, sizeof(di));
        di.udi_addr = a;
        e = ioctl(f, USB_DEVICEINFO, &di);
        if (e) {
@@ -112,6 +113,7 @@ usbdev(int f, int a, int rec)
                case USB_SPEED_LOW:  printf("low speed, "); break;
                case USB_SPEED_FULL: printf("full speed, "); break;
                case USB_SPEED_HIGH: printf("high speed, "); break;
+               case USB_SPEED_SUPER: printf("super speed, "); break;
                default: break;
                }
                if (di.udi_power)
--- xhci.c.orig 2014-08-11 20:14:13.000000000 +0900
+++ xhci.c      2014-08-12 16:29:09.000000000 +0900
@@ -868,10 +852,16 @@ int
 xhci_intr(void *v)
 {
        struct xhci_softc * const sc = v;
+       int ret = 0;
 
-       if (sc == NULL || sc->sc_dying || !device_has_power(sc->sc_dev))
+       if (sc == NULL)
                return 0;
 
+       mutex_spin_enter(&sc->sc_intr_lock);
+
+       if (sc->sc_dying || !device_has_power(sc->sc_dev))
+               goto done;
+
        DPRINTDF(16, "\n");
 
        /* If we get an interrupt while polling, then just ignore it. */
@@ -879,10 +869,13 @@ xhci_intr(void *v)
 #ifdef DIAGNOSTIC
                DPRINTFN(16, ("xhci_intr: ignored interrupt while polling\n"));
 #endif
-               return 0;
+               goto done;
        }
 
-       return xhci_intr1(sc);
+       ret = xhci_intr1(sc);
+done:
+       mutex_spin_exit(&sc->sc_intr_lock);
+       return ret;
 }
 
 int
@@ -1333,7 +1713,9 @@ xhci_poll(struct usbd_bus *bus)
 
        DPRINTDF(0, "\n");
 
+       mutex_spin_enter(&sc->sc_intr_lock);
        xhci_intr1(sc);
+       mutex_spin_exit(&sc->sc_intr_lock);
 
        return;
 }
--- xhci.c.orig 2014-08-11 20:14:13.000000000 +0900
+++ xhci.c      2014-08-12 16:29:09.000000000 +0900
@@ -1454,6 +1836,9 @@ xhci_new_device(device_t parent, usbd_bu
        dev->def_ep_desc.bEndpointAddress = USB_CONTROL_ENDPOINT;
        dev->def_ep_desc.bmAttributes = UE_CONTROL;
        /* XXX */
+       if (speed == USB_SPEED_LOW)
+               USETW(dev->def_ep_desc.wMaxPacketSize, USB_MAX_IPACKET);
+       else
        USETW(dev->def_ep_desc.wMaxPacketSize, 64);
        dev->def_ep_desc.bInterval = 0;
 


Home | Main Index | Thread Index | Old Index