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->root_port_index].state,
165 td->qh->ep_num & UE_ADDR,
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,
172 (td->qh->dev_speed == USB_SPEED_HIGH) ? td->qh->ep_mult : 0,
174 td->qh->hs_hub_port);
177 DPRINTFN(1, "cvmx_usb_open_pipe failed: %d\n", ep_handle);
178 return (1); /* busy */
182 &sc->sc_port[td->qh->root_port_index].state,
183 ep_handle, td->qh->ep_toggle_next);
185 td->qh->fixup_handle = -1;
186 td->qh->fixup_complete = 0;
187 td->qh->fixup_len = 0;
188 td->qh->fixup_off = 0;
189 td->qh->fixup_pending = 0;
190 td->qh->fixup_actlen = 0;
192 td->qh->ep_handle = ep_handle;
193 td->qh->ep_allocated = 1;
195 return (0); /* success */
199 octusb_host_free_endpoint(struct octusb_td *td)
201 struct octusb_softc *sc;
203 if (td->qh->ep_allocated == 0)
209 if (td->qh->fixup_handle >= 0) {
211 cvmx_usb_cancel(&sc->sc_port[td->qh->root_port_index].state,
212 td->qh->ep_handle, td->qh->fixup_handle);
214 cvmx_usb_close_pipe(&sc->sc_port[td->qh->root_port_index].state, td->qh->ep_handle);
216 td->qh->ep_allocated = 0;
220 octusb_complete_cb(cvmx_usb_state_t *state,
221 cvmx_usb_callback_t reason,
222 cvmx_usb_complete_t status,
223 int pipe_handle, int submit_handle,
224 int bytes_transferred, void *user_data)
226 struct octusb_td *td;
228 if (reason != CVMX_USB_CALLBACK_TRANSFER_COMPLETE)
233 td->qh->fixup_complete = 1;
234 td->qh->fixup_pending = 0;
235 td->qh->fixup_actlen = bytes_transferred;
236 td->qh->fixup_handle = -1;
239 case CVMX_USB_COMPLETE_SUCCESS:
240 case CVMX_USB_COMPLETE_SHORT:
244 case CVMX_USB_COMPLETE_STALL:
255 octusb_host_control_header_tx(struct octusb_td *td)
259 /* allocate endpoint and check pending */
260 if (octusb_host_alloc_endpoint(td))
261 return (1); /* busy */
265 return (0); /* done */
267 if (td->qh->fixup_complete != 0) {
268 /* clear complete flag */
269 td->qh->fixup_complete = 0;
272 usb_pc_cpu_invalidate(td->qh->fixup_pc);
273 return (0); /* done */
276 if (td->remainder != 8) {
278 return (0); /* done */
280 usbd_copy_out(td->pc, td->offset, td->qh->fixup_buf, 8);
282 /* update offset and remainder */
286 /* setup data length and offset */
287 td->qh->fixup_len = UGETW(td->qh->fixup_buf + 6);
288 td->qh->fixup_off = 0;
290 if (td->qh->fixup_len > (OCTUSB_MAX_FIXUP - 8)) {
292 return (0); /* done */
294 /* do control IN request */
295 if (td->qh->fixup_buf[0] & UE_DIR_IN) {
297 struct octusb_softc *sc;
303 usb_pc_cpu_flush(td->qh->fixup_pc);
305 status = cvmx_usb_submit_control(
306 &sc->sc_port[td->qh->root_port_index].state,
307 td->qh->ep_handle, td->qh->fixup_phys,
308 td->qh->fixup_phys + 8, td->qh->fixup_len,
309 &octusb_complete_cb, td);
313 return (0); /* done */
315 td->qh->fixup_handle = status;
316 td->qh->fixup_pending = 1;
317 td->qh->fixup_complete = 0;
319 return (1); /* busy */
321 return (0); /* done */
325 octusb_host_control_data_tx(struct octusb_td *td)
329 /* allocate endpoint and check pending */
330 if (octusb_host_alloc_endpoint(td))
331 return (1); /* busy */
335 return (0); /* done */
337 rem = td->qh->fixup_len - td->qh->fixup_off;
339 if (td->remainder > rem) {
341 DPRINTFN(1, "Excess setup transmit data\n");
342 return (0); /* done */
344 usbd_copy_out(td->pc, td->offset, td->qh->fixup_buf +
345 td->qh->fixup_off + 8, td->remainder);
347 td->offset += td->remainder;
348 td->qh->fixup_off += td->remainder;
351 return (0); /* done */
355 octusb_host_control_data_rx(struct octusb_td *td)
359 /* allocate endpoint and check pending */
360 if (octusb_host_alloc_endpoint(td))
361 return (1); /* busy */
365 return (0); /* done */
367 /* copy data from buffer */
368 rem = td->qh->fixup_actlen - td->qh->fixup_off;
370 if (rem > td->remainder)
373 usbd_copy_in(td->pc, td->offset, td->qh->fixup_buf +
374 td->qh->fixup_off + 8, rem);
377 td->remainder -= rem;
378 td->qh->fixup_off += rem;
380 return (0); /* done */
384 octusb_host_control_status_tx(struct octusb_td *td)
388 /* allocate endpoint and check pending */
389 if (octusb_host_alloc_endpoint(td))
390 return (1); /* busy */
394 return (0); /* done */
396 if (td->qh->fixup_complete != 0) {
397 /* clear complete flag */
398 td->qh->fixup_complete = 0;
402 /* do control IN request */
403 if (!(td->qh->fixup_buf[0] & UE_DIR_IN)) {
405 struct octusb_softc *sc;
411 usb_pc_cpu_flush(td->qh->fixup_pc);
413 /* start USB transfer */
414 status = cvmx_usb_submit_control(
415 &sc->sc_port[td->qh->root_port_index].state,
416 td->qh->ep_handle, td->qh->fixup_phys,
417 td->qh->fixup_phys + 8, td->qh->fixup_len,
418 &octusb_complete_cb, td);
423 return (0); /* done */
425 td->qh->fixup_handle = status;
426 td->qh->fixup_pending = 1;
427 td->qh->fixup_complete = 0;
429 return (1); /* busy */
431 return (0); /* done */
435 octusb_non_control_data_tx(struct octusb_td *td)
437 struct octusb_softc *sc;
441 /* allocate endpoint and check pending */
442 if (octusb_host_alloc_endpoint(td))
443 return (1); /* busy */
447 return (0); /* done */
449 if ((td->qh->fixup_complete != 0) &&
450 ((td->qh->ep_type & UE_XFERTYPE) == UE_ISOCHRONOUS)) {
451 td->qh->fixup_complete = 0;
452 return (0); /* done */
455 if (td->remainder == 0) {
457 return (0); /* complete */
458 /* else need to send a zero length packet */
462 /* get maximum length */
463 rem = OCTUSB_MAX_FIXUP % td->qh->max_frame_size;
464 rem = OCTUSB_MAX_FIXUP - rem;
467 /* should not happen */
468 DPRINTFN(1, "Fixup buffer is too small\n");
470 return (0); /* done */
472 /* get minimum length */
473 if (rem > td->remainder) {
475 if ((rem == 0) || (rem % td->qh->max_frame_size))
478 /* copy data into fixup buffer */
479 usbd_copy_out(td->pc, td->offset, td->qh->fixup_buf, rem);
482 usb_pc_cpu_flush(td->qh->fixup_pc);
484 /* pre-increment TX buffer offset */
486 td->remainder -= rem;
492 switch (td->qh->ep_type & UE_XFERTYPE) {
494 td->qh->iso_pkt.offset = 0;
495 td->qh->iso_pkt.length = rem;
496 td->qh->iso_pkt.status = 0;
497 /* start USB transfer */
498 status = cvmx_usb_submit_isochronous(&sc->sc_port[td->qh->root_port_index].state,
499 td->qh->ep_handle, 1, CVMX_USB_ISOCHRONOUS_FLAGS_ALLOW_SHORT |
500 CVMX_USB_ISOCHRONOUS_FLAGS_ASAP, 1, &td->qh->iso_pkt,
501 td->qh->fixup_phys, rem, &octusb_complete_cb, td);
504 /* start USB transfer */
505 status = cvmx_usb_submit_bulk(&sc->sc_port[td->qh->root_port_index].state,
506 td->qh->ep_handle, td->qh->fixup_phys, rem, &octusb_complete_cb, td);
509 /* start USB transfer (interrupt or interrupt) */
510 status = cvmx_usb_submit_interrupt(&sc->sc_port[td->qh->root_port_index].state,
511 td->qh->ep_handle, td->qh->fixup_phys, rem, &octusb_complete_cb, td);
521 return (0); /* done */
523 td->qh->fixup_handle = status;
524 td->qh->fixup_len = rem;
525 td->qh->fixup_pending = 1;
526 td->qh->fixup_complete = 0;
528 return (1); /* busy */
532 octusb_non_control_data_rx(struct octusb_td *td)
534 struct octusb_softc *sc;
539 /* allocate endpoint and check pending */
540 if (octusb_host_alloc_endpoint(td))
541 return (1); /* busy */
545 return (0); /* done */
549 if (td->qh->fixup_complete != 0) {
551 /* invalidate data */
552 usb_pc_cpu_invalidate(td->qh->fixup_pc);
554 rem = td->qh->fixup_actlen;
556 /* verify transfer length */
557 if (rem != td->qh->fixup_len) {
558 if (rem < td->qh->fixup_len) {
559 /* we have a short packet */
563 /* invalid USB packet */
565 return (0); /* we are complete */
568 /* copy data into fixup buffer */
569 usbd_copy_in(td->pc, td->offset, td->qh->fixup_buf, rem);
571 /* post-increment RX buffer offset */
573 td->remainder -= rem;
575 td->qh->fixup_complete = 0;
577 if ((td->qh->ep_type & UE_XFERTYPE) == UE_ISOCHRONOUS)
578 return (0); /* done */
580 /* check if we are complete */
581 if ((td->remainder == 0) || got_short) {
583 /* we are complete */
586 /* else need to receive a zero length packet */
590 /* get maximum length */
591 rem = OCTUSB_MAX_FIXUP % td->qh->max_frame_size;
592 rem = OCTUSB_MAX_FIXUP - rem;
595 /* should not happen */
596 DPRINTFN(1, "Fixup buffer is too small\n");
598 return (0); /* done */
600 /* get minimum length */
601 if (rem > td->remainder)
605 /* invalidate data */
606 usb_pc_cpu_invalidate(td->qh->fixup_pc);
611 switch (td->qh->ep_type & UE_XFERTYPE) {
613 td->qh->iso_pkt.offset = 0;
614 td->qh->iso_pkt.length = rem;
615 td->qh->iso_pkt.status = 0;
616 /* start USB transfer */
617 status = cvmx_usb_submit_isochronous(&sc->sc_port[td->qh->root_port_index].state,
618 td->qh->ep_handle, 1, CVMX_USB_ISOCHRONOUS_FLAGS_ALLOW_SHORT |
619 CVMX_USB_ISOCHRONOUS_FLAGS_ASAP, 1, &td->qh->iso_pkt,
620 td->qh->fixup_phys, rem, &octusb_complete_cb, td);
623 /* start USB transfer */
624 status = cvmx_usb_submit_bulk(&sc->sc_port[td->qh->root_port_index].state,
625 td->qh->ep_handle, td->qh->fixup_phys, rem, &octusb_complete_cb, td);
628 /* start USB transfer */
629 status = cvmx_usb_submit_interrupt(&sc->sc_port[td->qh->root_port_index].state,
630 td->qh->ep_handle, td->qh->fixup_phys, rem, &octusb_complete_cb, td);
640 return (0); /* done */
642 td->qh->fixup_handle = status;
643 td->qh->fixup_len = rem;
644 td->qh->fixup_pending = 1;
645 td->qh->fixup_complete = 0;
647 return (1); /* busy */
651 octusb_xfer_do_fifo(struct usb_xfer *xfer)
653 struct octusb_td *td;
657 td = xfer->td_transfer_cache;
660 if ((td->func) (td)) {
661 /* operation in progress */
664 if (((void *)td) == xfer->td_transfer_last) {
669 } else if (td->remainder > 0) {
671 * We had a short transfer. If there is no
672 * alternate next, stop processing !
674 if (td->alt_next == 0)
678 * Fetch the next transfer descriptor and transfer
679 * some flags to the next transfer descriptor
682 xfer->td_transfer_cache = td;
684 return (1); /* not complete */
687 /* compute all actual lengths */
689 octusb_standard_done(xfer);
691 return (0); /* complete */
695 octusb_standard_done_sub(struct usb_xfer *xfer)
697 struct octusb_td *td;
703 td = xfer->td_transfer_cache;
708 if (xfer->aframes != xfer->nframes) {
710 * Verify the length and subtract
711 * the remainder from "frlengths[]":
713 if (len > xfer->frlengths[xfer->aframes]) {
716 xfer->frlengths[xfer->aframes] -= len;
719 /* Check for transfer error */
721 /* the transfer is finished */
722 error = td->error_stall ? USB_ERR_STALLED : USB_ERR_IOERROR;
726 /* Check for short transfer */
728 if (xfer->flags_int.short_frames_ok) {
729 /* follow alt next */
736 /* the transfer is finished */
744 /* this USB frame is complete */
750 /* update transfer cache */
752 xfer->td_transfer_cache = td;
758 octusb_standard_done(struct usb_xfer *xfer)
760 struct octusb_softc *sc;
761 struct octusb_qh *qh;
762 usb_error_t error = 0;
764 DPRINTFN(12, "xfer=%p endpoint=%p transfer done\n",
765 xfer, xfer->endpoint);
769 xfer->td_transfer_cache = xfer->td_transfer_first;
771 if (xfer->flags_int.control_xfr) {
773 if (xfer->flags_int.control_hdr)
774 error = octusb_standard_done_sub(xfer);
778 if (xfer->td_transfer_cache == NULL)
781 while (xfer->aframes != xfer->nframes) {
783 error = octusb_standard_done_sub(xfer);
787 if (xfer->td_transfer_cache == NULL)
791 if (xfer->flags_int.control_xfr &&
792 !xfer->flags_int.control_act)
793 error = octusb_standard_done_sub(xfer);
796 /* update data toggle */
798 qh = xfer->qh_start[0];
801 xfer->endpoint->toggle_next =
803 &sc->sc_port[qh->root_port_index].state,
804 qh->ep_handle) ? 1 : 0;
806 octusb_device_done(xfer, error);
810 octusb_interrupt_poll(struct octusb_softc *sc)
812 struct usb_xfer *xfer;
816 for (x = 0; x != sc->sc_noport; x++)
817 cvmx_usb_poll(&sc->sc_port[x].state);
820 TAILQ_FOREACH(xfer, &sc->sc_bus.intr_q.head, wait_entry) {
821 if (!octusb_xfer_do_fifo(xfer)) {
822 /* queue has been modified */
829 octusb_start_standard_chain(struct usb_xfer *xfer)
834 if (octusb_xfer_do_fifo(xfer)) {
836 /* put transfer on interrupt queue */
837 usbd_transfer_enqueue(&xfer->xroot->bus->intr_q, xfer);
839 /* start timeout, if any */
840 if (xfer->timeout != 0) {
841 usbd_transfer_timeout_ms(xfer,
842 &octusb_timeout, xfer->timeout);
848 octusb_iterate_hw_softc(struct usb_bus *bus, usb_bus_mem_sub_cb_t *cb)
854 octusb_init(struct octusb_softc *sc)
856 cvmx_usb_initialize_flags_t flags;
860 /* flush all cache into memory */
862 usb_bus_mem_flush_all(&sc->sc_bus, &octusb_iterate_hw_softc);
864 /* set up the bus struct */
865 sc->sc_bus.methods = &octusb_bus_methods;
867 /* get number of ports */
868 sc->sc_noport = cvmx_usb_get_num_ports();
870 /* check number of ports */
871 if (sc->sc_noport > OCTUSB_MAX_PORTS)
872 sc->sc_noport = OCTUSB_MAX_PORTS;
874 /* set USB revision */
875 sc->sc_bus.usbrev = USB_REV_2_0;
877 /* flags for port initialization */
878 flags = CVMX_USB_INITIALIZE_FLAGS_CLOCK_AUTO;
880 if (octusbdebug > 100)
881 flags |= CVMX_USB_INITIALIZE_FLAGS_DEBUG_ALL;
884 USB_BUS_LOCK(&sc->sc_bus);
886 /* setup all ports */
887 for (x = 0; x != sc->sc_noport; x++) {
888 status = cvmx_usb_initialize(&sc->sc_port[x].state, x, flags);
890 sc->sc_port[x].disabled = 1;
893 USB_BUS_UNLOCK(&sc->sc_bus);
895 /* catch lost interrupts */
896 octusb_do_poll(&sc->sc_bus);
902 octusb_uninit(struct octusb_softc *sc)
906 USB_BUS_LOCK(&sc->sc_bus);
908 for (x = 0; x != sc->sc_noport; x++) {
909 if (sc->sc_port[x].disabled == 0)
910 cvmx_usb_shutdown(&sc->sc_port[x].state);
912 USB_BUS_UNLOCK(&sc->sc_bus);
919 octusb_suspend(struct octusb_softc *sc)
925 octusb_resume(struct octusb_softc *sc)
930 /*------------------------------------------------------------------------*
931 * octusb_interrupt - OCTUSB interrupt handler
932 *------------------------------------------------------------------------*/
934 octusb_interrupt(struct octusb_softc *sc)
936 USB_BUS_LOCK(&sc->sc_bus);
938 DPRINTFN(16, "real interrupt\n");
940 /* poll all the USB transfers */
941 octusb_interrupt_poll(sc);
943 USB_BUS_UNLOCK(&sc->sc_bus);
946 /*------------------------------------------------------------------------*
947 * octusb_timeout - OCTUSB transfer timeout handler
948 *------------------------------------------------------------------------*/
950 octusb_timeout(void *arg)
952 struct usb_xfer *xfer = arg;
954 DPRINTF("xfer=%p\n", xfer);
956 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
958 /* transfer is transferred */
959 octusb_device_done(xfer, USB_ERR_TIMEOUT);
962 /*------------------------------------------------------------------------*
963 * octusb_do_poll - OCTUSB poll transfers
964 *------------------------------------------------------------------------*/
966 octusb_do_poll(struct usb_bus *bus)
968 struct octusb_softc *sc = OCTUSB_BUS2SC(bus);
970 USB_BUS_LOCK(&sc->sc_bus);
971 octusb_interrupt_poll(sc);
972 USB_BUS_UNLOCK(&sc->sc_bus);
976 octusb_setup_standard_chain_sub(struct octusb_std_temp *temp)
978 struct octusb_td *td;
980 /* get current Transfer Descriptor */
984 /* prepare for next TD */
985 temp->td_next = td->obj_next;
987 /* fill out the Transfer Descriptor */
988 td->func = temp->func;
990 td->offset = temp->offset;
991 td->remainder = temp->len;
994 td->short_pkt = temp->short_pkt;
995 td->alt_next = temp->setup_alt_next;
999 octusb_setup_standard_chain(struct usb_xfer *xfer)
1001 struct octusb_std_temp temp;
1002 struct octusb_td *td;
1005 DPRINTFN(9, "addr=%d endpt=%d sumlen=%d speed=%d\n",
1006 xfer->address, UE_GET_ADDR(xfer->endpointno),
1007 xfer->sumlen, usbd_get_speed(xfer->xroot->udev));
1009 /* setup starting point */
1010 td = xfer->td_start[0];
1011 xfer->td_transfer_first = td;
1012 xfer->td_transfer_cache = td;
1016 temp.setup_alt_next = xfer->flags_int.short_frames_ok;
1019 /* check if we should prepend a setup message */
1021 if (xfer->flags_int.control_xfr) {
1023 if (xfer->flags_int.control_hdr) {
1025 temp.func = &octusb_host_control_header_tx;
1026 temp.len = xfer->frlengths[0];
1027 temp.pc = xfer->frbuffers + 0;
1028 temp.short_pkt = temp.len ? 1 : 0;
1030 /* check for last frame */
1031 if (xfer->nframes == 1) {
1033 * no STATUS stage yet, SETUP is
1036 if (xfer->flags_int.control_act)
1037 temp.setup_alt_next = 0;
1039 octusb_setup_standard_chain_sub(&temp);
1046 if (x != xfer->nframes) {
1047 if (xfer->endpointno & UE_DIR_IN) {
1048 if (xfer->flags_int.control_xfr)
1049 temp.func = &octusb_host_control_data_rx;
1051 temp.func = &octusb_non_control_data_rx;
1053 if (xfer->flags_int.control_xfr)
1054 temp.func = &octusb_host_control_data_tx;
1056 temp.func = &octusb_non_control_data_tx;
1059 /* setup "pc" pointer */
1060 temp.pc = xfer->frbuffers + x;
1062 while (x != xfer->nframes) {
1064 /* DATA0 or DATA1 message */
1066 temp.len = xfer->frlengths[x];
1070 if (x == xfer->nframes) {
1071 if (xfer->flags_int.control_xfr) {
1072 /* no STATUS stage yet, DATA is last */
1073 if (xfer->flags_int.control_act)
1074 temp.setup_alt_next = 0;
1076 temp.setup_alt_next = 0;
1079 if (temp.len == 0) {
1081 /* make sure that we send an USB packet */
1087 /* regular data transfer */
1089 temp.short_pkt = (xfer->flags.force_short_xfer) ? 0 : 1;
1092 octusb_setup_standard_chain_sub(&temp);
1094 if (xfer->flags_int.isochronous_xfr) {
1095 /* get next data offset */
1096 temp.offset += temp.len;
1098 /* get next Page Cache pointer */
1099 temp.pc = xfer->frbuffers + x;
1103 /* check if we should append a status stage */
1105 if (xfer->flags_int.control_xfr &&
1106 !xfer->flags_int.control_act) {
1108 temp.func = &octusb_host_control_status_tx;
1112 temp.setup_alt_next = 0;
1114 octusb_setup_standard_chain_sub(&temp);
1116 /* must have at least one frame! */
1118 xfer->td_transfer_last = td;
1120 /* properly setup QH */
1122 td->qh->ep_allocated = 0;
1123 td->qh->ep_toggle_next = xfer->endpoint->toggle_next ? 1 : 0;
1126 /*------------------------------------------------------------------------*
1127 * octusb_device_done - OCTUSB transfers done code
1129 * NOTE: This function can be called more than one time in a row.
1130 *------------------------------------------------------------------------*/
1132 octusb_device_done(struct usb_xfer *xfer, usb_error_t error)
1134 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
1136 DPRINTFN(2, "xfer=%p, endpoint=%p, error=%d\n",
1137 xfer, xfer->endpoint, error);
1140 * 1) Free any endpoints.
1141 * 2) Control transfers can be split and we should not re-open
1142 * the data pipe between transactions unless there is an error.
1144 if ((xfer->flags_int.control_act == 0) || (error != 0)) {
1145 struct octusb_td *td;
1147 td = xfer->td_start[0];
1149 octusb_host_free_endpoint(td);
1151 /* dequeue transfer and start next transfer */
1152 usbd_transfer_done(xfer, error);
1155 /*------------------------------------------------------------------------*
1156 * octusb bulk support
1157 *------------------------------------------------------------------------*/
1159 octusb_device_bulk_open(struct usb_xfer *xfer)
1165 octusb_device_bulk_close(struct usb_xfer *xfer)
1167 octusb_device_done(xfer, USB_ERR_CANCELLED);
1171 octusb_device_bulk_enter(struct usb_xfer *xfer)
1177 octusb_device_bulk_start(struct usb_xfer *xfer)
1180 octusb_setup_standard_chain(xfer);
1181 octusb_start_standard_chain(xfer);
1184 struct usb_pipe_methods octusb_device_bulk_methods =
1186 .open = octusb_device_bulk_open,
1187 .close = octusb_device_bulk_close,
1188 .enter = octusb_device_bulk_enter,
1189 .start = octusb_device_bulk_start,
1192 /*------------------------------------------------------------------------*
1193 * octusb control support
1194 *------------------------------------------------------------------------*/
1196 octusb_device_ctrl_open(struct usb_xfer *xfer)
1202 octusb_device_ctrl_close(struct usb_xfer *xfer)
1204 octusb_device_done(xfer, USB_ERR_CANCELLED);
1208 octusb_device_ctrl_enter(struct usb_xfer *xfer)
1214 octusb_device_ctrl_start(struct usb_xfer *xfer)
1217 octusb_setup_standard_chain(xfer);
1218 octusb_start_standard_chain(xfer);
1221 struct usb_pipe_methods octusb_device_ctrl_methods =
1223 .open = octusb_device_ctrl_open,
1224 .close = octusb_device_ctrl_close,
1225 .enter = octusb_device_ctrl_enter,
1226 .start = octusb_device_ctrl_start,
1229 /*------------------------------------------------------------------------*
1230 * octusb interrupt support
1231 *------------------------------------------------------------------------*/
1233 octusb_device_intr_open(struct usb_xfer *xfer)
1239 octusb_device_intr_close(struct usb_xfer *xfer)
1241 octusb_device_done(xfer, USB_ERR_CANCELLED);
1245 octusb_device_intr_enter(struct usb_xfer *xfer)
1251 octusb_device_intr_start(struct usb_xfer *xfer)
1254 octusb_setup_standard_chain(xfer);
1255 octusb_start_standard_chain(xfer);
1258 struct usb_pipe_methods octusb_device_intr_methods =
1260 .open = octusb_device_intr_open,
1261 .close = octusb_device_intr_close,
1262 .enter = octusb_device_intr_enter,
1263 .start = octusb_device_intr_start,
1266 /*------------------------------------------------------------------------*
1267 * octusb isochronous support
1268 *------------------------------------------------------------------------*/
1270 octusb_device_isoc_open(struct usb_xfer *xfer)
1276 octusb_device_isoc_close(struct usb_xfer *xfer)
1278 octusb_device_done(xfer, USB_ERR_CANCELLED);
1282 octusb_device_isoc_enter(struct usb_xfer *xfer)
1284 struct octusb_softc *sc = OCTUSB_BUS2SC(xfer->xroot->bus);
1286 uint32_t frame_count;
1289 DPRINTFN(5, "xfer=%p next=%d nframes=%d\n",
1290 xfer, xfer->endpoint->isoc_next, xfer->nframes);
1292 /* get the current frame index */
1294 frame_count = cvmx_usb_get_frame_number(
1295 &sc->sc_port[xfer->xroot->udev->port_index].state);
1298 * check if the frame index is within the window where the frames
1301 temp = (frame_count - xfer->endpoint->isoc_next) & 0x7FF;
1303 if (usbd_get_speed(xfer->xroot->udev) == USB_SPEED_HIGH) {
1304 fs_frames = (xfer->nframes + 7) / 8;
1306 fs_frames = xfer->nframes;
1309 if ((xfer->endpoint->is_synced == 0) || (temp < fs_frames)) {
1311 * If there is data underflow or the pipe queue is
1312 * empty we schedule the transfer a few frames ahead
1313 * of the current frame position. Else two isochronous
1314 * transfers might overlap.
1316 xfer->endpoint->isoc_next = (frame_count + 3) & 0x7FF;
1317 xfer->endpoint->is_synced = 1;
1318 DPRINTFN(2, "start next=%d\n", xfer->endpoint->isoc_next);
1321 * compute how many milliseconds the insertion is ahead of the
1322 * current frame position:
1324 temp = (xfer->endpoint->isoc_next - frame_count) & 0x7FF;
1327 * pre-compute when the isochronous transfer will be finished:
1329 xfer->isoc_time_complete =
1330 usb_isoc_time_expand(&sc->sc_bus, frame_count) + temp +
1333 /* compute frame number for next insertion */
1334 xfer->endpoint->isoc_next += fs_frames;
1338 octusb_device_isoc_start(struct usb_xfer *xfer)
1341 octusb_setup_standard_chain(xfer);
1342 octusb_start_standard_chain(xfer);
1345 struct usb_pipe_methods octusb_device_isoc_methods =
1347 .open = octusb_device_isoc_open,
1348 .close = octusb_device_isoc_close,
1349 .enter = octusb_device_isoc_enter,
1350 .start = octusb_device_isoc_start,
1353 /*------------------------------------------------------------------------*
1354 * OCTUSB root HUB support
1355 *------------------------------------------------------------------------*
1356 * Simulate a hardware HUB by handling all the necessary requests.
1357 *------------------------------------------------------------------------*/
1359 struct usb_device_descriptor octusb_devd = {
1360 .bLength = sizeof(octusb_devd),
1361 .bDescriptorType = UDESC_DEVICE,
1362 .bcdUSB = {0x00, 0x02},
1363 .bDeviceClass = UDCLASS_HUB,
1364 .bDeviceSubClass = UDSUBCLASS_HUB,
1365 .bDeviceProtocol = UDPROTO_FSHUB,
1366 .bMaxPacketSize = 64,
1369 .bcdDevice = {0x00, 0x01},
1373 .bNumConfigurations = 1,
1377 struct usb_device_qualifier octusb_odevd = {
1378 .bLength = sizeof(octusb_odevd),
1379 .bDescriptorType = UDESC_DEVICE_QUALIFIER,
1380 .bcdUSB = {0x00, 0x02},
1381 .bDeviceClass = UDCLASS_HUB,
1382 .bDeviceSubClass = UDSUBCLASS_HUB,
1383 .bDeviceProtocol = UDPROTO_FSHUB,
1384 .bMaxPacketSize0 = 0,
1385 .bNumConfigurations = 0,
1390 struct octusb_config_desc octusb_confd = {
1392 .bLength = sizeof(struct usb_config_descriptor),
1393 .bDescriptorType = UDESC_CONFIG,
1394 .wTotalLength[0] = sizeof(octusb_confd),
1396 .bConfigurationValue = 1,
1397 .iConfiguration = 0,
1398 .bmAttributes = UC_SELF_POWERED,
1399 .bMaxPower = 0 /* max power */
1402 .bLength = sizeof(struct usb_interface_descriptor),
1403 .bDescriptorType = UDESC_INTERFACE,
1405 .bInterfaceClass = UICLASS_HUB,
1406 .bInterfaceSubClass = UISUBCLASS_HUB,
1407 .bInterfaceProtocol = UIPROTO_FSHUB,
1410 .bLength = sizeof(struct usb_endpoint_descriptor),
1411 .bDescriptorType = UDESC_ENDPOINT,
1412 .bEndpointAddress = UE_DIR_IN | OCTUSB_INTR_ENDPT,
1413 .bmAttributes = UE_INTERRUPT,
1414 .wMaxPacketSize[0] = 8, /* max packet (63 ports) */
1420 struct usb_hub_descriptor_min octusb_hubd =
1422 .bDescLength = sizeof(octusb_hubd),
1423 .bDescriptorType = UDESC_HUB,
1425 .wHubCharacteristics = {UHD_PWR_NO_SWITCH | UHD_OC_INDIVIDUAL, 0},
1426 .bPwrOn2PwrGood = 50,
1427 .bHubContrCurrent = 0,
1428 .DeviceRemovable = {0x00}, /* all ports are removable */
1432 octusb_roothub_exec(struct usb_device *udev,
1433 struct usb_device_request *req, const void **pptr, uint16_t *plength)
1435 struct octusb_softc *sc = OCTUSB_BUS2SC(udev->bus);
1437 const char *str_ptr;
1444 cvmx_usb_port_status_t usb_port_status;
1446 USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
1448 /* XXX disable power save mode, hence it is not supported */
1449 udev->power_mode = USB_POWER_MODE_ON;
1452 ptr = (const void *)&sc->sc_hub_desc.temp;
1456 value = UGETW(req->wValue);
1457 index = UGETW(req->wIndex);
1459 DPRINTFN(3, "type=0x%02x request=0x%02x wLen=0x%04x "
1460 "wValue=0x%04x wIndex=0x%04x\n",
1461 req->bmRequestType, req->bRequest,
1462 UGETW(req->wLength), value, index);
1464 #define C(x,y) ((x) | ((y) << 8))
1465 switch (C(req->bRequest, req->bmRequestType)) {
1466 case C(UR_CLEAR_FEATURE, UT_WRITE_DEVICE):
1467 case C(UR_CLEAR_FEATURE, UT_WRITE_INTERFACE):
1468 case C(UR_CLEAR_FEATURE, UT_WRITE_ENDPOINT):
1470 case C(UR_GET_CONFIG, UT_READ_DEVICE):
1472 sc->sc_hub_desc.temp[0] = sc->sc_conf;
1474 case C(UR_GET_DESCRIPTOR, UT_READ_DEVICE):
1475 switch (value >> 8) {
1477 if ((value & 0xff) != 0) {
1478 err = USB_ERR_IOERROR;
1481 len = sizeof(octusb_devd);
1483 ptr = (const void *)&octusb_devd;
1486 case UDESC_DEVICE_QUALIFIER:
1487 if ((value & 0xff) != 0) {
1488 err = USB_ERR_IOERROR;
1491 len = sizeof(octusb_odevd);
1492 ptr = (const void *)&octusb_odevd;
1496 if ((value & 0xff) != 0) {
1497 err = USB_ERR_IOERROR;
1500 len = sizeof(octusb_confd);
1501 ptr = (const void *)&octusb_confd;
1505 switch (value & 0xff) {
1506 case 0: /* Language table */
1510 case 1: /* Vendor */
1511 str_ptr = "Cavium Networks";
1514 case 2: /* Product */
1515 str_ptr = "OCTUSB Root HUB";
1523 len = usb_make_str_desc(sc->sc_hub_desc.temp,
1524 sizeof(sc->sc_hub_desc.temp), str_ptr);
1528 err = USB_ERR_IOERROR;
1532 case C(UR_GET_INTERFACE, UT_READ_INTERFACE):
1534 sc->sc_hub_desc.temp[0] = 0;
1536 case C(UR_GET_STATUS, UT_READ_DEVICE):
1538 USETW(sc->sc_hub_desc.stat.wStatus, UDS_SELF_POWERED);
1540 case C(UR_GET_STATUS, UT_READ_INTERFACE):
1541 case C(UR_GET_STATUS, UT_READ_ENDPOINT):
1543 USETW(sc->sc_hub_desc.stat.wStatus, 0);
1545 case C(UR_SET_ADDRESS, UT_WRITE_DEVICE):
1546 if (value >= OCTUSB_MAX_DEVICES) {
1547 err = USB_ERR_IOERROR;
1550 sc->sc_addr = value;
1552 case C(UR_SET_CONFIG, UT_WRITE_DEVICE):
1553 if ((value != 0) && (value != 1)) {
1554 err = USB_ERR_IOERROR;
1557 sc->sc_conf = value;
1559 case C(UR_SET_DESCRIPTOR, UT_WRITE_DEVICE):
1561 case C(UR_SET_FEATURE, UT_WRITE_DEVICE):
1562 case C(UR_SET_FEATURE, UT_WRITE_INTERFACE):
1563 case C(UR_SET_FEATURE, UT_WRITE_ENDPOINT):
1564 err = USB_ERR_IOERROR;
1566 case C(UR_SET_INTERFACE, UT_WRITE_INTERFACE):
1568 case C(UR_SYNCH_FRAME, UT_WRITE_ENDPOINT):
1571 case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_DEVICE):
1573 case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_OTHER):
1574 DPRINTFN(4, "UR_CLEAR_PORT_FEATURE "
1575 "port=%d feature=%d\n",
1578 (index > sc->sc_noport) ||
1579 sc->sc_port[index - 1].disabled) {
1580 err = USB_ERR_IOERROR;
1586 case UHF_PORT_ENABLE:
1587 cvmx_usb_disable(&sc->sc_port[index].state);
1589 case UHF_PORT_SUSPEND:
1590 case UHF_PORT_RESET:
1592 case UHF_C_PORT_CONNECTION:
1593 cvmx_usb_set_status(&sc->sc_port[index].state,
1594 cvmx_usb_get_status(&sc->sc_port[index].state));
1596 case UHF_C_PORT_ENABLE:
1597 cvmx_usb_set_status(&sc->sc_port[index].state,
1598 cvmx_usb_get_status(&sc->sc_port[index].state));
1600 case UHF_C_PORT_OVER_CURRENT:
1601 cvmx_usb_set_status(&sc->sc_port[index].state,
1602 cvmx_usb_get_status(&sc->sc_port[index].state));
1604 case UHF_C_PORT_RESET:
1607 case UHF_C_PORT_SUSPEND:
1609 case UHF_PORT_CONNECTION:
1610 case UHF_PORT_OVER_CURRENT:
1611 case UHF_PORT_POWER:
1612 case UHF_PORT_LOW_SPEED:
1614 err = USB_ERR_IOERROR;
1618 case C(UR_GET_DESCRIPTOR, UT_READ_CLASS_DEVICE):
1619 if ((value & 0xff) != 0) {
1620 err = USB_ERR_IOERROR;
1623 sc->sc_hubd = octusb_hubd;
1624 sc->sc_hubd.bNbrPorts = sc->sc_noport;
1625 len = sizeof(sc->sc_hubd);
1626 ptr = (const void *)&sc->sc_hubd;
1628 case C(UR_GET_STATUS, UT_READ_CLASS_DEVICE):
1630 memset(sc->sc_hub_desc.temp, 0, 16);
1632 case C(UR_GET_STATUS, UT_READ_CLASS_OTHER):
1634 (index > sc->sc_noport) ||
1635 sc->sc_port[index - 1].disabled) {
1636 err = USB_ERR_IOERROR;
1641 usb_port_status = cvmx_usb_get_status(&sc->sc_port[index].state);
1643 status = change = 0;
1644 if (usb_port_status.connected)
1645 status |= UPS_CURRENT_CONNECT_STATUS;
1646 if (usb_port_status.port_enabled)
1647 status |= UPS_PORT_ENABLED;
1648 if (usb_port_status.port_over_current)
1649 status |= UPS_OVERCURRENT_INDICATOR;
1650 if (usb_port_status.port_powered)
1651 status |= UPS_PORT_POWER;
1653 switch (usb_port_status.port_speed) {
1654 case CVMX_USB_SPEED_HIGH:
1655 status |= UPS_HIGH_SPEED;
1657 case CVMX_USB_SPEED_FULL:
1660 status |= UPS_LOW_SPEED;
1664 if (usb_port_status.connect_change)
1665 change |= UPS_C_CONNECT_STATUS;
1667 change |= UPS_C_PORT_RESET;
1669 USETW(sc->sc_hub_desc.ps.wPortStatus, status);
1670 USETW(sc->sc_hub_desc.ps.wPortChange, change);
1672 len = sizeof(sc->sc_hub_desc.ps);
1674 case C(UR_SET_DESCRIPTOR, UT_WRITE_CLASS_DEVICE):
1675 err = USB_ERR_IOERROR;
1677 case C(UR_SET_FEATURE, UT_WRITE_CLASS_DEVICE):
1679 case C(UR_SET_FEATURE, UT_WRITE_CLASS_OTHER):
1681 (index > sc->sc_noport) ||
1682 sc->sc_port[index - 1].disabled) {
1683 err = USB_ERR_IOERROR;
1689 case UHF_PORT_ENABLE:
1691 case UHF_PORT_RESET:
1692 cvmx_usb_disable(&sc->sc_port[index].state);
1693 if (cvmx_usb_enable(&sc->sc_port[index].state)) {
1694 err = USB_ERR_IOERROR;
1699 case UHF_PORT_POWER:
1700 /* pretend we turned on power */
1702 case UHF_PORT_SUSPEND:
1703 case UHF_C_PORT_CONNECTION:
1704 case UHF_C_PORT_ENABLE:
1705 case UHF_C_PORT_OVER_CURRENT:
1706 case UHF_PORT_CONNECTION:
1707 case UHF_PORT_OVER_CURRENT:
1708 case UHF_PORT_LOW_SPEED:
1709 case UHF_C_PORT_SUSPEND:
1710 case UHF_C_PORT_RESET:
1712 err = USB_ERR_IOERROR;
1717 err = USB_ERR_IOERROR;
1727 octusb_xfer_setup(struct usb_setup_params *parm)
1729 struct usb_page_search page_info;
1730 struct usb_page_cache *pc;
1731 struct octusb_softc *sc;
1732 struct octusb_qh *qh;
1733 struct usb_xfer *xfer;
1734 struct usb_device *hub;
1739 sc = OCTUSB_BUS2SC(parm->udev->bus);
1740 xfer = parm->curr_xfer;
1744 * NOTE: This driver does not use any of the parameters that
1745 * are computed from the following values. Just set some
1746 * reasonable dummies:
1749 parm->hc_max_packet_size = 0x400;
1750 parm->hc_max_packet_count = 3;
1751 parm->hc_max_frame_size = 0xC00;
1753 usbd_transfer_setup_sub(parm);
1758 /* Allocate a queue head */
1760 if (usbd_transfer_setup_sub_malloc(
1761 parm, &pc, sizeof(struct octusb_qh),
1762 USB_HOST_ALIGN, 1)) {
1763 parm->err = USB_ERR_NOMEM;
1767 usbd_get_page(pc, 0, &page_info);
1769 qh = page_info.buffer;
1773 qh->sc = OCTUSB_BUS2SC(xfer->xroot->bus);
1774 qh->max_frame_size = xfer->max_frame_size;
1775 qh->max_packet_size = xfer->max_packet_size;
1776 qh->ep_num = xfer->endpointno;
1777 qh->ep_type = xfer->endpoint->edesc->bmAttributes;
1778 qh->dev_addr = xfer->address;
1779 qh->dev_speed = usbd_get_speed(xfer->xroot->udev);
1780 qh->root_port_index = xfer->xroot->udev->port_index;
1781 /* We need Octeon USB HUB's port index, not the local port */
1782 hub = xfer->xroot->udev->parent_hub;
1783 while(hub && hub->parent_hub) {
1784 qh->root_port_index = hub->port_index;
1785 hub = hub->parent_hub;
1788 switch (xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE) {
1790 if (usbd_get_speed(xfer->xroot->udev) == USB_SPEED_HIGH)
1791 qh->ep_interval = xfer->interval * 8;
1793 qh->ep_interval = xfer->interval * 1;
1795 case UE_ISOCHRONOUS:
1796 qh->ep_interval = 1 << xfer->fps_shift;
1799 qh->ep_interval = 0;
1803 qh->ep_mult = xfer->max_packet_count & 3;
1804 qh->hs_hub_addr = xfer->xroot->udev->hs_hub_addr;
1805 qh->hs_hub_port = xfer->xroot->udev->hs_port_no;
1807 xfer->qh_start[0] = qh;
1809 /* Allocate a fixup buffer */
1811 if (usbd_transfer_setup_sub_malloc(
1812 parm, &pc, OCTUSB_MAX_FIXUP,
1813 OCTUSB_MAX_FIXUP, 1)) {
1814 parm->err = USB_ERR_NOMEM;
1818 usbd_get_page(pc, 0, &page_info);
1820 qh->fixup_phys = page_info.physaddr;
1822 qh->fixup_buf = page_info.buffer;
1824 /* Allocate transfer descriptors */
1828 ntd = xfer->nframes + 1 /* STATUS */ + 1 /* SYNC */ ;
1830 if (usbd_transfer_setup_sub_malloc(
1831 parm, &pc, sizeof(struct octusb_td),
1832 USB_HOST_ALIGN, ntd)) {
1833 parm->err = USB_ERR_NOMEM;
1837 for (n = 0; n != ntd; n++) {
1838 struct octusb_td *td;
1840 usbd_get_page(pc + n, 0, &page_info);
1842 td = page_info.buffer;
1845 td->obj_next = last_obj;
1850 xfer->td_start[0] = last_obj;
1854 octusb_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor *edesc,
1855 struct usb_endpoint *ep)
1857 struct octusb_softc *sc = OCTUSB_BUS2SC(udev->bus);
1859 DPRINTFN(2, "endpoint=%p, addr=%d, endpt=%d, mode=%d (%d)\n",
1860 ep, udev->address, edesc->bEndpointAddress,
1861 udev->flags.usb_mode, sc->sc_addr);
1863 if (udev->device_index != sc->sc_addr) {
1864 switch (edesc->bmAttributes & UE_XFERTYPE) {
1866 ep->methods = &octusb_device_ctrl_methods;
1869 ep->methods = &octusb_device_intr_methods;
1871 case UE_ISOCHRONOUS:
1872 if (udev->speed != USB_SPEED_LOW)
1873 ep->methods = &octusb_device_isoc_methods;
1876 ep->methods = &octusb_device_bulk_methods;
1886 octusb_xfer_unsetup(struct usb_xfer *xfer)
1888 DPRINTF("Nothing to do.\n");
1892 octusb_get_dma_delay(struct usb_device *udev, uint32_t *pus)
1894 /* DMA delay - wait until any use of memory is finished */
1895 *pus = (2125); /* microseconds */
1899 octusb_device_resume(struct usb_device *udev)
1901 DPRINTF("Nothing to do.\n");
1905 octusb_device_suspend(struct usb_device *udev)
1907 DPRINTF("Nothing to do.\n");
1911 octusb_set_hw_power(struct usb_bus *bus)
1913 DPRINTF("Nothing to do.\n");
1917 octusb_set_hw_power_sleep(struct usb_bus *bus, uint32_t state)
1919 struct octusb_softc *sc = OCTUSB_BUS2SC(bus);
1922 case USB_HW_POWER_SUSPEND:
1925 case USB_HW_POWER_SHUTDOWN:
1928 case USB_HW_POWER_RESUME:
1936 struct usb_bus_methods octusb_bus_methods = {
1937 .endpoint_init = octusb_ep_init,
1938 .xfer_setup = octusb_xfer_setup,
1939 .xfer_unsetup = octusb_xfer_unsetup,
1940 .get_dma_delay = octusb_get_dma_delay,
1941 .device_resume = octusb_device_resume,
1942 .device_suspend = octusb_device_suspend,
1943 .set_hw_power = octusb_set_hw_power,
1944 .set_hw_power_sleep = octusb_set_hw_power_sleep,
1945 .roothub_exec = octusb_roothub_exec,
1946 .xfer_poll = octusb_do_poll,