More converstion from usbd_status to int for function error reporting. This time it's the turn of usb_allocmem.diff -r1.284 -r1.285 src/sys/dev/usb/ehci.c
(skrll)
--- src/sys/dev/usb/ehci.c 2020/12/22 01:07:23 1.284
+++ src/sys/dev/usb/ehci.c 2021/01/05 18:00:21 1.285
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ehci.c,v 1.284 2020/12/22 01:07:23 riastradh Exp $ */ | 1 | /* $NetBSD: ehci.c,v 1.285 2021/01/05 18:00:21 skrll Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2004-2012,2016,2020 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2004-2012,2016,2020 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), Charles M. Hannum, | 8 | * by Lennart Augustsson (lennart@augustsson.net), Charles M. Hannum, | |
9 | * Jeremy Morse (jeremy.morse@gmail.com), Jared D. McNeill | 9 | * Jeremy Morse (jeremy.morse@gmail.com), Jared D. McNeill | |
10 | * (jmcneill@invisible.ca). Matthew R. Green (mrg@eterna.com.au), and | 10 | * (jmcneill@invisible.ca). Matthew R. Green (mrg@eterna.com.au), and | |
11 | * Nick Hudson . | 11 | * Nick Hudson . | |
12 | * | 12 | * | |
13 | * Redistribution and use in source and binary forms, with or without | 13 | * Redistribution and use in source and binary forms, with or without | |
14 | * modification, are permitted provided that the following conditions | 14 | * modification, are permitted provided that the following conditions | |
@@ -44,27 +44,27 @@ | @@ -44,27 +44,27 @@ | |||
44 | 44 | |||
45 | /* | 45 | /* | |
46 | * TODO: | 46 | * TODO: | |
47 | * 1) hold off explorations by companion controllers until ehci has started. | 47 | * 1) hold off explorations by companion controllers until ehci has started. | |
48 | * | 48 | * | |
49 | * 2) The hub driver needs to handle and schedule the transaction translator, | 49 | * 2) The hub driver needs to handle and schedule the transaction translator, | |
50 | * to assign place in frame where different devices get to go. See chapter | 50 | * to assign place in frame where different devices get to go. See chapter | |
51 | * on hubs in USB 2.0 for details. | 51 | * on hubs in USB 2.0 for details. | |
52 | * | 52 | * | |
53 | * 3) Command failures are not recovered correctly. | 53 | * 3) Command failures are not recovered correctly. | |
54 | */ | 54 | */ | |
55 | 55 | |||
56 | #include <sys/cdefs.h> | 56 | #include <sys/cdefs.h> | |
57 | __KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.284 2020/12/22 01:07:23 riastradh Exp $"); | 57 | __KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.285 2021/01/05 18:00:21 skrll Exp $"); | |
58 | 58 | |||
59 | #include "ohci.h" | 59 | #include "ohci.h" | |
60 | #include "uhci.h" | 60 | #include "uhci.h" | |
61 | 61 | |||
62 | #ifdef _KERNEL_OPT | 62 | #ifdef _KERNEL_OPT | |
63 | #include "opt_usb.h" | 63 | #include "opt_usb.h" | |
64 | #endif | 64 | #endif | |
65 | 65 | |||
66 | #include <sys/param.h> | 66 | #include <sys/param.h> | |
67 | 67 | |||
68 | #include <sys/bus.h> | 68 | #include <sys/bus.h> | |
69 | #include <sys/cpu.h> | 69 | #include <sys/cpu.h> | |
70 | #include <sys/device.h> | 70 | #include <sys/device.h> | |
@@ -2835,39 +2835,40 @@ ehci_alloc_sqh(ehci_softc_t *sc) | @@ -2835,39 +2835,40 @@ ehci_alloc_sqh(ehci_softc_t *sc) | |||
2835 | Static void | 2835 | Static void | |
2836 | ehci_free_sqh(ehci_softc_t *sc, ehci_soft_qh_t *sqh) | 2836 | ehci_free_sqh(ehci_softc_t *sc, ehci_soft_qh_t *sqh) | |
2837 | { | 2837 | { | |
2838 | KASSERT(mutex_owned(&sc->sc_lock)); | 2838 | KASSERT(mutex_owned(&sc->sc_lock)); | |
2839 | 2839 | |||
2840 | sqh->next = sc->sc_freeqhs; | 2840 | sqh->next = sc->sc_freeqhs; | |
2841 | sc->sc_freeqhs = sqh; | 2841 | sc->sc_freeqhs = sqh; | |
2842 | } | 2842 | } | |
2843 | 2843 | |||
2844 | Static ehci_soft_qtd_t * | 2844 | Static ehci_soft_qtd_t * | |
2845 | ehci_alloc_sqtd(ehci_softc_t *sc) | 2845 | ehci_alloc_sqtd(ehci_softc_t *sc) | |
2846 | { | 2846 | { | |
2847 | ehci_soft_qtd_t *sqtd = NULL; | 2847 | ehci_soft_qtd_t *sqtd = NULL; | |
2848 | usbd_status err; | |||
2849 | int i, offs; | 2848 | int i, offs; | |
2850 | usb_dma_t dma; | 2849 | usb_dma_t dma; | |
2851 | 2850 | |||
2852 | EHCIHIST_FUNC(); EHCIHIST_CALLED(); | 2851 | EHCIHIST_FUNC(); EHCIHIST_CALLED(); | |
2853 | 2852 | |||
2854 | mutex_enter(&sc->sc_lock); | 2853 | mutex_enter(&sc->sc_lock); | |
2855 | if (sc->sc_freeqtds == NULL) { | 2854 | if (sc->sc_freeqtds == NULL) { | |
2856 | DPRINTF("allocating chunk", 0, 0, 0, 0); | 2855 | DPRINTF("allocating chunk", 0, 0, 0, 0); | |
2857 | mutex_exit(&sc->sc_lock); | 2856 | mutex_exit(&sc->sc_lock); | |
2858 | 2857 | |||
2859 | err = usb_allocmem(&sc->sc_bus, EHCI_SQTD_SIZE*EHCI_SQTD_CHUNK, | 2858 | int err = usb_allocmem(&sc->sc_bus, | |
2860 | EHCI_PAGE_SIZE, USBMALLOC_COHERENT, &dma); | 2859 | EHCI_SQTD_SIZE*EHCI_SQTD_CHUNK, | |
2860 | EHCI_PAGE_SIZE, USBMALLOC_COHERENT, | |||
2861 | &dma); | |||
2861 | #ifdef EHCI_DEBUG | 2862 | #ifdef EHCI_DEBUG | |
2862 | if (err) | 2863 | if (err) | |
2863 | printf("ehci_alloc_sqtd: usb_allocmem()=%d\n", err); | 2864 | printf("ehci_alloc_sqtd: usb_allocmem()=%d\n", err); | |
2864 | #endif | 2865 | #endif | |
2865 | if (err) | 2866 | if (err) | |
2866 | goto done; | 2867 | goto done; | |
2867 | 2868 | |||
2868 | mutex_enter(&sc->sc_lock); | 2869 | mutex_enter(&sc->sc_lock); | |
2869 | for (i = 0; i < EHCI_SQTD_CHUNK; i++) { | 2870 | for (i = 0; i < EHCI_SQTD_CHUNK; i++) { | |
2870 | offs = i * EHCI_SQTD_SIZE; | 2871 | offs = i * EHCI_SQTD_SIZE; | |
2871 | sqtd = KERNADDR(&dma, offs); | 2872 | sqtd = KERNADDR(&dma, offs); | |
2872 | sqtd->physaddr = DMAADDR(&dma, offs); | 2873 | sqtd->physaddr = DMAADDR(&dma, offs); | |
2873 | sqtd->dma = dma; | 2874 | sqtd->dma = dma; | |
@@ -3092,39 +3093,37 @@ ehci_reset_sqtd_chain(ehci_softc_t *sc, | @@ -3092,39 +3093,37 @@ ehci_reset_sqtd_chain(ehci_softc_t *sc, | |||
3092 | 3093 | |||
3093 | ehci_append_sqtd(sqtd, prev); | 3094 | ehci_append_sqtd(sqtd, prev); | |
3094 | tog ^= 1; | 3095 | tog ^= 1; | |
3095 | } | 3096 | } | |
3096 | 3097 | |||
3097 | *lsqtd = sqtd; | 3098 | *lsqtd = sqtd; | |
3098 | *toggle = tog; | 3099 | *toggle = tog; | |
3099 | } | 3100 | } | |
3100 | 3101 | |||
3101 | Static ehci_soft_itd_t * | 3102 | Static ehci_soft_itd_t * | |
3102 | ehci_alloc_itd(ehci_softc_t *sc) | 3103 | ehci_alloc_itd(ehci_softc_t *sc) | |
3103 | { | 3104 | { | |
3104 | struct ehci_soft_itd *itd, *freeitd; | 3105 | struct ehci_soft_itd *itd, *freeitd; | |
3105 | usbd_status err; | |||
3106 | usb_dma_t dma; | 3106 | usb_dma_t dma; | |
3107 | 3107 | |||
3108 | EHCIHIST_FUNC(); EHCIHIST_CALLED(); | 3108 | EHCIHIST_FUNC(); EHCIHIST_CALLED(); | |
3109 | 3109 | |||
3110 | mutex_enter(&sc->sc_lock); | 3110 | mutex_enter(&sc->sc_lock); | |
3111 | 3111 | |||
3112 | freeitd = LIST_FIRST(&sc->sc_freeitds); | 3112 | freeitd = LIST_FIRST(&sc->sc_freeitds); | |
3113 | if (freeitd == NULL) { | 3113 | if (freeitd == NULL) { | |
3114 | DPRINTF("allocating chunk", 0, 0, 0, 0); | 3114 | DPRINTF("allocating chunk", 0, 0, 0, 0); | |
3115 | mutex_exit(&sc->sc_lock); | 3115 | mutex_exit(&sc->sc_lock); | |
3116 | 3116 | int err = usb_allocmem(&sc->sc_bus, EHCI_ITD_SIZE * EHCI_ITD_CHUNK, | ||
3117 | err = usb_allocmem(&sc->sc_bus, EHCI_ITD_SIZE * EHCI_ITD_CHUNK, | |||
3118 | EHCI_PAGE_SIZE, USBMALLOC_COHERENT, &dma); | 3117 | EHCI_PAGE_SIZE, USBMALLOC_COHERENT, &dma); | |
3119 | 3118 | |||
3120 | if (err) { | 3119 | if (err) { | |
3121 | DPRINTF("alloc returned %jd", err, 0, 0, 0); | 3120 | DPRINTF("alloc returned %jd", err, 0, 0, 0); | |
3122 | return NULL; | 3121 | return NULL; | |
3123 | } | 3122 | } | |
3124 | mutex_enter(&sc->sc_lock); | 3123 | mutex_enter(&sc->sc_lock); | |
3125 | 3124 | |||
3126 | for (int i = 0; i < EHCI_ITD_CHUNK; i++) { | 3125 | for (int i = 0; i < EHCI_ITD_CHUNK; i++) { | |
3127 | int offs = i * EHCI_ITD_SIZE; | 3126 | int offs = i * EHCI_ITD_SIZE; | |
3128 | itd = KERNADDR(&dma, offs); | 3127 | itd = KERNADDR(&dma, offs); | |
3129 | itd->physaddr = DMAADDR(&dma, offs); | 3128 | itd->physaddr = DMAADDR(&dma, offs); | |
3130 | itd->dma = dma; | 3129 | itd->dma = dma; | |
@@ -3141,39 +3140,37 @@ ehci_alloc_itd(ehci_softc_t *sc) | @@ -3141,39 +3140,37 @@ ehci_alloc_itd(ehci_softc_t *sc) | |||
3141 | 3140 | |||
3142 | itd->frame_list.next = NULL; | 3141 | itd->frame_list.next = NULL; | |
3143 | itd->frame_list.prev = NULL; | 3142 | itd->frame_list.prev = NULL; | |
3144 | itd->xfer_next = NULL; | 3143 | itd->xfer_next = NULL; | |
3145 | itd->slot = 0; | 3144 | itd->slot = 0; | |
3146 | 3145 | |||
3147 | return itd; | 3146 | return itd; | |
3148 | } | 3147 | } | |
3149 | 3148 | |||
3150 | Static ehci_soft_sitd_t * | 3149 | Static ehci_soft_sitd_t * | |
3151 | ehci_alloc_sitd(ehci_softc_t *sc) | 3150 | ehci_alloc_sitd(ehci_softc_t *sc) | |
3152 | { | 3151 | { | |
3153 | struct ehci_soft_sitd *sitd, *freesitd; | 3152 | struct ehci_soft_sitd *sitd, *freesitd; | |
3154 | usbd_status err; | |||
3155 | int i, offs; | 3153 | int i, offs; | |
3156 | usb_dma_t dma; | 3154 | usb_dma_t dma; | |
3157 | 3155 | |||
3158 | EHCIHIST_FUNC(); EHCIHIST_CALLED(); | 3156 | EHCIHIST_FUNC(); EHCIHIST_CALLED(); | |
3159 | 3157 | |||
3160 | mutex_enter(&sc->sc_lock); | 3158 | mutex_enter(&sc->sc_lock); | |
3161 | freesitd = LIST_FIRST(&sc->sc_freesitds); | 3159 | freesitd = LIST_FIRST(&sc->sc_freesitds); | |
3162 | if (freesitd == NULL) { | 3160 | if (freesitd == NULL) { | |
3163 | DPRINTF("allocating chunk", 0, 0, 0, 0); | 3161 | DPRINTF("allocating chunk", 0, 0, 0, 0); | |
3164 | mutex_exit(&sc->sc_lock); | 3162 | mutex_exit(&sc->sc_lock); | |
3165 | 3163 | int err = usb_allocmem(&sc->sc_bus, EHCI_SITD_SIZE * EHCI_SITD_CHUNK, | ||
3166 | err = usb_allocmem(&sc->sc_bus, EHCI_SITD_SIZE * EHCI_SITD_CHUNK, | |||
3167 | EHCI_PAGE_SIZE, USBMALLOC_COHERENT, &dma); | 3164 | EHCI_PAGE_SIZE, USBMALLOC_COHERENT, &dma); | |
3168 | 3165 | |||
3169 | if (err) { | 3166 | if (err) { | |
3170 | DPRINTF("alloc returned %jd", err, 0, 0, | 3167 | DPRINTF("alloc returned %jd", err, 0, 0, | |
3171 | 0); | 3168 | 0); | |
3172 | return NULL; | 3169 | return NULL; | |
3173 | } | 3170 | } | |
3174 | 3171 | |||
3175 | mutex_enter(&sc->sc_lock); | 3172 | mutex_enter(&sc->sc_lock); | |
3176 | for (i = 0; i < EHCI_SITD_CHUNK; i++) { | 3173 | for (i = 0; i < EHCI_SITD_CHUNK; i++) { | |
3177 | offs = i * EHCI_SITD_SIZE; | 3174 | offs = i * EHCI_SITD_SIZE; | |
3178 | sitd = KERNADDR(&dma, offs); | 3175 | sitd = KERNADDR(&dma, offs); | |
3179 | sitd->physaddr = DMAADDR(&dma, offs); | 3176 | sitd->physaddr = DMAADDR(&dma, offs); |
--- src/sys/dev/usb/ohci.c 2020/12/22 01:07:23 1.314
+++ src/sys/dev/usb/ohci.c 2021/01/05 18:00:21 1.315
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ohci.c,v 1.314 2020/12/22 01:07:23 riastradh Exp $ */ | 1 | /* $NetBSD: ohci.c,v 1.315 2021/01/05 18:00:21 skrll Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1998, 2004, 2005, 2012, 2016, 2020 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1998, 2004, 2005, 2012, 2016, 2020 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 | * Matthew R. Green (mrg@eterna.com.au), and Nick Hudson. | 10 | * Matthew R. Green (mrg@eterna.com.au), and Nick Hudson. | |
11 | * | 11 | * | |
12 | * This code is derived from software contributed to The NetBSD Foundation | 12 | * This code is derived from software contributed to The NetBSD Foundation | |
13 | * by Charles M. Hannum. | 13 | * by Charles M. Hannum. | |
14 | * | 14 | * | |
@@ -32,27 +32,27 @@ | @@ -32,27 +32,27 @@ | |||
32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
34 | * POSSIBILITY OF SUCH DAMAGE. | 34 | * POSSIBILITY OF SUCH DAMAGE. | |
35 | */ | 35 | */ | |
36 | 36 | |||
37 | /* | 37 | /* | |
38 | * USB Open Host Controller driver. | 38 | * USB Open Host Controller driver. | |
39 | * | 39 | * | |
40 | * OHCI spec: http://www.compaq.com/productinfo/development/openhci.html | 40 | * OHCI spec: http://www.compaq.com/productinfo/development/openhci.html | |
41 | * USB spec: http://www.usb.org/developers/docs/ | 41 | * USB spec: http://www.usb.org/developers/docs/ | |
42 | */ | 42 | */ | |
43 | 43 | |||
44 | #include <sys/cdefs.h> | 44 | #include <sys/cdefs.h> | |
45 | __KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.314 2020/12/22 01:07:23 riastradh Exp $"); | 45 | __KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.315 2021/01/05 18:00:21 skrll Exp $"); | |
46 | 46 | |||
47 | #ifdef _KERNEL_OPT | 47 | #ifdef _KERNEL_OPT | |
48 | #include "opt_usb.h" | 48 | #include "opt_usb.h" | |
49 | #endif | 49 | #endif | |
50 | 50 | |||
51 | #include <sys/param.h> | 51 | #include <sys/param.h> | |
52 | 52 | |||
53 | #include <sys/cpu.h> | 53 | #include <sys/cpu.h> | |
54 | #include <sys/device.h> | 54 | #include <sys/device.h> | |
55 | #include <sys/kernel.h> | 55 | #include <sys/kernel.h> | |
56 | #include <sys/kmem.h> | 56 | #include <sys/kmem.h> | |
57 | #include <sys/proc.h> | 57 | #include <sys/proc.h> | |
58 | #include <sys/queue.h> | 58 | #include <sys/queue.h> | |
@@ -389,39 +389,38 @@ ohci_detach(struct ohci_softc *sc, int f | @@ -389,39 +389,38 @@ ohci_detach(struct ohci_softc *sc, int f | |||
389 | 389 | |||
390 | if (sc->sc_hcca != NULL) | 390 | if (sc->sc_hcca != NULL) | |
391 | usb_freemem(&sc->sc_bus, &sc->sc_hccadma); | 391 | usb_freemem(&sc->sc_bus, &sc->sc_hccadma); | |
392 | pool_cache_destroy(sc->sc_xferpool); | 392 | pool_cache_destroy(sc->sc_xferpool); | |
393 | cv_destroy(&sc->sc_abort_cv); | 393 | cv_destroy(&sc->sc_abort_cv); | |
394 | 394 | |||
395 | return rv; | 395 | return rv; | |
396 | } | 396 | } | |
397 | 397 | |||
398 | ohci_soft_ed_t * | 398 | ohci_soft_ed_t * | |
399 | ohci_alloc_sed(ohci_softc_t *sc) | 399 | ohci_alloc_sed(ohci_softc_t *sc) | |
400 | { | 400 | { | |
401 | ohci_soft_ed_t *sed; | 401 | ohci_soft_ed_t *sed; | |
402 | usbd_status err; | |||
403 | int i, offs; | 402 | int i, offs; | |
404 | usb_dma_t dma; | 403 | usb_dma_t dma; | |
405 | 404 | |||
406 | OHCIHIST_FUNC(); OHCIHIST_CALLED(); | 405 | OHCIHIST_FUNC(); OHCIHIST_CALLED(); | |
407 | 406 | |||
408 | mutex_enter(&sc->sc_lock); | 407 | mutex_enter(&sc->sc_lock); | |
409 | if (sc->sc_freeeds == NULL) { | 408 | if (sc->sc_freeeds == NULL) { | |
410 | DPRINTFN(2, "allocating chunk", 0, 0, 0, 0); | 409 | DPRINTFN(2, "allocating chunk", 0, 0, 0, 0); | |
411 | mutex_exit(&sc->sc_lock); | 410 | mutex_exit(&sc->sc_lock); | |
412 | 411 | |||
413 | err = usb_allocmem(&sc->sc_bus, OHCI_SED_SIZE * OHCI_SED_CHUNK, | 412 | int err = usb_allocmem(&sc->sc_bus, OHCI_SED_SIZE * OHCI_SED_CHUNK, | |
414 | OHCI_ED_ALIGN, USBMALLOC_COHERENT, &dma); | 413 | OHCI_ED_ALIGN, 0 /*!USBMALLOC_COHERENT*/, &dma); | |
415 | if (err) | 414 | if (err) | |
416 | return NULL; | 415 | return NULL; | |
417 | 416 | |||
418 | mutex_enter(&sc->sc_lock); | 417 | mutex_enter(&sc->sc_lock); | |
419 | for (i = 0; i < OHCI_SED_CHUNK; i++) { | 418 | for (i = 0; i < OHCI_SED_CHUNK; i++) { | |
420 | offs = i * OHCI_SED_SIZE; | 419 | offs = i * OHCI_SED_SIZE; | |
421 | sed = KERNADDR(&dma, offs); | 420 | sed = KERNADDR(&dma, offs); | |
422 | sed->physaddr = DMAADDR(&dma, offs); | 421 | sed->physaddr = DMAADDR(&dma, offs); | |
423 | sed->dma = dma; | 422 | sed->dma = dma; | |
424 | sed->offs = offs; | 423 | sed->offs = offs; | |
425 | sed->next = sc->sc_freeeds; | 424 | sed->next = sc->sc_freeeds; | |
426 | sc->sc_freeeds = sed; | 425 | sc->sc_freeeds = sed; | |
427 | } | 426 | } | |
@@ -448,39 +447,38 @@ ohci_free_sed_locked(ohci_softc_t *sc, o | @@ -448,39 +447,38 @@ ohci_free_sed_locked(ohci_softc_t *sc, o | |||
448 | void | 447 | void | |
449 | ohci_free_sed(ohci_softc_t *sc, ohci_soft_ed_t *sed) | 448 | ohci_free_sed(ohci_softc_t *sc, ohci_soft_ed_t *sed) | |
450 | { | 449 | { | |
451 | 450 | |||
452 | mutex_enter(&sc->sc_lock); | 451 | mutex_enter(&sc->sc_lock); | |
453 | ohci_free_sed_locked(sc, sed); | 452 | ohci_free_sed_locked(sc, sed); | |
454 | mutex_exit(&sc->sc_lock); | 453 | mutex_exit(&sc->sc_lock); | |
455 | } | 454 | } | |
456 | 455 | |||
457 | ohci_soft_td_t * | 456 | ohci_soft_td_t * | |
458 | ohci_alloc_std(ohci_softc_t *sc) | 457 | ohci_alloc_std(ohci_softc_t *sc) | |
459 | { | 458 | { | |
460 | ohci_soft_td_t *std; | 459 | ohci_soft_td_t *std; | |
461 | usbd_status err; | |||
462 | int i, offs; | 460 | int i, offs; | |
463 | usb_dma_t dma; | 461 | usb_dma_t dma; | |
464 | 462 | |||
465 | OHCIHIST_FUNC(); OHCIHIST_CALLED(); | 463 | OHCIHIST_FUNC(); OHCIHIST_CALLED(); | |
466 | 464 | |||
467 | mutex_enter(&sc->sc_lock); | 465 | mutex_enter(&sc->sc_lock); | |
468 | if (sc->sc_freetds == NULL) { | 466 | if (sc->sc_freetds == NULL) { | |
469 | DPRINTFN(2, "allocating chunk", 0, 0, 0, 0); | 467 | DPRINTFN(2, "allocating chunk", 0, 0, 0, 0); | |
470 | mutex_exit(&sc->sc_lock); | 468 | mutex_exit(&sc->sc_lock); | |
471 | 469 | |||
472 | err = usb_allocmem(&sc->sc_bus, OHCI_STD_SIZE * OHCI_STD_CHUNK, | 470 | int err = usb_allocmem(&sc->sc_bus, OHCI_STD_SIZE * OHCI_STD_CHUNK, | |
473 | OHCI_TD_ALIGN, USBMALLOC_COHERENT, &dma); | 471 | OHCI_TD_ALIGN, USBMALLOC_COHERENT, &dma); | |
474 | if (err) | 472 | if (err) | |
475 | return NULL; | 473 | return NULL; | |
476 | 474 | |||
477 | mutex_enter(&sc->sc_lock); | 475 | mutex_enter(&sc->sc_lock); | |
478 | for (i = 0; i < OHCI_STD_CHUNK; i++) { | 476 | for (i = 0; i < OHCI_STD_CHUNK; i++) { | |
479 | offs = i * OHCI_STD_SIZE; | 477 | offs = i * OHCI_STD_SIZE; | |
480 | std = KERNADDR(&dma, offs); | 478 | std = KERNADDR(&dma, offs); | |
481 | std->physaddr = DMAADDR(&dma, offs); | 479 | std->physaddr = DMAADDR(&dma, offs); | |
482 | std->dma = dma; | 480 | std->dma = dma; | |
483 | std->offs = offs; | 481 | std->offs = offs; | |
484 | std->nexttd = sc->sc_freetds; | 482 | std->nexttd = sc->sc_freetds; | |
485 | sc->sc_freetds = std; | 483 | sc->sc_freetds = std; | |
486 | } | 484 | } | |
@@ -701,38 +699,37 @@ ohci_reset_std_chain(ohci_softc_t *sc, s | @@ -701,38 +699,37 @@ ohci_reset_std_chain(ohci_softc_t *sc, s | |||
701 | ohci_hash_add_td(sc, cur); | 699 | ohci_hash_add_td(sc, cur); | |
702 | 700 | |||
703 | DPRINTFN(2, "add 0 xfer", 0, 0, 0, 0); | 701 | DPRINTFN(2, "add 0 xfer", 0, 0, 0, 0); | |
704 | } | 702 | } | |
705 | 703 | |||
706 | /* Last TD gets usb_syncmem'ed by caller */ | 704 | /* Last TD gets usb_syncmem'ed by caller */ | |
707 | *ep = cur; | 705 | *ep = cur; | |
708 | } | 706 | } | |
709 | 707 | |||
710 | ohci_soft_itd_t * | 708 | ohci_soft_itd_t * | |
711 | ohci_alloc_sitd(ohci_softc_t *sc) | 709 | ohci_alloc_sitd(ohci_softc_t *sc) | |
712 | { | 710 | { | |
713 | ohci_soft_itd_t *sitd; | 711 | ohci_soft_itd_t *sitd; | |
714 | usbd_status err; | |||
715 | int i, offs; | 712 | int i, offs; | |
716 | usb_dma_t dma; | 713 | usb_dma_t dma; | |
717 | 714 | |||
718 | OHCIHIST_FUNC(); OHCIHIST_CALLED(); | 715 | OHCIHIST_FUNC(); OHCIHIST_CALLED(); | |
719 | 716 | |||
720 | mutex_enter(&sc->sc_lock); | 717 | mutex_enter(&sc->sc_lock); | |
721 | if (sc->sc_freeitds == NULL) { | 718 | if (sc->sc_freeitds == NULL) { | |
722 | DPRINTFN(2, "allocating chunk", 0, 0, 0, 0); | 719 | DPRINTFN(2, "allocating chunk", 0, 0, 0, 0); | |
723 | mutex_exit(&sc->sc_lock); | 720 | mutex_exit(&sc->sc_lock); | |
724 | 721 | |||
725 | err = usb_allocmem(&sc->sc_bus, OHCI_SITD_SIZE * OHCI_SITD_CHUNK, | 722 | int err = usb_allocmem(&sc->sc_bus, OHCI_SITD_SIZE * OHCI_SITD_CHUNK, | |
726 | OHCI_ITD_ALIGN, USBMALLOC_COHERENT, &dma); | 723 | OHCI_ITD_ALIGN, USBMALLOC_COHERENT, &dma); | |
727 | if (err) | 724 | if (err) | |
728 | return NULL; | 725 | return NULL; | |
729 | mutex_enter(&sc->sc_lock); | 726 | mutex_enter(&sc->sc_lock); | |
730 | for (i = 0; i < OHCI_SITD_CHUNK; i++) { | 727 | for (i = 0; i < OHCI_SITD_CHUNK; i++) { | |
731 | offs = i * OHCI_SITD_SIZE; | 728 | offs = i * OHCI_SITD_SIZE; | |
732 | sitd = KERNADDR(&dma, offs); | 729 | sitd = KERNADDR(&dma, offs); | |
733 | sitd->physaddr = DMAADDR(&dma, offs); | 730 | sitd->physaddr = DMAADDR(&dma, offs); | |
734 | sitd->dma = dma; | 731 | sitd->dma = dma; | |
735 | sitd->offs = offs; | 732 | sitd->offs = offs; | |
736 | sitd->nextitd = sc->sc_freeitds; | 733 | sitd->nextitd = sc->sc_freeitds; | |
737 | sc->sc_freeitds = sitd; | 734 | sc->sc_freeitds = sitd; | |
738 | } | 735 | } | |
@@ -819,28 +816,28 @@ ohci_init(ohci_softc_t *sc) | @@ -819,28 +816,28 @@ ohci_init(ohci_softc_t *sc) | |||
819 | OHCI_REV_LEGACY(rev) ? ", legacy support" : ""); | 816 | OHCI_REV_LEGACY(rev) ? ", legacy support" : ""); | |
820 | 817 | |||
821 | if (OHCI_REV_HI(rev) != 1 || OHCI_REV_LO(rev) != 0) { | 818 | if (OHCI_REV_HI(rev) != 1 || OHCI_REV_LO(rev) != 0) { | |
822 | aprint_error_dev(sc->sc_dev, "unsupported OHCI revision\n"); | 819 | aprint_error_dev(sc->sc_dev, "unsupported OHCI revision\n"); | |
823 | sc->sc_bus.ub_revision = USBREV_UNKNOWN; | 820 | sc->sc_bus.ub_revision = USBREV_UNKNOWN; | |
824 | return -1; | 821 | return -1; | |
825 | } | 822 | } | |
826 | sc->sc_bus.ub_revision = USBREV_1_0; | 823 | sc->sc_bus.ub_revision = USBREV_1_0; | |
827 | sc->sc_bus.ub_usedma = true; | 824 | sc->sc_bus.ub_usedma = true; | |
828 | sc->sc_bus.ub_dmaflags = USBMALLOC_MULTISEG; | 825 | sc->sc_bus.ub_dmaflags = USBMALLOC_MULTISEG; | |
829 | 826 | |||
830 | /* XXX determine alignment by R/W */ | 827 | /* XXX determine alignment by R/W */ | |
831 | /* Allocate the HCCA area. */ | 828 | /* Allocate the HCCA area. */ | |
832 | err = usb_allocmem(&sc->sc_bus, OHCI_HCCA_SIZE, | 829 | err = usb_allocmem(&sc->sc_bus, OHCI_HCCA_SIZE, OHCI_HCCA_ALIGN, | |
833 | OHCI_HCCA_ALIGN, USBMALLOC_COHERENT, &sc->sc_hccadma); | 830 | USBMALLOC_COHERENT, &sc->sc_hccadma); | |
834 | if (err) { | 831 | if (err) { | |
835 | sc->sc_hcca = NULL; | 832 | sc->sc_hcca = NULL; | |
836 | return err; | 833 | return err; | |
837 | } | 834 | } | |
838 | sc->sc_hcca = KERNADDR(&sc->sc_hccadma, 0); | 835 | sc->sc_hcca = KERNADDR(&sc->sc_hccadma, 0); | |
839 | memset(sc->sc_hcca, 0, OHCI_HCCA_SIZE); | 836 | memset(sc->sc_hcca, 0, OHCI_HCCA_SIZE); | |
840 | 837 | |||
841 | sc->sc_eintrs = OHCI_NORMAL_INTRS; | 838 | sc->sc_eintrs = OHCI_NORMAL_INTRS; | |
842 | 839 | |||
843 | /* Allocate dummy ED that starts the control list. */ | 840 | /* Allocate dummy ED that starts the control list. */ | |
844 | sc->sc_ctrl_head = ohci_alloc_sed(sc); | 841 | sc->sc_ctrl_head = ohci_alloc_sed(sc); | |
845 | if (sc->sc_ctrl_head == NULL) { | 842 | if (sc->sc_ctrl_head == NULL) { | |
846 | err = ENOMEM; | 843 | err = ENOMEM; | |
@@ -2133,30 +2130,30 @@ ohci_open(struct usbd_pipe *pipe) | @@ -2133,30 +2130,30 @@ ohci_open(struct usbd_pipe *pipe) | |||
2133 | OHCI_ED_SET_EN(UE_GET_ADDR(ed->bEndpointAddress)) | | 2130 | OHCI_ED_SET_EN(UE_GET_ADDR(ed->bEndpointAddress)) | | |
2134 | (dev->ud_speed == USB_SPEED_LOW ? OHCI_ED_SPEED : 0) | | 2131 | (dev->ud_speed == USB_SPEED_LOW ? OHCI_ED_SPEED : 0) | | |
2135 | fmt | | 2132 | fmt | | |
2136 | OHCI_ED_SET_MAXP(UGETW(ed->wMaxPacketSize))); | 2133 | OHCI_ED_SET_MAXP(UGETW(ed->wMaxPacketSize))); | |
2137 | sed->ed.ed_headp = HTOO32(tdphys | | 2134 | sed->ed.ed_headp = HTOO32(tdphys | | |
2138 | (pipe->up_endpoint->ue_toggle ? OHCI_TOGGLECARRY : 0)); | 2135 | (pipe->up_endpoint->ue_toggle ? OHCI_TOGGLECARRY : 0)); | |
2139 | sed->ed.ed_tailp = HTOO32(tdphys); | 2136 | sed->ed.ed_tailp = HTOO32(tdphys); | |
2140 | usb_syncmem(&sed->dma, sed->offs, sizeof(sed->ed), | 2137 | usb_syncmem(&sed->dma, sed->offs, sizeof(sed->ed), | |
2141 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | 2138 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | |
2142 | 2139 | |||
2143 | switch (xfertype) { | 2140 | switch (xfertype) { | |
2144 | case UE_CONTROL: | 2141 | case UE_CONTROL: | |
2145 | pipe->up_methods = &ohci_device_ctrl_methods; | 2142 | pipe->up_methods = &ohci_device_ctrl_methods; | |
2146 | err = usb_allocmem(&sc->sc_bus, | 2143 | int error = usb_allocmem(&sc->sc_bus, | |
2147 | sizeof(usb_device_request_t), 0, | 2144 | sizeof(usb_device_request_t), 0, | |
2148 | USBMALLOC_COHERENT, &opipe->ctrl.reqdma); | 2145 | USBMALLOC_COHERENT, &opipe->ctrl.reqdma); | |
2149 | if (err) | 2146 | if (error) | |
2150 | goto bad; | 2147 | goto bad; | |
2151 | mutex_enter(&sc->sc_lock); | 2148 | mutex_enter(&sc->sc_lock); | |
2152 | ohci_add_ed(sc, sed, sc->sc_ctrl_head); | 2149 | ohci_add_ed(sc, sed, sc->sc_ctrl_head); | |
2153 | mutex_exit(&sc->sc_lock); | 2150 | mutex_exit(&sc->sc_lock); | |
2154 | break; | 2151 | break; | |
2155 | case UE_INTERRUPT: | 2152 | case UE_INTERRUPT: | |
2156 | pipe->up_methods = &ohci_device_intr_methods; | 2153 | pipe->up_methods = &ohci_device_intr_methods; | |
2157 | ival = pipe->up_interval; | 2154 | ival = pipe->up_interval; | |
2158 | if (ival == USBD_DEFAULT_INTERVAL) | 2155 | if (ival == USBD_DEFAULT_INTERVAL) | |
2159 | ival = ed->bInterval; | 2156 | ival = ed->bInterval; | |
2160 | err = ohci_device_setintr(sc, opipe, ival); | 2157 | err = ohci_device_setintr(sc, opipe, ival); | |
2161 | if (err) | 2158 | if (err) | |
2162 | goto bad; | 2159 | goto bad; |
--- src/sys/dev/usb/uhci.c 2020/12/22 01:07:23 1.305
+++ src/sys/dev/usb/uhci.c 2021/01/05 18:00:21 1.306
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: uhci.c,v 1.305 2020/12/22 01:07:23 riastradh Exp $ */ | 1 | /* $NetBSD: uhci.c,v 1.306 2021/01/05 18:00:21 skrll Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1998, 2004, 2011, 2012, 2016, 2020 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1998, 2004, 2011, 2012, 2016, 2020 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 | * Matthew R. Green (mrg@eterna.com.au) and Nick Hudson. | 10 | * Matthew R. Green (mrg@eterna.com.au) and Nick Hudson. | |
11 | * | 11 | * | |
12 | * Redistribution and use in source and binary forms, with or without | 12 | * Redistribution and use in source and binary forms, with or without | |
13 | * modification, are permitted provided that the following conditions | 13 | * modification, are permitted provided that the following conditions | |
14 | * are met: | 14 | * are met: | |
@@ -32,27 +32,27 @@ | @@ -32,27 +32,27 @@ | |||
32 | */ | 32 | */ | |
33 | 33 | |||
34 | /* | 34 | /* | |
35 | * USB Universal Host Controller driver. | 35 | * USB Universal Host Controller driver. | |
36 | * Handles e.g. PIIX3 and PIIX4. | 36 | * Handles e.g. PIIX3 and PIIX4. | |
37 | * | 37 | * | |
38 | * UHCI spec: http://www.intel.com/technology/usb/spec.htm | 38 | * UHCI spec: http://www.intel.com/technology/usb/spec.htm | |
39 | * USB spec: http://www.usb.org/developers/docs/ | 39 | * USB spec: http://www.usb.org/developers/docs/ | |
40 | * PIIXn spec: ftp://download.intel.com/design/intarch/datashts/29055002.pdf | 40 | * PIIXn spec: ftp://download.intel.com/design/intarch/datashts/29055002.pdf | |
41 | * ftp://download.intel.com/design/intarch/datashts/29056201.pdf | 41 | * ftp://download.intel.com/design/intarch/datashts/29056201.pdf | |
42 | */ | 42 | */ | |
43 | 43 | |||
44 | #include <sys/cdefs.h> | 44 | #include <sys/cdefs.h> | |
45 | __KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.305 2020/12/22 01:07:23 riastradh Exp $"); | 45 | __KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.306 2021/01/05 18:00:21 skrll Exp $"); | |
46 | 46 | |||
47 | #ifdef _KERNEL_OPT | 47 | #ifdef _KERNEL_OPT | |
48 | #include "opt_usb.h" | 48 | #include "opt_usb.h" | |
49 | #endif | 49 | #endif | |
50 | 50 | |||
51 | #include <sys/param.h> | 51 | #include <sys/param.h> | |
52 | 52 | |||
53 | #include <sys/bus.h> | 53 | #include <sys/bus.h> | |
54 | #include <sys/cpu.h> | 54 | #include <sys/cpu.h> | |
55 | #include <sys/device.h> | 55 | #include <sys/device.h> | |
56 | #include <sys/kernel.h> | 56 | #include <sys/kernel.h> | |
57 | #include <sys/kmem.h> | 57 | #include <sys/kmem.h> | |
58 | #include <sys/mutex.h> | 58 | #include <sys/mutex.h> | |
@@ -423,48 +423,47 @@ uhci_find_prev_qh(uhci_soft_qh_t *pqh, u | @@ -423,48 +423,47 @@ uhci_find_prev_qh(uhci_soft_qh_t *pqh, u | |||
423 | } | 423 | } | |
424 | 424 | |||
425 | void | 425 | void | |
426 | uhci_globalreset(uhci_softc_t *sc) | 426 | uhci_globalreset(uhci_softc_t *sc) | |
427 | { | 427 | { | |
428 | UHCICMD(sc, UHCI_CMD_GRESET); /* global reset */ | 428 | UHCICMD(sc, UHCI_CMD_GRESET); /* global reset */ | |
429 | usb_delay_ms(&sc->sc_bus, USB_BUS_RESET_DELAY); /* wait a little */ | 429 | usb_delay_ms(&sc->sc_bus, USB_BUS_RESET_DELAY); /* wait a little */ | |
430 | UHCICMD(sc, 0); /* do nothing */ | 430 | UHCICMD(sc, 0); /* do nothing */ | |
431 | } | 431 | } | |
432 | 432 | |||
433 | int | 433 | int | |
434 | uhci_init(uhci_softc_t *sc) | 434 | uhci_init(uhci_softc_t *sc) | |
435 | { | 435 | { | |
436 | usbd_status err; | |||
437 | int i, j; | 436 | int i, j; | |
438 | uhci_soft_qh_t *clsqh, *chsqh, *bsqh, *sqh, *lsqh; | 437 | uhci_soft_qh_t *clsqh, *chsqh, *bsqh, *sqh, *lsqh; | |
439 | uhci_soft_td_t *std; | 438 | uhci_soft_td_t *std; | |
440 | 439 | |||
441 | UHCIHIST_FUNC(); UHCIHIST_CALLED(); | 440 | UHCIHIST_FUNC(); UHCIHIST_CALLED(); | |
442 | 441 | |||
443 | #ifdef UHCI_DEBUG | 442 | #ifdef UHCI_DEBUG | |
444 | thesc = sc; | 443 | thesc = sc; | |
445 | 444 | |||
446 | if (uhcidebug >= 2) | 445 | if (uhcidebug >= 2) | |
447 | uhci_dumpregs(sc); | 446 | uhci_dumpregs(sc); | |
448 | #endif | 447 | #endif | |
449 | 448 | |||
450 | sc->sc_suspend = PWR_RESUME; | 449 | sc->sc_suspend = PWR_RESUME; | |
451 | 450 | |||
452 | UWRITE2(sc, UHCI_INTR, 0); /* disable interrupts */ | 451 | UWRITE2(sc, UHCI_INTR, 0); /* disable interrupts */ | |
453 | uhci_globalreset(sc); /* reset the controller */ | 452 | uhci_globalreset(sc); /* reset the controller */ | |
454 | uhci_reset(sc); | 453 | uhci_reset(sc); | |
455 | 454 | |||
456 | /* Allocate and initialize real frame array. */ | 455 | /* Allocate and initialize real frame array. */ | |
457 | err = usb_allocmem(&sc->sc_bus, | 456 | int err = usb_allocmem(&sc->sc_bus, | |
458 | UHCI_FRAMELIST_COUNT * sizeof(uhci_physaddr_t), | 457 | UHCI_FRAMELIST_COUNT * sizeof(uhci_physaddr_t), | |
459 | UHCI_FRAMELIST_ALIGN, USBMALLOC_COHERENT, &sc->sc_dma); | 458 | UHCI_FRAMELIST_ALIGN, USBMALLOC_COHERENT, &sc->sc_dma); | |
460 | if (err) | 459 | if (err) | |
461 | return err; | 460 | return err; | |
462 | sc->sc_pframes = KERNADDR(&sc->sc_dma, 0); | 461 | sc->sc_pframes = KERNADDR(&sc->sc_dma, 0); | |
463 | /* set frame number to 0 */ | 462 | /* set frame number to 0 */ | |
464 | UWRITE2(sc, UHCI_FRNUM, 0); | 463 | UWRITE2(sc, UHCI_FRNUM, 0); | |
465 | /* set frame list */ | 464 | /* set frame list */ | |
466 | UWRITE4(sc, UHCI_FLBASEADDR, DMAADDR(&sc->sc_dma, 0)); | 465 | UWRITE4(sc, UHCI_FLBASEADDR, DMAADDR(&sc->sc_dma, 0)); | |
467 | 466 | |||
468 | /* Initialise mutex early for uhci_alloc_* */ | 467 | /* Initialise mutex early for uhci_alloc_* */ | |
469 | mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB); | 468 | mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB); | |
470 | mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_USB); | 469 | mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_USB); | |
@@ -1825,38 +1824,37 @@ uhci_run(uhci_softc_t *sc, int run, int | @@ -1825,38 +1824,37 @@ uhci_run(uhci_softc_t *sc, int run, int | |||
1825 | * Memory management routines. | 1824 | * Memory management routines. | |
1826 | * uhci_alloc_std allocates TDs | 1825 | * uhci_alloc_std allocates TDs | |
1827 | * uhci_alloc_sqh allocates QHs | 1826 | * uhci_alloc_sqh allocates QHs | |
1828 | * These two routines do their own free list management, | 1827 | * These two routines do their own free list management, | |
1829 | * partly for speed, partly because allocating DMAable memory | 1828 | * partly for speed, partly because allocating DMAable memory | |
1830 | * has page size granularity so much memory would be wasted if | 1829 | * has page size granularity so much memory would be wasted if | |
1831 | * only one TD/QH (32 bytes) was placed in each allocated chunk. | 1830 | * only one TD/QH (32 bytes) was placed in each allocated chunk. | |
1832 | */ | 1831 | */ | |
1833 | 1832 | |||
1834 | uhci_soft_td_t * | 1833 | uhci_soft_td_t * | |
1835 | uhci_alloc_std(uhci_softc_t *sc) | 1834 | uhci_alloc_std(uhci_softc_t *sc) | |
1836 | { | 1835 | { | |
1837 | uhci_soft_td_t *std; | 1836 | uhci_soft_td_t *std; | |
1838 | usbd_status err; | |||
1839 | int i, offs; | 1837 | int i, offs; | |
1840 | usb_dma_t dma; | 1838 | usb_dma_t dma; | |
1841 | 1839 | |||
1842 | UHCIHIST_FUNC(); UHCIHIST_CALLED(); | 1840 | UHCIHIST_FUNC(); UHCIHIST_CALLED(); | |
1843 | 1841 | |||
1844 | mutex_enter(&sc->sc_lock); | 1842 | mutex_enter(&sc->sc_lock); | |
1845 | if (sc->sc_freetds == NULL) { | 1843 | if (sc->sc_freetds == NULL) { | |
1846 | DPRINTFN(2, "allocating chunk", 0, 0, 0, 0); | 1844 | DPRINTFN(2, "allocating chunk", 0, 0, 0, 0); | |
1847 | mutex_exit(&sc->sc_lock); | 1845 | mutex_exit(&sc->sc_lock); | |
1848 | 1846 | |||
1849 | err = usb_allocmem(&sc->sc_bus, UHCI_STD_SIZE * UHCI_STD_CHUNK, | 1847 | int err = usb_allocmem(&sc->sc_bus, UHCI_STD_SIZE * UHCI_STD_CHUNK, | |
1850 | UHCI_TD_ALIGN, USBMALLOC_COHERENT, &dma); | 1848 | UHCI_TD_ALIGN, USBMALLOC_COHERENT, &dma); | |
1851 | if (err) | 1849 | if (err) | |
1852 | return NULL; | 1850 | return NULL; | |
1853 | 1851 | |||
1854 | mutex_enter(&sc->sc_lock); | 1852 | mutex_enter(&sc->sc_lock); | |
1855 | for (i = 0; i < UHCI_STD_CHUNK; i++) { | 1853 | for (i = 0; i < UHCI_STD_CHUNK; i++) { | |
1856 | offs = i * UHCI_STD_SIZE; | 1854 | offs = i * UHCI_STD_SIZE; | |
1857 | std = KERNADDR(&dma, offs); | 1855 | std = KERNADDR(&dma, offs); | |
1858 | std->physaddr = DMAADDR(&dma, offs); | 1856 | std->physaddr = DMAADDR(&dma, offs); | |
1859 | std->dma = dma; | 1857 | std->dma = dma; | |
1860 | std->offs = offs; | 1858 | std->offs = offs; | |
1861 | std->link.std = sc->sc_freetds; | 1859 | std->link.std = sc->sc_freetds; | |
1862 | sc->sc_freetds = std; | 1860 | sc->sc_freetds = std; | |
@@ -1892,38 +1890,37 @@ uhci_free_std_locked(uhci_softc_t *sc, u | @@ -1892,38 +1890,37 @@ uhci_free_std_locked(uhci_softc_t *sc, u | |||
1892 | 1890 | |||
1893 | void | 1891 | void | |
1894 | uhci_free_std(uhci_softc_t *sc, uhci_soft_td_t *std) | 1892 | uhci_free_std(uhci_softc_t *sc, uhci_soft_td_t *std) | |
1895 | { | 1893 | { | |
1896 | mutex_enter(&sc->sc_lock); | 1894 | mutex_enter(&sc->sc_lock); | |
1897 | uhci_free_std_locked(sc, std); | 1895 | uhci_free_std_locked(sc, std); | |
1898 | mutex_exit(&sc->sc_lock); | 1896 | mutex_exit(&sc->sc_lock); | |
1899 | } | 1897 | } | |
1900 | 1898 | |||
1901 | uhci_soft_qh_t * | 1899 | uhci_soft_qh_t * | |
1902 | uhci_alloc_sqh(uhci_softc_t *sc) | 1900 | uhci_alloc_sqh(uhci_softc_t *sc) | |
1903 | { | 1901 | { | |
1904 | uhci_soft_qh_t *sqh; | 1902 | uhci_soft_qh_t *sqh; | |
1905 | usbd_status err; | |||
1906 | int i, offs; | 1903 | int i, offs; | |
1907 | usb_dma_t dma; | 1904 | usb_dma_t dma; | |
1908 | 1905 | |||
1909 | UHCIHIST_FUNC(); UHCIHIST_CALLED(); | 1906 | UHCIHIST_FUNC(); UHCIHIST_CALLED(); | |
1910 | 1907 | |||
1911 | mutex_enter(&sc->sc_lock); | 1908 | mutex_enter(&sc->sc_lock); | |
1912 | if (sc->sc_freeqhs == NULL) { | 1909 | if (sc->sc_freeqhs == NULL) { | |
1913 | DPRINTFN(2, "allocating chunk", 0, 0, 0, 0); | 1910 | DPRINTFN(2, "allocating chunk", 0, 0, 0, 0); | |
1914 | mutex_exit(&sc->sc_lock); | 1911 | mutex_exit(&sc->sc_lock); | |
1915 | 1912 | |||
1916 | err = usb_allocmem(&sc->sc_bus, UHCI_SQH_SIZE * UHCI_SQH_CHUNK, | 1913 | int err = usb_allocmem(&sc->sc_bus, UHCI_SQH_SIZE * UHCI_SQH_CHUNK, | |
1917 | UHCI_QH_ALIGN, USBMALLOC_COHERENT, &dma); | 1914 | UHCI_QH_ALIGN, USBMALLOC_COHERENT, &dma); | |
1918 | if (err) | 1915 | if (err) | |
1919 | return NULL; | 1916 | return NULL; | |
1920 | 1917 | |||
1921 | mutex_enter(&sc->sc_lock); | 1918 | mutex_enter(&sc->sc_lock); | |
1922 | for (i = 0; i < UHCI_SQH_CHUNK; i++) { | 1919 | for (i = 0; i < UHCI_SQH_CHUNK; i++) { | |
1923 | offs = i * UHCI_SQH_SIZE; | 1920 | offs = i * UHCI_SQH_SIZE; | |
1924 | sqh = KERNADDR(&dma, offs); | 1921 | sqh = KERNADDR(&dma, offs); | |
1925 | sqh->physaddr = DMAADDR(&dma, offs); | 1922 | sqh->physaddr = DMAADDR(&dma, offs); | |
1926 | sqh->dma = dma; | 1923 | sqh->dma = dma; | |
1927 | sqh->offs = offs; | 1924 | sqh->offs = offs; | |
1928 | sqh->hlink = sc->sc_freeqhs; | 1925 | sqh->hlink = sc->sc_freeqhs; | |
1929 | sc->sc_freeqhs = sqh; | 1926 | sc->sc_freeqhs = sqh; | |
@@ -3455,27 +3452,26 @@ uhci_device_setintr(uhci_softc_t *sc, st | @@ -3455,27 +3452,26 @@ uhci_device_setintr(uhci_softc_t *sc, st | |||
3455 | DPRINTFN(5, "returns %#jx", (uintptr_t)upipe, 0, 0, 0); | 3452 | DPRINTFN(5, "returns %#jx", (uintptr_t)upipe, 0, 0, 0); | |
3456 | 3453 | |||
3457 | return USBD_NORMAL_COMPLETION; | 3454 | return USBD_NORMAL_COMPLETION; | |
3458 | } | 3455 | } | |
3459 | 3456 | |||
3460 | /* Open a new pipe. */ | 3457 | /* Open a new pipe. */ | |
3461 | usbd_status | 3458 | usbd_status | |
3462 | uhci_open(struct usbd_pipe *pipe) | 3459 | uhci_open(struct usbd_pipe *pipe) | |
3463 | { | 3460 | { | |
3464 | uhci_softc_t *sc = UHCI_PIPE2SC(pipe); | 3461 | uhci_softc_t *sc = UHCI_PIPE2SC(pipe); | |
3465 | struct usbd_bus *bus = pipe->up_dev->ud_bus; | 3462 | struct usbd_bus *bus = pipe->up_dev->ud_bus; | |
3466 | struct uhci_pipe *upipe = UHCI_PIPE2UPIPE(pipe); | 3463 | struct uhci_pipe *upipe = UHCI_PIPE2UPIPE(pipe); | |
3467 | usb_endpoint_descriptor_t *ed = pipe->up_endpoint->ue_edesc; | 3464 | usb_endpoint_descriptor_t *ed = pipe->up_endpoint->ue_edesc; | |
3468 | usbd_status err = USBD_NOMEM; | |||
3469 | int ival; | 3465 | int ival; | |
3470 | 3466 | |||
3471 | UHCIHIST_FUNC(); UHCIHIST_CALLED(); | 3467 | UHCIHIST_FUNC(); UHCIHIST_CALLED(); | |
3472 | DPRINTF("pipe=%#jx, addr=%jd, endpt=%jd (%jd)", | 3468 | DPRINTF("pipe=%#jx, addr=%jd, endpt=%jd (%jd)", | |
3473 | (uintptr_t)pipe, pipe->up_dev->ud_addr, ed->bEndpointAddress, | 3469 | (uintptr_t)pipe, pipe->up_dev->ud_addr, ed->bEndpointAddress, | |
3474 | bus->ub_rhaddr); | 3470 | bus->ub_rhaddr); | |
3475 | 3471 | |||
3476 | if (sc->sc_dying) | 3472 | if (sc->sc_dying) | |
3477 | return USBD_IOERROR; | 3473 | return USBD_IOERROR; | |
3478 | 3474 | |||
3479 | upipe->aborting = 0; | 3475 | upipe->aborting = 0; | |
3480 | /* toggle state needed for bulk endpoints */ | 3476 | /* toggle state needed for bulk endpoints */ | |
3481 | upipe->nexttoggle = pipe->up_endpoint->ue_toggle; | 3477 | upipe->nexttoggle = pipe->up_endpoint->ue_toggle; | |
@@ -3499,27 +3495,27 @@ uhci_open(struct usbd_pipe *pipe) | @@ -3499,27 +3495,27 @@ uhci_open(struct usbd_pipe *pipe) | |||
3499 | if (upipe->ctrl.sqh == NULL) | 3495 | if (upipe->ctrl.sqh == NULL) | |
3500 | goto bad; | 3496 | goto bad; | |
3501 | upipe->ctrl.setup = uhci_alloc_std(sc); | 3497 | upipe->ctrl.setup = uhci_alloc_std(sc); | |
3502 | if (upipe->ctrl.setup == NULL) { | 3498 | if (upipe->ctrl.setup == NULL) { | |
3503 | uhci_free_sqh(sc, upipe->ctrl.sqh); | 3499 | uhci_free_sqh(sc, upipe->ctrl.sqh); | |
3504 | goto bad; | 3500 | goto bad; | |
3505 | } | 3501 | } | |
3506 | upipe->ctrl.stat = uhci_alloc_std(sc); | 3502 | upipe->ctrl.stat = uhci_alloc_std(sc); | |
3507 | if (upipe->ctrl.stat == NULL) { | 3503 | if (upipe->ctrl.stat == NULL) { | |
3508 | uhci_free_sqh(sc, upipe->ctrl.sqh); | 3504 | uhci_free_sqh(sc, upipe->ctrl.sqh); | |
3509 | uhci_free_std(sc, upipe->ctrl.setup); | 3505 | uhci_free_std(sc, upipe->ctrl.setup); | |
3510 | goto bad; | 3506 | goto bad; | |
3511 | } | 3507 | } | |
3512 | err = usb_allocmem(&sc->sc_bus, | 3508 | int err = usb_allocmem(&sc->sc_bus, | |
3513 | sizeof(usb_device_request_t), 0, | 3509 | sizeof(usb_device_request_t), 0, | |
3514 | USBMALLOC_COHERENT, &upipe->ctrl.reqdma); | 3510 | USBMALLOC_COHERENT, &upipe->ctrl.reqdma); | |
3515 | if (err) { | 3511 | if (err) { | |
3516 | uhci_free_sqh(sc, upipe->ctrl.sqh); | 3512 | uhci_free_sqh(sc, upipe->ctrl.sqh); | |
3517 | uhci_free_std(sc, upipe->ctrl.setup); | 3513 | uhci_free_std(sc, upipe->ctrl.setup); | |
3518 | uhci_free_std(sc, upipe->ctrl.stat); | 3514 | uhci_free_std(sc, upipe->ctrl.stat); | |
3519 | goto bad; | 3515 | goto bad; | |
3520 | } | 3516 | } | |
3521 | break; | 3517 | break; | |
3522 | case UE_INTERRUPT: | 3518 | case UE_INTERRUPT: | |
3523 | pipe->up_methods = &uhci_device_intr_methods; | 3519 | pipe->up_methods = &uhci_device_intr_methods; | |
3524 | ival = pipe->up_interval; | 3520 | ival = pipe->up_interval; | |
3525 | if (ival == USBD_DEFAULT_INTERVAL) | 3521 | if (ival == USBD_DEFAULT_INTERVAL) |
--- src/sys/dev/usb/usb_mem.c 2021/01/05 16:15:09 1.79
+++ src/sys/dev/usb/usb_mem.c 2021/01/05 18:00:21 1.80
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: usb_mem.c,v 1.79 2021/01/05 16:15:09 skrll Exp $ */ | 1 | /* $NetBSD: usb_mem.c,v 1.80 2021/01/05 18:00:21 skrll Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1998 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1998 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. | 9 | * Carlstedt Research & Technology. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -28,27 +28,27 @@ | @@ -28,27 +28,27 @@ | |||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
30 | * POSSIBILITY OF SUCH DAMAGE. | 30 | * POSSIBILITY OF SUCH DAMAGE. | |
31 | */ | 31 | */ | |
32 | 32 | |||
33 | /* | 33 | /* | |
34 | * USB DMA memory allocation. | 34 | * USB DMA memory allocation. | |
35 | * We need to allocate a lot of small (many 8 byte, some larger) | 35 | * We need to allocate a lot of small (many 8 byte, some larger) | |
36 | * memory blocks that can be used for DMA. Using the bus_dma | 36 | * memory blocks that can be used for DMA. Using the bus_dma | |
37 | * routines directly would incur large overheads in space and time. | 37 | * routines directly would incur large overheads in space and time. | |
38 | */ | 38 | */ | |
39 | 39 | |||
40 | #include <sys/cdefs.h> | 40 | #include <sys/cdefs.h> | |
41 | __KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.79 2021/01/05 16:15:09 skrll Exp $"); | 41 | __KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.80 2021/01/05 18:00:21 skrll Exp $"); | |
42 | 42 | |||
43 | #ifdef _KERNEL_OPT | 43 | #ifdef _KERNEL_OPT | |
44 | #include "opt_usb.h" | 44 | #include "opt_usb.h" | |
45 | #endif | 45 | #endif | |
46 | 46 | |||
47 | #include <sys/param.h> | 47 | #include <sys/param.h> | |
48 | #include <sys/bus.h> | 48 | #include <sys/bus.h> | |
49 | #include <sys/cpu.h> | 49 | #include <sys/cpu.h> | |
50 | #include <sys/device.h> /* for usbdivar.h */ | 50 | #include <sys/device.h> /* for usbdivar.h */ | |
51 | #include <sys/kernel.h> | 51 | #include <sys/kernel.h> | |
52 | #include <sys/kmem.h> | 52 | #include <sys/kmem.h> | |
53 | #include <sys/once.h> | 53 | #include <sys/once.h> | |
54 | #include <sys/queue.h> | 54 | #include <sys/queue.h> | |
@@ -64,29 +64,29 @@ __KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v | @@ -64,29 +64,29 @@ __KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v | |||
64 | #define DPRINTFN(N,FMT,A,B,C,D) USBHIST_LOGN(usbdebug,N,FMT,A,B,C,D) | 64 | #define DPRINTFN(N,FMT,A,B,C,D) USBHIST_LOGN(usbdebug,N,FMT,A,B,C,D) | |
65 | 65 | |||
66 | #define USB_MEM_SMALL roundup(64, CACHE_LINE_SIZE) | 66 | #define USB_MEM_SMALL roundup(64, CACHE_LINE_SIZE) | |
67 | #define USB_MEM_CHUNKS 64 | 67 | #define USB_MEM_CHUNKS 64 | |
68 | #define USB_MEM_BLOCK (USB_MEM_SMALL * USB_MEM_CHUNKS) | 68 | #define USB_MEM_BLOCK (USB_MEM_SMALL * USB_MEM_CHUNKS) | |
69 | 69 | |||
70 | /* This struct is overlayed on free fragments. */ | 70 | /* This struct is overlayed on free fragments. */ | |
71 | struct usb_frag_dma { | 71 | struct usb_frag_dma { | |
72 | usb_dma_block_t *ufd_block; | 72 | usb_dma_block_t *ufd_block; | |
73 | u_int ufd_offs; | 73 | u_int ufd_offs; | |
74 | LIST_ENTRY(usb_frag_dma) ufd_next; | 74 | LIST_ENTRY(usb_frag_dma) ufd_next; | |
75 | }; | 75 | }; | |
76 | 76 | |||
77 | Static usbd_status usb_block_allocmem(bus_dma_tag_t, size_t, size_t, | 77 | Static int usb_block_allocmem(bus_dma_tag_t, size_t, size_t, | |
78 | u_int, usb_dma_block_t **); | 78 | u_int, usb_dma_block_t **); | |
79 | Static void usb_block_freemem(usb_dma_block_t *); | 79 | Static void usb_block_freemem(usb_dma_block_t *); | |
80 | 80 | |||
81 | LIST_HEAD(usb_dma_block_qh, usb_dma_block); | 81 | LIST_HEAD(usb_dma_block_qh, usb_dma_block); | |
82 | Static struct usb_dma_block_qh usb_blk_freelist = | 82 | Static struct usb_dma_block_qh usb_blk_freelist = | |
83 | LIST_HEAD_INITIALIZER(usb_blk_freelist); | 83 | LIST_HEAD_INITIALIZER(usb_blk_freelist); | |
84 | kmutex_t usb_blk_lock; | 84 | kmutex_t usb_blk_lock; | |
85 | 85 | |||
86 | #ifdef DEBUG | 86 | #ifdef DEBUG | |
87 | Static struct usb_dma_block_qh usb_blk_fraglist = | 87 | Static struct usb_dma_block_qh usb_blk_fraglist = | |
88 | LIST_HEAD_INITIALIZER(usb_blk_fraglist); | 88 | LIST_HEAD_INITIALIZER(usb_blk_fraglist); | |
89 | Static struct usb_dma_block_qh usb_blk_fulllist = | 89 | Static struct usb_dma_block_qh usb_blk_fulllist = | |
90 | LIST_HEAD_INITIALIZER(usb_blk_fulllist); | 90 | LIST_HEAD_INITIALIZER(usb_blk_fulllist); | |
91 | #endif | 91 | #endif | |
92 | Static u_int usb_blk_nfree = 0; | 92 | Static u_int usb_blk_nfree = 0; | |
@@ -94,27 +94,27 @@ Static u_int usb_blk_nfree = 0; | @@ -94,27 +94,27 @@ Static u_int usb_blk_nfree = 0; | |||
94 | Static LIST_HEAD(, usb_frag_dma) usb_frag_freelist = | 94 | Static LIST_HEAD(, usb_frag_dma) usb_frag_freelist = | |
95 | LIST_HEAD_INITIALIZER(usb_frag_freelist); | 95 | LIST_HEAD_INITIALIZER(usb_frag_freelist); | |
96 | 96 | |||
97 | Static int usb_mem_init(void); | 97 | Static int usb_mem_init(void); | |
98 | 98 | |||
99 | Static int | 99 | Static int | |
100 | usb_mem_init(void) | 100 | usb_mem_init(void) | |
101 | { | 101 | { | |
102 | 102 | |||
103 | mutex_init(&usb_blk_lock, MUTEX_DEFAULT, IPL_NONE); | 103 | mutex_init(&usb_blk_lock, MUTEX_DEFAULT, IPL_NONE); | |
104 | return 0; | 104 | return 0; | |
105 | } | 105 | } | |
106 | 106 | |||
107 | Static usbd_status | 107 | Static int | |
108 | usb_block_allocmem(bus_dma_tag_t tag, size_t size, size_t align, | 108 | usb_block_allocmem(bus_dma_tag_t tag, size_t size, size_t align, | |
109 | u_int flags, usb_dma_block_t **dmap) | 109 | u_int flags, usb_dma_block_t **dmap) | |
110 | { | 110 | { | |
111 | usb_dma_block_t *b; | 111 | usb_dma_block_t *b; | |
112 | int error; | 112 | int error; | |
113 | 113 | |||
114 | USBHIST_FUNC(); | 114 | USBHIST_FUNC(); | |
115 | USBHIST_CALLARGS(usbdebug, "size=%ju align=%ju flags=%#jx", size, align, flags, 0); | 115 | USBHIST_CALLARGS(usbdebug, "size=%ju align=%ju flags=%#jx", size, align, flags, 0); | |
116 | 116 | |||
117 | ASSERT_SLEEPABLE(); | 117 | ASSERT_SLEEPABLE(); | |
118 | KASSERT(size != 0); | 118 | KASSERT(size != 0); | |
119 | KASSERT(mutex_owned(&usb_blk_lock)); | 119 | KASSERT(mutex_owned(&usb_blk_lock)); | |
120 | 120 | |||
@@ -125,27 +125,27 @@ usb_block_allocmem(bus_dma_tag_t tag, si | @@ -125,27 +125,27 @@ usb_block_allocmem(bus_dma_tag_t tag, si | |||
125 | /* First check the free list. */ | 125 | /* First check the free list. */ | |
126 | LIST_FOREACH(b, &usb_blk_freelist, next) { | 126 | LIST_FOREACH(b, &usb_blk_freelist, next) { | |
127 | /* Don't allocate multiple segments to unwilling callers */ | 127 | /* Don't allocate multiple segments to unwilling callers */ | |
128 | if (b->nsegs != 1 && !multiseg) | 128 | if (b->nsegs != 1 && !multiseg) | |
129 | continue; | 129 | continue; | |
130 | if (b->tag == tag && | 130 | if (b->tag == tag && | |
131 | b->size >= size && | 131 | b->size >= size && | |
132 | b->align >= align && | 132 | b->align >= align && | |
133 | (b->flags & USB_DMA_COHERENT) == dmaflags) { | 133 | (b->flags & USB_DMA_COHERENT) == dmaflags) { | |
134 | LIST_REMOVE(b, next); | 134 | LIST_REMOVE(b, next); | |
135 | usb_blk_nfree--; | 135 | usb_blk_nfree--; | |
136 | *dmap = b; | 136 | *dmap = b; | |
137 | DPRINTFN(6, "free list size=%ju", b->size, 0, 0, 0); | 137 | DPRINTFN(6, "free list size=%ju", b->size, 0, 0, 0); | |
138 | return USBD_NORMAL_COMPLETION; | 138 | return 0; | |
139 | } | 139 | } | |
140 | } | 140 | } | |
141 | 141 | |||
142 | DPRINTFN(6, "no freelist entry", 0, 0, 0, 0); | 142 | DPRINTFN(6, "no freelist entry", 0, 0, 0, 0); | |
143 | mutex_exit(&usb_blk_lock); | 143 | mutex_exit(&usb_blk_lock); | |
144 | 144 | |||
145 | b = kmem_zalloc(sizeof(*b), KM_SLEEP); | 145 | b = kmem_zalloc(sizeof(*b), KM_SLEEP); | |
146 | b->tag = tag; | 146 | b->tag = tag; | |
147 | b->size = size; | 147 | b->size = size; | |
148 | b->align = align; | 148 | b->align = align; | |
149 | b->flags = dmaflags; | 149 | b->flags = dmaflags; | |
150 | 150 | |||
151 | if (!multiseg) | 151 | if (!multiseg) | |
@@ -181,27 +181,27 @@ usb_block_allocmem(bus_dma_tag_t tag, si | @@ -181,27 +181,27 @@ usb_block_allocmem(bus_dma_tag_t tag, si | |||
181 | *dmap = b; | 181 | *dmap = b; | |
182 | 182 | |||
183 | #ifdef USB_FRAG_DMA_WORKAROUND | 183 | #ifdef USB_FRAG_DMA_WORKAROUND | |
184 | flags |= USBMALLOC_ZERO; | 184 | flags |= USBMALLOC_ZERO; | |
185 | #endif | 185 | #endif | |
186 | if ((flags & USBMALLOC_ZERO) != 0) { | 186 | if ((flags & USBMALLOC_ZERO) != 0) { | |
187 | memset(b->kaddr, 0, b->size); | 187 | memset(b->kaddr, 0, b->size); | |
188 | bus_dmamap_sync(b->tag, b->map, 0, b->size, | 188 | bus_dmamap_sync(b->tag, b->map, 0, b->size, | |
189 | BUS_DMASYNC_PREWRITE); | 189 | BUS_DMASYNC_PREWRITE); | |
190 | } | 190 | } | |
191 | 191 | |||
192 | mutex_enter(&usb_blk_lock); | 192 | mutex_enter(&usb_blk_lock); | |
193 | 193 | |||
194 | return USBD_NORMAL_COMPLETION; | 194 | return 0; | |
195 | 195 | |||
196 | destroy: | 196 | destroy: | |
197 | bus_dmamap_destroy(tag, b->map); | 197 | bus_dmamap_destroy(tag, b->map); | |
198 | unmap: | 198 | unmap: | |
199 | bus_dmamem_unmap(tag, b->kaddr, b->size); | 199 | bus_dmamem_unmap(tag, b->kaddr, b->size); | |
200 | free1: | 200 | free1: | |
201 | bus_dmamem_free(tag, b->segs, b->nsegs); | 201 | bus_dmamem_free(tag, b->segs, b->nsegs); | |
202 | free0: | 202 | free0: | |
203 | kmem_free(b->segs, b->nsegs_alloc * sizeof(*b->segs)); | 203 | kmem_free(b->segs, b->nsegs_alloc * sizeof(*b->segs)); | |
204 | kmem_free(b, sizeof(*b)); | 204 | kmem_free(b, sizeof(*b)); | |
205 | mutex_enter(&usb_blk_lock); | 205 | mutex_enter(&usb_blk_lock); | |
206 | 206 | |||
207 | return USBD_NOMEM; | 207 | return USBD_NOMEM; | |
@@ -245,27 +245,27 @@ usb_block_freemem(usb_dma_block_t *b) | @@ -245,27 +245,27 @@ usb_block_freemem(usb_dma_block_t *b) | |||
245 | { | 245 | { | |
246 | USBHIST_FUNC(); | 246 | USBHIST_FUNC(); | |
247 | USBHIST_CALLARGS(usbdebug, "size=%ju", b->size, 0, 0, 0); | 247 | USBHIST_CALLARGS(usbdebug, "size=%ju", b->size, 0, 0, 0); | |
248 | 248 | |||
249 | KASSERT(mutex_owned(&usb_blk_lock)); | 249 | KASSERT(mutex_owned(&usb_blk_lock)); | |
250 | 250 | |||
251 | #ifdef DEBUG | 251 | #ifdef DEBUG | |
252 | LIST_REMOVE(b, next); | 252 | LIST_REMOVE(b, next); | |
253 | #endif | 253 | #endif | |
254 | LIST_INSERT_HEAD(&usb_blk_freelist, b, next); | 254 | LIST_INSERT_HEAD(&usb_blk_freelist, b, next); | |
255 | usb_blk_nfree++; | 255 | usb_blk_nfree++; | |
256 | } | 256 | } | |
257 | 257 | |||
258 | usbd_status | 258 | int | |
259 | usb_allocmem(struct usbd_bus *bus, size_t size, size_t align, u_int flags, | 259 | usb_allocmem(struct usbd_bus *bus, size_t size, size_t align, u_int flags, | |
260 | usb_dma_t *p) | 260 | usb_dma_t *p) | |
261 | { | 261 | { | |
262 | bus_dma_tag_t tag = bus->ub_dmatag; | 262 | bus_dma_tag_t tag = bus->ub_dmatag; | |
263 | usbd_status err; | 263 | usbd_status err; | |
264 | struct usb_frag_dma *f; | 264 | struct usb_frag_dma *f; | |
265 | usb_dma_block_t *b; | 265 | usb_dma_block_t *b; | |
266 | int i; | 266 | int i; | |
267 | static ONCE_DECL(init_control); | 267 | static ONCE_DECL(init_control); | |
268 | 268 | |||
269 | USBHIST_FUNC(); USBHIST_CALLED(usbdebug); | 269 | USBHIST_FUNC(); USBHIST_CALLED(usbdebug); | |
270 | 270 | |||
271 | ASSERT_SLEEPABLE(); | 271 | ASSERT_SLEEPABLE(); | |
@@ -325,27 +325,27 @@ usb_allocmem(struct usbd_bus *bus, size_ | @@ -325,27 +325,27 @@ usb_allocmem(struct usbd_bus *bus, size_ | |||
325 | #endif | 325 | #endif | |
326 | } | 326 | } | |
327 | f = LIST_FIRST(&usb_frag_freelist); | 327 | f = LIST_FIRST(&usb_frag_freelist); | |
328 | } | 328 | } | |
329 | p->udma_block = f->ufd_block; | 329 | p->udma_block = f->ufd_block; | |
330 | p->udma_offs = f->ufd_offs; | 330 | p->udma_offs = f->ufd_offs; | |
331 | #ifdef USB_FRAG_DMA_WORKAROUND | 331 | #ifdef USB_FRAG_DMA_WORKAROUND | |
332 | p->udma_offs += USB_MEM_SMALL; | 332 | p->udma_offs += USB_MEM_SMALL; | |
333 | #endif | 333 | #endif | |
334 | LIST_REMOVE(f, ufd_next); | 334 | LIST_REMOVE(f, ufd_next); | |
335 | mutex_exit(&usb_blk_lock); | 335 | mutex_exit(&usb_blk_lock); | |
336 | DPRINTFN(5, "use frag=%#jx size=%jd", (uintptr_t)f, size, 0, 0); | 336 | DPRINTFN(5, "use frag=%#jx size=%jd", (uintptr_t)f, size, 0, 0); | |
337 | 337 | |||
338 | return USBD_NORMAL_COMPLETION; | 338 | return 0; | |
339 | } | 339 | } | |
340 | 340 | |||
341 | void | 341 | void | |
342 | usb_freemem(struct usbd_bus *bus, usb_dma_t *p) | 342 | usb_freemem(struct usbd_bus *bus, usb_dma_t *p) | |
343 | { | 343 | { | |
344 | struct usb_frag_dma *f; | 344 | struct usb_frag_dma *f; | |
345 | 345 | |||
346 | USBHIST_FUNC(); USBHIST_CALLED(usbdebug); | 346 | USBHIST_FUNC(); USBHIST_CALLED(usbdebug); | |
347 | 347 | |||
348 | mutex_enter(&usb_blk_lock); | 348 | mutex_enter(&usb_blk_lock); | |
349 | if (p->udma_block->flags & USB_DMA_FULLBLOCK) { | 349 | if (p->udma_block->flags & USB_DMA_FULLBLOCK) { | |
350 | KDASSERTMSG(usb_valid_block_p(p->udma_block, &usb_blk_fulllist), | 350 | KDASSERTMSG(usb_valid_block_p(p->udma_block, &usb_blk_fulllist), | |
351 | "%s: dma %p: invalid block pointer %p", | 351 | "%s: dma %p: invalid block pointer %p", |
--- src/sys/dev/usb/usb_mem.h 2021/01/02 12:39:03 1.33
+++ src/sys/dev/usb/usb_mem.h 2021/01/05 18:00:21 1.34
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: usb_mem.h,v 1.33 2021/01/02 12:39:03 jmcneill Exp $ */ | 1 | /* $NetBSD: usb_mem.h,v 1.34 2021/01/05 18:00:21 skrll Exp $ */ | |
2 | /* $FreeBSD: src/sys/dev/usb/usb_mem.h,v 1.9 1999/11/17 22:33:47 n_hibma Exp $ */ | 2 | /* $FreeBSD: src/sys/dev/usb/usb_mem.h,v 1.9 1999/11/17 22:33:47 n_hibma Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (c) 1998 The NetBSD Foundation, Inc. | 5 | * Copyright (c) 1998 The NetBSD Foundation, Inc. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * This code is derived from software contributed to The NetBSD Foundation | 8 | * This code is derived from software contributed to The NetBSD Foundation | |
9 | * by Lennart Augustsson (lennart@augustsson.net) at | 9 | * by Lennart Augustsson (lennart@augustsson.net) at | |
10 | * Carlstedt Research & Technology. | 10 | * Carlstedt Research & Technology. | |
11 | * | 11 | * | |
12 | * Redistribution and use in source and binary forms, with or without | 12 | * Redistribution and use in source and binary forms, with or without | |
13 | * modification, are permitted provided that the following conditions | 13 | * modification, are permitted provided that the following conditions | |
14 | * are met: | 14 | * are met: | |
@@ -41,22 +41,22 @@ typedef struct usb_dma_block { | @@ -41,22 +41,22 @@ typedef struct usb_dma_block { | |||
41 | size_t size; | 41 | size_t size; | |
42 | size_t align; | 42 | size_t align; | |
43 | int flags; | 43 | int flags; | |
44 | #define USB_DMA_FULLBLOCK __BIT(0) | 44 | #define USB_DMA_FULLBLOCK __BIT(0) | |
45 | #define USB_DMA_COHERENT __BIT(1) | 45 | #define USB_DMA_COHERENT __BIT(1) | |
46 | 46 | |||
47 | LIST_ENTRY(usb_dma_block) next; | 47 | LIST_ENTRY(usb_dma_block) next; | |
48 | } usb_dma_block_t; | 48 | } usb_dma_block_t; | |
49 | 49 | |||
50 | #define USBMALLOC_MULTISEG __BIT(0) | 50 | #define USBMALLOC_MULTISEG __BIT(0) | |
51 | #define USBMALLOC_COHERENT __BIT(1) | 51 | #define USBMALLOC_COHERENT __BIT(1) | |
52 | #define USBMALLOC_ZERO __BIT(2) | 52 | #define USBMALLOC_ZERO __BIT(2) | |
53 | 53 | |||
54 | usbd_status usb_allocmem(struct usbd_bus *, size_t, size_t, u_int, usb_dma_t *); | 54 | int usb_allocmem(struct usbd_bus *, size_t, size_t, u_int, usb_dma_t *); | |
55 | void usb_freemem(struct usbd_bus *, usb_dma_t *); | 55 | void usb_freemem(struct usbd_bus *, usb_dma_t *); | |
56 | void usb_syncmem(usb_dma_t *, bus_addr_t, bus_size_t, int); | 56 | void usb_syncmem(usb_dma_t *, bus_addr_t, bus_size_t, int); | |
57 | 57 | |||
58 | bus_addr_t usb_dmaaddr(usb_dma_t *, unsigned int); | 58 | bus_addr_t usb_dmaaddr(usb_dma_t *, unsigned int); | |
59 | 59 | |||
60 | #define DMAADDR(dma, o) usb_dmaaddr((dma), (o)) | 60 | #define DMAADDR(dma, o) usb_dmaaddr((dma), (o)) | |
61 | #define KERNADDR(dma, o) \ | 61 | #define KERNADDR(dma, o) \ | |
62 | ((void *)((char *)(dma)->udma_block->kaddr + (dma)->udma_offs + (o))) | 62 | ((void *)((char *)(dma)->udma_block->kaddr + (dma)->udma_offs + (o))) |
--- src/sys/dev/usb/xhci.c 2021/01/02 12:39:33 1.137
+++ src/sys/dev/usb/xhci.c 2021/01/05 18:00:21 1.138
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: xhci.c,v 1.137 2021/01/02 12:39:33 jmcneill Exp $ */ | 1 | /* $NetBSD: xhci.c,v 1.138 2021/01/05 18:00:21 skrll Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2013 Jonathan A. Kollasch | 4 | * Copyright (c) 2013 Jonathan A. Kollasch | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -24,27 +24,27 @@ | @@ -24,27 +24,27 @@ | |||
24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
25 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 25 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | /* | 29 | /* | |
30 | * USB rev 2.0 and rev 3.1 specification | 30 | * USB rev 2.0 and rev 3.1 specification | |
31 | * http://www.usb.org/developers/docs/ | 31 | * http://www.usb.org/developers/docs/ | |
32 | * xHCI rev 1.1 specification | 32 | * xHCI rev 1.1 specification | |
33 | * http://www.intel.com/technology/usb/spec.htm | 33 | * http://www.intel.com/technology/usb/spec.htm | |
34 | */ | 34 | */ | |
35 | 35 | |||
36 | #include <sys/cdefs.h> | 36 | #include <sys/cdefs.h> | |
37 | __KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.137 2021/01/02 12:39:33 jmcneill Exp $"); | 37 | __KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.138 2021/01/05 18:00:21 skrll Exp $"); | |
38 | 38 | |||
39 | #ifdef _KERNEL_OPT | 39 | #ifdef _KERNEL_OPT | |
40 | #include "opt_usb.h" | 40 | #include "opt_usb.h" | |
41 | #endif | 41 | #endif | |
42 | 42 | |||
43 | #include <sys/param.h> | 43 | #include <sys/param.h> | |
44 | #include <sys/systm.h> | 44 | #include <sys/systm.h> | |
45 | #include <sys/kernel.h> | 45 | #include <sys/kernel.h> | |
46 | #include <sys/kmem.h> | 46 | #include <sys/kmem.h> | |
47 | #include <sys/device.h> | 47 | #include <sys/device.h> | |
48 | #include <sys/select.h> | 48 | #include <sys/select.h> | |
49 | #include <sys/proc.h> | 49 | #include <sys/proc.h> | |
50 | #include <sys/queue.h> | 50 | #include <sys/queue.h> | |
@@ -1070,28 +1070,27 @@ xhci_init(struct xhci_softc *sc) | @@ -1070,28 +1070,27 @@ xhci_init(struct xhci_softc *sc) | |||
1070 | pagesize = xhci_op_read_4(sc, XHCI_PAGESIZE); | 1070 | pagesize = xhci_op_read_4(sc, XHCI_PAGESIZE); | |
1071 | aprint_debug_dev(sc->sc_dev, "PAGESIZE 0x%08x\n", pagesize); | 1071 | aprint_debug_dev(sc->sc_dev, "PAGESIZE 0x%08x\n", pagesize); | |
1072 | pagesize = ffs(pagesize); | 1072 | pagesize = ffs(pagesize); | |
1073 | if (pagesize == 0) { | 1073 | if (pagesize == 0) { | |
1074 | aprint_error_dev(sc->sc_dev, "pagesize is 0\n"); | 1074 | aprint_error_dev(sc->sc_dev, "pagesize is 0\n"); | |
1075 | return EIO; | 1075 | return EIO; | |
1076 | } | 1076 | } | |
1077 | sc->sc_pgsz = 1 << (12 + (pagesize - 1)); | 1077 | sc->sc_pgsz = 1 << (12 + (pagesize - 1)); | |
1078 | aprint_debug_dev(sc->sc_dev, "sc_pgsz 0x%08x\n", (uint32_t)sc->sc_pgsz); | 1078 | aprint_debug_dev(sc->sc_dev, "sc_pgsz 0x%08x\n", (uint32_t)sc->sc_pgsz); | |
1079 | aprint_debug_dev(sc->sc_dev, "sc_maxslots 0x%08x\n", | 1079 | aprint_debug_dev(sc->sc_dev, "sc_maxslots 0x%08x\n", | |
1080 | (uint32_t)sc->sc_maxslots); | 1080 | (uint32_t)sc->sc_maxslots); | |
1081 | aprint_debug_dev(sc->sc_dev, "sc_maxports %d\n", sc->sc_maxports); | 1081 | aprint_debug_dev(sc->sc_dev, "sc_maxports %d\n", sc->sc_maxports); | |
1082 | 1082 | |||
1083 | usbd_status err; | 1083 | int err; | |
1084 | ||||
1085 | sc->sc_maxspbuf = XHCI_HCS2_MAXSPBUF(hcs2); | 1084 | sc->sc_maxspbuf = XHCI_HCS2_MAXSPBUF(hcs2); | |
1086 | aprint_debug_dev(sc->sc_dev, "sc_maxspbuf %d\n", sc->sc_maxspbuf); | 1085 | aprint_debug_dev(sc->sc_dev, "sc_maxspbuf %d\n", sc->sc_maxspbuf); | |
1087 | if (sc->sc_maxspbuf != 0) { | 1086 | if (sc->sc_maxspbuf != 0) { | |
1088 | err = usb_allocmem(&sc->sc_bus, | 1087 | err = usb_allocmem(&sc->sc_bus, | |
1089 | sizeof(uint64_t) * sc->sc_maxspbuf, sizeof(uint64_t), | 1088 | sizeof(uint64_t) * sc->sc_maxspbuf, sizeof(uint64_t), | |
1090 | USBMALLOC_COHERENT | USBMALLOC_ZERO, | 1089 | USBMALLOC_COHERENT | USBMALLOC_ZERO, | |
1091 | &sc->sc_spbufarray_dma); | 1090 | &sc->sc_spbufarray_dma); | |
1092 | if (err) { | 1091 | if (err) { | |
1093 | aprint_error_dev(sc->sc_dev, | 1092 | aprint_error_dev(sc->sc_dev, | |
1094 | "spbufarray init fail, err %d\n", err); | 1093 | "spbufarray init fail, err %d\n", err); | |
1095 | return ENOMEM; | 1094 | return ENOMEM; | |
1096 | } | 1095 | } | |
1097 | 1096 | |||
@@ -2560,38 +2559,37 @@ xhci_new_device(device_t parent, struct | @@ -2560,38 +2559,37 @@ xhci_new_device(device_t parent, struct | |||
2560 | err = usbd_probe_and_attach(parent, dev, port, dev->ud_addr); | 2559 | err = usbd_probe_and_attach(parent, dev, port, dev->ud_addr); | |
2561 | bad: | 2560 | bad: | |
2562 | if (err != USBD_NORMAL_COMPLETION) { | 2561 | if (err != USBD_NORMAL_COMPLETION) { | |
2563 | usbd_remove_device(dev, up); | 2562 | usbd_remove_device(dev, up); | |
2564 | } | 2563 | } | |
2565 | 2564 | |||
2566 | return err; | 2565 | return err; | |
2567 | } | 2566 | } | |
2568 | 2567 | |||
2569 | static usbd_status | 2568 | static usbd_status | |
2570 | xhci_ring_init(struct xhci_softc * const sc, struct xhci_ring **xrp, | 2569 | xhci_ring_init(struct xhci_softc * const sc, struct xhci_ring **xrp, | |
2571 | size_t ntrb, size_t align) | 2570 | size_t ntrb, size_t align) | |
2572 | { | 2571 | { | |
2573 | usbd_status err; | |||
2574 | size_t size = ntrb * XHCI_TRB_SIZE; | 2572 | size_t size = ntrb * XHCI_TRB_SIZE; | |
2575 | struct xhci_ring *xr; | 2573 | struct xhci_ring *xr; | |
2576 | 2574 | |||
2577 | XHCIHIST_FUNC(); | 2575 | XHCIHIST_FUNC(); | |
2578 | XHCIHIST_CALLARGS("xr %#jx ntrb %#jx align %#jx", | 2576 | XHCIHIST_CALLARGS("xr %#jx ntrb %#jx align %#jx", | |
2579 | (uintptr_t)*xrp, ntrb, align, 0); | 2577 | (uintptr_t)*xrp, ntrb, align, 0); | |
2580 | 2578 | |||
2581 | xr = kmem_zalloc(sizeof(struct xhci_ring), KM_SLEEP); | 2579 | xr = kmem_zalloc(sizeof(struct xhci_ring), KM_SLEEP); | |
2582 | DPRINTFN(1, "ring %#jx", (uintptr_t)xr, 0, 0, 0); | 2580 | DPRINTFN(1, "ring %#jx", (uintptr_t)xr, 0, 0, 0); | |
2583 | 2581 | |||
2584 | err = usb_allocmem(&sc->sc_bus, size, align, | 2582 | int err = usb_allocmem(&sc->sc_bus, size, align, | |
2585 | USBMALLOC_COHERENT | USBMALLOC_ZERO, &xr->xr_dma); | 2583 | USBMALLOC_COHERENT | USBMALLOC_ZERO, &xr->xr_dma); | |
2586 | if (err) { | 2584 | if (err) { | |
2587 | kmem_free(xr, sizeof(struct xhci_ring)); | 2585 | kmem_free(xr, sizeof(struct xhci_ring)); | |
2588 | DPRINTFN(1, "alloc xr_dma failed %jd", err, 0, 0, 0); | 2586 | DPRINTFN(1, "alloc xr_dma failed %jd", err, 0, 0, 0); | |
2589 | return err; | 2587 | return err; | |
2590 | } | 2588 | } | |
2591 | mutex_init(&xr->xr_lock, MUTEX_DEFAULT, IPL_SOFTUSB); | 2589 | mutex_init(&xr->xr_lock, MUTEX_DEFAULT, IPL_SOFTUSB); | |
2592 | xr->xr_cookies = kmem_zalloc(sizeof(*xr->xr_cookies) * ntrb, KM_SLEEP); | 2590 | xr->xr_cookies = kmem_zalloc(sizeof(*xr->xr_cookies) * ntrb, KM_SLEEP); | |
2593 | xr->xr_trb = xhci_ring_trbv(xr, 0); | 2591 | xr->xr_trb = xhci_ring_trbv(xr, 0); | |
2594 | xr->xr_ntrb = ntrb; | 2592 | xr->xr_ntrb = ntrb; | |
2595 | xr->is_halted = false; | 2593 | xr->is_halted = false; | |
2596 | xhci_host_dequeue(xr); | 2594 | xhci_host_dequeue(xr); | |
2597 | *xrp = xr; | 2595 | *xrp = xr; | |
@@ -3002,59 +3000,57 @@ xhci_set_dcba(struct xhci_softc * const | @@ -3002,59 +3000,57 @@ xhci_set_dcba(struct xhci_softc * const | |||
3002 | usb_syncmem(&sc->sc_dcbaa_dma, si * sizeof(uint64_t), sizeof(uint64_t), | 3000 | usb_syncmem(&sc->sc_dcbaa_dma, si * sizeof(uint64_t), sizeof(uint64_t), | |
3003 | BUS_DMASYNC_PREWRITE); | 3001 | BUS_DMASYNC_PREWRITE); | |
3004 | } | 3002 | } | |
3005 | 3003 | |||
3006 | /* | 3004 | /* | |
3007 | * Allocate device and input context DMA buffer, and | 3005 | * Allocate device and input context DMA buffer, and | |
3008 | * TRB DMA buffer for each endpoint. | 3006 | * TRB DMA buffer for each endpoint. | |
3009 | */ | 3007 | */ | |
3010 | static usbd_status | 3008 | static usbd_status | |
3011 | xhci_init_slot(struct usbd_device *dev, uint32_t slot) | 3009 | xhci_init_slot(struct usbd_device *dev, uint32_t slot) | |
3012 | { | 3010 | { | |
3013 | struct xhci_softc * const sc = XHCI_BUS2SC(dev->ud_bus); | 3011 | struct xhci_softc * const sc = XHCI_BUS2SC(dev->ud_bus); | |
3014 | struct xhci_slot *xs; | 3012 | struct xhci_slot *xs; | |
3015 | usbd_status err; | |||
3016 | 3013 | |||
3017 | XHCIHIST_FUNC(); | 3014 | XHCIHIST_FUNC(); | |
3018 | XHCIHIST_CALLARGS("slot %ju", slot, 0, 0, 0); | 3015 | XHCIHIST_CALLARGS("slot %ju", slot, 0, 0, 0); | |
3019 | 3016 | |||
3020 | xs = &sc->sc_slots[slot]; | 3017 | xs = &sc->sc_slots[slot]; | |
3021 | 3018 | |||
3022 | /* allocate contexts */ | 3019 | /* allocate contexts */ | |
3023 | err = usb_allocmem(&sc->sc_bus, sc->sc_pgsz, sc->sc_pgsz, | 3020 | int err = usb_allocmem(&sc->sc_bus, sc->sc_pgsz, sc->sc_pgsz, | |
3024 | USBMALLOC_COHERENT | USBMALLOC_ZERO, &xs->xs_dc_dma); | 3021 | USBMALLOC_COHERENT | USBMALLOC_ZERO, &xs->xs_dc_dma); | |
3025 | if (err) { | 3022 | if (err) { | |
3026 | DPRINTFN(1, "failed to allocmem output device context %jd", | 3023 | DPRINTFN(1, "failed to allocmem output device context %jd", | |
3027 | err, 0, 0, 0); | 3024 | err, 0, 0, 0); | |
3028 | return err; | 3025 | return USBD_NOMEM; | |
3029 | } | 3026 | } | |
3030 | 3027 | |||
3031 | err = usb_allocmem(&sc->sc_bus, sc->sc_pgsz, sc->sc_pgsz, | 3028 | err = usb_allocmem(&sc->sc_bus, sc->sc_pgsz, sc->sc_pgsz, | |
3032 | USBMALLOC_COHERENT | USBMALLOC_ZERO, &xs->xs_ic_dma); | 3029 | USBMALLOC_COHERENT | USBMALLOC_ZERO, &xs->xs_ic_dma); | |
3033 | if (err) { | 3030 | if (err) { | |
3034 | DPRINTFN(1, "failed to allocmem input device context %jd", | 3031 | DPRINTFN(1, "failed to allocmem input device context %jd", | |
3035 | err, 0, 0, 0); | 3032 | err, 0, 0, 0); | |
3036 | goto bad1; | 3033 | return USBD_NOMEM; | |
3037 | } | 3034 | } | |
3038 | 3035 | |||
3039 | memset(&xs->xs_xr[0], 0, sizeof(xs->xs_xr)); | 3036 | memset(&xs->xs_xr[0], 0, sizeof(xs->xs_xr)); | |
3040 | xs->xs_idx = slot; | 3037 | xs->xs_idx = slot; | |
3041 | 3038 | |||
3042 | return USBD_NORMAL_COMPLETION; | 3039 | return USBD_NORMAL_COMPLETION; | |
3043 | 3040 | |||
3044 | bad1: | |||
3045 | usb_freemem(&sc->sc_bus, &xs->xs_dc_dma); | 3041 | usb_freemem(&sc->sc_bus, &xs->xs_dc_dma); | |
3046 | xs->xs_idx = 0; | 3042 | xs->xs_idx = 0; | |
3047 | return err; | 3043 | return USBD_NOMEM; | |
3048 | } | 3044 | } | |
3049 | 3045 | |||
3050 | static void | 3046 | static void | |
3051 | xhci_free_slot(struct xhci_softc *sc, struct xhci_slot *xs) | 3047 | xhci_free_slot(struct xhci_softc *sc, struct xhci_slot *xs) | |
3052 | { | 3048 | { | |
3053 | u_int dci; | 3049 | u_int dci; | |
3054 | 3050 | |||
3055 | XHCIHIST_FUNC(); | 3051 | XHCIHIST_FUNC(); | |
3056 | XHCIHIST_CALLARGS("slot %ju", xs->xs_idx, 0, 0, 0); | 3052 | XHCIHIST_CALLARGS("slot %ju", xs->xs_idx, 0, 0, 0); | |
3057 | 3053 | |||
3058 | /* deallocate all allocated rings in the slot */ | 3054 | /* deallocate all allocated rings in the slot */ | |
3059 | for (dci = XHCI_DCI_SLOT; dci <= XHCI_MAX_DCI; dci++) { | 3055 | for (dci = XHCI_DCI_SLOT; dci <= XHCI_MAX_DCI; dci++) { | |
3060 | if (xs->xs_xr[dci] != NULL) | 3056 | if (xs->xs_xr[dci] != NULL) |