5 * Copyright (c) 2010 Hans Petter Selasky. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * This file contains the driver for Octeon Executive Library USB
31 * Controller driver API.
34 /* TODO: The root HUB port callback is not yet implemented. */
36 #include <sys/stdint.h>
37 #include <sys/stddef.h>
38 #include <sys/param.h>
39 #include <sys/queue.h>
40 #include <sys/types.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
44 #include <sys/module.h>
46 #include <sys/mutex.h>
47 #include <sys/condvar.h>
48 #include <sys/sysctl.h>
50 #include <sys/unistd.h>
51 #include <sys/callout.h>
52 #include <sys/malloc.h>
55 #include <dev/usb/usb.h>
56 #include <dev/usb/usbdi.h>
58 #define USB_DEBUG_VAR octusbdebug
60 #include <dev/usb/usb_core.h>
61 #include <dev/usb/usb_debug.h>
62 #include <dev/usb/usb_busdma.h>
63 #include <dev/usb/usb_process.h>
64 #include <dev/usb/usb_transfer.h>
65 #include <dev/usb/usb_device.h>
66 #include <dev/usb/usb_hub.h>
67 #include <dev/usb/usb_util.h>
69 #include <dev/usb/usb_controller.h>
70 #include <dev/usb/usb_bus.h>
72 #include <contrib/octeon-sdk/cvmx.h>
73 #include <contrib/octeon-sdk/cvmx-usb.h>
75 #include <mips/cavium/usb/octusb.h>
77 #define OCTUSB_BUS2SC(bus) \
78 ((struct octusb_softc *)(((uint8_t *)(bus)) - \
79 ((uint8_t *)&(((struct octusb_softc *)0)->sc_bus))))
82 static int octusbdebug = 0;
84 static SYSCTL_NODE(_hw_usb, OID_AUTO, octusb, CTLFLAG_RW, 0, "OCTUSB");
85 SYSCTL_INT(_hw_usb_octusb, OID_AUTO, debug, CTLFLAG_RW,
86 &octusbdebug, 0, "OCTUSB debug level");
88 TUNABLE_INT("hw.usb.octusb.debug", &octusbdebug);
92 struct octusb_std_temp {
95 struct octusb_td *td_next;
96 struct usb_page_cache *pc;
100 uint8_t setup_alt_next;
103 extern struct usb_bus_methods octusb_bus_methods;
104 extern struct usb_pipe_methods octusb_device_bulk_methods;
105 extern struct usb_pipe_methods octusb_device_ctrl_methods;
106 extern struct usb_pipe_methods octusb_device_intr_methods;
107 extern struct usb_pipe_methods octusb_device_isoc_methods;
109 static void octusb_standard_done(struct usb_xfer *);
110 static void octusb_device_done(struct usb_xfer *, usb_error_t);
111 static void octusb_timeout(void *);
112 static void octusb_do_poll(struct usb_bus *);
114 static cvmx_usb_speed_t
115 octusb_convert_speed(enum usb_dev_speed speed)
120 return (CVMX_USB_SPEED_HIGH);
122 return (CVMX_USB_SPEED_FULL);
124 return (CVMX_USB_SPEED_LOW);
128 static cvmx_usb_transfer_t
129 octusb_convert_ep_type(uint8_t ep_type)
132 switch (ep_type & UE_XFERTYPE) {
134 return (CVMX_USB_TRANSFER_CONTROL);
136 return (CVMX_USB_TRANSFER_INTERRUPT);
138 return (CVMX_USB_TRANSFER_ISOCHRONOUS);
140 return (CVMX_USB_TRANSFER_BULK);
142 return (0); /* should not happen */
147 octusb_host_alloc_endpoint(struct octusb_td *td)
149 struct octusb_softc *sc;
152 if (td->qh->fixup_pending)
153 return (1); /* busy */
155 if (td->qh->ep_allocated)
156 return (0); /* success */
161 ep_handle = cvmx_usb_open_pipe(
162 &sc->sc_port[td->qh->port_index].state,
166 octusb_convert_speed(td->qh->dev_speed),
167 td->qh->max_packet_size,
168 octusb_convert_ep_type(td->qh->ep_type),
169 (td->qh->ep_num & UE_DIR_IN) ? CVMX_USB_DIRECTION_IN :
170 CVMX_USB_DIRECTION_OUT,
174 td->qh->hs_hub_port);
177 return (1); /* busy */
180 &sc->sc_port[td->qh->port_index].state,
181 ep_handle, td->qh->ep_toggle_next);
183 td->qh->fixup_handle = -1;
184 td->qh->fixup_complete = 0;
185 td->qh->fixup_len = 0;
186 td->qh->fixup_off = 0;
187 td->qh->fixup_pending = 0;
188 td->qh->fixup_actlen = 0;
190 td->qh->ep_handle = ep_handle;
191 td->qh->ep_allocated = 1;
193 return (0); /* success */
197 octusb_host_free_endpoint(struct octusb_td *td)
199 struct octusb_softc *sc;
201 if (td->qh->ep_allocated == 0)
207 if (td->qh->fixup_handle >= 0) {
209 cvmx_usb_cancel(&sc->sc_port[td->qh->port_index].state,
210 td->qh->ep_handle, td->qh->fixup_handle);
212 cvmx_usb_close_pipe(&sc->sc_port[td->qh->port_index].state, td->qh->ep_handle);
214 td->qh->ep_allocated = 0;
218 octusb_complete_cb(cvmx_usb_state_t *state,
219 cvmx_usb_callback_t reason,
220 cvmx_usb_complete_t status,
221 int pipe_handle, int submit_handle,
222 int bytes_transferred, void *user_data)
224 struct octusb_td *td;
226 if (reason != CVMX_USB_CALLBACK_TRANSFER_COMPLETE)
231 td->qh->fixup_complete = 1;
232 td->qh->fixup_pending = 0;
233 td->qh->fixup_actlen = bytes_transferred;
234 td->qh->fixup_handle = -1;
237 case CVMX_USB_COMPLETE_SUCCESS:
238 case CVMX_USB_COMPLETE_SHORT:
242 case CVMX_USB_COMPLETE_STALL:
253 octusb_host_control_header_tx(struct octusb_td *td)
257 /* allocate endpoint and check pending */
258 if (octusb_host_alloc_endpoint(td))
259 return (1); /* busy */
263 return (0); /* done */
265 if (td->qh->fixup_complete != 0) {
266 /* clear complete flag */
267 td->qh->fixup_complete = 0;
270 usb_pc_cpu_invalidate(td->qh->fixup_pc);
271 return (0); /* done */
274 if (td->remainder != 8) {
276 return (0); /* done */
278 usbd_copy_out(td->pc, td->offset, td->qh->fixup_buf, 8);
280 /* update offset and remainder */
284 /* setup data length and offset */
285 td->qh->fixup_len = UGETW(td->qh->fixup_buf + 6);
286 td->qh->fixup_off = 0;
288 if (td->qh->fixup_len > (OCTUSB_MAX_FIXUP - 8)) {
290 return (0); /* done */
292 /* do control IN request */
293 if (td->qh->fixup_buf[0] & UE_DIR_IN) {
295 struct octusb_softc *sc;
301 usb_pc_cpu_flush(td->qh->fixup_pc);
303 status = cvmx_usb_submit_control(
304 &sc->sc_port[td->qh->port_index].state,
305 td->qh->ep_handle, td->qh->fixup_phys,
306 td->qh->fixup_phys + 8, td->qh->fixup_len,
307 &octusb_complete_cb, td);
311 return (0); /* done */
313 td->qh->fixup_handle = status;
314 td->qh->fixup_pending = 1;
315 td->qh->fixup_complete = 0;
317 return (1); /* busy */
319 return (0); /* done */
323 octusb_host_control_data_tx(struct octusb_td *td)
327 /* allocate endpoint and check pending */
328 if (octusb_host_alloc_endpoint(td))
329 return (1); /* busy */
333 return (0); /* done */
335 rem = td->qh->fixup_len - td->qh->fixup_off;
337 if (td->remainder > rem) {
339 DPRINTFN(1, "Excess setup transmit data\n");
340 return (0); /* done */
342 usbd_copy_out(td->pc, td->offset, td->qh->fixup_buf +
343 td->qh->fixup_off + 8, td->remainder);
345 td->offset += td->remainder;
346 td->qh->fixup_off += td->remainder;
349 return (0); /* done */
353 octusb_host_control_data_rx(struct octusb_td *td)
357 /* allocate endpoint and check pending */
358 if (octusb_host_alloc_endpoint(td))
359 return (1); /* busy */
363 return (0); /* done */
365 /* copy data from buffer */
366 rem = td->qh->fixup_actlen - td->qh->fixup_off;
368 if (rem > td->remainder)
371 usbd_copy_in(td->pc, td->offset, td->qh->fixup_buf +
372 td->qh->fixup_off + 8, rem);
375 td->remainder -= rem;
376 td->qh->fixup_off += rem;
378 return (0); /* done */
382 octusb_host_control_status_tx(struct octusb_td *td)
386 /* allocate endpoint and check pending */
387 if (octusb_host_alloc_endpoint(td))
388 return (1); /* busy */
392 return (0); /* done */
394 if (td->qh->fixup_complete != 0) {
395 /* clear complete flag */
396 td->qh->fixup_complete = 0;
400 /* do control IN request */
401 if (!(td->qh->fixup_buf[0] & UE_DIR_IN)) {
403 struct octusb_softc *sc;
409 usb_pc_cpu_flush(td->qh->fixup_pc);
411 /* start USB transfer */
412 status = cvmx_usb_submit_control(
413 &sc->sc_port[td->qh->port_index].state,
414 td->qh->ep_handle, td->qh->fixup_phys,
415 td->qh->fixup_phys + 8, td->qh->fixup_len,
416 &octusb_complete_cb, td);
421 return (0); /* done */
423 td->qh->fixup_handle = status;
424 td->qh->fixup_pending = 1;
425 td->qh->fixup_complete = 0;
427 return (1); /* busy */
429 return (0); /* done */
433 octusb_non_control_data_tx(struct octusb_td *td)
435 struct octusb_softc *sc;
439 /* allocate endpoint and check pending */
440 if (octusb_host_alloc_endpoint(td))
441 return (1); /* busy */
445 return (0); /* done */
447 if ((td->qh->fixup_complete != 0) &&
448 ((td->qh->ep_type & UE_XFERTYPE) == UE_ISOCHRONOUS)) {
449 td->qh->fixup_complete = 0;
450 return (0); /* done */
453 if (td->remainder == 0) {
455 return (0); /* complete */
456 /* else need to send a zero length packet */
460 /* get maximum length */
461 rem = OCTUSB_MAX_FIXUP % td->qh->max_frame_size;
462 rem = OCTUSB_MAX_FIXUP - rem;
465 /* should not happen */
466 DPRINTFN(1, "Fixup buffer is too small\n");
468 return (0); /* done */
470 /* get minimum length */
471 if (rem > td->remainder) {
473 if ((rem == 0) || (rem % td->qh->max_frame_size))
476 /* copy data into fixup buffer */
477 usbd_copy_out(td->pc, td->offset, td->qh->fixup_buf, rem);
480 usb_pc_cpu_flush(td->qh->fixup_pc);
482 /* pre-increment TX buffer offset */
484 td->remainder -= rem;
490 switch (td->qh->ep_type & UE_XFERTYPE) {
492 td->qh->iso_pkt.offset = 0;
493 td->qh->iso_pkt.length = rem;
494 td->qh->iso_pkt.status = 0;
495 /* start USB transfer */
496 status = cvmx_usb_submit_isochronous(&sc->sc_port[td->qh->port_index].state,
497 td->qh->ep_handle, 1, CVMX_USB_ISOCHRONOUS_FLAGS_ALLOW_SHORT |
498 CVMX_USB_ISOCHRONOUS_FLAGS_ASAP, 1, &td->qh->iso_pkt,
499 td->qh->fixup_phys, rem, &octusb_complete_cb, td);
502 /* start USB transfer */
503 status = cvmx_usb_submit_bulk(&sc->sc_port[td->qh->port_index].state,
504 td->qh->ep_handle, td->qh->fixup_phys, rem, &octusb_complete_cb, td);
507 /* start USB transfer (interrupt or interrupt) */
508 status = cvmx_usb_submit_interrupt(&sc->sc_port[td->qh->port_index].state,
509 td->qh->ep_handle, td->qh->fixup_phys, rem, &octusb_complete_cb, td);
519 return (0); /* done */
521 td->qh->fixup_handle = status;
522 td->qh->fixup_len = rem;
523 td->qh->fixup_pending = 1;
524 td->qh->fixup_complete = 0;
526 return (1); /* busy */
530 octusb_non_control_data_rx(struct octusb_td *td)
532 struct octusb_softc *sc;
537 /* allocate endpoint and check pending */
538 if (octusb_host_alloc_endpoint(td))
539 return (1); /* busy */
543 return (0); /* done */
547 if (td->qh->fixup_complete != 0) {
549 /* invalidate data */
550 usb_pc_cpu_invalidate(td->qh->fixup_pc);
552 rem = td->qh->fixup_actlen;
554 /* verify transfer length */
555 if (rem != td->qh->fixup_len) {
556 if (rem < td->qh->fixup_len) {
557 /* we have a short packet */
561 /* invalid USB packet */
563 return (0); /* we are complete */
566 /* copy data into fixup buffer */
567 usbd_copy_in(td->pc, td->offset, td->qh->fixup_buf, rem);
569 /* post-increment RX buffer offset */
571 td->remainder -= rem;
573 td->qh->fixup_complete = 0;
575 if ((td->qh->ep_type & UE_XFERTYPE) == UE_ISOCHRONOUS)
576 return (0); /* done */
578 /* check if we are complete */
579 if ((td->remainder == 0) || got_short) {
581 /* we are complete */
584 /* else need to receive a zero length packet */
588 /* get maximum length */
589 rem = OCTUSB_MAX_FIXUP % td->qh->max_frame_size;
590 rem = OCTUSB_MAX_FIXUP - rem;
593 /* should not happen */
594 DPRINTFN(1, "Fixup buffer is too small\n");
596 return (0); /* done */
598 /* get minimum length */
599 if (rem > td->remainder)
603 /* invalidate data */
604 usb_pc_cpu_invalidate(td->qh->fixup_pc);
609 switch (td->qh->ep_type & UE_XFERTYPE) {
611 td->qh->iso_pkt.offset = 0;
612 td->qh->iso_pkt.length = rem;
613 td->qh->iso_pkt.status = 0;
614 /* start USB transfer */
615 status = cvmx_usb_submit_isochronous(&sc->sc_port[td->qh->port_index].state,
616 td->qh->ep_handle, 1, CVMX_USB_ISOCHRONOUS_FLAGS_ALLOW_SHORT |
617 CVMX_USB_ISOCHRONOUS_FLAGS_ASAP, 1, &td->qh->iso_pkt,
618 td->qh->fixup_phys, rem, &octusb_complete_cb, td);
621 /* start USB transfer */
622 status = cvmx_usb_submit_bulk(&sc->sc_port[td->qh->port_index].state,
623 td->qh->ep_handle, td->qh->fixup_phys, rem, &octusb_complete_cb, td);
626 /* start USB transfer */
627 status = cvmx_usb_submit_interrupt(&sc->sc_port[td->qh->port_index].state,
628 td->qh->ep_handle, td->qh->fixup_phys, rem, &octusb_complete_cb, td);
638 return (0); /* done */
640 td->qh->fixup_handle = status;
641 td->qh->fixup_len = rem;
642 td->qh->fixup_pending = 1;
643 td->qh->fixup_complete = 0;
645 return (1); /* busy */
649 octusb_xfer_do_fifo(struct usb_xfer *xfer)
651 struct octusb_td *td;
655 td = xfer->td_transfer_cache;
658 if ((td->func) (td)) {
659 /* operation in progress */
662 if (((void *)td) == xfer->td_transfer_last) {
667 } else if (td->remainder > 0) {
669 * We had a short transfer. If there is no
670 * alternate next, stop processing !
672 if (td->alt_next == 0)
676 * Fetch the next transfer descriptor and transfer
677 * some flags to the next transfer descriptor
680 xfer->td_transfer_cache = td;
682 return (1); /* not complete */
685 /* compute all actual lengths */
687 octusb_standard_done(xfer);
689 return (0); /* complete */
693 octusb_standard_done_sub(struct usb_xfer *xfer)
695 struct octusb_td *td;
701 td = xfer->td_transfer_cache;
706 if (xfer->aframes != xfer->nframes) {
708 * Verify the length and subtract
709 * the remainder from "frlengths[]":
711 if (len > xfer->frlengths[xfer->aframes]) {
714 xfer->frlengths[xfer->aframes] -= len;
717 /* Check for transfer error */
719 /* the transfer is finished */
720 error = td->error_stall ? USB_ERR_STALLED : USB_ERR_IOERROR;
724 /* Check for short transfer */
726 if (xfer->flags_int.short_frames_ok) {
727 /* follow alt next */
734 /* the transfer is finished */
742 /* this USB frame is complete */
748 /* update transfer cache */
750 xfer->td_transfer_cache = td;
756 octusb_standard_done(struct usb_xfer *xfer)
758 struct octusb_softc *sc;
759 struct octusb_qh *qh;
760 usb_error_t error = 0;
762 DPRINTFN(12, "xfer=%p endpoint=%p transfer done\n",
763 xfer, xfer->endpoint);
767 xfer->td_transfer_cache = xfer->td_transfer_first;
769 if (xfer->flags_int.control_xfr) {
771 if (xfer->flags_int.control_hdr)
772 error = octusb_standard_done_sub(xfer);
776 if (xfer->td_transfer_cache == NULL)
779 while (xfer->aframes != xfer->nframes) {
781 error = octusb_standard_done_sub(xfer);
785 if (xfer->td_transfer_cache == NULL)
789 if (xfer->flags_int.control_xfr &&
790 !xfer->flags_int.control_act)
791 error = octusb_standard_done_sub(xfer);
794 /* update data toggle */
796 qh = xfer->qh_start[0];
799 xfer->endpoint->toggle_next =
801 &sc->sc_port[qh->port_index].state,
802 qh->ep_handle) ? 1 : 0;
804 octusb_device_done(xfer, error);
808 octusb_interrupt_poll(struct octusb_softc *sc)
810 struct usb_xfer *xfer;
814 for (x = 0; x != sc->sc_noport; x++)
815 cvmx_usb_poll(&sc->sc_port[x].state);
818 TAILQ_FOREACH(xfer, &sc->sc_bus.intr_q.head, wait_entry) {
819 if (!octusb_xfer_do_fifo(xfer)) {
820 /* queue has been modified */
827 octusb_start_standard_chain(struct usb_xfer *xfer)
832 if (octusb_xfer_do_fifo(xfer)) {
834 /* put transfer on interrupt queue */
835 usbd_transfer_enqueue(&xfer->xroot->bus->intr_q, xfer);
837 /* start timeout, if any */
838 if (xfer->timeout != 0) {
839 usbd_transfer_timeout_ms(xfer,
840 &octusb_timeout, xfer->timeout);
846 octusb_iterate_hw_softc(struct usb_bus *bus, usb_bus_mem_sub_cb_t *cb)
852 octusb_init(struct octusb_softc *sc)
854 cvmx_usb_initialize_flags_t flags;
858 /* flush all cache into memory */
860 usb_bus_mem_flush_all(&sc->sc_bus, &octusb_iterate_hw_softc);
862 /* set up the bus struct */
863 sc->sc_bus.methods = &octusb_bus_methods;
865 /* get number of ports */
866 sc->sc_noport = cvmx_usb_get_num_ports();
868 /* check number of ports */
869 if (sc->sc_noport > OCTUSB_MAX_PORTS)
870 sc->sc_noport = OCTUSB_MAX_PORTS;
872 /* set USB revision */
873 sc->sc_bus.usbrev = USB_REV_2_0;
875 /* flags for port initialization */
876 flags = CVMX_USB_INITIALIZE_FLAGS_CLOCK_AUTO;
878 if (octusbdebug > 100)
879 flags |= CVMX_USB_INITIALIZE_FLAGS_DEBUG_ALL;
882 USB_BUS_LOCK(&sc->sc_bus);
884 /* setup all ports */
885 for (x = 0; x != sc->sc_noport; x++) {
886 status = cvmx_usb_initialize(&sc->sc_port[x].state, x, flags);
888 sc->sc_port[x].disabled = 1;
891 USB_BUS_UNLOCK(&sc->sc_bus);
893 /* catch lost interrupts */
894 octusb_do_poll(&sc->sc_bus);
900 octusb_uninit(struct octusb_softc *sc)
904 USB_BUS_LOCK(&sc->sc_bus);
906 for (x = 0; x != sc->sc_noport; x++) {
907 if (sc->sc_port[x].disabled == 0)
908 cvmx_usb_shutdown(&sc->sc_port[x].state);
910 USB_BUS_UNLOCK(&sc->sc_bus);
917 octusb_suspend(struct octusb_softc *sc)
923 octusb_resume(struct octusb_softc *sc)
928 /*------------------------------------------------------------------------*
929 * octusb_interrupt - OCTUSB interrupt handler
930 *------------------------------------------------------------------------*/
932 octusb_interrupt(struct octusb_softc *sc)
934 USB_BUS_LOCK(&sc->sc_bus);
936 DPRINTFN(16, "real interrupt\n");
938 /* poll all the USB transfers */
939 octusb_interrupt_poll(sc);
941 USB_BUS_UNLOCK(&sc->sc_bus);
944 /*------------------------------------------------------------------------*
945 * octusb_timeout - OCTUSB transfer timeout handler
946 *------------------------------------------------------------------------*/
948 octusb_timeout(void *arg)
950 struct usb_xfer *xfer = arg;
952 DPRINTF("xfer=%p\n", xfer);
954 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
956 /* transfer is transferred */
957 octusb_device_done(xfer, USB_ERR_TIMEOUT);
960 /*------------------------------------------------------------------------*
961 * octusb_do_poll - OCTUSB poll transfers
962 *------------------------------------------------------------------------*/
964 octusb_do_poll(struct usb_bus *bus)
966 struct octusb_softc *sc = OCTUSB_BUS2SC(bus);
968 USB_BUS_LOCK(&sc->sc_bus);
969 octusb_interrupt_poll(sc);
970 USB_BUS_UNLOCK(&sc->sc_bus);
974 octusb_setup_standard_chain_sub(struct octusb_std_temp *temp)
976 struct octusb_td *td;
978 /* get current Transfer Descriptor */
982 /* prepare for next TD */
983 temp->td_next = td->obj_next;
985 /* fill out the Transfer Descriptor */
986 td->func = temp->func;
988 td->offset = temp->offset;
989 td->remainder = temp->len;
992 td->short_pkt = temp->short_pkt;
993 td->alt_next = temp->setup_alt_next;
997 octusb_setup_standard_chain(struct usb_xfer *xfer)
999 struct octusb_std_temp temp;
1000 struct octusb_td *td;
1003 DPRINTFN(9, "addr=%d endpt=%d sumlen=%d speed=%d\n",
1004 xfer->address, UE_GET_ADDR(xfer->endpointno),
1005 xfer->sumlen, usbd_get_speed(xfer->xroot->udev));
1007 /* setup starting point */
1008 td = xfer->td_start[0];
1009 xfer->td_transfer_first = td;
1010 xfer->td_transfer_cache = td;
1014 temp.setup_alt_next = xfer->flags_int.short_frames_ok;
1017 /* check if we should prepend a setup message */
1019 if (xfer->flags_int.control_xfr) {
1021 if (xfer->flags_int.control_hdr) {
1023 temp.func = &octusb_host_control_header_tx;
1024 temp.len = xfer->frlengths[0];
1025 temp.pc = xfer->frbuffers + 0;
1026 temp.short_pkt = temp.len ? 1 : 0;
1028 /* check for last frame */
1029 if (xfer->nframes == 1) {
1031 * no STATUS stage yet, SETUP is
1034 if (xfer->flags_int.control_act)
1035 temp.setup_alt_next = 0;
1037 octusb_setup_standard_chain_sub(&temp);
1044 if (x != xfer->nframes) {
1045 if (xfer->endpointno & UE_DIR_IN) {
1046 if (xfer->flags_int.control_xfr)
1047 temp.func = &octusb_host_control_data_rx;
1049 temp.func = &octusb_non_control_data_rx;
1051 if (xfer->flags_int.control_xfr)
1052 temp.func = &octusb_host_control_data_tx;
1054 temp.func = &octusb_non_control_data_tx;
1057 /* setup "pc" pointer */
1058 temp.pc = xfer->frbuffers + x;
1060 while (x != xfer->nframes) {
1062 /* DATA0 or DATA1 message */
1064 temp.len = xfer->frlengths[x];
1068 if (x == xfer->nframes) {
1069 if (xfer->flags_int.control_xfr) {
1070 /* no STATUS stage yet, DATA is last */
1071 if (xfer->flags_int.control_act)
1072 temp.setup_alt_next = 0;
1074 temp.setup_alt_next = 0;
1077 if (temp.len == 0) {
1079 /* make sure that we send an USB packet */
1085 /* regular data transfer */
1087 temp.short_pkt = (xfer->flags.force_short_xfer) ? 0 : 1;
1090 octusb_setup_standard_chain_sub(&temp);
1092 if (xfer->flags_int.isochronous_xfr) {
1093 /* get next data offset */
1094 temp.offset += temp.len;
1096 /* get next Page Cache pointer */
1097 temp.pc = xfer->frbuffers + x;
1101 /* check if we should append a status stage */
1103 if (xfer->flags_int.control_xfr &&
1104 !xfer->flags_int.control_act) {
1106 temp.func = &octusb_host_control_status_tx;
1110 temp.setup_alt_next = 0;
1112 octusb_setup_standard_chain_sub(&temp);
1114 /* must have at least one frame! */
1116 xfer->td_transfer_last = td;
1118 /* properly setup QH */
1120 td->qh->ep_allocated = 0;
1121 td->qh->ep_toggle_next = xfer->endpoint->toggle_next ? 1 : 0;
1124 /*------------------------------------------------------------------------*
1125 * octusb_device_done - OCTUSB transfers done code
1127 * NOTE: This function can be called more than one time in a row.
1128 *------------------------------------------------------------------------*/
1130 octusb_device_done(struct usb_xfer *xfer, usb_error_t error)
1132 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
1134 DPRINTFN(2, "xfer=%p, endpoint=%p, error=%d\n",
1135 xfer, xfer->endpoint, error);
1138 * 1) Free any endpoints.
1139 * 2) Control transfers can be split and we should not re-open
1140 * the data pipe between transactions unless there is an error.
1142 if ((xfer->flags_int.control_act == 0) || (error != 0)) {
1143 struct octusb_td *td;
1145 td = xfer->td_start[0];
1147 octusb_host_free_endpoint(td);
1149 /* dequeue transfer and start next transfer */
1150 usbd_transfer_done(xfer, error);
1153 /*------------------------------------------------------------------------*
1154 * octusb bulk support
1155 *------------------------------------------------------------------------*/
1157 octusb_device_bulk_open(struct usb_xfer *xfer)
1163 octusb_device_bulk_close(struct usb_xfer *xfer)
1165 octusb_device_done(xfer, USB_ERR_CANCELLED);
1169 octusb_device_bulk_enter(struct usb_xfer *xfer)
1175 octusb_device_bulk_start(struct usb_xfer *xfer)
1178 octusb_setup_standard_chain(xfer);
1179 octusb_start_standard_chain(xfer);
1182 struct usb_pipe_methods octusb_device_bulk_methods =
1184 .open = octusb_device_bulk_open,
1185 .close = octusb_device_bulk_close,
1186 .enter = octusb_device_bulk_enter,
1187 .start = octusb_device_bulk_start,
1190 /*------------------------------------------------------------------------*
1191 * octusb control support
1192 *------------------------------------------------------------------------*/
1194 octusb_device_ctrl_open(struct usb_xfer *xfer)
1200 octusb_device_ctrl_close(struct usb_xfer *xfer)
1202 octusb_device_done(xfer, USB_ERR_CANCELLED);
1206 octusb_device_ctrl_enter(struct usb_xfer *xfer)
1212 octusb_device_ctrl_start(struct usb_xfer *xfer)
1215 octusb_setup_standard_chain(xfer);
1216 octusb_start_standard_chain(xfer);
1219 struct usb_pipe_methods octusb_device_ctrl_methods =
1221 .open = octusb_device_ctrl_open,
1222 .close = octusb_device_ctrl_close,
1223 .enter = octusb_device_ctrl_enter,
1224 .start = octusb_device_ctrl_start,
1227 /*------------------------------------------------------------------------*
1228 * octusb interrupt support
1229 *------------------------------------------------------------------------*/
1231 octusb_device_intr_open(struct usb_xfer *xfer)
1237 octusb_device_intr_close(struct usb_xfer *xfer)
1239 octusb_device_done(xfer, USB_ERR_CANCELLED);
1243 octusb_device_intr_enter(struct usb_xfer *xfer)
1249 octusb_device_intr_start(struct usb_xfer *xfer)
1252 octusb_setup_standard_chain(xfer);
1253 octusb_start_standard_chain(xfer);
1256 struct usb_pipe_methods octusb_device_intr_methods =
1258 .open = octusb_device_intr_open,
1259 .close = octusb_device_intr_close,
1260 .enter = octusb_device_intr_enter,
1261 .start = octusb_device_intr_start,
1264 /*------------------------------------------------------------------------*
1265 * octusb isochronous support
1266 *------------------------------------------------------------------------*/
1268 octusb_device_isoc_open(struct usb_xfer *xfer)
1274 octusb_device_isoc_close(struct usb_xfer *xfer)
1276 octusb_device_done(xfer, USB_ERR_CANCELLED);
1280 octusb_device_isoc_enter(struct usb_xfer *xfer)
1282 struct octusb_softc *sc = OCTUSB_BUS2SC(xfer->xroot->bus);
1284 uint32_t frame_count;
1287 DPRINTFN(5, "xfer=%p next=%d nframes=%d\n",
1288 xfer, xfer->endpoint->isoc_next, xfer->nframes);
1290 /* get the current frame index */
1292 frame_count = cvmx_usb_get_frame_number(
1293 &sc->sc_port[xfer->xroot->udev->port_index].state);
1296 * check if the frame index is within the window where the frames
1299 temp = (frame_count - xfer->endpoint->isoc_next) & 0x7FF;
1301 if (usbd_get_speed(xfer->xroot->udev) == USB_SPEED_HIGH) {
1302 fs_frames = (xfer->nframes + 7) / 8;
1304 fs_frames = xfer->nframes;
1307 if ((xfer->endpoint->is_synced == 0) || (temp < fs_frames)) {
1309 * If there is data underflow or the pipe queue is
1310 * empty we schedule the transfer a few frames ahead
1311 * of the current frame position. Else two isochronous
1312 * transfers might overlap.
1314 xfer->endpoint->isoc_next = (frame_count + 3) & 0x7FF;
1315 xfer->endpoint->is_synced = 1;
1316 DPRINTFN(2, "start next=%d\n", xfer->endpoint->isoc_next);
1319 * compute how many milliseconds the insertion is ahead of the
1320 * current frame position:
1322 temp = (xfer->endpoint->isoc_next - frame_count) & 0x7FF;
1325 * pre-compute when the isochronous transfer will be finished:
1327 xfer->isoc_time_complete =
1328 usb_isoc_time_expand(&sc->sc_bus, frame_count) + temp +
1331 /* compute frame number for next insertion */
1332 xfer->endpoint->isoc_next += fs_frames;
1336 octusb_device_isoc_start(struct usb_xfer *xfer)
1339 octusb_setup_standard_chain(xfer);
1340 octusb_start_standard_chain(xfer);
1343 struct usb_pipe_methods octusb_device_isoc_methods =
1345 .open = octusb_device_isoc_open,
1346 .close = octusb_device_isoc_close,
1347 .enter = octusb_device_isoc_enter,
1348 .start = octusb_device_isoc_start,
1351 /*------------------------------------------------------------------------*
1352 * OCTUSB root HUB support
1353 *------------------------------------------------------------------------*
1354 * Simulate a hardware HUB by handling all the necessary requests.
1355 *------------------------------------------------------------------------*/
1357 struct usb_device_descriptor octusb_devd = {
1358 .bLength = sizeof(octusb_devd),
1359 .bDescriptorType = UDESC_DEVICE,
1360 .bcdUSB = {0x00, 0x02},
1361 .bDeviceClass = UDCLASS_HUB,
1362 .bDeviceSubClass = UDSUBCLASS_HUB,
1363 .bDeviceProtocol = UDPROTO_FSHUB,
1364 .bMaxPacketSize = 64,
1367 .bcdDevice = {0x00, 0x01},
1371 .bNumConfigurations = 1,
1375 struct usb_device_qualifier octusb_odevd = {
1376 .bLength = sizeof(octusb_odevd),
1377 .bDescriptorType = UDESC_DEVICE_QUALIFIER,
1378 .bcdUSB = {0x00, 0x02},
1379 .bDeviceClass = UDCLASS_HUB,
1380 .bDeviceSubClass = UDSUBCLASS_HUB,
1381 .bDeviceProtocol = UDPROTO_FSHUB,
1382 .bMaxPacketSize0 = 0,
1383 .bNumConfigurations = 0,
1388 struct octusb_config_desc octusb_confd = {
1390 .bLength = sizeof(struct usb_config_descriptor),
1391 .bDescriptorType = UDESC_CONFIG,
1392 .wTotalLength[0] = sizeof(octusb_confd),
1394 .bConfigurationValue = 1,
1395 .iConfiguration = 0,
1396 .bmAttributes = UC_SELF_POWERED,
1397 .bMaxPower = 0 /* max power */
1400 .bLength = sizeof(struct usb_interface_descriptor),
1401 .bDescriptorType = UDESC_INTERFACE,
1403 .bInterfaceClass = UICLASS_HUB,
1404 .bInterfaceSubClass = UISUBCLASS_HUB,
1405 .bInterfaceProtocol = UIPROTO_FSHUB,
1408 .bLength = sizeof(struct usb_endpoint_descriptor),
1409 .bDescriptorType = UDESC_ENDPOINT,
1410 .bEndpointAddress = UE_DIR_IN | OCTUSB_INTR_ENDPT,
1411 .bmAttributes = UE_INTERRUPT,
1412 .wMaxPacketSize[0] = 8, /* max packet (63 ports) */
1418 struct usb_hub_descriptor_min octusb_hubd =
1420 .bDescLength = sizeof(octusb_hubd),
1421 .bDescriptorType = UDESC_HUB,
1423 .wHubCharacteristics = {UHD_PWR_NO_SWITCH | UHD_OC_INDIVIDUAL, 0},
1424 .bPwrOn2PwrGood = 50,
1425 .bHubContrCurrent = 0,
1426 .DeviceRemovable = {0x00}, /* all ports are removable */
1430 octusb_roothub_exec(struct usb_device *udev,
1431 struct usb_device_request *req, const void **pptr, uint16_t *plength)
1433 struct octusb_softc *sc = OCTUSB_BUS2SC(udev->bus);
1435 const char *str_ptr;
1442 cvmx_usb_port_status_t usb_port_status;
1444 USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
1446 /* XXX disable power save mode, hence it is not supported */
1447 udev->power_mode = USB_POWER_MODE_ON;
1450 ptr = (const void *)&sc->sc_hub_desc.temp;
1454 value = UGETW(req->wValue);
1455 index = UGETW(req->wIndex);
1457 DPRINTFN(3, "type=0x%02x request=0x%02x wLen=0x%04x "
1458 "wValue=0x%04x wIndex=0x%04x\n",
1459 req->bmRequestType, req->bRequest,
1460 UGETW(req->wLength), value, index);
1462 #define C(x,y) ((x) | ((y) << 8))
1463 switch (C(req->bRequest, req->bmRequestType)) {
1464 case C(UR_CLEAR_FEATURE, UT_WRITE_DEVICE):
1465 case C(UR_CLEAR_FEATURE, UT_WRITE_INTERFACE):
1466 case C(UR_CLEAR_FEATURE, UT_WRITE_ENDPOINT):
1468 case C(UR_GET_CONFIG, UT_READ_DEVICE):
1470 sc->sc_hub_desc.temp[0] = sc->sc_conf;
1472 case C(UR_GET_DESCRIPTOR, UT_READ_DEVICE):
1473 switch (value >> 8) {
1475 if ((value & 0xff) != 0) {
1476 err = USB_ERR_IOERROR;
1479 len = sizeof(octusb_devd);
1481 ptr = (const void *)&octusb_devd;
1484 case UDESC_DEVICE_QUALIFIER:
1485 if ((value & 0xff) != 0) {
1486 err = USB_ERR_IOERROR;
1489 len = sizeof(octusb_odevd);
1490 ptr = (const void *)&octusb_odevd;
1494 if ((value & 0xff) != 0) {
1495 err = USB_ERR_IOERROR;
1498 len = sizeof(octusb_confd);
1499 ptr = (const void *)&octusb_confd;
1503 switch (value & 0xff) {
1504 case 0: /* Language table */
1508 case 1: /* Vendor */
1509 str_ptr = "Cavium Networks";
1512 case 2: /* Product */
1513 str_ptr = "OCTUSB Root HUB";
1521 len = usb_make_str_desc(sc->sc_hub_desc.temp,
1522 sizeof(sc->sc_hub_desc.temp), str_ptr);
1526 err = USB_ERR_IOERROR;
1530 case C(UR_GET_INTERFACE, UT_READ_INTERFACE):
1532 sc->sc_hub_desc.temp[0] = 0;
1534 case C(UR_GET_STATUS, UT_READ_DEVICE):
1536 USETW(sc->sc_hub_desc.stat.wStatus, UDS_SELF_POWERED);
1538 case C(UR_GET_STATUS, UT_READ_INTERFACE):
1539 case C(UR_GET_STATUS, UT_READ_ENDPOINT):
1541 USETW(sc->sc_hub_desc.stat.wStatus, 0);
1543 case C(UR_SET_ADDRESS, UT_WRITE_DEVICE):
1544 if (value >= OCTUSB_MAX_DEVICES) {
1545 err = USB_ERR_IOERROR;
1548 sc->sc_addr = value;
1550 case C(UR_SET_CONFIG, UT_WRITE_DEVICE):
1551 if ((value != 0) && (value != 1)) {
1552 err = USB_ERR_IOERROR;
1555 sc->sc_conf = value;
1557 case C(UR_SET_DESCRIPTOR, UT_WRITE_DEVICE):
1559 case C(UR_SET_FEATURE, UT_WRITE_DEVICE):
1560 case C(UR_SET_FEATURE, UT_WRITE_INTERFACE):
1561 case C(UR_SET_FEATURE, UT_WRITE_ENDPOINT):
1562 err = USB_ERR_IOERROR;
1564 case C(UR_SET_INTERFACE, UT_WRITE_INTERFACE):
1566 case C(UR_SYNCH_FRAME, UT_WRITE_ENDPOINT):
1569 case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_DEVICE):
1571 case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_OTHER):
1572 DPRINTFN(4, "UR_CLEAR_PORT_FEATURE "
1573 "port=%d feature=%d\n",
1576 (index > sc->sc_noport) ||
1577 sc->sc_port[index - 1].disabled) {
1578 err = USB_ERR_IOERROR;
1584 case UHF_PORT_ENABLE:
1585 cvmx_usb_disable(&sc->sc_port[index].state);
1587 case UHF_PORT_SUSPEND:
1588 case UHF_PORT_RESET:
1590 case UHF_C_PORT_CONNECTION:
1591 cvmx_usb_set_status(&sc->sc_port[index].state,
1592 cvmx_usb_get_status(&sc->sc_port[index].state));
1594 case UHF_C_PORT_ENABLE:
1595 cvmx_usb_set_status(&sc->sc_port[index].state,
1596 cvmx_usb_get_status(&sc->sc_port[index].state));
1598 case UHF_C_PORT_OVER_CURRENT:
1599 cvmx_usb_set_status(&sc->sc_port[index].state,
1600 cvmx_usb_get_status(&sc->sc_port[index].state));
1602 case UHF_C_PORT_RESET:
1605 case UHF_C_PORT_SUSPEND:
1607 case UHF_PORT_CONNECTION:
1608 case UHF_PORT_OVER_CURRENT:
1609 case UHF_PORT_POWER:
1610 case UHF_PORT_LOW_SPEED:
1612 err = USB_ERR_IOERROR;
1616 case C(UR_GET_DESCRIPTOR, UT_READ_CLASS_DEVICE):
1617 if ((value & 0xff) != 0) {
1618 err = USB_ERR_IOERROR;
1621 sc->sc_hubd = octusb_hubd;
1622 sc->sc_hubd.bNbrPorts = sc->sc_noport;
1623 len = sizeof(sc->sc_hubd);
1624 ptr = (const void *)&sc->sc_hubd;
1626 case C(UR_GET_STATUS, UT_READ_CLASS_DEVICE):
1628 memset(sc->sc_hub_desc.temp, 0, 16);
1630 case C(UR_GET_STATUS, UT_READ_CLASS_OTHER):
1632 (index > sc->sc_noport) ||
1633 sc->sc_port[index - 1].disabled) {
1634 err = USB_ERR_IOERROR;
1639 usb_port_status = cvmx_usb_get_status(&sc->sc_port[index].state);
1641 status = change = 0;
1642 if (usb_port_status.connected)
1643 status |= UPS_CURRENT_CONNECT_STATUS;
1644 if (usb_port_status.port_enabled)
1645 status |= UPS_PORT_ENABLED;
1646 if (usb_port_status.port_over_current)
1647 status |= UPS_OVERCURRENT_INDICATOR;
1648 if (usb_port_status.port_powered)
1649 status |= UPS_PORT_POWER;
1651 switch (usb_port_status.port_speed) {
1652 case CVMX_USB_SPEED_HIGH:
1653 status |= UPS_HIGH_SPEED;
1655 case CVMX_USB_SPEED_FULL:
1658 status |= UPS_LOW_SPEED;
1662 if (usb_port_status.connect_change)
1663 change |= UPS_C_CONNECT_STATUS;
1665 change |= UPS_C_PORT_RESET;
1667 USETW(sc->sc_hub_desc.ps.wPortStatus, status);
1668 USETW(sc->sc_hub_desc.ps.wPortChange, change);
1670 len = sizeof(sc->sc_hub_desc.ps);
1672 case C(UR_SET_DESCRIPTOR, UT_WRITE_CLASS_DEVICE):
1673 err = USB_ERR_IOERROR;
1675 case C(UR_SET_FEATURE, UT_WRITE_CLASS_DEVICE):
1677 case C(UR_SET_FEATURE, UT_WRITE_CLASS_OTHER):
1679 (index > sc->sc_noport) ||
1680 sc->sc_port[index - 1].disabled) {
1681 err = USB_ERR_IOERROR;
1687 case UHF_PORT_ENABLE:
1689 case UHF_PORT_RESET:
1690 cvmx_usb_disable(&sc->sc_port[index].state);
1691 if (cvmx_usb_enable(&sc->sc_port[index].state)) {
1692 err = USB_ERR_IOERROR;
1697 case UHF_PORT_POWER:
1698 /* pretend we turned on power */
1700 case UHF_PORT_SUSPEND:
1701 case UHF_C_PORT_CONNECTION:
1702 case UHF_C_PORT_ENABLE:
1703 case UHF_C_PORT_OVER_CURRENT:
1704 case UHF_PORT_CONNECTION:
1705 case UHF_PORT_OVER_CURRENT:
1706 case UHF_PORT_LOW_SPEED:
1707 case UHF_C_PORT_SUSPEND:
1708 case UHF_C_PORT_RESET:
1710 err = USB_ERR_IOERROR;
1715 err = USB_ERR_IOERROR;
1725 octusb_xfer_setup(struct usb_setup_params *parm)
1727 struct usb_page_search page_info;
1728 struct usb_page_cache *pc;
1729 struct octusb_softc *sc;
1730 struct octusb_qh *qh;
1731 struct usb_xfer *xfer;
1736 sc = OCTUSB_BUS2SC(parm->udev->bus);
1737 xfer = parm->curr_xfer;
1741 * NOTE: This driver does not use any of the parameters that
1742 * are computed from the following values. Just set some
1743 * reasonable dummies:
1746 parm->hc_max_packet_size = 0x400;
1747 parm->hc_max_packet_count = 3;
1748 parm->hc_max_frame_size = 0xC00;
1750 usbd_transfer_setup_sub(parm);
1755 /* Allocate a queue head */
1757 if (usbd_transfer_setup_sub_malloc(
1758 parm, &pc, sizeof(struct octusb_qh),
1759 USB_HOST_ALIGN, 1)) {
1760 parm->err = USB_ERR_NOMEM;
1764 usbd_get_page(pc, 0, &page_info);
1766 qh = page_info.buffer;
1770 qh->sc = OCTUSB_BUS2SC(xfer->xroot->bus);
1771 qh->max_frame_size = xfer->max_frame_size;
1772 qh->max_packet_size = xfer->max_packet_size;
1773 qh->ep_num = xfer->endpointno;
1774 qh->ep_type = xfer->endpoint->edesc->bmAttributes;
1775 qh->dev_addr = xfer->address;
1776 qh->dev_speed = usbd_get_speed(xfer->xroot->udev);
1777 qh->port_index = xfer->xroot->udev->port_index;
1779 switch (xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE) {
1781 if (usbd_get_speed(xfer->xroot->udev) == USB_SPEED_HIGH)
1782 qh->ep_interval = xfer->interval * 8;
1784 qh->ep_interval = xfer->interval * 1;
1786 case UE_ISOCHRONOUS:
1787 qh->ep_interval = 1 << xfer->fps_shift;
1790 qh->ep_interval = 0;
1794 qh->ep_mult = xfer->max_packet_count & 3;
1795 qh->hs_hub_addr = xfer->xroot->udev->hs_hub_addr;
1796 qh->hs_hub_port = xfer->xroot->udev->hs_port_no;
1798 xfer->qh_start[0] = qh;
1800 /* Allocate a fixup buffer */
1802 if (usbd_transfer_setup_sub_malloc(
1803 parm, &pc, OCTUSB_MAX_FIXUP,
1804 OCTUSB_MAX_FIXUP, 1)) {
1805 parm->err = USB_ERR_NOMEM;
1809 usbd_get_page(pc, 0, &page_info);
1811 qh->fixup_phys = page_info.physaddr;
1813 qh->fixup_buf = page_info.buffer;
1815 /* Allocate transfer descriptors */
1819 ntd = xfer->nframes + 1 /* STATUS */ + 1 /* SYNC */ ;
1821 if (usbd_transfer_setup_sub_malloc(
1822 parm, &pc, sizeof(struct octusb_td),
1823 USB_HOST_ALIGN, ntd)) {
1824 parm->err = USB_ERR_NOMEM;
1828 for (n = 0; n != ntd; n++) {
1829 struct octusb_td *td;
1831 usbd_get_page(pc + n, 0, &page_info);
1833 td = page_info.buffer;
1836 td->obj_next = last_obj;
1841 xfer->td_start[0] = last_obj;
1845 octusb_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor *edesc,
1846 struct usb_endpoint *ep)
1848 struct octusb_softc *sc = OCTUSB_BUS2SC(udev->bus);
1850 DPRINTFN(2, "endpoint=%p, addr=%d, endpt=%d, mode=%d (%d)\n",
1851 ep, udev->address, edesc->bEndpointAddress,
1852 udev->flags.usb_mode, sc->sc_addr);
1854 if (udev->flags.usb_mode != USB_MODE_HOST) {
1858 if (udev->device_index != sc->sc_addr) {
1859 switch (edesc->bmAttributes & UE_XFERTYPE) {
1861 ep->methods = &octusb_device_ctrl_methods;
1864 ep->methods = &octusb_device_intr_methods;
1866 case UE_ISOCHRONOUS:
1867 if (udev->speed != USB_SPEED_LOW)
1868 ep->methods = &octusb_device_isoc_methods;
1871 ep->methods = &octusb_device_bulk_methods;
1881 octusb_xfer_unsetup(struct usb_xfer *xfer)
1883 DPRINTF("Nothing to do.\n");
1887 octusb_get_dma_delay(struct usb_device *udev, uint32_t *pus)
1889 /* DMA delay - wait until any use of memory is finished */
1890 *pus = (2125); /* microseconds */
1894 octusb_device_resume(struct usb_device *udev)
1896 DPRINTF("Nothing to do.\n");
1900 octusb_device_suspend(struct usb_device *udev)
1902 DPRINTF("Nothing to do.\n");
1906 octusb_set_hw_power(struct usb_bus *bus)
1908 DPRINTF("Nothing to do.\n");
1912 octusb_set_hw_power_sleep(struct usb_bus *bus, uint32_t state)
1914 struct octusb_softc *sc = OCTUSB_BUS2SC(bus);
1917 case USB_HW_POWER_SUSPEND:
1920 case USB_HW_POWER_SHUTDOWN:
1923 case USB_HW_POWER_RESUME:
1931 struct usb_bus_methods octusb_bus_methods = {
1932 .endpoint_init = octusb_ep_init,
1933 .xfer_setup = octusb_xfer_setup,
1934 .xfer_unsetup = octusb_xfer_unsetup,
1935 .get_dma_delay = octusb_get_dma_delay,
1936 .device_resume = octusb_device_resume,
1937 .device_suspend = octusb_device_suspend,
1938 .set_hw_power = octusb_set_hw_power,
1939 .set_hw_power_sleep = octusb_set_hw_power_sleep,
1940 .roothub_exec = octusb_roothub_exec,
1941 .xfer_poll = octusb_do_poll,