| @@ -1,1055 +1,1055 @@ | | | @@ -1,1055 +1,1055 @@ |
1 | /* $NetBSD: ehci.c,v 1.234.2.37 2015/03/03 06:36:53 skrll Exp $ */ | | 1 | /* $NetBSD: ehci.c,v 1.234.2.38 2015/03/03 10:06:01 skrll Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2004-2012 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2004-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), 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) and Matthew R. Green (mrg@eterna.com.au). | | 10 | * (jmcneill@invisible.ca) and Matthew R. Green (mrg@eterna.com.au). |
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: |
15 | * 1. Redistributions of source code must retain the above copyright | | 15 | * 1. Redistributions of source code must retain the above copyright |
16 | * notice, this list of conditions and the following disclaimer. | | 16 | * notice, this list of conditions and the following disclaimer. |
17 | * 2. Redistributions in binary form must reproduce the above copyright | | 17 | * 2. Redistributions in binary form must reproduce the above copyright |
18 | * notice, this list of conditions and the following disclaimer in the | | 18 | * notice, this list of conditions and the following disclaimer in the |
19 | * documentation and/or other materials provided with the distribution. | | 19 | * documentation and/or other materials provided with the distribution. |
20 | * | | 20 | * |
21 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 21 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
23 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 23 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
31 | * POSSIBILITY OF SUCH DAMAGE. | | 31 | * POSSIBILITY OF SUCH DAMAGE. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | /* | | 34 | /* |
35 | * USB Enhanced Host Controller Driver, a.k.a. USB 2.0 controller. | | 35 | * USB Enhanced Host Controller Driver, a.k.a. USB 2.0 controller. |
36 | * | | 36 | * |
37 | * The EHCI 1.0 spec can be found at | | 37 | * The EHCI 1.0 spec can be found at |
38 | * http://www.intel.com/technology/usb/spec.htm | | 38 | * http://www.intel.com/technology/usb/spec.htm |
39 | * and the USB 2.0 spec at | | 39 | * and the USB 2.0 spec at |
40 | * http://www.usb.org/developers/docs/ | | 40 | * http://www.usb.org/developers/docs/ |
41 | * | | 41 | * |
42 | */ | | 42 | */ |
43 | | | 43 | |
44 | /* | | 44 | /* |
45 | * TODO: | | 45 | * TODO: |
46 | * 1) hold off explorations by companion controllers until ehci has started. | | 46 | * 1) hold off explorations by companion controllers until ehci has started. |
47 | * | | 47 | * |
48 | * 2) The hub driver needs to handle and schedule the transaction translator, | | 48 | * 2) The hub driver needs to handle and schedule the transaction translator, |
49 | * to assign place in frame where different devices get to go. See chapter | | 49 | * to assign place in frame where different devices get to go. See chapter |
50 | * on hubs in USB 2.0 for details. | | 50 | * on hubs in USB 2.0 for details. |
51 | * | | 51 | * |
52 | * 3) Command failures are not recovered correctly. | | 52 | * 3) Command failures are not recovered correctly. |
53 | */ | | 53 | */ |
54 | | | 54 | |
55 | #include <sys/cdefs.h> | | 55 | #include <sys/cdefs.h> |
56 | __KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.234.2.37 2015/03/03 06:36:53 skrll Exp $"); | | 56 | __KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.234.2.38 2015/03/03 10:06:01 skrll Exp $"); |
57 | | | 57 | |
58 | #include "ohci.h" | | 58 | #include "ohci.h" |
59 | #include "uhci.h" | | 59 | #include "uhci.h" |
60 | #include "opt_usb.h" | | 60 | #include "opt_usb.h" |
61 | | | 61 | |
62 | #include <sys/param.h> | | 62 | #include <sys/param.h> |
63 | | | 63 | |
64 | #include <sys/bus.h> | | 64 | #include <sys/bus.h> |
65 | #include <sys/cpu.h> | | 65 | #include <sys/cpu.h> |
66 | #include <sys/device.h> | | 66 | #include <sys/device.h> |
67 | #include <sys/kernel.h> | | 67 | #include <sys/kernel.h> |
68 | #include <sys/kmem.h> | | 68 | #include <sys/kmem.h> |
69 | #include <sys/mutex.h> | | 69 | #include <sys/mutex.h> |
70 | #include <sys/proc.h> | | 70 | #include <sys/proc.h> |
71 | #include <sys/queue.h> | | 71 | #include <sys/queue.h> |
72 | #include <sys/select.h> | | 72 | #include <sys/select.h> |
73 | #include <sys/sysctl.h> | | 73 | #include <sys/sysctl.h> |
74 | #include <sys/systm.h> | | 74 | #include <sys/systm.h> |
75 | | | 75 | |
76 | #include <machine/endian.h> | | 76 | #include <machine/endian.h> |
77 | | | 77 | |
78 | #include <dev/usb/usb.h> | | 78 | #include <dev/usb/usb.h> |
79 | #include <dev/usb/usbdi.h> | | 79 | #include <dev/usb/usbdi.h> |
80 | #include <dev/usb/usbdivar.h> | | 80 | #include <dev/usb/usbdivar.h> |
81 | #include <dev/usb/usbhist.h> | | 81 | #include <dev/usb/usbhist.h> |
82 | #include <dev/usb/usb_mem.h> | | 82 | #include <dev/usb/usb_mem.h> |
83 | #include <dev/usb/usb_quirks.h> | | 83 | #include <dev/usb/usb_quirks.h> |
84 | | | 84 | |
85 | #include <dev/usb/ehcireg.h> | | 85 | #include <dev/usb/ehcireg.h> |
86 | #include <dev/usb/ehcivar.h> | | 86 | #include <dev/usb/ehcivar.h> |
87 | #include <dev/usb/usbroothub.h> | | 87 | #include <dev/usb/usbroothub.h> |
88 | | | 88 | |
89 | | | 89 | |
90 | #ifdef USB_DEBUG | | 90 | #ifdef USB_DEBUG |
91 | #ifndef EHCI_DEBUG | | 91 | #ifndef EHCI_DEBUG |
92 | #define ehcidebug 0 | | 92 | #define ehcidebug 0 |
93 | #else | | 93 | #else |
94 | static int ehcidebug = 0; | | 94 | static int ehcidebug = 0; |
95 | | | 95 | |
96 | SYSCTL_SETUP(sysctl_hw_ehci_setup, "sysctl hw.ehci setup") | | 96 | SYSCTL_SETUP(sysctl_hw_ehci_setup, "sysctl hw.ehci setup") |
97 | { | | 97 | { |
98 | int err; | | 98 | int err; |
99 | const struct sysctlnode *rnode; | | 99 | const struct sysctlnode *rnode; |
100 | const struct sysctlnode *cnode; | | 100 | const struct sysctlnode *cnode; |
101 | | | 101 | |
102 | err = sysctl_createv(clog, 0, NULL, &rnode, | | 102 | err = sysctl_createv(clog, 0, NULL, &rnode, |
103 | CTLFLAG_PERMANENT, CTLTYPE_NODE, "ehci", | | 103 | CTLFLAG_PERMANENT, CTLTYPE_NODE, "ehci", |
104 | SYSCTL_DESCR("ehci global controls"), | | 104 | SYSCTL_DESCR("ehci global controls"), |
105 | NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL); | | 105 | NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL); |
106 | | | 106 | |
107 | if (err) | | 107 | if (err) |
108 | goto fail; | | 108 | goto fail; |
109 | | | 109 | |
110 | /* control debugging printfs */ | | 110 | /* control debugging printfs */ |
111 | err = sysctl_createv(clog, 0, &rnode, &cnode, | | 111 | err = sysctl_createv(clog, 0, &rnode, &cnode, |
112 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, | | 112 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, |
113 | "debug", SYSCTL_DESCR("Enable debugging output"), | | 113 | "debug", SYSCTL_DESCR("Enable debugging output"), |
114 | NULL, 0, &ehcidebug, sizeof(ehcidebug), CTL_CREATE, CTL_EOL); | | 114 | NULL, 0, &ehcidebug, sizeof(ehcidebug), CTL_CREATE, CTL_EOL); |
115 | if (err) | | 115 | if (err) |
116 | goto fail; | | 116 | goto fail; |
117 | | | 117 | |
118 | return; | | 118 | return; |
119 | fail: | | 119 | fail: |
120 | aprint_error("%s: sysctl_createv failed (err = %d)\n", __func__, err); | | 120 | aprint_error("%s: sysctl_createv failed (err = %d)\n", __func__, err); |
121 | } | | 121 | } |
122 | | | 122 | |
123 | #endif /* EHCI_DEBUG */ | | 123 | #endif /* EHCI_DEBUG */ |
124 | #endif /* USB_DEBUG */ | | 124 | #endif /* USB_DEBUG */ |
125 | | | 125 | |
126 | struct ehci_pipe { | | 126 | struct ehci_pipe { |
127 | struct usbd_pipe pipe; | | 127 | struct usbd_pipe pipe; |
128 | int nexttoggle; | | 128 | int nexttoggle; |
129 | | | 129 | |
130 | ehci_soft_qh_t *sqh; | | 130 | ehci_soft_qh_t *sqh; |
131 | union { | | 131 | union { |
132 | ehci_soft_qtd_t *qtd; | | 132 | ehci_soft_qtd_t *qtd; |
133 | /* ehci_soft_itd_t *itd; */ | | 133 | /* ehci_soft_itd_t *itd; */ |
134 | /* ehci_soft_sitd_t *sitd; */ | | 134 | /* ehci_soft_sitd_t *sitd; */ |
135 | } tail; | | 135 | } tail; |
136 | union { | | 136 | union { |
137 | /* Control pipe */ | | 137 | /* Control pipe */ |
138 | struct { | | 138 | struct { |
139 | usb_dma_t reqdma; | | 139 | usb_dma_t reqdma; |
140 | } ctl; | | 140 | } ctl; |
141 | /* Interrupt pipe */ | | 141 | /* Interrupt pipe */ |
142 | struct { | | 142 | struct { |
143 | u_int length; | | 143 | u_int length; |
144 | } intr; | | 144 | } intr; |
145 | /* Bulk pipe */ | | 145 | /* Bulk pipe */ |
146 | struct { | | 146 | struct { |
147 | u_int length; | | 147 | u_int length; |
148 | } bulk; | | 148 | } bulk; |
149 | /* Iso pipe */ | | 149 | /* Iso pipe */ |
150 | struct { | | 150 | struct { |
151 | u_int next_frame; | | 151 | u_int next_frame; |
152 | u_int cur_xfers; | | 152 | u_int cur_xfers; |
153 | } isoc; | | 153 | } isoc; |
154 | } u; | | 154 | } u; |
155 | }; | | 155 | }; |
156 | | | 156 | |
157 | Static usbd_status ehci_open(usbd_pipe_handle); | | 157 | Static usbd_status ehci_open(usbd_pipe_handle); |
158 | Static void ehci_poll(struct usbd_bus *); | | 158 | Static void ehci_poll(struct usbd_bus *); |
159 | Static void ehci_softintr(void *); | | 159 | Static void ehci_softintr(void *); |
160 | Static int ehci_intr1(ehci_softc_t *); | | 160 | Static int ehci_intr1(ehci_softc_t *); |
161 | Static void ehci_waitintr(ehci_softc_t *, usbd_xfer_handle); | | 161 | Static void ehci_waitintr(ehci_softc_t *, usbd_xfer_handle); |
162 | Static void ehci_check_intr(ehci_softc_t *, struct ehci_xfer *); | | 162 | Static void ehci_check_intr(ehci_softc_t *, struct ehci_xfer *); |
163 | Static void ehci_check_qh_intr(ehci_softc_t *, struct ehci_xfer *); | | 163 | Static void ehci_check_qh_intr(ehci_softc_t *, struct ehci_xfer *); |
164 | Static void ehci_check_itd_intr(ehci_softc_t *, struct ehci_xfer *); | | 164 | Static void ehci_check_itd_intr(ehci_softc_t *, struct ehci_xfer *); |
165 | Static void ehci_check_sitd_intr(ehci_softc_t *, struct ehci_xfer *); | | 165 | Static void ehci_check_sitd_intr(ehci_softc_t *, struct ehci_xfer *); |
166 | Static void ehci_idone(struct ehci_xfer *); | | 166 | Static void ehci_idone(struct ehci_xfer *); |
167 | Static void ehci_timeout(void *); | | 167 | Static void ehci_timeout(void *); |
168 | Static void ehci_timeout_task(void *); | | 168 | Static void ehci_timeout_task(void *); |
169 | Static void ehci_intrlist_timeout(void *); | | 169 | Static void ehci_intrlist_timeout(void *); |
170 | Static void ehci_doorbell(void *); | | 170 | Static void ehci_doorbell(void *); |
171 | Static void ehci_pcd(void *); | | 171 | Static void ehci_pcd(void *); |
172 | | | 172 | |
173 | Static usbd_xfer_handle ehci_allocx(struct usbd_bus *); | | 173 | Static usbd_xfer_handle ehci_allocx(struct usbd_bus *); |
174 | Static void ehci_freex(struct usbd_bus *, usbd_xfer_handle); | | 174 | Static void ehci_freex(struct usbd_bus *, usbd_xfer_handle); |
175 | Static void ehci_get_lock(struct usbd_bus *, kmutex_t **); | | 175 | Static void ehci_get_lock(struct usbd_bus *, kmutex_t **); |
176 | Static int ehci_roothub_ctrl(struct usbd_bus *, | | 176 | Static int ehci_roothub_ctrl(struct usbd_bus *, |
177 | usb_device_request_t *, void *, int); | | 177 | usb_device_request_t *, void *, int); |
178 | | | 178 | |
179 | Static usbd_status ehci_root_intr_transfer(usbd_xfer_handle); | | 179 | Static usbd_status ehci_root_intr_transfer(usbd_xfer_handle); |
180 | Static usbd_status ehci_root_intr_start(usbd_xfer_handle); | | 180 | Static usbd_status ehci_root_intr_start(usbd_xfer_handle); |
181 | Static void ehci_root_intr_abort(usbd_xfer_handle); | | 181 | Static void ehci_root_intr_abort(usbd_xfer_handle); |
182 | Static void ehci_root_intr_close(usbd_pipe_handle); | | 182 | Static void ehci_root_intr_close(usbd_pipe_handle); |
183 | Static void ehci_root_intr_done(usbd_xfer_handle); | | 183 | Static void ehci_root_intr_done(usbd_xfer_handle); |
184 | | | 184 | |
185 | Static usbd_status ehci_device_ctrl_transfer(usbd_xfer_handle); | | 185 | Static usbd_status ehci_device_ctrl_transfer(usbd_xfer_handle); |
186 | Static usbd_status ehci_device_ctrl_start(usbd_xfer_handle); | | 186 | Static usbd_status ehci_device_ctrl_start(usbd_xfer_handle); |
187 | Static void ehci_device_ctrl_abort(usbd_xfer_handle); | | 187 | Static void ehci_device_ctrl_abort(usbd_xfer_handle); |
188 | Static void ehci_device_ctrl_close(usbd_pipe_handle); | | 188 | Static void ehci_device_ctrl_close(usbd_pipe_handle); |
189 | Static void ehci_device_ctrl_done(usbd_xfer_handle); | | 189 | Static void ehci_device_ctrl_done(usbd_xfer_handle); |
190 | | | 190 | |
191 | Static usbd_status ehci_device_bulk_transfer(usbd_xfer_handle); | | 191 | Static usbd_status ehci_device_bulk_transfer(usbd_xfer_handle); |
192 | Static usbd_status ehci_device_bulk_start(usbd_xfer_handle); | | 192 | Static usbd_status ehci_device_bulk_start(usbd_xfer_handle); |
193 | Static void ehci_device_bulk_abort(usbd_xfer_handle); | | 193 | Static void ehci_device_bulk_abort(usbd_xfer_handle); |
194 | Static void ehci_device_bulk_close(usbd_pipe_handle); | | 194 | Static void ehci_device_bulk_close(usbd_pipe_handle); |
195 | Static void ehci_device_bulk_done(usbd_xfer_handle); | | 195 | Static void ehci_device_bulk_done(usbd_xfer_handle); |
196 | | | 196 | |
197 | Static usbd_status ehci_device_intr_transfer(usbd_xfer_handle); | | 197 | Static usbd_status ehci_device_intr_transfer(usbd_xfer_handle); |
198 | Static usbd_status ehci_device_intr_start(usbd_xfer_handle); | | 198 | Static usbd_status ehci_device_intr_start(usbd_xfer_handle); |
199 | Static void ehci_device_intr_abort(usbd_xfer_handle); | | 199 | Static void ehci_device_intr_abort(usbd_xfer_handle); |
200 | Static void ehci_device_intr_close(usbd_pipe_handle); | | 200 | Static void ehci_device_intr_close(usbd_pipe_handle); |
201 | Static void ehci_device_intr_done(usbd_xfer_handle); | | 201 | Static void ehci_device_intr_done(usbd_xfer_handle); |
202 | | | 202 | |
203 | Static usbd_status ehci_device_isoc_transfer(usbd_xfer_handle); | | 203 | Static usbd_status ehci_device_isoc_transfer(usbd_xfer_handle); |
204 | Static usbd_status ehci_device_isoc_start(usbd_xfer_handle); | | 204 | Static usbd_status ehci_device_isoc_start(usbd_xfer_handle); |
205 | Static void ehci_device_isoc_abort(usbd_xfer_handle); | | 205 | Static void ehci_device_isoc_abort(usbd_xfer_handle); |
206 | Static void ehci_device_isoc_close(usbd_pipe_handle); | | 206 | Static void ehci_device_isoc_close(usbd_pipe_handle); |
207 | Static void ehci_device_isoc_done(usbd_xfer_handle); | | 207 | Static void ehci_device_isoc_done(usbd_xfer_handle); |
208 | | | 208 | |
209 | Static usbd_status ehci_device_fs_isoc_transfer(usbd_xfer_handle); | | 209 | Static usbd_status ehci_device_fs_isoc_transfer(usbd_xfer_handle); |
210 | Static usbd_status ehci_device_fs_isoc_start(usbd_xfer_handle); | | 210 | Static usbd_status ehci_device_fs_isoc_start(usbd_xfer_handle); |
211 | Static void ehci_device_fs_isoc_abort(usbd_xfer_handle); | | 211 | Static void ehci_device_fs_isoc_abort(usbd_xfer_handle); |
212 | Static void ehci_device_fs_isoc_close(usbd_pipe_handle); | | 212 | Static void ehci_device_fs_isoc_close(usbd_pipe_handle); |
213 | Static void ehci_device_fs_isoc_done(usbd_xfer_handle); | | 213 | Static void ehci_device_fs_isoc_done(usbd_xfer_handle); |
214 | | | 214 | |
215 | Static void ehci_device_clear_toggle(usbd_pipe_handle); | | 215 | Static void ehci_device_clear_toggle(usbd_pipe_handle); |
216 | Static void ehci_noop(usbd_pipe_handle); | | 216 | Static void ehci_noop(usbd_pipe_handle); |
217 | | | 217 | |
218 | Static void ehci_disown(ehci_softc_t *, int, int); | | 218 | Static void ehci_disown(ehci_softc_t *, int, int); |
219 | | | 219 | |
220 | Static ehci_soft_qh_t *ehci_alloc_sqh(ehci_softc_t *); | | 220 | Static ehci_soft_qh_t *ehci_alloc_sqh(ehci_softc_t *); |
221 | Static void ehci_free_sqh(ehci_softc_t *, ehci_soft_qh_t *); | | 221 | Static void ehci_free_sqh(ehci_softc_t *, ehci_soft_qh_t *); |
222 | | | 222 | |
223 | Static ehci_soft_qtd_t *ehci_alloc_sqtd(ehci_softc_t *); | | 223 | Static ehci_soft_qtd_t *ehci_alloc_sqtd(ehci_softc_t *); |
224 | Static void ehci_free_sqtd(ehci_softc_t *, ehci_soft_qtd_t *); | | 224 | Static void ehci_free_sqtd(ehci_softc_t *, ehci_soft_qtd_t *); |
225 | Static usbd_status ehci_alloc_sqtd_chain(struct ehci_pipe *, | | 225 | Static usbd_status ehci_alloc_sqtd_chain(struct ehci_pipe *, |
226 | ehci_softc_t *, int, int, usbd_xfer_handle, | | 226 | ehci_softc_t *, int, int, usbd_xfer_handle, |
227 | ehci_soft_qtd_t **, ehci_soft_qtd_t **); | | 227 | ehci_soft_qtd_t **, ehci_soft_qtd_t **); |
228 | Static void ehci_free_sqtd_chain(ehci_softc_t *, ehci_soft_qtd_t *, | | 228 | Static void ehci_free_sqtd_chain(ehci_softc_t *, ehci_soft_qtd_t *, |
229 | ehci_soft_qtd_t *); | | 229 | ehci_soft_qtd_t *); |
230 | | | 230 | |
231 | Static ehci_soft_itd_t *ehci_alloc_itd(ehci_softc_t *); | | 231 | Static ehci_soft_itd_t *ehci_alloc_itd(ehci_softc_t *); |
232 | Static ehci_soft_sitd_t *ehci_alloc_sitd(ehci_softc_t *); | | 232 | Static ehci_soft_sitd_t *ehci_alloc_sitd(ehci_softc_t *); |
233 | Static void ehci_free_itd(ehci_softc_t *, ehci_soft_itd_t *); | | 233 | Static void ehci_free_itd(ehci_softc_t *, ehci_soft_itd_t *); |
234 | Static void ehci_free_sitd(ehci_softc_t *, ehci_soft_sitd_t *); | | 234 | Static void ehci_free_sitd(ehci_softc_t *, ehci_soft_sitd_t *); |
235 | Static void ehci_rem_free_itd_chain(ehci_softc_t *, | | 235 | Static void ehci_rem_free_itd_chain(ehci_softc_t *, |
236 | struct ehci_xfer *); | | 236 | struct ehci_xfer *); |
237 | Static void ehci_rem_free_sitd_chain(ehci_softc_t *, | | 237 | Static void ehci_rem_free_sitd_chain(ehci_softc_t *, |
238 | struct ehci_xfer *); | | 238 | struct ehci_xfer *); |
239 | Static void ehci_abort_isoc_xfer(usbd_xfer_handle, | | 239 | Static void ehci_abort_isoc_xfer(usbd_xfer_handle, |
240 | usbd_status); | | 240 | usbd_status); |
241 | | | 241 | |
242 | Static usbd_status ehci_device_request(usbd_xfer_handle); | | 242 | Static usbd_status ehci_device_request(usbd_xfer_handle); |
243 | | | 243 | |
244 | Static usbd_status ehci_device_setintr(ehci_softc_t *, ehci_soft_qh_t *, | | 244 | Static usbd_status ehci_device_setintr(ehci_softc_t *, ehci_soft_qh_t *, |
245 | int); | | 245 | int); |
246 | | | 246 | |
247 | Static void ehci_add_qh(ehci_softc_t *, ehci_soft_qh_t *, | | 247 | Static void ehci_add_qh(ehci_softc_t *, ehci_soft_qh_t *, |
248 | ehci_soft_qh_t *); | | 248 | ehci_soft_qh_t *); |
249 | Static void ehci_rem_qh(ehci_softc_t *, ehci_soft_qh_t *, | | 249 | Static void ehci_rem_qh(ehci_softc_t *, ehci_soft_qh_t *, |
250 | ehci_soft_qh_t *); | | 250 | ehci_soft_qh_t *); |
251 | Static void ehci_set_qh_qtd(ehci_soft_qh_t *, ehci_soft_qtd_t *); | | 251 | Static void ehci_set_qh_qtd(ehci_soft_qh_t *, ehci_soft_qtd_t *); |
252 | Static void ehci_sync_hc(ehci_softc_t *); | | 252 | Static void ehci_sync_hc(ehci_softc_t *); |
253 | | | 253 | |
254 | Static void ehci_close_pipe(usbd_pipe_handle, ehci_soft_qh_t *); | | 254 | Static void ehci_close_pipe(usbd_pipe_handle, ehci_soft_qh_t *); |
255 | Static void ehci_abort_xfer(usbd_xfer_handle, usbd_status); | | 255 | Static void ehci_abort_xfer(usbd_xfer_handle, usbd_status); |
256 | | | 256 | |
257 | #ifdef EHCI_DEBUG | | 257 | #ifdef EHCI_DEBUG |
258 | Static ehci_softc_t *theehci; | | 258 | Static ehci_softc_t *theehci; |
259 | void ehci_dump(void); | | 259 | void ehci_dump(void); |
260 | #endif | | 260 | #endif |
261 | | | 261 | |
262 | #ifdef EHCI_DEBUG | | 262 | #ifdef EHCI_DEBUG |
263 | Static void ehci_dump_regs(ehci_softc_t *); | | 263 | Static void ehci_dump_regs(ehci_softc_t *); |
264 | Static void ehci_dump_sqtds(ehci_soft_qtd_t *); | | 264 | Static void ehci_dump_sqtds(ehci_soft_qtd_t *); |
265 | Static void ehci_dump_sqtd(ehci_soft_qtd_t *); | | 265 | Static void ehci_dump_sqtd(ehci_soft_qtd_t *); |
266 | Static void ehci_dump_qtd(ehci_qtd_t *); | | 266 | Static void ehci_dump_qtd(ehci_qtd_t *); |
267 | Static void ehci_dump_sqh(ehci_soft_qh_t *); | | 267 | Static void ehci_dump_sqh(ehci_soft_qh_t *); |
268 | Static void ehci_dump_sitd(struct ehci_soft_itd *); | | 268 | Static void ehci_dump_sitd(struct ehci_soft_itd *); |
269 | Static void ehci_dump_itd(struct ehci_soft_itd *); | | 269 | Static void ehci_dump_itd(struct ehci_soft_itd *); |
270 | Static void ehci_dump_exfer(struct ehci_xfer *); | | 270 | Static void ehci_dump_exfer(struct ehci_xfer *); |
271 | #endif | | 271 | #endif |
272 | | | 272 | |
273 | #define EHCI_NULL htole32(EHCI_LINK_TERMINATE) | | 273 | #define EHCI_NULL htole32(EHCI_LINK_TERMINATE) |
274 | | | 274 | |
275 | #define ehci_add_intr_list(sc, ex) \ | | 275 | #define ehci_add_intr_list(sc, ex) \ |
276 | TAILQ_INSERT_TAIL(&(sc)->sc_intrhead, (ex), ex_next); | | 276 | TAILQ_INSERT_TAIL(&(sc)->sc_intrhead, (ex), ex_next); |
277 | #define ehci_del_intr_list(sc, ex) \ | | 277 | #define ehci_del_intr_list(sc, ex) \ |
278 | do { \ | | 278 | do { \ |
279 | TAILQ_REMOVE(&sc->sc_intrhead, (ex), ex_next); \ | | 279 | TAILQ_REMOVE(&sc->sc_intrhead, (ex), ex_next); \ |
280 | (ex)->ex_next.tqe_prev = NULL; \ | | 280 | (ex)->ex_next.tqe_prev = NULL; \ |
281 | } while (0) | | 281 | } while (0) |
282 | #define ehci_active_intr_list(ex) ((ex)->ex_next.tqe_prev != NULL) | | 282 | #define ehci_active_intr_list(ex) ((ex)->ex_next.tqe_prev != NULL) |
283 | | | 283 | |
284 | Static const struct usbd_bus_methods ehci_bus_methods = { | | 284 | Static const struct usbd_bus_methods ehci_bus_methods = { |
285 | .ubm_open = ehci_open, | | 285 | .ubm_open = ehci_open, |
286 | .ubm_softint = ehci_softintr, | | 286 | .ubm_softint = ehci_softintr, |
287 | .ubm_dopoll = ehci_poll, | | 287 | .ubm_dopoll = ehci_poll, |
288 | .ubm_allocx = ehci_allocx, | | 288 | .ubm_allocx = ehci_allocx, |
289 | .ubm_freex = ehci_freex, | | 289 | .ubm_freex = ehci_freex, |
290 | .ubm_getlock = ehci_get_lock, | | 290 | .ubm_getlock = ehci_get_lock, |
291 | .ubm_rhctrl = ehci_roothub_ctrl, | | 291 | .ubm_rhctrl = ehci_roothub_ctrl, |
292 | }; | | 292 | }; |
293 | | | 293 | |
294 | Static const struct usbd_pipe_methods ehci_root_intr_methods = { | | 294 | Static const struct usbd_pipe_methods ehci_root_intr_methods = { |
295 | .upm_transfer = ehci_root_intr_transfer, | | 295 | .upm_transfer = ehci_root_intr_transfer, |
296 | .upm_start = ehci_root_intr_start, | | 296 | .upm_start = ehci_root_intr_start, |
297 | .upm_abort = ehci_root_intr_abort, | | 297 | .upm_abort = ehci_root_intr_abort, |
298 | .upm_close = ehci_root_intr_close, | | 298 | .upm_close = ehci_root_intr_close, |
299 | .upm_cleartoggle = ehci_noop, | | 299 | .upm_cleartoggle = ehci_noop, |
300 | .upm_done = ehci_root_intr_done, | | 300 | .upm_done = ehci_root_intr_done, |
301 | }; | | 301 | }; |
302 | | | 302 | |
303 | Static const struct usbd_pipe_methods ehci_device_ctrl_methods = { | | 303 | Static const struct usbd_pipe_methods ehci_device_ctrl_methods = { |
304 | .upm_transfer = ehci_device_ctrl_transfer, | | 304 | .upm_transfer = ehci_device_ctrl_transfer, |
305 | .upm_start = ehci_device_ctrl_start, | | 305 | .upm_start = ehci_device_ctrl_start, |
306 | .upm_abort = ehci_device_ctrl_abort, | | 306 | .upm_abort = ehci_device_ctrl_abort, |
307 | .upm_close = ehci_device_ctrl_close, | | 307 | .upm_close = ehci_device_ctrl_close, |
308 | .upm_cleartoggle = ehci_noop, | | 308 | .upm_cleartoggle = ehci_noop, |
309 | .upm_done = ehci_device_ctrl_done, | | 309 | .upm_done = ehci_device_ctrl_done, |
310 | }; | | 310 | }; |
311 | | | 311 | |
312 | Static const struct usbd_pipe_methods ehci_device_intr_methods = { | | 312 | Static const struct usbd_pipe_methods ehci_device_intr_methods = { |
313 | .upm_transfer = ehci_device_intr_transfer, | | 313 | .upm_transfer = ehci_device_intr_transfer, |
314 | .upm_start = ehci_device_intr_start, | | 314 | .upm_start = ehci_device_intr_start, |
315 | .upm_abort = ehci_device_intr_abort, | | 315 | .upm_abort = ehci_device_intr_abort, |
316 | .upm_close = ehci_device_intr_close, | | 316 | .upm_close = ehci_device_intr_close, |
317 | .upm_cleartoggle = ehci_device_clear_toggle, | | 317 | .upm_cleartoggle = ehci_device_clear_toggle, |
318 | .upm_done = ehci_device_intr_done, | | 318 | .upm_done = ehci_device_intr_done, |
319 | }; | | 319 | }; |
320 | | | 320 | |
321 | Static const struct usbd_pipe_methods ehci_device_bulk_methods = { | | 321 | Static const struct usbd_pipe_methods ehci_device_bulk_methods = { |
322 | .upm_transfer = ehci_device_bulk_transfer, | | 322 | .upm_transfer = ehci_device_bulk_transfer, |
323 | .upm_start = ehci_device_bulk_start, | | 323 | .upm_start = ehci_device_bulk_start, |
324 | .upm_abort = ehci_device_bulk_abort, | | 324 | .upm_abort = ehci_device_bulk_abort, |
325 | .upm_close = ehci_device_bulk_close, | | 325 | .upm_close = ehci_device_bulk_close, |
326 | .upm_cleartoggle = ehci_device_clear_toggle, | | 326 | .upm_cleartoggle = ehci_device_clear_toggle, |
327 | .upm_done = ehci_device_bulk_done, | | 327 | .upm_done = ehci_device_bulk_done, |
328 | }; | | 328 | }; |
329 | | | 329 | |
330 | Static const struct usbd_pipe_methods ehci_device_isoc_methods = { | | 330 | Static const struct usbd_pipe_methods ehci_device_isoc_methods = { |
331 | .upm_transfer = ehci_device_isoc_transfer, | | 331 | .upm_transfer = ehci_device_isoc_transfer, |
332 | .upm_start = ehci_device_isoc_start, | | 332 | .upm_start = ehci_device_isoc_start, |
333 | .upm_abort = ehci_device_isoc_abort, | | 333 | .upm_abort = ehci_device_isoc_abort, |
334 | .upm_close = ehci_device_isoc_close, | | 334 | .upm_close = ehci_device_isoc_close, |
335 | .upm_cleartoggle = ehci_noop, | | 335 | .upm_cleartoggle = ehci_noop, |
336 | .upm_done = ehci_device_isoc_done, | | 336 | .upm_done = ehci_device_isoc_done, |
337 | }; | | 337 | }; |
338 | | | 338 | |
339 | Static const struct usbd_pipe_methods ehci_device_fs_isoc_methods = { | | 339 | Static const struct usbd_pipe_methods ehci_device_fs_isoc_methods = { |
340 | .upm_transfer = ehci_device_fs_isoc_transfer, | | 340 | .upm_transfer = ehci_device_fs_isoc_transfer, |
341 | .upm_start = ehci_device_fs_isoc_start, | | 341 | .upm_start = ehci_device_fs_isoc_start, |
342 | .upm_abort = ehci_device_fs_isoc_abort, | | 342 | .upm_abort = ehci_device_fs_isoc_abort, |
343 | .upm_close = ehci_device_fs_isoc_close, | | 343 | .upm_close = ehci_device_fs_isoc_close, |
344 | .upm_cleartoggle = ehci_noop, | | 344 | .upm_cleartoggle = ehci_noop, |
345 | .upm_done = ehci_device_fs_isoc_done, | | 345 | .upm_done = ehci_device_fs_isoc_done, |
346 | }; | | 346 | }; |
347 | | | 347 | |
348 | static const uint8_t revbits[EHCI_MAX_POLLRATE] = { | | 348 | static const uint8_t revbits[EHCI_MAX_POLLRATE] = { |
349 | 0x00,0x40,0x20,0x60,0x10,0x50,0x30,0x70,0x08,0x48,0x28,0x68,0x18,0x58,0x38,0x78, | | 349 | 0x00,0x40,0x20,0x60,0x10,0x50,0x30,0x70,0x08,0x48,0x28,0x68,0x18,0x58,0x38,0x78, |
350 | 0x04,0x44,0x24,0x64,0x14,0x54,0x34,0x74,0x0c,0x4c,0x2c,0x6c,0x1c,0x5c,0x3c,0x7c, | | 350 | 0x04,0x44,0x24,0x64,0x14,0x54,0x34,0x74,0x0c,0x4c,0x2c,0x6c,0x1c,0x5c,0x3c,0x7c, |
351 | 0x02,0x42,0x22,0x62,0x12,0x52,0x32,0x72,0x0a,0x4a,0x2a,0x6a,0x1a,0x5a,0x3a,0x7a, | | 351 | 0x02,0x42,0x22,0x62,0x12,0x52,0x32,0x72,0x0a,0x4a,0x2a,0x6a,0x1a,0x5a,0x3a,0x7a, |
352 | 0x06,0x46,0x26,0x66,0x16,0x56,0x36,0x76,0x0e,0x4e,0x2e,0x6e,0x1e,0x5e,0x3e,0x7e, | | 352 | 0x06,0x46,0x26,0x66,0x16,0x56,0x36,0x76,0x0e,0x4e,0x2e,0x6e,0x1e,0x5e,0x3e,0x7e, |
353 | 0x01,0x41,0x21,0x61,0x11,0x51,0x31,0x71,0x09,0x49,0x29,0x69,0x19,0x59,0x39,0x79, | | 353 | 0x01,0x41,0x21,0x61,0x11,0x51,0x31,0x71,0x09,0x49,0x29,0x69,0x19,0x59,0x39,0x79, |
354 | 0x05,0x45,0x25,0x65,0x15,0x55,0x35,0x75,0x0d,0x4d,0x2d,0x6d,0x1d,0x5d,0x3d,0x7d, | | 354 | 0x05,0x45,0x25,0x65,0x15,0x55,0x35,0x75,0x0d,0x4d,0x2d,0x6d,0x1d,0x5d,0x3d,0x7d, |
355 | 0x03,0x43,0x23,0x63,0x13,0x53,0x33,0x73,0x0b,0x4b,0x2b,0x6b,0x1b,0x5b,0x3b,0x7b, | | 355 | 0x03,0x43,0x23,0x63,0x13,0x53,0x33,0x73,0x0b,0x4b,0x2b,0x6b,0x1b,0x5b,0x3b,0x7b, |
356 | 0x07,0x47,0x27,0x67,0x17,0x57,0x37,0x77,0x0f,0x4f,0x2f,0x6f,0x1f,0x5f,0x3f,0x7f, | | 356 | 0x07,0x47,0x27,0x67,0x17,0x57,0x37,0x77,0x0f,0x4f,0x2f,0x6f,0x1f,0x5f,0x3f,0x7f, |
357 | }; | | 357 | }; |
358 | | | 358 | |
359 | int | | 359 | int |
360 | ehci_init(ehci_softc_t *sc) | | 360 | ehci_init(ehci_softc_t *sc) |
361 | { | | 361 | { |
362 | uint32_t vers, sparams, cparams, hcr; | | 362 | uint32_t vers, sparams, cparams, hcr; |
363 | u_int i; | | 363 | u_int i; |
364 | usbd_status err; | | 364 | usbd_status err; |
365 | ehci_soft_qh_t *sqh; | | 365 | ehci_soft_qh_t *sqh; |
366 | u_int ncomp; | | 366 | u_int ncomp; |
367 | | | 367 | |
368 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 368 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
369 | #ifdef EHCI_DEBUG | | 369 | #ifdef EHCI_DEBUG |
370 | theehci = sc; | | 370 | theehci = sc; |
371 | #endif | | 371 | #endif |
372 | | | 372 | |
373 | mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB); | | 373 | mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB); |
374 | mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED); | | 374 | mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED); |
375 | cv_init(&sc->sc_softwake_cv, "ehciab"); | | 375 | cv_init(&sc->sc_softwake_cv, "ehciab"); |
376 | cv_init(&sc->sc_doorbell, "ehcidi"); | | 376 | cv_init(&sc->sc_doorbell, "ehcidi"); |
377 | | | 377 | |
378 | sc->sc_xferpool = pool_cache_init(sizeof(struct ehci_xfer), 0, 0, 0, | | 378 | sc->sc_xferpool = pool_cache_init(sizeof(struct ehci_xfer), 0, 0, 0, |
379 | "ehcixfer", NULL, IPL_USB, NULL, NULL, NULL); | | 379 | "ehcixfer", NULL, IPL_USB, NULL, NULL, NULL); |
380 | | | 380 | |
381 | sc->sc_doorbell_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE, | | 381 | sc->sc_doorbell_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE, |
382 | ehci_doorbell, sc); | | 382 | ehci_doorbell, sc); |
383 | KASSERT(sc->sc_doorbell_si != NULL); | | 383 | KASSERT(sc->sc_doorbell_si != NULL); |
384 | sc->sc_pcd_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE, | | 384 | sc->sc_pcd_si = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE, |
385 | ehci_pcd, sc); | | 385 | ehci_pcd, sc); |
386 | KASSERT(sc->sc_pcd_si != NULL); | | 386 | KASSERT(sc->sc_pcd_si != NULL); |
387 | | | 387 | |
388 | sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH); | | 388 | sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH); |
389 | | | 389 | |
390 | vers = EREAD2(sc, EHCI_HCIVERSION); | | 390 | vers = EREAD2(sc, EHCI_HCIVERSION); |
391 | aprint_verbose("%s: EHCI version %x.%x\n", device_xname(sc->sc_dev), | | 391 | aprint_verbose("%s: EHCI version %x.%x\n", device_xname(sc->sc_dev), |
392 | vers >> 8, vers & 0xff); | | 392 | vers >> 8, vers & 0xff); |
393 | | | 393 | |
394 | sparams = EREAD4(sc, EHCI_HCSPARAMS); | | 394 | sparams = EREAD4(sc, EHCI_HCSPARAMS); |
395 | USBHIST_LOG(ehcidebug, "sparams=%#x", sparams, 0, 0, 0); | | 395 | USBHIST_LOG(ehcidebug, "sparams=%#x", sparams, 0, 0, 0); |
396 | sc->sc_npcomp = EHCI_HCS_N_PCC(sparams); | | 396 | sc->sc_npcomp = EHCI_HCS_N_PCC(sparams); |
397 | ncomp = EHCI_HCS_N_CC(sparams); | | 397 | ncomp = EHCI_HCS_N_CC(sparams); |
398 | if (ncomp != sc->sc_ncomp) { | | 398 | if (ncomp != sc->sc_ncomp) { |
399 | aprint_verbose("%s: wrong number of companions (%d != %d)\n", | | 399 | aprint_verbose("%s: wrong number of companions (%d != %d)\n", |
400 | device_xname(sc->sc_dev), ncomp, sc->sc_ncomp); | | 400 | device_xname(sc->sc_dev), ncomp, sc->sc_ncomp); |
401 | #if NOHCI == 0 || NUHCI == 0 | | 401 | #if NOHCI == 0 || NUHCI == 0 |
402 | aprint_error("%s: ohci or uhci probably not configured\n", | | 402 | aprint_error("%s: ohci or uhci probably not configured\n", |
403 | device_xname(sc->sc_dev)); | | 403 | device_xname(sc->sc_dev)); |
404 | #endif | | 404 | #endif |
405 | if (ncomp < sc->sc_ncomp) | | 405 | if (ncomp < sc->sc_ncomp) |
406 | sc->sc_ncomp = ncomp; | | 406 | sc->sc_ncomp = ncomp; |
407 | } | | 407 | } |
408 | if (sc->sc_ncomp > 0) { | | 408 | if (sc->sc_ncomp > 0) { |
409 | KASSERT(!(sc->sc_flags & EHCIF_ETTF)); | | 409 | KASSERT(!(sc->sc_flags & EHCIF_ETTF)); |
410 | aprint_normal("%s: companion controller%s, %d port%s each:", | | 410 | aprint_normal("%s: companion controller%s, %d port%s each:", |
411 | device_xname(sc->sc_dev), sc->sc_ncomp!=1 ? "s" : "", | | 411 | device_xname(sc->sc_dev), sc->sc_ncomp!=1 ? "s" : "", |
412 | EHCI_HCS_N_PCC(sparams), | | 412 | EHCI_HCS_N_PCC(sparams), |
413 | EHCI_HCS_N_PCC(sparams)!=1 ? "s" : ""); | | 413 | EHCI_HCS_N_PCC(sparams)!=1 ? "s" : ""); |
414 | for (i = 0; i < sc->sc_ncomp; i++) | | 414 | for (i = 0; i < sc->sc_ncomp; i++) |
415 | aprint_normal(" %s", device_xname(sc->sc_comps[i])); | | 415 | aprint_normal(" %s", device_xname(sc->sc_comps[i])); |
416 | aprint_normal("\n"); | | 416 | aprint_normal("\n"); |
417 | } | | 417 | } |
418 | sc->sc_noport = EHCI_HCS_N_PORTS(sparams); | | 418 | sc->sc_noport = EHCI_HCS_N_PORTS(sparams); |
419 | cparams = EREAD4(sc, EHCI_HCCPARAMS); | | 419 | cparams = EREAD4(sc, EHCI_HCCPARAMS); |
420 | USBHIST_LOG(ehcidebug, "cparams=%#x", cparams, 0, 0, 0); | | 420 | USBHIST_LOG(ehcidebug, "cparams=%#x", cparams, 0, 0, 0); |
421 | sc->sc_hasppc = EHCI_HCS_PPC(sparams); | | 421 | sc->sc_hasppc = EHCI_HCS_PPC(sparams); |
422 | | | 422 | |
423 | if (EHCI_HCC_64BIT(cparams)) { | | 423 | if (EHCI_HCC_64BIT(cparams)) { |
424 | /* MUST clear segment register if 64 bit capable. */ | | 424 | /* MUST clear segment register if 64 bit capable. */ |
425 | EWRITE4(sc, EHCI_CTRLDSSEGMENT, 0); | | 425 | EWRITE4(sc, EHCI_CTRLDSSEGMENT, 0); |
426 | } | | 426 | } |
427 | | | 427 | |
428 | sc->sc_bus.ub_revision = USBREV_2_0; | | 428 | sc->sc_bus.ub_revision = USBREV_2_0; |
429 | sc->sc_bus.ub_usedma = true; | | 429 | sc->sc_bus.ub_usedma = true; |
430 | sc->sc_bus.ub_dmaflags = USBMALLOC_MULTISEG; | | 430 | sc->sc_bus.ub_dmaflags = USBMALLOC_MULTISEG; |
431 | | | 431 | |
432 | /* Reset the controller */ | | 432 | /* Reset the controller */ |
433 | USBHIST_LOG(ehcidebug, "resetting", 0, 0, 0, 0); | | 433 | USBHIST_LOG(ehcidebug, "resetting", 0, 0, 0, 0); |
434 | EOWRITE4(sc, EHCI_USBCMD, 0); /* Halt controller */ | | 434 | EOWRITE4(sc, EHCI_USBCMD, 0); /* Halt controller */ |
435 | usb_delay_ms(&sc->sc_bus, 1); | | 435 | usb_delay_ms(&sc->sc_bus, 1); |
436 | EOWRITE4(sc, EHCI_USBCMD, EHCI_CMD_HCRESET); | | 436 | EOWRITE4(sc, EHCI_USBCMD, EHCI_CMD_HCRESET); |
437 | for (i = 0; i < 100; i++) { | | 437 | for (i = 0; i < 100; i++) { |
438 | usb_delay_ms(&sc->sc_bus, 1); | | 438 | usb_delay_ms(&sc->sc_bus, 1); |
439 | hcr = EOREAD4(sc, EHCI_USBCMD) & EHCI_CMD_HCRESET; | | 439 | hcr = EOREAD4(sc, EHCI_USBCMD) & EHCI_CMD_HCRESET; |
440 | if (!hcr) | | 440 | if (!hcr) |
441 | break; | | 441 | break; |
442 | } | | 442 | } |
443 | if (hcr) { | | 443 | if (hcr) { |
444 | aprint_error("%s: reset timeout\n", device_xname(sc->sc_dev)); | | 444 | aprint_error("%s: reset timeout\n", device_xname(sc->sc_dev)); |
445 | return EIO; | | 445 | return EIO; |
446 | } | | 446 | } |
447 | if (sc->sc_vendor_init) | | 447 | if (sc->sc_vendor_init) |
448 | sc->sc_vendor_init(sc); | | 448 | sc->sc_vendor_init(sc); |
449 | | | 449 | |
450 | /* | | 450 | /* |
451 | * If we are doing embedded transaction translation function, force | | 451 | * If we are doing embedded transaction translation function, force |
452 | * the controller to host mode. | | 452 | * the controller to host mode. |
453 | */ | | 453 | */ |
454 | if (sc->sc_flags & EHCIF_ETTF) { | | 454 | if (sc->sc_flags & EHCIF_ETTF) { |
455 | uint32_t usbmode = EREAD4(sc, EHCI_USBMODE); | | 455 | uint32_t usbmode = EREAD4(sc, EHCI_USBMODE); |
456 | usbmode &= ~EHCI_USBMODE_CM; | | 456 | usbmode &= ~EHCI_USBMODE_CM; |
457 | usbmode |= EHCI_USBMODE_CM_HOST; | | 457 | usbmode |= EHCI_USBMODE_CM_HOST; |
458 | EWRITE4(sc, EHCI_USBMODE, usbmode); | | 458 | EWRITE4(sc, EHCI_USBMODE, usbmode); |
459 | } | | 459 | } |
460 | | | 460 | |
461 | /* XXX need proper intr scheduling */ | | 461 | /* XXX need proper intr scheduling */ |
462 | sc->sc_rand = 96; | | 462 | sc->sc_rand = 96; |
463 | | | 463 | |
464 | /* frame list size at default, read back what we got and use that */ | | 464 | /* frame list size at default, read back what we got and use that */ |
465 | switch (EHCI_CMD_FLS(EOREAD4(sc, EHCI_USBCMD))) { | | 465 | switch (EHCI_CMD_FLS(EOREAD4(sc, EHCI_USBCMD))) { |
466 | case 0: sc->sc_flsize = 1024; break; | | 466 | case 0: sc->sc_flsize = 1024; break; |
467 | case 1: sc->sc_flsize = 512; break; | | 467 | case 1: sc->sc_flsize = 512; break; |
468 | case 2: sc->sc_flsize = 256; break; | | 468 | case 2: sc->sc_flsize = 256; break; |
469 | case 3: return EIO; | | 469 | case 3: return EIO; |
470 | } | | 470 | } |
471 | err = usb_allocmem(&sc->sc_bus, sc->sc_flsize * sizeof(ehci_link_t), | | 471 | err = usb_allocmem(&sc->sc_bus, sc->sc_flsize * sizeof(ehci_link_t), |
472 | EHCI_FLALIGN_ALIGN, &sc->sc_fldma); | | 472 | EHCI_FLALIGN_ALIGN, &sc->sc_fldma); |
473 | if (err) | | 473 | if (err) |
474 | return err; | | 474 | return err; |
475 | USBHIST_LOG(ehcidebug, "flsize=%d", sc->sc_flsize, 0, 0, 0); | | 475 | USBHIST_LOG(ehcidebug, "flsize=%d", sc->sc_flsize, 0, 0, 0); |
476 | sc->sc_flist = KERNADDR(&sc->sc_fldma, 0); | | 476 | sc->sc_flist = KERNADDR(&sc->sc_fldma, 0); |
477 | | | 477 | |
478 | for (i = 0; i < sc->sc_flsize; i++) { | | 478 | for (i = 0; i < sc->sc_flsize; i++) { |
479 | sc->sc_flist[i] = EHCI_NULL; | | 479 | sc->sc_flist[i] = EHCI_NULL; |
480 | } | | 480 | } |
481 | | | 481 | |
482 | EOWRITE4(sc, EHCI_PERIODICLISTBASE, DMAADDR(&sc->sc_fldma, 0)); | | 482 | EOWRITE4(sc, EHCI_PERIODICLISTBASE, DMAADDR(&sc->sc_fldma, 0)); |
483 | | | 483 | |
484 | sc->sc_softitds = kmem_zalloc(sc->sc_flsize * sizeof(ehci_soft_itd_t *), | | 484 | sc->sc_softitds = kmem_zalloc(sc->sc_flsize * sizeof(ehci_soft_itd_t *), |
485 | KM_SLEEP); | | 485 | KM_SLEEP); |
486 | if (sc->sc_softitds == NULL) | | 486 | if (sc->sc_softitds == NULL) |
487 | return ENOMEM; | | 487 | return ENOMEM; |
488 | LIST_INIT(&sc->sc_freeitds); | | 488 | LIST_INIT(&sc->sc_freeitds); |
489 | LIST_INIT(&sc->sc_freesitds); | | 489 | LIST_INIT(&sc->sc_freesitds); |
490 | TAILQ_INIT(&sc->sc_intrhead); | | 490 | TAILQ_INIT(&sc->sc_intrhead); |
491 | | | 491 | |
492 | /* Set up the bus struct. */ | | 492 | /* Set up the bus struct. */ |
493 | sc->sc_bus.ub_methods = &ehci_bus_methods; | | 493 | sc->sc_bus.ub_methods = &ehci_bus_methods; |
494 | sc->sc_bus.ub_pipesize= sizeof(struct ehci_pipe); | | 494 | sc->sc_bus.ub_pipesize= sizeof(struct ehci_pipe); |
495 | | | 495 | |
496 | sc->sc_eintrs = EHCI_NORMAL_INTRS; | | 496 | sc->sc_eintrs = EHCI_NORMAL_INTRS; |
497 | | | 497 | |
498 | /* | | 498 | /* |
499 | * Allocate the interrupt dummy QHs. These are arranged to give poll | | 499 | * Allocate the interrupt dummy QHs. These are arranged to give poll |
500 | * intervals that are powers of 2 times 1ms. | | 500 | * intervals that are powers of 2 times 1ms. |
501 | */ | | 501 | */ |
502 | for (i = 0; i < EHCI_INTRQHS; i++) { | | 502 | for (i = 0; i < EHCI_INTRQHS; i++) { |
503 | sqh = ehci_alloc_sqh(sc); | | 503 | sqh = ehci_alloc_sqh(sc); |
504 | if (sqh == NULL) { | | 504 | if (sqh == NULL) { |
505 | err = ENOMEM; | | 505 | err = ENOMEM; |
506 | goto bad1; | | 506 | goto bad1; |
507 | } | | 507 | } |
508 | sc->sc_islots[i].sqh = sqh; | | 508 | sc->sc_islots[i].sqh = sqh; |
509 | } | | 509 | } |
510 | for (i = 0; i < EHCI_INTRQHS; i++) { | | 510 | for (i = 0; i < EHCI_INTRQHS; i++) { |
511 | sqh = sc->sc_islots[i].sqh; | | 511 | sqh = sc->sc_islots[i].sqh; |
512 | if (i == 0) { | | 512 | if (i == 0) { |
513 | /* The last (1ms) QH terminates. */ | | 513 | /* The last (1ms) QH terminates. */ |
514 | sqh->qh.qh_link = EHCI_NULL; | | 514 | sqh->qh.qh_link = EHCI_NULL; |
515 | sqh->next = NULL; | | 515 | sqh->next = NULL; |
516 | } else { | | 516 | } else { |
517 | /* Otherwise the next QH has half the poll interval */ | | 517 | /* Otherwise the next QH has half the poll interval */ |
518 | sqh->next = sc->sc_islots[(i + 1) / 2 - 1].sqh; | | 518 | sqh->next = sc->sc_islots[(i + 1) / 2 - 1].sqh; |
519 | sqh->qh.qh_link = htole32(sqh->next->physaddr | | | 519 | sqh->qh.qh_link = htole32(sqh->next->physaddr | |
520 | EHCI_LINK_QH); | | 520 | EHCI_LINK_QH); |
521 | } | | 521 | } |
522 | sqh->qh.qh_endp = htole32(EHCI_QH_SET_EPS(EHCI_QH_SPEED_HIGH)); | | 522 | sqh->qh.qh_endp = htole32(EHCI_QH_SET_EPS(EHCI_QH_SPEED_HIGH)); |
523 | sqh->qh.qh_curqtd = EHCI_NULL; | | 523 | sqh->qh.qh_curqtd = EHCI_NULL; |
524 | sqh->next = NULL; | | 524 | sqh->next = NULL; |
525 | sqh->qh.qh_qtd.qtd_next = EHCI_NULL; | | 525 | sqh->qh.qh_qtd.qtd_next = EHCI_NULL; |
526 | sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL; | | 526 | sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL; |
527 | sqh->qh.qh_qtd.qtd_status = htole32(EHCI_QTD_HALTED); | | 527 | sqh->qh.qh_qtd.qtd_status = htole32(EHCI_QTD_HALTED); |
528 | sqh->sqtd = NULL; | | 528 | sqh->sqtd = NULL; |
529 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), | | 529 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), |
530 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 530 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
531 | } | | 531 | } |
532 | /* Point the frame list at the last level (128ms). */ | | 532 | /* Point the frame list at the last level (128ms). */ |
533 | for (i = 0; i < sc->sc_flsize; i++) { | | 533 | for (i = 0; i < sc->sc_flsize; i++) { |
534 | int j; | | 534 | int j; |
535 | | | 535 | |
536 | j = (i & ~(EHCI_MAX_POLLRATE-1)) | | | 536 | j = (i & ~(EHCI_MAX_POLLRATE-1)) | |
537 | revbits[i & (EHCI_MAX_POLLRATE-1)]; | | 537 | revbits[i & (EHCI_MAX_POLLRATE-1)]; |
538 | sc->sc_flist[j] = htole32(EHCI_LINK_QH | | | 538 | sc->sc_flist[j] = htole32(EHCI_LINK_QH | |
539 | sc->sc_islots[EHCI_IQHIDX(EHCI_IPOLLRATES - 1, | | 539 | sc->sc_islots[EHCI_IQHIDX(EHCI_IPOLLRATES - 1, |
540 | i)].sqh->physaddr); | | 540 | i)].sqh->physaddr); |
541 | } | | 541 | } |
542 | usb_syncmem(&sc->sc_fldma, 0, sc->sc_flsize * sizeof(ehci_link_t), | | 542 | usb_syncmem(&sc->sc_fldma, 0, sc->sc_flsize * sizeof(ehci_link_t), |
543 | BUS_DMASYNC_PREWRITE); | | 543 | BUS_DMASYNC_PREWRITE); |
544 | | | 544 | |
545 | /* Allocate dummy QH that starts the async list. */ | | 545 | /* Allocate dummy QH that starts the async list. */ |
546 | sqh = ehci_alloc_sqh(sc); | | 546 | sqh = ehci_alloc_sqh(sc); |
547 | if (sqh == NULL) { | | 547 | if (sqh == NULL) { |
548 | err = ENOMEM; | | 548 | err = ENOMEM; |
549 | goto bad1; | | 549 | goto bad1; |
550 | } | | 550 | } |
551 | /* Fill the QH */ | | 551 | /* Fill the QH */ |
552 | sqh->qh.qh_endp = | | 552 | sqh->qh.qh_endp = |
553 | htole32(EHCI_QH_SET_EPS(EHCI_QH_SPEED_HIGH) | EHCI_QH_HRECL); | | 553 | htole32(EHCI_QH_SET_EPS(EHCI_QH_SPEED_HIGH) | EHCI_QH_HRECL); |
554 | sqh->qh.qh_link = | | 554 | sqh->qh.qh_link = |
555 | htole32(sqh->physaddr | EHCI_LINK_QH); | | 555 | htole32(sqh->physaddr | EHCI_LINK_QH); |
556 | sqh->qh.qh_curqtd = EHCI_NULL; | | 556 | sqh->qh.qh_curqtd = EHCI_NULL; |
557 | sqh->next = NULL; | | 557 | sqh->next = NULL; |
558 | /* Fill the overlay qTD */ | | 558 | /* Fill the overlay qTD */ |
559 | sqh->qh.qh_qtd.qtd_next = EHCI_NULL; | | 559 | sqh->qh.qh_qtd.qtd_next = EHCI_NULL; |
560 | sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL; | | 560 | sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL; |
561 | sqh->qh.qh_qtd.qtd_status = htole32(EHCI_QTD_HALTED); | | 561 | sqh->qh.qh_qtd.qtd_status = htole32(EHCI_QTD_HALTED); |
562 | sqh->sqtd = NULL; | | 562 | sqh->sqtd = NULL; |
563 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), | | 563 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), |
564 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 564 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
565 | #ifdef EHCI_DEBUG | | 565 | #ifdef EHCI_DEBUG |
566 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); | | 566 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); |
567 | ehci_dump_sqh(sqh); | | 567 | ehci_dump_sqh(sqh); |
568 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); | | 568 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); |
569 | #endif | | 569 | #endif |
570 | | | 570 | |
571 | /* Point to async list */ | | 571 | /* Point to async list */ |
572 | sc->sc_async_head = sqh; | | 572 | sc->sc_async_head = sqh; |
573 | EOWRITE4(sc, EHCI_ASYNCLISTADDR, sqh->physaddr | EHCI_LINK_QH); | | 573 | EOWRITE4(sc, EHCI_ASYNCLISTADDR, sqh->physaddr | EHCI_LINK_QH); |
574 | | | 574 | |
575 | callout_init(&sc->sc_tmo_intrlist, CALLOUT_MPSAFE); | | 575 | callout_init(&sc->sc_tmo_intrlist, CALLOUT_MPSAFE); |
576 | | | 576 | |
577 | /* Turn on controller */ | | 577 | /* Turn on controller */ |
578 | EOWRITE4(sc, EHCI_USBCMD, | | 578 | EOWRITE4(sc, EHCI_USBCMD, |
579 | EHCI_CMD_ITC_2 | /* 2 microframes interrupt delay */ | | 579 | EHCI_CMD_ITC_2 | /* 2 microframes interrupt delay */ |
580 | (EOREAD4(sc, EHCI_USBCMD) & EHCI_CMD_FLS_M) | | | 580 | (EOREAD4(sc, EHCI_USBCMD) & EHCI_CMD_FLS_M) | |
581 | EHCI_CMD_ASE | | | 581 | EHCI_CMD_ASE | |
582 | EHCI_CMD_PSE | | | 582 | EHCI_CMD_PSE | |
583 | EHCI_CMD_RS); | | 583 | EHCI_CMD_RS); |
584 | | | 584 | |
585 | /* Take over port ownership */ | | 585 | /* Take over port ownership */ |
586 | EOWRITE4(sc, EHCI_CONFIGFLAG, EHCI_CONF_CF); | | 586 | EOWRITE4(sc, EHCI_CONFIGFLAG, EHCI_CONF_CF); |
587 | | | 587 | |
588 | for (i = 0; i < 100; i++) { | | 588 | for (i = 0; i < 100; i++) { |
589 | usb_delay_ms(&sc->sc_bus, 1); | | 589 | usb_delay_ms(&sc->sc_bus, 1); |
590 | hcr = EOREAD4(sc, EHCI_USBSTS) & EHCI_STS_HCH; | | 590 | hcr = EOREAD4(sc, EHCI_USBSTS) & EHCI_STS_HCH; |
591 | if (!hcr) | | 591 | if (!hcr) |
592 | break; | | 592 | break; |
593 | } | | 593 | } |
594 | if (hcr) { | | 594 | if (hcr) { |
595 | aprint_error("%s: run timeout\n", device_xname(sc->sc_dev)); | | 595 | aprint_error("%s: run timeout\n", device_xname(sc->sc_dev)); |
596 | return EIO; | | 596 | return EIO; |
597 | } | | 597 | } |
598 | | | 598 | |
599 | /* Enable interrupts */ | | 599 | /* Enable interrupts */ |
600 | USBHIST_LOG(ehcidebug, "enabling interupts", 0, 0, 0, 0); | | 600 | USBHIST_LOG(ehcidebug, "enabling interupts", 0, 0, 0, 0); |
601 | EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs); | | 601 | EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs); |
602 | | | 602 | |
603 | return 0; | | 603 | return 0; |
604 | | | 604 | |
605 | #if 0 | | 605 | #if 0 |
606 | bad2: | | 606 | bad2: |
607 | ehci_free_sqh(sc, sc->sc_async_head); | | 607 | ehci_free_sqh(sc, sc->sc_async_head); |
608 | #endif | | 608 | #endif |
609 | bad1: | | 609 | bad1: |
610 | usb_freemem(&sc->sc_bus, &sc->sc_fldma); | | 610 | usb_freemem(&sc->sc_bus, &sc->sc_fldma); |
611 | return err; | | 611 | return err; |
612 | } | | 612 | } |
613 | | | 613 | |
614 | int | | 614 | int |
615 | ehci_intr(void *v) | | 615 | ehci_intr(void *v) |
616 | { | | 616 | { |
617 | ehci_softc_t *sc = v; | | 617 | ehci_softc_t *sc = v; |
618 | int ret = 0; | | 618 | int ret = 0; |
619 | | | 619 | |
620 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 620 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
621 | | | 621 | |
622 | if (sc == NULL) | | 622 | if (sc == NULL) |
623 | return 0; | | 623 | return 0; |
624 | | | 624 | |
625 | mutex_spin_enter(&sc->sc_intr_lock); | | 625 | mutex_spin_enter(&sc->sc_intr_lock); |
626 | | | 626 | |
627 | if (sc->sc_dying || !device_has_power(sc->sc_dev)) | | 627 | if (sc->sc_dying || !device_has_power(sc->sc_dev)) |
628 | goto done; | | 628 | goto done; |
629 | | | 629 | |
630 | /* If we get an interrupt while polling, then just ignore it. */ | | 630 | /* If we get an interrupt while polling, then just ignore it. */ |
631 | if (sc->sc_bus.ub_usepolling) { | | 631 | if (sc->sc_bus.ub_usepolling) { |
632 | uint32_t intrs = EHCI_STS_INTRS(EOREAD4(sc, EHCI_USBSTS)); | | 632 | uint32_t intrs = EHCI_STS_INTRS(EOREAD4(sc, EHCI_USBSTS)); |
633 | | | 633 | |
634 | if (intrs) | | 634 | if (intrs) |
635 | EOWRITE4(sc, EHCI_USBSTS, intrs); /* Acknowledge */ | | 635 | EOWRITE4(sc, EHCI_USBSTS, intrs); /* Acknowledge */ |
636 | USBHIST_LOGN(ehcidebug, 16, | | 636 | USBHIST_LOGN(ehcidebug, 16, |
637 | "ignored interrupt while polling", 0, 0, 0, 0); | | 637 | "ignored interrupt while polling", 0, 0, 0, 0); |
638 | goto done; | | 638 | goto done; |
639 | } | | 639 | } |
640 | | | 640 | |
641 | ret = ehci_intr1(sc); | | 641 | ret = ehci_intr1(sc); |
642 | | | 642 | |
643 | done: | | 643 | done: |
644 | mutex_spin_exit(&sc->sc_intr_lock); | | 644 | mutex_spin_exit(&sc->sc_intr_lock); |
645 | return ret; | | 645 | return ret; |
646 | } | | 646 | } |
647 | | | 647 | |
648 | Static int | | 648 | Static int |
649 | ehci_intr1(ehci_softc_t *sc) | | 649 | ehci_intr1(ehci_softc_t *sc) |
650 | { | | 650 | { |
651 | uint32_t intrs, eintrs; | | 651 | uint32_t intrs, eintrs; |
652 | | | 652 | |
653 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 653 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
654 | | | 654 | |
655 | /* In case the interrupt occurs before initialization has completed. */ | | 655 | /* In case the interrupt occurs before initialization has completed. */ |
656 | if (sc == NULL) { | | 656 | if (sc == NULL) { |
657 | #ifdef DIAGNOSTIC | | 657 | #ifdef DIAGNOSTIC |
658 | printf("ehci_intr1: sc == NULL\n"); | | 658 | printf("ehci_intr1: sc == NULL\n"); |
659 | #endif | | 659 | #endif |
660 | return 0; | | 660 | return 0; |
661 | } | | 661 | } |
662 | | | 662 | |
663 | KASSERT(mutex_owned(&sc->sc_intr_lock)); | | 663 | KASSERT(mutex_owned(&sc->sc_intr_lock)); |
664 | | | 664 | |
665 | intrs = EHCI_STS_INTRS(EOREAD4(sc, EHCI_USBSTS)); | | 665 | intrs = EHCI_STS_INTRS(EOREAD4(sc, EHCI_USBSTS)); |
666 | if (!intrs) | | 666 | if (!intrs) |
667 | return 0; | | 667 | return 0; |
668 | | | 668 | |
669 | eintrs = intrs & sc->sc_eintrs; | | 669 | eintrs = intrs & sc->sc_eintrs; |
670 | USBHIST_LOG(ehcidebug, "sc=%p intrs=%#x(%#x) eintrs=%#x", | | 670 | USBHIST_LOG(ehcidebug, "sc=%p intrs=%#x(%#x) eintrs=%#x", |
671 | sc, intrs, EOREAD4(sc, EHCI_USBSTS), eintrs); | | 671 | sc, intrs, EOREAD4(sc, EHCI_USBSTS), eintrs); |
672 | if (!eintrs) | | 672 | if (!eintrs) |
673 | return 0; | | 673 | return 0; |
674 | | | 674 | |
675 | EOWRITE4(sc, EHCI_USBSTS, intrs); /* Acknowledge */ | | 675 | EOWRITE4(sc, EHCI_USBSTS, intrs); /* Acknowledge */ |
676 | if (eintrs & EHCI_STS_IAA) { | | 676 | if (eintrs & EHCI_STS_IAA) { |
677 | USBHIST_LOG(ehcidebug, "door bell", 0, 0, 0, 0); | | 677 | USBHIST_LOG(ehcidebug, "door bell", 0, 0, 0, 0); |
678 | kpreempt_disable(); | | 678 | kpreempt_disable(); |
679 | KASSERT(sc->sc_doorbell_si != NULL); | | 679 | KASSERT(sc->sc_doorbell_si != NULL); |
680 | softint_schedule(sc->sc_doorbell_si); | | 680 | softint_schedule(sc->sc_doorbell_si); |
681 | kpreempt_enable(); | | 681 | kpreempt_enable(); |
682 | eintrs &= ~EHCI_STS_IAA; | | 682 | eintrs &= ~EHCI_STS_IAA; |
683 | } | | 683 | } |
684 | if (eintrs & (EHCI_STS_INT | EHCI_STS_ERRINT)) { | | 684 | if (eintrs & (EHCI_STS_INT | EHCI_STS_ERRINT)) { |
685 | USBHIST_LOG(ehcidebug, "INT=%d ERRINT=%d", | | 685 | USBHIST_LOG(ehcidebug, "INT=%d ERRINT=%d", |
686 | eintrs & EHCI_STS_INT ? 1 : 0, | | 686 | eintrs & EHCI_STS_INT ? 1 : 0, |
687 | eintrs & EHCI_STS_ERRINT ? 1 : 0, 0, 0); | | 687 | eintrs & EHCI_STS_ERRINT ? 1 : 0, 0, 0); |
688 | usb_schedsoftintr(&sc->sc_bus); | | 688 | usb_schedsoftintr(&sc->sc_bus); |
689 | eintrs &= ~(EHCI_STS_INT | EHCI_STS_ERRINT); | | 689 | eintrs &= ~(EHCI_STS_INT | EHCI_STS_ERRINT); |
690 | } | | 690 | } |
691 | if (eintrs & EHCI_STS_HSE) { | | 691 | if (eintrs & EHCI_STS_HSE) { |
692 | printf("%s: unrecoverable error, controller halted\n", | | 692 | printf("%s: unrecoverable error, controller halted\n", |
693 | device_xname(sc->sc_dev)); | | 693 | device_xname(sc->sc_dev)); |
694 | /* XXX what else */ | | 694 | /* XXX what else */ |
695 | } | | 695 | } |
696 | if (eintrs & EHCI_STS_PCD) { | | 696 | if (eintrs & EHCI_STS_PCD) { |
697 | kpreempt_disable(); | | 697 | kpreempt_disable(); |
698 | KASSERT(sc->sc_pcd_si != NULL); | | 698 | KASSERT(sc->sc_pcd_si != NULL); |
699 | softint_schedule(sc->sc_pcd_si); | | 699 | softint_schedule(sc->sc_pcd_si); |
700 | kpreempt_enable(); | | 700 | kpreempt_enable(); |
701 | eintrs &= ~EHCI_STS_PCD; | | 701 | eintrs &= ~EHCI_STS_PCD; |
702 | } | | 702 | } |
703 | | | 703 | |
704 | if (eintrs != 0) { | | 704 | if (eintrs != 0) { |
705 | /* Block unprocessed interrupts. */ | | 705 | /* Block unprocessed interrupts. */ |
706 | sc->sc_eintrs &= ~eintrs; | | 706 | sc->sc_eintrs &= ~eintrs; |
707 | EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs); | | 707 | EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs); |
708 | printf("%s: blocking intrs 0x%x\n", | | 708 | printf("%s: blocking intrs 0x%x\n", |
709 | device_xname(sc->sc_dev), eintrs); | | 709 | device_xname(sc->sc_dev), eintrs); |
710 | } | | 710 | } |
711 | | | 711 | |
712 | return 1; | | 712 | return 1; |
713 | } | | 713 | } |
714 | | | 714 | |
715 | Static void | | 715 | Static void |
716 | ehci_doorbell(void *addr) | | 716 | ehci_doorbell(void *addr) |
717 | { | | 717 | { |
718 | ehci_softc_t *sc = addr; | | 718 | ehci_softc_t *sc = addr; |
719 | | | 719 | |
720 | mutex_enter(&sc->sc_lock); | | 720 | mutex_enter(&sc->sc_lock); |
721 | cv_broadcast(&sc->sc_doorbell); | | 721 | cv_broadcast(&sc->sc_doorbell); |
722 | mutex_exit(&sc->sc_lock); | | 722 | mutex_exit(&sc->sc_lock); |
723 | } | | 723 | } |
724 | | | 724 | |
725 | Static void | | 725 | Static void |
726 | ehci_pcd(void *addr) | | 726 | ehci_pcd(void *addr) |
727 | { | | 727 | { |
728 | ehci_softc_t *sc = addr; | | 728 | ehci_softc_t *sc = addr; |
729 | usbd_xfer_handle xfer; | | 729 | usbd_xfer_handle xfer; |
730 | u_char *p; | | 730 | u_char *p; |
731 | int i, m; | | 731 | int i, m; |
732 | | | 732 | |
733 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 733 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
734 | | | 734 | |
735 | mutex_enter(&sc->sc_lock); | | 735 | mutex_enter(&sc->sc_lock); |
736 | xfer = sc->sc_intrxfer; | | 736 | xfer = sc->sc_intrxfer; |
737 | | | 737 | |
738 | if (xfer == NULL) { | | 738 | if (xfer == NULL) { |
739 | /* Just ignore the change. */ | | 739 | /* Just ignore the change. */ |
740 | goto done; | | 740 | goto done; |
741 | } | | 741 | } |
742 | | | 742 | |
743 | p = xfer->ux_buf; | | 743 | p = xfer->ux_buf; |
744 | m = min(sc->sc_noport, xfer->ux_length * 8 - 1); | | 744 | m = min(sc->sc_noport, xfer->ux_length * 8 - 1); |
745 | memset(p, 0, xfer->ux_length); | | 745 | memset(p, 0, xfer->ux_length); |
746 | for (i = 1; i <= m; i++) { | | 746 | for (i = 1; i <= m; i++) { |
747 | /* Pick out CHANGE bits from the status reg. */ | | 747 | /* Pick out CHANGE bits from the status reg. */ |
748 | if (EOREAD4(sc, EHCI_PORTSC(i)) & EHCI_PS_CLEAR) | | 748 | if (EOREAD4(sc, EHCI_PORTSC(i)) & EHCI_PS_CLEAR) |
749 | p[i/8] |= 1 << (i%8); | | 749 | p[i/8] |= 1 << (i%8); |
750 | if (i % 8 == 7) | | 750 | if (i % 8 == 7) |
751 | USBHIST_LOG(ehcidebug, "change(%d)=0x%02x", i / 8, | | 751 | USBHIST_LOG(ehcidebug, "change(%d)=0x%02x", i / 8, |
752 | p[i/8], 0, 0); | | 752 | p[i/8], 0, 0); |
753 | } | | 753 | } |
754 | xfer->ux_actlen = xfer->ux_length; | | 754 | xfer->ux_actlen = xfer->ux_length; |
755 | xfer->ux_status = USBD_NORMAL_COMPLETION; | | 755 | xfer->ux_status = USBD_NORMAL_COMPLETION; |
756 | | | 756 | |
757 | usb_transfer_complete(xfer); | | 757 | usb_transfer_complete(xfer); |
758 | | | 758 | |
759 | done: | | 759 | done: |
760 | mutex_exit(&sc->sc_lock); | | 760 | mutex_exit(&sc->sc_lock); |
761 | } | | 761 | } |
762 | | | 762 | |
763 | Static void | | 763 | Static void |
764 | ehci_softintr(void *v) | | 764 | ehci_softintr(void *v) |
765 | { | | 765 | { |
766 | struct usbd_bus *bus = v; | | 766 | struct usbd_bus *bus = v; |
767 | ehci_softc_t *sc = bus->ub_hcpriv; | | 767 | ehci_softc_t *sc = bus->ub_hcpriv; |
768 | struct ehci_xfer *ex, *nextex; | | 768 | struct ehci_xfer *ex, *nextex; |
769 | | | 769 | |
770 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); | | 770 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); |
771 | | | 771 | |
772 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 772 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
773 | | | 773 | |
774 | /* | | 774 | /* |
775 | * The only explanation I can think of for why EHCI is as brain dead | | 775 | * The only explanation I can think of for why EHCI is as brain dead |
776 | * as UHCI interrupt-wise is that Intel was involved in both. | | 776 | * as UHCI interrupt-wise is that Intel was involved in both. |
777 | * An interrupt just tells us that something is done, we have no | | 777 | * An interrupt just tells us that something is done, we have no |
778 | * clue what, so we need to scan through all active transfers. :-( | | 778 | * clue what, so we need to scan through all active transfers. :-( |
779 | */ | | 779 | */ |
780 | for (ex = TAILQ_FIRST(&sc->sc_intrhead); ex; ex = nextex) { | | 780 | for (ex = TAILQ_FIRST(&sc->sc_intrhead); ex; ex = nextex) { |
781 | nextex = TAILQ_NEXT(ex, ex_next); | | 781 | nextex = TAILQ_NEXT(ex, ex_next); |
782 | ehci_check_intr(sc, ex); | | 782 | ehci_check_intr(sc, ex); |
783 | } | | 783 | } |
784 | | | 784 | |
785 | /* Schedule a callout to catch any dropped transactions. */ | | 785 | /* Schedule a callout to catch any dropped transactions. */ |
786 | if ((sc->sc_flags & EHCIF_DROPPED_INTR_WORKAROUND) && | | 786 | if ((sc->sc_flags & EHCIF_DROPPED_INTR_WORKAROUND) && |
787 | !TAILQ_EMPTY(&sc->sc_intrhead)) | | 787 | !TAILQ_EMPTY(&sc->sc_intrhead)) |
788 | callout_reset(&sc->sc_tmo_intrlist, | | 788 | callout_reset(&sc->sc_tmo_intrlist, |
789 | hz, ehci_intrlist_timeout, sc); | | 789 | hz, ehci_intrlist_timeout, sc); |
790 | | | 790 | |
791 | if (sc->sc_softwake) { | | 791 | if (sc->sc_softwake) { |
792 | sc->sc_softwake = 0; | | 792 | sc->sc_softwake = 0; |
793 | cv_broadcast(&sc->sc_softwake_cv); | | 793 | cv_broadcast(&sc->sc_softwake_cv); |
794 | } | | 794 | } |
795 | } | | 795 | } |
796 | | | 796 | |
797 | /* Check for an interrupt. */ | | 797 | /* Check for an interrupt. */ |
798 | Static void | | 798 | Static void |
799 | ehci_check_intr(ehci_softc_t *sc, struct ehci_xfer *ex) | | 799 | ehci_check_intr(ehci_softc_t *sc, struct ehci_xfer *ex) |
800 | { | | 800 | { |
801 | usbd_device_handle dev = ex->ex_xfer.ux_pipe->up_dev; | | 801 | usbd_device_handle dev = ex->ex_xfer.ux_pipe->up_dev; |
802 | int attr; | | 802 | int attr; |
803 | | | 803 | |
804 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 804 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
805 | USBHIST_LOG(ehcidebug, "ex = %p", ex, 0, 0, 0); | | 805 | USBHIST_LOG(ehcidebug, "ex = %p", ex, 0, 0, 0); |
806 | | | 806 | |
807 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); | | 807 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); |
808 | | | 808 | |
809 | attr = ex->ex_xfer.ux_pipe->up_endpoint->ue_edesc->bmAttributes; | | 809 | attr = ex->ex_xfer.ux_pipe->up_endpoint->ue_edesc->bmAttributes; |
810 | if (UE_GET_XFERTYPE(attr) == UE_ISOCHRONOUS) { | | 810 | if (UE_GET_XFERTYPE(attr) == UE_ISOCHRONOUS) { |
811 | if (dev->ud_speed == USB_SPEED_HIGH) | | 811 | if (dev->ud_speed == USB_SPEED_HIGH) |
812 | ehci_check_itd_intr(sc, ex); | | 812 | ehci_check_itd_intr(sc, ex); |
813 | else | | 813 | else |
814 | ehci_check_sitd_intr(sc, ex); | | 814 | ehci_check_sitd_intr(sc, ex); |
815 | } else | | 815 | } else |
816 | ehci_check_qh_intr(sc, ex); | | 816 | ehci_check_qh_intr(sc, ex); |
817 | | | 817 | |
818 | return; | | 818 | return; |
819 | } | | 819 | } |
820 | | | 820 | |
821 | Static void | | 821 | Static void |
822 | ehci_check_qh_intr(ehci_softc_t *sc, struct ehci_xfer *ex) | | 822 | ehci_check_qh_intr(ehci_softc_t *sc, struct ehci_xfer *ex) |
823 | { | | 823 | { |
824 | ehci_soft_qtd_t *sqtd, *lsqtd; | | 824 | ehci_soft_qtd_t *sqtd, *lsqtd; |
825 | uint32_t status; | | 825 | uint32_t status; |
826 | | | 826 | |
827 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 827 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
828 | | | 828 | |
829 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); | | 829 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); |
830 | | | 830 | |
831 | if (ex->ex_sqtdstart == NULL) { | | 831 | if (ex->ex_sqtdstart == NULL) { |
832 | printf("ehci_check_qh_intr: not valid sqtd\n"); | | 832 | printf("ehci_check_qh_intr: not valid sqtd\n"); |
833 | return; | | 833 | return; |
834 | } | | 834 | } |
835 | | | 835 | |
836 | lsqtd = ex->ex_sqtdend; | | 836 | lsqtd = ex->ex_sqtdend; |
837 | #ifdef DIAGNOSTIC | | 837 | #ifdef DIAGNOSTIC |
838 | if (lsqtd == NULL) { | | 838 | if (lsqtd == NULL) { |
839 | printf("ehci_check_qh_intr: lsqtd==0\n"); | | 839 | printf("ehci_check_qh_intr: lsqtd==0\n"); |
840 | return; | | 840 | return; |
841 | } | | 841 | } |
842 | #endif | | 842 | #endif |
843 | /* | | 843 | /* |
844 | * If the last TD is still active we need to check whether there | | 844 | * If the last TD is still active we need to check whether there |
845 | * is an error somewhere in the middle, or whether there was a | | 845 | * is an error somewhere in the middle, or whether there was a |
846 | * short packet (SPD and not ACTIVE). | | 846 | * short packet (SPD and not ACTIVE). |
847 | */ | | 847 | */ |
848 | usb_syncmem(&lsqtd->dma, | | 848 | usb_syncmem(&lsqtd->dma, |
849 | lsqtd->offs + offsetof(ehci_qtd_t, qtd_status), | | 849 | lsqtd->offs + offsetof(ehci_qtd_t, qtd_status), |
850 | sizeof(lsqtd->qtd.qtd_status), | | 850 | sizeof(lsqtd->qtd.qtd_status), |
851 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 851 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
852 | status = le32toh(lsqtd->qtd.qtd_status); | | 852 | status = le32toh(lsqtd->qtd.qtd_status); |
853 | usb_syncmem(&lsqtd->dma, | | 853 | usb_syncmem(&lsqtd->dma, |
854 | lsqtd->offs + offsetof(ehci_qtd_t, qtd_status), | | 854 | lsqtd->offs + offsetof(ehci_qtd_t, qtd_status), |
855 | sizeof(lsqtd->qtd.qtd_status), BUS_DMASYNC_PREREAD); | | 855 | sizeof(lsqtd->qtd.qtd_status), BUS_DMASYNC_PREREAD); |
856 | if (status & EHCI_QTD_ACTIVE) { | | 856 | if (status & EHCI_QTD_ACTIVE) { |
857 | USBHIST_LOGN(ehcidebug, 10, "active ex=%p", ex, 0, 0, 0); | | 857 | USBHIST_LOGN(ehcidebug, 10, "active ex=%p", ex, 0, 0, 0); |
858 | for (sqtd = ex->ex_sqtdstart; sqtd != lsqtd; | | 858 | for (sqtd = ex->ex_sqtdstart; sqtd != lsqtd; |
859 | sqtd = sqtd->nextqtd) { | | 859 | sqtd = sqtd->nextqtd) { |
860 | usb_syncmem(&sqtd->dma, | | 860 | usb_syncmem(&sqtd->dma, |
861 | sqtd->offs + offsetof(ehci_qtd_t, qtd_status), | | 861 | sqtd->offs + offsetof(ehci_qtd_t, qtd_status), |
862 | sizeof(sqtd->qtd.qtd_status), | | 862 | sizeof(sqtd->qtd.qtd_status), |
863 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 863 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
864 | status = le32toh(sqtd->qtd.qtd_status); | | 864 | status = le32toh(sqtd->qtd.qtd_status); |
865 | usb_syncmem(&sqtd->dma, | | 865 | usb_syncmem(&sqtd->dma, |
866 | sqtd->offs + offsetof(ehci_qtd_t, qtd_status), | | 866 | sqtd->offs + offsetof(ehci_qtd_t, qtd_status), |
867 | sizeof(sqtd->qtd.qtd_status), BUS_DMASYNC_PREREAD); | | 867 | sizeof(sqtd->qtd.qtd_status), BUS_DMASYNC_PREREAD); |
868 | /* If there's an active QTD the xfer isn't done. */ | | 868 | /* If there's an active QTD the xfer isn't done. */ |
869 | if (status & EHCI_QTD_ACTIVE) | | 869 | if (status & EHCI_QTD_ACTIVE) |
870 | break; | | 870 | break; |
871 | /* Any kind of error makes the xfer done. */ | | 871 | /* Any kind of error makes the xfer done. */ |
872 | if (status & EHCI_QTD_HALTED) | | 872 | if (status & EHCI_QTD_HALTED) |
873 | goto done; | | 873 | goto done; |
874 | /* Handle short packets */ | | 874 | /* Handle short packets */ |
875 | if (EHCI_QTD_GET_BYTES(status) != 0) { | | 875 | if (EHCI_QTD_GET_BYTES(status) != 0) { |
876 | usbd_pipe_handle pipe = ex->ex_xfer.ux_pipe; | | 876 | usbd_pipe_handle pipe = ex->ex_xfer.ux_pipe; |
877 | usb_endpoint_descriptor_t *ed = | | 877 | usb_endpoint_descriptor_t *ed = |
878 | pipe->up_endpoint->ue_edesc; | | 878 | pipe->up_endpoint->ue_edesc; |
879 | uint8_t xt = UE_GET_XFERTYPE(ed->bmAttributes); | | 879 | uint8_t xt = UE_GET_XFERTYPE(ed->bmAttributes); |
880 | | | 880 | |
881 | /* | | 881 | /* |
882 | * If we get here for a control transfer then | | 882 | * If we get here for a control transfer then |
883 | * we need to let the hardware complete the | | 883 | * we need to let the hardware complete the |
884 | * status phase. That is, we're not done | | 884 | * status phase. That is, we're not done |
885 | * quite yet. | | 885 | * quite yet. |
886 | * | | 886 | * |
887 | * Otherwise, we're done. | | 887 | * Otherwise, we're done. |
888 | */ | | 888 | */ |
889 | if (xt == UE_CONTROL) { | | 889 | if (xt == UE_CONTROL) { |
890 | break; | | 890 | break; |
891 | } | | 891 | } |
892 | goto done; | | 892 | goto done; |
893 | } | | 893 | } |
894 | } | | 894 | } |
895 | USBHIST_LOGN(ehcidebug, 10, "ex=%p std=%p still active", | | 895 | USBHIST_LOGN(ehcidebug, 10, "ex=%p std=%p still active", |
896 | ex, ex->ex_sqtdstart, 0, 0); | | 896 | ex, ex->ex_sqtdstart, 0, 0); |
897 | #ifdef EHCI_DEBUG | | 897 | #ifdef EHCI_DEBUG |
898 | USBHIST_LOGN(ehcidebug, 5, "--- still active start ---", 0, 0, 0, 0); | | 898 | USBHIST_LOGN(ehcidebug, 5, "--- still active start ---", 0, 0, 0, 0); |
899 | ehci_dump_sqtds(ex->ex_sqtdstart); | | 899 | ehci_dump_sqtds(ex->ex_sqtdstart); |
900 | USBHIST_LOGN(ehcidebug, 5, "--- still active end ---", 0, 0, 0, 0); | | 900 | USBHIST_LOGN(ehcidebug, 5, "--- still active end ---", 0, 0, 0, 0); |
901 | #endif | | 901 | #endif |
902 | return; | | 902 | return; |
903 | } | | 903 | } |
904 | done: | | 904 | done: |
905 | USBHIST_LOGN(ehcidebug, 10, "ex=%p done", ex, 0, 0, 0); | | 905 | USBHIST_LOGN(ehcidebug, 10, "ex=%p done", ex, 0, 0, 0); |
906 | callout_stop(&ex->ex_xfer.ux_callout); | | 906 | callout_stop(&ex->ex_xfer.ux_callout); |
907 | ehci_idone(ex); | | 907 | ehci_idone(ex); |
908 | } | | 908 | } |
909 | | | 909 | |
910 | Static void | | 910 | Static void |
911 | ehci_check_itd_intr(ehci_softc_t *sc, struct ehci_xfer *ex) | | 911 | ehci_check_itd_intr(ehci_softc_t *sc, struct ehci_xfer *ex) |
912 | { | | 912 | { |
913 | ehci_soft_itd_t *itd; | | 913 | ehci_soft_itd_t *itd; |
914 | int i; | | 914 | int i; |
915 | | | 915 | |
916 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 916 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
917 | | | 917 | |
918 | KASSERT(mutex_owned(&sc->sc_lock)); | | 918 | KASSERT(mutex_owned(&sc->sc_lock)); |
919 | | | 919 | |
920 | if (&ex->ex_xfer != SIMPLEQ_FIRST(&ex->ex_xfer.ux_pipe->up_queue)) | | 920 | if (&ex->ex_xfer != SIMPLEQ_FIRST(&ex->ex_xfer.ux_pipe->up_queue)) |
921 | return; | | 921 | return; |
922 | | | 922 | |
923 | if (ex->ex_itdstart == NULL) { | | 923 | if (ex->ex_itdstart == NULL) { |
924 | printf("ehci_check_itd_intr: not valid itd\n"); | | 924 | printf("ehci_check_itd_intr: not valid itd\n"); |
925 | return; | | 925 | return; |
926 | } | | 926 | } |
927 | | | 927 | |
928 | itd = ex->ex_itdend; | | 928 | itd = ex->ex_itdend; |
929 | #ifdef DIAGNOSTIC | | 929 | #ifdef DIAGNOSTIC |
930 | if (itd == NULL) { | | 930 | if (itd == NULL) { |
931 | printf("ehci_check_itd_intr: itdend == 0\n"); | | 931 | printf("ehci_check_itd_intr: itdend == 0\n"); |
932 | return; | | 932 | return; |
933 | } | | 933 | } |
934 | #endif | | 934 | #endif |
935 | | | 935 | |
936 | /* | | 936 | /* |
937 | * check no active transfers in last itd, meaning we're finished | | 937 | * check no active transfers in last itd, meaning we're finished |
938 | */ | | 938 | */ |
939 | | | 939 | |
940 | usb_syncmem(&itd->dma, itd->offs + offsetof(ehci_itd_t, itd_ctl), | | 940 | usb_syncmem(&itd->dma, itd->offs + offsetof(ehci_itd_t, itd_ctl), |
941 | sizeof(itd->itd.itd_ctl), BUS_DMASYNC_POSTWRITE | | | 941 | sizeof(itd->itd.itd_ctl), BUS_DMASYNC_POSTWRITE | |
942 | BUS_DMASYNC_POSTREAD); | | 942 | BUS_DMASYNC_POSTREAD); |
943 | | | 943 | |
944 | for (i = 0; i < EHCI_ITD_NUFRAMES; i++) { | | 944 | for (i = 0; i < EHCI_ITD_NUFRAMES; i++) { |
945 | if (le32toh(itd->itd.itd_ctl[i]) & EHCI_ITD_ACTIVE) | | 945 | if (le32toh(itd->itd.itd_ctl[i]) & EHCI_ITD_ACTIVE) |
946 | break; | | 946 | break; |
947 | } | | 947 | } |
948 | | | 948 | |
949 | if (i == EHCI_ITD_NUFRAMES) { | | 949 | if (i == EHCI_ITD_NUFRAMES) { |
950 | goto done; /* All 8 descriptors inactive, it's done */ | | 950 | goto done; /* All 8 descriptors inactive, it's done */ |
951 | } | | 951 | } |
952 | | | 952 | |
953 | USBHIST_LOGN(ehcidebug, 10, "ex %p itd %p still active", ex, | | 953 | USBHIST_LOGN(ehcidebug, 10, "ex %p itd %p still active", ex, |
954 | ex->ex_itdstart, 0, 0); | | 954 | ex->ex_itdstart, 0, 0); |
955 | return; | | 955 | return; |
956 | done: | | 956 | done: |
957 | USBHIST_LOG(ehcidebug, "ex %p done", ex, 0, 0, 0); | | 957 | USBHIST_LOG(ehcidebug, "ex %p done", ex, 0, 0, 0); |
958 | callout_stop(&ex->ex_xfer.ux_callout); | | 958 | callout_stop(&ex->ex_xfer.ux_callout); |
959 | ehci_idone(ex); | | 959 | ehci_idone(ex); |
960 | } | | 960 | } |
961 | | | 961 | |
962 | void | | 962 | void |
963 | ehci_check_sitd_intr(ehci_softc_t *sc, struct ehci_xfer *ex) | | 963 | ehci_check_sitd_intr(ehci_softc_t *sc, struct ehci_xfer *ex) |
964 | { | | 964 | { |
965 | ehci_soft_sitd_t *sitd; | | 965 | ehci_soft_sitd_t *sitd; |
966 | | | 966 | |
967 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 967 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
968 | | | 968 | |
969 | KASSERT(mutex_owned(&sc->sc_lock)); | | 969 | KASSERT(mutex_owned(&sc->sc_lock)); |
970 | | | 970 | |
971 | if (&ex->ex_xfer != SIMPLEQ_FIRST(&ex->ex_xfer.ux_pipe->up_queue)) | | 971 | if (&ex->ex_xfer != SIMPLEQ_FIRST(&ex->ex_xfer.ux_pipe->up_queue)) |
972 | return; | | 972 | return; |
973 | | | 973 | |
974 | if (ex->ex_sitdstart == NULL) { | | 974 | if (ex->ex_sitdstart == NULL) { |
975 | printf("ehci_check_sitd_intr: not valid sitd\n"); | | 975 | printf("ehci_check_sitd_intr: not valid sitd\n"); |
976 | return; | | 976 | return; |
977 | } | | 977 | } |
978 | | | 978 | |
979 | sitd = ex->ex_sitdend; | | 979 | sitd = ex->ex_sitdend; |
980 | #ifdef DIAGNOSTIC | | 980 | #ifdef DIAGNOSTIC |
981 | if (sitd == NULL) { | | 981 | if (sitd == NULL) { |
982 | printf("ehci_check_sitd_intr: sitdend == 0\n"); | | 982 | printf("ehci_check_sitd_intr: sitdend == 0\n"); |
983 | return; | | 983 | return; |
984 | } | | 984 | } |
985 | #endif | | 985 | #endif |
986 | | | 986 | |
987 | /* | | 987 | /* |
988 | * check no active transfers in last sitd, meaning we're finished | | 988 | * check no active transfers in last sitd, meaning we're finished |
989 | */ | | 989 | */ |
990 | | | 990 | |
991 | usb_syncmem(&sitd->dma, sitd->offs + offsetof(ehci_sitd_t, sitd_buffer), | | 991 | usb_syncmem(&sitd->dma, sitd->offs + offsetof(ehci_sitd_t, sitd_buffer), |
992 | sizeof(sitd->sitd.sitd_buffer), BUS_DMASYNC_POSTWRITE | | | 992 | sizeof(sitd->sitd.sitd_buffer), BUS_DMASYNC_POSTWRITE | |
993 | BUS_DMASYNC_POSTREAD); | | 993 | BUS_DMASYNC_POSTREAD); |
994 | | | 994 | |
995 | if (le32toh(sitd->sitd.sitd_trans) & EHCI_SITD_ACTIVE) | | 995 | if (le32toh(sitd->sitd.sitd_trans) & EHCI_SITD_ACTIVE) |
996 | return; | | 996 | return; |
997 | | | 997 | |
998 | USBHIST_LOGN(ehcidebug, 10, "ex=%p done", ex, 0, 0, 0); | | 998 | USBHIST_LOGN(ehcidebug, 10, "ex=%p done", ex, 0, 0, 0); |
999 | callout_stop(&(ex->ex_xfer.ux_callout)); | | 999 | callout_stop(&(ex->ex_xfer.ux_callout)); |
1000 | ehci_idone(ex); | | 1000 | ehci_idone(ex); |
1001 | } | | 1001 | } |
1002 | | | 1002 | |
1003 | | | 1003 | |
1004 | Static void | | 1004 | Static void |
1005 | ehci_idone(struct ehci_xfer *ex) | | 1005 | ehci_idone(struct ehci_xfer *ex) |
1006 | { | | 1006 | { |
1007 | usbd_xfer_handle xfer = &ex->ex_xfer; | | 1007 | usbd_xfer_handle xfer = &ex->ex_xfer; |
1008 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; | | 1008 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; |
1009 | struct ehci_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 1009 | struct ehci_softc *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
1010 | ehci_soft_qtd_t *sqtd, *lsqtd; | | 1010 | ehci_soft_qtd_t *sqtd, *lsqtd; |
1011 | uint32_t status = 0, nstatus = 0; | | 1011 | uint32_t status = 0, nstatus = 0; |
1012 | int actlen; | | 1012 | int actlen; |
1013 | | | 1013 | |
1014 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 1014 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
1015 | | | 1015 | |
1016 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); | | 1016 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); |
1017 | | | 1017 | |
1018 | USBHIST_LOG(ehcidebug, "ex=%p", ex, 0, 0, 0); | | 1018 | USBHIST_LOG(ehcidebug, "ex=%p", ex, 0, 0, 0); |
1019 | | | 1019 | |
1020 | #ifdef DIAGNOSTIC | | 1020 | #ifdef DIAGNOSTIC |
1021 | #ifdef EHCI_DEBUG | | 1021 | #ifdef EHCI_DEBUG |
1022 | if (ex->ex_isdone) { | | 1022 | if (ex->ex_isdone) { |
1023 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); | | 1023 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); |
1024 | ehci_dump_exfer(ex); | | 1024 | ehci_dump_exfer(ex); |
1025 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); | | 1025 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); |
1026 | } | | 1026 | } |
1027 | #endif | | 1027 | #endif |
1028 | KASSERT(!ex->ex_isdone); | | 1028 | KASSERT(!ex->ex_isdone); |
1029 | ex->ex_isdone = true; | | 1029 | ex->ex_isdone = true; |
1030 | #endif | | 1030 | #endif |
1031 | | | 1031 | |
1032 | if (xfer->ux_status == USBD_CANCELLED || | | 1032 | if (xfer->ux_status == USBD_CANCELLED || |
1033 | xfer->ux_status == USBD_TIMEOUT) { | | 1033 | xfer->ux_status == USBD_TIMEOUT) { |
1034 | USBHIST_LOG(ehcidebug, "aborted xfer=%p", xfer, 0, 0, 0); | | 1034 | USBHIST_LOG(ehcidebug, "aborted xfer=%p", xfer, 0, 0, 0); |
1035 | return; | | 1035 | return; |
1036 | } | | 1036 | } |
1037 | | | 1037 | |
1038 | USBHIST_LOG(ehcidebug, "xfer=%p, pipe=%p ready", xfer, epipe, 0, 0); | | 1038 | USBHIST_LOG(ehcidebug, "xfer=%p, pipe=%p ready", xfer, epipe, 0, 0); |
1039 | #ifdef EHCI_DEBUG | | 1039 | #ifdef EHCI_DEBUG |
1040 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); | | 1040 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); |
1041 | ehci_dump_sqtds(ex->ex_sqtdstart); | | 1041 | ehci_dump_sqtds(ex->ex_sqtdstart); |
1042 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); | | 1042 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); |
1043 | #endif | | 1043 | #endif |
1044 | | | 1044 | |
1045 | /* The transfer is done, compute actual length and status. */ | | 1045 | /* The transfer is done, compute actual length and status. */ |
1046 | | | 1046 | |
1047 | u_int xfertype, speed; | | 1047 | u_int xfertype, speed; |
1048 | | | 1048 | |
1049 | xfertype = UE_GET_XFERTYPE(xfer->ux_pipe->up_endpoint->ue_edesc->bmAttributes); | | 1049 | xfertype = UE_GET_XFERTYPE(xfer->ux_pipe->up_endpoint->ue_edesc->bmAttributes); |
1050 | speed = xfer->ux_pipe->up_dev->ud_speed; | | 1050 | speed = xfer->ux_pipe->up_dev->ud_speed; |
1051 | if (xfertype == UE_ISOCHRONOUS && speed == USB_SPEED_HIGH) { | | 1051 | if (xfertype == UE_ISOCHRONOUS && speed == USB_SPEED_HIGH) { |
1052 | /* HS isoc transfer */ | | 1052 | /* HS isoc transfer */ |
1053 | | | 1053 | |
1054 | struct ehci_soft_itd *itd; | | 1054 | struct ehci_soft_itd *itd; |
1055 | int i, nframes, len, uframes; | | 1055 | int i, nframes, len, uframes; |
| @@ -2539,2003 +2539,2003 @@ ehci_roothub_ctrl(struct usbd_bus *bus, | | | @@ -2539,2003 +2539,2003 @@ ehci_roothub_ctrl(struct usbd_bus *bus, |
2539 | break; | | 2539 | break; |
2540 | default: | | 2540 | default: |
2541 | return -1; | | 2541 | return -1; |
2542 | } | | 2542 | } |
2543 | break; | | 2543 | break; |
2544 | case C(UR_CLEAR_TT_BUFFER, UT_WRITE_CLASS_OTHER): | | 2544 | case C(UR_CLEAR_TT_BUFFER, UT_WRITE_CLASS_OTHER): |
2545 | case C(UR_RESET_TT, UT_WRITE_CLASS_OTHER): | | 2545 | case C(UR_RESET_TT, UT_WRITE_CLASS_OTHER): |
2546 | case C(UR_GET_TT_STATE, UT_READ_CLASS_OTHER): | | 2546 | case C(UR_GET_TT_STATE, UT_READ_CLASS_OTHER): |
2547 | case C(UR_STOP_TT, UT_WRITE_CLASS_OTHER): | | 2547 | case C(UR_STOP_TT, UT_WRITE_CLASS_OTHER): |
2548 | break; | | 2548 | break; |
2549 | default: | | 2549 | default: |
2550 | /* default from usbroothub */ | | 2550 | /* default from usbroothub */ |
2551 | USBHIST_LOG(ehcidebug, "returning %d (usbroothub default)", | | 2551 | USBHIST_LOG(ehcidebug, "returning %d (usbroothub default)", |
2552 | buflen, 0, 0, 0); | | 2552 | buflen, 0, 0, 0); |
2553 | | | 2553 | |
2554 | return buflen; | | 2554 | return buflen; |
2555 | } | | 2555 | } |
2556 | | | 2556 | |
2557 | USBHIST_LOG(ehcidebug, "returning %d", totlen, 0, 0, 0); | | 2557 | USBHIST_LOG(ehcidebug, "returning %d", totlen, 0, 0, 0); |
2558 | | | 2558 | |
2559 | return totlen; | | 2559 | return totlen; |
2560 | } | | 2560 | } |
2561 | | | 2561 | |
2562 | Static void | | 2562 | Static void |
2563 | ehci_disown(ehci_softc_t *sc, int index, int lowspeed) | | 2563 | ehci_disown(ehci_softc_t *sc, int index, int lowspeed) |
2564 | { | | 2564 | { |
2565 | int port; | | 2565 | int port; |
2566 | uint32_t v; | | 2566 | uint32_t v; |
2567 | | | 2567 | |
2568 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2568 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2569 | | | 2569 | |
2570 | USBHIST_LOG(ehcidebug, "index=%d lowspeed=%d", index, lowspeed, 0, 0); | | 2570 | USBHIST_LOG(ehcidebug, "index=%d lowspeed=%d", index, lowspeed, 0, 0); |
2571 | #ifdef DIAGNOSTIC | | 2571 | #ifdef DIAGNOSTIC |
2572 | if (sc->sc_npcomp != 0) { | | 2572 | if (sc->sc_npcomp != 0) { |
2573 | int i = (index-1) / sc->sc_npcomp; | | 2573 | int i = (index-1) / sc->sc_npcomp; |
2574 | if (i >= sc->sc_ncomp) | | 2574 | if (i >= sc->sc_ncomp) |
2575 | printf("%s: strange port\n", | | 2575 | printf("%s: strange port\n", |
2576 | device_xname(sc->sc_dev)); | | 2576 | device_xname(sc->sc_dev)); |
2577 | else | | 2577 | else |
2578 | printf("%s: handing over %s speed device on " | | 2578 | printf("%s: handing over %s speed device on " |
2579 | "port %d to %s\n", | | 2579 | "port %d to %s\n", |
2580 | device_xname(sc->sc_dev), | | 2580 | device_xname(sc->sc_dev), |
2581 | lowspeed ? "low" : "full", | | 2581 | lowspeed ? "low" : "full", |
2582 | index, device_xname(sc->sc_comps[i])); | | 2582 | index, device_xname(sc->sc_comps[i])); |
2583 | } else { | | 2583 | } else { |
2584 | printf("%s: npcomp == 0\n", device_xname(sc->sc_dev)); | | 2584 | printf("%s: npcomp == 0\n", device_xname(sc->sc_dev)); |
2585 | } | | 2585 | } |
2586 | #endif | | 2586 | #endif |
2587 | port = EHCI_PORTSC(index); | | 2587 | port = EHCI_PORTSC(index); |
2588 | v = EOREAD4(sc, port) &~ EHCI_PS_CLEAR; | | 2588 | v = EOREAD4(sc, port) &~ EHCI_PS_CLEAR; |
2589 | EOWRITE4(sc, port, v | EHCI_PS_PO); | | 2589 | EOWRITE4(sc, port, v | EHCI_PS_PO); |
2590 | } | | 2590 | } |
2591 | | | 2591 | |
2592 | Static usbd_status | | 2592 | Static usbd_status |
2593 | ehci_root_intr_transfer(usbd_xfer_handle xfer) | | 2593 | ehci_root_intr_transfer(usbd_xfer_handle xfer) |
2594 | { | | 2594 | { |
2595 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 2595 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
2596 | usbd_status err; | | 2596 | usbd_status err; |
2597 | | | 2597 | |
2598 | /* Insert last in queue. */ | | 2598 | /* Insert last in queue. */ |
2599 | mutex_enter(&sc->sc_lock); | | 2599 | mutex_enter(&sc->sc_lock); |
2600 | err = usb_insert_transfer(xfer); | | 2600 | err = usb_insert_transfer(xfer); |
2601 | mutex_exit(&sc->sc_lock); | | 2601 | mutex_exit(&sc->sc_lock); |
2602 | if (err) | | 2602 | if (err) |
2603 | return err; | | 2603 | return err; |
2604 | | | 2604 | |
2605 | /* Pipe isn't running, start first */ | | 2605 | /* Pipe isn't running, start first */ |
2606 | return ehci_root_intr_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); | | 2606 | return ehci_root_intr_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); |
2607 | } | | 2607 | } |
2608 | | | 2608 | |
2609 | Static usbd_status | | 2609 | Static usbd_status |
2610 | ehci_root_intr_start(usbd_xfer_handle xfer) | | 2610 | ehci_root_intr_start(usbd_xfer_handle xfer) |
2611 | { | | 2611 | { |
2612 | usbd_pipe_handle pipe = xfer->ux_pipe; | | 2612 | usbd_pipe_handle pipe = xfer->ux_pipe; |
2613 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; | | 2613 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; |
2614 | | | 2614 | |
2615 | if (sc->sc_dying) | | 2615 | if (sc->sc_dying) |
2616 | return USBD_IOERROR; | | 2616 | return USBD_IOERROR; |
2617 | | | 2617 | |
2618 | mutex_enter(&sc->sc_lock); | | 2618 | mutex_enter(&sc->sc_lock); |
2619 | sc->sc_intrxfer = xfer; | | 2619 | sc->sc_intrxfer = xfer; |
2620 | mutex_exit(&sc->sc_lock); | | 2620 | mutex_exit(&sc->sc_lock); |
2621 | | | 2621 | |
2622 | return USBD_IN_PROGRESS; | | 2622 | return USBD_IN_PROGRESS; |
2623 | } | | 2623 | } |
2624 | | | 2624 | |
2625 | /* Abort a root interrupt request. */ | | 2625 | /* Abort a root interrupt request. */ |
2626 | Static void | | 2626 | Static void |
2627 | ehci_root_intr_abort(usbd_xfer_handle xfer) | | 2627 | ehci_root_intr_abort(usbd_xfer_handle xfer) |
2628 | { | | 2628 | { |
2629 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 2629 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
2630 | | | 2630 | |
2631 | KASSERT(mutex_owned(&sc->sc_lock)); | | 2631 | KASSERT(mutex_owned(&sc->sc_lock)); |
2632 | KASSERT(xfer->ux_pipe->up_intrxfer == xfer); | | 2632 | KASSERT(xfer->ux_pipe->up_intrxfer == xfer); |
2633 | | | 2633 | |
2634 | sc->sc_intrxfer = NULL; | | 2634 | sc->sc_intrxfer = NULL; |
2635 | | | 2635 | |
2636 | xfer->ux_status = USBD_CANCELLED; | | 2636 | xfer->ux_status = USBD_CANCELLED; |
2637 | usb_transfer_complete(xfer); | | 2637 | usb_transfer_complete(xfer); |
2638 | } | | 2638 | } |
2639 | | | 2639 | |
2640 | /* Close the root pipe. */ | | 2640 | /* Close the root pipe. */ |
2641 | Static void | | 2641 | Static void |
2642 | ehci_root_intr_close(usbd_pipe_handle pipe) | | 2642 | ehci_root_intr_close(usbd_pipe_handle pipe) |
2643 | { | | 2643 | { |
2644 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; | | 2644 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; |
2645 | | | 2645 | |
2646 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2646 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2647 | | | 2647 | |
2648 | KASSERT(mutex_owned(&sc->sc_lock)); | | 2648 | KASSERT(mutex_owned(&sc->sc_lock)); |
2649 | | | 2649 | |
2650 | sc->sc_intrxfer = NULL; | | 2650 | sc->sc_intrxfer = NULL; |
2651 | } | | 2651 | } |
2652 | | | 2652 | |
2653 | Static void | | 2653 | Static void |
2654 | ehci_root_intr_done(usbd_xfer_handle xfer) | | 2654 | ehci_root_intr_done(usbd_xfer_handle xfer) |
2655 | { | | 2655 | { |
2656 | xfer->ux_hcpriv = NULL; | | 2656 | xfer->ux_hcpriv = NULL; |
2657 | } | | 2657 | } |
2658 | | | 2658 | |
2659 | /************************/ | | 2659 | /************************/ |
2660 | | | 2660 | |
2661 | Static ehci_soft_qh_t * | | 2661 | Static ehci_soft_qh_t * |
2662 | ehci_alloc_sqh(ehci_softc_t *sc) | | 2662 | ehci_alloc_sqh(ehci_softc_t *sc) |
2663 | { | | 2663 | { |
2664 | ehci_soft_qh_t *sqh; | | 2664 | ehci_soft_qh_t *sqh; |
2665 | usbd_status err; | | 2665 | usbd_status err; |
2666 | int i, offs; | | 2666 | int i, offs; |
2667 | usb_dma_t dma; | | 2667 | usb_dma_t dma; |
2668 | | | 2668 | |
2669 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2669 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2670 | | | 2670 | |
2671 | if (sc->sc_freeqhs == NULL) { | | 2671 | if (sc->sc_freeqhs == NULL) { |
2672 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); | | 2672 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); |
2673 | err = usb_allocmem(&sc->sc_bus, EHCI_SQH_SIZE * EHCI_SQH_CHUNK, | | 2673 | err = usb_allocmem(&sc->sc_bus, EHCI_SQH_SIZE * EHCI_SQH_CHUNK, |
2674 | EHCI_PAGE_SIZE, &dma); | | 2674 | EHCI_PAGE_SIZE, &dma); |
2675 | #ifdef EHCI_DEBUG | | 2675 | #ifdef EHCI_DEBUG |
2676 | if (err) | | 2676 | if (err) |
2677 | printf("ehci_alloc_sqh: usb_allocmem()=%d\n", err); | | 2677 | printf("ehci_alloc_sqh: usb_allocmem()=%d\n", err); |
2678 | #endif | | 2678 | #endif |
2679 | if (err) | | 2679 | if (err) |
2680 | return NULL; | | 2680 | return NULL; |
2681 | for (i = 0; i < EHCI_SQH_CHUNK; i++) { | | 2681 | for (i = 0; i < EHCI_SQH_CHUNK; i++) { |
2682 | offs = i * EHCI_SQH_SIZE; | | 2682 | offs = i * EHCI_SQH_SIZE; |
2683 | sqh = KERNADDR(&dma, offs); | | 2683 | sqh = KERNADDR(&dma, offs); |
2684 | sqh->physaddr = DMAADDR(&dma, offs); | | 2684 | sqh->physaddr = DMAADDR(&dma, offs); |
2685 | sqh->dma = dma; | | 2685 | sqh->dma = dma; |
2686 | sqh->offs = offs; | | 2686 | sqh->offs = offs; |
2687 | sqh->next = sc->sc_freeqhs; | | 2687 | sqh->next = sc->sc_freeqhs; |
2688 | sc->sc_freeqhs = sqh; | | 2688 | sc->sc_freeqhs = sqh; |
2689 | } | | 2689 | } |
2690 | } | | 2690 | } |
2691 | sqh = sc->sc_freeqhs; | | 2691 | sqh = sc->sc_freeqhs; |
2692 | sc->sc_freeqhs = sqh->next; | | 2692 | sc->sc_freeqhs = sqh->next; |
2693 | memset(&sqh->qh, 0, sizeof(ehci_qh_t)); | | 2693 | memset(&sqh->qh, 0, sizeof(ehci_qh_t)); |
2694 | sqh->next = NULL; | | 2694 | sqh->next = NULL; |
2695 | return sqh; | | 2695 | return sqh; |
2696 | } | | 2696 | } |
2697 | | | 2697 | |
2698 | Static void | | 2698 | Static void |
2699 | ehci_free_sqh(ehci_softc_t *sc, ehci_soft_qh_t *sqh) | | 2699 | ehci_free_sqh(ehci_softc_t *sc, ehci_soft_qh_t *sqh) |
2700 | { | | 2700 | { |
2701 | sqh->next = sc->sc_freeqhs; | | 2701 | sqh->next = sc->sc_freeqhs; |
2702 | sc->sc_freeqhs = sqh; | | 2702 | sc->sc_freeqhs = sqh; |
2703 | } | | 2703 | } |
2704 | | | 2704 | |
2705 | Static ehci_soft_qtd_t * | | 2705 | Static ehci_soft_qtd_t * |
2706 | ehci_alloc_sqtd(ehci_softc_t *sc) | | 2706 | ehci_alloc_sqtd(ehci_softc_t *sc) |
2707 | { | | 2707 | { |
2708 | ehci_soft_qtd_t *sqtd = NULL; | | 2708 | ehci_soft_qtd_t *sqtd = NULL; |
2709 | usbd_status err; | | 2709 | usbd_status err; |
2710 | int i, offs; | | 2710 | int i, offs; |
2711 | usb_dma_t dma; | | 2711 | usb_dma_t dma; |
2712 | | | 2712 | |
2713 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2713 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2714 | | | 2714 | |
2715 | if (sc->sc_freeqtds == NULL) { | | 2715 | if (sc->sc_freeqtds == NULL) { |
2716 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); | | 2716 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); |
2717 | | | 2717 | |
2718 | err = usb_allocmem(&sc->sc_bus, EHCI_SQTD_SIZE*EHCI_SQTD_CHUNK, | | 2718 | err = usb_allocmem(&sc->sc_bus, EHCI_SQTD_SIZE*EHCI_SQTD_CHUNK, |
2719 | EHCI_PAGE_SIZE, &dma); | | 2719 | EHCI_PAGE_SIZE, &dma); |
2720 | #ifdef EHCI_DEBUG | | 2720 | #ifdef EHCI_DEBUG |
2721 | if (err) | | 2721 | if (err) |
2722 | printf("ehci_alloc_sqtd: usb_allocmem()=%d\n", err); | | 2722 | printf("ehci_alloc_sqtd: usb_allocmem()=%d\n", err); |
2723 | #endif | | 2723 | #endif |
2724 | if (err) | | 2724 | if (err) |
2725 | goto done; | | 2725 | goto done; |
2726 | | | 2726 | |
2727 | for (i = 0; i < EHCI_SQTD_CHUNK; i++) { | | 2727 | for (i = 0; i < EHCI_SQTD_CHUNK; i++) { |
2728 | offs = i * EHCI_SQTD_SIZE; | | 2728 | offs = i * EHCI_SQTD_SIZE; |
2729 | sqtd = KERNADDR(&dma, offs); | | 2729 | sqtd = KERNADDR(&dma, offs); |
2730 | sqtd->physaddr = DMAADDR(&dma, offs); | | 2730 | sqtd->physaddr = DMAADDR(&dma, offs); |
2731 | sqtd->dma = dma; | | 2731 | sqtd->dma = dma; |
2732 | sqtd->offs = offs; | | 2732 | sqtd->offs = offs; |
2733 | | | 2733 | |
2734 | sqtd->nextqtd = sc->sc_freeqtds; | | 2734 | sqtd->nextqtd = sc->sc_freeqtds; |
2735 | sc->sc_freeqtds = sqtd; | | 2735 | sc->sc_freeqtds = sqtd; |
2736 | } | | 2736 | } |
2737 | } | | 2737 | } |
2738 | | | 2738 | |
2739 | sqtd = sc->sc_freeqtds; | | 2739 | sqtd = sc->sc_freeqtds; |
2740 | sc->sc_freeqtds = sqtd->nextqtd; | | 2740 | sc->sc_freeqtds = sqtd->nextqtd; |
2741 | memset(&sqtd->qtd, 0, sizeof(ehci_qtd_t)); | | 2741 | memset(&sqtd->qtd, 0, sizeof(ehci_qtd_t)); |
2742 | sqtd->nextqtd = NULL; | | 2742 | sqtd->nextqtd = NULL; |
2743 | sqtd->xfer = NULL; | | 2743 | sqtd->xfer = NULL; |
2744 | | | 2744 | |
2745 | done: | | 2745 | done: |
2746 | return sqtd; | | 2746 | return sqtd; |
2747 | } | | 2747 | } |
2748 | | | 2748 | |
2749 | Static void | | 2749 | Static void |
2750 | ehci_free_sqtd(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd) | | 2750 | ehci_free_sqtd(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd) |
2751 | { | | 2751 | { |
2752 | | | 2752 | |
2753 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); | | 2753 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); |
2754 | | | 2754 | |
2755 | sqtd->nextqtd = sc->sc_freeqtds; | | 2755 | sqtd->nextqtd = sc->sc_freeqtds; |
2756 | sc->sc_freeqtds = sqtd; | | 2756 | sc->sc_freeqtds = sqtd; |
2757 | } | | 2757 | } |
2758 | | | 2758 | |
2759 | Static usbd_status | | 2759 | Static usbd_status |
2760 | ehci_alloc_sqtd_chain(struct ehci_pipe *epipe, ehci_softc_t *sc, | | 2760 | ehci_alloc_sqtd_chain(struct ehci_pipe *epipe, ehci_softc_t *sc, |
2761 | int alen, int rd, usbd_xfer_handle xfer, | | 2761 | int alen, int rd, usbd_xfer_handle xfer, |
2762 | ehci_soft_qtd_t **sp, ehci_soft_qtd_t **ep) | | 2762 | ehci_soft_qtd_t **sp, ehci_soft_qtd_t **ep) |
2763 | { | | 2763 | { |
2764 | ehci_soft_qtd_t *next, *cur; | | 2764 | ehci_soft_qtd_t *next, *cur; |
2765 | ehci_physaddr_t nextphys; | | 2765 | ehci_physaddr_t nextphys; |
2766 | uint32_t qtdstatus; | | 2766 | uint32_t qtdstatus; |
2767 | int len, curlen, mps; | | 2767 | int len, curlen, mps; |
2768 | int i, tog; | | 2768 | int i, tog; |
2769 | int pages, pageoffs; | | 2769 | int pages, pageoffs; |
2770 | size_t curoffs; | | 2770 | size_t curoffs; |
2771 | vaddr_t va, va_offs; | | 2771 | vaddr_t va, va_offs; |
2772 | usb_dma_t *dma = &xfer->ux_dmabuf; | | 2772 | usb_dma_t *dma = &xfer->ux_dmabuf; |
2773 | uint16_t flags = xfer->ux_flags; | | 2773 | uint16_t flags = xfer->ux_flags; |
2774 | paddr_t a; | | 2774 | paddr_t a; |
2775 | | | 2775 | |
2776 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2776 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2777 | | | 2777 | |
2778 | USBHIST_LOG(ehcidebug, "start len=%d", alen, 0, 0, 0); | | 2778 | USBHIST_LOG(ehcidebug, "start len=%d", alen, 0, 0, 0); |
2779 | | | 2779 | |
2780 | len = alen; | | 2780 | len = alen; |
2781 | qtdstatus = EHCI_QTD_ACTIVE | | | 2781 | qtdstatus = EHCI_QTD_ACTIVE | |
2782 | EHCI_QTD_SET_PID(rd ? EHCI_QTD_PID_IN : EHCI_QTD_PID_OUT) | | | 2782 | EHCI_QTD_SET_PID(rd ? EHCI_QTD_PID_IN : EHCI_QTD_PID_OUT) | |
2783 | EHCI_QTD_SET_CERR(3) | | 2783 | EHCI_QTD_SET_CERR(3) |
2784 | /* IOC set below */ | | 2784 | /* IOC set below */ |
2785 | /* BYTES set below */ | | 2785 | /* BYTES set below */ |
2786 | ; | | 2786 | ; |
2787 | mps = UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize); | | 2787 | mps = UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize); |
2788 | tog = epipe->nexttoggle; | | 2788 | tog = epipe->nexttoggle; |
2789 | qtdstatus |= EHCI_QTD_SET_TOGGLE(tog); | | 2789 | qtdstatus |= EHCI_QTD_SET_TOGGLE(tog); |
2790 | | | 2790 | |
2791 | cur = ehci_alloc_sqtd(sc); | | 2791 | cur = ehci_alloc_sqtd(sc); |
2792 | *sp = cur; | | 2792 | *sp = cur; |
2793 | if (cur == NULL) | | 2793 | if (cur == NULL) |
2794 | goto nomem; | | 2794 | goto nomem; |
2795 | | | 2795 | |
2796 | usb_syncmem(dma, 0, alen, | | 2796 | usb_syncmem(dma, 0, alen, |
2797 | rd ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE); | | 2797 | rd ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE); |
2798 | curoffs = 0; | | 2798 | curoffs = 0; |
2799 | for (;;) { | | 2799 | for (;;) { |
2800 | /* The EHCI hardware can handle at most 5 pages. */ | | 2800 | /* The EHCI hardware can handle at most 5 pages. */ |
2801 | va_offs = (vaddr_t)KERNADDR(dma, curoffs); | | 2801 | va_offs = (vaddr_t)KERNADDR(dma, curoffs); |
2802 | va_offs = EHCI_PAGE_OFFSET(va_offs); | | 2802 | va_offs = EHCI_PAGE_OFFSET(va_offs); |
2803 | if (len-curoffs < EHCI_QTD_MAXTRANSFER - va_offs) { | | 2803 | if (len-curoffs < EHCI_QTD_MAXTRANSFER - va_offs) { |
2804 | /* we can handle it in this QTD */ | | 2804 | /* we can handle it in this QTD */ |
2805 | curlen = len - curoffs; | | 2805 | curlen = len - curoffs; |
2806 | } else { | | 2806 | } else { |
2807 | /* must use multiple TDs, fill as much as possible. */ | | 2807 | /* must use multiple TDs, fill as much as possible. */ |
2808 | curlen = EHCI_QTD_MAXTRANSFER - va_offs; | | 2808 | curlen = EHCI_QTD_MAXTRANSFER - va_offs; |
2809 | | | 2809 | |
2810 | /* the length must be a multiple of the max size */ | | 2810 | /* the length must be a multiple of the max size */ |
2811 | curlen -= curlen % mps; | | 2811 | curlen -= curlen % mps; |
2812 | USBHIST_LOG(ehcidebug, "multiple QTDs, " | | 2812 | USBHIST_LOG(ehcidebug, "multiple QTDs, " |
2813 | "curlen=%d", curlen, 0, 0, 0); | | 2813 | "curlen=%d", curlen, 0, 0, 0); |
2814 | KASSERT(curlen != 0); | | 2814 | KASSERT(curlen != 0); |
2815 | } | | 2815 | } |
2816 | USBHIST_LOG(ehcidebug, "len=%d curlen=%d curoffs=%zu", | | 2816 | USBHIST_LOG(ehcidebug, "len=%d curlen=%d curoffs=%zu", |
2817 | len, curlen, curoffs, 0); | | 2817 | len, curlen, curoffs, 0); |
2818 | | | 2818 | |
2819 | /* | | 2819 | /* |
2820 | * Allocate another transfer if there's more data left, | | 2820 | * Allocate another transfer if there's more data left, |
2821 | * or if force last short transfer flag is set and we're | | 2821 | * or if force last short transfer flag is set and we're |
2822 | * allocating a multiple of the max packet size. | | 2822 | * allocating a multiple of the max packet size. |
2823 | */ | | 2823 | */ |
2824 | | | 2824 | |
2825 | if (curoffs + curlen != len || | | 2825 | if (curoffs + curlen != len || |
2826 | ((curlen % mps) == 0 && !rd && curlen != 0 && | | 2826 | ((curlen % mps) == 0 && !rd && curlen != 0 && |
2827 | (flags & USBD_FORCE_SHORT_XFER))) { | | 2827 | (flags & USBD_FORCE_SHORT_XFER))) { |
2828 | next = ehci_alloc_sqtd(sc); | | 2828 | next = ehci_alloc_sqtd(sc); |
2829 | if (next == NULL) | | 2829 | if (next == NULL) |
2830 | goto nomem; | | 2830 | goto nomem; |
2831 | nextphys = htole32(next->physaddr); | | 2831 | nextphys = htole32(next->physaddr); |
2832 | } else { | | 2832 | } else { |
2833 | next = NULL; | | 2833 | next = NULL; |
2834 | nextphys = EHCI_NULL; | | 2834 | nextphys = EHCI_NULL; |
2835 | } | | 2835 | } |
2836 | | | 2836 | |
2837 | /* Find number of pages we'll be using, insert dma addresses */ | | 2837 | /* Find number of pages we'll be using, insert dma addresses */ |
2838 | pages = EHCI_NPAGES(curlen); | | 2838 | pages = EHCI_NPAGES(curlen); |
2839 | KASSERT(pages <= EHCI_QTD_NBUFFERS); | | 2839 | KASSERT(pages <= EHCI_QTD_NBUFFERS); |
2840 | pageoffs = EHCI_PAGE(curoffs); | | 2840 | pageoffs = EHCI_PAGE(curoffs); |
2841 | for (i = 0; i < pages; i++) { | | 2841 | for (i = 0; i < pages; i++) { |
2842 | a = DMAADDR(dma, pageoffs + i * EHCI_PAGE_SIZE); | | 2842 | a = DMAADDR(dma, pageoffs + i * EHCI_PAGE_SIZE); |
2843 | cur->qtd.qtd_buffer[i] = htole32(EHCI_PAGE(a)); | | 2843 | cur->qtd.qtd_buffer[i] = htole32(EHCI_PAGE(a)); |
2844 | /* Cast up to avoid compiler warnings */ | | 2844 | /* Cast up to avoid compiler warnings */ |
2845 | cur->qtd.qtd_buffer_hi[i] = htole32((uint64_t)a >> 32); | | 2845 | cur->qtd.qtd_buffer_hi[i] = htole32((uint64_t)a >> 32); |
2846 | } | | 2846 | } |
2847 | | | 2847 | |
2848 | /* First buffer pointer requires a page offset to start at */ | | 2848 | /* First buffer pointer requires a page offset to start at */ |
2849 | va = (vaddr_t)KERNADDR(dma, curoffs); | | 2849 | va = (vaddr_t)KERNADDR(dma, curoffs); |
2850 | cur->qtd.qtd_buffer[0] |= htole32(EHCI_PAGE_OFFSET(va)); | | 2850 | cur->qtd.qtd_buffer[0] |= htole32(EHCI_PAGE_OFFSET(va)); |
2851 | | | 2851 | |
2852 | cur->nextqtd = next; | | 2852 | cur->nextqtd = next; |
2853 | cur->qtd.qtd_next = cur->qtd.qtd_altnext = nextphys; | | 2853 | cur->qtd.qtd_next = cur->qtd.qtd_altnext = nextphys; |
2854 | cur->qtd.qtd_status = | | 2854 | cur->qtd.qtd_status = |
2855 | htole32(qtdstatus | EHCI_QTD_SET_BYTES(curlen)); | | 2855 | htole32(qtdstatus | EHCI_QTD_SET_BYTES(curlen)); |
2856 | cur->xfer = xfer; | | 2856 | cur->xfer = xfer; |
2857 | cur->len = curlen; | | 2857 | cur->len = curlen; |
2858 | | | 2858 | |
2859 | USBHIST_LOG(ehcidebug, "cbp=0x%08zx end=0x%08zx", | | 2859 | USBHIST_LOG(ehcidebug, "cbp=0x%08zx end=0x%08zx", |
2860 | curoffs, curoffs + curlen, 0, 0); | | 2860 | curoffs, curoffs + curlen, 0, 0); |
2861 | | | 2861 | |
2862 | /* | | 2862 | /* |
2863 | * adjust the toggle based on the number of packets in this | | 2863 | * adjust the toggle based on the number of packets in this |
2864 | * qtd | | 2864 | * qtd |
2865 | */ | | 2865 | */ |
2866 | if (((curlen + mps - 1) / mps) & 1) { | | 2866 | if (((curlen + mps - 1) / mps) & 1) { |
2867 | tog ^= 1; | | 2867 | tog ^= 1; |
2868 | qtdstatus ^= EHCI_QTD_TOGGLE_MASK; | | 2868 | qtdstatus ^= EHCI_QTD_TOGGLE_MASK; |
2869 | } | | 2869 | } |
2870 | if (next == NULL) | | 2870 | if (next == NULL) |
2871 | break; | | 2871 | break; |
2872 | usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd), | | 2872 | usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd), |
2873 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2873 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2874 | USBHIST_LOG(ehcidebug, "extend chain", 0, 0, 0, 0); | | 2874 | USBHIST_LOG(ehcidebug, "extend chain", 0, 0, 0, 0); |
2875 | if (len) | | 2875 | if (len) |
2876 | curoffs += curlen; | | 2876 | curoffs += curlen; |
2877 | cur = next; | | 2877 | cur = next; |
2878 | } | | 2878 | } |
2879 | cur->qtd.qtd_status |= htole32(EHCI_QTD_IOC); | | 2879 | cur->qtd.qtd_status |= htole32(EHCI_QTD_IOC); |
2880 | usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd), | | 2880 | usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd), |
2881 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2881 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2882 | *ep = cur; | | 2882 | *ep = cur; |
2883 | epipe->nexttoggle = tog; | | 2883 | epipe->nexttoggle = tog; |
2884 | | | 2884 | |
2885 | USBHIST_LOG(ehcidebug, "return sqtd=%p sqtdend=%p", | | 2885 | USBHIST_LOG(ehcidebug, "return sqtd=%p sqtdend=%p", |
2886 | *sp, *ep, 0, 0); | | 2886 | *sp, *ep, 0, 0); |
2887 | | | 2887 | |
2888 | return USBD_NORMAL_COMPLETION; | | 2888 | return USBD_NORMAL_COMPLETION; |
2889 | | | 2889 | |
2890 | nomem: | | 2890 | nomem: |
2891 | /* XXX free chain */ | | 2891 | /* XXX free chain */ |
2892 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); | | 2892 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); |
2893 | return USBD_NOMEM; | | 2893 | return USBD_NOMEM; |
2894 | } | | 2894 | } |
2895 | | | 2895 | |
2896 | Static void | | 2896 | Static void |
2897 | ehci_free_sqtd_chain(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd, | | 2897 | ehci_free_sqtd_chain(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd, |
2898 | ehci_soft_qtd_t *sqtdend) | | 2898 | ehci_soft_qtd_t *sqtdend) |
2899 | { | | 2899 | { |
2900 | ehci_soft_qtd_t *p; | | 2900 | ehci_soft_qtd_t *p; |
2901 | int i; | | 2901 | int i; |
2902 | | | 2902 | |
2903 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2903 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2904 | | | 2904 | |
2905 | USBHIST_LOG(ehcidebug, "sqtd=%p sqtdend=%p", | | 2905 | USBHIST_LOG(ehcidebug, "sqtd=%p sqtdend=%p", |
2906 | sqtd, sqtdend, 0, 0); | | 2906 | sqtd, sqtdend, 0, 0); |
2907 | | | 2907 | |
2908 | for (i = 0; sqtd != sqtdend; sqtd = p, i++) { | | 2908 | for (i = 0; sqtd != sqtdend; sqtd = p, i++) { |
2909 | p = sqtd->nextqtd; | | 2909 | p = sqtd->nextqtd; |
2910 | ehci_free_sqtd(sc, sqtd); | | 2910 | ehci_free_sqtd(sc, sqtd); |
2911 | } | | 2911 | } |
2912 | } | | 2912 | } |
2913 | | | 2913 | |
2914 | Static ehci_soft_itd_t * | | 2914 | Static ehci_soft_itd_t * |
2915 | ehci_alloc_itd(ehci_softc_t *sc) | | 2915 | ehci_alloc_itd(ehci_softc_t *sc) |
2916 | { | | 2916 | { |
2917 | struct ehci_soft_itd *itd, *freeitd; | | 2917 | struct ehci_soft_itd *itd, *freeitd; |
2918 | usbd_status err; | | 2918 | usbd_status err; |
2919 | int i, offs, frindex, previndex; | | 2919 | int i, offs, frindex, previndex; |
2920 | usb_dma_t dma; | | 2920 | usb_dma_t dma; |
2921 | | | 2921 | |
2922 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2922 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2923 | | | 2923 | |
2924 | mutex_enter(&sc->sc_lock); | | 2924 | mutex_enter(&sc->sc_lock); |
2925 | | | 2925 | |
2926 | /* | | 2926 | /* |
2927 | * Find an itd that wasn't freed this frame or last frame. This can | | 2927 | * Find an itd that wasn't freed this frame or last frame. This can |
2928 | * discard itds that were freed before frindex wrapped around | | 2928 | * discard itds that were freed before frindex wrapped around |
2929 | * XXX - can this lead to thrashing? Could fix by enabling wrap-around | | 2929 | * XXX - can this lead to thrashing? Could fix by enabling wrap-around |
2930 | * interrupt and fiddling with list when that happens | | 2930 | * interrupt and fiddling with list when that happens |
2931 | */ | | 2931 | */ |
2932 | frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3; | | 2932 | frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3; |
2933 | previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize; | | 2933 | previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize; |
2934 | | | 2934 | |
2935 | freeitd = NULL; | | 2935 | freeitd = NULL; |
2936 | LIST_FOREACH(itd, &sc->sc_freeitds, u.free_list) { | | 2936 | LIST_FOREACH(itd, &sc->sc_freeitds, u.free_list) { |
2937 | if (itd == NULL) | | 2937 | if (itd == NULL) |
2938 | break; | | 2938 | break; |
2939 | if (itd->slot != frindex && itd->slot != previndex) { | | 2939 | if (itd->slot != frindex && itd->slot != previndex) { |
2940 | freeitd = itd; | | 2940 | freeitd = itd; |
2941 | break; | | 2941 | break; |
2942 | } | | 2942 | } |
2943 | } | | 2943 | } |
2944 | | | 2944 | |
2945 | if (freeitd == NULL) { | | 2945 | if (freeitd == NULL) { |
2946 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); | | 2946 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); |
2947 | err = usb_allocmem(&sc->sc_bus, EHCI_ITD_SIZE * EHCI_ITD_CHUNK, | | 2947 | err = usb_allocmem(&sc->sc_bus, EHCI_ITD_SIZE * EHCI_ITD_CHUNK, |
2948 | EHCI_PAGE_SIZE, &dma); | | 2948 | EHCI_PAGE_SIZE, &dma); |
2949 | | | 2949 | |
2950 | if (err) { | | 2950 | if (err) { |
2951 | USBHIST_LOG(ehcidebug, | | 2951 | USBHIST_LOG(ehcidebug, |
2952 | "alloc returned %d", err, 0, 0, 0); | | 2952 | "alloc returned %d", err, 0, 0, 0); |
2953 | mutex_exit(&sc->sc_lock); | | 2953 | mutex_exit(&sc->sc_lock); |
2954 | return NULL; | | 2954 | return NULL; |
2955 | } | | 2955 | } |
2956 | | | 2956 | |
2957 | for (i = 0; i < EHCI_ITD_CHUNK; i++) { | | 2957 | for (i = 0; i < EHCI_ITD_CHUNK; i++) { |
2958 | offs = i * EHCI_ITD_SIZE; | | 2958 | offs = i * EHCI_ITD_SIZE; |
2959 | itd = KERNADDR(&dma, offs); | | 2959 | itd = KERNADDR(&dma, offs); |
2960 | itd->physaddr = DMAADDR(&dma, offs); | | 2960 | itd->physaddr = DMAADDR(&dma, offs); |
2961 | itd->dma = dma; | | 2961 | itd->dma = dma; |
2962 | itd->offs = offs; | | 2962 | itd->offs = offs; |
2963 | LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list); | | 2963 | LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list); |
2964 | } | | 2964 | } |
2965 | freeitd = LIST_FIRST(&sc->sc_freeitds); | | 2965 | freeitd = LIST_FIRST(&sc->sc_freeitds); |
2966 | } | | 2966 | } |
2967 | | | 2967 | |
2968 | itd = freeitd; | | 2968 | itd = freeitd; |
2969 | LIST_REMOVE(itd, u.free_list); | | 2969 | LIST_REMOVE(itd, u.free_list); |
2970 | memset(&itd->itd, 0, sizeof(ehci_itd_t)); | | 2970 | memset(&itd->itd, 0, sizeof(ehci_itd_t)); |
2971 | usb_syncmem(&itd->dma, itd->offs + offsetof(ehci_itd_t, itd_next), | | 2971 | usb_syncmem(&itd->dma, itd->offs + offsetof(ehci_itd_t, itd_next), |
2972 | sizeof(itd->itd.itd_next), | | 2972 | sizeof(itd->itd.itd_next), |
2973 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2973 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2974 | | | 2974 | |
2975 | itd->u.frame_list.next = NULL; | | 2975 | itd->u.frame_list.next = NULL; |
2976 | itd->u.frame_list.prev = NULL; | | 2976 | itd->u.frame_list.prev = NULL; |
2977 | itd->xfer_next = NULL; | | 2977 | itd->xfer_next = NULL; |
2978 | itd->slot = 0; | | 2978 | itd->slot = 0; |
2979 | | | 2979 | |
2980 | mutex_exit(&sc->sc_lock); | | 2980 | mutex_exit(&sc->sc_lock); |
2981 | | | 2981 | |
2982 | return itd; | | 2982 | return itd; |
2983 | } | | 2983 | } |
2984 | | | 2984 | |
2985 | Static ehci_soft_sitd_t * | | 2985 | Static ehci_soft_sitd_t * |
2986 | ehci_alloc_sitd(ehci_softc_t *sc) | | 2986 | ehci_alloc_sitd(ehci_softc_t *sc) |
2987 | { | | 2987 | { |
2988 | struct ehci_soft_sitd *sitd, *freesitd; | | 2988 | struct ehci_soft_sitd *sitd, *freesitd; |
2989 | usbd_status err; | | 2989 | usbd_status err; |
2990 | int i, offs, frindex, previndex; | | 2990 | int i, offs, frindex, previndex; |
2991 | usb_dma_t dma; | | 2991 | usb_dma_t dma; |
2992 | | | 2992 | |
2993 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2993 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2994 | | | 2994 | |
2995 | mutex_enter(&sc->sc_lock); | | 2995 | mutex_enter(&sc->sc_lock); |
2996 | | | 2996 | |
2997 | /* | | 2997 | /* |
2998 | * Find an sitd that wasn't freed this frame or last frame. This can | | 2998 | * Find an sitd that wasn't freed this frame or last frame. This can |
2999 | * discard sitds that were freed before frindex wrapped around | | 2999 | * discard sitds that were freed before frindex wrapped around |
3000 | * XXX - can this lead to thrashing? Could fix by enabling wrap-around | | 3000 | * XXX - can this lead to thrashing? Could fix by enabling wrap-around |
3001 | * interrupt and fiddling with list when that happens | | 3001 | * interrupt and fiddling with list when that happens |
3002 | */ | | 3002 | */ |
3003 | frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3; | | 3003 | frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3; |
3004 | previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize; | | 3004 | previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize; |
3005 | | | 3005 | |
3006 | freesitd = NULL; | | 3006 | freesitd = NULL; |
3007 | LIST_FOREACH(sitd, &sc->sc_freesitds, u.free_list) { | | 3007 | LIST_FOREACH(sitd, &sc->sc_freesitds, u.free_list) { |
3008 | if (sitd == NULL) | | 3008 | if (sitd == NULL) |
3009 | break; | | 3009 | break; |
3010 | if (sitd->slot != frindex && sitd->slot != previndex) { | | 3010 | if (sitd->slot != frindex && sitd->slot != previndex) { |
3011 | freesitd = sitd; | | 3011 | freesitd = sitd; |
3012 | break; | | 3012 | break; |
3013 | } | | 3013 | } |
3014 | } | | 3014 | } |
3015 | | | 3015 | |
3016 | if (freesitd == NULL) { | | 3016 | if (freesitd == NULL) { |
3017 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); | | 3017 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); |
3018 | err = usb_allocmem(&sc->sc_bus, EHCI_SITD_SIZE * EHCI_SITD_CHUNK, | | 3018 | err = usb_allocmem(&sc->sc_bus, EHCI_SITD_SIZE * EHCI_SITD_CHUNK, |
3019 | EHCI_PAGE_SIZE, &dma); | | 3019 | EHCI_PAGE_SIZE, &dma); |
3020 | | | 3020 | |
3021 | if (err) { | | 3021 | if (err) { |
3022 | USBHIST_LOG(ehcidebug, | | 3022 | USBHIST_LOG(ehcidebug, |
3023 | "alloc returned %d", err, 0, 0, 0); | | 3023 | "alloc returned %d", err, 0, 0, 0); |
3024 | mutex_exit(&sc->sc_lock); | | 3024 | mutex_exit(&sc->sc_lock); |
3025 | return NULL; | | 3025 | return NULL; |
3026 | } | | 3026 | } |
3027 | | | 3027 | |
3028 | for (i = 0; i < EHCI_SITD_CHUNK; i++) { | | 3028 | for (i = 0; i < EHCI_SITD_CHUNK; i++) { |
3029 | offs = i * EHCI_SITD_SIZE; | | 3029 | offs = i * EHCI_SITD_SIZE; |
3030 | sitd = KERNADDR(&dma, offs); | | 3030 | sitd = KERNADDR(&dma, offs); |
3031 | sitd->physaddr = DMAADDR(&dma, offs); | | 3031 | sitd->physaddr = DMAADDR(&dma, offs); |
3032 | sitd->dma = dma; | | 3032 | sitd->dma = dma; |
3033 | sitd->offs = offs; | | 3033 | sitd->offs = offs; |
3034 | LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list); | | 3034 | LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list); |
3035 | } | | 3035 | } |
3036 | freesitd = LIST_FIRST(&sc->sc_freesitds); | | 3036 | freesitd = LIST_FIRST(&sc->sc_freesitds); |
3037 | } | | 3037 | } |
3038 | | | 3038 | |
3039 | sitd = freesitd; | | 3039 | sitd = freesitd; |
3040 | LIST_REMOVE(sitd, u.free_list); | | 3040 | LIST_REMOVE(sitd, u.free_list); |
3041 | memset(&sitd->sitd, 0, sizeof(ehci_sitd_t)); | | 3041 | memset(&sitd->sitd, 0, sizeof(ehci_sitd_t)); |
3042 | usb_syncmem(&sitd->dma, sitd->offs + offsetof(ehci_sitd_t, sitd_next), | | 3042 | usb_syncmem(&sitd->dma, sitd->offs + offsetof(ehci_sitd_t, sitd_next), |
3043 | sizeof(sitd->sitd.sitd_next), BUS_DMASYNC_PREWRITE | | | 3043 | sizeof(sitd->sitd.sitd_next), BUS_DMASYNC_PREWRITE | |
3044 | BUS_DMASYNC_PREREAD); | | 3044 | BUS_DMASYNC_PREREAD); |
3045 | | | 3045 | |
3046 | sitd->u.frame_list.next = NULL; | | 3046 | sitd->u.frame_list.next = NULL; |
3047 | sitd->u.frame_list.prev = NULL; | | 3047 | sitd->u.frame_list.prev = NULL; |
3048 | sitd->xfer_next = NULL; | | 3048 | sitd->xfer_next = NULL; |
3049 | sitd->slot = 0; | | 3049 | sitd->slot = 0; |
3050 | | | 3050 | |
3051 | mutex_exit(&sc->sc_lock); | | 3051 | mutex_exit(&sc->sc_lock); |
3052 | | | 3052 | |
3053 | return sitd; | | 3053 | return sitd; |
3054 | } | | 3054 | } |
3055 | | | 3055 | |
3056 | Static void | | 3056 | Static void |
3057 | ehci_free_itd(ehci_softc_t *sc, ehci_soft_itd_t *itd) | | 3057 | ehci_free_itd(ehci_softc_t *sc, ehci_soft_itd_t *itd) |
3058 | { | | 3058 | { |
3059 | | | 3059 | |
3060 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3060 | KASSERT(mutex_owned(&sc->sc_lock)); |
3061 | | | 3061 | |
3062 | LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list); | | 3062 | LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list); |
3063 | } | | 3063 | } |
3064 | | | 3064 | |
3065 | Static void | | 3065 | Static void |
3066 | ehci_free_sitd(ehci_softc_t *sc, ehci_soft_sitd_t *sitd) | | 3066 | ehci_free_sitd(ehci_softc_t *sc, ehci_soft_sitd_t *sitd) |
3067 | { | | 3067 | { |
3068 | | | 3068 | |
3069 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3069 | KASSERT(mutex_owned(&sc->sc_lock)); |
3070 | | | 3070 | |
3071 | LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list); | | 3071 | LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list); |
3072 | } | | 3072 | } |
3073 | | | 3073 | |
3074 | /****************/ | | 3074 | /****************/ |
3075 | | | 3075 | |
3076 | /* | | 3076 | /* |
3077 | * Close a reqular pipe. | | 3077 | * Close a reqular pipe. |
3078 | * Assumes that there are no pending transactions. | | 3078 | * Assumes that there are no pending transactions. |
3079 | */ | | 3079 | */ |
3080 | Static void | | 3080 | Static void |
3081 | ehci_close_pipe(usbd_pipe_handle pipe, ehci_soft_qh_t *head) | | 3081 | ehci_close_pipe(usbd_pipe_handle pipe, ehci_soft_qh_t *head) |
3082 | { | | 3082 | { |
3083 | struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; | | 3083 | struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; |
3084 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; | | 3084 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; |
3085 | ehci_soft_qh_t *sqh = epipe->sqh; | | 3085 | ehci_soft_qh_t *sqh = epipe->sqh; |
3086 | | | 3086 | |
3087 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3087 | KASSERT(mutex_owned(&sc->sc_lock)); |
3088 | | | 3088 | |
3089 | ehci_rem_qh(sc, sqh, head); | | 3089 | ehci_rem_qh(sc, sqh, head); |
3090 | ehci_free_sqh(sc, epipe->sqh); | | 3090 | ehci_free_sqh(sc, epipe->sqh); |
3091 | } | | 3091 | } |
3092 | | | 3092 | |
3093 | /* | | 3093 | /* |
3094 | * Abort a device request. | | 3094 | * Abort a device request. |
3095 | * If this routine is called at splusb() it guarantees that the request | | 3095 | * If this routine is called at splusb() it guarantees that the request |
3096 | * will be removed from the hardware scheduling and that the callback | | 3096 | * will be removed from the hardware scheduling and that the callback |
3097 | * for it will be called with USBD_CANCELLED status. | | 3097 | * for it will be called with USBD_CANCELLED status. |
3098 | * It's impossible to guarantee that the requested transfer will not | | 3098 | * It's impossible to guarantee that the requested transfer will not |
3099 | * have happened since the hardware runs concurrently. | | 3099 | * have happened since the hardware runs concurrently. |
3100 | * If the transaction has already happened we rely on the ordinary | | 3100 | * If the transaction has already happened we rely on the ordinary |
3101 | * interrupt processing to process it. | | 3101 | * interrupt processing to process it. |
3102 | * XXX This is most probably wrong. | | 3102 | * XXX This is most probably wrong. |
3103 | * XXXMRG this doesn't make sense anymore. | | 3103 | * XXXMRG this doesn't make sense anymore. |
3104 | */ | | 3104 | */ |
3105 | Static void | | 3105 | Static void |
3106 | ehci_abort_xfer(usbd_xfer_handle xfer, usbd_status status) | | 3106 | ehci_abort_xfer(usbd_xfer_handle xfer, usbd_status status) |
3107 | { | | 3107 | { |
3108 | #define exfer EXFER(xfer) | | 3108 | #define exfer EXFER(xfer) |
3109 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; | | 3109 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; |
3110 | ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; | | 3110 | ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; |
3111 | ehci_soft_qh_t *sqh = epipe->sqh; | | 3111 | ehci_soft_qh_t *sqh = epipe->sqh; |
3112 | ehci_soft_qtd_t *sqtd; | | 3112 | ehci_soft_qtd_t *sqtd; |
3113 | ehci_physaddr_t cur; | | 3113 | ehci_physaddr_t cur; |
3114 | uint32_t qhstatus; | | 3114 | uint32_t qhstatus; |
3115 | int hit; | | 3115 | int hit; |
3116 | int wake; | | 3116 | int wake; |
3117 | | | 3117 | |
3118 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3118 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3119 | | | 3119 | |
3120 | USBHIST_LOG(ehcidebug, "xfer=%p pipe=%p", xfer, epipe, 0, 0); | | 3120 | USBHIST_LOG(ehcidebug, "xfer=%p pipe=%p", xfer, epipe, 0, 0); |
3121 | | | 3121 | |
3122 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3122 | KASSERT(mutex_owned(&sc->sc_lock)); |
3123 | ASSERT_SLEEPABLE(); | | 3123 | ASSERT_SLEEPABLE(); |
3124 | | | 3124 | |
3125 | if (sc->sc_dying) { | | 3125 | if (sc->sc_dying) { |
3126 | /* If we're dying, just do the software part. */ | | 3126 | /* If we're dying, just do the software part. */ |
3127 | xfer->ux_status = status; /* make software ignore it */ | | 3127 | xfer->ux_status = status; /* make software ignore it */ |
3128 | callout_stop(&xfer->ux_callout); | | 3128 | callout_stop(&xfer->ux_callout); |
3129 | usb_transfer_complete(xfer); | | 3129 | usb_transfer_complete(xfer); |
3130 | return; | | 3130 | return; |
3131 | } | | 3131 | } |
3132 | | | 3132 | |
3133 | /* | | 3133 | /* |
3134 | * If an abort is already in progress then just wait for it to | | 3134 | * If an abort is already in progress then just wait for it to |
3135 | * complete and return. | | 3135 | * complete and return. |
3136 | */ | | 3136 | */ |
3137 | if (xfer->ux_hcflags & UXFER_ABORTING) { | | 3137 | if (xfer->ux_hcflags & UXFER_ABORTING) { |
3138 | USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0); | | 3138 | USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0); |
3139 | #ifdef DIAGNOSTIC | | 3139 | #ifdef DIAGNOSTIC |
3140 | if (status == USBD_TIMEOUT) | | 3140 | if (status == USBD_TIMEOUT) |
3141 | printf("ehci_abort_xfer: TIMEOUT while aborting\n"); | | 3141 | printf("ehci_abort_xfer: TIMEOUT while aborting\n"); |
3142 | #endif | | 3142 | #endif |
3143 | /* Override the status which might be USBD_TIMEOUT. */ | | 3143 | /* Override the status which might be USBD_TIMEOUT. */ |
3144 | xfer->ux_status = status; | | 3144 | xfer->ux_status = status; |
3145 | USBHIST_LOG(ehcidebug, "waiting for abort to finish", | | 3145 | USBHIST_LOG(ehcidebug, "waiting for abort to finish", |
3146 | 0, 0, 0, 0); | | 3146 | 0, 0, 0, 0); |
3147 | xfer->ux_hcflags |= UXFER_ABORTWAIT; | | 3147 | xfer->ux_hcflags |= UXFER_ABORTWAIT; |
3148 | while (xfer->ux_hcflags & UXFER_ABORTING) | | 3148 | while (xfer->ux_hcflags & UXFER_ABORTING) |
3149 | cv_wait(&xfer->ux_hccv, &sc->sc_lock); | | 3149 | cv_wait(&xfer->ux_hccv, &sc->sc_lock); |
3150 | return; | | 3150 | return; |
3151 | } | | 3151 | } |
3152 | xfer->ux_hcflags |= UXFER_ABORTING; | | 3152 | xfer->ux_hcflags |= UXFER_ABORTING; |
3153 | | | 3153 | |
3154 | /* | | 3154 | /* |
3155 | * Step 1: Make interrupt routine and hardware ignore xfer. | | 3155 | * Step 1: Make interrupt routine and hardware ignore xfer. |
3156 | */ | | 3156 | */ |
3157 | xfer->ux_status = status; /* make software ignore it */ | | 3157 | xfer->ux_status = status; /* make software ignore it */ |
3158 | callout_stop(&xfer->ux_callout); | | 3158 | callout_stop(&xfer->ux_callout); |
3159 | | | 3159 | |
3160 | usb_syncmem(&sqh->dma, | | 3160 | usb_syncmem(&sqh->dma, |
3161 | sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), | | 3161 | sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), |
3162 | sizeof(sqh->qh.qh_qtd.qtd_status), | | 3162 | sizeof(sqh->qh.qh_qtd.qtd_status), |
3163 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 3163 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
3164 | qhstatus = sqh->qh.qh_qtd.qtd_status; | | 3164 | qhstatus = sqh->qh.qh_qtd.qtd_status; |
3165 | sqh->qh.qh_qtd.qtd_status = qhstatus | htole32(EHCI_QTD_HALTED); | | 3165 | sqh->qh.qh_qtd.qtd_status = qhstatus | htole32(EHCI_QTD_HALTED); |
3166 | usb_syncmem(&sqh->dma, | | 3166 | usb_syncmem(&sqh->dma, |
3167 | sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), | | 3167 | sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), |
3168 | sizeof(sqh->qh.qh_qtd.qtd_status), | | 3168 | sizeof(sqh->qh.qh_qtd.qtd_status), |
3169 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3169 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3170 | for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) { | | 3170 | for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) { |
3171 | usb_syncmem(&sqtd->dma, | | 3171 | usb_syncmem(&sqtd->dma, |
3172 | sqtd->offs + offsetof(ehci_qtd_t, qtd_status), | | 3172 | sqtd->offs + offsetof(ehci_qtd_t, qtd_status), |
3173 | sizeof(sqtd->qtd.qtd_status), | | 3173 | sizeof(sqtd->qtd.qtd_status), |
3174 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 3174 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
3175 | sqtd->qtd.qtd_status |= htole32(EHCI_QTD_HALTED); | | 3175 | sqtd->qtd.qtd_status |= htole32(EHCI_QTD_HALTED); |
3176 | usb_syncmem(&sqtd->dma, | | 3176 | usb_syncmem(&sqtd->dma, |
3177 | sqtd->offs + offsetof(ehci_qtd_t, qtd_status), | | 3177 | sqtd->offs + offsetof(ehci_qtd_t, qtd_status), |
3178 | sizeof(sqtd->qtd.qtd_status), | | 3178 | sizeof(sqtd->qtd.qtd_status), |
3179 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3179 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3180 | if (sqtd == exfer->ex_sqtdend) | | 3180 | if (sqtd == exfer->ex_sqtdend) |
3181 | break; | | 3181 | break; |
3182 | } | | 3182 | } |
3183 | | | 3183 | |
3184 | /* | | 3184 | /* |
3185 | * Step 2: Wait until we know hardware has finished any possible | | 3185 | * Step 2: Wait until we know hardware has finished any possible |
3186 | * use of the xfer. Also make sure the soft interrupt routine | | 3186 | * use of the xfer. Also make sure the soft interrupt routine |
3187 | * has run. | | 3187 | * has run. |
3188 | */ | | 3188 | */ |
3189 | ehci_sync_hc(sc); | | 3189 | ehci_sync_hc(sc); |
3190 | sc->sc_softwake = 1; | | 3190 | sc->sc_softwake = 1; |
3191 | usb_schedsoftintr(&sc->sc_bus); | | 3191 | usb_schedsoftintr(&sc->sc_bus); |
3192 | cv_wait(&sc->sc_softwake_cv, &sc->sc_lock); | | 3192 | cv_wait(&sc->sc_softwake_cv, &sc->sc_lock); |
3193 | | | 3193 | |
3194 | /* | | 3194 | /* |
3195 | * Step 3: Remove any vestiges of the xfer from the hardware. | | 3195 | * Step 3: Remove any vestiges of the xfer from the hardware. |
3196 | * The complication here is that the hardware may have executed | | 3196 | * The complication here is that the hardware may have executed |
3197 | * beyond the xfer we're trying to abort. So as we're scanning | | 3197 | * beyond the xfer we're trying to abort. So as we're scanning |
3198 | * the TDs of this xfer we check if the hardware points to | | 3198 | * the TDs of this xfer we check if the hardware points to |
3199 | * any of them. | | 3199 | * any of them. |
3200 | */ | | 3200 | */ |
3201 | | | 3201 | |
3202 | usb_syncmem(&sqh->dma, | | 3202 | usb_syncmem(&sqh->dma, |
3203 | sqh->offs + offsetof(ehci_qh_t, qh_curqtd), | | 3203 | sqh->offs + offsetof(ehci_qh_t, qh_curqtd), |
3204 | sizeof(sqh->qh.qh_curqtd), | | 3204 | sizeof(sqh->qh.qh_curqtd), |
3205 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 3205 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
3206 | cur = EHCI_LINK_ADDR(le32toh(sqh->qh.qh_curqtd)); | | 3206 | cur = EHCI_LINK_ADDR(le32toh(sqh->qh.qh_curqtd)); |
3207 | hit = 0; | | 3207 | hit = 0; |
3208 | for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) { | | 3208 | for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) { |
3209 | hit |= cur == sqtd->physaddr; | | 3209 | hit |= cur == sqtd->physaddr; |
3210 | if (sqtd == exfer->ex_sqtdend) | | 3210 | if (sqtd == exfer->ex_sqtdend) |
3211 | break; | | 3211 | break; |
3212 | } | | 3212 | } |
3213 | sqtd = sqtd->nextqtd; | | 3213 | sqtd = sqtd->nextqtd; |
3214 | /* Zap curqtd register if hardware pointed inside the xfer. */ | | 3214 | /* Zap curqtd register if hardware pointed inside the xfer. */ |
3215 | if (hit && sqtd != NULL) { | | 3215 | if (hit && sqtd != NULL) { |
3216 | USBHIST_LOG(ehcidebug, "cur=0x%08x", sqtd->physaddr, 0, 0, 0); | | 3216 | USBHIST_LOG(ehcidebug, "cur=0x%08x", sqtd->physaddr, 0, 0, 0); |
3217 | sqh->qh.qh_curqtd = htole32(sqtd->physaddr); /* unlink qTDs */ | | 3217 | sqh->qh.qh_curqtd = htole32(sqtd->physaddr); /* unlink qTDs */ |
3218 | usb_syncmem(&sqh->dma, | | 3218 | usb_syncmem(&sqh->dma, |
3219 | sqh->offs + offsetof(ehci_qh_t, qh_curqtd), | | 3219 | sqh->offs + offsetof(ehci_qh_t, qh_curqtd), |
3220 | sizeof(sqh->qh.qh_curqtd), | | 3220 | sizeof(sqh->qh.qh_curqtd), |
3221 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3221 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3222 | sqh->qh.qh_qtd.qtd_status = qhstatus; | | 3222 | sqh->qh.qh_qtd.qtd_status = qhstatus; |
3223 | usb_syncmem(&sqh->dma, | | 3223 | usb_syncmem(&sqh->dma, |
3224 | sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), | | 3224 | sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), |
3225 | sizeof(sqh->qh.qh_qtd.qtd_status), | | 3225 | sizeof(sqh->qh.qh_qtd.qtd_status), |
3226 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3226 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3227 | } else { | | 3227 | } else { |
3228 | USBHIST_LOG(ehcidebug, "no hit", 0, 0, 0, 0); | | 3228 | USBHIST_LOG(ehcidebug, "no hit", 0, 0, 0, 0); |
3229 | } | | 3229 | } |
3230 | | | 3230 | |
3231 | /* | | 3231 | /* |
3232 | * Step 4: Execute callback. | | 3232 | * Step 4: Execute callback. |
3233 | */ | | 3233 | */ |
3234 | #ifdef DIAGNOSTIC | | 3234 | #ifdef DIAGNOSTIC |
3235 | exfer->ex_isdone = true; | | 3235 | exfer->ex_isdone = true; |
3236 | #endif | | 3236 | #endif |
3237 | wake = xfer->ux_hcflags & UXFER_ABORTWAIT; | | 3237 | wake = xfer->ux_hcflags & UXFER_ABORTWAIT; |
3238 | xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT); | | 3238 | xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT); |
3239 | usb_transfer_complete(xfer); | | 3239 | usb_transfer_complete(xfer); |
3240 | if (wake) { | | 3240 | if (wake) { |
3241 | cv_broadcast(&xfer->ux_hccv); | | 3241 | cv_broadcast(&xfer->ux_hccv); |
3242 | } | | 3242 | } |
3243 | | | 3243 | |
3244 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3244 | KASSERT(mutex_owned(&sc->sc_lock)); |
3245 | #undef exfer | | 3245 | #undef exfer |
3246 | } | | 3246 | } |
3247 | | | 3247 | |
3248 | Static void | | 3248 | Static void |
3249 | ehci_abort_isoc_xfer(usbd_xfer_handle xfer, usbd_status status) | | 3249 | ehci_abort_isoc_xfer(usbd_xfer_handle xfer, usbd_status status) |
3250 | { | | 3250 | { |
3251 | ehci_isoc_trans_t trans_status; | | 3251 | ehci_isoc_trans_t trans_status; |
3252 | struct ehci_pipe *epipe; | | 3252 | struct ehci_pipe *epipe; |
3253 | struct ehci_xfer *exfer; | | 3253 | struct ehci_xfer *exfer; |
3254 | ehci_softc_t *sc; | | 3254 | ehci_softc_t *sc; |
3255 | struct ehci_soft_itd *itd; | | 3255 | struct ehci_soft_itd *itd; |
3256 | struct ehci_soft_sitd *sitd; | | 3256 | struct ehci_soft_sitd *sitd; |
3257 | int i, wake; | | 3257 | int i, wake; |
3258 | | | 3258 | |
3259 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3259 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3260 | | | 3260 | |
3261 | epipe = (struct ehci_pipe *) xfer->ux_pipe; | | 3261 | epipe = (struct ehci_pipe *) xfer->ux_pipe; |
3262 | exfer = EXFER(xfer); | | 3262 | exfer = EXFER(xfer); |
3263 | sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; | | 3263 | sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; |
3264 | | | 3264 | |
3265 | USBHIST_LOG(ehcidebug, "xfer %p pipe %p", xfer, epipe, 0, 0); | | 3265 | USBHIST_LOG(ehcidebug, "xfer %p pipe %p", xfer, epipe, 0, 0); |
3266 | | | 3266 | |
3267 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3267 | KASSERT(mutex_owned(&sc->sc_lock)); |
3268 | | | 3268 | |
3269 | if (sc->sc_dying) { | | 3269 | if (sc->sc_dying) { |
3270 | xfer->ux_status = status; | | 3270 | xfer->ux_status = status; |
3271 | callout_stop(&xfer->ux_callout); | | 3271 | callout_stop(&xfer->ux_callout); |
3272 | usb_transfer_complete(xfer); | | 3272 | usb_transfer_complete(xfer); |
3273 | return; | | 3273 | return; |
3274 | } | | 3274 | } |
3275 | | | 3275 | |
3276 | if (xfer->ux_hcflags & UXFER_ABORTING) { | | 3276 | if (xfer->ux_hcflags & UXFER_ABORTING) { |
3277 | USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0); | | 3277 | USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0); |
3278 | | | 3278 | |
3279 | #ifdef DIAGNOSTIC | | 3279 | #ifdef DIAGNOSTIC |
3280 | if (status == USBD_TIMEOUT) | | 3280 | if (status == USBD_TIMEOUT) |
3281 | printf("ehci_abort_isoc_xfer: TIMEOUT while aborting\n"); | | 3281 | printf("ehci_abort_isoc_xfer: TIMEOUT while aborting\n"); |
3282 | #endif | | 3282 | #endif |
3283 | | | 3283 | |
3284 | xfer->ux_status = status; | | 3284 | xfer->ux_status = status; |
3285 | USBHIST_LOG(ehcidebug, | | 3285 | USBHIST_LOG(ehcidebug, |
3286 | "waiting for abort to finish", 0, 0, 0, 0); | | 3286 | "waiting for abort to finish", 0, 0, 0, 0); |
3287 | xfer->ux_hcflags |= UXFER_ABORTWAIT; | | 3287 | xfer->ux_hcflags |= UXFER_ABORTWAIT; |
3288 | while (xfer->ux_hcflags & UXFER_ABORTING) | | 3288 | while (xfer->ux_hcflags & UXFER_ABORTING) |
3289 | cv_wait(&xfer->ux_hccv, &sc->sc_lock); | | 3289 | cv_wait(&xfer->ux_hccv, &sc->sc_lock); |
3290 | goto done; | | 3290 | goto done; |
3291 | } | | 3291 | } |
3292 | xfer->ux_hcflags |= UXFER_ABORTING; | | 3292 | xfer->ux_hcflags |= UXFER_ABORTING; |
3293 | | | 3293 | |
3294 | xfer->ux_status = status; | | 3294 | xfer->ux_status = status; |
3295 | callout_stop(&xfer->ux_callout); | | 3295 | callout_stop(&xfer->ux_callout); |
3296 | | | 3296 | |
3297 | if (xfer->ux_pipe->up_dev->ud_speed == USB_SPEED_HIGH) { | | 3297 | if (xfer->ux_pipe->up_dev->ud_speed == USB_SPEED_HIGH) { |
3298 | for (itd = exfer->ex_itdstart; itd != NULL; | | 3298 | for (itd = exfer->ex_itdstart; itd != NULL; |
3299 | itd = itd->xfer_next) { | | 3299 | itd = itd->xfer_next) { |
3300 | usb_syncmem(&itd->dma, | | 3300 | usb_syncmem(&itd->dma, |
3301 | itd->offs + offsetof(ehci_itd_t, itd_ctl), | | 3301 | itd->offs + offsetof(ehci_itd_t, itd_ctl), |
3302 | sizeof(itd->itd.itd_ctl), | | 3302 | sizeof(itd->itd.itd_ctl), |
3303 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 3303 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
3304 | | | 3304 | |
3305 | for (i = 0; i < 8; i++) { | | 3305 | for (i = 0; i < 8; i++) { |
3306 | trans_status = le32toh(itd->itd.itd_ctl[i]); | | 3306 | trans_status = le32toh(itd->itd.itd_ctl[i]); |
3307 | trans_status &= ~EHCI_ITD_ACTIVE; | | 3307 | trans_status &= ~EHCI_ITD_ACTIVE; |
3308 | itd->itd.itd_ctl[i] = htole32(trans_status); | | 3308 | itd->itd.itd_ctl[i] = htole32(trans_status); |
3309 | } | | 3309 | } |
3310 | | | 3310 | |
3311 | usb_syncmem(&itd->dma, | | 3311 | usb_syncmem(&itd->dma, |
3312 | itd->offs + offsetof(ehci_itd_t, itd_ctl), | | 3312 | itd->offs + offsetof(ehci_itd_t, itd_ctl), |
3313 | sizeof(itd->itd.itd_ctl), | | 3313 | sizeof(itd->itd.itd_ctl), |
3314 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3314 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3315 | } | | 3315 | } |
3316 | } else { | | 3316 | } else { |
3317 | for (sitd = exfer->ex_sitdstart; sitd != NULL; | | 3317 | for (sitd = exfer->ex_sitdstart; sitd != NULL; |
3318 | sitd = sitd->xfer_next) { | | 3318 | sitd = sitd->xfer_next) { |
3319 | usb_syncmem(&sitd->dma, | | 3319 | usb_syncmem(&sitd->dma, |
3320 | sitd->offs + offsetof(ehci_sitd_t, sitd_buffer), | | 3320 | sitd->offs + offsetof(ehci_sitd_t, sitd_buffer), |
3321 | sizeof(sitd->sitd.sitd_buffer), | | 3321 | sizeof(sitd->sitd.sitd_buffer), |
3322 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 3322 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
3323 | | | 3323 | |
3324 | trans_status = le32toh(sitd->sitd.sitd_trans); | | 3324 | trans_status = le32toh(sitd->sitd.sitd_trans); |
3325 | trans_status &= ~EHCI_SITD_ACTIVE; | | 3325 | trans_status &= ~EHCI_SITD_ACTIVE; |
3326 | sitd->sitd.sitd_trans = htole32(trans_status); | | 3326 | sitd->sitd.sitd_trans = htole32(trans_status); |
3327 | | | 3327 | |
3328 | usb_syncmem(&sitd->dma, | | 3328 | usb_syncmem(&sitd->dma, |
3329 | sitd->offs + offsetof(ehci_sitd_t, sitd_buffer), | | 3329 | sitd->offs + offsetof(ehci_sitd_t, sitd_buffer), |
3330 | sizeof(sitd->sitd.sitd_buffer), | | 3330 | sizeof(sitd->sitd.sitd_buffer), |
3331 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3331 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3332 | } | | 3332 | } |
3333 | } | | 3333 | } |
3334 | | | 3334 | |
3335 | sc->sc_softwake = 1; | | 3335 | sc->sc_softwake = 1; |
3336 | usb_schedsoftintr(&sc->sc_bus); | | 3336 | usb_schedsoftintr(&sc->sc_bus); |
3337 | cv_wait(&sc->sc_softwake_cv, &sc->sc_lock); | | 3337 | cv_wait(&sc->sc_softwake_cv, &sc->sc_lock); |
3338 | | | 3338 | |
3339 | #ifdef DIAGNOSTIC | | 3339 | #ifdef DIAGNOSTIC |
3340 | exfer->ex_isdone = true; | | 3340 | exfer->ex_isdone = true; |
3341 | #endif | | 3341 | #endif |
3342 | wake = xfer->ux_hcflags & UXFER_ABORTWAIT; | | 3342 | wake = xfer->ux_hcflags & UXFER_ABORTWAIT; |
3343 | xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT); | | 3343 | xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT); |
3344 | usb_transfer_complete(xfer); | | 3344 | usb_transfer_complete(xfer); |
3345 | if (wake) { | | 3345 | if (wake) { |
3346 | cv_broadcast(&xfer->ux_hccv); | | 3346 | cv_broadcast(&xfer->ux_hccv); |
3347 | } | | 3347 | } |
3348 | | | 3348 | |
3349 | done: | | 3349 | done: |
3350 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3350 | KASSERT(mutex_owned(&sc->sc_lock)); |
3351 | return; | | 3351 | return; |
3352 | } | | 3352 | } |
3353 | | | 3353 | |
3354 | Static void | | 3354 | Static void |
3355 | ehci_timeout(void *addr) | | 3355 | ehci_timeout(void *addr) |
3356 | { | | 3356 | { |
3357 | struct ehci_xfer *exfer = addr; | | 3357 | struct ehci_xfer *exfer = addr; |
3358 | struct ehci_pipe *epipe = (struct ehci_pipe *)exfer->ex_xfer.ux_pipe; | | 3358 | struct ehci_pipe *epipe = (struct ehci_pipe *)exfer->ex_xfer.ux_pipe; |
3359 | ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; | | 3359 | ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; |
3360 | | | 3360 | |
3361 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3361 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3362 | | | 3362 | |
3363 | USBHIST_LOG(ehcidebug, "exfer %p", exfer, 0, 0, 0); | | 3363 | USBHIST_LOG(ehcidebug, "exfer %p", exfer, 0, 0, 0); |
3364 | #ifdef EHCI_DEBUG | | 3364 | #ifdef EHCI_DEBUG |
3365 | if (ehcidebug > 1) | | 3365 | if (ehcidebug > 1) |
3366 | usbd_dump_pipe(exfer->ex_xfer.ux_pipe); | | 3366 | usbd_dump_pipe(exfer->ex_xfer.ux_pipe); |
3367 | #endif | | 3367 | #endif |
3368 | | | 3368 | |
3369 | if (sc->sc_dying) { | | 3369 | if (sc->sc_dying) { |
3370 | mutex_enter(&sc->sc_lock); | | 3370 | mutex_enter(&sc->sc_lock); |
3371 | ehci_abort_xfer(&exfer->ex_xfer, USBD_TIMEOUT); | | 3371 | ehci_abort_xfer(&exfer->ex_xfer, USBD_TIMEOUT); |
3372 | mutex_exit(&sc->sc_lock); | | 3372 | mutex_exit(&sc->sc_lock); |
3373 | return; | | 3373 | return; |
3374 | } | | 3374 | } |
3375 | | | 3375 | |
3376 | /* Execute the abort in a process context. */ | | 3376 | /* Execute the abort in a process context. */ |
3377 | usb_init_task(&exfer->ex_aborttask, ehci_timeout_task, addr, | | 3377 | usb_init_task(&exfer->ex_aborttask, ehci_timeout_task, addr, |
3378 | USB_TASKQ_MPSAFE); | | 3378 | USB_TASKQ_MPSAFE); |
3379 | usb_add_task(exfer->ex_xfer.ux_pipe->up_dev, &exfer->ex_aborttask, | | 3379 | usb_add_task(exfer->ex_xfer.ux_pipe->up_dev, &exfer->ex_aborttask, |
3380 | USB_TASKQ_HC); | | 3380 | USB_TASKQ_HC); |
3381 | } | | 3381 | } |
3382 | | | 3382 | |
3383 | Static void | | 3383 | Static void |
3384 | ehci_timeout_task(void *addr) | | 3384 | ehci_timeout_task(void *addr) |
3385 | { | | 3385 | { |
3386 | usbd_xfer_handle xfer = addr; | | 3386 | usbd_xfer_handle xfer = addr; |
3387 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 3387 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
3388 | | | 3388 | |
3389 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3389 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3390 | | | 3390 | |
3391 | USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); | | 3391 | USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); |
3392 | | | 3392 | |
3393 | mutex_enter(&sc->sc_lock); | | 3393 | mutex_enter(&sc->sc_lock); |
3394 | ehci_abort_xfer(xfer, USBD_TIMEOUT); | | 3394 | ehci_abort_xfer(xfer, USBD_TIMEOUT); |
3395 | mutex_exit(&sc->sc_lock); | | 3395 | mutex_exit(&sc->sc_lock); |
3396 | } | | 3396 | } |
3397 | | | 3397 | |
3398 | /************************/ | | 3398 | /************************/ |
3399 | | | 3399 | |
3400 | Static usbd_status | | 3400 | Static usbd_status |
3401 | ehci_device_ctrl_transfer(usbd_xfer_handle xfer) | | 3401 | ehci_device_ctrl_transfer(usbd_xfer_handle xfer) |
3402 | { | | 3402 | { |
3403 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 3403 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
3404 | usbd_status err; | | 3404 | usbd_status err; |
3405 | | | 3405 | |
3406 | /* Insert last in queue. */ | | 3406 | /* Insert last in queue. */ |
3407 | mutex_enter(&sc->sc_lock); | | 3407 | mutex_enter(&sc->sc_lock); |
3408 | err = usb_insert_transfer(xfer); | | 3408 | err = usb_insert_transfer(xfer); |
3409 | mutex_exit(&sc->sc_lock); | | 3409 | mutex_exit(&sc->sc_lock); |
3410 | if (err) | | 3410 | if (err) |
3411 | return err; | | 3411 | return err; |
3412 | | | 3412 | |
3413 | /* Pipe isn't running, start first */ | | 3413 | /* Pipe isn't running, start first */ |
3414 | return ehci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); | | 3414 | return ehci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); |
3415 | } | | 3415 | } |
3416 | | | 3416 | |
3417 | Static usbd_status | | 3417 | Static usbd_status |
3418 | ehci_device_ctrl_start(usbd_xfer_handle xfer) | | 3418 | ehci_device_ctrl_start(usbd_xfer_handle xfer) |
3419 | { | | 3419 | { |
3420 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 3420 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
3421 | usbd_status err; | | 3421 | usbd_status err; |
3422 | | | 3422 | |
3423 | if (sc->sc_dying) | | 3423 | if (sc->sc_dying) |
3424 | return USBD_IOERROR; | | 3424 | return USBD_IOERROR; |
3425 | | | 3425 | |
3426 | KASSERT(xfer->ux_rqflags & URQ_REQUEST); | | 3426 | KASSERT(xfer->ux_rqflags & URQ_REQUEST); |
3427 | | | 3427 | |
3428 | err = ehci_device_request(xfer); | | 3428 | err = ehci_device_request(xfer); |
3429 | if (err) { | | 3429 | if (err) { |
3430 | return err; | | 3430 | return err; |
3431 | } | | 3431 | } |
3432 | | | 3432 | |
3433 | if (sc->sc_bus.ub_usepolling) | | 3433 | if (sc->sc_bus.ub_usepolling) |
3434 | ehci_waitintr(sc, xfer); | | 3434 | ehci_waitintr(sc, xfer); |
3435 | | | 3435 | |
3436 | return USBD_IN_PROGRESS; | | 3436 | return USBD_IN_PROGRESS; |
3437 | } | | 3437 | } |
3438 | | | 3438 | |
3439 | Static void | | 3439 | Static void |
3440 | ehci_device_ctrl_done(usbd_xfer_handle xfer) | | 3440 | ehci_device_ctrl_done(usbd_xfer_handle xfer) |
3441 | { | | 3441 | { |
3442 | struct ehci_xfer *ex = EXFER(xfer); | | 3442 | struct ehci_xfer *ex = EXFER(xfer); |
3443 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 3443 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
3444 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; | | 3444 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; |
3445 | usb_device_request_t *req = &xfer->ux_request; | | 3445 | usb_device_request_t *req = &xfer->ux_request; |
3446 | int len = UGETW(req->wLength); | | 3446 | int len = UGETW(req->wLength); |
3447 | int rd = req->bmRequestType & UT_READ; | | 3447 | int rd = req->bmRequestType & UT_READ; |
3448 | | | 3448 | |
3449 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3449 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3450 | | | 3450 | |
3451 | USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); | | 3451 | USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); |
3452 | | | 3452 | |
3453 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); | | 3453 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); |
3454 | KASSERT(xfer->ux_rqflags & URQ_REQUEST); | | 3454 | KASSERT(xfer->ux_rqflags & URQ_REQUEST); |
3455 | | | 3455 | |
3456 | if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { | | 3456 | if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { |
3457 | ehci_del_intr_list(sc, ex); /* remove from active list */ | | 3457 | ehci_del_intr_list(sc, ex); /* remove from active list */ |
3458 | ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); | | 3458 | ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); |
3459 | usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req), | | 3459 | usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req), |
3460 | BUS_DMASYNC_POSTWRITE); | | 3460 | BUS_DMASYNC_POSTWRITE); |
3461 | if (len) | | 3461 | if (len) |
3462 | usb_syncmem(&xfer->ux_dmabuf, 0, len, | | 3462 | usb_syncmem(&xfer->ux_dmabuf, 0, len, |
3463 | rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); | | 3463 | rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); |
3464 | } | | 3464 | } |
3465 | | | 3465 | |
3466 | USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0); | | 3466 | USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0); |
3467 | } | | 3467 | } |
3468 | | | 3468 | |
3469 | /* Abort a device control request. */ | | 3469 | /* Abort a device control request. */ |
3470 | Static void | | 3470 | Static void |
3471 | ehci_device_ctrl_abort(usbd_xfer_handle xfer) | | 3471 | ehci_device_ctrl_abort(usbd_xfer_handle xfer) |
3472 | { | | 3472 | { |
3473 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3473 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3474 | | | 3474 | |
3475 | USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); | | 3475 | USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); |
3476 | ehci_abort_xfer(xfer, USBD_CANCELLED); | | 3476 | ehci_abort_xfer(xfer, USBD_CANCELLED); |
3477 | } | | 3477 | } |
3478 | | | 3478 | |
3479 | /* Close a device control pipe. */ | | 3479 | /* Close a device control pipe. */ |
3480 | Static void | | 3480 | Static void |
3481 | ehci_device_ctrl_close(usbd_pipe_handle pipe) | | 3481 | ehci_device_ctrl_close(usbd_pipe_handle pipe) |
3482 | { | | 3482 | { |
3483 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; | | 3483 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; |
3484 | /*struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;*/ | | 3484 | /*struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;*/ |
3485 | | | 3485 | |
3486 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3486 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3487 | | | 3487 | |
3488 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3488 | KASSERT(mutex_owned(&sc->sc_lock)); |
3489 | | | 3489 | |
3490 | USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0); | | 3490 | USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0); |
3491 | | | 3491 | |
3492 | ehci_close_pipe(pipe, sc->sc_async_head); | | 3492 | ehci_close_pipe(pipe, sc->sc_async_head); |
3493 | } | | 3493 | } |
3494 | | | 3494 | |
3495 | Static usbd_status | | 3495 | Static usbd_status |
3496 | ehci_device_request(usbd_xfer_handle xfer) | | 3496 | ehci_device_request(usbd_xfer_handle xfer) |
3497 | { | | 3497 | { |
3498 | #define exfer EXFER(xfer) | | 3498 | #define exfer EXFER(xfer) |
3499 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; | | 3499 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; |
3500 | usb_device_request_t *req = &xfer->ux_request; | | 3500 | usb_device_request_t *req = &xfer->ux_request; |
3501 | usbd_device_handle dev = epipe->pipe.up_dev; | | 3501 | usbd_device_handle dev = epipe->pipe.up_dev; |
3502 | ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; | | 3502 | ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; |
3503 | ehci_soft_qtd_t *setup, *stat, *next; | | 3503 | ehci_soft_qtd_t *setup, *stat, *next; |
3504 | ehci_soft_qh_t *sqh; | | 3504 | ehci_soft_qh_t *sqh; |
3505 | int isread; | | 3505 | int isread; |
3506 | int len; | | 3506 | int len; |
3507 | usbd_status err; | | 3507 | usbd_status err; |
3508 | | | 3508 | |
3509 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3509 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3510 | | | 3510 | |
3511 | isread = req->bmRequestType & UT_READ; | | 3511 | isread = req->bmRequestType & UT_READ; |
3512 | len = UGETW(req->wLength); | | 3512 | len = UGETW(req->wLength); |
3513 | | | 3513 | |
3514 | USBHIST_LOG(ehcidebug, "type=0x%02x, request=0x%02x, " | | 3514 | USBHIST_LOG(ehcidebug, "type=0x%02x, request=0x%02x, " |
3515 | "wValue=0x%04x, wIndex=0x%04x", | | 3515 | "wValue=0x%04x, wIndex=0x%04x", |
3516 | req->bmRequestType, req->bRequest, UGETW(req->wValue), | | 3516 | req->bmRequestType, req->bRequest, UGETW(req->wValue), |
3517 | UGETW(req->wIndex)); | | 3517 | UGETW(req->wIndex)); |
3518 | USBHIST_LOG(ehcidebug, "len=%d, addr=%d, endpt=%d", | | 3518 | USBHIST_LOG(ehcidebug, "len=%d, addr=%d, endpt=%d", |
3519 | len, dev->ud_addr, | | 3519 | len, dev->ud_addr, |
3520 | epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress, 0); | | 3520 | epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress, 0); |
3521 | | | 3521 | |
3522 | setup = ehci_alloc_sqtd(sc); | | 3522 | setup = ehci_alloc_sqtd(sc); |
3523 | if (setup == NULL) { | | 3523 | if (setup == NULL) { |
3524 | err = USBD_NOMEM; | | 3524 | err = USBD_NOMEM; |
3525 | goto bad1; | | 3525 | goto bad1; |
3526 | } | | 3526 | } |
3527 | stat = ehci_alloc_sqtd(sc); | | 3527 | stat = ehci_alloc_sqtd(sc); |
3528 | if (stat == NULL) { | | 3528 | if (stat == NULL) { |
3529 | err = USBD_NOMEM; | | 3529 | err = USBD_NOMEM; |
3530 | goto bad2; | | 3530 | goto bad2; |
3531 | } | | 3531 | } |
3532 | | | 3532 | |
3533 | mutex_enter(&sc->sc_lock); | | 3533 | mutex_enter(&sc->sc_lock); |
3534 | | | 3534 | |
3535 | sqh = epipe->sqh; | | 3535 | sqh = epipe->sqh; |
3536 | | | 3536 | |
3537 | KASSERTMSG(EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)) == dev->ud_addr, | | 3537 | KASSERTMSG(EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)) == dev->ud_addr, |
3538 | "address QH %d pipe %d\n", | | 3538 | "address QH %" __PRIuBIT " pipe %d\n", |
3539 | EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)), dev->ud_addr); | | 3539 | EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)), dev->ud_addr); |
3540 | KASSERTMSG(EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)) == | | 3540 | KASSERTMSG(EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)) == |
3541 | UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize), | | 3541 | UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize), |
3542 | "MPS QH %d pipe %d\n", | | 3542 | "MPS QH %" __PRIuBIT " pipe %d\n", |
3543 | EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)), | | 3543 | EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)), |
3544 | UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize)); | | 3544 | UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize)); |
3545 | | | 3545 | |
3546 | /* Set up data transaction */ | | 3546 | /* Set up data transaction */ |
3547 | if (len != 0) { | | 3547 | if (len != 0) { |
3548 | ehci_soft_qtd_t *end; | | 3548 | ehci_soft_qtd_t *end; |
3549 | | | 3549 | |
3550 | /* Start toggle at 1. */ | | 3550 | /* Start toggle at 1. */ |
3551 | epipe->nexttoggle = 1; | | 3551 | epipe->nexttoggle = 1; |
3552 | err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, | | 3552 | err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, |
3553 | &next, &end); | | 3553 | &next, &end); |
3554 | if (err) | | 3554 | if (err) |
3555 | goto bad3; | | 3555 | goto bad3; |
3556 | end->qtd.qtd_status &= htole32(~EHCI_QTD_IOC); | | 3556 | end->qtd.qtd_status &= htole32(~EHCI_QTD_IOC); |
3557 | end->nextqtd = stat; | | 3557 | end->nextqtd = stat; |
3558 | end->qtd.qtd_next = end->qtd.qtd_altnext = | | 3558 | end->qtd.qtd_next = end->qtd.qtd_altnext = |
3559 | htole32(stat->physaddr); | | 3559 | htole32(stat->physaddr); |
3560 | usb_syncmem(&end->dma, end->offs, sizeof(end->qtd), | | 3560 | usb_syncmem(&end->dma, end->offs, sizeof(end->qtd), |
3561 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3561 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3562 | } else { | | 3562 | } else { |
3563 | next = stat; | | 3563 | next = stat; |
3564 | } | | 3564 | } |
3565 | | | 3565 | |
3566 | memcpy(KERNADDR(&epipe->u.ctl.reqdma, 0), req, sizeof(*req)); | | 3566 | memcpy(KERNADDR(&epipe->u.ctl.reqdma, 0), req, sizeof(*req)); |
3567 | usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req), BUS_DMASYNC_PREWRITE); | | 3567 | usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req), BUS_DMASYNC_PREWRITE); |
3568 | | | 3568 | |
3569 | /* Clear toggle */ | | 3569 | /* Clear toggle */ |
3570 | setup->qtd.qtd_status = htole32( | | 3570 | setup->qtd.qtd_status = htole32( |
3571 | EHCI_QTD_ACTIVE | | | 3571 | EHCI_QTD_ACTIVE | |
3572 | EHCI_QTD_SET_PID(EHCI_QTD_PID_SETUP) | | | 3572 | EHCI_QTD_SET_PID(EHCI_QTD_PID_SETUP) | |
3573 | EHCI_QTD_SET_CERR(3) | | | 3573 | EHCI_QTD_SET_CERR(3) | |
3574 | EHCI_QTD_SET_TOGGLE(0) | | | 3574 | EHCI_QTD_SET_TOGGLE(0) | |
3575 | EHCI_QTD_SET_BYTES(sizeof(*req)) | | 3575 | EHCI_QTD_SET_BYTES(sizeof(*req)) |
3576 | ); | | 3576 | ); |
3577 | setup->qtd.qtd_buffer[0] = htole32(DMAADDR(&epipe->u.ctl.reqdma, 0)); | | 3577 | setup->qtd.qtd_buffer[0] = htole32(DMAADDR(&epipe->u.ctl.reqdma, 0)); |
3578 | setup->qtd.qtd_buffer_hi[0] = 0; | | 3578 | setup->qtd.qtd_buffer_hi[0] = 0; |
3579 | setup->nextqtd = next; | | 3579 | setup->nextqtd = next; |
3580 | setup->qtd.qtd_next = setup->qtd.qtd_altnext = htole32(next->physaddr); | | 3580 | setup->qtd.qtd_next = setup->qtd.qtd_altnext = htole32(next->physaddr); |
3581 | setup->xfer = xfer; | | 3581 | setup->xfer = xfer; |
3582 | setup->len = sizeof(*req); | | 3582 | setup->len = sizeof(*req); |
3583 | usb_syncmem(&setup->dma, setup->offs, sizeof(setup->qtd), | | 3583 | usb_syncmem(&setup->dma, setup->offs, sizeof(setup->qtd), |
3584 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3584 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3585 | | | 3585 | |
3586 | stat->qtd.qtd_status = htole32( | | 3586 | stat->qtd.qtd_status = htole32( |
3587 | EHCI_QTD_ACTIVE | | | 3587 | EHCI_QTD_ACTIVE | |
3588 | EHCI_QTD_SET_PID(isread ? EHCI_QTD_PID_OUT : EHCI_QTD_PID_IN) | | | 3588 | EHCI_QTD_SET_PID(isread ? EHCI_QTD_PID_OUT : EHCI_QTD_PID_IN) | |
3589 | EHCI_QTD_SET_CERR(3) | | | 3589 | EHCI_QTD_SET_CERR(3) | |
3590 | EHCI_QTD_SET_TOGGLE(1) | | | 3590 | EHCI_QTD_SET_TOGGLE(1) | |
3591 | EHCI_QTD_IOC | | 3591 | EHCI_QTD_IOC |
3592 | ); | | 3592 | ); |
3593 | stat->qtd.qtd_buffer[0] = 0; /* XXX not needed? */ | | 3593 | stat->qtd.qtd_buffer[0] = 0; /* XXX not needed? */ |
3594 | stat->qtd.qtd_buffer_hi[0] = 0; /* XXX not needed? */ | | 3594 | stat->qtd.qtd_buffer_hi[0] = 0; /* XXX not needed? */ |
3595 | stat->nextqtd = NULL; | | 3595 | stat->nextqtd = NULL; |
3596 | stat->qtd.qtd_next = stat->qtd.qtd_altnext = EHCI_NULL; | | 3596 | stat->qtd.qtd_next = stat->qtd.qtd_altnext = EHCI_NULL; |
3597 | stat->xfer = xfer; | | 3597 | stat->xfer = xfer; |
3598 | stat->len = 0; | | 3598 | stat->len = 0; |
3599 | usb_syncmem(&stat->dma, stat->offs, sizeof(stat->qtd), | | 3599 | usb_syncmem(&stat->dma, stat->offs, sizeof(stat->qtd), |
3600 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3600 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3601 | | | 3601 | |
3602 | #ifdef EHCI_DEBUG | | 3602 | #ifdef EHCI_DEBUG |
3603 | USBHIST_LOGN(ehcidebug, 5, "dump:", 0, 0, 0, 0); | | 3603 | USBHIST_LOGN(ehcidebug, 5, "dump:", 0, 0, 0, 0); |
3604 | ehci_dump_sqh(sqh); | | 3604 | ehci_dump_sqh(sqh); |
3605 | ehci_dump_sqtds(setup); | | 3605 | ehci_dump_sqtds(setup); |
3606 | #endif | | 3606 | #endif |
3607 | | | 3607 | |
3608 | exfer->ex_sqtdstart = setup; | | 3608 | exfer->ex_sqtdstart = setup; |
3609 | exfer->ex_sqtdend = stat; | | 3609 | exfer->ex_sqtdend = stat; |
3610 | KASSERT(exfer->ex_isdone); | | 3610 | KASSERT(exfer->ex_isdone); |
3611 | #ifdef DIAGNOSTIC | | 3611 | #ifdef DIAGNOSTIC |
3612 | exfer->ex_isdone = false; | | 3612 | exfer->ex_isdone = false; |
3613 | #endif | | 3613 | #endif |
3614 | | | 3614 | |
3615 | /* Insert qTD in QH list. */ | | 3615 | /* Insert qTD in QH list. */ |
3616 | ehci_set_qh_qtd(sqh, setup); /* also does usb_syncmem(sqh) */ | | 3616 | ehci_set_qh_qtd(sqh, setup); /* also does usb_syncmem(sqh) */ |
3617 | if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { | | 3617 | if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { |
3618 | callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), | | 3618 | callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), |
3619 | ehci_timeout, xfer); | | 3619 | ehci_timeout, xfer); |
3620 | } | | 3620 | } |
3621 | ehci_add_intr_list(sc, exfer); | | 3621 | ehci_add_intr_list(sc, exfer); |
3622 | xfer->ux_status = USBD_IN_PROGRESS; | | 3622 | xfer->ux_status = USBD_IN_PROGRESS; |
3623 | mutex_exit(&sc->sc_lock); | | 3623 | mutex_exit(&sc->sc_lock); |
3624 | | | 3624 | |
3625 | #ifdef EHCI_DEBUG | | 3625 | #ifdef EHCI_DEBUG |
3626 | USBHIST_LOGN(ehcidebug, 10, "status=%x, dump:", | | 3626 | USBHIST_LOGN(ehcidebug, 10, "status=%x, dump:", |
3627 | EOREAD4(sc, EHCI_USBSTS), 0, 0, 0); | | 3627 | EOREAD4(sc, EHCI_USBSTS), 0, 0, 0); |
3628 | // delay(10000); | | 3628 | // delay(10000); |
3629 | ehci_dump_regs(sc); | | 3629 | ehci_dump_regs(sc); |
3630 | ehci_dump_sqh(sc->sc_async_head); | | 3630 | ehci_dump_sqh(sc->sc_async_head); |
3631 | ehci_dump_sqh(sqh); | | 3631 | ehci_dump_sqh(sqh); |
3632 | ehci_dump_sqtds(setup); | | 3632 | ehci_dump_sqtds(setup); |
3633 | #endif | | 3633 | #endif |
3634 | | | 3634 | |
3635 | return USBD_NORMAL_COMPLETION; | | 3635 | return USBD_NORMAL_COMPLETION; |
3636 | | | 3636 | |
3637 | bad3: | | 3637 | bad3: |
3638 | mutex_exit(&sc->sc_lock); | | 3638 | mutex_exit(&sc->sc_lock); |
3639 | ehci_free_sqtd(sc, stat); | | 3639 | ehci_free_sqtd(sc, stat); |
3640 | bad2: | | 3640 | bad2: |
3641 | ehci_free_sqtd(sc, setup); | | 3641 | ehci_free_sqtd(sc, setup); |
3642 | bad1: | | 3642 | bad1: |
3643 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); | | 3643 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); |
3644 | mutex_enter(&sc->sc_lock); | | 3644 | mutex_enter(&sc->sc_lock); |
3645 | xfer->ux_status = err; | | 3645 | xfer->ux_status = err; |
3646 | usb_transfer_complete(xfer); | | 3646 | usb_transfer_complete(xfer); |
3647 | mutex_exit(&sc->sc_lock); | | 3647 | mutex_exit(&sc->sc_lock); |
3648 | return err; | | 3648 | return err; |
3649 | #undef exfer | | 3649 | #undef exfer |
3650 | } | | 3650 | } |
3651 | | | 3651 | |
3652 | /* | | 3652 | /* |
3653 | * Some EHCI chips from VIA seem to trigger interrupts before writing back the | | 3653 | * Some EHCI chips from VIA seem to trigger interrupts before writing back the |
3654 | * qTD status, or miss signalling occasionally under heavy load. If the host | | 3654 | * qTD status, or miss signalling occasionally under heavy load. If the host |
3655 | * machine is too fast, we we can miss transaction completion - when we scan | | 3655 | * machine is too fast, we we can miss transaction completion - when we scan |
3656 | * the active list the transaction still seems to be active. This generally | | 3656 | * the active list the transaction still seems to be active. This generally |
3657 | * exhibits itself as a umass stall that never recovers. | | 3657 | * exhibits itself as a umass stall that never recovers. |
3658 | * | | 3658 | * |
3659 | * We work around this behaviour by setting up this callback after any softintr | | 3659 | * We work around this behaviour by setting up this callback after any softintr |
3660 | * that completes with transactions still pending, giving us another chance to | | 3660 | * that completes with transactions still pending, giving us another chance to |
3661 | * check for completion after the writeback has taken place. | | 3661 | * check for completion after the writeback has taken place. |
3662 | */ | | 3662 | */ |
3663 | Static void | | 3663 | Static void |
3664 | ehci_intrlist_timeout(void *arg) | | 3664 | ehci_intrlist_timeout(void *arg) |
3665 | { | | 3665 | { |
3666 | ehci_softc_t *sc = arg; | | 3666 | ehci_softc_t *sc = arg; |
3667 | | | 3667 | |
3668 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3668 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3669 | | | 3669 | |
3670 | usb_schedsoftintr(&sc->sc_bus); | | 3670 | usb_schedsoftintr(&sc->sc_bus); |
3671 | } | | 3671 | } |
3672 | | | 3672 | |
3673 | /************************/ | | 3673 | /************************/ |
3674 | | | 3674 | |
3675 | Static usbd_status | | 3675 | Static usbd_status |
3676 | ehci_device_bulk_transfer(usbd_xfer_handle xfer) | | 3676 | ehci_device_bulk_transfer(usbd_xfer_handle xfer) |
3677 | { | | 3677 | { |
3678 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 3678 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
3679 | usbd_status err; | | 3679 | usbd_status err; |
3680 | | | 3680 | |
3681 | /* Insert last in queue. */ | | 3681 | /* Insert last in queue. */ |
3682 | mutex_enter(&sc->sc_lock); | | 3682 | mutex_enter(&sc->sc_lock); |
3683 | err = usb_insert_transfer(xfer); | | 3683 | err = usb_insert_transfer(xfer); |
3684 | mutex_exit(&sc->sc_lock); | | 3684 | mutex_exit(&sc->sc_lock); |
3685 | if (err) | | 3685 | if (err) |
3686 | return err; | | 3686 | return err; |
3687 | | | 3687 | |
3688 | /* Pipe isn't running, start first */ | | 3688 | /* Pipe isn't running, start first */ |
3689 | return ehci_device_bulk_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); | | 3689 | return ehci_device_bulk_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); |
3690 | } | | 3690 | } |
3691 | | | 3691 | |
3692 | Static usbd_status | | 3692 | Static usbd_status |
3693 | ehci_device_bulk_start(usbd_xfer_handle xfer) | | 3693 | ehci_device_bulk_start(usbd_xfer_handle xfer) |
3694 | { | | 3694 | { |
3695 | #define exfer EXFER(xfer) | | 3695 | #define exfer EXFER(xfer) |
3696 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; | | 3696 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; |
3697 | usbd_device_handle dev = epipe->pipe.up_dev; | | 3697 | usbd_device_handle dev = epipe->pipe.up_dev; |
3698 | ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; | | 3698 | ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; |
3699 | ehci_soft_qtd_t *data, *dataend; | | 3699 | ehci_soft_qtd_t *data, *dataend; |
3700 | ehci_soft_qh_t *sqh; | | 3700 | ehci_soft_qh_t *sqh; |
3701 | usbd_status err; | | 3701 | usbd_status err; |
3702 | int len, isread, endpt; | | 3702 | int len, isread, endpt; |
3703 | | | 3703 | |
3704 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3704 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3705 | | | 3705 | |
3706 | USBHIST_LOG(ehcidebug, "xfer=%p len=%d flags=%d", | | 3706 | USBHIST_LOG(ehcidebug, "xfer=%p len=%d flags=%d", |
3707 | xfer, xfer->ux_length, xfer->ux_flags, 0); | | 3707 | xfer, xfer->ux_length, xfer->ux_flags, 0); |
3708 | | | 3708 | |
3709 | if (sc->sc_dying) | | 3709 | if (sc->sc_dying) |
3710 | return USBD_IOERROR; | | 3710 | return USBD_IOERROR; |
3711 | | | 3711 | |
3712 | KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); | | 3712 | KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); |
3713 | | | 3713 | |
3714 | mutex_enter(&sc->sc_lock); | | 3714 | mutex_enter(&sc->sc_lock); |
3715 | | | 3715 | |
3716 | len = xfer->ux_length; | | 3716 | len = xfer->ux_length; |
3717 | endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; | | 3717 | endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; |
3718 | isread = UE_GET_DIR(endpt) == UE_DIR_IN; | | 3718 | isread = UE_GET_DIR(endpt) == UE_DIR_IN; |
3719 | sqh = epipe->sqh; | | 3719 | sqh = epipe->sqh; |
3720 | | | 3720 | |
3721 | epipe->u.bulk.length = len; | | 3721 | epipe->u.bulk.length = len; |
3722 | | | 3722 | |
3723 | err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data, | | 3723 | err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data, |
3724 | &dataend); | | 3724 | &dataend); |
3725 | if (err) { | | 3725 | if (err) { |
3726 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); | | 3726 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); |
3727 | xfer->ux_status = err; | | 3727 | xfer->ux_status = err; |
3728 | usb_transfer_complete(xfer); | | 3728 | usb_transfer_complete(xfer); |
3729 | mutex_exit(&sc->sc_lock); | | 3729 | mutex_exit(&sc->sc_lock); |
3730 | return err; | | 3730 | return err; |
3731 | } | | 3731 | } |
3732 | | | 3732 | |
3733 | #ifdef EHCI_DEBUG | | 3733 | #ifdef EHCI_DEBUG |
3734 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); | | 3734 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); |
3735 | ehci_dump_sqh(sqh); | | 3735 | ehci_dump_sqh(sqh); |
3736 | ehci_dump_sqtds(data); | | 3736 | ehci_dump_sqtds(data); |
3737 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); | | 3737 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); |
3738 | #endif | | 3738 | #endif |
3739 | | | 3739 | |
3740 | /* Set up interrupt info. */ | | 3740 | /* Set up interrupt info. */ |
3741 | exfer->ex_sqtdstart = data; | | 3741 | exfer->ex_sqtdstart = data; |
3742 | exfer->ex_sqtdend = dataend; | | 3742 | exfer->ex_sqtdend = dataend; |
3743 | KASSERT(exfer->ex_isdone); | | 3743 | KASSERT(exfer->ex_isdone); |
3744 | #ifdef DIAGNOSTIC | | 3744 | #ifdef DIAGNOSTIC |
3745 | exfer->ex_isdone = false; | | 3745 | exfer->ex_isdone = false; |
3746 | #endif | | 3746 | #endif |
3747 | | | 3747 | |
3748 | ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */ | | 3748 | ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */ |
3749 | if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { | | 3749 | if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { |
3750 | callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), | | 3750 | callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), |
3751 | ehci_timeout, xfer); | | 3751 | ehci_timeout, xfer); |
3752 | } | | 3752 | } |
3753 | ehci_add_intr_list(sc, exfer); | | 3753 | ehci_add_intr_list(sc, exfer); |
3754 | xfer->ux_status = USBD_IN_PROGRESS; | | 3754 | xfer->ux_status = USBD_IN_PROGRESS; |
3755 | mutex_exit(&sc->sc_lock); | | 3755 | mutex_exit(&sc->sc_lock); |
3756 | | | 3756 | |
3757 | #ifdef EHCI_DEBUG | | 3757 | #ifdef EHCI_DEBUG |
3758 | USBHIST_LOGN(ehcidebug, 5, "data(2)", 0, 0, 0, 0); | | 3758 | USBHIST_LOGN(ehcidebug, 5, "data(2)", 0, 0, 0, 0); |
3759 | // delay(10000); | | 3759 | // delay(10000); |
3760 | USBHIST_LOGN(ehcidebug, 5, "data(3)", 0, 0, 0, 0); | | 3760 | USBHIST_LOGN(ehcidebug, 5, "data(3)", 0, 0, 0, 0); |
3761 | ehci_dump_regs(sc); | | 3761 | ehci_dump_regs(sc); |
3762 | #if 0 | | 3762 | #if 0 |
3763 | printf("async_head:\n"); | | 3763 | printf("async_head:\n"); |
3764 | ehci_dump_sqh(sc->sc_async_head); | | 3764 | ehci_dump_sqh(sc->sc_async_head); |
3765 | #endif | | 3765 | #endif |
3766 | USBHIST_LOG(ehcidebug, "sqh:", 0, 0, 0, 0); | | 3766 | USBHIST_LOG(ehcidebug, "sqh:", 0, 0, 0, 0); |
3767 | ehci_dump_sqh(sqh); | | 3767 | ehci_dump_sqh(sqh); |
3768 | ehci_dump_sqtds(data); | | 3768 | ehci_dump_sqtds(data); |
3769 | #endif | | 3769 | #endif |
3770 | | | 3770 | |
3771 | if (sc->sc_bus.ub_usepolling) | | 3771 | if (sc->sc_bus.ub_usepolling) |
3772 | ehci_waitintr(sc, xfer); | | 3772 | ehci_waitintr(sc, xfer); |
3773 | | | 3773 | |
3774 | return USBD_IN_PROGRESS; | | 3774 | return USBD_IN_PROGRESS; |
3775 | #undef exfer | | 3775 | #undef exfer |
3776 | } | | 3776 | } |
3777 | | | 3777 | |
3778 | Static void | | 3778 | Static void |
3779 | ehci_device_bulk_abort(usbd_xfer_handle xfer) | | 3779 | ehci_device_bulk_abort(usbd_xfer_handle xfer) |
3780 | { | | 3780 | { |
3781 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3781 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3782 | | | 3782 | |
3783 | USBHIST_LOG(ehcidebug, "xfer %p", xfer, 0, 0, 0); | | 3783 | USBHIST_LOG(ehcidebug, "xfer %p", xfer, 0, 0, 0); |
3784 | ehci_abort_xfer(xfer, USBD_CANCELLED); | | 3784 | ehci_abort_xfer(xfer, USBD_CANCELLED); |
3785 | } | | 3785 | } |
3786 | | | 3786 | |
3787 | /* | | 3787 | /* |
3788 | * Close a device bulk pipe. | | 3788 | * Close a device bulk pipe. |
3789 | */ | | 3789 | */ |
3790 | Static void | | 3790 | Static void |
3791 | ehci_device_bulk_close(usbd_pipe_handle pipe) | | 3791 | ehci_device_bulk_close(usbd_pipe_handle pipe) |
3792 | { | | 3792 | { |
3793 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; | | 3793 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; |
3794 | struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; | | 3794 | struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; |
3795 | | | 3795 | |
3796 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3796 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3797 | | | 3797 | |
3798 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3798 | KASSERT(mutex_owned(&sc->sc_lock)); |
3799 | | | 3799 | |
3800 | USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0); | | 3800 | USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0); |
3801 | pipe->up_endpoint->ue_toggle = epipe->nexttoggle; | | 3801 | pipe->up_endpoint->ue_toggle = epipe->nexttoggle; |
3802 | ehci_close_pipe(pipe, sc->sc_async_head); | | 3802 | ehci_close_pipe(pipe, sc->sc_async_head); |
3803 | } | | 3803 | } |
3804 | | | 3804 | |
3805 | Static void | | 3805 | Static void |
3806 | ehci_device_bulk_done(usbd_xfer_handle xfer) | | 3806 | ehci_device_bulk_done(usbd_xfer_handle xfer) |
3807 | { | | 3807 | { |
3808 | struct ehci_xfer *ex = EXFER(xfer); | | 3808 | struct ehci_xfer *ex = EXFER(xfer); |
3809 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 3809 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
3810 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; | | 3810 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; |
3811 | int endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; | | 3811 | int endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; |
3812 | int rd = UE_GET_DIR(endpt) == UE_DIR_IN; | | 3812 | int rd = UE_GET_DIR(endpt) == UE_DIR_IN; |
3813 | | | 3813 | |
3814 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3814 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3815 | | | 3815 | |
3816 | USBHIST_LOG(ehcidebug, "xfer=%p, actlen=%d", | | 3816 | USBHIST_LOG(ehcidebug, "xfer=%p, actlen=%d", |
3817 | xfer, xfer->ux_actlen, 0, 0); | | 3817 | xfer, xfer->ux_actlen, 0, 0); |
3818 | | | 3818 | |
3819 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3819 | KASSERT(mutex_owned(&sc->sc_lock)); |
3820 | | | 3820 | |
3821 | if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { | | 3821 | if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { |
3822 | ehci_del_intr_list(sc, ex); /* remove from active list */ | | 3822 | ehci_del_intr_list(sc, ex); /* remove from active list */ |
3823 | ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); | | 3823 | ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); |
3824 | usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, | | 3824 | usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, |
3825 | rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); | | 3825 | rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); |
3826 | } | | 3826 | } |
3827 | | | 3827 | |
3828 | USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0); | | 3828 | USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0); |
3829 | } | | 3829 | } |
3830 | | | 3830 | |
3831 | /************************/ | | 3831 | /************************/ |
3832 | | | 3832 | |
3833 | Static usbd_status | | 3833 | Static usbd_status |
3834 | ehci_device_setintr(ehci_softc_t *sc, ehci_soft_qh_t *sqh, int ival) | | 3834 | ehci_device_setintr(ehci_softc_t *sc, ehci_soft_qh_t *sqh, int ival) |
3835 | { | | 3835 | { |
3836 | struct ehci_soft_islot *isp; | | 3836 | struct ehci_soft_islot *isp; |
3837 | int islot, lev; | | 3837 | int islot, lev; |
3838 | | | 3838 | |
3839 | /* Find a poll rate that is large enough. */ | | 3839 | /* Find a poll rate that is large enough. */ |
3840 | for (lev = EHCI_IPOLLRATES - 1; lev > 0; lev--) | | 3840 | for (lev = EHCI_IPOLLRATES - 1; lev > 0; lev--) |
3841 | if (EHCI_ILEV_IVAL(lev) <= ival) | | 3841 | if (EHCI_ILEV_IVAL(lev) <= ival) |
3842 | break; | | 3842 | break; |
3843 | | | 3843 | |
3844 | /* Pick an interrupt slot at the right level. */ | | 3844 | /* Pick an interrupt slot at the right level. */ |
3845 | /* XXX could do better than picking at random */ | | 3845 | /* XXX could do better than picking at random */ |
3846 | sc->sc_rand = (sc->sc_rand + 191) % sc->sc_flsize; | | 3846 | sc->sc_rand = (sc->sc_rand + 191) % sc->sc_flsize; |
3847 | islot = EHCI_IQHIDX(lev, sc->sc_rand); | | 3847 | islot = EHCI_IQHIDX(lev, sc->sc_rand); |
3848 | | | 3848 | |
3849 | sqh->islot = islot; | | 3849 | sqh->islot = islot; |
3850 | isp = &sc->sc_islots[islot]; | | 3850 | isp = &sc->sc_islots[islot]; |
3851 | mutex_enter(&sc->sc_lock); | | 3851 | mutex_enter(&sc->sc_lock); |
3852 | ehci_add_qh(sc, sqh, isp->sqh); | | 3852 | ehci_add_qh(sc, sqh, isp->sqh); |
3853 | mutex_exit(&sc->sc_lock); | | 3853 | mutex_exit(&sc->sc_lock); |
3854 | | | 3854 | |
3855 | return USBD_NORMAL_COMPLETION; | | 3855 | return USBD_NORMAL_COMPLETION; |
3856 | } | | 3856 | } |
3857 | | | 3857 | |
3858 | Static usbd_status | | 3858 | Static usbd_status |
3859 | ehci_device_intr_transfer(usbd_xfer_handle xfer) | | 3859 | ehci_device_intr_transfer(usbd_xfer_handle xfer) |
3860 | { | | 3860 | { |
3861 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 3861 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
3862 | usbd_status err; | | 3862 | usbd_status err; |
3863 | | | 3863 | |
3864 | /* Insert last in queue. */ | | 3864 | /* Insert last in queue. */ |
3865 | mutex_enter(&sc->sc_lock); | | 3865 | mutex_enter(&sc->sc_lock); |
3866 | err = usb_insert_transfer(xfer); | | 3866 | err = usb_insert_transfer(xfer); |
3867 | mutex_exit(&sc->sc_lock); | | 3867 | mutex_exit(&sc->sc_lock); |
3868 | if (err) | | 3868 | if (err) |
3869 | return err; | | 3869 | return err; |
3870 | | | 3870 | |
3871 | /* | | 3871 | /* |
3872 | * Pipe isn't running (otherwise err would be USBD_INPROG), | | 3872 | * Pipe isn't running (otherwise err would be USBD_INPROG), |
3873 | * so start it first. | | 3873 | * so start it first. |
3874 | */ | | 3874 | */ |
3875 | return ehci_device_intr_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); | | 3875 | return ehci_device_intr_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); |
3876 | } | | 3876 | } |
3877 | | | 3877 | |
3878 | Static usbd_status | | 3878 | Static usbd_status |
3879 | ehci_device_intr_start(usbd_xfer_handle xfer) | | 3879 | ehci_device_intr_start(usbd_xfer_handle xfer) |
3880 | { | | 3880 | { |
3881 | #define exfer EXFER(xfer) | | 3881 | #define exfer EXFER(xfer) |
3882 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; | | 3882 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; |
3883 | usbd_device_handle dev = xfer->ux_pipe->up_dev; | | 3883 | usbd_device_handle dev = xfer->ux_pipe->up_dev; |
3884 | ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; | | 3884 | ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; |
3885 | ehci_soft_qtd_t *data, *dataend; | | 3885 | ehci_soft_qtd_t *data, *dataend; |
3886 | ehci_soft_qh_t *sqh; | | 3886 | ehci_soft_qh_t *sqh; |
3887 | usbd_status err; | | 3887 | usbd_status err; |
3888 | int len, isread, endpt; | | 3888 | int len, isread, endpt; |
3889 | | | 3889 | |
3890 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3890 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3891 | | | 3891 | |
3892 | USBHIST_LOG(ehcidebug, "xfer=%p len=%d flags=%d", | | 3892 | USBHIST_LOG(ehcidebug, "xfer=%p len=%d flags=%d", |
3893 | xfer, xfer->ux_length, xfer->ux_flags, 0); | | 3893 | xfer, xfer->ux_length, xfer->ux_flags, 0); |
3894 | | | 3894 | |
3895 | if (sc->sc_dying) | | 3895 | if (sc->sc_dying) |
3896 | return USBD_IOERROR; | | 3896 | return USBD_IOERROR; |
3897 | | | 3897 | |
3898 | KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); | | 3898 | KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); |
3899 | | | 3899 | |
3900 | mutex_enter(&sc->sc_lock); | | 3900 | mutex_enter(&sc->sc_lock); |
3901 | | | 3901 | |
3902 | len = xfer->ux_length; | | 3902 | len = xfer->ux_length; |
3903 | endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; | | 3903 | endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; |
3904 | isread = UE_GET_DIR(endpt) == UE_DIR_IN; | | 3904 | isread = UE_GET_DIR(endpt) == UE_DIR_IN; |
3905 | sqh = epipe->sqh; | | 3905 | sqh = epipe->sqh; |
3906 | | | 3906 | |
3907 | epipe->u.intr.length = len; | | 3907 | epipe->u.intr.length = len; |
3908 | | | 3908 | |
3909 | err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data, | | 3909 | err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data, |
3910 | &dataend); | | 3910 | &dataend); |
3911 | if (err) { | | 3911 | if (err) { |
3912 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); | | 3912 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); |
3913 | xfer->ux_status = err; | | 3913 | xfer->ux_status = err; |
3914 | usb_transfer_complete(xfer); | | 3914 | usb_transfer_complete(xfer); |
3915 | mutex_exit(&sc->sc_lock); | | 3915 | mutex_exit(&sc->sc_lock); |
3916 | return err; | | 3916 | return err; |
3917 | } | | 3917 | } |
3918 | | | 3918 | |
3919 | #ifdef EHCI_DEBUG | | 3919 | #ifdef EHCI_DEBUG |
3920 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); | | 3920 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); |
3921 | ehci_dump_sqh(sqh); | | 3921 | ehci_dump_sqh(sqh); |
3922 | ehci_dump_sqtds(data); | | 3922 | ehci_dump_sqtds(data); |
3923 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); | | 3923 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); |
3924 | #endif | | 3924 | #endif |
3925 | | | 3925 | |
3926 | /* Set up interrupt info. */ | | 3926 | /* Set up interrupt info. */ |
3927 | exfer->ex_sqtdstart = data; | | 3927 | exfer->ex_sqtdstart = data; |
3928 | exfer->ex_sqtdend = dataend; | | 3928 | exfer->ex_sqtdend = dataend; |
3929 | KASSERT(exfer->ex_isdone); | | 3929 | KASSERT(exfer->ex_isdone); |
3930 | #ifdef DIAGNOSTIC | | 3930 | #ifdef DIAGNOSTIC |
3931 | exfer->ex_isdone = false; | | 3931 | exfer->ex_isdone = false; |
3932 | #endif | | 3932 | #endif |
3933 | | | 3933 | |
3934 | ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */ | | 3934 | ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */ |
3935 | if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { | | 3935 | if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { |
3936 | callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), | | 3936 | callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), |
3937 | ehci_timeout, xfer); | | 3937 | ehci_timeout, xfer); |
3938 | } | | 3938 | } |
3939 | ehci_add_intr_list(sc, exfer); | | 3939 | ehci_add_intr_list(sc, exfer); |
3940 | xfer->ux_status = USBD_IN_PROGRESS; | | 3940 | xfer->ux_status = USBD_IN_PROGRESS; |
3941 | mutex_exit(&sc->sc_lock); | | 3941 | mutex_exit(&sc->sc_lock); |
3942 | | | 3942 | |
3943 | #ifdef EHCI_DEBUG | | 3943 | #ifdef EHCI_DEBUG |
3944 | USBHIST_LOGN(ehcidebug, 5, "data(2)", 0, 0, 0, 0); | | 3944 | USBHIST_LOGN(ehcidebug, 5, "data(2)", 0, 0, 0, 0); |
3945 | // delay(10000); | | 3945 | // delay(10000); |
3946 | USBHIST_LOGN(ehcidebug, 5, "data(3)", 0, 0, 0, 0); | | 3946 | USBHIST_LOGN(ehcidebug, 5, "data(3)", 0, 0, 0, 0); |
3947 | ehci_dump_regs(sc); | | 3947 | ehci_dump_regs(sc); |
3948 | USBHIST_LOGN(ehcidebug, 5, "sqh:", 0, 0, 0, 0); | | 3948 | USBHIST_LOGN(ehcidebug, 5, "sqh:", 0, 0, 0, 0); |
3949 | ehci_dump_sqh(sqh); | | 3949 | ehci_dump_sqh(sqh); |
3950 | ehci_dump_sqtds(data); | | 3950 | ehci_dump_sqtds(data); |
3951 | #endif | | 3951 | #endif |
3952 | | | 3952 | |
3953 | if (sc->sc_bus.ub_usepolling) | | 3953 | if (sc->sc_bus.ub_usepolling) |
3954 | ehci_waitintr(sc, xfer); | | 3954 | ehci_waitintr(sc, xfer); |
3955 | | | 3955 | |
3956 | return USBD_IN_PROGRESS; | | 3956 | return USBD_IN_PROGRESS; |
3957 | #undef exfer | | 3957 | #undef exfer |
3958 | } | | 3958 | } |
3959 | | | 3959 | |
3960 | Static void | | 3960 | Static void |
3961 | ehci_device_intr_abort(usbd_xfer_handle xfer) | | 3961 | ehci_device_intr_abort(usbd_xfer_handle xfer) |
3962 | { | | 3962 | { |
3963 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3963 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3964 | | | 3964 | |
3965 | USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); | | 3965 | USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); |
3966 | KASSERT(xfer->ux_pipe->up_intrxfer == xfer); | | 3966 | KASSERT(xfer->ux_pipe->up_intrxfer == xfer); |
3967 | | | 3967 | |
3968 | /* | | 3968 | /* |
3969 | * XXX - abort_xfer uses ehci_sync_hc, which syncs via the advance | | 3969 | * XXX - abort_xfer uses ehci_sync_hc, which syncs via the advance |
3970 | * async doorbell. That's dependent on the async list, wheras | | 3970 | * async doorbell. That's dependent on the async list, wheras |
3971 | * intr xfers are periodic, should not use this? | | 3971 | * intr xfers are periodic, should not use this? |
3972 | */ | | 3972 | */ |
3973 | ehci_abort_xfer(xfer, USBD_CANCELLED); | | 3973 | ehci_abort_xfer(xfer, USBD_CANCELLED); |
3974 | } | | 3974 | } |
3975 | | | 3975 | |
3976 | Static void | | 3976 | Static void |
3977 | ehci_device_intr_close(usbd_pipe_handle pipe) | | 3977 | ehci_device_intr_close(usbd_pipe_handle pipe) |
3978 | { | | 3978 | { |
3979 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; | | 3979 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; |
3980 | struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; | | 3980 | struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; |
3981 | struct ehci_soft_islot *isp; | | 3981 | struct ehci_soft_islot *isp; |
3982 | | | 3982 | |
3983 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3983 | KASSERT(mutex_owned(&sc->sc_lock)); |
3984 | | | 3984 | |
3985 | isp = &sc->sc_islots[epipe->sqh->islot]; | | 3985 | isp = &sc->sc_islots[epipe->sqh->islot]; |
3986 | ehci_close_pipe(pipe, isp->sqh); | | 3986 | ehci_close_pipe(pipe, isp->sqh); |
3987 | } | | 3987 | } |
3988 | | | 3988 | |
3989 | Static void | | 3989 | Static void |
3990 | ehci_device_intr_done(usbd_xfer_handle xfer) | | 3990 | ehci_device_intr_done(usbd_xfer_handle xfer) |
3991 | { | | 3991 | { |
3992 | #define exfer EXFER(xfer) | | 3992 | #define exfer EXFER(xfer) |
3993 | struct ehci_xfer *ex = EXFER(xfer); | | 3993 | struct ehci_xfer *ex = EXFER(xfer); |
3994 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 3994 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
3995 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; | | 3995 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; |
3996 | ehci_soft_qtd_t *data, *dataend; | | 3996 | ehci_soft_qtd_t *data, *dataend; |
3997 | ehci_soft_qh_t *sqh; | | 3997 | ehci_soft_qh_t *sqh; |
3998 | usbd_status err; | | 3998 | usbd_status err; |
3999 | int len, isread, endpt; | | 3999 | int len, isread, endpt; |
4000 | | | 4000 | |
4001 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 4001 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
4002 | | | 4002 | |
4003 | USBHIST_LOG(ehcidebug, "xfer=%p, actlen=%d", | | 4003 | USBHIST_LOG(ehcidebug, "xfer=%p, actlen=%d", |
4004 | xfer, xfer->ux_actlen, 0, 0); | | 4004 | xfer, xfer->ux_actlen, 0, 0); |
4005 | | | 4005 | |
4006 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); | | 4006 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); |
4007 | | | 4007 | |
4008 | if (xfer->ux_pipe->up_repeat) { | | 4008 | if (xfer->ux_pipe->up_repeat) { |
4009 | ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); | | 4009 | ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); |
4010 | | | 4010 | |
4011 | len = epipe->u.intr.length; | | 4011 | len = epipe->u.intr.length; |
4012 | xfer->ux_length = len; | | 4012 | xfer->ux_length = len; |
4013 | endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; | | 4013 | endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; |
4014 | isread = UE_GET_DIR(endpt) == UE_DIR_IN; | | 4014 | isread = UE_GET_DIR(endpt) == UE_DIR_IN; |
4015 | usb_syncmem(&xfer->ux_dmabuf, 0, len, | | 4015 | usb_syncmem(&xfer->ux_dmabuf, 0, len, |
4016 | isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); | | 4016 | isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); |
4017 | sqh = epipe->sqh; | | 4017 | sqh = epipe->sqh; |
4018 | | | 4018 | |
4019 | err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, | | 4019 | err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, |
4020 | &data, &dataend); | | 4020 | &data, &dataend); |
4021 | if (err) { | | 4021 | if (err) { |
4022 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); | | 4022 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); |
4023 | xfer->ux_status = err; | | 4023 | xfer->ux_status = err; |
4024 | return; | | 4024 | return; |
4025 | } | | 4025 | } |
4026 | | | 4026 | |
4027 | /* Set up interrupt info. */ | | 4027 | /* Set up interrupt info. */ |
4028 | exfer->ex_sqtdstart = data; | | 4028 | exfer->ex_sqtdstart = data; |
4029 | exfer->ex_sqtdend = dataend; | | 4029 | exfer->ex_sqtdend = dataend; |
4030 | KASSERT(exfer->ex_isdone); | | 4030 | KASSERT(exfer->ex_isdone); |
4031 | #ifdef DIAGNOSTIC | | 4031 | #ifdef DIAGNOSTIC |
4032 | exfer->ex_isdone = false; | | 4032 | exfer->ex_isdone = false; |
4033 | #endif | | 4033 | #endif |
4034 | | | 4034 | |
4035 | ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */ | | 4035 | ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */ |
4036 | if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { | | 4036 | if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { |
4037 | callout_reset(&xfer->ux_callout, | | 4037 | callout_reset(&xfer->ux_callout, |
4038 | mstohz(xfer->ux_timeout), ehci_timeout, xfer); | | 4038 | mstohz(xfer->ux_timeout), ehci_timeout, xfer); |
4039 | } | | 4039 | } |
4040 | | | 4040 | |
4041 | xfer->ux_status = USBD_IN_PROGRESS; | | 4041 | xfer->ux_status = USBD_IN_PROGRESS; |
4042 | } else if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { | | 4042 | } else if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { |
4043 | ehci_del_intr_list(sc, ex); /* remove from active list */ | | 4043 | ehci_del_intr_list(sc, ex); /* remove from active list */ |
4044 | ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); | | 4044 | ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); |
4045 | endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; | | 4045 | endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; |
4046 | isread = UE_GET_DIR(endpt) == UE_DIR_IN; | | 4046 | isread = UE_GET_DIR(endpt) == UE_DIR_IN; |
4047 | usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, | | 4047 | usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, |
4048 | isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); | | 4048 | isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); |
4049 | } | | 4049 | } |
4050 | #undef exfer | | 4050 | #undef exfer |
4051 | } | | 4051 | } |
4052 | | | 4052 | |
4053 | /************************/ | | 4053 | /************************/ |
4054 | | | 4054 | |
4055 | Static usbd_status | | 4055 | Static usbd_status |
4056 | ehci_device_fs_isoc_transfer(usbd_xfer_handle xfer) | | 4056 | ehci_device_fs_isoc_transfer(usbd_xfer_handle xfer) |
4057 | { | | 4057 | { |
4058 | usbd_status err; | | 4058 | usbd_status err; |
4059 | | | 4059 | |
4060 | err = usb_insert_transfer(xfer); | | 4060 | err = usb_insert_transfer(xfer); |
4061 | if (err && err != USBD_IN_PROGRESS) | | 4061 | if (err && err != USBD_IN_PROGRESS) |
4062 | return err; | | 4062 | return err; |
4063 | | | 4063 | |
4064 | return ehci_device_fs_isoc_start(xfer); | | 4064 | return ehci_device_fs_isoc_start(xfer); |
4065 | } | | 4065 | } |
4066 | | | 4066 | |
4067 | Static usbd_status | | 4067 | Static usbd_status |
4068 | ehci_device_fs_isoc_start(usbd_xfer_handle xfer) | | 4068 | ehci_device_fs_isoc_start(usbd_xfer_handle xfer) |
4069 | { | | 4069 | { |
4070 | struct ehci_pipe *epipe; | | 4070 | struct ehci_pipe *epipe; |
4071 | usbd_device_handle dev; | | 4071 | usbd_device_handle dev; |
4072 | ehci_softc_t *sc; | | 4072 | ehci_softc_t *sc; |
4073 | struct ehci_xfer *exfer; | | 4073 | struct ehci_xfer *exfer; |
4074 | ehci_soft_sitd_t *sitd, *prev, *start, *stop; | | 4074 | ehci_soft_sitd_t *sitd, *prev, *start, *stop; |
4075 | usb_dma_t *dma_buf; | | 4075 | usb_dma_t *dma_buf; |
4076 | int i, j, k, frames; | | 4076 | int i, j, k, frames; |
4077 | int offs, total_length; | | 4077 | int offs, total_length; |
4078 | int frindex; | | 4078 | int frindex; |
4079 | u_int huba, dir; | | 4079 | u_int huba, dir; |
4080 | | | 4080 | |
4081 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 4081 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
4082 | | | 4082 | |
4083 | start = NULL; | | 4083 | start = NULL; |
4084 | prev = NULL; | | 4084 | prev = NULL; |
4085 | sitd = NULL; | | 4085 | sitd = NULL; |
4086 | total_length = 0; | | 4086 | total_length = 0; |
4087 | exfer = (struct ehci_xfer *) xfer; | | 4087 | exfer = (struct ehci_xfer *) xfer; |
4088 | sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 4088 | sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
4089 | dev = xfer->ux_pipe->up_dev; | | 4089 | dev = xfer->ux_pipe->up_dev; |
4090 | epipe = (struct ehci_pipe *)xfer->ux_pipe; | | 4090 | epipe = (struct ehci_pipe *)xfer->ux_pipe; |
4091 | | | 4091 | |
4092 | /* | | 4092 | /* |
4093 | * To allow continuous transfers, above we start all transfers | | 4093 | * To allow continuous transfers, above we start all transfers |
4094 | * immediately. However, we're still going to get usbd_start_next call | | 4094 | * immediately. However, we're still going to get usbd_start_next call |
4095 | * this when another xfer completes. So, check if this is already | | 4095 | * this when another xfer completes. So, check if this is already |
4096 | * in progress or not | | 4096 | * in progress or not |
4097 | */ | | 4097 | */ |
4098 | | | 4098 | |
4099 | if (exfer->ex_sitdstart != NULL) | | 4099 | if (exfer->ex_sitdstart != NULL) |
4100 | return USBD_IN_PROGRESS; | | 4100 | return USBD_IN_PROGRESS; |
4101 | | | 4101 | |
4102 | USBHIST_LOG(ehcidebug, "xfer %p len %d flags %d", | | 4102 | USBHIST_LOG(ehcidebug, "xfer %p len %d flags %d", |
4103 | xfer, xfer->ux_length, xfer->ux_flags, 0); | | 4103 | xfer, xfer->ux_length, xfer->ux_flags, 0); |
4104 | | | 4104 | |
4105 | if (sc->sc_dying) | | 4105 | if (sc->sc_dying) |
4106 | return USBD_IOERROR; | | 4106 | return USBD_IOERROR; |
4107 | | | 4107 | |
4108 | /* | | 4108 | /* |
4109 | * To avoid complication, don't allow a request right now that'll span | | 4109 | * To avoid complication, don't allow a request right now that'll span |
4110 | * the entire frame table. To within 4 frames, to allow some leeway | | 4110 | * the entire frame table. To within 4 frames, to allow some leeway |
4111 | * on either side of where the hc currently is. | | 4111 | * on either side of where the hc currently is. |
4112 | */ | | 4112 | */ |
4113 | if (epipe->pipe.up_endpoint->ue_edesc->bInterval * | | 4113 | if (epipe->pipe.up_endpoint->ue_edesc->bInterval * |
4114 | xfer->ux_nframes >= sc->sc_flsize - 4) { | | 4114 | xfer->ux_nframes >= sc->sc_flsize - 4) { |
4115 | printf("ehci: isoc descriptor requested that spans the entire" | | 4115 | printf("ehci: isoc descriptor requested that spans the entire" |
4116 | "frametable, too many frames\n"); | | 4116 | "frametable, too many frames\n"); |
4117 | return USBD_INVAL; | | 4117 | return USBD_INVAL; |
4118 | } | | 4118 | } |
4119 | | | 4119 | |
4120 | KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); | | 4120 | KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); |
4121 | KASSERT(exfer->ex_isdone); | | 4121 | KASSERT(exfer->ex_isdone); |
4122 | | | 4122 | |
4123 | #ifdef DIAGNOSTIC | | 4123 | #ifdef DIAGNOSTIC |
4124 | exfer->ex_isdone = false; | | 4124 | exfer->ex_isdone = false; |
4125 | #endif | | 4125 | #endif |
4126 | | | 4126 | |
4127 | /* | | 4127 | /* |
4128 | * Step 1: Allocate and initialize sitds. | | 4128 | * Step 1: Allocate and initialize sitds. |
4129 | */ | | 4129 | */ |
4130 | | | 4130 | |
4131 | i = epipe->pipe.up_endpoint->ue_edesc->bInterval; | | 4131 | i = epipe->pipe.up_endpoint->ue_edesc->bInterval; |
4132 | if (i > 16 || i == 0) { | | 4132 | if (i > 16 || i == 0) { |
4133 | /* Spec page 271 says intervals > 16 are invalid */ | | 4133 | /* Spec page 271 says intervals > 16 are invalid */ |
4134 | USBHIST_LOG(ehcidebug, "bInterval %d invalid", 0, 0, 0, 0); | | 4134 | USBHIST_LOG(ehcidebug, "bInterval %d invalid", 0, 0, 0, 0); |
4135 | | | 4135 | |
4136 | return USBD_INVAL; | | 4136 | return USBD_INVAL; |
4137 | } | | 4137 | } |
4138 | | | 4138 | |
4139 | frames = xfer->ux_nframes; | | 4139 | frames = xfer->ux_nframes; |
4140 | | | 4140 | |
4141 | if (frames == 0) { | | 4141 | if (frames == 0) { |
4142 | USBHIST_LOG(ehcidebug, "frames == 0", 0, 0, 0, 0); | | 4142 | USBHIST_LOG(ehcidebug, "frames == 0", 0, 0, 0, 0); |
4143 | | | 4143 | |
4144 | return USBD_INVAL; | | 4144 | return USBD_INVAL; |
4145 | } | | 4145 | } |
4146 | | | 4146 | |
4147 | dma_buf = &xfer->ux_dmabuf; | | 4147 | dma_buf = &xfer->ux_dmabuf; |
4148 | offs = 0; | | 4148 | offs = 0; |
4149 | | | 4149 | |
4150 | for (i = 0; i < frames; i++) { | | 4150 | for (i = 0; i < frames; i++) { |
4151 | sitd = ehci_alloc_sitd(sc); | | 4151 | sitd = ehci_alloc_sitd(sc); |
4152 | | | 4152 | |
4153 | if (prev) | | 4153 | if (prev) |
4154 | prev->xfer_next = sitd; | | 4154 | prev->xfer_next = sitd; |
4155 | else | | 4155 | else |
4156 | start = sitd; | | 4156 | start = sitd; |
4157 | | | 4157 | |
4158 | #ifdef DIAGNOSTIC | | 4158 | #ifdef DIAGNOSTIC |
4159 | if (xfer->ux_frlengths[i] > 0x3ff) { | | 4159 | if (xfer->ux_frlengths[i] > 0x3ff) { |
4160 | printf("ehci: invalid frame length\n"); | | 4160 | printf("ehci: invalid frame length\n"); |
4161 | xfer->ux_frlengths[i] = 0x3ff; | | 4161 | xfer->ux_frlengths[i] = 0x3ff; |
4162 | } | | 4162 | } |
4163 | #endif | | 4163 | #endif |
4164 | | | 4164 | |
4165 | sitd->sitd.sitd_trans = htole32(EHCI_SITD_ACTIVE | | | 4165 | sitd->sitd.sitd_trans = htole32(EHCI_SITD_ACTIVE | |
4166 | EHCI_SITD_SET_LEN(xfer->ux_frlengths[i])); | | 4166 | EHCI_SITD_SET_LEN(xfer->ux_frlengths[i])); |
4167 | | | 4167 | |
4168 | /* Set page0 index and offset. */ | | 4168 | /* Set page0 index and offset. */ |
4169 | sitd->sitd.sitd_buffer[0] = htole32(DMAADDR(dma_buf, offs)); | | 4169 | sitd->sitd.sitd_buffer[0] = htole32(DMAADDR(dma_buf, offs)); |
4170 | | | 4170 | |
4171 | total_length += xfer->ux_frlengths[i]; | | 4171 | total_length += xfer->ux_frlengths[i]; |
4172 | offs += xfer->ux_frlengths[i]; | | 4172 | offs += xfer->ux_frlengths[i]; |
4173 | | | 4173 | |
4174 | sitd->sitd.sitd_buffer[1] = | | 4174 | sitd->sitd.sitd_buffer[1] = |
4175 | htole32(EHCI_SITD_SET_BPTR(DMAADDR(dma_buf, offs - 1))); | | 4175 | htole32(EHCI_SITD_SET_BPTR(DMAADDR(dma_buf, offs - 1))); |
4176 | | | 4176 | |
4177 | huba = dev->ud_myhsport->up_parent->ud_addr; | | 4177 | huba = dev->ud_myhsport->up_parent->ud_addr; |
4178 | | | 4178 | |
4179 | /* if (sc->sc_flags & EHCIF_FREESCALE) { | | 4179 | /* if (sc->sc_flags & EHCIF_FREESCALE) { |
4180 | // Set hub address to 0 if embedded TT is used. | | 4180 | // Set hub address to 0 if embedded TT is used. |
4181 | if (huba == sc->sc_addr) | | 4181 | if (huba == sc->sc_addr) |
4182 | huba = 0; | | 4182 | huba = 0; |
4183 | } | | 4183 | } |
4184 | */ | | 4184 | */ |
4185 | | | 4185 | |
4186 | k = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; | | 4186 | k = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; |
4187 | dir = UE_GET_DIR(k) ? 1 : 0; | | 4187 | dir = UE_GET_DIR(k) ? 1 : 0; |
4188 | sitd->sitd.sitd_endp = | | 4188 | sitd->sitd.sitd_endp = |
4189 | htole32(EHCI_SITD_SET_ENDPT(UE_GET_ADDR(k)) | | | 4189 | htole32(EHCI_SITD_SET_ENDPT(UE_GET_ADDR(k)) | |
4190 | EHCI_SITD_SET_DADDR(dev->ud_addr) | | | 4190 | EHCI_SITD_SET_DADDR(dev->ud_addr) | |
4191 | EHCI_SITD_SET_PORT(dev->ud_myhsport->up_portno) | | | 4191 | EHCI_SITD_SET_PORT(dev->ud_myhsport->up_portno) | |
4192 | EHCI_SITD_SET_HUBA(huba) | | | 4192 | EHCI_SITD_SET_HUBA(huba) | |
4193 | EHCI_SITD_SET_DIR(dir)); | | 4193 | EHCI_SITD_SET_DIR(dir)); |
4194 | | | 4194 | |
4195 | sitd->sitd.sitd_back = htole32(EHCI_LINK_TERMINATE); | | 4195 | sitd->sitd.sitd_back = htole32(EHCI_LINK_TERMINATE); |
4196 | | | 4196 | |
4197 | /* XXX */ | | 4197 | /* XXX */ |
4198 | u_char sa, sb; | | 4198 | u_char sa, sb; |
4199 | u_int temp, tlen; | | 4199 | u_int temp, tlen; |
4200 | sa = 0; | | 4200 | sa = 0; |
4201 | | | 4201 | |
4202 | if (dir == 0) { /* OUT */ | | 4202 | if (dir == 0) { /* OUT */ |
4203 | temp = 0; | | 4203 | temp = 0; |
4204 | tlen = xfer->ux_frlengths[i]; | | 4204 | tlen = xfer->ux_frlengths[i]; |
4205 | if (tlen <= 188) { | | 4205 | if (tlen <= 188) { |
4206 | temp |= 1; /* T-count = 1, TP = ALL */ | | 4206 | temp |= 1; /* T-count = 1, TP = ALL */ |
4207 | tlen = 1; | | 4207 | tlen = 1; |
4208 | } else { | | 4208 | } else { |
4209 | tlen += 187; | | 4209 | tlen += 187; |
4210 | tlen /= 188; | | 4210 | tlen /= 188; |
4211 | temp |= tlen; /* T-count = [1..6] */ | | 4211 | temp |= tlen; /* T-count = [1..6] */ |
4212 | temp |= 8; /* TP = Begin */ | | 4212 | temp |= 8; /* TP = Begin */ |
4213 | } | | 4213 | } |
4214 | sitd->sitd.sitd_buffer[1] |= htole32(temp); | | 4214 | sitd->sitd.sitd_buffer[1] |= htole32(temp); |
4215 | | | 4215 | |
4216 | tlen += sa; | | 4216 | tlen += sa; |
4217 | | | 4217 | |
4218 | if (tlen >= 8) { | | 4218 | if (tlen >= 8) { |
4219 | sb = 0; | | 4219 | sb = 0; |
4220 | } else { | | 4220 | } else { |
4221 | sb = (1 << tlen); | | 4221 | sb = (1 << tlen); |
4222 | } | | 4222 | } |
4223 | | | 4223 | |
4224 | sa = (1 << sa); | | 4224 | sa = (1 << sa); |
4225 | sa = (sb - sa) & 0x3F; | | 4225 | sa = (sb - sa) & 0x3F; |
4226 | sb = 0; | | 4226 | sb = 0; |
4227 | } else { | | 4227 | } else { |
4228 | sb = (-(4 << sa)) & 0xFE; | | 4228 | sb = (-(4 << sa)) & 0xFE; |
4229 | sa = (1 << sa) & 0x3F; | | 4229 | sa = (1 << sa) & 0x3F; |
4230 | sa = 0x01; | | 4230 | sa = 0x01; |
4231 | sb = 0xfc; | | 4231 | sb = 0xfc; |
4232 | } | | 4232 | } |
4233 | | | 4233 | |
4234 | sitd->sitd.sitd_sched = htole32(EHCI_SITD_SET_SMASK(sa) | | | 4234 | sitd->sitd.sitd_sched = htole32(EHCI_SITD_SET_SMASK(sa) | |
4235 | EHCI_SITD_SET_CMASK(sb)); | | 4235 | EHCI_SITD_SET_CMASK(sb)); |
4236 | | | 4236 | |
4237 | prev = sitd; | | 4237 | prev = sitd; |
4238 | } /* End of frame */ | | 4238 | } /* End of frame */ |
4239 | | | 4239 | |
4240 | sitd->sitd.sitd_trans |= htole32(EHCI_SITD_IOC); | | 4240 | sitd->sitd.sitd_trans |= htole32(EHCI_SITD_IOC); |
4241 | | | 4241 | |
4242 | stop = sitd; | | 4242 | stop = sitd; |
4243 | stop->xfer_next = NULL; | | 4243 | stop->xfer_next = NULL; |
4244 | | | 4244 | |
4245 | usb_syncmem(&exfer->ex_xfer.ux_dmabuf, 0, total_length, | | 4245 | usb_syncmem(&exfer->ex_xfer.ux_dmabuf, 0, total_length, |
4246 | BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); | | 4246 | BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); |
4247 | | | 4247 | |
4248 | /* | | 4248 | /* |
4249 | * Part 2: Transfer descriptors have now been set up, now they must | | 4249 | * Part 2: Transfer descriptors have now been set up, now they must |
4250 | * be scheduled into the periodic frame list. Erk. Not wanting to | | 4250 | * be scheduled into the periodic frame list. Erk. Not wanting to |
4251 | * complicate matters, transfer is denied if the transfer spans | | 4251 | * complicate matters, transfer is denied if the transfer spans |
4252 | * more than the period frame list. | | 4252 | * more than the period frame list. |
4253 | */ | | 4253 | */ |
4254 | | | 4254 | |
4255 | mutex_enter(&sc->sc_lock); | | 4255 | mutex_enter(&sc->sc_lock); |
4256 | | | 4256 | |
4257 | /* Start inserting frames */ | | 4257 | /* Start inserting frames */ |
4258 | if (epipe->u.isoc.cur_xfers > 0) { | | 4258 | if (epipe->u.isoc.cur_xfers > 0) { |
4259 | frindex = epipe->u.isoc.next_frame; | | 4259 | frindex = epipe->u.isoc.next_frame; |
4260 | } else { | | 4260 | } else { |
4261 | frindex = EOREAD4(sc, EHCI_FRINDEX); | | 4261 | frindex = EOREAD4(sc, EHCI_FRINDEX); |
4262 | frindex = frindex >> 3; /* Erase microframe index */ | | 4262 | frindex = frindex >> 3; /* Erase microframe index */ |
4263 | frindex += 2; | | 4263 | frindex += 2; |
4264 | } | | 4264 | } |
4265 | | | 4265 | |
4266 | if (frindex >= sc->sc_flsize) | | 4266 | if (frindex >= sc->sc_flsize) |
4267 | frindex &= (sc->sc_flsize - 1); | | 4267 | frindex &= (sc->sc_flsize - 1); |
4268 | | | 4268 | |
4269 | /* Whats the frame interval? */ | | 4269 | /* Whats the frame interval? */ |
4270 | i = epipe->pipe.up_endpoint->ue_edesc->bInterval; | | 4270 | i = epipe->pipe.up_endpoint->ue_edesc->bInterval; |
4271 | | | 4271 | |
4272 | sitd = start; | | 4272 | sitd = start; |
4273 | for (j = 0; j < frames; j++) { | | 4273 | for (j = 0; j < frames; j++) { |
4274 | if (sitd == NULL) | | 4274 | if (sitd == NULL) |
4275 | panic("ehci: unexpectedly ran out of isoc sitds\n"); | | 4275 | panic("ehci: unexpectedly ran out of isoc sitds\n"); |
4276 | | | 4276 | |
4277 | sitd->sitd.sitd_next = sc->sc_flist[frindex]; | | 4277 | sitd->sitd.sitd_next = sc->sc_flist[frindex]; |
4278 | if (sitd->sitd.sitd_next == 0) | | 4278 | if (sitd->sitd.sitd_next == 0) |
4279 | /* FIXME: frindex table gets initialized to NULL | | 4279 | /* FIXME: frindex table gets initialized to NULL |
4280 | * or EHCI_NULL? */ | | 4280 | * or EHCI_NULL? */ |
4281 | sitd->sitd.sitd_next = EHCI_NULL; | | 4281 | sitd->sitd.sitd_next = EHCI_NULL; |
4282 | | | 4282 | |
4283 | usb_syncmem(&sitd->dma, | | 4283 | usb_syncmem(&sitd->dma, |
4284 | sitd->offs + offsetof(ehci_sitd_t, sitd_next), | | 4284 | sitd->offs + offsetof(ehci_sitd_t, sitd_next), |
4285 | sizeof(ehci_sitd_t), | | 4285 | sizeof(ehci_sitd_t), |
4286 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 4286 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
4287 | | | 4287 | |
4288 | sc->sc_flist[frindex] = | | 4288 | sc->sc_flist[frindex] = |
4289 | htole32(EHCI_LINK_SITD | sitd->physaddr); | | 4289 | htole32(EHCI_LINK_SITD | sitd->physaddr); |
4290 | | | 4290 | |
4291 | usb_syncmem(&sc->sc_fldma, | | 4291 | usb_syncmem(&sc->sc_fldma, |
4292 | sizeof(ehci_link_t) * frindex, | | 4292 | sizeof(ehci_link_t) * frindex, |
4293 | sizeof(ehci_link_t), | | 4293 | sizeof(ehci_link_t), |
4294 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 4294 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
4295 | | | 4295 | |
4296 | sitd->u.frame_list.next = sc->sc_softsitds[frindex]; | | 4296 | sitd->u.frame_list.next = sc->sc_softsitds[frindex]; |
4297 | sc->sc_softsitds[frindex] = sitd; | | 4297 | sc->sc_softsitds[frindex] = sitd; |
4298 | if (sitd->u.frame_list.next != NULL) | | 4298 | if (sitd->u.frame_list.next != NULL) |
4299 | sitd->u.frame_list.next->u.frame_list.prev = sitd; | | 4299 | sitd->u.frame_list.next->u.frame_list.prev = sitd; |
4300 | sitd->slot = frindex; | | 4300 | sitd->slot = frindex; |
4301 | sitd->u.frame_list.prev = NULL; | | 4301 | sitd->u.frame_list.prev = NULL; |
4302 | | | 4302 | |
4303 | frindex += i; | | 4303 | frindex += i; |
4304 | if (frindex >= sc->sc_flsize) | | 4304 | if (frindex >= sc->sc_flsize) |
4305 | frindex -= sc->sc_flsize; | | 4305 | frindex -= sc->sc_flsize; |
4306 | | | 4306 | |
4307 | sitd = sitd->xfer_next; | | 4307 | sitd = sitd->xfer_next; |
4308 | } | | 4308 | } |
4309 | | | 4309 | |
4310 | epipe->u.isoc.cur_xfers++; | | 4310 | epipe->u.isoc.cur_xfers++; |
4311 | epipe->u.isoc.next_frame = frindex; | | 4311 | epipe->u.isoc.next_frame = frindex; |
4312 | | | 4312 | |
4313 | exfer->ex_sitdstart = start; | | 4313 | exfer->ex_sitdstart = start; |
4314 | exfer->ex_sitdend = stop; | | 4314 | exfer->ex_sitdend = stop; |
4315 | | | 4315 | |
4316 | ehci_add_intr_list(sc, exfer); | | 4316 | ehci_add_intr_list(sc, exfer); |
4317 | xfer->ux_status = USBD_IN_PROGRESS; | | 4317 | xfer->ux_status = USBD_IN_PROGRESS; |
4318 | xfer->ux_done = 0; | | 4318 | xfer->ux_done = 0; |
4319 | | | 4319 | |
4320 | mutex_exit(&sc->sc_lock); | | 4320 | mutex_exit(&sc->sc_lock); |
4321 | | | 4321 | |
4322 | if (sc->sc_bus.ub_usepolling) { | | 4322 | if (sc->sc_bus.ub_usepolling) { |
4323 | printf("Starting ehci isoc xfer with polling. Bad idea?\n"); | | 4323 | printf("Starting ehci isoc xfer with polling. Bad idea?\n"); |
4324 | ehci_waitintr(sc, xfer); | | 4324 | ehci_waitintr(sc, xfer); |
4325 | } | | 4325 | } |
4326 | | | 4326 | |
4327 | return USBD_IN_PROGRESS; | | 4327 | return USBD_IN_PROGRESS; |
4328 | } | | 4328 | } |
4329 | | | 4329 | |
4330 | Static void | | 4330 | Static void |
4331 | ehci_device_fs_isoc_abort(usbd_xfer_handle xfer) | | 4331 | ehci_device_fs_isoc_abort(usbd_xfer_handle xfer) |
4332 | { | | 4332 | { |
4333 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 4333 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
4334 | | | 4334 | |
4335 | USBHIST_LOG(ehcidebug, "xfer = %p", xfer, 0, 0, 0); | | 4335 | USBHIST_LOG(ehcidebug, "xfer = %p", xfer, 0, 0, 0); |
4336 | ehci_abort_isoc_xfer(xfer, USBD_CANCELLED); | | 4336 | ehci_abort_isoc_xfer(xfer, USBD_CANCELLED); |
4337 | } | | 4337 | } |
4338 | | | 4338 | |
4339 | Static void | | 4339 | Static void |
4340 | ehci_device_fs_isoc_close(usbd_pipe_handle pipe) | | 4340 | ehci_device_fs_isoc_close(usbd_pipe_handle pipe) |
4341 | { | | 4341 | { |
4342 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 4342 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
4343 | | | 4343 | |
4344 | USBHIST_LOG(ehcidebug, "nothing in the pipe to free?", 0, 0, 0, 0); | | 4344 | USBHIST_LOG(ehcidebug, "nothing in the pipe to free?", 0, 0, 0, 0); |
4345 | } | | 4345 | } |
4346 | | | 4346 | |
4347 | Static void | | 4347 | Static void |
4348 | ehci_device_fs_isoc_done(usbd_xfer_handle xfer) | | 4348 | ehci_device_fs_isoc_done(usbd_xfer_handle xfer) |
4349 | { | | 4349 | { |
4350 | struct ehci_xfer *exfer; | | 4350 | struct ehci_xfer *exfer; |
4351 | ehci_softc_t *sc; | | 4351 | ehci_softc_t *sc; |
4352 | struct ehci_pipe *epipe; | | 4352 | struct ehci_pipe *epipe; |
4353 | | | 4353 | |
4354 | exfer = EXFER(xfer); | | 4354 | exfer = EXFER(xfer); |
4355 | sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 4355 | sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
4356 | epipe = (struct ehci_pipe *) xfer->ux_pipe; | | 4356 | epipe = (struct ehci_pipe *) xfer->ux_pipe; |
4357 | | | 4357 | |
4358 | KASSERT(mutex_owned(&sc->sc_lock)); | | 4358 | KASSERT(mutex_owned(&sc->sc_lock)); |
4359 | | | 4359 | |
4360 | epipe->u.isoc.cur_xfers--; | | 4360 | epipe->u.isoc.cur_xfers--; |
4361 | if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(exfer)) { | | 4361 | if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(exfer)) { |
4362 | ehci_del_intr_list(sc, exfer); | | 4362 | ehci_del_intr_list(sc, exfer); |
4363 | ehci_rem_free_sitd_chain(sc, exfer); | | 4363 | ehci_rem_free_sitd_chain(sc, exfer); |
4364 | } | | 4364 | } |
4365 | | | 4365 | |
4366 | usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, BUS_DMASYNC_POSTWRITE | | | 4366 | usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, BUS_DMASYNC_POSTWRITE | |
4367 | BUS_DMASYNC_POSTREAD); | | 4367 | BUS_DMASYNC_POSTREAD); |
4368 | } | | 4368 | } |
4369 | Static usbd_status | | 4369 | Static usbd_status |
4370 | ehci_device_isoc_transfer(usbd_xfer_handle xfer) | | 4370 | ehci_device_isoc_transfer(usbd_xfer_handle xfer) |
4371 | { | | 4371 | { |
4372 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 4372 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
4373 | usbd_status err; | | 4373 | usbd_status err; |
4374 | | | 4374 | |
4375 | mutex_enter(&sc->sc_lock); | | 4375 | mutex_enter(&sc->sc_lock); |
4376 | err = usb_insert_transfer(xfer); | | 4376 | err = usb_insert_transfer(xfer); |
4377 | mutex_exit(&sc->sc_lock); | | 4377 | mutex_exit(&sc->sc_lock); |
4378 | if (err && err != USBD_IN_PROGRESS) | | 4378 | if (err && err != USBD_IN_PROGRESS) |
4379 | return err; | | 4379 | return err; |
4380 | | | 4380 | |
4381 | return ehci_device_isoc_start(xfer); | | 4381 | return ehci_device_isoc_start(xfer); |
4382 | } | | 4382 | } |
4383 | | | 4383 | |
4384 | Static usbd_status | | 4384 | Static usbd_status |
4385 | ehci_device_isoc_start(usbd_xfer_handle xfer) | | 4385 | ehci_device_isoc_start(usbd_xfer_handle xfer) |
4386 | { | | 4386 | { |
4387 | struct ehci_pipe *epipe; | | 4387 | struct ehci_pipe *epipe; |
4388 | ehci_softc_t *sc; | | 4388 | ehci_softc_t *sc; |
4389 | struct ehci_xfer *exfer; | | 4389 | struct ehci_xfer *exfer; |
4390 | ehci_soft_itd_t *itd, *prev, *start, *stop; | | 4390 | ehci_soft_itd_t *itd, *prev, *start, *stop; |
4391 | usb_dma_t *dma_buf; | | 4391 | usb_dma_t *dma_buf; |
4392 | int i, j, k, frames, uframes, ufrperframe; | | 4392 | int i, j, k, frames, uframes, ufrperframe; |
4393 | int trans_count, offs, total_length; | | 4393 | int trans_count, offs, total_length; |
4394 | int frindex; | | 4394 | int frindex; |
4395 | | | 4395 | |
4396 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 4396 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
4397 | | | 4397 | |
4398 | start = NULL; | | 4398 | start = NULL; |
4399 | prev = NULL; | | 4399 | prev = NULL; |
4400 | itd = NULL; | | 4400 | itd = NULL; |
4401 | trans_count = 0; | | 4401 | trans_count = 0; |
4402 | total_length = 0; | | 4402 | total_length = 0; |
4403 | exfer = (struct ehci_xfer *) xfer; | | 4403 | exfer = (struct ehci_xfer *) xfer; |
4404 | sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 4404 | sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
4405 | epipe = (struct ehci_pipe *)xfer->ux_pipe; | | 4405 | epipe = (struct ehci_pipe *)xfer->ux_pipe; |
4406 | | | 4406 | |
4407 | /* | | 4407 | /* |
4408 | * To allow continuous transfers, above we start all transfers | | 4408 | * To allow continuous transfers, above we start all transfers |
4409 | * immediately. However, we're still going to get usbd_start_next call | | 4409 | * immediately. However, we're still going to get usbd_start_next call |
4410 | * this when another xfer completes. So, check if this is already | | 4410 | * this when another xfer completes. So, check if this is already |
4411 | * in progress or not | | 4411 | * in progress or not |
4412 | */ | | 4412 | */ |
4413 | | | 4413 | |
4414 | if (exfer->ex_itdstart != NULL) | | 4414 | if (exfer->ex_itdstart != NULL) |
4415 | return USBD_IN_PROGRESS; | | 4415 | return USBD_IN_PROGRESS; |
4416 | | | 4416 | |
4417 | USBHIST_LOG(ehcidebug, "xfer %p len %d flags %d", | | 4417 | USBHIST_LOG(ehcidebug, "xfer %p len %d flags %d", |
4418 | xfer, xfer->ux_length, xfer->ux_flags, 0); | | 4418 | xfer, xfer->ux_length, xfer->ux_flags, 0); |
4419 | | | 4419 | |
4420 | if (sc->sc_dying) | | 4420 | if (sc->sc_dying) |
4421 | return USBD_IOERROR; | | 4421 | return USBD_IOERROR; |
4422 | | | 4422 | |
4423 | /* | | 4423 | /* |
4424 | * To avoid complication, don't allow a request right now that'll span | | 4424 | * To avoid complication, don't allow a request right now that'll span |
4425 | * the entire frame table. To within 4 frames, to allow some leeway | | 4425 | * the entire frame table. To within 4 frames, to allow some leeway |
4426 | * on either side of where the hc currently is. | | 4426 | * on either side of where the hc currently is. |
4427 | */ | | 4427 | */ |
4428 | if ((1 << (epipe->pipe.up_endpoint->ue_edesc->bInterval)) * | | 4428 | if ((1 << (epipe->pipe.up_endpoint->ue_edesc->bInterval)) * |
4429 | xfer->ux_nframes >= (sc->sc_flsize - 4) * 8) { | | 4429 | xfer->ux_nframes >= (sc->sc_flsize - 4) * 8) { |
4430 | USBHIST_LOG(ehcidebug, | | 4430 | USBHIST_LOG(ehcidebug, |
4431 | "isoc descriptor spans entire frametable", 0, 0, 0, 0); | | 4431 | "isoc descriptor spans entire frametable", 0, 0, 0, 0); |
4432 | printf("ehci: isoc descriptor requested that spans the entire frametable, too many frames\n"); | | 4432 | printf("ehci: isoc descriptor requested that spans the entire frametable, too many frames\n"); |
4433 | return USBD_INVAL; | | 4433 | return USBD_INVAL; |
4434 | } | | 4434 | } |
4435 | | | 4435 | |
4436 | KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); | | 4436 | KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); |
4437 | KASSERT(exfer->ex_isdone); | | 4437 | KASSERT(exfer->ex_isdone); |
4438 | #ifdef DIAGNOSTIC | | 4438 | #ifdef DIAGNOSTIC |
4439 | exfer->ex_isdone = false; | | 4439 | exfer->ex_isdone = false; |
4440 | #endif | | 4440 | #endif |
4441 | | | 4441 | |
4442 | /* | | 4442 | /* |
4443 | * Step 1: Allocate and initialize itds, how many do we need? | | 4443 | * Step 1: Allocate and initialize itds, how many do we need? |
4444 | * One per transfer if interval >= 8 microframes, fewer if we use | | 4444 | * One per transfer if interval >= 8 microframes, fewer if we use |
4445 | * multiple microframes per frame. | | 4445 | * multiple microframes per frame. |
4446 | */ | | 4446 | */ |
4447 | | | 4447 | |
4448 | i = epipe->pipe.up_endpoint->ue_edesc->bInterval; | | 4448 | i = epipe->pipe.up_endpoint->ue_edesc->bInterval; |
4449 | if (i > 16 || i == 0) { | | 4449 | if (i > 16 || i == 0) { |
4450 | /* Spec page 271 says intervals > 16 are invalid */ | | 4450 | /* Spec page 271 says intervals > 16 are invalid */ |
4451 | USBHIST_LOG(ehcidebug, "bInterval %d invalid", i, 0, 0, 0); | | 4451 | USBHIST_LOG(ehcidebug, "bInterval %d invalid", i, 0, 0, 0); |
4452 | return USBD_INVAL; | | 4452 | return USBD_INVAL; |
4453 | } | | 4453 | } |
4454 | | | 4454 | |
4455 | ufrperframe = max(1, USB_UFRAMES_PER_FRAME / (1 << (i - 1))); | | 4455 | ufrperframe = max(1, USB_UFRAMES_PER_FRAME / (1 << (i - 1))); |
4456 | frames = (xfer->ux_nframes + (ufrperframe - 1)) / ufrperframe; | | 4456 | frames = (xfer->ux_nframes + (ufrperframe - 1)) / ufrperframe; |
4457 | uframes = USB_UFRAMES_PER_FRAME / ufrperframe; | | 4457 | uframes = USB_UFRAMES_PER_FRAME / ufrperframe; |
4458 | | | 4458 | |
4459 | if (frames == 0) { | | 4459 | if (frames == 0) { |
4460 | USBHIST_LOG(ehcidebug, "frames == 0", 0, 0, 0, 0); | | 4460 | USBHIST_LOG(ehcidebug, "frames == 0", 0, 0, 0, 0); |
4461 | return USBD_INVAL; | | 4461 | return USBD_INVAL; |
4462 | } | | 4462 | } |
4463 | | | 4463 | |
4464 | dma_buf = &xfer->ux_dmabuf; | | 4464 | dma_buf = &xfer->ux_dmabuf; |
4465 | offs = 0; | | 4465 | offs = 0; |
4466 | | | 4466 | |
4467 | for (i = 0; i < frames; i++) { | | 4467 | for (i = 0; i < frames; i++) { |
4468 | int froffs = offs; | | 4468 | int froffs = offs; |
4469 | itd = ehci_alloc_itd(sc); | | 4469 | itd = ehci_alloc_itd(sc); |
4470 | | | 4470 | |
4471 | if (prev != NULL) { | | 4471 | if (prev != NULL) { |
4472 | prev->itd.itd_next = | | 4472 | prev->itd.itd_next = |
4473 | htole32(itd->physaddr | EHCI_LINK_ITD); | | 4473 | htole32(itd->physaddr | EHCI_LINK_ITD); |
4474 | usb_syncmem(&itd->dma, | | 4474 | usb_syncmem(&itd->dma, |
4475 | itd->offs + offsetof(ehci_itd_t, itd_next), | | 4475 | itd->offs + offsetof(ehci_itd_t, itd_next), |
4476 | sizeof(itd->itd.itd_next), BUS_DMASYNC_POSTWRITE); | | 4476 | sizeof(itd->itd.itd_next), BUS_DMASYNC_POSTWRITE); |
4477 | | | 4477 | |
4478 | prev->xfer_next = itd; | | 4478 | prev->xfer_next = itd; |
4479 | } else { | | 4479 | } else { |
4480 | start = itd; | | 4480 | start = itd; |
4481 | } | | 4481 | } |
4482 | | | 4482 | |
4483 | /* | | 4483 | /* |
4484 | * Step 1.5, initialize uframes | | 4484 | * Step 1.5, initialize uframes |
4485 | */ | | 4485 | */ |
4486 | for (j = 0; j < EHCI_ITD_NUFRAMES; j += uframes) { | | 4486 | for (j = 0; j < EHCI_ITD_NUFRAMES; j += uframes) { |
4487 | /* Calculate which page in the list this starts in */ | | 4487 | /* Calculate which page in the list this starts in */ |
4488 | int addr = DMAADDR(dma_buf, froffs); | | 4488 | int addr = DMAADDR(dma_buf, froffs); |
4489 | addr = EHCI_PAGE_OFFSET(addr); | | 4489 | addr = EHCI_PAGE_OFFSET(addr); |
4490 | addr += (offs - froffs); | | 4490 | addr += (offs - froffs); |
4491 | addr = EHCI_PAGE(addr); | | 4491 | addr = EHCI_PAGE(addr); |
4492 | addr /= EHCI_PAGE_SIZE; | | 4492 | addr /= EHCI_PAGE_SIZE; |
4493 | | | 4493 | |
4494 | /* | | 4494 | /* |
4495 | * This gets the initial offset into the first page, | | 4495 | * This gets the initial offset into the first page, |
4496 | * looks how far further along the current uframe | | 4496 | * looks how far further along the current uframe |
4497 | * offset is. Works out how many pages that is. | | 4497 | * offset is. Works out how many pages that is. |
4498 | */ | | 4498 | */ |
4499 | | | 4499 | |
4500 | itd->itd.itd_ctl[j] = htole32 ( EHCI_ITD_ACTIVE | | | 4500 | itd->itd.itd_ctl[j] = htole32 ( EHCI_ITD_ACTIVE | |
4501 | EHCI_ITD_SET_LEN(xfer->ux_frlengths[trans_count]) | | | 4501 | EHCI_ITD_SET_LEN(xfer->ux_frlengths[trans_count]) | |
4502 | EHCI_ITD_SET_PG(addr) | | | 4502 | EHCI_ITD_SET_PG(addr) | |
4503 | EHCI_ITD_SET_OFFS(EHCI_PAGE_OFFSET(DMAADDR(dma_buf,offs)))); | | 4503 | EHCI_ITD_SET_OFFS(EHCI_PAGE_OFFSET(DMAADDR(dma_buf,offs)))); |
4504 | | | 4504 | |
4505 | total_length += xfer->ux_frlengths[trans_count]; | | 4505 | total_length += xfer->ux_frlengths[trans_count]; |
4506 | offs += xfer->ux_frlengths[trans_count]; | | 4506 | offs += xfer->ux_frlengths[trans_count]; |
4507 | trans_count++; | | 4507 | trans_count++; |
4508 | | | 4508 | |
4509 | if (trans_count >= xfer->ux_nframes) { /*Set IOC*/ | | 4509 | if (trans_count >= xfer->ux_nframes) { /*Set IOC*/ |
4510 | itd->itd.itd_ctl[j] |= htole32(EHCI_ITD_IOC); | | 4510 | itd->itd.itd_ctl[j] |= htole32(EHCI_ITD_IOC); |
4511 | break; | | 4511 | break; |
4512 | } | | 4512 | } |
4513 | } | | 4513 | } |
4514 | | | 4514 | |
4515 | /* | | 4515 | /* |
4516 | * Step 1.75, set buffer pointers. To simplify matters, all | | 4516 | * Step 1.75, set buffer pointers. To simplify matters, all |
4517 | * pointers are filled out for the next 7 hardware pages in | | 4517 | * pointers are filled out for the next 7 hardware pages in |
4518 | * the dma block, so no need to worry what pages to cover | | 4518 | * the dma block, so no need to worry what pages to cover |
4519 | * and what to not. | | 4519 | * and what to not. |
4520 | */ | | 4520 | */ |
4521 | | | 4521 | |
4522 | for (j = 0; j < EHCI_ITD_NBUFFERS; j++) { | | 4522 | for (j = 0; j < EHCI_ITD_NBUFFERS; j++) { |
4523 | /* | | 4523 | /* |
4524 | * Don't try to lookup a page that's past the end | | 4524 | * Don't try to lookup a page that's past the end |
4525 | * of buffer | | 4525 | * of buffer |
4526 | */ | | 4526 | */ |
4527 | int page_offs = EHCI_PAGE(froffs + (EHCI_PAGE_SIZE * j)); | | 4527 | int page_offs = EHCI_PAGE(froffs + (EHCI_PAGE_SIZE * j)); |
4528 | if (page_offs >= dma_buf->udma_block->size) | | 4528 | if (page_offs >= dma_buf->udma_block->size) |
4529 | break; | | 4529 | break; |
4530 | | | 4530 | |
4531 | unsigned long long page = DMAADDR(dma_buf, page_offs); | | 4531 | unsigned long long page = DMAADDR(dma_buf, page_offs); |
4532 | page = EHCI_PAGE(page); | | 4532 | page = EHCI_PAGE(page); |
4533 | itd->itd.itd_bufr[j] = | | 4533 | itd->itd.itd_bufr[j] = |
4534 | htole32(EHCI_ITD_SET_BPTR(page)); | | 4534 | htole32(EHCI_ITD_SET_BPTR(page)); |
4535 | itd->itd.itd_bufr_hi[j] = | | 4535 | itd->itd.itd_bufr_hi[j] = |
4536 | htole32(page >> 32); | | 4536 | htole32(page >> 32); |
4537 | } | | 4537 | } |
4538 | | | 4538 | |
4539 | /* | | 4539 | /* |
4540 | * Other special values | | 4540 | * Other special values |
4541 | */ | | 4541 | */ |