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 $ */
3 /* $DragonFly: src/sys/bus/usb/uhci.c,v 1.3 2003/06/21 17:27:24 dillon Exp $ */
6 * Copyright (c) 1998 The NetBSD Foundation, Inc.
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Lennart Augustsson (lennart@augustsson.net) at
11 * Carlstedt Research & Technology.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by the NetBSD
24 * Foundation, Inc. and its contributors.
25 * 4. Neither the name of The NetBSD Foundation nor the names of its
26 * contributors may be used to endorse or promote products derived
27 * from this software without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
30 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
33 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
43 * USB Universal Host Controller driver.
44 * Handles e.g. PIIX3 and PIIX4.
46 * UHCI spec: http://www.intel.com/design/usb/uhci11d.pdf
47 * USB spec: http://www.usb.org/developers/data/usb11.pdf
48 * PIIXn spec: ftp://download.intel.com/design/intarch/datashts/29055002.pdf
49 * ftp://download.intel.com/design/intarch/datashts/29056201.pdf
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/kernel.h>
55 #include <sys/malloc.h>
56 #if defined(__NetBSD__) || defined(__OpenBSD__)
57 #include <sys/device.h>
58 #include <sys/select.h>
59 #elif defined(__FreeBSD__)
60 #include <sys/module.h>
62 #include <machine/bus_pio.h>
63 #if defined(DIAGNOSTIC) && defined(__i386__)
64 #include <machine/cpu.h>
68 #include <sys/queue.h>
69 #include <sys/sysctl.h>
71 #include <machine/bus.h>
72 #include <machine/endian.h>
74 #include <dev/usb/usb.h>
75 #include <dev/usb/usbdi.h>
76 #include <dev/usb/usbdivar.h>
77 #include <dev/usb/usb_mem.h>
78 #include <dev/usb/usb_quirks.h>
80 #include <dev/usb/uhcireg.h>
81 #include <dev/usb/uhcivar.h>
83 #if defined(__FreeBSD__)
84 #include <machine/clock.h>
86 #define delay(d) DELAY(d)
89 #define MS_TO_TICKS(ms) ((ms) * hz / 1000)
91 #if defined(__OpenBSD__)
92 struct cfdriver uhci_cd = {
98 #define DPRINTF(x) if (uhcidebug) printf x
99 #define DPRINTFN(n,x) if (uhcidebug>(n)) printf x
101 SYSCTL_NODE(_hw_usb, OID_AUTO, uhci, CTLFLAG_RW, 0, "USB uhci");
102 SYSCTL_INT(_hw_usb_uhci, OID_AUTO, debug, CTLFLAG_RW,
103 &uhcidebug, 0, "uhci debug level");
106 #define DPRINTFN(n,x)
110 * The UHCI controller is little endian, so on big endian machines
111 * the data strored in memory needs to be swapped.
113 #if BYTE_ORDER == BIG_ENDIAN
114 #define LE(x) (bswap32(x))
120 struct usbd_pipe pipe;
121 uhci_intr_info_t *iinfo;
123 /* Info needed for different pipe kinds. */
129 uhci_soft_td_t *setup, *stat;
135 uhci_soft_qh_t **qhs;
145 uhci_soft_td_t **stds;
152 * The uhci_intr_info free list can be global since they contain
153 * no dma specific data. The other free lists do.
155 LIST_HEAD(, uhci_intr_info) uhci_ii_free;
157 Static void uhci_busreset(uhci_softc_t *);
158 Static usbd_status uhci_run(uhci_softc_t *, int run);
159 Static uhci_soft_td_t *uhci_alloc_std(uhci_softc_t *);
160 Static void uhci_free_std(uhci_softc_t *, uhci_soft_td_t *);
161 Static uhci_soft_qh_t *uhci_alloc_sqh(uhci_softc_t *);
162 Static void uhci_free_sqh(uhci_softc_t *, uhci_soft_qh_t *);
163 Static uhci_intr_info_t *uhci_alloc_intr_info(uhci_softc_t *);
164 Static void uhci_free_intr_info(uhci_intr_info_t *ii);
166 Static void uhci_enter_ctl_q(uhci_softc_t *, uhci_soft_qh_t *,
168 Static void uhci_exit_ctl_q(uhci_softc_t *, uhci_soft_qh_t *);
171 Static void uhci_free_std_chain(uhci_softc_t *,
172 uhci_soft_td_t *, uhci_soft_td_t *);
173 Static usbd_status uhci_alloc_std_chain(struct uhci_pipe *,
174 uhci_softc_t *, int, int, u_int16_t, usb_dma_t *,
175 uhci_soft_td_t **, uhci_soft_td_t **);
176 Static void uhci_timo(void *);
177 Static void uhci_waitintr(uhci_softc_t *, usbd_xfer_handle);
178 Static void uhci_check_intr(uhci_softc_t *, uhci_intr_info_t *);
179 Static void uhci_idone(uhci_intr_info_t *);
181 Static void uhci_abort_xfer(usbd_xfer_handle, usbd_status status);
182 Static void uhci_abort_xfer_end(void *v);
184 Static void uhci_timeout(void *);
185 Static void uhci_lock_frames(uhci_softc_t *);
186 Static void uhci_unlock_frames(uhci_softc_t *);
187 Static void uhci_add_ctrl(uhci_softc_t *, uhci_soft_qh_t *);
188 Static void uhci_add_bulk(uhci_softc_t *, uhci_soft_qh_t *);
189 Static void uhci_remove_ctrl(uhci_softc_t *,uhci_soft_qh_t *);
190 Static void uhci_remove_bulk(uhci_softc_t *,uhci_soft_qh_t *);
191 Static int uhci_str(usb_string_descriptor_t *, int, char *);
193 Static usbd_status uhci_setup_isoc(usbd_pipe_handle pipe);
194 Static void uhci_device_isoc_enter(usbd_xfer_handle);
196 Static usbd_status uhci_allocm(struct usbd_bus *, usb_dma_t *, u_int32_t);
197 Static void uhci_freem(struct usbd_bus *, usb_dma_t *);
199 Static usbd_xfer_handle uhci_allocx(struct usbd_bus *);
200 Static void uhci_freex(struct usbd_bus *, usbd_xfer_handle);
202 Static usbd_status uhci_device_ctrl_transfer(usbd_xfer_handle);
203 Static usbd_status uhci_device_ctrl_start(usbd_xfer_handle);
204 Static void uhci_device_ctrl_abort(usbd_xfer_handle);
205 Static void uhci_device_ctrl_close(usbd_pipe_handle);
206 Static void uhci_device_ctrl_done (usbd_xfer_handle);
208 Static usbd_status uhci_device_intr_transfer(usbd_xfer_handle);
209 Static usbd_status uhci_device_intr_start(usbd_xfer_handle);
210 Static void uhci_device_intr_abort(usbd_xfer_handle);
211 Static void uhci_device_intr_close(usbd_pipe_handle);
212 Static void uhci_device_intr_done (usbd_xfer_handle);
214 Static usbd_status uhci_device_bulk_transfer(usbd_xfer_handle);
215 Static usbd_status uhci_device_bulk_start(usbd_xfer_handle);
216 Static void uhci_device_bulk_abort(usbd_xfer_handle);
217 Static void uhci_device_bulk_close(usbd_pipe_handle);
218 Static void uhci_device_bulk_done (usbd_xfer_handle);
220 Static usbd_status uhci_device_isoc_transfer(usbd_xfer_handle);
221 Static usbd_status uhci_device_isoc_start(usbd_xfer_handle);
222 Static void uhci_device_isoc_abort(usbd_xfer_handle);
223 Static void uhci_device_isoc_close(usbd_pipe_handle);
224 Static void uhci_device_isoc_done (usbd_xfer_handle);
226 Static usbd_status uhci_root_ctrl_transfer(usbd_xfer_handle);
227 Static usbd_status uhci_root_ctrl_start(usbd_xfer_handle);
228 Static void uhci_root_ctrl_abort(usbd_xfer_handle);
229 Static void uhci_root_ctrl_close(usbd_pipe_handle);
231 Static usbd_status uhci_root_intr_transfer(usbd_xfer_handle);
232 Static usbd_status uhci_root_intr_start(usbd_xfer_handle);
233 Static void uhci_root_intr_abort(usbd_xfer_handle);
234 Static void uhci_root_intr_close(usbd_pipe_handle);
235 Static void uhci_root_intr_done (usbd_xfer_handle);
237 Static usbd_status uhci_open(usbd_pipe_handle);
238 Static void uhci_poll(struct usbd_bus *);
240 Static usbd_status uhci_device_request(usbd_xfer_handle xfer);
242 Static void uhci_add_intr(uhci_softc_t *, int, uhci_soft_qh_t *);
243 Static void uhci_remove_intr(uhci_softc_t *, int, uhci_soft_qh_t *);
244 Static usbd_status uhci_device_setintr(uhci_softc_t *sc,
245 struct uhci_pipe *pipe, int ival);
247 Static void uhci_device_clear_toggle(usbd_pipe_handle pipe);
248 Static void uhci_noop(usbd_pipe_handle pipe);
251 Static void uhci_dumpregs(uhci_softc_t *);
252 Static void uhci_dump_qhs(uhci_soft_qh_t *);
253 Static void uhci_dump_qh(uhci_soft_qh_t *);
254 Static void uhci_dump_tds(uhci_soft_td_t *);
255 Static void uhci_dump_td(uhci_soft_td_t *);
258 #define UWRITE1(sc, r, x) bus_space_write_1((sc)->iot, (sc)->ioh, (r), (x))
259 #define UWRITE2(sc, r, x) bus_space_write_2((sc)->iot, (sc)->ioh, (r), (x))
260 #define UWRITE4(sc, r, x) bus_space_write_4((sc)->iot, (sc)->ioh, (r), (x))
261 #define UREAD1(sc, r) bus_space_read_1((sc)->iot, (sc)->ioh, (r))
262 #define UREAD2(sc, r) bus_space_read_2((sc)->iot, (sc)->ioh, (r))
263 #define UREAD4(sc, r) bus_space_read_4((sc)->iot, (sc)->ioh, (r))
265 #define UHCICMD(sc, cmd) UWRITE2(sc, UHCI_CMD, cmd)
266 #define UHCISTS(sc) UREAD2(sc, UHCI_STS)
268 #define UHCI_RESET_TIMEOUT 100 /* reset timeout */
270 #define UHCI_CURFRAME(sc) (UREAD2(sc, UHCI_FRNUM) & UHCI_FRNUM_MASK)
272 #define UHCI_INTR_ENDPT 1
274 struct usbd_bus_methods uhci_bus_methods = {
283 struct usbd_pipe_methods uhci_root_ctrl_methods = {
284 uhci_root_ctrl_transfer,
285 uhci_root_ctrl_start,
286 uhci_root_ctrl_abort,
287 uhci_root_ctrl_close,
292 struct usbd_pipe_methods uhci_root_intr_methods = {
293 uhci_root_intr_transfer,
294 uhci_root_intr_start,
295 uhci_root_intr_abort,
296 uhci_root_intr_close,
301 struct usbd_pipe_methods uhci_device_ctrl_methods = {
302 uhci_device_ctrl_transfer,
303 uhci_device_ctrl_start,
304 uhci_device_ctrl_abort,
305 uhci_device_ctrl_close,
307 uhci_device_ctrl_done,
310 struct usbd_pipe_methods uhci_device_intr_methods = {
311 uhci_device_intr_transfer,
312 uhci_device_intr_start,
313 uhci_device_intr_abort,
314 uhci_device_intr_close,
315 uhci_device_clear_toggle,
316 uhci_device_intr_done,
319 struct usbd_pipe_methods uhci_device_bulk_methods = {
320 uhci_device_bulk_transfer,
321 uhci_device_bulk_start,
322 uhci_device_bulk_abort,
323 uhci_device_bulk_close,
324 uhci_device_clear_toggle,
325 uhci_device_bulk_done,
328 struct usbd_pipe_methods uhci_device_isoc_methods = {
329 uhci_device_isoc_transfer,
330 uhci_device_isoc_start,
331 uhci_device_isoc_abort,
332 uhci_device_isoc_close,
334 uhci_device_isoc_done,
338 uhci_busreset(uhci_softc_t *sc)
340 UHCICMD(sc, UHCI_CMD_GRESET); /* global reset */
341 usb_delay_ms(&sc->sc_bus, USB_BUS_RESET_DELAY); /* wait a little */
342 UHCICMD(sc, 0); /* do nothing */
346 uhci_init(uhci_softc_t *sc)
350 uhci_soft_qh_t *csqh, *bsqh, *sqh;
353 DPRINTFN(1,("uhci_init: start\n"));
360 uhci_run(sc, 0); /* stop the controller */
361 UWRITE2(sc, UHCI_INTR, 0); /* disable interrupts */
365 /* Allocate and initialize real frame array. */
366 err = usb_allocmem(&sc->sc_bus,
367 UHCI_FRAMELIST_COUNT * sizeof(uhci_physaddr_t),
368 UHCI_FRAMELIST_ALIGN, &sc->sc_dma);
371 sc->sc_pframes = KERNADDR(&sc->sc_dma, 0);
372 UWRITE2(sc, UHCI_FRNUM, 0); /* set frame number to 0 */
373 UWRITE4(sc, UHCI_FLBASEADDR, DMAADDR(&sc->sc_dma, 0)); /* set frame list*/
375 /* Allocate the dummy QH where bulk traffic will be queued. */
376 bsqh = uhci_alloc_sqh(sc);
379 bsqh->qh.qh_hlink = LE(UHCI_PTR_T); /* end of QH chain */
380 bsqh->qh.qh_elink = LE(UHCI_PTR_T);
381 sc->sc_bulk_start = sc->sc_bulk_end = bsqh;
383 /* Allocate the dummy QH where control traffic will be queued. */
384 csqh = uhci_alloc_sqh(sc);
388 csqh->qh.qh_hlink = LE(bsqh->physaddr | UHCI_PTR_Q);
389 csqh->qh.qh_elink = LE(UHCI_PTR_T);
390 sc->sc_ctl_start = sc->sc_ctl_end = csqh;
393 * Make all (virtual) frame list pointers point to the interrupt
394 * queue heads and the interrupt queue heads at the control
395 * queue head and point the physical frame list to the virtual.
397 for(i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
398 std = uhci_alloc_std(sc);
399 sqh = uhci_alloc_sqh(sc);
400 if (std == NULL || sqh == NULL)
403 std->td.td_link = LE(sqh->physaddr | UHCI_PTR_Q);
404 std->td.td_status = LE(UHCI_TD_IOS); /* iso, inactive */
405 std->td.td_xtoken = LE(0);
406 std->td.td_buffer = LE(0);
408 sqh->qh.qh_hlink = LE(csqh->physaddr | UHCI_PTR_Q);
410 sqh->qh.qh_elink = LE(UHCI_PTR_T);
411 sc->sc_vframes[i].htd = std;
412 sc->sc_vframes[i].etd = std;
413 sc->sc_vframes[i].hqh = sqh;
414 sc->sc_vframes[i].eqh = sqh;
416 j < UHCI_FRAMELIST_COUNT;
417 j += UHCI_VFRAMELIST_COUNT)
418 sc->sc_pframes[j] = LE(std->physaddr);
421 LIST_INIT(&sc->sc_intrhead);
423 SIMPLEQ_INIT(&sc->sc_free_xfers);
425 /* Set up the bus struct. */
426 sc->sc_bus.methods = &uhci_bus_methods;
427 sc->sc_bus.pipe_size = sizeof(struct uhci_pipe);
429 sc->sc_suspend = PWR_RESUME;
430 #if defined(__NetBSD__)
431 sc->sc_powerhook = powerhook_establish(uhci_power, sc);
432 sc->sc_shutdownhook = shutdownhook_establish(uhci_shutdown, sc);
434 DPRINTFN(1,("uhci_init: enabling\n"));
435 UWRITE2(sc, UHCI_INTR, UHCI_INTR_TOCRCIE | UHCI_INTR_RIE |
436 UHCI_INTR_IOCE | UHCI_INTR_SPIE); /* enable interrupts */
438 UHCICMD(sc, UHCI_CMD_MAXP); /* Assume 64 byte packets at frame end */
440 return (uhci_run(sc, 1)); /* and here we go... */
443 #if defined(__NetBSD__) || defined(__OpenBSD__)
445 uhci_activate(device_ptr_t self, enum devact act)
447 struct uhci_softc *sc = (struct uhci_softc *)self;
455 case DVACT_DEACTIVATE:
456 if (sc->sc_child != NULL)
457 rv = config_deactivate(sc->sc_child);
464 uhci_detach(struct uhci_softc *sc, int flags)
466 usbd_xfer_handle xfer;
469 if (sc->sc_child != NULL)
470 rv = config_detach(sc->sc_child, flags);
475 #if defined(__NetBSD__)
476 powerhook_disestablish(sc->sc_powerhook);
477 shutdownhook_disestablish(sc->sc_shutdownhook);
480 /* Free all xfers associated with this HC. */
482 xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers);
485 SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, xfer, next);
489 /* XXX free other data structures XXX */
496 uhci_allocm(struct usbd_bus *bus, usb_dma_t *dma, u_int32_t size)
498 return (usb_allocmem(&((struct uhci_softc *)bus)->sc_bus, size, 0,
503 uhci_freem(struct usbd_bus *bus, usb_dma_t *dma)
505 usb_freemem(&((struct uhci_softc *)bus)->sc_bus, dma);
509 uhci_allocx(struct usbd_bus *bus)
511 struct uhci_softc *sc = (struct uhci_softc *)bus;
512 usbd_xfer_handle xfer;
514 xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers);
516 SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, xfer, next);
518 xfer = malloc(sizeof(*xfer), M_USB, M_NOWAIT);
520 memset(xfer, 0, sizeof *xfer);
525 uhci_freex(struct usbd_bus *bus, usbd_xfer_handle xfer)
527 struct uhci_softc *sc = (struct uhci_softc *)bus;
529 SIMPLEQ_INSERT_HEAD(&sc->sc_free_xfers, xfer, next);
533 * Shut down the controller when the system is going down.
536 uhci_shutdown(void *v)
538 uhci_softc_t *sc = v;
540 DPRINTF(("uhci_shutdown: stopping the HC\n"));
541 uhci_run(sc, 0); /* stop the controller */
545 * Handle suspend/resume.
547 * We need to switch to polling mode here, because this routine is
548 * called from an intterupt context. This is all right since we
549 * are almost suspended anyway.
552 uhci_power(int why, void *v)
554 uhci_softc_t *sc = v;
559 cmd = UREAD2(sc, UHCI_CMD);
561 DPRINTF(("uhci_power: sc=%p, why=%d (was %d), cmd=0x%x\n",
562 sc, why, sc->sc_suspend, cmd));
564 if (why != PWR_RESUME) {
569 if (sc->sc_has_timo != NULL)
570 usb_untimeout(uhci_timo, sc->sc_has_timo,
571 sc->sc_has_timo->timo_handle);
572 sc->sc_bus.use_polling++;
573 uhci_run(sc, 0); /* stop the controller */
575 /* save some state if BIOS doesn't */
576 sc->sc_saved_frnum = UREAD2(sc, UHCI_FRNUM);
577 sc->sc_saved_sof = UREAD1(sc, UHCI_SOF);
579 UHCICMD(sc, cmd | UHCI_CMD_EGSM); /* enter global suspend */
580 usb_delay_ms(&sc->sc_bus, USB_RESUME_WAIT);
581 sc->sc_suspend = why;
582 sc->sc_bus.use_polling--;
583 DPRINTF(("uhci_power: cmd=0x%x\n", UREAD2(sc, UHCI_CMD)));
586 if (sc->sc_suspend == PWR_RESUME)
587 printf("uhci_power: weird, resume without suspend.\n");
589 sc->sc_bus.use_polling++;
590 sc->sc_suspend = why;
591 if (cmd & UHCI_CMD_RS)
592 uhci_run(sc, 0); /* in case BIOS has started it */
594 /* restore saved state */
595 UWRITE4(sc, UHCI_FLBASEADDR, DMAADDR(&sc->sc_dma, 0));
596 UWRITE2(sc, UHCI_FRNUM, sc->sc_saved_frnum);
597 UWRITE1(sc, UHCI_SOF, sc->sc_saved_sof);
599 UHCICMD(sc, cmd | UHCI_CMD_FGR); /* force global resume */
600 usb_delay_ms(&sc->sc_bus, USB_RESUME_DELAY);
601 UHCICMD(sc, cmd & ~UHCI_CMD_EGSM); /* back to normal */
602 UWRITE2(sc, UHCI_INTR, UHCI_INTR_TOCRCIE | UHCI_INTR_RIE |
603 UHCI_INTR_IOCE | UHCI_INTR_SPIE); /* re-enable intrs */
604 UHCICMD(sc, UHCI_CMD_MAXP);
605 uhci_run(sc, 1); /* and start traffic again */
606 usb_delay_ms(&sc->sc_bus, USB_RESUME_RECOVERY);
607 sc->sc_bus.use_polling--;
608 if (sc->sc_has_timo != NULL)
609 usb_timeout(uhci_timo, sc->sc_has_timo,
610 sc->sc_ival, sc->sc_has_timo->timo_handle);
621 uhci_dumpregs(uhci_softc_t *sc)
623 DPRINTFN(-1,("%s regs: cmd=%04x, sts=%04x, intr=%04x, frnum=%04x, "
624 "flbase=%08x, sof=%04x, portsc1=%04x, portsc2=%04x\n",
625 USBDEVNAME(sc->sc_bus.bdev),
626 UREAD2(sc, UHCI_CMD),
627 UREAD2(sc, UHCI_STS),
628 UREAD2(sc, UHCI_INTR),
629 UREAD2(sc, UHCI_FRNUM),
630 UREAD4(sc, UHCI_FLBASEADDR),
631 UREAD1(sc, UHCI_SOF),
632 UREAD2(sc, UHCI_PORTSC1),
633 UREAD2(sc, UHCI_PORTSC2)));
637 uhci_dump_td(uhci_soft_td_t *p)
639 DPRINTFN(-1,("TD(%p) at %08lx = link=0x%08lx status=0x%08lx "
640 "token=0x%08lx buffer=0x%08lx\n",
641 p, (long)p->physaddr,
642 (long)LE(p->td.td_link),
643 (long)LE(p->td.td_status),
644 (long)LE(p->td.td_xtoken),
645 (long)LE(p->td.td_buffer)));
646 DPRINTFN(-1,(" %b %b,errcnt=%d,actlen=%d pid=%02x,addr=%d,endpt=%d,"
648 (int)LE(p->td.td_link),
650 (int)LE(p->td.td_status),
651 "\20\22BITSTUFF\23CRCTO\24NAK\25BABBLE\26DBUFFER\27"
652 "STALLED\30ACTIVE\31IOC\32ISO\33LS\36SPD",
653 UHCI_TD_GET_ERRCNT(LE(p->td.td_status)),
654 UHCI_TD_GET_ACTLEN(LE(p->td.td_status)),
655 UHCI_TD_GET_PID(LE(p->td.td_xtoken)),
656 UHCI_TD_GET_DEVADDR(LE(p->td.td_xtoken)),
657 UHCI_TD_GET_ENDPT(LE(p->td.td_xtoken)),
658 UHCI_TD_GET_DT(LE(p->td.td_xtoken)),
659 UHCI_TD_GET_MAXLEN(LE(p->td.td_xtoken))));
663 uhci_dump_qh(uhci_soft_qh_t *sqh)
665 DPRINTFN(-1,("QH(%p) at %08x: hlink=%08x elink=%08x\n", sqh,
666 (int)sqh->physaddr, LE(sqh->qh.qh_hlink), LE(sqh->qh.qh_elink)));
674 uhci_softc_t *sc = uhci;
677 printf("intrs=%d\n", sc->sc_bus.no_intrs);
678 printf("framelist[i].link = %08x\n", sc->sc_framelist[0].link);
679 uhci_dump_qh(sc->sc_ctl_start->qh.hlink);
685 uhci_dump_qhs(uhci_soft_qh_t *sqh)
689 /* uhci_dump_qhs displays all the QHs and TDs from the given QH onwards
690 * Traverses sideways first, then down.
700 * TD2.x being the TDs queued at QH2 and QH1 being referenced from QH1.
704 if (sqh->hlink != NULL && !(sqh->qh.qh_hlink & UHCI_PTR_T))
705 uhci_dump_qhs(sqh->hlink);
707 DPRINTF(("No QH\n"));
709 if (sqh->elink != NULL && !(sqh->qh.qh_elink & UHCI_PTR_T))
710 uhci_dump_tds(sqh->elink);
712 DPRINTF(("No TD\n"));
716 uhci_dump_tds(uhci_soft_td_t *std)
720 for(td = std; td != NULL; td = td->link.std) {
723 /* Check whether the link pointer in this TD marks
724 * the link pointer as end of queue. This avoids
725 * printing the free list in case the queue/TD has
726 * already been moved there (seatbelt).
728 if (td->td.td_link & UHCI_PTR_T ||
736 * This routine is executed periodically and simulates interrupts
737 * from the root controller interrupt pipe for port status change.
740 uhci_timo(void *addr)
742 usbd_xfer_handle xfer = addr;
743 usbd_pipe_handle pipe = xfer->pipe;
744 uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
748 DPRINTFN(20, ("uhci_timo\n"));
750 usb_timeout(uhci_timo, xfer, sc->sc_ival, xfer->timo_handle);
752 p = KERNADDR(&xfer->dmabuf, 0);
754 if (UREAD2(sc, UHCI_PORTSC1) & (UHCI_PORTSC_CSC|UHCI_PORTSC_OCIC))
756 if (UREAD2(sc, UHCI_PORTSC2) & (UHCI_PORTSC_CSC|UHCI_PORTSC_OCIC))
759 /* No change, try again in a while */
763 xfer->status = USBD_NORMAL_COMPLETION;
766 xfer->device->bus->intr_context++;
767 usb_transfer_complete(xfer);
768 xfer->device->bus->intr_context--;
773 uhci_root_intr_done(usbd_xfer_handle xfer)
778 uhci_lock_frames(uhci_softc_t *sc)
782 while (sc->sc_vflock & UHCI_HAS_LOCK) {
783 sc->sc_vflock |= UHCI_WANT_LOCK;
784 tsleep(&sc->sc_vflock, PRIBIO, "uhcqhl", 0);
786 sc->sc_vflock = UHCI_HAS_LOCK;
791 uhci_unlock_frames(uhci_softc_t *sc)
795 sc->sc_vflock &= ~UHCI_HAS_LOCK;
796 if (sc->sc_vflock & UHCI_WANT_LOCK)
797 wakeup(&sc->sc_vflock);
802 * Allocate an interrupt information struct. A free list is kept
803 * for fast allocation.
806 uhci_alloc_intr_info(uhci_softc_t *sc)
808 uhci_intr_info_t *ii;
810 ii = LIST_FIRST(&uhci_ii_free);
812 LIST_REMOVE(ii, list);
814 ii = malloc(sizeof(uhci_intr_info_t), M_USBHC, M_NOWAIT);
817 #if defined(__FreeBSD__)
818 callout_handle_init(&ii->timeout_handle);
825 uhci_free_intr_info(uhci_intr_info_t *ii)
827 LIST_INSERT_HEAD(&uhci_ii_free, ii, list); /* and put on free list */
830 /* Add control QH, called at splusb(). */
832 uhci_add_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
838 DPRINTFN(10, ("uhci_add_ctrl: sqh=%p\n", sqh));
839 eqh = sc->sc_ctl_end;
840 sqh->hlink = eqh->hlink;
841 sqh->qh.qh_hlink = eqh->qh.qh_hlink;
843 eqh->qh.qh_hlink = LE(sqh->physaddr | UHCI_PTR_Q);
844 sc->sc_ctl_end = sqh;
847 /* Remove control QH, called at splusb(). */
849 uhci_remove_ctrl(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
855 DPRINTFN(10, ("uhci_remove_ctrl: sqh=%p\n", sqh));
856 for (pqh = sc->sc_ctl_start; pqh->hlink != sqh; pqh=pqh->hlink)
857 #if defined(DIAGNOSTIC) || defined(USB_DEBUG)
858 if (LE(pqh->qh.qh_hlink) & UHCI_PTR_T) {
859 printf("uhci_remove_ctrl: QH not found\n");
865 pqh->hlink = sqh->hlink;
866 pqh->qh.qh_hlink = sqh->qh.qh_hlink;
867 if (sc->sc_ctl_end == sqh)
868 sc->sc_ctl_end = pqh;
871 /* Add bulk QH, called at splusb(). */
873 uhci_add_bulk(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
879 DPRINTFN(10, ("uhci_add_bulk: sqh=%p\n", sqh));
880 eqh = sc->sc_bulk_end;
881 sqh->hlink = eqh->hlink;
882 sqh->qh.qh_hlink = eqh->qh.qh_hlink;
884 eqh->qh.qh_hlink = LE(sqh->physaddr | UHCI_PTR_Q);
885 sc->sc_bulk_end = sqh;
888 /* Remove bulk QH, called at splusb(). */
890 uhci_remove_bulk(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
896 DPRINTFN(10, ("uhci_remove_bulk: sqh=%p\n", sqh));
897 for (pqh = sc->sc_bulk_start; pqh->hlink != sqh; pqh = pqh->hlink)
898 #if defined(DIAGNOSTIC) || defined(USB_DEBUG)
899 if (LE(pqh->qh.qh_hlink) & UHCI_PTR_T) {
900 printf("uhci_remove_bulk: QH not found\n");
906 pqh->hlink = sqh->hlink;
907 pqh->qh.qh_hlink = sqh->qh.qh_hlink;
908 if (sc->sc_bulk_end == sqh)
909 sc->sc_bulk_end = pqh;
915 uhci_softc_t *sc = arg;
918 uhci_intr_info_t *ii;
921 * It can happen that an interrupt will be delivered to
922 * us before the device has been fully attached and the
923 * softc struct has been configured. Usually this happens
924 * when kldloading the USB support as a module after the
925 * system has been booted. If we detect this condition,
926 * we need to squelch the unwanted interrupts until we're
929 if (sc->sc_bus.bdev == NULL) {
930 UWRITE2(sc, UHCI_STS, 0xFFFF); /* ack pending interrupts */
931 uhci_run(sc, 0); /* stop the controller */
932 UWRITE2(sc, UHCI_INTR, 0); /* disable interrupts */
937 if (uhcidebug > 15) {
938 DPRINTF(("%s: uhci_intr\n", USBDEVNAME(sc->sc_bus.bdev)));
943 status = UREAD2(sc, UHCI_STS);
944 if (status == 0) /* The interrupt was not for us. */
947 #if defined(DIAGNOSTIC) && defined(__NetBSD__)
948 if (sc->sc_suspend != PWR_RESUME)
949 printf("uhci_intr: suspended sts=0x%x\n", status);
953 if (status & UHCI_STS_USBINT)
954 ack |= UHCI_STS_USBINT;
955 if (status & UHCI_STS_USBEI)
956 ack |= UHCI_STS_USBEI;
957 if (status & UHCI_STS_RD) {
959 printf("%s: resume detect\n", USBDEVNAME(sc->sc_bus.bdev));
961 if (status & UHCI_STS_HSE) {
963 printf("%s: host system error\n", USBDEVNAME(sc->sc_bus.bdev));
965 if (status & UHCI_STS_HCPE) {
966 ack |= UHCI_STS_HCPE;
967 printf("%s: host controller process error\n",
968 USBDEVNAME(sc->sc_bus.bdev));
970 if (status & UHCI_STS_HCH) {
971 /* no acknowledge needed */
972 printf("%s: host controller halted\n",
973 USBDEVNAME(sc->sc_bus.bdev));
976 if (ack) /* acknowledge the ints */
977 UWRITE2(sc, UHCI_STS, ack);
978 else /* nothing to acknowledge */
981 sc->sc_bus.intr_context++;
982 sc->sc_bus.no_intrs++;
985 * Interrupts on UHCI really suck. When the host controller
986 * interrupts because a transfer is completed there is no
987 * way of knowing which transfer it was. You can scan down
988 * the TDs and QHs of the previous frame to limit the search,
989 * but that assumes that the interrupt was not delayed by more
990 * than 1 ms, which may not always be true (e.g. after debug
991 * output on a slow console).
992 * We scan all interrupt descriptors to see if any have
995 for (ii = LIST_FIRST(&sc->sc_intrhead); ii; ii = LIST_NEXT(ii, list))
996 uhci_check_intr(sc, ii);
998 DPRINTFN(10, ("%s: uhci_intr: exit\n", USBDEVNAME(sc->sc_bus.bdev)));
1000 sc->sc_bus.intr_context--;
1005 /* Check for an interrupt. */
1007 uhci_check_intr(uhci_softc_t *sc, uhci_intr_info_t *ii)
1009 uhci_soft_td_t *std, *lstd;
1012 DPRINTFN(15, ("uhci_check_intr: ii=%p\n", ii));
1015 printf("uhci_check_intr: no ii? %p\n", ii);
1019 if (ii->stdstart == NULL)
1024 printf("uhci_check_intr: std==0\n");
1029 * If the last TD is still active we need to check whether there
1030 * is a an error somewhere in the middle, or whether there was a
1031 * short packet (SPD and not ACTIVE).
1033 if (LE(lstd->td.td_status) & UHCI_TD_ACTIVE) {
1034 DPRINTFN(15, ("uhci_check_intr: active ii=%p\n", ii));
1035 for (std = ii->stdstart; std != lstd; std = std->link.std) {
1036 status = LE(std->td.td_status);
1037 /* If there's an active TD the xfer isn't done. */
1038 if (status & UHCI_TD_ACTIVE)
1040 /* Any kind of error makes the xfer done. */
1041 if (status & UHCI_TD_STALLED)
1044 * We want short packets,
1045 * and it is short: it's done
1047 if ((status & UHCI_TD_SPD) &&
1048 UHCI_TD_GET_ACTLEN(status) <
1049 UHCI_TD_GET_MAXLEN(LE(std->td.td_xtoken)))
1052 DPRINTFN(15, ("uhci_check_intr: ii=%p std=%p still active\n",
1058 usb_untimeout(uhci_timeout, ii, ii->timeout_handle);
1062 /* Called at splusb() */
1064 uhci_idone(uhci_intr_info_t *ii)
1066 usbd_xfer_handle xfer = ii->xfer;
1067 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
1068 uhci_soft_td_t *std;
1069 u_int32_t status = 0, nstatus;
1077 printf("uhci_idone: ii=%p is done!\n", ii);
1085 if (xfer->status == USBD_CANCELLED ||
1086 xfer->status == USBD_TIMEOUT) {
1087 DPRINTF(("uhci_idone: aborted xfer=%p\n", xfer));
1091 if (xfer->nframes != 0) {
1092 /* Isoc transfer, do things differently. */
1093 uhci_soft_td_t **stds = upipe->u.iso.stds;
1096 DPRINTFN(5,("uhci_idone: ii=%p isoc ready\n", ii));
1098 nframes = xfer->nframes;
1100 n = xfer->hcprivint;
1101 for (i = 0; i < nframes; i++) {
1104 if (uhcidebug > 5) {
1105 DPRINTFN(-1,("uhci_idone: isoc TD %d\n", i));
1109 if (++n >= UHCI_VFRAMELIST_COUNT)
1111 status = LE(std->td.td_status);
1112 actlen += UHCI_TD_GET_ACTLEN(status);
1114 upipe->u.iso.inuse -= nframes;
1115 xfer->actlen = actlen;
1116 xfer->status = USBD_NORMAL_COMPLETION;
1118 usb_transfer_complete(xfer);
1123 DPRINTFN(10, ("uhci_idone: ii=%p, xfer=%p, pipe=%p ready\n",
1126 uhci_dump_tds(ii->stdstart);
1129 /* The transfer is done, compute actual length and status. */
1131 for (std = ii->stdstart; std != NULL; std = std->link.std) {
1132 nstatus = LE(std->td.td_status);
1133 if (nstatus & UHCI_TD_ACTIVE)
1137 if (UHCI_TD_GET_PID(LE(std->td.td_xtoken)) != UHCI_TD_PID_SETUP)
1138 actlen += UHCI_TD_GET_ACTLEN(status);
1140 /* If there are left over TDs we need to update the toggle. */
1142 upipe->nexttoggle = UHCI_TD_GET_DT(LE(std->td.td_xtoken));
1144 status &= UHCI_TD_ERROR;
1145 DPRINTFN(10, ("uhci_check_intr: actlen=%d, status=0x%x\n",
1147 xfer->actlen = actlen;
1149 DPRINTFN((status == UHCI_TD_STALLED)*10,
1150 ("uhci_idone: error, addr=%d, endpt=0x%02x, "
1152 xfer->pipe->device->address,
1153 xfer->pipe->endpoint->edesc->bEndpointAddress,
1155 "\20\22BITSTUFF\23CRCTO\24NAK\25BABBLE\26DBUFFER\27"
1156 "STALLED\30ACTIVE"));
1157 if (status == UHCI_TD_STALLED)
1158 xfer->status = USBD_STALLED;
1160 xfer->status = USBD_IOERROR; /* more info XXX */
1162 xfer->status = USBD_NORMAL_COMPLETION;
1165 usb_transfer_complete(xfer);
1169 * Called when a request does not complete.
1172 uhci_timeout(void *addr)
1174 uhci_intr_info_t *ii = addr;
1176 DPRINTF(("uhci_timeout: ii=%p\n", ii));
1180 uhci_dump_tds(ii->stdstart);
1183 ii->xfer->device->bus->intr_context++;
1184 uhci_abort_xfer(ii->xfer, USBD_TIMEOUT);
1185 ii->xfer->device->bus->intr_context--;
1189 * Wait here until controller claims to have an interrupt.
1190 * Then call uhci_intr and return. Use timeout to avoid waiting
1192 * Only used during boot when interrupts are not enabled yet.
1195 uhci_waitintr(uhci_softc_t *sc, usbd_xfer_handle xfer)
1197 int timo = xfer->timeout;
1198 uhci_intr_info_t *ii;
1200 DPRINTFN(10,("uhci_waitintr: timeout = %dms\n", timo));
1202 xfer->status = USBD_IN_PROGRESS;
1203 for (; timo >= 0; timo--) {
1204 usb_delay_ms(&sc->sc_bus, 1);
1205 DPRINTFN(20,("uhci_waitintr: 0x%04x\n", UREAD2(sc, UHCI_STS)));
1206 if (UREAD2(sc, UHCI_STS) & UHCI_STS_USBINT) {
1208 if (xfer->status != USBD_IN_PROGRESS)
1214 DPRINTF(("uhci_waitintr: timeout\n"));
1215 for (ii = LIST_FIRST(&sc->sc_intrhead);
1216 ii != NULL && ii->xfer != xfer;
1217 ii = LIST_NEXT(ii, list))
1221 panic("uhci_waitintr: lost intr_info\n");
1227 uhci_poll(struct usbd_bus *bus)
1229 uhci_softc_t *sc = (uhci_softc_t *)bus;
1231 if (UREAD2(sc, UHCI_STS) & UHCI_STS_USBINT)
1239 uhci_softc_t *sc = p;
1242 UHCICMD(sc, UHCI_CMD_HCRESET);
1243 /* The reset bit goes low when the controller is done. */
1244 for (n = 0; n < UHCI_RESET_TIMEOUT &&
1245 (UREAD2(sc, UHCI_CMD) & UHCI_CMD_HCRESET); n++)
1247 if (n >= UHCI_RESET_TIMEOUT)
1248 printf("%s: controller did not reset\n",
1249 USBDEVNAME(sc->sc_bus.bdev));
1254 uhci_run(uhci_softc_t *sc, int run)
1261 DPRINTF(("uhci_run: setting run=%d\n", run));
1262 cmd = UREAD2(sc, UHCI_CMD);
1266 cmd &= ~UHCI_CMD_RS;
1268 for(n = 0; n < 10; n++) {
1269 running = !(UREAD2(sc, UHCI_STS) & UHCI_STS_HCH);
1270 /* return when we've entered the state we want */
1271 if (run == running) {
1273 DPRINTF(("uhci_run: done cmd=0x%x sts=0x%x\n",
1274 UREAD2(sc, UHCI_CMD), UREAD2(sc, UHCI_STS)));
1275 return (USBD_NORMAL_COMPLETION);
1277 usb_delay_ms(&sc->sc_bus, 1);
1280 printf("%s: cannot %s\n", USBDEVNAME(sc->sc_bus.bdev),
1281 run ? "start" : "stop");
1282 return (USBD_IOERROR);
1286 * Memory management routines.
1287 * uhci_alloc_std allocates TDs
1288 * uhci_alloc_sqh allocates QHs
1289 * These two routines do their own free list management,
1290 * partly for speed, partly because allocating DMAable memory
1291 * has page size granularaity so much memory would be wasted if
1292 * only one TD/QH (32 bytes) was placed in each allocated chunk.
1296 uhci_alloc_std(uhci_softc_t *sc)
1298 uhci_soft_td_t *std;
1303 if (sc->sc_freetds == NULL) {
1304 DPRINTFN(2,("uhci_alloc_std: allocating chunk\n"));
1305 err = usb_allocmem(&sc->sc_bus, UHCI_STD_SIZE * UHCI_STD_CHUNK,
1306 UHCI_TD_ALIGN, &dma);
1309 for(i = 0; i < UHCI_STD_CHUNK; i++) {
1310 offs = i * UHCI_STD_SIZE;
1311 std = (uhci_soft_td_t *)((char *)KERNADDR(&dma, offs));
1312 std->physaddr = DMAADDR(&dma, offs);
1313 std->link.std = sc->sc_freetds;
1314 sc->sc_freetds = std;
1317 std = sc->sc_freetds;
1318 sc->sc_freetds = std->link.std;
1319 memset(&std->td, 0, sizeof(uhci_td_t));
1324 uhci_free_std(uhci_softc_t *sc, uhci_soft_td_t *std)
1327 #define TD_IS_FREE 0x12345678
1328 if (std->td.td_xtoken == LE(TD_IS_FREE)) {
1329 printf("uhci_free_std: freeing free TD %p\n", std);
1332 std->td.td_xtoken = LE(TD_IS_FREE);
1334 std->link.std = sc->sc_freetds;
1335 sc->sc_freetds = std;
1339 uhci_alloc_sqh(uhci_softc_t *sc)
1341 uhci_soft_qh_t *sqh;
1346 if (sc->sc_freeqhs == NULL) {
1347 DPRINTFN(2, ("uhci_alloc_sqh: allocating chunk\n"));
1348 err = usb_allocmem(&sc->sc_bus, UHCI_SQH_SIZE * UHCI_SQH_CHUNK,
1349 UHCI_QH_ALIGN, &dma);
1352 for(i = 0; i < UHCI_SQH_CHUNK; i++) {
1353 offs = i * UHCI_SQH_SIZE;
1354 sqh = (uhci_soft_qh_t *)((char *)KERNADDR(&dma, offs));
1355 sqh->physaddr = DMAADDR(&dma, offs);
1356 sqh->hlink = sc->sc_freeqhs;
1357 sc->sc_freeqhs = sqh;
1360 sqh = sc->sc_freeqhs;
1361 sc->sc_freeqhs = sqh->hlink;
1362 memset(&sqh->qh, 0, sizeof(uhci_qh_t));
1367 uhci_free_sqh(uhci_softc_t *sc, uhci_soft_qh_t *sqh)
1369 sqh->hlink = sc->sc_freeqhs;
1370 sc->sc_freeqhs = sqh;
1375 * Enter a list of transfers onto a control queue.
1376 * Called at splusb()
1379 uhci_enter_ctl_q(uhci_softc_t *sc, uhci_soft_qh_t *sqh, uhci_intr_info_t *ii)
1381 DPRINTFN(5, ("uhci_enter_ctl_q: sqh=%p\n", sqh));
1387 uhci_free_std_chain(uhci_softc_t *sc, uhci_soft_td_t *std,
1388 uhci_soft_td_t *stdend)
1392 for (; std != stdend; std = p) {
1394 uhci_free_std(sc, std);
1399 uhci_alloc_std_chain(struct uhci_pipe *upipe, uhci_softc_t *sc,
1400 int len, int rd, u_int16_t flags, usb_dma_t *dma,
1401 uhci_soft_td_t **sp, uhci_soft_td_t **ep)
1403 uhci_soft_td_t *p, *lastp;
1404 uhci_physaddr_t lastlink;
1405 int i, ntd, l, tog, maxp;
1407 int addr = upipe->pipe.device->address;
1408 int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress;
1410 DPRINTFN(8, ("uhci_alloc_std_chain: addr=%d endpt=%d len=%d ls=%d "
1411 "flags=0x%x\n", addr, UE_GET_ADDR(endpt), len,
1412 upipe->pipe.device->lowspeed, flags));
1413 maxp = UGETW(upipe->pipe.endpoint->edesc->wMaxPacketSize);
1415 printf("uhci_alloc_std_chain: maxp=0\n");
1416 return (USBD_INVAL);
1418 ntd = (len + maxp - 1) / maxp;
1419 if ((flags & USBD_FORCE_SHORT_XFER) && len % maxp == 0)
1421 DPRINTFN(10, ("uhci_alloc_std_chain: maxp=%d ntd=%d\n", maxp, ntd));
1424 DPRINTFN(-1,("uhci_alloc_std_chain: ntd=0\n"));
1425 return (USBD_NORMAL_COMPLETION);
1427 tog = upipe->nexttoggle;
1430 upipe->nexttoggle = tog ^ 1;
1432 lastlink = UHCI_PTR_T;
1434 status = UHCI_TD_ZERO_ACTLEN(UHCI_TD_SET_ERRCNT(3) | UHCI_TD_ACTIVE);
1435 if (upipe->pipe.device->lowspeed)
1436 status |= UHCI_TD_LS;
1437 if (flags & USBD_SHORT_XFER_OK)
1438 status |= UHCI_TD_SPD;
1439 for (i = ntd; i >= 0; i--) {
1440 p = uhci_alloc_std(sc);
1442 uhci_free_std_chain(sc, lastp, 0);
1443 return (USBD_NOMEM);
1445 p->link.std = lastp;
1446 if (lastlink == UHCI_PTR_T)
1447 p->td.td_link = LE(lastlink);
1449 p->td.td_link = LE(lastlink|UHCI_PTR_VF);
1451 lastlink = p->physaddr;
1452 p->td.td_status = LE(status);
1456 if (l == 0 && !(flags & USBD_FORCE_SHORT_XFER))
1462 LE(rd ? UHCI_TD_IN (l, endpt, addr, tog) :
1463 UHCI_TD_OUT(l, endpt, addr, tog));
1464 p->td.td_buffer = LE(DMAADDR(dma, i * maxp));
1468 DPRINTFN(10, ("uhci_alloc_std_chain: nexttog=%d\n",
1469 upipe->nexttoggle));
1470 return (USBD_NORMAL_COMPLETION);
1474 uhci_device_clear_toggle(usbd_pipe_handle pipe)
1476 struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
1477 upipe->nexttoggle = 0;
1481 uhci_noop(usbd_pipe_handle pipe)
1486 uhci_device_bulk_transfer(usbd_xfer_handle xfer)
1490 /* Insert last in queue. */
1491 err = usb_insert_transfer(xfer);
1495 /* Pipe isn't running (otherwise err would be USBD_INPROG),
1498 return (uhci_device_bulk_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
1502 uhci_device_bulk_start(usbd_xfer_handle xfer)
1504 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
1505 usbd_device_handle dev = upipe->pipe.device;
1506 uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
1507 uhci_intr_info_t *ii = upipe->iinfo;
1508 uhci_soft_td_t *data, *dataend;
1509 uhci_soft_qh_t *sqh;
1511 int len, isread, endpt;
1514 DPRINTFN(3, ("uhci_device_bulk_transfer: xfer=%p len=%d flags=%d\n",
1515 xfer, xfer->length, xfer->flags));
1518 if (xfer->rqflags & URQ_REQUEST)
1519 panic("uhci_device_bulk_transfer: a request\n");
1523 endpt = xfer->pipe->endpoint->edesc->bEndpointAddress;
1524 isread = UE_GET_DIR(endpt) == UE_DIR_IN;
1525 sqh = upipe->u.bulk.sqh;
1527 upipe->u.bulk.isread = isread;
1528 upipe->u.bulk.length = len;
1530 err = uhci_alloc_std_chain(upipe, sc, len, isread, xfer->flags,
1531 &xfer->dmabuf, &data, &dataend);
1534 dataend->td.td_status |= LE(UHCI_TD_IOC);
1537 if (uhcidebug > 8) {
1538 DPRINTF(("uhci_device_bulk_transfer: data(1)\n"));
1539 uhci_dump_tds(data);
1543 /* Set up interrupt info. */
1545 ii->stdstart = data;
1546 ii->stdend = dataend;
1547 #if defined(__FreeBSD__)
1548 callout_handle_init(&ii->timeout_handle);
1552 printf("uhci_device_bulk_transfer: not done, ii=%p\n", ii);
1558 sqh->qh.qh_elink = LE(data->physaddr);
1559 sqh->intr_info = ii;
1562 uhci_add_bulk(sc, sqh);
1563 LIST_INSERT_HEAD(&sc->sc_intrhead, ii, list);
1565 if (xfer->timeout && !sc->sc_bus.use_polling) {
1566 usb_timeout(uhci_timeout, ii, MS_TO_TICKS(xfer->timeout),
1567 ii->timeout_handle);
1572 if (uhcidebug > 10) {
1573 DPRINTF(("uhci_device_bulk_transfer: data(2)\n"));
1574 uhci_dump_tds(data);
1578 if (sc->sc_bus.use_polling)
1579 uhci_waitintr(sc, xfer);
1581 return (USBD_IN_PROGRESS);
1584 /* Abort a device bulk request. */
1586 uhci_device_bulk_abort(usbd_xfer_handle xfer)
1588 DPRINTF(("uhci_device_bulk_abort:\n"));
1589 uhci_abort_xfer(xfer, USBD_CANCELLED);
1593 uhci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
1595 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
1596 uhci_intr_info_t *ii = upipe->iinfo;
1597 uhci_soft_td_t *std;
1599 DPRINTFN(1,("uhci_abort_xfer: xfer=%p, status=%d\n", xfer, status));
1601 /* Make interrupt routine ignore it, */
1602 xfer->status = status;
1604 /* don't timeout, */
1605 usb_untimeout(uhci_timeout, ii, ii->timeout_handle);
1607 /* make hardware ignore it, */
1608 for (std = ii->stdstart; std != 0; std = std->link.std)
1609 std->td.td_status &= LE(~(UHCI_TD_ACTIVE | UHCI_TD_IOC));
1614 /* Make sure hardware has completed. */
1615 if (xfer->device->bus->intr_context) {
1616 /* We have no process context, so we can't use tsleep(). */
1617 timeout(uhci_abort_xfer_end, xfer, hz / USB_FRAMES_PER_SECOND);
1619 #if defined(DIAGNOSTIC) && defined(__i386__) && defined(__FreeBSD__)
1620 KASSERT(intr_nesting_level == 0,
1621 ("ohci_abort_req in interrupt context"));
1623 usb_delay_ms(xfer->pipe->device->bus, 1);
1624 /* and call final part of interrupt handler. */
1625 uhci_abort_xfer_end(xfer);
1629 uhci_abort_xfer_end(xfer);
1634 uhci_abort_xfer_end(void *v)
1636 usbd_xfer_handle xfer = v;
1640 usb_transfer_complete(xfer);
1644 /* Close a device bulk pipe. */
1646 uhci_device_bulk_close(usbd_pipe_handle pipe)
1648 struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
1649 usbd_device_handle dev = upipe->pipe.device;
1650 uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
1652 uhci_free_sqh(sc, upipe->u.bulk.sqh);
1653 uhci_free_intr_info(upipe->iinfo);
1654 /* XXX free other resources */
1658 uhci_device_ctrl_transfer(usbd_xfer_handle xfer)
1662 /* Insert last in queue. */
1663 err = usb_insert_transfer(xfer);
1667 /* Pipe isn't running (otherwise err would be USBD_INPROG),
1670 return (uhci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
1674 uhci_device_ctrl_start(usbd_xfer_handle xfer)
1676 uhci_softc_t *sc = (uhci_softc_t *)xfer->pipe->device->bus;
1680 if (!(xfer->rqflags & URQ_REQUEST))
1681 panic("uhci_device_ctrl_transfer: not a request\n");
1684 err = uhci_device_request(xfer);
1688 if (sc->sc_bus.use_polling)
1689 uhci_waitintr(sc, xfer);
1690 return (USBD_IN_PROGRESS);
1694 uhci_device_intr_transfer(usbd_xfer_handle xfer)
1698 /* Insert last in queue. */
1699 err = usb_insert_transfer(xfer);
1703 /* Pipe isn't running (otherwise err would be USBD_INPROG),
1706 return (uhci_device_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
1710 uhci_device_intr_start(usbd_xfer_handle xfer)
1712 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
1713 usbd_device_handle dev = upipe->pipe.device;
1714 uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
1715 uhci_intr_info_t *ii = upipe->iinfo;
1716 uhci_soft_td_t *data, *dataend;
1717 uhci_soft_qh_t *sqh;
1721 DPRINTFN(3,("uhci_device_intr_transfer: xfer=%p len=%d flags=%d\n",
1722 xfer, xfer->length, xfer->flags));
1725 if (xfer->rqflags & URQ_REQUEST)
1726 panic("uhci_device_intr_transfer: a request\n");
1729 err = uhci_alloc_std_chain(upipe, sc, xfer->length, 1, xfer->flags,
1730 &xfer->dmabuf, &data, &dataend);
1733 dataend->td.td_status |= LE(UHCI_TD_IOC);
1736 if (uhcidebug > 10) {
1737 DPRINTF(("uhci_device_intr_transfer: data(1)\n"));
1738 uhci_dump_tds(data);
1739 uhci_dump_qh(upipe->u.intr.qhs[0]);
1744 /* Set up interrupt info. */
1746 ii->stdstart = data;
1747 ii->stdend = dataend;
1748 #if defined(__FreeBSD__)
1749 callout_handle_init(&ii->timeout_handle);
1753 printf("uhci_device_intr_transfer: not done, ii=%p\n", ii);
1758 DPRINTFN(10,("uhci_device_intr_transfer: qhs[0]=%p\n",
1759 upipe->u.intr.qhs[0]));
1760 for (i = 0; i < upipe->u.intr.npoll; i++) {
1761 sqh = upipe->u.intr.qhs[i];
1763 sqh->qh.qh_elink = LE(data->physaddr);
1768 if (uhcidebug > 10) {
1769 DPRINTF(("uhci_device_intr_transfer: data(2)\n"));
1770 uhci_dump_tds(data);
1771 uhci_dump_qh(upipe->u.intr.qhs[0]);
1775 return (USBD_IN_PROGRESS);
1778 /* Abort a device control request. */
1780 uhci_device_ctrl_abort(usbd_xfer_handle xfer)
1782 DPRINTF(("uhci_device_ctrl_abort:\n"));
1783 uhci_abort_xfer(xfer, USBD_CANCELLED);
1786 /* Close a device control pipe. */
1788 uhci_device_ctrl_close(usbd_pipe_handle pipe)
1790 struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
1792 uhci_free_intr_info(upipe->iinfo);
1793 /* XXX free other resources? */
1796 /* Abort a device interrupt request. */
1798 uhci_device_intr_abort(usbd_xfer_handle xfer)
1800 DPRINTFN(1,("uhci_device_intr_abort: xfer=%p\n", xfer));
1801 if (xfer->pipe->intrxfer == xfer) {
1802 DPRINTFN(1,("uhci_device_intr_abort: remove\n"));
1803 xfer->pipe->intrxfer = 0;
1805 uhci_abort_xfer(xfer, USBD_CANCELLED);
1808 /* Close a device interrupt pipe. */
1810 uhci_device_intr_close(usbd_pipe_handle pipe)
1812 struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
1813 uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
1816 upipe->iinfo->stdstart = 0; /* inactive */
1818 /* Unlink descriptors from controller data structures. */
1819 npoll = upipe->u.intr.npoll;
1820 uhci_lock_frames(sc);
1821 for (i = 0; i < npoll; i++)
1822 uhci_remove_intr(sc, upipe->u.intr.qhs[i]->pos,
1823 upipe->u.intr.qhs[i]);
1824 uhci_unlock_frames(sc);
1827 * We now have to wait for any activity on the physical
1828 * descriptors to stop.
1830 usb_delay_ms(&sc->sc_bus, 2);
1832 for(i = 0; i < npoll; i++)
1833 uhci_free_sqh(sc, upipe->u.intr.qhs[i]);
1834 free(upipe->u.intr.qhs, M_USBHC);
1837 LIST_REMOVE(upipe->iinfo, list); /* remove from active list */
1839 uhci_free_intr_info(upipe->iinfo);
1841 /* XXX free other resources */
1845 uhci_device_request(usbd_xfer_handle xfer)
1847 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
1848 usb_device_request_t *req = &xfer->request;
1849 usbd_device_handle dev = upipe->pipe.device;
1850 uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
1851 int addr = dev->address;
1852 int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress;
1853 uhci_intr_info_t *ii = upipe->iinfo;
1854 uhci_soft_td_t *setup, *data, *stat, *next, *dataend;
1855 uhci_soft_qh_t *sqh;
1862 DPRINTFN(3,("uhci_device_control type=0x%02x, request=0x%02x, "
1863 "wValue=0x%04x, wIndex=0x%04x len=%d, addr=%d, endpt=%d\n",
1864 req->bmRequestType, req->bRequest, UGETW(req->wValue),
1865 UGETW(req->wIndex), UGETW(req->wLength),
1868 ls = dev->lowspeed ? UHCI_TD_LS : 0;
1869 isread = req->bmRequestType & UT_READ;
1870 len = UGETW(req->wLength);
1872 setup = upipe->u.ctl.setup;
1873 stat = upipe->u.ctl.stat;
1874 sqh = upipe->u.ctl.sqh;
1876 /* Set up data transaction */
1878 upipe->nexttoggle = 1;
1879 err = uhci_alloc_std_chain(upipe, sc, len, isread, xfer->flags,
1880 &xfer->dmabuf, &data, &dataend);
1884 dataend->link.std = stat;
1885 dataend->td.td_link = LE(stat->physaddr | UHCI_PTR_VF);
1889 upipe->u.ctl.length = len;
1891 memcpy(KERNADDR(&upipe->u.ctl.reqdma, 0), req, sizeof *req);
1893 setup->link.std = next;
1894 setup->td.td_link = LE(next->physaddr | UHCI_PTR_VF);
1895 setup->td.td_status = LE(UHCI_TD_SET_ERRCNT(3) | ls | UHCI_TD_ACTIVE);
1896 setup->td.td_xtoken = LE(UHCI_TD_SETUP(sizeof *req, endpt, addr));
1897 setup->td.td_buffer = LE(DMAADDR(&upipe->u.ctl.reqdma, 0));
1900 stat->td.td_link = LE(UHCI_PTR_T);
1901 stat->td.td_status = LE(UHCI_TD_SET_ERRCNT(3) | ls |
1902 UHCI_TD_ACTIVE | UHCI_TD_IOC);
1903 stat->td.td_xtoken =
1904 LE(isread ? UHCI_TD_OUT(0, endpt, addr, 1) :
1905 UHCI_TD_IN (0, endpt, addr, 1));
1906 stat->td.td_buffer = LE(0);
1909 if (uhcidebug > 10) {
1910 DPRINTF(("uhci_device_request: before transfer\n"));
1911 uhci_dump_tds(setup);
1915 /* Set up interrupt info. */
1917 ii->stdstart = setup;
1919 #if defined(__FreeBSD__)
1920 callout_handle_init(&ii->timeout_handle);
1924 printf("uhci_device_request: not done, ii=%p\n", ii);
1930 sqh->qh.qh_elink = LE(setup->physaddr);
1931 sqh->intr_info = ii;
1934 uhci_add_ctrl(sc, sqh);
1935 LIST_INSERT_HEAD(&sc->sc_intrhead, ii, list);
1937 if (uhcidebug > 12) {
1938 uhci_soft_td_t *std;
1939 uhci_soft_qh_t *xqh;
1940 uhci_soft_qh_t *sxqh;
1942 uhci_physaddr_t link;
1943 DPRINTF(("uhci_enter_ctl_q: follow from [0]\n"));
1944 for (std = sc->sc_vframes[0].htd, link = 0;
1945 (link & UHCI_PTR_Q) == 0;
1946 std = std->link.std) {
1947 link = LE(std->td.td_link);
1950 sxqh = (uhci_soft_qh_t *)std;
1954 xqh = (maxqh++ == 5 || xqh->hlink==sxqh ||
1955 xqh->hlink==xqh ? NULL : xqh->hlink)) {
1958 DPRINTF(("Enqueued QH:\n"));
1960 uhci_dump_tds(sqh->elink);
1963 if (xfer->timeout && !sc->sc_bus.use_polling) {
1964 usb_timeout(uhci_timeout, ii,
1965 MS_TO_TICKS(xfer->timeout), ii->timeout_handle);
1969 return (USBD_NORMAL_COMPLETION);
1973 uhci_device_isoc_transfer(usbd_xfer_handle xfer)
1977 DPRINTFN(5,("uhci_device_isoc_transfer: xfer=%p\n", xfer));
1979 /* Put it on our queue, */
1980 err = usb_insert_transfer(xfer);
1982 /* bail out on error, */
1983 if (err && err != USBD_IN_PROGRESS)
1986 /* XXX should check inuse here */
1988 /* insert into schedule, */
1989 uhci_device_isoc_enter(xfer);
1991 /* and put on interrupt list if the pipe wasn't running */
1993 uhci_device_isoc_start(SIMPLEQ_FIRST(&xfer->pipe->queue));
1999 uhci_device_isoc_enter(usbd_xfer_handle xfer)
2001 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
2002 usbd_device_handle dev = upipe->pipe.device;
2003 uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
2004 struct iso *iso = &upipe->u.iso;
2005 uhci_soft_td_t *std;
2006 u_int32_t buf, len, status;
2007 int s, i, next, nframes;
2009 DPRINTFN(5,("uhci_device_isoc_enter: used=%d next=%d xfer=%p "
2011 iso->inuse, iso->next, xfer, xfer->nframes));
2013 if (xfer->status == USBD_IN_PROGRESS) {
2014 /* This request has already been entered into the frame list */
2019 if (iso->inuse >= UHCI_VFRAMELIST_COUNT)
2020 printf("uhci_device_isoc_enter: overflow!\n");
2025 /* Not in use yet, schedule it a few frames ahead. */
2026 next = (UREAD2(sc, UHCI_FRNUM) + 3) % UHCI_VFRAMELIST_COUNT;
2027 DPRINTFN(2,("uhci_device_isoc_enter: start next=%d\n", next));
2030 xfer->status = USBD_IN_PROGRESS;
2031 xfer->hcprivint = next;
2033 buf = DMAADDR(&xfer->dmabuf, 0);
2034 status = LE(UHCI_TD_ZERO_ACTLEN(UHCI_TD_SET_ERRCNT(0) |
2037 nframes = xfer->nframes;
2039 for (i = 0; i < nframes; i++) {
2040 std = iso->stds[next];
2041 if (++next >= UHCI_VFRAMELIST_COUNT)
2043 len = xfer->frlengths[i];
2044 std->td.td_buffer = LE(buf);
2045 if (i == nframes - 1)
2046 status |= LE(UHCI_TD_IOC);
2047 std->td.td_status = status;
2048 std->td.td_xtoken &= LE(~UHCI_TD_MAXLEN_MASK);
2049 std->td.td_xtoken |= LE(UHCI_TD_SET_MAXLEN(len));
2051 if (uhcidebug > 5) {
2052 DPRINTFN(5,("uhci_device_isoc_enter: TD %d\n", i));
2059 iso->inuse += xfer->nframes;
2065 uhci_device_isoc_start(usbd_xfer_handle xfer)
2067 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
2068 uhci_softc_t *sc = (uhci_softc_t *)upipe->pipe.device->bus;
2069 uhci_intr_info_t *ii = upipe->iinfo;
2070 uhci_soft_td_t *end;
2074 if (xfer->status != USBD_IN_PROGRESS)
2075 printf("uhci_device_isoc_start: not in progress %p\n", xfer);
2078 /* Find the last TD */
2079 i = xfer->hcprivint + xfer->nframes;
2080 if (i >= UHCI_VFRAMELIST_COUNT)
2081 i -= UHCI_VFRAMELIST_COUNT;
2082 end = upipe->u.iso.stds[i];
2086 /* Set up interrupt info. */
2090 #if defined(__FreeBSD__)
2091 callout_handle_init(&ii->timeout_handle);
2095 printf("uhci_device_isoc_start: not done, ii=%p\n", ii);
2099 LIST_INSERT_HEAD(&sc->sc_intrhead, ii, list);
2103 return (USBD_IN_PROGRESS);
2107 uhci_device_isoc_abort(usbd_xfer_handle xfer)
2109 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
2110 uhci_intr_info_t *ii = upipe->iinfo;
2111 uhci_soft_td_t **stds = upipe->u.iso.stds;
2112 uhci_soft_td_t *std;
2115 /* Make interrupt routine ignore it, */
2116 xfer->status = USBD_CANCELLED;
2118 /* make hardware ignore it, */
2119 nframes = xfer->nframes;
2120 n = xfer->hcprivint;
2121 for (i = 0; i < nframes; i++) {
2123 std->td.td_status &= LE(~(UHCI_TD_ACTIVE | UHCI_TD_IOC));
2124 if (++n >= UHCI_VFRAMELIST_COUNT)
2130 /* make sure hardware has completed, */
2131 if (xfer->device->bus->intr_context) {
2132 /* We have no process context, so we can't use tsleep(). */
2133 timeout(uhci_abort_xfer_end, xfer, hz / USB_FRAMES_PER_SECOND);
2135 usb_delay_ms(xfer->pipe->device->bus, 1);
2136 /* and call final part of interrupt handler. */
2137 uhci_abort_xfer_end(xfer);
2142 uhci_device_isoc_close(usbd_pipe_handle pipe)
2144 struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
2145 usbd_device_handle dev = upipe->pipe.device;
2146 uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
2147 uhci_soft_td_t *std, *vstd;
2152 * Make sure all TDs are marked as inactive.
2153 * Wait for completion.
2157 iso = &upipe->u.iso;
2159 for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++)
2160 iso->stds[i]->td.td_status &= LE(~UHCI_TD_ACTIVE);
2161 usb_delay_ms(&sc->sc_bus, 2); /* wait for completion */
2163 uhci_lock_frames(sc);
2164 for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
2166 for (vstd = sc->sc_vframes[i].htd;
2167 vstd != NULL && vstd->link.std != std;
2168 vstd = vstd->link.std)
2172 printf("uhci_device_isoc_close: %p not found\n", std);
2173 uhci_unlock_frames(sc);
2176 vstd->link = std->link;
2177 vstd->td.td_link = std->td.td_link;
2178 uhci_free_std(sc, std);
2180 uhci_unlock_frames(sc);
2182 free(iso->stds, M_USBHC);
2186 uhci_setup_isoc(usbd_pipe_handle pipe)
2188 struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
2189 usbd_device_handle dev = upipe->pipe.device;
2190 uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
2191 int addr = upipe->pipe.device->address;
2192 int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress;
2193 int rd = UE_GET_DIR(endpt) == UE_DIR_IN;
2194 uhci_soft_td_t *std, *vstd;
2199 iso = &upipe->u.iso;
2200 iso->stds = malloc(UHCI_VFRAMELIST_COUNT * sizeof (uhci_soft_td_t *),
2203 token = LE(rd ? UHCI_TD_IN (0, endpt, addr, 0) :
2204 UHCI_TD_OUT(0, endpt, addr, 0));
2206 /* Allocate the TDs and mark as inactive; */
2207 for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
2208 std = uhci_alloc_std(sc);
2211 std->td.td_status = LE(UHCI_TD_IOS); /* iso, inactive */
2212 std->td.td_xtoken = token;
2216 /* Insert TDs into schedule. */
2217 uhci_lock_frames(sc);
2218 for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
2220 vstd = sc->sc_vframes[i].htd;
2221 std->link = vstd->link;
2222 std->td.td_link = vstd->td.td_link;
2223 vstd->link.std = std;
2224 vstd->td.td_link = LE(std->physaddr);
2226 uhci_unlock_frames(sc);
2231 return (USBD_NORMAL_COMPLETION);
2235 uhci_free_std(sc, iso->stds[i]);
2236 free(iso->stds, M_USBHC);
2237 return (USBD_NOMEM);
2241 uhci_device_isoc_done(usbd_xfer_handle xfer)
2243 uhci_intr_info_t *ii = xfer->hcpriv;
2245 DPRINTFN(4, ("uhci_isoc_done: length=%d\n", xfer->actlen));
2247 /* Turn off the interrupt since it is active even if the TD is not. */
2248 ii->stdend->td.td_status &= LE(~UHCI_TD_IOC);
2250 LIST_REMOVE(ii, list); /* remove from active list */
2254 uhci_device_intr_done(usbd_xfer_handle xfer)
2256 uhci_intr_info_t *ii = xfer->hcpriv;
2257 uhci_softc_t *sc = ii->sc;
2258 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
2259 uhci_soft_qh_t *sqh;
2262 DPRINTFN(5, ("uhci_intr_done: length=%d\n", xfer->actlen));
2264 npoll = upipe->u.intr.npoll;
2265 for(i = 0; i < npoll; i++) {
2266 sqh = upipe->u.intr.qhs[i];
2268 sqh->qh.qh_elink = LE(UHCI_PTR_T);
2270 uhci_free_std_chain(sc, ii->stdstart, 0);
2273 if (xfer->pipe->repeat) {
2274 uhci_soft_td_t *data, *dataend;
2276 /* This alloc cannot fail since we freed the chain above. */
2277 uhci_alloc_std_chain(upipe, sc, xfer->length, 1, xfer->flags,
2278 &xfer->dmabuf, &data, &dataend);
2279 dataend->td.td_status |= LE(UHCI_TD_IOC);
2282 if (uhcidebug > 10) {
2283 DPRINTF(("uhci_device_intr_done: data(1)\n"));
2284 uhci_dump_tds(data);
2285 uhci_dump_qh(upipe->u.intr.qhs[0]);
2289 ii->stdstart = data;
2290 ii->stdend = dataend;
2291 #if defined(__FreeBSD__)
2292 callout_handle_init(&ii->timeout_handle);
2296 printf("uhci_device_intr_done: not done, ii=%p\n", ii);
2300 for (i = 0; i < npoll; i++) {
2301 sqh = upipe->u.intr.qhs[i];
2303 sqh->qh.qh_elink = LE(data->physaddr);
2306 ii->stdstart = 0; /* mark as inactive */
2310 /* Deallocate request data structures */
2312 uhci_device_ctrl_done(usbd_xfer_handle xfer)
2314 uhci_intr_info_t *ii = xfer->hcpriv;
2315 uhci_softc_t *sc = ii->sc;
2316 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
2319 if (!(xfer->rqflags & URQ_REQUEST))
2320 panic("uhci_ctrl_done: not a request\n");
2323 LIST_REMOVE(ii, list); /* remove from active list */
2325 uhci_remove_ctrl(sc, upipe->u.ctl.sqh);
2327 if (upipe->u.ctl.length != 0)
2328 uhci_free_std_chain(sc, ii->stdstart->link.std, ii->stdend);
2330 DPRINTFN(5, ("uhci_ctrl_done: length=%d\n", xfer->actlen));
2333 /* Deallocate request data structures */
2335 uhci_device_bulk_done(usbd_xfer_handle xfer)
2337 uhci_intr_info_t *ii = xfer->hcpriv;
2338 uhci_softc_t *sc = ii->sc;
2339 struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
2341 LIST_REMOVE(ii, list); /* remove from active list */
2343 uhci_remove_bulk(sc, upipe->u.bulk.sqh);
2345 uhci_free_std_chain(sc, ii->stdstart, 0);
2347 DPRINTFN(5, ("uhci_bulk_done: length=%d\n", xfer->actlen));
2350 /* Add interrupt QH, called with vflock. */
2352 uhci_add_intr(uhci_softc_t *sc, int n, uhci_soft_qh_t *sqh)
2354 struct uhci_vframe *vf = &sc->sc_vframes[n];
2355 uhci_soft_qh_t *eqh;
2357 DPRINTFN(4, ("uhci_add_intr: n=%d sqh=%p\n", n, sqh));
2359 sqh->hlink = eqh->hlink;
2360 sqh->qh.qh_hlink = eqh->qh.qh_hlink;
2362 eqh->qh.qh_hlink = LE(sqh->physaddr | UHCI_PTR_Q);
2367 /* Remove interrupt QH, called with vflock. */
2369 uhci_remove_intr(uhci_softc_t *sc, int n, uhci_soft_qh_t *sqh)
2371 struct uhci_vframe *vf = &sc->sc_vframes[n];
2372 uhci_soft_qh_t *pqh;
2374 DPRINTFN(4, ("uhci_remove_intr: n=%d sqh=%p\n", n, sqh));
2376 for (pqh = vf->hqh; pqh->hlink != sqh; pqh = pqh->hlink)
2377 #if defined(DIAGNOSTIC) || defined(USB_DEBUG)
2378 if (LE(pqh->qh.qh_hlink) & UHCI_PTR_T) {
2379 DPRINTF(("uhci_remove_intr: QH not found\n"));
2385 pqh->hlink = sqh->hlink;
2386 pqh->qh.qh_hlink = sqh->qh.qh_hlink;
2393 uhci_device_setintr(uhci_softc_t *sc, struct uhci_pipe *upipe, int ival)
2395 uhci_soft_qh_t *sqh;
2397 u_int bestbw, bw, bestoffs, offs;
2399 DPRINTFN(2, ("uhci_setintr: pipe=%p\n", upipe));
2401 printf("uhci_setintr: 0 interval\n");
2402 return (USBD_INVAL);
2405 if (ival > UHCI_VFRAMELIST_COUNT)
2406 ival = UHCI_VFRAMELIST_COUNT;
2407 npoll = (UHCI_VFRAMELIST_COUNT + ival - 1) / ival;
2408 DPRINTFN(2, ("uhci_setintr: ival=%d npoll=%d\n", ival, npoll));
2410 upipe->u.intr.npoll = npoll;
2412 malloc(npoll * sizeof(uhci_soft_qh_t *), M_USBHC, M_WAITOK);
2415 * Figure out which offset in the schedule that has most
2416 * bandwidth left over.
2418 #define MOD(i) ((i) & (UHCI_VFRAMELIST_COUNT-1))
2419 for (bestoffs = offs = 0, bestbw = ~0; offs < ival; offs++) {
2420 for (bw = i = 0; i < npoll; i++)
2421 bw += sc->sc_vframes[MOD(i * ival + offs)].bandwidth;
2427 DPRINTFN(1, ("uhci_setintr: bw=%d offs=%d\n", bestbw, bestoffs));
2429 upipe->iinfo->stdstart = 0;
2430 for(i = 0; i < npoll; i++) {
2431 upipe->u.intr.qhs[i] = sqh = uhci_alloc_sqh(sc);
2433 sqh->qh.qh_elink = LE(UHCI_PTR_T);
2434 sqh->pos = MOD(i * ival + bestoffs);
2435 sqh->intr_info = upipe->iinfo;
2440 LIST_INSERT_HEAD(&sc->sc_intrhead, upipe->iinfo, list);
2443 uhci_lock_frames(sc);
2444 /* Enter QHs into the controller data structures. */
2445 for(i = 0; i < npoll; i++)
2446 uhci_add_intr(sc, upipe->u.intr.qhs[i]->pos,
2447 upipe->u.intr.qhs[i]);
2448 uhci_unlock_frames(sc);
2450 DPRINTFN(5, ("uhci_setintr: returns %p\n", upipe));
2451 return (USBD_NORMAL_COMPLETION);
2454 /* Open a new pipe. */
2456 uhci_open(usbd_pipe_handle pipe)
2458 uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
2459 struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
2460 usb_endpoint_descriptor_t *ed = pipe->endpoint->edesc;
2464 DPRINTFN(1, ("uhci_open: pipe=%p, addr=%d, endpt=%d (%d)\n",
2465 pipe, pipe->device->address,
2466 ed->bEndpointAddress, sc->sc_addr));
2467 if (pipe->device->address == sc->sc_addr) {
2468 switch (ed->bEndpointAddress) {
2469 case USB_CONTROL_ENDPOINT:
2470 pipe->methods = &uhci_root_ctrl_methods;
2472 case UE_DIR_IN | UHCI_INTR_ENDPT:
2473 pipe->methods = &uhci_root_intr_methods;
2476 return (USBD_INVAL);
2479 upipe->iinfo = uhci_alloc_intr_info(sc);
2480 if (upipe->iinfo == 0)
2481 return (USBD_NOMEM);
2482 switch (ed->bmAttributes & UE_XFERTYPE) {
2484 pipe->methods = &uhci_device_ctrl_methods;
2485 upipe->u.ctl.sqh = uhci_alloc_sqh(sc);
2486 if (upipe->u.ctl.sqh == NULL)
2488 upipe->u.ctl.setup = uhci_alloc_std(sc);
2489 if (upipe->u.ctl.setup == NULL) {
2490 uhci_free_sqh(sc, upipe->u.ctl.sqh);
2493 upipe->u.ctl.stat = uhci_alloc_std(sc);
2494 if (upipe->u.ctl.stat == NULL) {
2495 uhci_free_sqh(sc, upipe->u.ctl.sqh);
2496 uhci_free_std(sc, upipe->u.ctl.setup);
2499 err = usb_allocmem(&sc->sc_bus,
2500 sizeof(usb_device_request_t),
2501 0, &upipe->u.ctl.reqdma);
2503 uhci_free_sqh(sc, upipe->u.ctl.sqh);
2504 uhci_free_std(sc, upipe->u.ctl.setup);
2505 uhci_free_std(sc, upipe->u.ctl.stat);
2510 pipe->methods = &uhci_device_intr_methods;
2511 ival = pipe->interval;
2512 if (ival == USBD_DEFAULT_INTERVAL)
2513 ival = ed->bInterval;
2514 return (uhci_device_setintr(sc, upipe, ival));
2515 case UE_ISOCHRONOUS:
2516 pipe->methods = &uhci_device_isoc_methods;
2517 return (uhci_setup_isoc(pipe));
2519 pipe->methods = &uhci_device_bulk_methods;
2520 upipe->u.bulk.sqh = uhci_alloc_sqh(sc);
2521 if (upipe->u.bulk.sqh == NULL)
2526 return (USBD_NORMAL_COMPLETION);
2529 uhci_free_intr_info(upipe->iinfo);
2530 return (USBD_NOMEM);
2534 * Data structures and routines to emulate the root hub.
2536 usb_device_descriptor_t uhci_devd = {
2537 USB_DEVICE_DESCRIPTOR_SIZE,
2538 UDESC_DEVICE, /* type */
2539 {0x00, 0x01}, /* USB version */
2540 UDCLASS_HUB, /* class */
2541 UDSUBCLASS_HUB, /* subclass */
2542 UDPROTO_FSHUB, /* protocol */
2543 64, /* max packet */
2544 {0},{0},{0x00,0x01}, /* device id */
2545 1,2,0, /* string indicies */
2546 1 /* # of configurations */
2549 usb_config_descriptor_t uhci_confd = {
2550 USB_CONFIG_DESCRIPTOR_SIZE,
2552 {USB_CONFIG_DESCRIPTOR_SIZE +
2553 USB_INTERFACE_DESCRIPTOR_SIZE +
2554 USB_ENDPOINT_DESCRIPTOR_SIZE},
2562 usb_interface_descriptor_t uhci_ifcd = {
2563 USB_INTERFACE_DESCRIPTOR_SIZE,
2574 usb_endpoint_descriptor_t uhci_endpd = {
2575 USB_ENDPOINT_DESCRIPTOR_SIZE,
2577 UE_DIR_IN | UHCI_INTR_ENDPT,
2583 usb_hub_descriptor_t uhci_hubd_piix = {
2584 USB_HUB_DESCRIPTOR_SIZE,
2587 { UHD_PWR_NO_SWITCH | UHD_OC_INDIVIDUAL, 0 },
2588 50, /* power on to power good */
2590 { 0x00 }, /* both ports are removable */
2594 uhci_str(usb_string_descriptor_t *p, int l, char *s)
2600 p->bLength = 2 * strlen(s) + 2;
2603 p->bDescriptorType = UDESC_STRING;
2605 for (i = 0; s[i] && l > 1; i++, l -= 2)
2606 USETW2(p->bString[i], 0, s[i]);
2611 * Simulate a hardware hub by handling all the necessary requests.
2614 uhci_root_ctrl_transfer(usbd_xfer_handle xfer)
2618 /* Insert last in queue. */
2619 err = usb_insert_transfer(xfer);
2623 /* Pipe isn't running (otherwise err would be USBD_INPROG),
2626 return (uhci_root_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
2630 uhci_root_ctrl_start(usbd_xfer_handle xfer)
2632 uhci_softc_t *sc = (uhci_softc_t *)xfer->pipe->device->bus;
2633 usb_device_request_t *req;
2636 int s, len, value, index, status, change, l, totlen = 0;
2637 usb_port_status_t ps;
2641 if (!(xfer->rqflags & URQ_REQUEST))
2642 panic("uhci_root_ctrl_transfer: not a request\n");
2644 req = &xfer->request;
2646 DPRINTFN(2,("uhci_root_ctrl_control type=0x%02x request=%02x\n",
2647 req->bmRequestType, req->bRequest));
2649 len = UGETW(req->wLength);
2650 value = UGETW(req->wValue);
2651 index = UGETW(req->wIndex);
2654 buf = KERNADDR(&xfer->dmabuf, 0);
2656 #define C(x,y) ((x) | ((y) << 8))
2657 switch(C(req->bRequest, req->bmRequestType)) {
2658 case C(UR_CLEAR_FEATURE, UT_WRITE_DEVICE):
2659 case C(UR_CLEAR_FEATURE, UT_WRITE_INTERFACE):
2660 case C(UR_CLEAR_FEATURE, UT_WRITE_ENDPOINT):
2662 * DEVICE_REMOTE_WAKEUP and ENDPOINT_HALT are no-ops
2663 * for the integrated root hub.
2666 case C(UR_GET_CONFIG, UT_READ_DEVICE):
2668 *(u_int8_t *)buf = sc->sc_conf;
2672 case C(UR_GET_DESCRIPTOR, UT_READ_DEVICE):
2673 DPRINTFN(2,("uhci_root_ctrl_control wValue=0x%04x\n", value));
2674 switch(value >> 8) {
2676 if ((value & 0xff) != 0) {
2680 totlen = l = min(len, USB_DEVICE_DESCRIPTOR_SIZE);
2681 USETW(uhci_devd.idVendor, sc->sc_id_vendor);
2682 memcpy(buf, &uhci_devd, l);
2685 if ((value & 0xff) != 0) {
2689 totlen = l = min(len, USB_CONFIG_DESCRIPTOR_SIZE);
2690 memcpy(buf, &uhci_confd, l);
2691 buf = (char *)buf + l;
2693 l = min(len, USB_INTERFACE_DESCRIPTOR_SIZE);
2695 memcpy(buf, &uhci_ifcd, l);
2696 buf = (char *)buf + l;
2698 l = min(len, USB_ENDPOINT_DESCRIPTOR_SIZE);
2700 memcpy(buf, &uhci_endpd, l);
2705 *(u_int8_t *)buf = 0;
2707 switch (value & 0xff) {
2708 case 1: /* Vendor */
2709 totlen = uhci_str(buf, len, sc->sc_vendor);
2711 case 2: /* Product */
2712 totlen = uhci_str(buf, len, "UHCI root hub");
2721 case C(UR_GET_INTERFACE, UT_READ_INTERFACE):
2723 *(u_int8_t *)buf = 0;
2727 case C(UR_GET_STATUS, UT_READ_DEVICE):
2729 USETW(((usb_status_t *)buf)->wStatus,UDS_SELF_POWERED);
2733 case C(UR_GET_STATUS, UT_READ_INTERFACE):
2734 case C(UR_GET_STATUS, UT_READ_ENDPOINT):
2736 USETW(((usb_status_t *)buf)->wStatus, 0);
2740 case C(UR_SET_ADDRESS, UT_WRITE_DEVICE):
2741 if (value >= USB_MAX_DEVICES) {
2745 sc->sc_addr = value;
2747 case C(UR_SET_CONFIG, UT_WRITE_DEVICE):
2748 if (value != 0 && value != 1) {
2752 sc->sc_conf = value;
2754 case C(UR_SET_DESCRIPTOR, UT_WRITE_DEVICE):
2756 case C(UR_SET_FEATURE, UT_WRITE_DEVICE):
2757 case C(UR_SET_FEATURE, UT_WRITE_INTERFACE):
2758 case C(UR_SET_FEATURE, UT_WRITE_ENDPOINT):
2761 case C(UR_SET_INTERFACE, UT_WRITE_INTERFACE):
2763 case C(UR_SYNCH_FRAME, UT_WRITE_ENDPOINT):
2766 case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_DEVICE):
2768 case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_OTHER):
2769 DPRINTFN(3, ("uhci_root_ctrl_control: UR_CLEAR_PORT_FEATURE "
2770 "port=%d feature=%d\n",
2773 port = UHCI_PORTSC1;
2774 else if (index == 2)
2775 port = UHCI_PORTSC2;
2781 case UHF_PORT_ENABLE:
2782 x = UREAD2(sc, port);
2783 UWRITE2(sc, port, x & ~UHCI_PORTSC_PE);
2785 case UHF_PORT_SUSPEND:
2786 x = UREAD2(sc, port);
2787 UWRITE2(sc, port, x & ~UHCI_PORTSC_SUSP);
2789 case UHF_PORT_RESET:
2790 x = UREAD2(sc, port);
2791 UWRITE2(sc, port, x & ~UHCI_PORTSC_PR);
2793 case UHF_C_PORT_CONNECTION:
2794 x = UREAD2(sc, port);
2795 UWRITE2(sc, port, x | UHCI_PORTSC_CSC);
2797 case UHF_C_PORT_ENABLE:
2798 x = UREAD2(sc, port);
2799 UWRITE2(sc, port, x | UHCI_PORTSC_POEDC);
2801 case UHF_C_PORT_OVER_CURRENT:
2802 x = UREAD2(sc, port);
2803 UWRITE2(sc, port, x | UHCI_PORTSC_OCIC);
2805 case UHF_C_PORT_RESET:
2807 err = USBD_NORMAL_COMPLETION;
2809 case UHF_PORT_CONNECTION:
2810 case UHF_PORT_OVER_CURRENT:
2811 case UHF_PORT_POWER:
2812 case UHF_PORT_LOW_SPEED:
2813 case UHF_C_PORT_SUSPEND:
2819 case C(UR_GET_BUS_STATE, UT_READ_CLASS_OTHER):
2821 port = UHCI_PORTSC1;
2822 else if (index == 2)
2823 port = UHCI_PORTSC2;
2830 (UREAD2(sc, port) & UHCI_PORTSC_LS) >>
2831 UHCI_PORTSC_LS_SHIFT;
2835 case C(UR_GET_DESCRIPTOR, UT_READ_CLASS_DEVICE):
2840 l = min(len, USB_HUB_DESCRIPTOR_SIZE);
2842 memcpy(buf, &uhci_hubd_piix, l);
2844 case C(UR_GET_STATUS, UT_READ_CLASS_DEVICE):
2849 memset(buf, 0, len);
2852 case C(UR_GET_STATUS, UT_READ_CLASS_OTHER):
2854 port = UHCI_PORTSC1;
2855 else if (index == 2)
2856 port = UHCI_PORTSC2;
2865 x = UREAD2(sc, port);
2866 status = change = 0;
2867 if (x & UHCI_PORTSC_CCS )
2868 status |= UPS_CURRENT_CONNECT_STATUS;
2869 if (x & UHCI_PORTSC_CSC )
2870 change |= UPS_C_CONNECT_STATUS;
2871 if (x & UHCI_PORTSC_PE )
2872 status |= UPS_PORT_ENABLED;
2873 if (x & UHCI_PORTSC_POEDC)
2874 change |= UPS_C_PORT_ENABLED;
2875 if (x & UHCI_PORTSC_OCI )
2876 status |= UPS_OVERCURRENT_INDICATOR;
2877 if (x & UHCI_PORTSC_OCIC )
2878 change |= UPS_C_OVERCURRENT_INDICATOR;
2879 if (x & UHCI_PORTSC_SUSP )
2880 status |= UPS_SUSPEND;
2881 if (x & UHCI_PORTSC_LSDA )
2882 status |= UPS_LOW_SPEED;
2883 status |= UPS_PORT_POWER;
2885 change |= UPS_C_PORT_RESET;
2886 USETW(ps.wPortStatus, status);
2887 USETW(ps.wPortChange, change);
2888 l = min(len, sizeof ps);
2889 memcpy(buf, &ps, l);
2892 case C(UR_SET_DESCRIPTOR, UT_WRITE_CLASS_DEVICE):
2895 case C(UR_SET_FEATURE, UT_WRITE_CLASS_DEVICE):
2897 case C(UR_SET_FEATURE, UT_WRITE_CLASS_OTHER):
2899 port = UHCI_PORTSC1;
2900 else if (index == 2)
2901 port = UHCI_PORTSC2;
2907 case UHF_PORT_ENABLE:
2908 x = UREAD2(sc, port);
2909 UWRITE2(sc, port, x | UHCI_PORTSC_PE);
2911 case UHF_PORT_SUSPEND:
2912 x = UREAD2(sc, port);
2913 UWRITE2(sc, port, x | UHCI_PORTSC_SUSP);
2915 case UHF_PORT_RESET:
2916 x = UREAD2(sc, port);
2917 UWRITE2(sc, port, x | UHCI_PORTSC_PR);
2918 usb_delay_ms(&sc->sc_bus, 10);
2919 UWRITE2(sc, port, x & ~UHCI_PORTSC_PR);
2921 x = UREAD2(sc, port);
2922 UWRITE2(sc, port, x | UHCI_PORTSC_PE);
2924 DPRINTFN(3,("uhci port %d reset, status = 0x%04x\n",
2925 index, UREAD2(sc, port)));
2928 case UHF_PORT_POWER:
2929 /* Pretend we turned on power */
2930 err = USBD_NORMAL_COMPLETION;
2932 case UHF_C_PORT_CONNECTION:
2933 case UHF_C_PORT_ENABLE:
2934 case UHF_C_PORT_OVER_CURRENT:
2935 case UHF_PORT_CONNECTION:
2936 case UHF_PORT_OVER_CURRENT:
2937 case UHF_PORT_LOW_SPEED:
2938 case UHF_C_PORT_SUSPEND:
2939 case UHF_C_PORT_RESET:
2949 xfer->actlen = totlen;
2950 err = USBD_NORMAL_COMPLETION;
2955 usb_transfer_complete(xfer);
2957 return (USBD_IN_PROGRESS);
2960 /* Abort a root control request. */
2962 uhci_root_ctrl_abort(usbd_xfer_handle xfer)
2964 /* Nothing to do, all transfers are synchronous. */
2967 /* Close the root pipe. */
2969 uhci_root_ctrl_close(usbd_pipe_handle pipe)
2971 DPRINTF(("uhci_root_ctrl_close\n"));
2974 /* Abort a root interrupt request. */
2976 uhci_root_intr_abort(usbd_xfer_handle xfer)
2978 uhci_softc_t *sc = (uhci_softc_t *)xfer->pipe->device->bus;
2980 usb_untimeout(uhci_timo, xfer, xfer->timo_handle);
2981 sc->sc_has_timo = NULL;
2983 if (xfer->pipe->intrxfer == xfer) {
2984 DPRINTF(("uhci_root_intr_abort: remove\n"));
2985 xfer->pipe->intrxfer = 0;
2987 xfer->status = USBD_CANCELLED;
2988 usb_transfer_complete(xfer);
2992 uhci_root_intr_transfer(usbd_xfer_handle xfer)
2996 /* Insert last in queue. */
2997 err = usb_insert_transfer(xfer);
3001 /* Pipe isn't running (otherwise err would be USBD_INPROG),
3004 return (uhci_root_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
3007 /* Start a transfer on the root interrupt pipe */
3009 uhci_root_intr_start(usbd_xfer_handle xfer)
3011 usbd_pipe_handle pipe = xfer->pipe;
3012 uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
3014 DPRINTFN(3, ("uhci_root_intr_transfer: xfer=%p len=%d flags=%d\n",
3015 xfer, xfer->length, xfer->flags));
3017 sc->sc_ival = MS_TO_TICKS(xfer->pipe->endpoint->edesc->bInterval);
3018 usb_timeout(uhci_timo, xfer, sc->sc_ival, xfer->timo_handle);
3019 sc->sc_has_timo = xfer;
3020 return (USBD_IN_PROGRESS);
3023 /* Close the root interrupt pipe. */
3025 uhci_root_intr_close(usbd_pipe_handle pipe)
3027 uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
3029 usb_untimeout(uhci_timo, pipe->intrxfer, pipe->intrxfer->timo_handle);
3030 sc->sc_has_timo = NULL;
3031 DPRINTF(("uhci_root_intr_close\n"));