1 /* $NetBSD: uhci.c,v 1.80 2000/01/19 01:16:38 augustss Exp $ */
2 /* $FreeBSD: src/sys/dev/usb/uhci.c,v 1.40.2.10 2003/01/12 02:13:58 iedowse Exp $ */
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson (lennart@augustsson.net) at
10 * Carlstedt Research & Technology.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
42 * USB Universal Host Controller driver.
43 * Handles e.g. PIIX3 and PIIX4.
45 * UHCI spec: http://www.intel.com/design/usb/uhci11d.pdf
46 * USB spec: http://www.usb.org/developers/data/usb11.pdf
47 * PIIXn spec: ftp://download.intel.com/design/intarch/datashts/29055002.pdf
48 * ftp://download.intel.com/design/intarch/datashts/29056201.pdf
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/kernel.h>
54 #include <sys/malloc.h>
55 #if defined(__NetBSD__) || defined(__OpenBSD__)
56 #include <sys/device.h>
57 #include <sys/select.h>
58 #elif defined(__FreeBSD__)
59 #include <sys/module.h>
61 #include <machine/bus_pio.h>
62 #if defined(DIAGNOSTIC) && defined(__i386__)
63 #include <machine/cpu.h>
67 #include <sys/queue.h>
68 #include <sys/sysctl.h>
70 #include <machine/bus.h>
71 #include <machine/endian.h>
73 #include <dev/usb/usb.h>
74 #include <dev/usb/usbdi.h>
75 #include <dev/usb/usbdivar.h>
76 #include <dev/usb/usb_mem.h>
77 #include <dev/usb/usb_quirks.h>
79 #include <dev/usb/uhcireg.h>
80 #include <dev/usb/uhcivar.h>
82 #if defined(__FreeBSD__)
83 #include <machine/clock.h>
85 #define delay(d) DELAY(d)
88 #define MS_TO_TICKS(ms) ((ms) * hz / 1000)
90 #if defined(__OpenBSD__)
91 struct cfdriver uhci_cd = {
97 #define DPRINTF(x) if (uhcidebug) printf x
98 #define DPRINTFN(n,x) if (uhcidebug>(n)) printf x
100 SYSCTL_NODE(_hw_usb, OID_AUTO, uhci, CTLFLAG_RW, 0, "USB uhci");
101 SYSCTL_INT(_hw_usb_uhci, OID_AUTO, debug, CTLFLAG_RW,
102 &uhcidebug, 0, "uhci debug level");
105 #define DPRINTFN(n,x)
109 * The UHCI controller is little endian, so on big endian machines
110 * the data strored in memory needs to be swapped.
112 #if BYTE_ORDER == BIG_ENDIAN
113 #define LE(x) (bswap32(x))
119 struct usbd_pipe pipe;
120 uhci_intr_info_t *iinfo;
122 /* Info needed for different pipe kinds. */
128 uhci_soft_td_t *setup, *stat;
134 uhci_soft_qh_t **qhs;
144 uhci_soft_td_t **stds;
151 * The uhci_intr_info free list can be global since they contain
152 * no dma specific data. The other free lists do.
154 LIST_HEAD(, uhci_intr_info) uhci_ii_free;
156 Static void uhci_busreset(uhci_softc_t *);
157 Static usbd_status uhci_run(uhci_softc_t *, int run);
158 Static uhci_soft_td_t *uhci_alloc_std(uhci_softc_t *);
159 Static void uhci_free_std(uhci_softc_t *, uhci_soft_td_t *);
160 Static uhci_soft_qh_t *uhci_alloc_sqh(uhci_softc_t *);
161 Static void uhci_free_sqh(uhci_softc_t *, uhci_soft_qh_t *);
162 Static uhci_intr_info_t *uhci_alloc_intr_info(uhci_softc_t *);
163 Static void uhci_free_intr_info(uhci_intr_info_t *ii);
165 Static void uhci_enter_ctl_q(uhci_softc_t *, uhci_soft_qh_t *,
167 Static void uhci_exit_ctl_q(uhci_softc_t *, uhci_soft_qh_t *);
170 Static void uhci_free_std_chain(uhci_softc_t *,
171 uhci_soft_td_t *, uhci_soft_td_t *);
172 Static usbd_status uhci_alloc_std_chain(struct uhci_pipe *,
173 uhci_softc_t *, int, int, u_int16_t, usb_dma_t *,
174 uhci_soft_td_t **, uhci_soft_td_t **);
175 Static void uhci_timo(void *);
176 Static void uhci_waitintr(uhci_softc_t *, usbd_xfer_handle);
177 Static void uhci_check_intr(uhci_softc_t *, uhci_intr_info_t *);
178 Static void uhci_idone(uhci_intr_info_t *);
180 Static void uhci_abort_xfer(usbd_xfer_handle, usbd_status status);
181 Static void uhci_abort_xfer_end(void *v);
183 Static void uhci_timeout(void *);
184 Static void uhci_lock_frames(uhci_softc_t *);
185 Static void uhci_unlock_frames(uhci_softc_t *);
186 Static void uhci_add_ctrl(uhci_softc_t *, uhci_soft_qh_t *);
187 Static void uhci_add_bulk(uhci_softc_t *, uhci_soft_qh_t *);
188 Static void uhci_remove_ctrl(uhci_softc_t *,uhci_soft_qh_t *);
189 Static void uhci_remove_bulk(uhci_softc_t *,uhci_soft_qh_t *);
190 Static int uhci_str(usb_string_descriptor_t *, int, char *);
192 Static usbd_status uhci_setup_isoc(usbd_pipe_handle pipe);
193 Static void uhci_device_isoc_enter(usbd_xfer_handle);
195 Static usbd_status uhci_allocm(struct usbd_bus *, usb_dma_t *, u_int32_t);
196 Static void uhci_freem(struct usbd_bus *, usb_dma_t *);
198 Static usbd_xfer_handle uhci_allocx(struct usbd_bus *);
199 Static void uhci_freex(struct usbd_bus *, usbd_xfer_handle);
201 Static usbd_status uhci_device_ctrl_transfer(usbd_xfer_handle);
202 Static usbd_status uhci_device_ctrl_start(usbd_xfer_handle);
203 Static void uhci_device_ctrl_abort(usbd_xfer_handle);
204 Static void uhci_device_ctrl_close(usbd_pipe_handle);
205 Static void uhci_device_ctrl_done (usbd_xfer_handle);
207 Static usbd_status uhci_device_intr_transfer(usbd_xfer_handle);
208 Static usbd_status uhci_device_intr_start(usbd_xfer_handle);
209 Static void uhci_device_intr_abort(usbd_xfer_handle);
210 Static void uhci_device_intr_close(usbd_pipe_handle);
211 Static void uhci_device_intr_done (usbd_xfer_handle);
213 Static usbd_status uhci_device_bulk_transfer(usbd_xfer_handle);
214 Static usbd_status uhci_device_bulk_start(usbd_xfer_handle);
215 Static void uhci_device_bulk_abort(usbd_xfer_handle);
216 Static void uhci_device_bulk_close(usbd_pipe_handle);
217 Static void uhci_device_bulk_done (usbd_xfer_handle);
219 Static usbd_status uhci_device_isoc_transfer(usbd_xfer_handle);
220 Static usbd_status uhci_device_isoc_start(usbd_xfer_handle);
221 Static void uhci_device_isoc_abort(usbd_xfer_handle);
222 Static void uhci_device_isoc_close(usbd_pipe_handle);
223 Static void uhci_device_isoc_done (usbd_xfer_handle);
225 Static usbd_status uhci_root_ctrl_transfer(usbd_xfer_handle);
226 Static usbd_status uhci_root_ctrl_start(usbd_xfer_handle);
227 Static void uhci_root_ctrl_abort(usbd_xfer_handle);
228 Static void uhci_root_ctrl_close(usbd_pipe_handle);
230 Static usbd_status uhci_root_intr_transfer(usbd_xfer_handle);
231 Static usbd_status uhci_root_intr_start(usbd_xfer_handle);
232 Static void uhci_root_intr_abort(usbd_xfer_handle);
233 Static void uhci_root_intr_close(usbd_pipe_handle);
234 Static void uhci_root_intr_done (usbd_xfer_handle);
236 Static usbd_status uhci_open(usbd_pipe_handle);
237 Static void uhci_poll(struct usbd_bus *);
239 Static usbd_status uhci_device_request(usbd_xfer_handle xfer);
241 Static void uhci_add_intr(uhci_softc_t *, int, uhci_soft_qh_t *);
242 Static void uhci_remove_intr(uhci_softc_t *, int, uhci_soft_qh_t *);
243 Static usbd_status uhci_device_setintr(uhci_softc_t *sc,
244 struct uhci_pipe *pipe, int ival);
246 Static void uhci_device_clear_toggle(usbd_pipe_handle pipe);
247 Static void uhci_noop(usbd_pipe_handle pipe);
250 Static void uhci_dumpregs(uhci_softc_t *);
251 Static void uhci_dump_qhs(uhci_soft_qh_t *);
252 Static void uhci_dump_qh(uhci_soft_qh_t *);
253 Static void uhci_dump_tds(uhci_soft_td_t *);
254 Static void uhci_dump_td(uhci_soft_td_t *);
257 #define UWRITE1(sc, r, x) bus_space_write_1((sc)->iot, (sc)->ioh, (r), (x))
258 #define UWRITE2(sc, r, x) bus_space_write_2((sc)->iot, (sc)->ioh, (r), (x))
259 #define UWRITE4(sc, r, x) bus_space_write_4((sc)->iot, (sc)->ioh, (r), (x))
260 #define UREAD1(sc, r) bus_space_read_1((sc)->iot, (sc)->ioh, (r))
261 #define UREAD2(sc, r) bus_space_read_2((sc)->iot, (sc)->ioh, (r))
262 #define UREAD4(sc, r) bus_space_read_4((sc)->iot, (sc)->ioh, (r))
264 #define UHCICMD(sc, cmd) UWRITE2(sc, UHCI_CMD, cmd)
265 #define UHCISTS(sc) UREAD2(sc, UHCI_STS)
267 #define UHCI_RESET_TIMEOUT 100 /* reset timeout */
269 #define UHCI_CURFRAME(sc) (UREAD2(sc, UHCI_FRNUM) & UHCI_FRNUM_MASK)
271 #define UHCI_INTR_ENDPT 1
273 struct usbd_bus_methods uhci_bus_methods = {
282 struct usbd_pipe_methods uhci_root_ctrl_methods = {
283 uhci_root_ctrl_transfer,
284 uhci_root_ctrl_start,
285 uhci_root_ctrl_abort,
286 uhci_root_ctrl_close,
291 struct usbd_pipe_methods uhci_root_intr_methods = {
292 uhci_root_intr_transfer,
293 uhci_root_intr_start,
294 uhci_root_intr_abort,
295 uhci_root_intr_close,
300 struct usbd_pipe_methods uhci_device_ctrl_methods = {
301 uhci_device_ctrl_transfer,
302 uhci_device_ctrl_start,
303 uhci_device_ctrl_abort,
304 uhci_device_ctrl_close,
306 uhci_device_ctrl_done,
309 struct usbd_pipe_methods uhci_device_intr_methods = {
310 uhci_device_intr_transfer,
311 uhci_device_intr_start,
312 uhci_device_intr_abort,
313 uhci_device_intr_close,
314 uhci_device_clear_toggle,
315 uhci_device_intr_done,
318 struct usbd_pipe_methods uhci_device_bulk_methods = {
319 uhci_device_bulk_transfer,
320 uhci_device_bulk_start,
321 uhci_device_bulk_abort,
322 uhci_device_bulk_close,
323 uhci_device_clear_toggle,
324 uhci_device_bulk_done,
327 struct usbd_pipe_methods uhci_device_isoc_methods = {
328 uhci_device_isoc_transfer,
329 uhci_device_isoc_start,
330 uhci_device_isoc_abort,
331 uhci_device_isoc_close,
333 uhci_device_isoc_done,
337 uhci_busreset(uhci_softc_t *sc)
339 UHCICMD(sc, UHCI_CMD_GRESET); /* global reset */
340 usb_delay_ms(&sc->sc_bus, USB_BUS_RESET_DELAY); /* wait a little */
341 UHCICMD(sc, 0); /* do nothing */
345 uhci_init(uhci_softc_t *sc)
349 uhci_soft_qh_t *csqh, *bsqh, *sqh;
352 DPRINTFN(1,("uhci_init: start\n"));
359 uhci_run(sc, 0); /* stop the controller */
360 UWRITE2(sc, UHCI_INTR, 0); /* disable interrupts */
364 /* Allocate and initialize real frame array. */
365 err = usb_allocmem(&sc->sc_bus,
366 UHCI_FRAMELIST_COUNT * sizeof(uhci_physaddr_t),
367 UHCI_FRAMELIST_ALIGN, &sc->sc_dma);
370 sc->sc_pframes = KERNADDR(&sc->sc_dma, 0);
371 UWRITE2(sc, UHCI_FRNUM, 0); /* set frame number to 0 */
372 UWRITE4(sc, UHCI_FLBASEADDR, DMAADDR(&sc->sc_dma, 0)); /* set frame list*/
374 /* Allocate the dummy QH where bulk traffic will be queued. */
375 bsqh = uhci_alloc_sqh(sc);
378 bsqh->qh.qh_hlink = LE(UHCI_PTR_T); /* end of QH chain */
379 bsqh->qh.qh_elink = LE(UHCI_PTR_T);
380 sc->sc_bulk_start = sc->sc_bulk_end = bsqh;
382 /* Allocate the dummy QH where control traffic will be queued. */
383 csqh = uhci_alloc_sqh(sc);
387 csqh->qh.qh_hlink = LE(bsqh->physaddr | UHCI_PTR_Q);
388 csqh->qh.qh_elink = LE(UHCI_PTR_T);
389 sc->sc_ctl_start = sc->sc_ctl_end = csqh;
392 * Make all (virtual) frame list pointers point to the interrupt
393 * queue heads and the interrupt queue heads at the control
394 * queue head and point the physical frame list to the virtual.
396 for(i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
397 std = uhci_alloc_std(sc);
398 sqh = uhci_alloc_sqh(sc);
399 if (std == NULL || sqh == NULL)
402 std->td.td_link = LE(sqh->physaddr | UHCI_PTR_Q);
403 std->td.td_status = LE(UHCI_TD_IOS); /* iso, inactive */
404 std->td.td_token = LE(0);
405 std->td.td_buffer = LE(0);
407 sqh->qh.qh_hlink = LE(csqh->physaddr | UHCI_PTR_Q);
409 sqh->qh.qh_elink = LE(UHCI_PTR_T);
410 sc->sc_vframes[i].htd = std;
411 sc->sc_vframes[i].etd = std;
412 sc->sc_vframes[i].hqh = sqh;
413 sc->sc_vframes[i].eqh = sqh;
415 j < UHCI_FRAMELIST_COUNT;
416 j += UHCI_VFRAMELIST_COUNT)
417 sc->sc_pframes[j] = LE(std->physaddr);
420 LIST_INIT(&sc->sc_intrhead);
422 SIMPLEQ_INIT(&sc->sc_free_xfers);
424 /* Set up the bus struct. */
425 sc->sc_bus.methods = &uhci_bus_methods;
426 sc->sc_bus.pipe_size = sizeof(struct uhci_pipe);
428 sc->sc_suspend = PWR_RESUME;
429 #if defined(__NetBSD__)
430 sc->sc_powerhook = powerhook_establish(uhci_power, sc);
431 sc->sc_shutdownhook = shutdownhook_establish(uhci_shutdown, sc);
433 DPRINTFN(1,("uhci_init: enabling\n"));
434 UWRITE2(sc, UHCI_INTR, UHCI_INTR_TOCRCIE | UHCI_INTR_RIE |
435 UHCI_INTR_IOCE | UHCI_INTR_SPIE); /* enable interrupts */
437 UHCICMD(sc, UHCI_CMD_MAXP); /* Assume 64 byte packets at frame end */
439 return (uhci_run(sc, 1)); /* and here we go... */
442 #if defined(__NetBSD__) || defined(__OpenBSD__)
444 uhci_activate(device_ptr_t self, enum devact act)
446 struct uhci_softc *sc = (struct uhci_softc *)self;
454 case DVACT_DEACTIVATE:
455 if (sc->sc_child != NULL)
456 rv = config_deactivate(sc->sc_child);
463 uhci_detach(struct uhci_softc *sc, int flags)
465 usbd_xfer_handle xfer;
468 if (sc->sc_child != NULL)
469 rv = config_detach(sc->sc_child, flags);
474 #if defined(__NetBSD__)
475 powerhook_disestablish(sc->sc_powerhook);
476 shutdownhook_disestablish(sc->sc_shutdownhook);
479 /* Free all xfers associated with this HC. */
481 xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers);
484 SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, xfer, next);
488 /* XXX free other data structures XXX */
495 uhci_allocm(struct usbd_bus *bus, usb_dma_t *dma, u_int32_t size)
497 return (usb_allocmem(&((struct uhci_softc *)bus)->sc_bus, size, 0,
502 uhci_freem(struct usbd_bus *bus, usb_dma_t *dma)
504 usb_freemem(&((struct uhci_softc *)bus)->sc_bus, dma);
508 uhci_allocx(struct usbd_bus *bus)
510 struct uhci_softc *sc = (struct uhci_softc *)bus;
511 usbd_xfer_handle xfer;
513 xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers);
515 SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, xfer, next);
517 xfer = malloc(sizeof(*xfer), M_USB, M_NOWAIT);
519 memset(xfer, 0, sizeof *xfer);
524 uhci_freex(struct usbd_bus *bus, usbd_xfer_handle xfer)
526 struct uhci_softc *sc = (struct uhci_softc *)bus;
528 SIMPLEQ_INSERT_HEAD(&sc->sc_free_xfers, xfer, next);
532 * Shut down the controller when the system is going down.
535 uhci_shutdown(void *v)
537 uhci_softc_t *sc = v;
539 DPRINTF(("uhci_shutdown: stopping the HC\n"));
540 uhci_run(sc, 0); /* stop the controller */
544 * Handle suspend/resume.
546 * We need to switch to polling mode here, because this routine is
547 * called from an intterupt context. This is all right since we
548 * are almost suspended anyway.
551 uhci_power(int why, void *v)
553 uhci_softc_t *sc = v;
558 cmd = UREAD2(sc, UHCI_CMD);
560 DPRINTF(("uhci_power: sc=%p, why=%d (was %d), cmd=0x%x\n",
561 sc, why, sc->sc_suspend, cmd));
563 if (why != PWR_RESUME) {
568 if (sc->sc_has_timo != NULL)
569 usb_untimeout(uhci_timo, sc->sc_has_timo,
570 sc->sc_has_timo->timo_handle);
571 sc->sc_bus.use_polling++;
572 uhci_run(sc, 0); /* stop the controller */
574 /* save some state if BIOS doesn't */
575 sc->sc_saved_frnum = UREAD2(sc, UHCI_FRNUM);
576 sc->sc_saved_sof = UREAD1(sc, UHCI_SOF);
578 UHCICMD(sc, cmd | UHCI_CMD_EGSM); /* enter global suspend */
579 usb_delay_ms(&sc->sc_bus, USB_RESUME_WAIT);
580 sc->sc_suspend = why;
581 sc->sc_bus.use_polling--;
582 DPRINTF(("uhci_power: cmd=0x%x\n", UREAD2(sc, UHCI_CMD)));
585 if (sc->sc_suspend == PWR_RESUME)
586 printf("uhci_power: weird, resume without suspend.\n");
588 sc->sc_bus.use_polling++;
589 sc->sc_suspend = why;
590 if (cmd & UHCI_CMD_RS)
591 uhci_run(sc, 0); /* in case BIOS has started it */
593 /* restore saved state */
594 UWRITE4(sc, UHCI_FLBASEADDR, DMAADDR(&sc->sc_dma, 0));
595 UWRITE2(sc, UHCI_FRNUM, sc->sc_saved_frnum);
596 UWRITE1(sc, UHCI_SOF, sc->sc_saved_sof);
598 UHCICMD(sc, cmd | UHCI_CMD_FGR); /* force global resume */
599 usb_delay_ms(&sc->sc_bus, USB_RESUME_DELAY);
600 UHCICMD(sc, cmd & ~UHCI_CMD_EGSM); /* back to normal */
601 UWRITE2(sc, UHCI_INTR, UHCI_INTR_TOCRCIE | UHCI_INTR_RIE |
602 UHCI_INTR_IOCE | UHCI_INTR_SPIE); /* re-enable intrs */
603 UHCICMD(sc, UHCI_CMD_MAXP);
604 uhci_run(sc, 1); /* and start traffic again */
605 usb_delay_ms(&sc->sc_bus, USB_RESUME_RECOVERY);
606 sc->sc_bus.use_polling--;
607 if (sc->sc_has_timo != NULL)
608 usb_timeout(uhci_timo, sc->sc_has_timo,
609 sc->sc_ival, sc->sc_has_timo->timo_handle);
620 uhci_dumpregs(uhci_softc_t *sc)
622 DPRINTFN(-1,("%s regs: cmd=%04x, sts=%04x, intr=%04x, frnum=%04x, "
623 "flbase=%08x, sof=%04x, portsc1=%04x, portsc2=%04x\n",
624 USBDEVNAME(sc->sc_bus.bdev),
625 UREAD2(sc, UHCI_CMD),
626 UREAD2(sc, UHCI_STS),
627 UREAD2(sc, UHCI_INTR),
628 UREAD2(sc, UHCI_FRNUM),
629 UREAD4(sc, UHCI_FLBASEADDR),
630 UREAD1(sc, UHCI_SOF),
631 UREAD2(sc, UHCI_PORTSC1),
632 UREAD2(sc, UHCI_PORTSC2)));
636 uhci_dump_td(uhci_soft_td_t *p)
638 DPRINTFN(-1,("TD(%p) at %08lx = link=0x%08lx status=0x%08lx "
639 "token=0x%08lx buffer=0x%08lx\n",
640 p, (long)p->physaddr,
641 (long)LE(p->td.td_link),
642 (long)LE(p->td.td_status),
643 (long)LE(p->td.td_token),
644 (long)LE(p->td.td_buffer)));
645 DPRINTFN(-1,(" %b %b,errcnt=%d,actlen=%d pid=%02x,addr=%d,endpt=%d,"
647 (int)LE(p->td.td_link),
649 (int)LE(p->td.td_status),
650 "\20\22BITSTUFF\23CRCTO\24NAK\25BABBLE\26DBUFFER\27"
651 "STALLED\30ACTIVE\31IOC\32ISO\33LS\36SPD",
652 UHCI_TD_GET_ERRCNT(LE(p->td.td_status)),
653 UHCI_TD_GET_ACTLEN(LE(p->td.td_status)),
654 UHCI_TD_GET_PID(LE(p->td.td_token)),
655 UHCI_TD_GET_DEVADDR(LE(p->td.td_token)),
656 UHCI_TD_GET_ENDPT(LE(p->td.td_token)),
657 UHCI_TD_GET_DT(LE(p->td.td_token)),
658 UHCI_TD_GET_MAXLEN(LE(p->td.td_token))));
662 uhci_dump_qh(uhci_soft_qh_t *sqh)
664 DPRINTFN(-1,("QH(%p) at %08x: hlink=%08x elink=%08x\n", sqh,
665 (int)sqh->physaddr, LE(sqh->qh.qh_hlink), LE(sqh->qh.qh_elink)));
673 uhci_softc_t *sc = uhci;
676 printf("intrs=%d\n", sc->sc_bus.no_intrs);
677 printf("framelist[i].link = %08x\n", sc->sc_framelist[0].link);
678 uhci_dump_qh(sc->sc_ctl_start->qh.hlink);
684 uhci_dump_qhs(uhci_soft_qh_t *sqh)
688 /* uhci_dump_qhs displays all the QHs and TDs from the given QH onwards
689 * Traverses sideways first, then down.
699 * TD2.x being the TDs queued at QH2 and QH1 being referenced from QH1.
703 if (sqh->hlink != NULL && !(sqh->qh.qh_hlink & UHCI_PTR_T))
704 uhci_dump_qhs(sqh->hlink);
706 DPRINTF(("No QH\n"));
708 if (sqh->elink != NULL && !(sqh->qh.qh_elink & UHCI_PTR_T))
709 uhci_dump_tds(sqh->elink);
711 DPRINTF(("No TD\n"));
715 uhci_dump_tds(uhci_soft_td_t *std)
719 for(td = std; td != NULL; td = td->link.std) {
722 /* Check whether the link pointer in this TD marks
723 * the link pointer as end of queue. This avoids
724 * printing the free list in case the queue/TD has
725 * already been moved there (seatbelt).
727 if (td->td.td_link & UHCI_PTR_T ||
735 * This routine is executed periodically and simulates interrupts
736 * from the root controller interrupt pipe for port status change.
739 uhci_timo(void *addr)
741 usbd_xfer_handle xfer = addr;
742 usbd_pipe_handle pipe = xfer->pipe;
743 uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
747 DPRINTFN(20, ("uhci_timo\n"));
749 usb_timeout(uhci_timo, xfer, sc->sc_ival, xfer->timo_handle);
751 p = KERNADDR(&xfer->dmabuf, 0);
753 if (UREAD2(sc, UHCI_PORTSC1) & (UHCI_PORTSC_CSC|UHCI_PORTSC_OCIC))
755 if (UREAD2(sc, UHCI_PORTSC2) & (UHCI_PORTSC_CSC|UHCI_PORTSC_OCIC))
758 /* No change, try again in a while */
762 xfer->status = USBD_NORMAL_COMPLETION;
765 xfer->device->bus->intr_context++;
766 usb_transfer_complete(xfer);
767 xfer->device->bus->intr_context--;
772 uhci_root_intr_done(usbd_xfer_handle xfer)
777 uhci_lock_frames(uhci_softc_t *sc)
781 while (sc->sc_vflock & UHCI_HAS_LOCK) {
782 sc->sc_vflock |= UHCI_WANT_LOCK;
783 tsleep(&sc->sc_vflock, PRIBIO, "uhcqhl", 0);
785 sc->sc_vflock = UHCI_HAS_LOCK;
790 uhci_unlock_frames(uhci_softc_t *sc)
794 sc->sc_vflock &= ~UHCI_HAS_LOCK;
795 if (sc->sc_vflock & UHCI_WANT_LOCK)
796 wakeup(&sc->sc_vflock);
801 * Allocate an interrupt information struct. A free list is kept
802 * for fast allocation.
805 uhci_alloc_intr_info(uhci_softc_t *sc)
807 uhci_intr_info_t *ii;
809 ii = LIST_FIRST(&uhci_ii_free);
811 LIST_REMOVE(ii, list);
813 ii = malloc(sizeof(uhci_intr_info_t), M_USBHC, M_NOWAIT);
816 #if defined(__FreeBSD__)
817 callout_handle_init(&ii->timeout_handle);
824 uhci_free_intr_info(uhci_intr_info_t *ii)
826 LIST_INSERT_HEAD(&uhci_ii_free, ii, list); /* and put on free list */
829 /* Add control QH, called at splusb(). */
831 uhci_add_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
837 DPRINTFN(10, ("uhci_add_ctrl: sqh=%p\n", sqh));
838 eqh = sc->sc_ctl_end;
839 sqh->hlink = eqh->hlink;
840 sqh->qh.qh_hlink = eqh->qh.qh_hlink;
842 eqh->qh.qh_hlink = LE(sqh->physaddr | UHCI_PTR_Q);
843 sc->sc_ctl_end = sqh;
846 /* Remove control QH, called at splusb(). */
848 uhci_remove_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
854 DPRINTFN(10, ("uhci_remove_ctrl: sqh=%p\n", sqh));
855 for (pqh = sc->sc_ctl_start; pqh->hlink != sqh; pqh=pqh->hlink)
856 #if defined(DIAGNOSTIC) || defined(USB_DEBUG)
857 if (LE(pqh->qh.qh_hlink) & UHCI_PTR_T) {
858 printf("uhci_remove_ctrl: QH not found\n");
864 pqh->hlink = sqh->hlink;
865 pqh->qh.qh_hlink = sqh->qh.qh_hlink;
866 if (sc->sc_ctl_end == sqh)
867 sc->sc_ctl_end = pqh;
870 /* Add bulk QH, called at splusb(). */
872 uhci_add_bulk(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
878 DPRINTFN(10, ("uhci_add_bulk: sqh=%p\n", sqh));
879 eqh = sc->sc_bulk_end;
880 sqh->hlink = eqh->hlink;
881 sqh->qh.qh_hlink = eqh->qh.qh_hlink;
883 eqh->qh.qh_hlink = LE(sqh->physaddr | UHCI_PTR_Q);
884 sc->sc_bulk_end = sqh;
887 /* Remove bulk QH, called at splusb(). */
889 uhci_remove_bulk(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
895 DPRINTFN(10, ("uhci_remove_bulk: sqh=%p\n", sqh));
896 for (pqh = sc->sc_bulk_start; pqh->hlink != sqh; pqh = pqh->hlink)
897 #if defined(DIAGNOSTIC) || defined(USB_DEBUG)
898 if (LE(pqh->qh.qh_hlink) & UHCI_PTR_T) {
899 printf("uhci_remove_bulk: QH not found\n");
905 pqh->hlink = sqh->hlink;
906 pqh->qh.qh_hlink = sqh->qh.qh_hlink;
907 if (sc->sc_bulk_end == sqh)
908 sc->sc_bulk_end = pqh;
914 uhci_softc_t *sc = arg;
917 uhci_intr_info_t *ii;
920 * It can happen that an interrupt will be delivered to
921 * us before the device has been fully attached and the
922 * softc struct has been configured. Usually this happens
923 * when kldloading the USB support as a module after the
924 * system has been booted. If we detect this condition,
925 * we need to squelch the unwanted interrupts until we're
928 if (sc->sc_bus.bdev == NULL) {
929 UWRITE2(sc, UHCI_STS, 0xFFFF); /* ack pending interrupts */
930 uhci_run(sc, 0); /* stop the controller */
931 UWRITE2(sc, UHCI_INTR, 0); /* disable interrupts */
936 if (uhcidebug > 15) {
937 DPRINTF(("%s: uhci_intr\n", USBDEVNAME(sc->sc_bus.bdev)));
942 status = UREAD2(sc, UHCI_STS);
943 if (status == 0) /* The interrupt was not for us. */
946 #if defined(DIAGNOSTIC) && defined(__NetBSD__)
947 if (sc->sc_suspend != PWR_RESUME)
948 printf("uhci_intr: suspended sts=0x%x\n", status);
952 if (status & UHCI_STS_USBINT)
953 ack |= UHCI_STS_USBINT;
954 if (status & UHCI_STS_USBEI)
955 ack |= UHCI_STS_USBEI;
956 if (status & UHCI_STS_RD) {
958 printf("%s: resume detect\n", USBDEVNAME(sc->sc_bus.bdev));
960 if (status & UHCI_STS_HSE) {
962 printf("%s: host system error\n", USBDEVNAME(sc->sc_bus.bdev));
964 if (status & UHCI_STS_HCPE) {
965 ack |= UHCI_STS_HCPE;
966 printf("%s: host controller process error\n",
967 USBDEVNAME(sc->sc_bus.bdev));
969 if (status & UHCI_STS_HCH) {
970 /* no acknowledge needed */
971 printf("%s: host controller halted\n",
972 USBDEVNAME(sc->sc_bus.bdev));
975 if (ack) /* acknowledge the ints */
976 UWRITE2(sc, UHCI_STS, ack);
977 else /* nothing to acknowledge */
980 sc->sc_bus.intr_context++;
981 sc->sc_bus.no_intrs++;
984 * Interrupts on UHCI really suck. When the host controller
985 * interrupts because a transfer is completed there is no
986 * way of knowing which transfer it was. You can scan down
987 * the TDs and QHs of the previous frame to limit the search,
988 * but that assumes that the interrupt was not delayed by more
989 * than 1 ms, which may not always be true (e.g. after debug
990 * output on a slow console).
991 * We scan all interrupt descriptors to see if any have
994 for (ii = LIST_FIRST(&sc->sc_intrhead); ii; ii = LIST_NEXT(ii, list))
995 uhci_check_intr(sc, ii);
997 DPRINTFN(10, ("%s: uhci_intr: exit\n", USBDEVNAME(sc->sc_bus.bdev)));
999 sc->sc_bus.intr_context--;
1004 /* Check for an interrupt. */
1006 uhci_check_intr(uhci_softc_t *sc, uhci_intr_info_t *ii)
1008 uhci_soft_td_t *std, *lstd;
1011 DPRINTFN(15, ("uhci_check_intr: ii=%p\n", ii));
1014 printf("uhci_check_intr: no ii? %p\n", ii);
1018 if (ii->stdstart == NULL)
1023 printf("uhci_check_intr: std==0\n");
1028 * If the last TD is still active we need to check whether there
1029 * is a an error somewhere in the middle, or whether there was a
1030 * short packet (SPD and not ACTIVE).
1032 if (LE(lstd->td.td_status) & UHCI_TD_ACTIVE) {
1033 DPRINTFN(15, ("uhci_check_intr: active ii=%p\n", ii));
1034 for (std = ii->stdstart; std != lstd; std = std->link.std) {
1035 status = LE(std->td.td_status);
1036 /* If there's an active TD the xfer isn't done. */
1037 if (status & UHCI_TD_ACTIVE)
1039 /* Any kind of error makes the xfer done. */
1040 if (status & UHCI_TD_STALLED)
1043 * We want short packets,
1044 * and it is short: it's done
1046 if ((status & UHCI_TD_SPD) &&
1047 UHCI_TD_GET_ACTLEN(status) <
1048 UHCI_TD_GET_MAXLEN(LE(std->td.td_token)))
1051 DPRINTFN(15, ("uhci_check_intr: ii=%p std=%p still active\n",
1057 usb_untimeout(uhci_timeout, ii, ii->timeout_handle);
1061 /* Called at splusb() */
1063 uhci_idone(uhci_intr_info_t *ii)
1065 usbd_xfer_handle xfer = ii->xfer;
1066 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
1067 uhci_soft_td_t *std;
1068 u_int32_t status = 0, nstatus;
1076 printf("uhci_idone: ii=%p is done!\n", ii);
1084 if (xfer->status == USBD_CANCELLED ||
1085 xfer->status == USBD_TIMEOUT) {
1086 DPRINTF(("uhci_idone: aborted xfer=%p\n", xfer));
1090 if (xfer->nframes != 0) {
1091 /* Isoc transfer, do things differently. */
1092 uhci_soft_td_t **stds = upipe->u.iso.stds;
1095 DPRINTFN(5,("uhci_idone: ii=%p isoc ready\n", ii));
1097 nframes = xfer->nframes;
1099 n = xfer->hcprivint;
1100 for (i = 0; i < nframes; i++) {
1103 if (uhcidebug > 5) {
1104 DPRINTFN(-1,("uhci_idone: isoc TD %d\n", i));
1108 if (++n >= UHCI_VFRAMELIST_COUNT)
1110 status = LE(std->td.td_status);
1111 actlen += UHCI_TD_GET_ACTLEN(status);
1113 upipe->u.iso.inuse -= nframes;
1114 xfer->actlen = actlen;
1115 xfer->status = USBD_NORMAL_COMPLETION;
1117 usb_transfer_complete(xfer);
1122 DPRINTFN(10, ("uhci_idone: ii=%p, xfer=%p, pipe=%p ready\n",
1125 uhci_dump_tds(ii->stdstart);
1128 /* The transfer is done, compute actual length and status. */
1130 for (std = ii->stdstart; std != NULL; std = std->link.std) {
1131 nstatus = LE(std->td.td_status);
1132 if (nstatus & UHCI_TD_ACTIVE)
1136 if (UHCI_TD_GET_PID(LE(std->td.td_token)) != UHCI_TD_PID_SETUP)
1137 actlen += UHCI_TD_GET_ACTLEN(status);
1139 /* If there are left over TDs we need to update the toggle. */
1141 upipe->nexttoggle = UHCI_TD_GET_DT(LE(std->td.td_token));
1143 status &= UHCI_TD_ERROR;
1144 DPRINTFN(10, ("uhci_check_intr: actlen=%d, status=0x%x\n",
1146 xfer->actlen = actlen;
1148 DPRINTFN((status == UHCI_TD_STALLED)*10,
1149 ("uhci_idone: error, addr=%d, endpt=0x%02x, "
1151 xfer->pipe->device->address,
1152 xfer->pipe->endpoint->edesc->bEndpointAddress,
1154 "\20\22BITSTUFF\23CRCTO\24NAK\25BABBLE\26DBUFFER\27"
1155 "STALLED\30ACTIVE"));
1156 if (status == UHCI_TD_STALLED)
1157 xfer->status = USBD_STALLED;
1159 xfer->status = USBD_IOERROR; /* more info XXX */
1161 xfer->status = USBD_NORMAL_COMPLETION;
1164 usb_transfer_complete(xfer);
1168 * Called when a request does not complete.
1171 uhci_timeout(void *addr)
1173 uhci_intr_info_t *ii = addr;
1175 DPRINTF(("uhci_timeout: ii=%p\n", ii));
1179 uhci_dump_tds(ii->stdstart);
1182 ii->xfer->device->bus->intr_context++;
1183 uhci_abort_xfer(ii->xfer, USBD_TIMEOUT);
1184 ii->xfer->device->bus->intr_context--;
1188 * Wait here until controller claims to have an interrupt.
1189 * Then call uhci_intr and return. Use timeout to avoid waiting
1191 * Only used during boot when interrupts are not enabled yet.
1194 uhci_waitintr(uhci_softc_t *sc, usbd_xfer_handle xfer)
1196 int timo = xfer->timeout;
1197 uhci_intr_info_t *ii;
1199 DPRINTFN(10,("uhci_waitintr: timeout = %dms\n", timo));
1201 xfer->status = USBD_IN_PROGRESS;
1202 for (; timo >= 0; timo--) {
1203 usb_delay_ms(&sc->sc_bus, 1);
1204 DPRINTFN(20,("uhci_waitintr: 0x%04x\n", UREAD2(sc, UHCI_STS)));
1205 if (UREAD2(sc, UHCI_STS) & UHCI_STS_USBINT) {
1207 if (xfer->status != USBD_IN_PROGRESS)
1213 DPRINTF(("uhci_waitintr: timeout\n"));
1214 for (ii = LIST_FIRST(&sc->sc_intrhead);
1215 ii != NULL && ii->xfer != xfer;
1216 ii = LIST_NEXT(ii, list))
1220 panic("uhci_waitintr: lost intr_info\n");
1226 uhci_poll(struct usbd_bus *bus)
1228 uhci_softc_t *sc = (uhci_softc_t *)bus;
1230 if (UREAD2(sc, UHCI_STS) & UHCI_STS_USBINT)
1238 uhci_softc_t *sc = p;
1241 UHCICMD(sc, UHCI_CMD_HCRESET);
1242 /* The reset bit goes low when the controller is done. */
1243 for (n = 0; n < UHCI_RESET_TIMEOUT &&
1244 (UREAD2(sc, UHCI_CMD) & UHCI_CMD_HCRESET); n++)
1246 if (n >= UHCI_RESET_TIMEOUT)
1247 printf("%s: controller did not reset\n",
1248 USBDEVNAME(sc->sc_bus.bdev));
1253 uhci_run(uhci_softc_t *sc, int run)
1260 DPRINTF(("uhci_run: setting run=%d\n", run));
1261 cmd = UREAD2(sc, UHCI_CMD);
1265 cmd &= ~UHCI_CMD_RS;
1267 for(n = 0; n < 10; n++) {
1268 running = !(UREAD2(sc, UHCI_STS) & UHCI_STS_HCH);
1269 /* return when we've entered the state we want */
1270 if (run == running) {
1272 DPRINTF(("uhci_run: done cmd=0x%x sts=0x%x\n",
1273 UREAD2(sc, UHCI_CMD), UREAD2(sc, UHCI_STS)));
1274 return (USBD_NORMAL_COMPLETION);
1276 usb_delay_ms(&sc->sc_bus, 1);
1279 printf("%s: cannot %s\n", USBDEVNAME(sc->sc_bus.bdev),
1280 run ? "start" : "stop");
1281 return (USBD_IOERROR);
1285 * Memory management routines.
1286 * uhci_alloc_std allocates TDs
1287 * uhci_alloc_sqh allocates QHs
1288 * These two routines do their own free list management,
1289 * partly for speed, partly because allocating DMAable memory
1290 * has page size granularaity so much memory would be wasted if
1291 * only one TD/QH (32 bytes) was placed in each allocated chunk.
1295 uhci_alloc_std(uhci_softc_t *sc)
1297 uhci_soft_td_t *std;
1302 if (sc->sc_freetds == NULL) {
1303 DPRINTFN(2,("uhci_alloc_std: allocating chunk\n"));
1304 err = usb_allocmem(&sc->sc_bus, UHCI_STD_SIZE * UHCI_STD_CHUNK,
1305 UHCI_TD_ALIGN, &dma);
1308 for(i = 0; i < UHCI_STD_CHUNK; i++) {
1309 offs = i * UHCI_STD_SIZE;
1310 std = (uhci_soft_td_t *)((char *)KERNADDR(&dma, offs));
1311 std->physaddr = DMAADDR(&dma, offs);
1312 std->link.std = sc->sc_freetds;
1313 sc->sc_freetds = std;
1316 std = sc->sc_freetds;
1317 sc->sc_freetds = std->link.std;
1318 memset(&std->td, 0, sizeof(uhci_td_t));
1323 uhci_free_std(uhci_softc_t *sc, uhci_soft_td_t *std)
1326 #define TD_IS_FREE 0x12345678
1327 if (std->td.td_token == LE(TD_IS_FREE)) {
1328 printf("uhci_free_std: freeing free TD %p\n", std);
1331 std->td.td_token = LE(TD_IS_FREE);
1333 std->link.std = sc->sc_freetds;
1334 sc->sc_freetds = std;
1338 uhci_alloc_sqh(uhci_softc_t *sc)
1340 uhci_soft_qh_t *sqh;
1345 if (sc->sc_freeqhs == NULL) {
1346 DPRINTFN(2, ("uhci_alloc_sqh: allocating chunk\n"));
1347 err = usb_allocmem(&sc->sc_bus, UHCI_SQH_SIZE * UHCI_SQH_CHUNK,
1348 UHCI_QH_ALIGN, &dma);
1351 for(i = 0; i < UHCI_SQH_CHUNK; i++) {
1352 offs = i * UHCI_SQH_SIZE;
1353 sqh = (uhci_soft_qh_t *)((char *)KERNADDR(&dma, offs));
1354 sqh->physaddr = DMAADDR(&dma, offs);
1355 sqh->hlink = sc->sc_freeqhs;
1356 sc->sc_freeqhs = sqh;
1359 sqh = sc->sc_freeqhs;
1360 sc->sc_freeqhs = sqh->hlink;
1361 memset(&sqh->qh, 0, sizeof(uhci_qh_t));
1366 uhci_free_sqh(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
1368 sqh->hlink = sc->sc_freeqhs;
1369 sc->sc_freeqhs = sqh;
1374 * Enter a list of transfers onto a control queue.
1375 * Called at splusb()
1378 uhci_enter_ctl_q(uhci_softc_t *sc, uhci_soft_qh_t *sqh, uhci_intr_info_t *ii)
1380 DPRINTFN(5, ("uhci_enter_ctl_q: sqh=%p\n", sqh));
1386 uhci_free_std_chain(uhci_softc_t *sc, uhci_soft_td_t *std,
1387 uhci_soft_td_t *stdend)
1391 for (; std != stdend; std = p) {
1393 uhci_free_std(sc, std);
1398 uhci_alloc_std_chain(struct uhci_pipe *upipe, uhci_softc_t *sc,
1399 int len, int rd, u_int16_t flags, usb_dma_t *dma,
1400 uhci_soft_td_t **sp, uhci_soft_td_t **ep)
1402 uhci_soft_td_t *p, *lastp;
1403 uhci_physaddr_t lastlink;
1404 int i, ntd, l, tog, maxp;
1406 int addr = upipe->pipe.device->address;
1407 int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress;
1409 DPRINTFN(8, ("uhci_alloc_std_chain: addr=%d endpt=%d len=%d ls=%d "
1410 "flags=0x%x\n", addr, UE_GET_ADDR(endpt), len,
1411 upipe->pipe.device->lowspeed, flags));
1412 maxp = UGETW(upipe->pipe.endpoint->edesc->wMaxPacketSize);
1414 printf("uhci_alloc_std_chain: maxp=0\n");
1415 return (USBD_INVAL);
1417 ntd = (len + maxp - 1) / maxp;
1418 if ((flags & USBD_FORCE_SHORT_XFER) && len % maxp == 0)
1420 DPRINTFN(10, ("uhci_alloc_std_chain: maxp=%d ntd=%d\n", maxp, ntd));
1423 DPRINTFN(-1,("uhci_alloc_std_chain: ntd=0\n"));
1424 return (USBD_NORMAL_COMPLETION);
1426 tog = upipe->nexttoggle;
1429 upipe->nexttoggle = tog ^ 1;
1431 lastlink = UHCI_PTR_T;
1433 status = UHCI_TD_ZERO_ACTLEN(UHCI_TD_SET_ERRCNT(3) | UHCI_TD_ACTIVE);
1434 if (upipe->pipe.device->lowspeed)
1435 status |= UHCI_TD_LS;
1436 if (flags & USBD_SHORT_XFER_OK)
1437 status |= UHCI_TD_SPD;
1438 for (i = ntd; i >= 0; i--) {
1439 p = uhci_alloc_std(sc);
1441 uhci_free_std_chain(sc, lastp, 0);
1442 return (USBD_NOMEM);
1444 p->link.std = lastp;
1445 if (lastlink == UHCI_PTR_T)
1446 p->td.td_link = LE(lastlink);
1448 p->td.td_link = LE(lastlink|UHCI_PTR_VF);
1450 lastlink = p->physaddr;
1451 p->td.td_status = LE(status);
1455 if (l == 0 && !(flags & USBD_FORCE_SHORT_XFER))
1461 LE(rd ? UHCI_TD_IN (l, endpt, addr, tog) :
1462 UHCI_TD_OUT(l, endpt, addr, tog));
1463 p->td.td_buffer = LE(DMAADDR(dma, i * maxp));
1467 DPRINTFN(10, ("uhci_alloc_std_chain: nexttog=%d\n",
1468 upipe->nexttoggle));
1469 return (USBD_NORMAL_COMPLETION);
1473 uhci_device_clear_toggle(usbd_pipe_handle pipe)
1475 struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
1476 upipe->nexttoggle = 0;
1480 uhci_noop(usbd_pipe_handle pipe)
1485 uhci_device_bulk_transfer(usbd_xfer_handle xfer)
1489 /* Insert last in queue. */
1490 err = usb_insert_transfer(xfer);
1494 /* Pipe isn't running (otherwise err would be USBD_INPROG),
1497 return (uhci_device_bulk_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
1501 uhci_device_bulk_start(usbd_xfer_handle xfer)
1503 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
1504 usbd_device_handle dev = upipe->pipe.device;
1505 uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
1506 uhci_intr_info_t *ii = upipe->iinfo;
1507 uhci_soft_td_t *data, *dataend;
1508 uhci_soft_qh_t *sqh;
1510 int len, isread, endpt;
1513 DPRINTFN(3, ("uhci_device_bulk_transfer: xfer=%p len=%d flags=%d\n",
1514 xfer, xfer->length, xfer->flags));
1517 if (xfer->rqflags & URQ_REQUEST)
1518 panic("uhci_device_bulk_transfer: a request\n");
1522 endpt = xfer->pipe->endpoint->edesc->bEndpointAddress;
1523 isread = UE_GET_DIR(endpt) == UE_DIR_IN;
1524 sqh = upipe->u.bulk.sqh;
1526 upipe->u.bulk.isread = isread;
1527 upipe->u.bulk.length = len;
1529 err = uhci_alloc_std_chain(upipe, sc, len, isread, xfer->flags,
1530 &xfer->dmabuf, &data, &dataend);
1533 dataend->td.td_status |= LE(UHCI_TD_IOC);
1536 if (uhcidebug > 8) {
1537 DPRINTF(("uhci_device_bulk_transfer: data(1)\n"));
1538 uhci_dump_tds(data);
1542 /* Set up interrupt info. */
1544 ii->stdstart = data;
1545 ii->stdend = dataend;
1546 #if defined(__FreeBSD__)
1547 callout_handle_init(&ii->timeout_handle);
1551 printf("uhci_device_bulk_transfer: not done, ii=%p\n", ii);
1557 sqh->qh.qh_elink = LE(data->physaddr);
1558 sqh->intr_info = ii;
1561 uhci_add_bulk(sc, sqh);
1562 LIST_INSERT_HEAD(&sc->sc_intrhead, ii, list);
1564 if (xfer->timeout && !sc->sc_bus.use_polling) {
1565 usb_timeout(uhci_timeout, ii, MS_TO_TICKS(xfer->timeout),
1566 ii->timeout_handle);
1571 if (uhcidebug > 10) {
1572 DPRINTF(("uhci_device_bulk_transfer: data(2)\n"));
1573 uhci_dump_tds(data);
1577 if (sc->sc_bus.use_polling)
1578 uhci_waitintr(sc, xfer);
1580 return (USBD_IN_PROGRESS);
1583 /* Abort a device bulk request. */
1585 uhci_device_bulk_abort(usbd_xfer_handle xfer)
1587 DPRINTF(("uhci_device_bulk_abort:\n"));
1588 uhci_abort_xfer(xfer, USBD_CANCELLED);
1592 uhci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
1594 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
1595 uhci_intr_info_t *ii = upipe->iinfo;
1596 uhci_soft_td_t *std;
1598 DPRINTFN(1,("uhci_abort_xfer: xfer=%p, status=%d\n", xfer, status));
1600 /* Make interrupt routine ignore it, */
1601 xfer->status = status;
1603 /* don't timeout, */
1604 usb_untimeout(uhci_timeout, ii, ii->timeout_handle);
1606 /* make hardware ignore it, */
1607 for (std = ii->stdstart; std != 0; std = std->link.std)
1608 std->td.td_status &= LE(~(UHCI_TD_ACTIVE | UHCI_TD_IOC));
1613 /* Make sure hardware has completed. */
1614 if (xfer->device->bus->intr_context) {
1615 /* We have no process context, so we can't use tsleep(). */
1616 timeout(uhci_abort_xfer_end, xfer, hz / USB_FRAMES_PER_SECOND);
1618 #if defined(DIAGNOSTIC) && defined(__i386__) && defined(__FreeBSD__)
1619 KASSERT(intr_nesting_level == 0,
1620 ("ohci_abort_req in interrupt context"));
1622 usb_delay_ms(xfer->pipe->device->bus, 1);
1623 /* and call final part of interrupt handler. */
1624 uhci_abort_xfer_end(xfer);
1628 uhci_abort_xfer_end(xfer);
1633 uhci_abort_xfer_end(void *v)
1635 usbd_xfer_handle xfer = v;
1639 usb_transfer_complete(xfer);
1643 /* Close a device bulk pipe. */
1645 uhci_device_bulk_close(usbd_pipe_handle pipe)
1647 struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
1648 usbd_device_handle dev = upipe->pipe.device;
1649 uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
1651 uhci_free_sqh(sc, upipe->u.bulk.sqh);
1652 uhci_free_intr_info(upipe->iinfo);
1653 /* XXX free other resources */
1657 uhci_device_ctrl_transfer(usbd_xfer_handle xfer)
1661 /* Insert last in queue. */
1662 err = usb_insert_transfer(xfer);
1666 /* Pipe isn't running (otherwise err would be USBD_INPROG),
1669 return (uhci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
1673 uhci_device_ctrl_start(usbd_xfer_handle xfer)
1675 uhci_softc_t *sc = (uhci_softc_t *)xfer->pipe->device->bus;
1679 if (!(xfer->rqflags & URQ_REQUEST))
1680 panic("uhci_device_ctrl_transfer: not a request\n");
1683 err = uhci_device_request(xfer);
1687 if (sc->sc_bus.use_polling)
1688 uhci_waitintr(sc, xfer);
1689 return (USBD_IN_PROGRESS);
1693 uhci_device_intr_transfer(usbd_xfer_handle xfer)
1697 /* Insert last in queue. */
1698 err = usb_insert_transfer(xfer);
1702 /* Pipe isn't running (otherwise err would be USBD_INPROG),
1705 return (uhci_device_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
1709 uhci_device_intr_start(usbd_xfer_handle xfer)
1711 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
1712 usbd_device_handle dev = upipe->pipe.device;
1713 uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
1714 uhci_intr_info_t *ii = upipe->iinfo;
1715 uhci_soft_td_t *data, *dataend;
1716 uhci_soft_qh_t *sqh;
1720 DPRINTFN(3,("uhci_device_intr_transfer: xfer=%p len=%d flags=%d\n",
1721 xfer, xfer->length, xfer->flags));
1724 if (xfer->rqflags & URQ_REQUEST)
1725 panic("uhci_device_intr_transfer: a request\n");
1728 err = uhci_alloc_std_chain(upipe, sc, xfer->length, 1, xfer->flags,
1729 &xfer->dmabuf, &data, &dataend);
1732 dataend->td.td_status |= LE(UHCI_TD_IOC);
1735 if (uhcidebug > 10) {
1736 DPRINTF(("uhci_device_intr_transfer: data(1)\n"));
1737 uhci_dump_tds(data);
1738 uhci_dump_qh(upipe->u.intr.qhs[0]);
1743 /* Set up interrupt info. */
1745 ii->stdstart = data;
1746 ii->stdend = dataend;
1747 #if defined(__FreeBSD__)
1748 callout_handle_init(&ii->timeout_handle);
1752 printf("uhci_device_intr_transfer: not done, ii=%p\n", ii);
1757 DPRINTFN(10,("uhci_device_intr_transfer: qhs[0]=%p\n",
1758 upipe->u.intr.qhs[0]));
1759 for (i = 0; i < upipe->u.intr.npoll; i++) {
1760 sqh = upipe->u.intr.qhs[i];
1762 sqh->qh.qh_elink = LE(data->physaddr);
1767 if (uhcidebug > 10) {
1768 DPRINTF(("uhci_device_intr_transfer: data(2)\n"));
1769 uhci_dump_tds(data);
1770 uhci_dump_qh(upipe->u.intr.qhs[0]);
1774 return (USBD_IN_PROGRESS);
1777 /* Abort a device control request. */
1779 uhci_device_ctrl_abort(usbd_xfer_handle xfer)
1781 DPRINTF(("uhci_device_ctrl_abort:\n"));
1782 uhci_abort_xfer(xfer, USBD_CANCELLED);
1785 /* Close a device control pipe. */
1787 uhci_device_ctrl_close(usbd_pipe_handle pipe)
1789 struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
1791 uhci_free_intr_info(upipe->iinfo);
1792 /* XXX free other resources? */
1795 /* Abort a device interrupt request. */
1797 uhci_device_intr_abort(usbd_xfer_handle xfer)
1799 DPRINTFN(1,("uhci_device_intr_abort: xfer=%p\n", xfer));
1800 if (xfer->pipe->intrxfer == xfer) {
1801 DPRINTFN(1,("uhci_device_intr_abort: remove\n"));
1802 xfer->pipe->intrxfer = 0;
1804 uhci_abort_xfer(xfer, USBD_CANCELLED);
1807 /* Close a device interrupt pipe. */
1809 uhci_device_intr_close(usbd_pipe_handle pipe)
1811 struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
1812 uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
1815 upipe->iinfo->stdstart = 0; /* inactive */
1817 /* Unlink descriptors from controller data structures. */
1818 npoll = upipe->u.intr.npoll;
1819 uhci_lock_frames(sc);
1820 for (i = 0; i < npoll; i++)
1821 uhci_remove_intr(sc, upipe->u.intr.qhs[i]->pos,
1822 upipe->u.intr.qhs[i]);
1823 uhci_unlock_frames(sc);
1826 * We now have to wait for any activity on the physical
1827 * descriptors to stop.
1829 usb_delay_ms(&sc->sc_bus, 2);
1831 for(i = 0; i < npoll; i++)
1832 uhci_free_sqh(sc, upipe->u.intr.qhs[i]);
1833 free(upipe->u.intr.qhs, M_USBHC);
1836 LIST_REMOVE(upipe->iinfo, list); /* remove from active list */
1838 uhci_free_intr_info(upipe->iinfo);
1840 /* XXX free other resources */
1844 uhci_device_request(usbd_xfer_handle xfer)
1846 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
1847 usb_device_request_t *req = &xfer->request;
1848 usbd_device_handle dev = upipe->pipe.device;
1849 uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
1850 int addr = dev->address;
1851 int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress;
1852 uhci_intr_info_t *ii = upipe->iinfo;
1853 uhci_soft_td_t *setup, *data, *stat, *next, *dataend;
1854 uhci_soft_qh_t *sqh;
1861 DPRINTFN(3,("uhci_device_control type=0x%02x, request=0x%02x, "
1862 "wValue=0x%04x, wIndex=0x%04x len=%d, addr=%d, endpt=%d\n",
1863 req->bmRequestType, req->bRequest, UGETW(req->wValue),
1864 UGETW(req->wIndex), UGETW(req->wLength),
1867 ls = dev->lowspeed ? UHCI_TD_LS : 0;
1868 isread = req->bmRequestType & UT_READ;
1869 len = UGETW(req->wLength);
1871 setup = upipe->u.ctl.setup;
1872 stat = upipe->u.ctl.stat;
1873 sqh = upipe->u.ctl.sqh;
1875 /* Set up data transaction */
1877 upipe->nexttoggle = 1;
1878 err = uhci_alloc_std_chain(upipe, sc, len, isread, xfer->flags,
1879 &xfer->dmabuf, &data, &dataend);
1883 dataend->link.std = stat;
1884 dataend->td.td_link = LE(stat->physaddr | UHCI_PTR_VF);
1888 upipe->u.ctl.length = len;
1890 memcpy(KERNADDR(&upipe->u.ctl.reqdma, 0), req, sizeof *req);
1892 setup->link.std = next;
1893 setup->td.td_link = LE(next->physaddr | UHCI_PTR_VF);
1894 setup->td.td_status = LE(UHCI_TD_SET_ERRCNT(3) | ls | UHCI_TD_ACTIVE);
1895 setup->td.td_token = LE(UHCI_TD_SETUP(sizeof *req, endpt, addr));
1896 setup->td.td_buffer = LE(DMAADDR(&upipe->u.ctl.reqdma, 0));
1899 stat->td.td_link = LE(UHCI_PTR_T);
1900 stat->td.td_status = LE(UHCI_TD_SET_ERRCNT(3) | ls |
1901 UHCI_TD_ACTIVE | UHCI_TD_IOC);
1903 LE(isread ? UHCI_TD_OUT(0, endpt, addr, 1) :
1904 UHCI_TD_IN (0, endpt, addr, 1));
1905 stat->td.td_buffer = LE(0);
1908 if (uhcidebug > 10) {
1909 DPRINTF(("uhci_device_request: before transfer\n"));
1910 uhci_dump_tds(setup);
1914 /* Set up interrupt info. */
1916 ii->stdstart = setup;
1918 #if defined(__FreeBSD__)
1919 callout_handle_init(&ii->timeout_handle);
1923 printf("uhci_device_request: not done, ii=%p\n", ii);
1929 sqh->qh.qh_elink = LE(setup->physaddr);
1930 sqh->intr_info = ii;
1933 uhci_add_ctrl(sc, sqh);
1934 LIST_INSERT_HEAD(&sc->sc_intrhead, ii, list);
1936 if (uhcidebug > 12) {
1937 uhci_soft_td_t *std;
1938 uhci_soft_qh_t *xqh;
1939 uhci_soft_qh_t *sxqh;
1941 uhci_physaddr_t link;
1942 DPRINTF(("uhci_enter_ctl_q: follow from [0]\n"));
1943 for (std = sc->sc_vframes[0].htd, link = 0;
1944 (link & UHCI_PTR_Q) == 0;
1945 std = std->link.std) {
1946 link = LE(std->td.td_link);
1949 sxqh = (uhci_soft_qh_t *)std;
1953 xqh = (maxqh++ == 5 || xqh->hlink==sxqh ||
1954 xqh->hlink==xqh ? NULL : xqh->hlink)) {
1957 DPRINTF(("Enqueued QH:\n"));
1959 uhci_dump_tds(sqh->elink);
1962 if (xfer->timeout && !sc->sc_bus.use_polling) {
1963 usb_timeout(uhci_timeout, ii,
1964 MS_TO_TICKS(xfer->timeout), ii->timeout_handle);
1968 return (USBD_NORMAL_COMPLETION);
1972 uhci_device_isoc_transfer(usbd_xfer_handle xfer)
1976 DPRINTFN(5,("uhci_device_isoc_transfer: xfer=%p\n", xfer));
1978 /* Put it on our queue, */
1979 err = usb_insert_transfer(xfer);
1981 /* bail out on error, */
1982 if (err && err != USBD_IN_PROGRESS)
1985 /* XXX should check inuse here */
1987 /* insert into schedule, */
1988 uhci_device_isoc_enter(xfer);
1990 /* and put on interrupt list if the pipe wasn't running */
1992 uhci_device_isoc_start(SIMPLEQ_FIRST(&xfer->pipe->queue));
1998 uhci_device_isoc_enter(usbd_xfer_handle xfer)
2000 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
2001 usbd_device_handle dev = upipe->pipe.device;
2002 uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
2003 struct iso *iso = &upipe->u.iso;
2004 uhci_soft_td_t *std;
2005 u_int32_t buf, len, status;
2006 int s, i, next, nframes;
2008 DPRINTFN(5,("uhci_device_isoc_enter: used=%d next=%d xfer=%p "
2010 iso->inuse, iso->next, xfer, xfer->nframes));
2012 if (xfer->status == USBD_IN_PROGRESS) {
2013 /* This request has already been entered into the frame list */
2018 if (iso->inuse >= UHCI_VFRAMELIST_COUNT)
2019 printf("uhci_device_isoc_enter: overflow!\n");
2024 /* Not in use yet, schedule it a few frames ahead. */
2025 next = (UREAD2(sc, UHCI_FRNUM) + 3) % UHCI_VFRAMELIST_COUNT;
2026 DPRINTFN(2,("uhci_device_isoc_enter: start next=%d\n", next));
2029 xfer->status = USBD_IN_PROGRESS;
2030 xfer->hcprivint = next;
2032 buf = DMAADDR(&xfer->dmabuf, 0);
2033 status = LE(UHCI_TD_ZERO_ACTLEN(UHCI_TD_SET_ERRCNT(0) |
2036 nframes = xfer->nframes;
2038 for (i = 0; i < nframes; i++) {
2039 std = iso->stds[next];
2040 if (++next >= UHCI_VFRAMELIST_COUNT)
2042 len = xfer->frlengths[i];
2043 std->td.td_buffer = LE(buf);
2044 if (i == nframes - 1)
2045 status |= LE(UHCI_TD_IOC);
2046 std->td.td_status = status;
2047 std->td.td_token &= LE(~UHCI_TD_MAXLEN_MASK);
2048 std->td.td_token |= LE(UHCI_TD_SET_MAXLEN(len));
2050 if (uhcidebug > 5) {
2051 DPRINTFN(5,("uhci_device_isoc_enter: TD %d\n", i));
2058 iso->inuse += xfer->nframes;
2064 uhci_device_isoc_start(usbd_xfer_handle xfer)
2066 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
2067 uhci_softc_t *sc = (uhci_softc_t *)upipe->pipe.device->bus;
2068 uhci_intr_info_t *ii = upipe->iinfo;
2069 uhci_soft_td_t *end;
2073 if (xfer->status != USBD_IN_PROGRESS)
2074 printf("uhci_device_isoc_start: not in progress %p\n", xfer);
2077 /* Find the last TD */
2078 i = xfer->hcprivint + xfer->nframes;
2079 if (i >= UHCI_VFRAMELIST_COUNT)
2080 i -= UHCI_VFRAMELIST_COUNT;
2081 end = upipe->u.iso.stds[i];
2085 /* Set up interrupt info. */
2089 #if defined(__FreeBSD__)
2090 callout_handle_init(&ii->timeout_handle);
2094 printf("uhci_device_isoc_start: not done, ii=%p\n", ii);
2098 LIST_INSERT_HEAD(&sc->sc_intrhead, ii, list);
2102 return (USBD_IN_PROGRESS);
2106 uhci_device_isoc_abort(usbd_xfer_handle xfer)
2108 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
2109 uhci_intr_info_t *ii = upipe->iinfo;
2110 uhci_soft_td_t **stds = upipe->u.iso.stds;
2111 uhci_soft_td_t *std;
2114 /* Make interrupt routine ignore it, */
2115 xfer->status = USBD_CANCELLED;
2117 /* make hardware ignore it, */
2118 nframes = xfer->nframes;
2119 n = xfer->hcprivint;
2120 for (i = 0; i < nframes; i++) {
2122 std->td.td_status &= LE(~(UHCI_TD_ACTIVE | UHCI_TD_IOC));
2123 if (++n >= UHCI_VFRAMELIST_COUNT)
2129 /* make sure hardware has completed, */
2130 if (xfer->device->bus->intr_context) {
2131 /* We have no process context, so we can't use tsleep(). */
2132 timeout(uhci_abort_xfer_end, xfer, hz / USB_FRAMES_PER_SECOND);
2134 usb_delay_ms(xfer->pipe->device->bus, 1);
2135 /* and call final part of interrupt handler. */
2136 uhci_abort_xfer_end(xfer);
2141 uhci_device_isoc_close(usbd_pipe_handle pipe)
2143 struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
2144 usbd_device_handle dev = upipe->pipe.device;
2145 uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
2146 uhci_soft_td_t *std, *vstd;
2151 * Make sure all TDs are marked as inactive.
2152 * Wait for completion.
2156 iso = &upipe->u.iso;
2158 for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++)
2159 iso->stds[i]->td.td_status &= LE(~UHCI_TD_ACTIVE);
2160 usb_delay_ms(&sc->sc_bus, 2); /* wait for completion */
2162 uhci_lock_frames(sc);
2163 for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
2165 for (vstd = sc->sc_vframes[i].htd;
2166 vstd != NULL && vstd->link.std != std;
2167 vstd = vstd->link.std)
2171 printf("uhci_device_isoc_close: %p not found\n", std);
2172 uhci_unlock_frames(sc);
2175 vstd->link = std->link;
2176 vstd->td.td_link = std->td.td_link;
2177 uhci_free_std(sc, std);
2179 uhci_unlock_frames(sc);
2181 free(iso->stds, M_USBHC);
2185 uhci_setup_isoc(usbd_pipe_handle pipe)
2187 struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
2188 usbd_device_handle dev = upipe->pipe.device;
2189 uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
2190 int addr = upipe->pipe.device->address;
2191 int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress;
2192 int rd = UE_GET_DIR(endpt) == UE_DIR_IN;
2193 uhci_soft_td_t *std, *vstd;
2198 iso = &upipe->u.iso;
2199 iso->stds = malloc(UHCI_VFRAMELIST_COUNT * sizeof (uhci_soft_td_t *),
2202 token = LE(rd ? UHCI_TD_IN (0, endpt, addr, 0) :
2203 UHCI_TD_OUT(0, endpt, addr, 0));
2205 /* Allocate the TDs and mark as inactive; */
2206 for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
2207 std = uhci_alloc_std(sc);
2210 std->td.td_status = LE(UHCI_TD_IOS); /* iso, inactive */
2211 std->td.td_token = token;
2215 /* Insert TDs into schedule. */
2216 uhci_lock_frames(sc);
2217 for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
2219 vstd = sc->sc_vframes[i].htd;
2220 std->link = vstd->link;
2221 std->td.td_link = vstd->td.td_link;
2222 vstd->link.std = std;
2223 vstd->td.td_link = LE(std->physaddr);
2225 uhci_unlock_frames(sc);
2230 return (USBD_NORMAL_COMPLETION);
2234 uhci_free_std(sc, iso->stds[i]);
2235 free(iso->stds, M_USBHC);
2236 return (USBD_NOMEM);
2240 uhci_device_isoc_done(usbd_xfer_handle xfer)
2242 uhci_intr_info_t *ii = xfer->hcpriv;
2244 DPRINTFN(4, ("uhci_isoc_done: length=%d\n", xfer->actlen));
2246 /* Turn off the interrupt since it is active even if the TD is not. */
2247 ii->stdend->td.td_status &= LE(~UHCI_TD_IOC);
2249 LIST_REMOVE(ii, list); /* remove from active list */
2253 uhci_device_intr_done(usbd_xfer_handle xfer)
2255 uhci_intr_info_t *ii = xfer->hcpriv;
2256 uhci_softc_t *sc = ii->sc;
2257 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
2258 uhci_soft_qh_t *sqh;
2261 DPRINTFN(5, ("uhci_intr_done: length=%d\n", xfer->actlen));
2263 npoll = upipe->u.intr.npoll;
2264 for(i = 0; i < npoll; i++) {
2265 sqh = upipe->u.intr.qhs[i];
2267 sqh->qh.qh_elink = LE(UHCI_PTR_T);
2269 uhci_free_std_chain(sc, ii->stdstart, 0);
2272 if (xfer->pipe->repeat) {
2273 uhci_soft_td_t *data, *dataend;
2275 /* This alloc cannot fail since we freed the chain above. */
2276 uhci_alloc_std_chain(upipe, sc, xfer->length, 1, xfer->flags,
2277 &xfer->dmabuf, &data, &dataend);
2278 dataend->td.td_status |= LE(UHCI_TD_IOC);
2281 if (uhcidebug > 10) {
2282 DPRINTF(("uhci_device_intr_done: data(1)\n"));
2283 uhci_dump_tds(data);
2284 uhci_dump_qh(upipe->u.intr.qhs[0]);
2288 ii->stdstart = data;
2289 ii->stdend = dataend;
2290 #if defined(__FreeBSD__)
2291 callout_handle_init(&ii->timeout_handle);
2295 printf("uhci_device_intr_done: not done, ii=%p\n", ii);
2299 for (i = 0; i < npoll; i++) {
2300 sqh = upipe->u.intr.qhs[i];
2302 sqh->qh.qh_elink = LE(data->physaddr);
2305 ii->stdstart = 0; /* mark as inactive */
2309 /* Deallocate request data structures */
2311 uhci_device_ctrl_done(usbd_xfer_handle xfer)
2313 uhci_intr_info_t *ii = xfer->hcpriv;
2314 uhci_softc_t *sc = ii->sc;
2315 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
2318 if (!(xfer->rqflags & URQ_REQUEST))
2319 panic("uhci_ctrl_done: not a request\n");
2322 LIST_REMOVE(ii, list); /* remove from active list */
2324 uhci_remove_ctrl(sc, upipe->u.ctl.sqh);
2326 if (upipe->u.ctl.length != 0)
2327 uhci_free_std_chain(sc, ii->stdstart->link.std, ii->stdend);
2329 DPRINTFN(5, ("uhci_ctrl_done: length=%d\n", xfer->actlen));
2332 /* Deallocate request data structures */
2334 uhci_device_bulk_done(usbd_xfer_handle xfer)
2336 uhci_intr_info_t *ii = xfer->hcpriv;
2337 uhci_softc_t *sc = ii->sc;
2338 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
2340 LIST_REMOVE(ii, list); /* remove from active list */
2342 uhci_remove_bulk(sc, upipe->u.bulk.sqh);
2344 uhci_free_std_chain(sc, ii->stdstart, 0);
2346 DPRINTFN(5, ("uhci_bulk_done: length=%d\n", xfer->actlen));
2349 /* Add interrupt QH, called with vflock. */
2351 uhci_add_intr(uhci_softc_t *sc, int n, uhci_soft_qh_t *sqh)
2353 struct uhci_vframe *vf = &sc->sc_vframes[n];
2354 uhci_soft_qh_t *eqh;
2356 DPRINTFN(4, ("uhci_add_intr: n=%d sqh=%p\n", n, sqh));
2358 sqh->hlink = eqh->hlink;
2359 sqh->qh.qh_hlink = eqh->qh.qh_hlink;
2361 eqh->qh.qh_hlink = LE(sqh->physaddr | UHCI_PTR_Q);
2366 /* Remove interrupt QH, called with vflock. */
2368 uhci_remove_intr(uhci_softc_t *sc, int n, uhci_soft_qh_t *sqh)
2370 struct uhci_vframe *vf = &sc->sc_vframes[n];
2371 uhci_soft_qh_t *pqh;
2373 DPRINTFN(4, ("uhci_remove_intr: n=%d sqh=%p\n", n, sqh));
2375 for (pqh = vf->hqh; pqh->hlink != sqh; pqh = pqh->hlink)
2376 #if defined(DIAGNOSTIC) || defined(USB_DEBUG)
2377 if (LE(pqh->qh.qh_hlink) & UHCI_PTR_T) {
2378 DPRINTF(("uhci_remove_intr: QH not found\n"));
2384 pqh->hlink = sqh->hlink;
2385 pqh->qh.qh_hlink = sqh->qh.qh_hlink;
2392 uhci_device_setintr(uhci_softc_t *sc, struct uhci_pipe *upipe, int ival)
2394 uhci_soft_qh_t *sqh;
2396 u_int bestbw, bw, bestoffs, offs;
2398 DPRINTFN(2, ("uhci_setintr: pipe=%p\n", upipe));
2400 printf("uhci_setintr: 0 interval\n");
2401 return (USBD_INVAL);
2404 if (ival > UHCI_VFRAMELIST_COUNT)
2405 ival = UHCI_VFRAMELIST_COUNT;
2406 npoll = (UHCI_VFRAMELIST_COUNT + ival - 1) / ival;
2407 DPRINTFN(2, ("uhci_setintr: ival=%d npoll=%d\n", ival, npoll));
2409 upipe->u.intr.npoll = npoll;
2411 malloc(npoll * sizeof(uhci_soft_qh_t *), M_USBHC, M_WAITOK);
2414 * Figure out which offset in the schedule that has most
2415 * bandwidth left over.
2417 #define MOD(i) ((i) & (UHCI_VFRAMELIST_COUNT-1))
2418 for (bestoffs = offs = 0, bestbw = ~0; offs < ival; offs++) {
2419 for (bw = i = 0; i < npoll; i++)
2420 bw += sc->sc_vframes[MOD(i * ival + offs)].bandwidth;
2426 DPRINTFN(1, ("uhci_setintr: bw=%d offs=%d\n", bestbw, bestoffs));
2428 upipe->iinfo->stdstart = 0;
2429 for(i = 0; i < npoll; i++) {
2430 upipe->u.intr.qhs[i] = sqh = uhci_alloc_sqh(sc);
2432 sqh->qh.qh_elink = LE(UHCI_PTR_T);
2433 sqh->pos = MOD(i * ival + bestoffs);
2434 sqh->intr_info = upipe->iinfo;
2439 LIST_INSERT_HEAD(&sc->sc_intrhead, upipe->iinfo, list);
2442 uhci_lock_frames(sc);
2443 /* Enter QHs into the controller data structures. */
2444 for(i = 0; i < npoll; i++)
2445 uhci_add_intr(sc, upipe->u.intr.qhs[i]->pos,
2446 upipe->u.intr.qhs[i]);
2447 uhci_unlock_frames(sc);
2449 DPRINTFN(5, ("uhci_setintr: returns %p\n", upipe));
2450 return (USBD_NORMAL_COMPLETION);
2453 /* Open a new pipe. */
2455 uhci_open(usbd_pipe_handle pipe)
2457 uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
2458 struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
2459 usb_endpoint_descriptor_t *ed = pipe->endpoint->edesc;
2463 DPRINTFN(1, ("uhci_open: pipe=%p, addr=%d, endpt=%d (%d)\n",
2464 pipe, pipe->device->address,
2465 ed->bEndpointAddress, sc->sc_addr));
2466 if (pipe->device->address == sc->sc_addr) {
2467 switch (ed->bEndpointAddress) {
2468 case USB_CONTROL_ENDPOINT:
2469 pipe->methods = &uhci_root_ctrl_methods;
2471 case UE_DIR_IN | UHCI_INTR_ENDPT:
2472 pipe->methods = &uhci_root_intr_methods;
2475 return (USBD_INVAL);
2478 upipe->iinfo = uhci_alloc_intr_info(sc);
2479 if (upipe->iinfo == 0)
2480 return (USBD_NOMEM);
2481 switch (ed->bmAttributes & UE_XFERTYPE) {
2483 pipe->methods = &uhci_device_ctrl_methods;
2484 upipe->u.ctl.sqh = uhci_alloc_sqh(sc);
2485 if (upipe->u.ctl.sqh == NULL)
2487 upipe->u.ctl.setup = uhci_alloc_std(sc);
2488 if (upipe->u.ctl.setup == NULL) {
2489 uhci_free_sqh(sc, upipe->u.ctl.sqh);
2492 upipe->u.ctl.stat = uhci_alloc_std(sc);
2493 if (upipe->u.ctl.stat == NULL) {
2494 uhci_free_sqh(sc, upipe->u.ctl.sqh);
2495 uhci_free_std(sc, upipe->u.ctl.setup);
2498 err = usb_allocmem(&sc->sc_bus,
2499 sizeof(usb_device_request_t),
2500 0, &upipe->u.ctl.reqdma);
2502 uhci_free_sqh(sc, upipe->u.ctl.sqh);
2503 uhci_free_std(sc, upipe->u.ctl.setup);
2504 uhci_free_std(sc, upipe->u.ctl.stat);
2509 pipe->methods = &uhci_device_intr_methods;
2510 ival = pipe->interval;
2511 if (ival == USBD_DEFAULT_INTERVAL)
2512 ival = ed->bInterval;
2513 return (uhci_device_setintr(sc, upipe, ival));
2514 case UE_ISOCHRONOUS:
2515 pipe->methods = &uhci_device_isoc_methods;
2516 return (uhci_setup_isoc(pipe));
2518 pipe->methods = &uhci_device_bulk_methods;
2519 upipe->u.bulk.sqh = uhci_alloc_sqh(sc);
2520 if (upipe->u.bulk.sqh == NULL)
2525 return (USBD_NORMAL_COMPLETION);
2528 uhci_free_intr_info(upipe->iinfo);
2529 return (USBD_NOMEM);
2533 * Data structures and routines to emulate the root hub.
2535 usb_device_descriptor_t uhci_devd = {
2536 USB_DEVICE_DESCRIPTOR_SIZE,
2537 UDESC_DEVICE, /* type */
2538 {0x00, 0x01}, /* USB version */
2539 UDCLASS_HUB, /* class */
2540 UDSUBCLASS_HUB, /* subclass */
2541 UDPROTO_FSHUB, /* protocol */
2542 64, /* max packet */
2543 {0},{0},{0x00,0x01}, /* device id */
2544 1,2,0, /* string indicies */
2545 1 /* # of configurations */
2548 usb_config_descriptor_t uhci_confd = {
2549 USB_CONFIG_DESCRIPTOR_SIZE,
2551 {USB_CONFIG_DESCRIPTOR_SIZE +
2552 USB_INTERFACE_DESCRIPTOR_SIZE +
2553 USB_ENDPOINT_DESCRIPTOR_SIZE},
2561 usb_interface_descriptor_t uhci_ifcd = {
2562 USB_INTERFACE_DESCRIPTOR_SIZE,
2573 usb_endpoint_descriptor_t uhci_endpd = {
2574 USB_ENDPOINT_DESCRIPTOR_SIZE,
2576 UE_DIR_IN | UHCI_INTR_ENDPT,
2582 usb_hub_descriptor_t uhci_hubd_piix = {
2583 USB_HUB_DESCRIPTOR_SIZE,
2586 { UHD_PWR_NO_SWITCH | UHD_OC_INDIVIDUAL, 0 },
2587 50, /* power on to power good */
2589 { 0x00 }, /* both ports are removable */
2593 uhci_str(usb_string_descriptor_t *p, int l, char *s)
2599 p->bLength = 2 * strlen(s) + 2;
2602 p->bDescriptorType = UDESC_STRING;
2604 for (i = 0; s[i] && l > 1; i++, l -= 2)
2605 USETW2(p->bString[i], 0, s[i]);
2610 * Simulate a hardware hub by handling all the necessary requests.
2613 uhci_root_ctrl_transfer(usbd_xfer_handle xfer)
2617 /* Insert last in queue. */
2618 err = usb_insert_transfer(xfer);
2622 /* Pipe isn't running (otherwise err would be USBD_INPROG),
2625 return (uhci_root_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
2629 uhci_root_ctrl_start(usbd_xfer_handle xfer)
2631 uhci_softc_t *sc = (uhci_softc_t *)xfer->pipe->device->bus;
2632 usb_device_request_t *req;
2635 int s, len, value, index, status, change, l, totlen = 0;
2636 usb_port_status_t ps;
2640 if (!(xfer->rqflags & URQ_REQUEST))
2641 panic("uhci_root_ctrl_transfer: not a request\n");
2643 req = &xfer->request;
2645 DPRINTFN(2,("uhci_root_ctrl_control type=0x%02x request=%02x\n",
2646 req->bmRequestType, req->bRequest));
2648 len = UGETW(req->wLength);
2649 value = UGETW(req->wValue);
2650 index = UGETW(req->wIndex);
2653 buf = KERNADDR(&xfer->dmabuf, 0);
2655 #define C(x,y) ((x) | ((y) << 8))
2656 switch(C(req->bRequest, req->bmRequestType)) {
2657 case C(UR_CLEAR_FEATURE, UT_WRITE_DEVICE):
2658 case C(UR_CLEAR_FEATURE, UT_WRITE_INTERFACE):
2659 case C(UR_CLEAR_FEATURE, UT_WRITE_ENDPOINT):
2661 * DEVICE_REMOTE_WAKEUP and ENDPOINT_HALT are no-ops
2662 * for the integrated root hub.
2665 case C(UR_GET_CONFIG, UT_READ_DEVICE):
2667 *(u_int8_t *)buf = sc->sc_conf;
2671 case C(UR_GET_DESCRIPTOR, UT_READ_DEVICE):
2672 DPRINTFN(2,("uhci_root_ctrl_control wValue=0x%04x\n", value));
2673 switch(value >> 8) {
2675 if ((value & 0xff) != 0) {
2679 totlen = l = min(len, USB_DEVICE_DESCRIPTOR_SIZE);
2680 USETW(uhci_devd.idVendor, sc->sc_id_vendor);
2681 memcpy(buf, &uhci_devd, l);
2684 if ((value & 0xff) != 0) {
2688 totlen = l = min(len, USB_CONFIG_DESCRIPTOR_SIZE);
2689 memcpy(buf, &uhci_confd, l);
2690 buf = (char *)buf + l;
2692 l = min(len, USB_INTERFACE_DESCRIPTOR_SIZE);
2694 memcpy(buf, &uhci_ifcd, l);
2695 buf = (char *)buf + l;
2697 l = min(len, USB_ENDPOINT_DESCRIPTOR_SIZE);
2699 memcpy(buf, &uhci_endpd, l);
2704 *(u_int8_t *)buf = 0;
2706 switch (value & 0xff) {
2707 case 1: /* Vendor */
2708 totlen = uhci_str(buf, len, sc->sc_vendor);
2710 case 2: /* Product */
2711 totlen = uhci_str(buf, len, "UHCI root hub");
2720 case C(UR_GET_INTERFACE, UT_READ_INTERFACE):
2722 *(u_int8_t *)buf = 0;
2726 case C(UR_GET_STATUS, UT_READ_DEVICE):
2728 USETW(((usb_status_t *)buf)->wStatus,UDS_SELF_POWERED);
2732 case C(UR_GET_STATUS, UT_READ_INTERFACE):
2733 case C(UR_GET_STATUS, UT_READ_ENDPOINT):
2735 USETW(((usb_status_t *)buf)->wStatus, 0);
2739 case C(UR_SET_ADDRESS, UT_WRITE_DEVICE):
2740 if (value >= USB_MAX_DEVICES) {
2744 sc->sc_addr = value;
2746 case C(UR_SET_CONFIG, UT_WRITE_DEVICE):
2747 if (value != 0 && value != 1) {
2751 sc->sc_conf = value;
2753 case C(UR_SET_DESCRIPTOR, UT_WRITE_DEVICE):
2755 case C(UR_SET_FEATURE, UT_WRITE_DEVICE):
2756 case C(UR_SET_FEATURE, UT_WRITE_INTERFACE):
2757 case C(UR_SET_FEATURE, UT_WRITE_ENDPOINT):
2760 case C(UR_SET_INTERFACE, UT_WRITE_INTERFACE):
2762 case C(UR_SYNCH_FRAME, UT_WRITE_ENDPOINT):
2765 case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_DEVICE):
2767 case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_OTHER):
2768 DPRINTFN(3, ("uhci_root_ctrl_control: UR_CLEAR_PORT_FEATURE "
2769 "port=%d feature=%d\n",
2772 port = UHCI_PORTSC1;
2773 else if (index == 2)
2774 port = UHCI_PORTSC2;
2780 case UHF_PORT_ENABLE:
2781 x = UREAD2(sc, port);
2782 UWRITE2(sc, port, x & ~UHCI_PORTSC_PE);
2784 case UHF_PORT_SUSPEND:
2785 x = UREAD2(sc, port);
2786 UWRITE2(sc, port, x & ~UHCI_PORTSC_SUSP);
2788 case UHF_PORT_RESET:
2789 x = UREAD2(sc, port);
2790 UWRITE2(sc, port, x & ~UHCI_PORTSC_PR);
2792 case UHF_C_PORT_CONNECTION:
2793 x = UREAD2(sc, port);
2794 UWRITE2(sc, port, x | UHCI_PORTSC_CSC);
2796 case UHF_C_PORT_ENABLE:
2797 x = UREAD2(sc, port);
2798 UWRITE2(sc, port, x | UHCI_PORTSC_POEDC);
2800 case UHF_C_PORT_OVER_CURRENT:
2801 x = UREAD2(sc, port);
2802 UWRITE2(sc, port, x | UHCI_PORTSC_OCIC);
2804 case UHF_C_PORT_RESET:
2806 err = USBD_NORMAL_COMPLETION;
2808 case UHF_PORT_CONNECTION:
2809 case UHF_PORT_OVER_CURRENT:
2810 case UHF_PORT_POWER:
2811 case UHF_PORT_LOW_SPEED:
2812 case UHF_C_PORT_SUSPEND:
2818 case C(UR_GET_BUS_STATE, UT_READ_CLASS_OTHER):
2820 port = UHCI_PORTSC1;
2821 else if (index == 2)
2822 port = UHCI_PORTSC2;
2829 (UREAD2(sc, port) & UHCI_PORTSC_LS) >>
2830 UHCI_PORTSC_LS_SHIFT;
2834 case C(UR_GET_DESCRIPTOR, UT_READ_CLASS_DEVICE):
2839 l = min(len, USB_HUB_DESCRIPTOR_SIZE);
2841 memcpy(buf, &uhci_hubd_piix, l);
2843 case C(UR_GET_STATUS, UT_READ_CLASS_DEVICE):
2848 memset(buf, 0, len);
2851 case C(UR_GET_STATUS, UT_READ_CLASS_OTHER):
2853 port = UHCI_PORTSC1;
2854 else if (index == 2)
2855 port = UHCI_PORTSC2;
2864 x = UREAD2(sc, port);
2865 status = change = 0;
2866 if (x & UHCI_PORTSC_CCS )
2867 status |= UPS_CURRENT_CONNECT_STATUS;
2868 if (x & UHCI_PORTSC_CSC )
2869 change |= UPS_C_CONNECT_STATUS;
2870 if (x & UHCI_PORTSC_PE )
2871 status |= UPS_PORT_ENABLED;
2872 if (x & UHCI_PORTSC_POEDC)
2873 change |= UPS_C_PORT_ENABLED;
2874 if (x & UHCI_PORTSC_OCI )
2875 status |= UPS_OVERCURRENT_INDICATOR;
2876 if (x & UHCI_PORTSC_OCIC )
2877 change |= UPS_C_OVERCURRENT_INDICATOR;
2878 if (x & UHCI_PORTSC_SUSP )
2879 status |= UPS_SUSPEND;
2880 if (x & UHCI_PORTSC_LSDA )
2881 status |= UPS_LOW_SPEED;
2882 status |= UPS_PORT_POWER;
2884 change |= UPS_C_PORT_RESET;
2885 USETW(ps.wPortStatus, status);
2886 USETW(ps.wPortChange, change);
2887 l = min(len, sizeof ps);
2888 memcpy(buf, &ps, l);
2891 case C(UR_SET_DESCRIPTOR, UT_WRITE_CLASS_DEVICE):
2894 case C(UR_SET_FEATURE, UT_WRITE_CLASS_DEVICE):
2896 case C(UR_SET_FEATURE, UT_WRITE_CLASS_OTHER):
2898 port = UHCI_PORTSC1;
2899 else if (index == 2)
2900 port = UHCI_PORTSC2;
2906 case UHF_PORT_ENABLE:
2907 x = UREAD2(sc, port);
2908 UWRITE2(sc, port, x | UHCI_PORTSC_PE);
2910 case UHF_PORT_SUSPEND:
2911 x = UREAD2(sc, port);
2912 UWRITE2(sc, port, x | UHCI_PORTSC_SUSP);
2914 case UHF_PORT_RESET:
2915 x = UREAD2(sc, port);
2916 UWRITE2(sc, port, x | UHCI_PORTSC_PR);
2917 usb_delay_ms(&sc->sc_bus, 10);
2918 UWRITE2(sc, port, x & ~UHCI_PORTSC_PR);
2920 x = UREAD2(sc, port);
2921 UWRITE2(sc, port, x | UHCI_PORTSC_PE);
2923 DPRINTFN(3,("uhci port %d reset, status = 0x%04x\n",
2924 index, UREAD2(sc, port)));
2927 case UHF_PORT_POWER:
2928 /* Pretend we turned on power */
2929 err = USBD_NORMAL_COMPLETION;
2931 case UHF_C_PORT_CONNECTION:
2932 case UHF_C_PORT_ENABLE:
2933 case UHF_C_PORT_OVER_CURRENT:
2934 case UHF_PORT_CONNECTION:
2935 case UHF_PORT_OVER_CURRENT:
2936 case UHF_PORT_LOW_SPEED:
2937 case UHF_C_PORT_SUSPEND:
2938 case UHF_C_PORT_RESET:
2948 xfer->actlen = totlen;
2949 err = USBD_NORMAL_COMPLETION;
2954 usb_transfer_complete(xfer);
2956 return (USBD_IN_PROGRESS);
2959 /* Abort a root control request. */
2961 uhci_root_ctrl_abort(usbd_xfer_handle xfer)
2963 /* Nothing to do, all transfers are synchronous. */
2966 /* Close the root pipe. */
2968 uhci_root_ctrl_close(usbd_pipe_handle pipe)
2970 DPRINTF(("uhci_root_ctrl_close\n"));
2973 /* Abort a root interrupt request. */
2975 uhci_root_intr_abort(usbd_xfer_handle xfer)
2977 uhci_softc_t *sc = (uhci_softc_t *)xfer->pipe->device->bus;
2979 usb_untimeout(uhci_timo, xfer, xfer->timo_handle);
2980 sc->sc_has_timo = NULL;
2982 if (xfer->pipe->intrxfer == xfer) {
2983 DPRINTF(("uhci_root_intr_abort: remove\n"));
2984 xfer->pipe->intrxfer = 0;
2986 xfer->status = USBD_CANCELLED;
2987 usb_transfer_complete(xfer);
2991 uhci_root_intr_transfer(usbd_xfer_handle xfer)
2995 /* Insert last in queue. */
2996 err = usb_insert_transfer(xfer);
3000 /* Pipe isn't running (otherwise err would be USBD_INPROG),
3003 return (uhci_root_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
3006 /* Start a transfer on the root interrupt pipe */
3008 uhci_root_intr_start(usbd_xfer_handle xfer)
3010 usbd_pipe_handle pipe = xfer->pipe;
3011 uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
3013 DPRINTFN(3, ("uhci_root_intr_transfer: xfer=%p len=%d flags=%d\n",
3014 xfer, xfer->length, xfer->flags));
3016 sc->sc_ival = MS_TO_TICKS(xfer->pipe->endpoint->edesc->bInterval);
3017 usb_timeout(uhci_timo, xfer, sc->sc_ival, xfer->timo_handle);
3018 sc->sc_has_timo = xfer;
3019 return (USBD_IN_PROGRESS);
3022 /* Close the root interrupt pipe. */
3024 uhci_root_intr_close(usbd_pipe_handle pipe)
3026 uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
3028 usb_untimeout(uhci_timo, pipe->intrxfer, pipe->intrxfer->timo_handle);
3029 sc->sc_has_timo = NULL;
3030 DPRINTF(("uhci_root_intr_close\n"));