5 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
7 * Copyright (c) 2010 Hans Petter Selasky. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * This file contains the driver for Octeon Executive Library USB
33 * Controller driver API.
36 /* TODO: The root HUB port callback is not yet implemented. */
38 #include <sys/stdint.h>
39 #include <sys/stddef.h>
40 #include <sys/param.h>
41 #include <sys/queue.h>
42 #include <sys/types.h>
43 #include <sys/systm.h>
44 #include <sys/kernel.h>
46 #include <sys/module.h>
48 #include <sys/mutex.h>
49 #include <sys/condvar.h>
50 #include <sys/sysctl.h>
52 #include <sys/unistd.h>
53 #include <sys/callout.h>
54 #include <sys/malloc.h>
57 #include <dev/usb/usb.h>
58 #include <dev/usb/usbdi.h>
60 #define USB_DEBUG_VAR octusbdebug
62 #include <dev/usb/usb_core.h>
63 #include <dev/usb/usb_debug.h>
64 #include <dev/usb/usb_busdma.h>
65 #include <dev/usb/usb_process.h>
66 #include <dev/usb/usb_transfer.h>
67 #include <dev/usb/usb_device.h>
68 #include <dev/usb/usb_hub.h>
69 #include <dev/usb/usb_util.h>
71 #include <dev/usb/usb_controller.h>
72 #include <dev/usb/usb_bus.h>
74 #include <contrib/octeon-sdk/cvmx.h>
75 #include <contrib/octeon-sdk/cvmx-usb.h>
77 #include <mips/cavium/usb/octusb.h>
79 #define OCTUSB_BUS2SC(bus) \
80 ((struct octusb_softc *)(((uint8_t *)(bus)) - \
81 ((uint8_t *)&(((struct octusb_softc *)0)->sc_bus))))
84 static int octusbdebug = 0;
86 static SYSCTL_NODE(_hw_usb, OID_AUTO, octusb, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
88 SYSCTL_INT(_hw_usb_octusb, OID_AUTO, debug, CTLFLAG_RWTUN,
89 &octusbdebug, 0, "OCTUSB debug level");
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) {
296 struct octusb_softc *sc;
302 usb_pc_cpu_flush(td->qh->fixup_pc);
304 status = cvmx_usb_submit_control(
305 &sc->sc_port[td->qh->root_port_index].state,
306 td->qh->ep_handle, td->qh->fixup_phys,
307 td->qh->fixup_phys + 8, td->qh->fixup_len,
308 &octusb_complete_cb, td);
312 return (0); /* done */
314 td->qh->fixup_handle = status;
315 td->qh->fixup_pending = 1;
316 td->qh->fixup_complete = 0;
318 return (1); /* busy */
320 return (0); /* done */
324 octusb_host_control_data_tx(struct octusb_td *td)
328 /* allocate endpoint and check pending */
329 if (octusb_host_alloc_endpoint(td))
330 return (1); /* busy */
334 return (0); /* done */
336 rem = td->qh->fixup_len - td->qh->fixup_off;
338 if (td->remainder > rem) {
340 DPRINTFN(1, "Excess setup transmit data\n");
341 return (0); /* done */
343 usbd_copy_out(td->pc, td->offset, td->qh->fixup_buf +
344 td->qh->fixup_off + 8, td->remainder);
346 td->offset += td->remainder;
347 td->qh->fixup_off += td->remainder;
350 return (0); /* done */
354 octusb_host_control_data_rx(struct octusb_td *td)
358 /* allocate endpoint and check pending */
359 if (octusb_host_alloc_endpoint(td))
360 return (1); /* busy */
364 return (0); /* done */
366 /* copy data from buffer */
367 rem = td->qh->fixup_actlen - td->qh->fixup_off;
369 if (rem > td->remainder)
372 usbd_copy_in(td->pc, td->offset, td->qh->fixup_buf +
373 td->qh->fixup_off + 8, rem);
376 td->remainder -= rem;
377 td->qh->fixup_off += rem;
379 return (0); /* done */
383 octusb_host_control_status_tx(struct octusb_td *td)
387 /* allocate endpoint and check pending */
388 if (octusb_host_alloc_endpoint(td))
389 return (1); /* busy */
393 return (0); /* done */
395 if (td->qh->fixup_complete != 0) {
396 /* clear complete flag */
397 td->qh->fixup_complete = 0;
401 /* do control IN request */
402 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->root_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->root_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->root_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->root_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) {
548 /* invalidate data */
549 usb_pc_cpu_invalidate(td->qh->fixup_pc);
551 rem = td->qh->fixup_actlen;
553 /* verify transfer length */
554 if (rem != td->qh->fixup_len) {
555 if (rem < td->qh->fixup_len) {
556 /* we have a short packet */
560 /* invalid USB packet */
562 return (0); /* we are complete */
565 /* copy data into fixup buffer */
566 usbd_copy_in(td->pc, td->offset, td->qh->fixup_buf, rem);
568 /* post-increment RX buffer offset */
570 td->remainder -= rem;
572 td->qh->fixup_complete = 0;
574 if ((td->qh->ep_type & UE_XFERTYPE) == UE_ISOCHRONOUS)
575 return (0); /* done */
577 /* check if we are complete */
578 if ((td->remainder == 0) || got_short) {
580 /* we are complete */
583 /* else need to receive a zero length packet */
587 /* get maximum length */
588 rem = OCTUSB_MAX_FIXUP % td->qh->max_frame_size;
589 rem = OCTUSB_MAX_FIXUP - rem;
592 /* should not happen */
593 DPRINTFN(1, "Fixup buffer is too small\n");
595 return (0); /* done */
597 /* get minimum length */
598 if (rem > td->remainder)
602 /* invalidate data */
603 usb_pc_cpu_invalidate(td->qh->fixup_pc);
608 switch (td->qh->ep_type & UE_XFERTYPE) {
610 td->qh->iso_pkt.offset = 0;
611 td->qh->iso_pkt.length = rem;
612 td->qh->iso_pkt.status = 0;
613 /* start USB transfer */
614 status = cvmx_usb_submit_isochronous(&sc->sc_port[td->qh->root_port_index].state,
615 td->qh->ep_handle, 1, CVMX_USB_ISOCHRONOUS_FLAGS_ALLOW_SHORT |
616 CVMX_USB_ISOCHRONOUS_FLAGS_ASAP, 1, &td->qh->iso_pkt,
617 td->qh->fixup_phys, rem, &octusb_complete_cb, td);
620 /* start USB transfer */
621 status = cvmx_usb_submit_bulk(&sc->sc_port[td->qh->root_port_index].state,
622 td->qh->ep_handle, td->qh->fixup_phys, rem, &octusb_complete_cb, td);
625 /* start USB transfer */
626 status = cvmx_usb_submit_interrupt(&sc->sc_port[td->qh->root_port_index].state,
627 td->qh->ep_handle, td->qh->fixup_phys, rem, &octusb_complete_cb, td);
637 return (0); /* done */
639 td->qh->fixup_handle = status;
640 td->qh->fixup_len = rem;
641 td->qh->fixup_pending = 1;
642 td->qh->fixup_complete = 0;
644 return (1); /* busy */
648 octusb_xfer_do_fifo(struct usb_xfer *xfer)
650 struct octusb_td *td;
654 td = xfer->td_transfer_cache;
657 if ((td->func) (td)) {
658 /* operation in progress */
661 if (((void *)td) == xfer->td_transfer_last) {
666 } else if (td->remainder > 0) {
668 * We had a short transfer. If there is no
669 * alternate next, stop processing !
671 if (td->alt_next == 0)
675 * Fetch the next transfer descriptor and transfer
676 * some flags to the next transfer descriptor
679 xfer->td_transfer_cache = td;
681 return (1); /* not complete */
684 /* compute all actual lengths */
686 octusb_standard_done(xfer);
688 return (0); /* complete */
692 octusb_standard_done_sub(struct usb_xfer *xfer)
694 struct octusb_td *td;
700 td = xfer->td_transfer_cache;
705 if (xfer->aframes != xfer->nframes) {
707 * Verify the length and subtract
708 * the remainder from "frlengths[]":
710 if (len > xfer->frlengths[xfer->aframes]) {
713 xfer->frlengths[xfer->aframes] -= len;
716 /* Check for transfer error */
718 /* the transfer is finished */
719 error = td->error_stall ? USB_ERR_STALLED : USB_ERR_IOERROR;
723 /* Check for short transfer */
725 if (xfer->flags_int.short_frames_ok) {
726 /* follow alt next */
733 /* the transfer is finished */
741 /* this USB frame is complete */
747 /* update transfer cache */
749 xfer->td_transfer_cache = td;
755 octusb_standard_done(struct usb_xfer *xfer)
757 struct octusb_softc *sc;
758 struct octusb_qh *qh;
759 usb_error_t error = 0;
761 DPRINTFN(12, "xfer=%p endpoint=%p transfer done\n",
762 xfer, xfer->endpoint);
766 xfer->td_transfer_cache = xfer->td_transfer_first;
768 if (xfer->flags_int.control_xfr) {
769 if (xfer->flags_int.control_hdr)
770 error = octusb_standard_done_sub(xfer);
774 if (xfer->td_transfer_cache == NULL)
777 while (xfer->aframes != xfer->nframes) {
778 error = octusb_standard_done_sub(xfer);
782 if (xfer->td_transfer_cache == NULL)
786 if (xfer->flags_int.control_xfr &&
787 !xfer->flags_int.control_act)
788 error = octusb_standard_done_sub(xfer);
791 /* update data toggle */
793 qh = xfer->qh_start[0];
796 xfer->endpoint->toggle_next =
798 &sc->sc_port[qh->root_port_index].state,
799 qh->ep_handle) ? 1 : 0;
801 octusb_device_done(xfer, error);
805 octusb_interrupt_poll(struct octusb_softc *sc)
807 struct usb_xfer *xfer;
811 for (x = 0; x != sc->sc_noport; x++)
812 cvmx_usb_poll(&sc->sc_port[x].state);
815 TAILQ_FOREACH(xfer, &sc->sc_bus.intr_q.head, wait_entry) {
816 if (!octusb_xfer_do_fifo(xfer)) {
817 /* queue has been modified */
824 octusb_start_standard_chain(struct usb_xfer *xfer)
829 if (octusb_xfer_do_fifo(xfer)) {
830 /* put transfer on interrupt queue */
831 usbd_transfer_enqueue(&xfer->xroot->bus->intr_q, xfer);
833 /* start timeout, if any */
834 if (xfer->timeout != 0) {
835 usbd_transfer_timeout_ms(xfer,
836 &octusb_timeout, xfer->timeout);
842 octusb_iterate_hw_softc(struct usb_bus *bus, usb_bus_mem_sub_cb_t *cb)
848 octusb_init(struct octusb_softc *sc)
850 cvmx_usb_initialize_flags_t flags;
854 /* flush all cache into memory */
856 usb_bus_mem_flush_all(&sc->sc_bus, &octusb_iterate_hw_softc);
858 /* set up the bus struct */
859 sc->sc_bus.methods = &octusb_bus_methods;
861 /* get number of ports */
862 sc->sc_noport = cvmx_usb_get_num_ports();
864 /* check number of ports */
865 if (sc->sc_noport > OCTUSB_MAX_PORTS)
866 sc->sc_noport = OCTUSB_MAX_PORTS;
868 /* set USB revision */
869 sc->sc_bus.usbrev = USB_REV_2_0;
871 /* flags for port initialization */
872 flags = CVMX_USB_INITIALIZE_FLAGS_CLOCK_AUTO;
874 if (octusbdebug > 100)
875 flags |= CVMX_USB_INITIALIZE_FLAGS_DEBUG_ALL;
878 USB_BUS_LOCK(&sc->sc_bus);
880 /* setup all ports */
881 for (x = 0; x != sc->sc_noport; x++) {
882 status = cvmx_usb_initialize(&sc->sc_port[x].state, x, flags);
884 sc->sc_port[x].disabled = 1;
887 USB_BUS_UNLOCK(&sc->sc_bus);
889 /* catch lost interrupts */
890 octusb_do_poll(&sc->sc_bus);
896 octusb_uninit(struct octusb_softc *sc)
900 USB_BUS_LOCK(&sc->sc_bus);
902 for (x = 0; x != sc->sc_noport; x++) {
903 if (sc->sc_port[x].disabled == 0)
904 cvmx_usb_shutdown(&sc->sc_port[x].state);
906 USB_BUS_UNLOCK(&sc->sc_bus);
913 octusb_suspend(struct octusb_softc *sc)
919 octusb_resume(struct octusb_softc *sc)
924 /*------------------------------------------------------------------------*
925 * octusb_interrupt - OCTUSB interrupt handler
926 *------------------------------------------------------------------------*/
928 octusb_interrupt(struct octusb_softc *sc)
930 USB_BUS_LOCK(&sc->sc_bus);
932 DPRINTFN(16, "real interrupt\n");
934 /* poll all the USB transfers */
935 octusb_interrupt_poll(sc);
937 USB_BUS_UNLOCK(&sc->sc_bus);
940 /*------------------------------------------------------------------------*
941 * octusb_timeout - OCTUSB transfer timeout handler
942 *------------------------------------------------------------------------*/
944 octusb_timeout(void *arg)
946 struct usb_xfer *xfer = arg;
948 DPRINTF("xfer=%p\n", xfer);
950 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
952 /* transfer is transferred */
953 octusb_device_done(xfer, USB_ERR_TIMEOUT);
956 /*------------------------------------------------------------------------*
957 * octusb_do_poll - OCTUSB poll transfers
958 *------------------------------------------------------------------------*/
960 octusb_do_poll(struct usb_bus *bus)
962 struct octusb_softc *sc = OCTUSB_BUS2SC(bus);
964 USB_BUS_LOCK(&sc->sc_bus);
965 octusb_interrupt_poll(sc);
966 USB_BUS_UNLOCK(&sc->sc_bus);
970 octusb_setup_standard_chain_sub(struct octusb_std_temp *temp)
972 struct octusb_td *td;
974 /* get current Transfer Descriptor */
978 /* prepare for next TD */
979 temp->td_next = td->obj_next;
981 /* fill out the Transfer Descriptor */
982 td->func = temp->func;
984 td->offset = temp->offset;
985 td->remainder = temp->len;
988 td->short_pkt = temp->short_pkt;
989 td->alt_next = temp->setup_alt_next;
993 octusb_setup_standard_chain(struct usb_xfer *xfer)
995 struct octusb_std_temp temp;
996 struct octusb_td *td;
999 DPRINTFN(9, "addr=%d endpt=%d sumlen=%d speed=%d\n",
1000 xfer->address, UE_GET_ADDR(xfer->endpointno),
1001 xfer->sumlen, usbd_get_speed(xfer->xroot->udev));
1003 /* setup starting point */
1004 td = xfer->td_start[0];
1005 xfer->td_transfer_first = td;
1006 xfer->td_transfer_cache = td;
1010 temp.setup_alt_next = xfer->flags_int.short_frames_ok;
1013 /* check if we should prepend a setup message */
1015 if (xfer->flags_int.control_xfr) {
1016 if (xfer->flags_int.control_hdr) {
1017 temp.func = &octusb_host_control_header_tx;
1018 temp.len = xfer->frlengths[0];
1019 temp.pc = xfer->frbuffers + 0;
1020 temp.short_pkt = temp.len ? 1 : 0;
1022 /* check for last frame */
1023 if (xfer->nframes == 1) {
1025 * no STATUS stage yet, SETUP is
1028 if (xfer->flags_int.control_act)
1029 temp.setup_alt_next = 0;
1031 octusb_setup_standard_chain_sub(&temp);
1038 if (x != xfer->nframes) {
1039 if (xfer->endpointno & UE_DIR_IN) {
1040 if (xfer->flags_int.control_xfr)
1041 temp.func = &octusb_host_control_data_rx;
1043 temp.func = &octusb_non_control_data_rx;
1045 if (xfer->flags_int.control_xfr)
1046 temp.func = &octusb_host_control_data_tx;
1048 temp.func = &octusb_non_control_data_tx;
1051 /* setup "pc" pointer */
1052 temp.pc = xfer->frbuffers + x;
1054 while (x != xfer->nframes) {
1055 /* DATA0 or DATA1 message */
1057 temp.len = xfer->frlengths[x];
1061 if (x == xfer->nframes) {
1062 if (xfer->flags_int.control_xfr) {
1063 /* no STATUS stage yet, DATA is last */
1064 if (xfer->flags_int.control_act)
1065 temp.setup_alt_next = 0;
1067 temp.setup_alt_next = 0;
1070 if (temp.len == 0) {
1071 /* make sure that we send an USB packet */
1076 /* regular data transfer */
1078 temp.short_pkt = (xfer->flags.force_short_xfer) ? 0 : 1;
1081 octusb_setup_standard_chain_sub(&temp);
1083 if (xfer->flags_int.isochronous_xfr) {
1084 /* get next data offset */
1085 temp.offset += temp.len;
1087 /* get next Page Cache pointer */
1088 temp.pc = xfer->frbuffers + x;
1092 /* check if we should append a status stage */
1094 if (xfer->flags_int.control_xfr &&
1095 !xfer->flags_int.control_act) {
1096 temp.func = &octusb_host_control_status_tx;
1100 temp.setup_alt_next = 0;
1102 octusb_setup_standard_chain_sub(&temp);
1104 /* must have at least one frame! */
1106 xfer->td_transfer_last = td;
1108 /* properly setup QH */
1110 td->qh->ep_allocated = 0;
1111 td->qh->ep_toggle_next = xfer->endpoint->toggle_next ? 1 : 0;
1114 /*------------------------------------------------------------------------*
1115 * octusb_device_done - OCTUSB transfers done code
1117 * NOTE: This function can be called more than one time in a row.
1118 *------------------------------------------------------------------------*/
1120 octusb_device_done(struct usb_xfer *xfer, usb_error_t error)
1122 USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
1124 DPRINTFN(2, "xfer=%p, endpoint=%p, error=%d\n",
1125 xfer, xfer->endpoint, error);
1128 * 1) Free any endpoints.
1129 * 2) Control transfers can be split and we should not re-open
1130 * the data pipe between transactions unless there is an error.
1132 if ((xfer->flags_int.control_act == 0) || (error != 0)) {
1133 struct octusb_td *td;
1135 td = xfer->td_start[0];
1137 octusb_host_free_endpoint(td);
1139 /* dequeue transfer and start next transfer */
1140 usbd_transfer_done(xfer, error);
1143 /*------------------------------------------------------------------------*
1144 * octusb bulk support
1145 *------------------------------------------------------------------------*/
1147 octusb_device_bulk_open(struct usb_xfer *xfer)
1153 octusb_device_bulk_close(struct usb_xfer *xfer)
1155 octusb_device_done(xfer, USB_ERR_CANCELLED);
1159 octusb_device_bulk_enter(struct usb_xfer *xfer)
1165 octusb_device_bulk_start(struct usb_xfer *xfer)
1168 octusb_setup_standard_chain(xfer);
1169 octusb_start_standard_chain(xfer);
1172 struct usb_pipe_methods octusb_device_bulk_methods =
1174 .open = octusb_device_bulk_open,
1175 .close = octusb_device_bulk_close,
1176 .enter = octusb_device_bulk_enter,
1177 .start = octusb_device_bulk_start,
1180 /*------------------------------------------------------------------------*
1181 * octusb control support
1182 *------------------------------------------------------------------------*/
1184 octusb_device_ctrl_open(struct usb_xfer *xfer)
1190 octusb_device_ctrl_close(struct usb_xfer *xfer)
1192 octusb_device_done(xfer, USB_ERR_CANCELLED);
1196 octusb_device_ctrl_enter(struct usb_xfer *xfer)
1202 octusb_device_ctrl_start(struct usb_xfer *xfer)
1205 octusb_setup_standard_chain(xfer);
1206 octusb_start_standard_chain(xfer);
1209 struct usb_pipe_methods octusb_device_ctrl_methods =
1211 .open = octusb_device_ctrl_open,
1212 .close = octusb_device_ctrl_close,
1213 .enter = octusb_device_ctrl_enter,
1214 .start = octusb_device_ctrl_start,
1217 /*------------------------------------------------------------------------*
1218 * octusb interrupt support
1219 *------------------------------------------------------------------------*/
1221 octusb_device_intr_open(struct usb_xfer *xfer)
1227 octusb_device_intr_close(struct usb_xfer *xfer)
1229 octusb_device_done(xfer, USB_ERR_CANCELLED);
1233 octusb_device_intr_enter(struct usb_xfer *xfer)
1239 octusb_device_intr_start(struct usb_xfer *xfer)
1242 octusb_setup_standard_chain(xfer);
1243 octusb_start_standard_chain(xfer);
1246 struct usb_pipe_methods octusb_device_intr_methods =
1248 .open = octusb_device_intr_open,
1249 .close = octusb_device_intr_close,
1250 .enter = octusb_device_intr_enter,
1251 .start = octusb_device_intr_start,
1254 /*------------------------------------------------------------------------*
1255 * octusb isochronous support
1256 *------------------------------------------------------------------------*/
1258 octusb_device_isoc_open(struct usb_xfer *xfer)
1264 octusb_device_isoc_close(struct usb_xfer *xfer)
1266 octusb_device_done(xfer, USB_ERR_CANCELLED);
1270 octusb_device_isoc_enter(struct usb_xfer *xfer)
1272 struct octusb_softc *sc = OCTUSB_BUS2SC(xfer->xroot->bus);
1274 uint32_t frame_count;
1277 DPRINTFN(5, "xfer=%p next=%d nframes=%d\n",
1278 xfer, xfer->endpoint->isoc_next, xfer->nframes);
1280 /* get the current frame index */
1282 frame_count = cvmx_usb_get_frame_number(
1283 &sc->sc_port[xfer->xroot->udev->port_index].state);
1286 * check if the frame index is within the window where the frames
1289 temp = (frame_count - xfer->endpoint->isoc_next) & 0x7FF;
1291 if (usbd_get_speed(xfer->xroot->udev) == USB_SPEED_HIGH) {
1292 fs_frames = (xfer->nframes + 7) / 8;
1294 fs_frames = xfer->nframes;
1297 if ((xfer->endpoint->is_synced == 0) || (temp < fs_frames)) {
1299 * If there is data underflow or the pipe queue is
1300 * empty we schedule the transfer a few frames ahead
1301 * of the current frame position. Else two isochronous
1302 * transfers might overlap.
1304 xfer->endpoint->isoc_next = (frame_count + 3) & 0x7FF;
1305 xfer->endpoint->is_synced = 1;
1306 DPRINTFN(2, "start next=%d\n", xfer->endpoint->isoc_next);
1309 * compute how many milliseconds the insertion is ahead of the
1310 * current frame position:
1312 temp = (xfer->endpoint->isoc_next - frame_count) & 0x7FF;
1315 * pre-compute when the isochronous transfer will be finished:
1317 xfer->isoc_time_complete =
1318 usb_isoc_time_expand(&sc->sc_bus, frame_count) + temp +
1321 /* compute frame number for next insertion */
1322 xfer->endpoint->isoc_next += fs_frames;
1326 octusb_device_isoc_start(struct usb_xfer *xfer)
1329 octusb_setup_standard_chain(xfer);
1330 octusb_start_standard_chain(xfer);
1333 struct usb_pipe_methods octusb_device_isoc_methods =
1335 .open = octusb_device_isoc_open,
1336 .close = octusb_device_isoc_close,
1337 .enter = octusb_device_isoc_enter,
1338 .start = octusb_device_isoc_start,
1341 /*------------------------------------------------------------------------*
1342 * OCTUSB root HUB support
1343 *------------------------------------------------------------------------*
1344 * Simulate a hardware HUB by handling all the necessary requests.
1345 *------------------------------------------------------------------------*/
1347 struct usb_device_descriptor octusb_devd = {
1348 .bLength = sizeof(octusb_devd),
1349 .bDescriptorType = UDESC_DEVICE,
1350 .bcdUSB = {0x00, 0x02},
1351 .bDeviceClass = UDCLASS_HUB,
1352 .bDeviceSubClass = UDSUBCLASS_HUB,
1353 .bDeviceProtocol = UDPROTO_FSHUB,
1354 .bMaxPacketSize = 64,
1357 .bcdDevice = {0x00, 0x01},
1361 .bNumConfigurations = 1,
1365 struct usb_device_qualifier octusb_odevd = {
1366 .bLength = sizeof(octusb_odevd),
1367 .bDescriptorType = UDESC_DEVICE_QUALIFIER,
1368 .bcdUSB = {0x00, 0x02},
1369 .bDeviceClass = UDCLASS_HUB,
1370 .bDeviceSubClass = UDSUBCLASS_HUB,
1371 .bDeviceProtocol = UDPROTO_FSHUB,
1372 .bMaxPacketSize0 = 0,
1373 .bNumConfigurations = 0,
1378 struct octusb_config_desc octusb_confd = {
1380 .bLength = sizeof(struct usb_config_descriptor),
1381 .bDescriptorType = UDESC_CONFIG,
1382 .wTotalLength[0] = sizeof(octusb_confd),
1384 .bConfigurationValue = 1,
1385 .iConfiguration = 0,
1386 .bmAttributes = UC_SELF_POWERED,
1387 .bMaxPower = 0 /* max power */
1390 .bLength = sizeof(struct usb_interface_descriptor),
1391 .bDescriptorType = UDESC_INTERFACE,
1393 .bInterfaceClass = UICLASS_HUB,
1394 .bInterfaceSubClass = UISUBCLASS_HUB,
1395 .bInterfaceProtocol = UIPROTO_FSHUB,
1398 .bLength = sizeof(struct usb_endpoint_descriptor),
1399 .bDescriptorType = UDESC_ENDPOINT,
1400 .bEndpointAddress = UE_DIR_IN | OCTUSB_INTR_ENDPT,
1401 .bmAttributes = UE_INTERRUPT,
1402 .wMaxPacketSize[0] = 8, /* max packet (63 ports) */
1408 struct usb_hub_descriptor_min octusb_hubd =
1410 .bDescLength = sizeof(octusb_hubd),
1411 .bDescriptorType = UDESC_HUB,
1413 .wHubCharacteristics = {UHD_PWR_NO_SWITCH | UHD_OC_INDIVIDUAL, 0},
1414 .bPwrOn2PwrGood = 50,
1415 .bHubContrCurrent = 0,
1416 .DeviceRemovable = {0x00}, /* all ports are removable */
1420 octusb_roothub_exec(struct usb_device *udev,
1421 struct usb_device_request *req, const void **pptr, uint16_t *plength)
1423 struct octusb_softc *sc = OCTUSB_BUS2SC(udev->bus);
1425 const char *str_ptr;
1432 cvmx_usb_port_status_t usb_port_status;
1434 USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
1436 /* XXX disable power save mode, hence it is not supported */
1437 udev->power_mode = USB_POWER_MODE_ON;
1440 ptr = (const void *)&sc->sc_hub_desc.temp;
1444 value = UGETW(req->wValue);
1445 index = UGETW(req->wIndex);
1447 DPRINTFN(3, "type=0x%02x request=0x%02x wLen=0x%04x "
1448 "wValue=0x%04x wIndex=0x%04x\n",
1449 req->bmRequestType, req->bRequest,
1450 UGETW(req->wLength), value, index);
1452 #define C(x,y) ((x) | ((y) << 8))
1453 switch (C(req->bRequest, req->bmRequestType)) {
1454 case C(UR_CLEAR_FEATURE, UT_WRITE_DEVICE):
1455 case C(UR_CLEAR_FEATURE, UT_WRITE_INTERFACE):
1456 case C(UR_CLEAR_FEATURE, UT_WRITE_ENDPOINT):
1458 case C(UR_GET_CONFIG, UT_READ_DEVICE):
1460 sc->sc_hub_desc.temp[0] = sc->sc_conf;
1462 case C(UR_GET_DESCRIPTOR, UT_READ_DEVICE):
1463 switch (value >> 8) {
1465 if ((value & 0xff) != 0) {
1466 err = USB_ERR_IOERROR;
1469 len = sizeof(octusb_devd);
1471 ptr = (const void *)&octusb_devd;
1474 case UDESC_DEVICE_QUALIFIER:
1475 if ((value & 0xff) != 0) {
1476 err = USB_ERR_IOERROR;
1479 len = sizeof(octusb_odevd);
1480 ptr = (const void *)&octusb_odevd;
1484 if ((value & 0xff) != 0) {
1485 err = USB_ERR_IOERROR;
1488 len = sizeof(octusb_confd);
1489 ptr = (const void *)&octusb_confd;
1493 switch (value & 0xff) {
1494 case 0: /* Language table */
1498 case 1: /* Vendor */
1499 str_ptr = "Cavium Networks";
1502 case 2: /* Product */
1503 str_ptr = "OCTUSB Root HUB";
1511 len = usb_make_str_desc(sc->sc_hub_desc.temp,
1512 sizeof(sc->sc_hub_desc.temp), str_ptr);
1516 err = USB_ERR_IOERROR;
1520 case C(UR_GET_INTERFACE, UT_READ_INTERFACE):
1522 sc->sc_hub_desc.temp[0] = 0;
1524 case C(UR_GET_STATUS, UT_READ_DEVICE):
1526 USETW(sc->sc_hub_desc.stat.wStatus, UDS_SELF_POWERED);
1528 case C(UR_GET_STATUS, UT_READ_INTERFACE):
1529 case C(UR_GET_STATUS, UT_READ_ENDPOINT):
1531 USETW(sc->sc_hub_desc.stat.wStatus, 0);
1533 case C(UR_SET_ADDRESS, UT_WRITE_DEVICE):
1534 if (value >= OCTUSB_MAX_DEVICES) {
1535 err = USB_ERR_IOERROR;
1538 sc->sc_addr = value;
1540 case C(UR_SET_CONFIG, UT_WRITE_DEVICE):
1541 if ((value != 0) && (value != 1)) {
1542 err = USB_ERR_IOERROR;
1545 sc->sc_conf = value;
1547 case C(UR_SET_DESCRIPTOR, UT_WRITE_DEVICE):
1549 case C(UR_SET_FEATURE, UT_WRITE_DEVICE):
1550 case C(UR_SET_FEATURE, UT_WRITE_INTERFACE):
1551 case C(UR_SET_FEATURE, UT_WRITE_ENDPOINT):
1552 err = USB_ERR_IOERROR;
1554 case C(UR_SET_INTERFACE, UT_WRITE_INTERFACE):
1556 case C(UR_SYNCH_FRAME, UT_WRITE_ENDPOINT):
1559 case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_DEVICE):
1561 case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_OTHER):
1562 DPRINTFN(4, "UR_CLEAR_PORT_FEATURE "
1563 "port=%d feature=%d\n",
1566 (index > sc->sc_noport) ||
1567 sc->sc_port[index - 1].disabled) {
1568 err = USB_ERR_IOERROR;
1574 case UHF_PORT_ENABLE:
1575 cvmx_usb_disable(&sc->sc_port[index].state);
1577 case UHF_PORT_SUSPEND:
1578 case UHF_PORT_RESET:
1580 case UHF_C_PORT_CONNECTION:
1581 cvmx_usb_set_status(&sc->sc_port[index].state,
1582 cvmx_usb_get_status(&sc->sc_port[index].state));
1584 case UHF_C_PORT_ENABLE:
1585 cvmx_usb_set_status(&sc->sc_port[index].state,
1586 cvmx_usb_get_status(&sc->sc_port[index].state));
1588 case UHF_C_PORT_OVER_CURRENT:
1589 cvmx_usb_set_status(&sc->sc_port[index].state,
1590 cvmx_usb_get_status(&sc->sc_port[index].state));
1592 case UHF_C_PORT_RESET:
1595 case UHF_C_PORT_SUSPEND:
1597 case UHF_PORT_CONNECTION:
1598 case UHF_PORT_OVER_CURRENT:
1599 case UHF_PORT_POWER:
1600 case UHF_PORT_LOW_SPEED:
1602 err = USB_ERR_IOERROR;
1606 case C(UR_GET_DESCRIPTOR, UT_READ_CLASS_DEVICE):
1607 if ((value & 0xff) != 0) {
1608 err = USB_ERR_IOERROR;
1611 sc->sc_hubd = octusb_hubd;
1612 sc->sc_hubd.bNbrPorts = sc->sc_noport;
1613 len = sizeof(sc->sc_hubd);
1614 ptr = (const void *)&sc->sc_hubd;
1616 case C(UR_GET_STATUS, UT_READ_CLASS_DEVICE):
1618 memset(sc->sc_hub_desc.temp, 0, 16);
1620 case C(UR_GET_STATUS, UT_READ_CLASS_OTHER):
1622 (index > sc->sc_noport) ||
1623 sc->sc_port[index - 1].disabled) {
1624 err = USB_ERR_IOERROR;
1629 usb_port_status = cvmx_usb_get_status(&sc->sc_port[index].state);
1631 status = change = 0;
1632 if (usb_port_status.connected)
1633 status |= UPS_CURRENT_CONNECT_STATUS;
1634 if (usb_port_status.port_enabled)
1635 status |= UPS_PORT_ENABLED;
1636 if (usb_port_status.port_over_current)
1637 status |= UPS_OVERCURRENT_INDICATOR;
1638 if (usb_port_status.port_powered)
1639 status |= UPS_PORT_POWER;
1641 switch (usb_port_status.port_speed) {
1642 case CVMX_USB_SPEED_HIGH:
1643 status |= UPS_HIGH_SPEED;
1645 case CVMX_USB_SPEED_FULL:
1648 status |= UPS_LOW_SPEED;
1652 if (usb_port_status.connect_change)
1653 change |= UPS_C_CONNECT_STATUS;
1655 change |= UPS_C_PORT_RESET;
1657 USETW(sc->sc_hub_desc.ps.wPortStatus, status);
1658 USETW(sc->sc_hub_desc.ps.wPortChange, change);
1660 len = sizeof(sc->sc_hub_desc.ps);
1662 case C(UR_SET_DESCRIPTOR, UT_WRITE_CLASS_DEVICE):
1663 err = USB_ERR_IOERROR;
1665 case C(UR_SET_FEATURE, UT_WRITE_CLASS_DEVICE):
1667 case C(UR_SET_FEATURE, UT_WRITE_CLASS_OTHER):
1669 (index > sc->sc_noport) ||
1670 sc->sc_port[index - 1].disabled) {
1671 err = USB_ERR_IOERROR;
1677 case UHF_PORT_ENABLE:
1679 case UHF_PORT_RESET:
1680 cvmx_usb_disable(&sc->sc_port[index].state);
1681 if (cvmx_usb_enable(&sc->sc_port[index].state)) {
1682 err = USB_ERR_IOERROR;
1687 case UHF_PORT_POWER:
1688 /* pretend we turned on power */
1690 case UHF_PORT_SUSPEND:
1691 case UHF_C_PORT_CONNECTION:
1692 case UHF_C_PORT_ENABLE:
1693 case UHF_C_PORT_OVER_CURRENT:
1694 case UHF_PORT_CONNECTION:
1695 case UHF_PORT_OVER_CURRENT:
1696 case UHF_PORT_LOW_SPEED:
1697 case UHF_C_PORT_SUSPEND:
1698 case UHF_C_PORT_RESET:
1700 err = USB_ERR_IOERROR;
1705 err = USB_ERR_IOERROR;
1715 octusb_xfer_setup(struct usb_setup_params *parm)
1717 struct usb_page_search page_info;
1718 struct usb_page_cache *pc;
1719 struct octusb_softc *sc;
1720 struct octusb_qh *qh;
1721 struct usb_xfer *xfer;
1722 struct usb_device *hub;
1727 sc = OCTUSB_BUS2SC(parm->udev->bus);
1728 xfer = parm->curr_xfer;
1732 * NOTE: This driver does not use any of the parameters that
1733 * are computed from the following values. Just set some
1734 * reasonable dummies:
1737 parm->hc_max_packet_size = 0x400;
1738 parm->hc_max_packet_count = 3;
1739 parm->hc_max_frame_size = 0xC00;
1741 usbd_transfer_setup_sub(parm);
1746 /* Allocate a queue head */
1748 if (usbd_transfer_setup_sub_malloc(
1749 parm, &pc, sizeof(struct octusb_qh),
1750 USB_HOST_ALIGN, 1)) {
1751 parm->err = USB_ERR_NOMEM;
1755 usbd_get_page(pc, 0, &page_info);
1757 qh = page_info.buffer;
1761 qh->sc = OCTUSB_BUS2SC(xfer->xroot->bus);
1762 qh->max_frame_size = xfer->max_frame_size;
1763 qh->max_packet_size = xfer->max_packet_size;
1764 qh->ep_num = xfer->endpointno;
1765 qh->ep_type = xfer->endpoint->edesc->bmAttributes;
1766 qh->dev_addr = xfer->address;
1767 qh->dev_speed = usbd_get_speed(xfer->xroot->udev);
1768 qh->root_port_index = xfer->xroot->udev->port_index;
1769 /* We need Octeon USB HUB's port index, not the local port */
1770 hub = xfer->xroot->udev->parent_hub;
1771 while(hub && hub->parent_hub) {
1772 qh->root_port_index = hub->port_index;
1773 hub = hub->parent_hub;
1776 switch (xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE) {
1778 if (usbd_get_speed(xfer->xroot->udev) == USB_SPEED_HIGH)
1779 qh->ep_interval = xfer->interval * 8;
1781 qh->ep_interval = xfer->interval * 1;
1783 case UE_ISOCHRONOUS:
1784 qh->ep_interval = 1 << xfer->fps_shift;
1787 qh->ep_interval = 0;
1791 qh->ep_mult = xfer->max_packet_count & 3;
1792 qh->hs_hub_addr = xfer->xroot->udev->hs_hub_addr;
1793 qh->hs_hub_port = xfer->xroot->udev->hs_port_no;
1795 xfer->qh_start[0] = qh;
1797 /* Allocate a fixup buffer */
1799 if (usbd_transfer_setup_sub_malloc(
1800 parm, &pc, OCTUSB_MAX_FIXUP,
1801 OCTUSB_MAX_FIXUP, 1)) {
1802 parm->err = USB_ERR_NOMEM;
1806 usbd_get_page(pc, 0, &page_info);
1808 qh->fixup_phys = page_info.physaddr;
1810 qh->fixup_buf = page_info.buffer;
1812 /* Allocate transfer descriptors */
1816 ntd = xfer->nframes + 1 /* STATUS */ + 1 /* SYNC */ ;
1818 if (usbd_transfer_setup_sub_malloc(
1819 parm, &pc, sizeof(struct octusb_td),
1820 USB_HOST_ALIGN, ntd)) {
1821 parm->err = USB_ERR_NOMEM;
1825 for (n = 0; n != ntd; n++) {
1826 struct octusb_td *td;
1828 usbd_get_page(pc + n, 0, &page_info);
1830 td = page_info.buffer;
1833 td->obj_next = last_obj;
1838 xfer->td_start[0] = last_obj;
1842 octusb_ep_init(struct usb_device *udev, struct usb_endpoint_descriptor *edesc,
1843 struct usb_endpoint *ep)
1845 struct octusb_softc *sc = OCTUSB_BUS2SC(udev->bus);
1847 DPRINTFN(2, "endpoint=%p, addr=%d, endpt=%d, mode=%d (%d)\n",
1848 ep, udev->address, edesc->bEndpointAddress,
1849 udev->flags.usb_mode, sc->sc_addr);
1851 if (udev->device_index != sc->sc_addr) {
1852 switch (edesc->bmAttributes & UE_XFERTYPE) {
1854 ep->methods = &octusb_device_ctrl_methods;
1857 ep->methods = &octusb_device_intr_methods;
1859 case UE_ISOCHRONOUS:
1860 if (udev->speed != USB_SPEED_LOW)
1861 ep->methods = &octusb_device_isoc_methods;
1864 ep->methods = &octusb_device_bulk_methods;
1874 octusb_xfer_unsetup(struct usb_xfer *xfer)
1876 DPRINTF("Nothing to do.\n");
1880 octusb_get_dma_delay(struct usb_device *udev, uint32_t *pus)
1882 /* DMA delay - wait until any use of memory is finished */
1883 *pus = (2125); /* microseconds */
1887 octusb_device_resume(struct usb_device *udev)
1889 DPRINTF("Nothing to do.\n");
1893 octusb_device_suspend(struct usb_device *udev)
1895 DPRINTF("Nothing to do.\n");
1899 octusb_set_hw_power(struct usb_bus *bus)
1901 DPRINTF("Nothing to do.\n");
1905 octusb_set_hw_power_sleep(struct usb_bus *bus, uint32_t state)
1907 struct octusb_softc *sc = OCTUSB_BUS2SC(bus);
1910 case USB_HW_POWER_SUSPEND:
1913 case USB_HW_POWER_SHUTDOWN:
1916 case USB_HW_POWER_RESUME:
1924 struct usb_bus_methods octusb_bus_methods = {
1925 .endpoint_init = octusb_ep_init,
1926 .xfer_setup = octusb_xfer_setup,
1927 .xfer_unsetup = octusb_xfer_unsetup,
1928 .get_dma_delay = octusb_get_dma_delay,
1929 .device_resume = octusb_device_resume,
1930 .device_suspend = octusb_device_suspend,
1931 .set_hw_power = octusb_set_hw_power,
1932 .set_hw_power_sleep = octusb_set_hw_power_sleep,
1933 .roothub_exec = octusb_roothub_exec,
1934 .xfer_poll = octusb_do_poll,