| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ohci.c,v 1.297 2020/03/05 08:12:30 skrll Exp $ */ | | 1 | /* $NetBSD: ohci.c,v 1.298 2020/03/05 08:30:58 skrll Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1998, 2004, 2005, 2012 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1998, 2004, 2005, 2012 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Lennart Augustsson (lennart@augustsson.net) at | | 8 | * by Lennart Augustsson (lennart@augustsson.net) at |
9 | * Carlstedt Research & Technology, Jared D. McNeill (jmcneill@invisible.ca) | | 9 | * Carlstedt Research & Technology, Jared D. McNeill (jmcneill@invisible.ca) |
10 | * and Matthew R. Green (mrg@eterna.com.au). | | 10 | * and Matthew R. Green (mrg@eterna.com.au). |
11 | * This code is derived from software contributed to The NetBSD Foundation | | 11 | * This code is derived from software contributed to The NetBSD Foundation |
12 | * by Charles M. Hannum. | | 12 | * by Charles M. Hannum. |
13 | * | | 13 | * |
14 | * Redistribution and use in source and binary forms, with or without | | 14 | * Redistribution and use in source and binary forms, with or without |
| @@ -31,27 +31,27 @@ | | | @@ -31,27 +31,27 @@ |
31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
33 | * POSSIBILITY OF SUCH DAMAGE. | | 33 | * POSSIBILITY OF SUCH DAMAGE. |
34 | */ | | 34 | */ |
35 | | | 35 | |
36 | /* | | 36 | /* |
37 | * USB Open Host Controller driver. | | 37 | * USB Open Host Controller driver. |
38 | * | | 38 | * |
39 | * OHCI spec: http://www.compaq.com/productinfo/development/openhci.html | | 39 | * OHCI spec: http://www.compaq.com/productinfo/development/openhci.html |
40 | * USB spec: http://www.usb.org/developers/docs/ | | 40 | * USB spec: http://www.usb.org/developers/docs/ |
41 | */ | | 41 | */ |
42 | | | 42 | |
43 | #include <sys/cdefs.h> | | 43 | #include <sys/cdefs.h> |
44 | __KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.297 2020/03/05 08:12:30 skrll Exp $"); | | 44 | __KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.298 2020/03/05 08:30:58 skrll Exp $"); |
45 | | | 45 | |
46 | #ifdef _KERNEL_OPT | | 46 | #ifdef _KERNEL_OPT |
47 | #include "opt_usb.h" | | 47 | #include "opt_usb.h" |
48 | #endif | | 48 | #endif |
49 | | | 49 | |
50 | #include <sys/param.h> | | 50 | #include <sys/param.h> |
51 | | | 51 | |
52 | #include <sys/cpu.h> | | 52 | #include <sys/cpu.h> |
53 | #include <sys/device.h> | | 53 | #include <sys/device.h> |
54 | #include <sys/kernel.h> | | 54 | #include <sys/kernel.h> |
55 | #include <sys/kmem.h> | | 55 | #include <sys/kmem.h> |
56 | #include <sys/proc.h> | | 56 | #include <sys/proc.h> |
57 | #include <sys/queue.h> | | 57 | #include <sys/queue.h> |
| @@ -521,27 +521,27 @@ ohci_alloc_std_chain(ohci_softc_t *sc, s | | | @@ -521,27 +521,27 @@ ohci_alloc_std_chain(ohci_softc_t *sc, s |
521 | uint16_t flags = xfer->ux_flags; | | 521 | uint16_t flags = xfer->ux_flags; |
522 | | | 522 | |
523 | OHCIHIST_FUNC(); OHCIHIST_CALLED(); | | 523 | OHCIHIST_FUNC(); OHCIHIST_CALLED(); |
524 | | | 524 | |
525 | DPRINTFN(8, "addr=%jd endpt=%jd len=%jd speed=%jd", | | 525 | DPRINTFN(8, "addr=%jd endpt=%jd len=%jd speed=%jd", |
526 | xfer->ux_pipe->up_dev->ud_addr, | | 526 | xfer->ux_pipe->up_dev->ud_addr, |
527 | UE_GET_ADDR(xfer->ux_pipe->up_endpoint->ue_edesc->bEndpointAddress), | | 527 | UE_GET_ADDR(xfer->ux_pipe->up_endpoint->ue_edesc->bEndpointAddress), |
528 | length, xfer->ux_pipe->up_dev->ud_speed); | | 528 | length, xfer->ux_pipe->up_dev->ud_speed); |
529 | | | 529 | |
530 | ASSERT_SLEEPABLE(); | | 530 | ASSERT_SLEEPABLE(); |
531 | KASSERT(length != 0 || (!rd && (flags & USBD_FORCE_SHORT_XFER))); | | 531 | KASSERT(length != 0 || (!rd && (flags & USBD_FORCE_SHORT_XFER))); |
532 | | | 532 | |
533 | size_t nstd = (!rd && (flags & USBD_FORCE_SHORT_XFER)) ? 1 : 0; | | 533 | size_t nstd = (!rd && (flags & USBD_FORCE_SHORT_XFER)) ? 1 : 0; |
534 | nstd += ((length + OHCI_PAGE_SIZE - 1) / OHCI_PAGE_SIZE); | | 534 | nstd += howmany(length, OHCI_PAGE_SIZE); |
535 | ox->ox_stds = kmem_zalloc(sizeof(ohci_soft_td_t *) * nstd, | | 535 | ox->ox_stds = kmem_zalloc(sizeof(ohci_soft_td_t *) * nstd, |
536 | KM_SLEEP); | | 536 | KM_SLEEP); |
537 | ox->ox_nstd = nstd; | | 537 | ox->ox_nstd = nstd; |
538 | | | 538 | |
539 | DPRINTFN(8, "xfer %#jx nstd %jd", (uintptr_t)xfer, nstd, 0, 0); | | 539 | DPRINTFN(8, "xfer %#jx nstd %jd", (uintptr_t)xfer, nstd, 0, 0); |
540 | | | 540 | |
541 | for (size_t j = 0; j < ox->ox_nstd;) { | | 541 | for (size_t j = 0; j < ox->ox_nstd;) { |
542 | ohci_soft_td_t *cur = ohci_alloc_std(sc); | | 542 | ohci_soft_td_t *cur = ohci_alloc_std(sc); |
543 | if (cur == NULL) | | 543 | if (cur == NULL) |
544 | goto nomem; | | 544 | goto nomem; |
545 | | | 545 | |
546 | ox->ox_stds[j++] = cur; | | 546 | ox->ox_stds[j++] = cur; |
547 | cur->xfer = xfer; | | 547 | cur->xfer = xfer; |
| @@ -3348,28 +3348,27 @@ Static int | | | @@ -3348,28 +3348,27 @@ Static int |
3348 | ohci_device_isoc_init(struct usbd_xfer *xfer) | | 3348 | ohci_device_isoc_init(struct usbd_xfer *xfer) |
3349 | { | | 3349 | { |
3350 | struct ohci_xfer *ox = OHCI_XFER2OXFER(xfer); | | 3350 | struct ohci_xfer *ox = OHCI_XFER2OXFER(xfer); |
3351 | ohci_softc_t *sc = OHCI_XFER2SC(xfer); | | 3351 | ohci_softc_t *sc = OHCI_XFER2SC(xfer); |
3352 | ohci_soft_itd_t *sitd; | | 3352 | ohci_soft_itd_t *sitd; |
3353 | size_t i; | | 3353 | size_t i; |
3354 | int err; | | 3354 | int err; |
3355 | | | 3355 | |
3356 | OHCIHIST_FUNC(); OHCIHIST_CALLED(); | | 3356 | OHCIHIST_FUNC(); OHCIHIST_CALLED(); |
3357 | | | 3357 | |
3358 | DPRINTFN(1, "xfer %#jx len %jd flags %jd", (uintptr_t)xfer, | | 3358 | DPRINTFN(1, "xfer %#jx len %jd flags %jd", (uintptr_t)xfer, |
3359 | xfer->ux_length, xfer->ux_flags, 0); | | 3359 | xfer->ux_length, xfer->ux_flags, 0); |
3360 | | | 3360 | |
3361 | const size_t nfsitd = | | 3361 | const size_t nfsitd = howmany(xfer->ux_nframes, OHCI_ITD_NOFFSET); |
3362 | (xfer->ux_nframes + OHCI_ITD_NOFFSET - 1) / OHCI_ITD_NOFFSET; | | | |
3363 | const size_t nbsitd = xfer->ux_bufsize / OHCI_PAGE_SIZE; | | 3362 | const size_t nbsitd = xfer->ux_bufsize / OHCI_PAGE_SIZE; |
3364 | const size_t nsitd = MAX(nfsitd, nbsitd) + 1; | | 3363 | const size_t nsitd = MAX(nfsitd, nbsitd) + 1; |
3365 | | | 3364 | |
3366 | ox->ox_sitds = kmem_zalloc(sizeof(ohci_soft_itd_t *) * nsitd, | | 3365 | ox->ox_sitds = kmem_zalloc(sizeof(ohci_soft_itd_t *) * nsitd, |
3367 | KM_SLEEP); | | 3366 | KM_SLEEP); |
3368 | ox->ox_nsitd = nsitd; | | 3367 | ox->ox_nsitd = nsitd; |
3369 | | | 3368 | |
3370 | for (i = 0; i < nsitd; i++) { | | 3369 | for (i = 0; i < nsitd; i++) { |
3371 | /* Allocate next ITD */ | | 3370 | /* Allocate next ITD */ |
3372 | sitd = ohci_alloc_sitd(sc); | | 3371 | sitd = ohci_alloc_sitd(sc); |
3373 | if (sitd == NULL) { | | 3372 | if (sitd == NULL) { |
3374 | err = ENOMEM; | | 3373 | err = ENOMEM; |
3375 | goto fail; | | 3374 | goto fail; |