| @@ -1,1055 +1,1055 @@ | | | @@ -1,1055 +1,1055 @@ |
1 | /* $NetBSD: ehci.c,v 1.234.2.33 2015/03/01 08:18:16 skrll Exp $ */ | | 1 | /* $NetBSD: ehci.c,v 1.234.2.34 2015/03/01 08:26:55 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.33 2015/03/01 08:18:16 skrll Exp $"); | | 56 | __KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.234.2.34 2015/03/01 08:26:55 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 | if (ex->ex_isdone) { | | 1021 | if (ex->ex_isdone) { |
1022 | printf("ehci_idone: ex=%p is done!\n", ex); | | 1022 | printf("ehci_idone: ex=%p is done!\n", ex); |
1023 | #ifdef EHCI_DEBUG | | 1023 | #ifdef EHCI_DEBUG |
1024 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); | | 1024 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); |
1025 | ehci_dump_exfer(ex); | | 1025 | ehci_dump_exfer(ex); |
1026 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); | | 1026 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); |
1027 | #endif | | 1027 | #endif |
1028 | return; | | 1028 | return; |
1029 | } | | 1029 | } |
1030 | ex->ex_isdone = 1; | | 1030 | ex->ex_isdone = 1; |
1031 | #endif | | 1031 | #endif |
1032 | | | 1032 | |
1033 | if (xfer->ux_status == USBD_CANCELLED || | | 1033 | if (xfer->ux_status == USBD_CANCELLED || |
1034 | xfer->ux_status == USBD_TIMEOUT) { | | 1034 | xfer->ux_status == USBD_TIMEOUT) { |
1035 | USBHIST_LOG(ehcidebug, "aborted xfer=%p", xfer, 0, 0, 0); | | 1035 | USBHIST_LOG(ehcidebug, "aborted xfer=%p", xfer, 0, 0, 0); |
1036 | return; | | 1036 | return; |
1037 | } | | 1037 | } |
1038 | | | 1038 | |
1039 | USBHIST_LOG(ehcidebug, "xfer=%p, pipe=%p ready", xfer, epipe, 0, 0); | | 1039 | USBHIST_LOG(ehcidebug, "xfer=%p, pipe=%p ready", xfer, epipe, 0, 0); |
1040 | #ifdef EHCI_DEBUG | | 1040 | #ifdef EHCI_DEBUG |
1041 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); | | 1041 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); |
1042 | ehci_dump_sqtds(ex->ex_sqtdstart); | | 1042 | ehci_dump_sqtds(ex->ex_sqtdstart); |
1043 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); | | 1043 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); |
1044 | #endif | | 1044 | #endif |
1045 | | | 1045 | |
1046 | /* The transfer is done, compute actual length and status. */ | | 1046 | /* The transfer is done, compute actual length and status. */ |
1047 | | | 1047 | |
1048 | u_int xfertype, speed; | | 1048 | u_int xfertype, speed; |
1049 | | | 1049 | |
1050 | xfertype = UE_GET_XFERTYPE(xfer->ux_pipe->up_endpoint->ue_edesc->bmAttributes); | | 1050 | xfertype = UE_GET_XFERTYPE(xfer->ux_pipe->up_endpoint->ue_edesc->bmAttributes); |
1051 | speed = xfer->ux_pipe->up_dev->ud_speed; | | 1051 | speed = xfer->ux_pipe->up_dev->ud_speed; |
1052 | if (xfertype == UE_ISOCHRONOUS && speed == USB_SPEED_HIGH) { | | 1052 | if (xfertype == UE_ISOCHRONOUS && speed == USB_SPEED_HIGH) { |
1053 | /* HS isoc transfer */ | | 1053 | /* HS isoc transfer */ |
1054 | | | 1054 | |
1055 | struct ehci_soft_itd *itd; | | 1055 | struct ehci_soft_itd *itd; |
| @@ -1845,1999 +1845,1999 @@ ehci_open(usbd_pipe_handle pipe) | | | @@ -1845,1999 +1845,1999 @@ ehci_open(usbd_pipe_handle pipe) |
1845 | uint8_t rhaddr = dev->ud_bus->ub_rhaddr; | | 1845 | uint8_t rhaddr = dev->ud_bus->ub_rhaddr; |
1846 | uint8_t addr = dev->ud_addr; | | 1846 | uint8_t addr = dev->ud_addr; |
1847 | uint8_t xfertype = UE_GET_XFERTYPE(ed->bmAttributes); | | 1847 | uint8_t xfertype = UE_GET_XFERTYPE(ed->bmAttributes); |
1848 | struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; | | 1848 | struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; |
1849 | ehci_soft_qh_t *sqh; | | 1849 | ehci_soft_qh_t *sqh; |
1850 | usbd_status err; | | 1850 | usbd_status err; |
1851 | int ival, speed, naks; | | 1851 | int ival, speed, naks; |
1852 | int hshubaddr, hshubport; | | 1852 | int hshubaddr, hshubport; |
1853 | | | 1853 | |
1854 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 1854 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
1855 | | | 1855 | |
1856 | USBHIST_LOG(ehcidebug, "pipe=%p, addr=%d, endpt=%d (%d)", | | 1856 | USBHIST_LOG(ehcidebug, "pipe=%p, addr=%d, endpt=%d (%d)", |
1857 | pipe, addr, ed->bEndpointAddress, rhaddr); | | 1857 | pipe, addr, ed->bEndpointAddress, rhaddr); |
1858 | | | 1858 | |
1859 | if (dev->ud_myhsport) { | | 1859 | if (dev->ud_myhsport) { |
1860 | /* | | 1860 | /* |
1861 | * When directly attached FS/LS device while doing embedded | | 1861 | * When directly attached FS/LS device while doing embedded |
1862 | * transaction translations and we are the hub, set the hub | | 1862 | * transaction translations and we are the hub, set the hub |
1863 | * address to 0 (us). | | 1863 | * address to 0 (us). |
1864 | */ | | 1864 | */ |
1865 | if (!(sc->sc_flags & EHCIF_ETTF) | | 1865 | if (!(sc->sc_flags & EHCIF_ETTF) |
1866 | || (dev->ud_myhsport->up_parent->ud_addr != rhaddr)) { | | 1866 | || (dev->ud_myhsport->up_parent->ud_addr != rhaddr)) { |
1867 | hshubaddr = dev->ud_myhsport->up_parent->ud_addr; | | 1867 | hshubaddr = dev->ud_myhsport->up_parent->ud_addr; |
1868 | } else { | | 1868 | } else { |
1869 | hshubaddr = 0; | | 1869 | hshubaddr = 0; |
1870 | } | | 1870 | } |
1871 | hshubport = dev->ud_myhsport->up_portno; | | 1871 | hshubport = dev->ud_myhsport->up_portno; |
1872 | } else { | | 1872 | } else { |
1873 | hshubaddr = 0; | | 1873 | hshubaddr = 0; |
1874 | hshubport = 0; | | 1874 | hshubport = 0; |
1875 | } | | 1875 | } |
1876 | | | 1876 | |
1877 | if (sc->sc_dying) | | 1877 | if (sc->sc_dying) |
1878 | return USBD_IOERROR; | | 1878 | return USBD_IOERROR; |
1879 | | | 1879 | |
1880 | /* toggle state needed for bulk endpoints */ | | 1880 | /* toggle state needed for bulk endpoints */ |
1881 | epipe->nexttoggle = pipe->up_endpoint->ue_toggle; | | 1881 | epipe->nexttoggle = pipe->up_endpoint->ue_toggle; |
1882 | | | 1882 | |
1883 | if (addr == rhaddr) { | | 1883 | if (addr == rhaddr) { |
1884 | switch (ed->bEndpointAddress) { | | 1884 | switch (ed->bEndpointAddress) { |
1885 | case USB_CONTROL_ENDPOINT: | | 1885 | case USB_CONTROL_ENDPOINT: |
1886 | pipe->up_methods = &roothub_ctrl_methods; | | 1886 | pipe->up_methods = &roothub_ctrl_methods; |
1887 | break; | | 1887 | break; |
1888 | case UE_DIR_IN | USBROOTHUB_INTR_ENDPT: | | 1888 | case UE_DIR_IN | USBROOTHUB_INTR_ENDPT: |
1889 | pipe->up_methods = &ehci_root_intr_methods; | | 1889 | pipe->up_methods = &ehci_root_intr_methods; |
1890 | break; | | 1890 | break; |
1891 | default: | | 1891 | default: |
1892 | USBHIST_LOG(ehcidebug, | | 1892 | USBHIST_LOG(ehcidebug, |
1893 | "bad bEndpointAddress 0x%02x", | | 1893 | "bad bEndpointAddress 0x%02x", |
1894 | ed->bEndpointAddress, 0, 0, 0); | | 1894 | ed->bEndpointAddress, 0, 0, 0); |
1895 | return USBD_INVAL; | | 1895 | return USBD_INVAL; |
1896 | } | | 1896 | } |
1897 | return USBD_NORMAL_COMPLETION; | | 1897 | return USBD_NORMAL_COMPLETION; |
1898 | } | | 1898 | } |
1899 | | | 1899 | |
1900 | /* XXX All this stuff is only valid for async. */ | | 1900 | /* XXX All this stuff is only valid for async. */ |
1901 | switch (dev->ud_speed) { | | 1901 | switch (dev->ud_speed) { |
1902 | case USB_SPEED_LOW: speed = EHCI_QH_SPEED_LOW; break; | | 1902 | case USB_SPEED_LOW: speed = EHCI_QH_SPEED_LOW; break; |
1903 | case USB_SPEED_FULL: speed = EHCI_QH_SPEED_FULL; break; | | 1903 | case USB_SPEED_FULL: speed = EHCI_QH_SPEED_FULL; break; |
1904 | case USB_SPEED_HIGH: speed = EHCI_QH_SPEED_HIGH; break; | | 1904 | case USB_SPEED_HIGH: speed = EHCI_QH_SPEED_HIGH; break; |
1905 | default: panic("ehci_open: bad device speed %d", dev->ud_speed); | | 1905 | default: panic("ehci_open: bad device speed %d", dev->ud_speed); |
1906 | } | | 1906 | } |
1907 | if (speed == EHCI_QH_SPEED_LOW && xfertype == UE_ISOCHRONOUS) { | | 1907 | if (speed == EHCI_QH_SPEED_LOW && xfertype == UE_ISOCHRONOUS) { |
1908 | USBHIST_LOG(ehcidebug, "hshubaddr=%d hshubport=%d", | | 1908 | USBHIST_LOG(ehcidebug, "hshubaddr=%d hshubport=%d", |
1909 | hshubaddr, hshubport, 0, 0); | | 1909 | hshubaddr, hshubport, 0, 0); |
1910 | return USBD_INVAL; | | 1910 | return USBD_INVAL; |
1911 | } | | 1911 | } |
1912 | | | 1912 | |
1913 | /* | | 1913 | /* |
1914 | * For interrupt transfer, nak throttling must be disabled, but for | | 1914 | * For interrupt transfer, nak throttling must be disabled, but for |
1915 | * the other transfer type, nak throttling should be enabled from the | | 1915 | * the other transfer type, nak throttling should be enabled from the |
1916 | * viewpoint that avoids the memory thrashing. | | 1916 | * viewpoint that avoids the memory thrashing. |
1917 | */ | | 1917 | */ |
1918 | naks = (xfertype == UE_INTERRUPT) ? 0 | | 1918 | naks = (xfertype == UE_INTERRUPT) ? 0 |
1919 | : ((speed == EHCI_QH_SPEED_HIGH) ? 4 : 0); | | 1919 | : ((speed == EHCI_QH_SPEED_HIGH) ? 4 : 0); |
1920 | | | 1920 | |
1921 | /* Allocate sqh for everything, save isoc xfers */ | | 1921 | /* Allocate sqh for everything, save isoc xfers */ |
1922 | if (xfertype != UE_ISOCHRONOUS) { | | 1922 | if (xfertype != UE_ISOCHRONOUS) { |
1923 | sqh = ehci_alloc_sqh(sc); | | 1923 | sqh = ehci_alloc_sqh(sc); |
1924 | if (sqh == NULL) | | 1924 | if (sqh == NULL) |
1925 | return USBD_NOMEM; | | 1925 | return USBD_NOMEM; |
1926 | /* qh_link filled when the QH is added */ | | 1926 | /* qh_link filled when the QH is added */ |
1927 | sqh->qh.qh_endp = htole32( | | 1927 | sqh->qh.qh_endp = htole32( |
1928 | EHCI_QH_SET_ADDR(addr) | | | 1928 | EHCI_QH_SET_ADDR(addr) | |
1929 | EHCI_QH_SET_ENDPT(UE_GET_ADDR(ed->bEndpointAddress)) | | | 1929 | EHCI_QH_SET_ENDPT(UE_GET_ADDR(ed->bEndpointAddress)) | |
1930 | EHCI_QH_SET_EPS(speed) | | | 1930 | EHCI_QH_SET_EPS(speed) | |
1931 | EHCI_QH_DTC | | | 1931 | EHCI_QH_DTC | |
1932 | EHCI_QH_SET_MPL(UGETW(ed->wMaxPacketSize)) | | | 1932 | EHCI_QH_SET_MPL(UGETW(ed->wMaxPacketSize)) | |
1933 | (speed != EHCI_QH_SPEED_HIGH && xfertype == UE_CONTROL ? | | 1933 | (speed != EHCI_QH_SPEED_HIGH && xfertype == UE_CONTROL ? |
1934 | EHCI_QH_CTL : 0) | | | 1934 | EHCI_QH_CTL : 0) | |
1935 | EHCI_QH_SET_NRL(naks) | | 1935 | EHCI_QH_SET_NRL(naks) |
1936 | ); | | 1936 | ); |
1937 | sqh->qh.qh_endphub = htole32( | | 1937 | sqh->qh.qh_endphub = htole32( |
1938 | EHCI_QH_SET_MULT(1) | | | 1938 | EHCI_QH_SET_MULT(1) | |
1939 | EHCI_QH_SET_SMASK(xfertype == UE_INTERRUPT ? 0x02 : 0) | | 1939 | EHCI_QH_SET_SMASK(xfertype == UE_INTERRUPT ? 0x02 : 0) |
1940 | ); | | 1940 | ); |
1941 | if (speed != EHCI_QH_SPEED_HIGH) | | 1941 | if (speed != EHCI_QH_SPEED_HIGH) |
1942 | sqh->qh.qh_endphub |= htole32( | | 1942 | sqh->qh.qh_endphub |= htole32( |
1943 | EHCI_QH_SET_PORT(hshubport) | | | 1943 | EHCI_QH_SET_PORT(hshubport) | |
1944 | EHCI_QH_SET_HUBA(hshubaddr) | | | 1944 | EHCI_QH_SET_HUBA(hshubaddr) | |
1945 | EHCI_QH_SET_CMASK(0x08) /* XXX */ | | 1945 | EHCI_QH_SET_CMASK(0x08) /* XXX */ |
1946 | ); | | 1946 | ); |
1947 | sqh->qh.qh_curqtd = EHCI_NULL; | | 1947 | sqh->qh.qh_curqtd = EHCI_NULL; |
1948 | /* Fill the overlay qTD */ | | 1948 | /* Fill the overlay qTD */ |
1949 | sqh->qh.qh_qtd.qtd_next = EHCI_NULL; | | 1949 | sqh->qh.qh_qtd.qtd_next = EHCI_NULL; |
1950 | sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL; | | 1950 | sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL; |
1951 | sqh->qh.qh_qtd.qtd_status = htole32(0); | | 1951 | sqh->qh.qh_qtd.qtd_status = htole32(0); |
1952 | | | 1952 | |
1953 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), | | 1953 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), |
1954 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 1954 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
1955 | epipe->sqh = sqh; | | 1955 | epipe->sqh = sqh; |
1956 | } else { | | 1956 | } else { |
1957 | sqh = NULL; | | 1957 | sqh = NULL; |
1958 | } /*xfertype == UE_ISOC*/ | | 1958 | } /*xfertype == UE_ISOC*/ |
1959 | | | 1959 | |
1960 | switch (xfertype) { | | 1960 | switch (xfertype) { |
1961 | case UE_CONTROL: | | 1961 | case UE_CONTROL: |
1962 | err = usb_allocmem(&sc->sc_bus, sizeof(usb_device_request_t), | | 1962 | err = usb_allocmem(&sc->sc_bus, sizeof(usb_device_request_t), |
1963 | 0, &epipe->u.ctl.reqdma); | | 1963 | 0, &epipe->u.ctl.reqdma); |
1964 | #ifdef EHCI_DEBUG | | 1964 | #ifdef EHCI_DEBUG |
1965 | if (err) | | 1965 | if (err) |
1966 | printf("ehci_open: usb_allocmem()=%d\n", err); | | 1966 | printf("ehci_open: usb_allocmem()=%d\n", err); |
1967 | #endif | | 1967 | #endif |
1968 | if (err) | | 1968 | if (err) |
1969 | goto bad; | | 1969 | goto bad; |
1970 | pipe->up_methods = &ehci_device_ctrl_methods; | | 1970 | pipe->up_methods = &ehci_device_ctrl_methods; |
1971 | mutex_enter(&sc->sc_lock); | | 1971 | mutex_enter(&sc->sc_lock); |
1972 | ehci_add_qh(sc, sqh, sc->sc_async_head); | | 1972 | ehci_add_qh(sc, sqh, sc->sc_async_head); |
1973 | mutex_exit(&sc->sc_lock); | | 1973 | mutex_exit(&sc->sc_lock); |
1974 | break; | | 1974 | break; |
1975 | case UE_BULK: | | 1975 | case UE_BULK: |
1976 | pipe->up_methods = &ehci_device_bulk_methods; | | 1976 | pipe->up_methods = &ehci_device_bulk_methods; |
1977 | mutex_enter(&sc->sc_lock); | | 1977 | mutex_enter(&sc->sc_lock); |
1978 | ehci_add_qh(sc, sqh, sc->sc_async_head); | | 1978 | ehci_add_qh(sc, sqh, sc->sc_async_head); |
1979 | mutex_exit(&sc->sc_lock); | | 1979 | mutex_exit(&sc->sc_lock); |
1980 | break; | | 1980 | break; |
1981 | case UE_INTERRUPT: | | 1981 | case UE_INTERRUPT: |
1982 | pipe->up_methods = &ehci_device_intr_methods; | | 1982 | pipe->up_methods = &ehci_device_intr_methods; |
1983 | ival = pipe->up_interval; | | 1983 | ival = pipe->up_interval; |
1984 | if (ival == USBD_DEFAULT_INTERVAL) { | | 1984 | if (ival == USBD_DEFAULT_INTERVAL) { |
1985 | if (speed == EHCI_QH_SPEED_HIGH) { | | 1985 | if (speed == EHCI_QH_SPEED_HIGH) { |
1986 | if (ed->bInterval > 16) { | | 1986 | if (ed->bInterval > 16) { |
1987 | /* | | 1987 | /* |
1988 | * illegal with high-speed, but there | | 1988 | * illegal with high-speed, but there |
1989 | * were documentation bugs in the spec, | | 1989 | * were documentation bugs in the spec, |
1990 | * so be generous | | 1990 | * so be generous |
1991 | */ | | 1991 | */ |
1992 | ival = 256; | | 1992 | ival = 256; |
1993 | } else | | 1993 | } else |
1994 | ival = (1 << (ed->bInterval - 1)) / 8; | | 1994 | ival = (1 << (ed->bInterval - 1)) / 8; |
1995 | } else | | 1995 | } else |
1996 | ival = ed->bInterval; | | 1996 | ival = ed->bInterval; |
1997 | } | | 1997 | } |
1998 | err = ehci_device_setintr(sc, sqh, ival); | | 1998 | err = ehci_device_setintr(sc, sqh, ival); |
1999 | if (err) | | 1999 | if (err) |
2000 | goto bad; | | 2000 | goto bad; |
2001 | break; | | 2001 | break; |
2002 | case UE_ISOCHRONOUS: | | 2002 | case UE_ISOCHRONOUS: |
2003 | if (speed == EHCI_QH_SPEED_HIGH) | | 2003 | if (speed == EHCI_QH_SPEED_HIGH) |
2004 | pipe->up_methods = &ehci_device_isoc_methods; | | 2004 | pipe->up_methods = &ehci_device_isoc_methods; |
2005 | else | | 2005 | else |
2006 | pipe->up_methods = &ehci_device_fs_isoc_methods; | | 2006 | pipe->up_methods = &ehci_device_fs_isoc_methods; |
2007 | if (ed->bInterval == 0 || ed->bInterval > 16) { | | 2007 | if (ed->bInterval == 0 || ed->bInterval > 16) { |
2008 | printf("ehci: opening pipe with invalid bInterval\n"); | | 2008 | printf("ehci: opening pipe with invalid bInterval\n"); |
2009 | err = USBD_INVAL; | | 2009 | err = USBD_INVAL; |
2010 | goto bad; | | 2010 | goto bad; |
2011 | } | | 2011 | } |
2012 | if (UGETW(ed->wMaxPacketSize) == 0) { | | 2012 | if (UGETW(ed->wMaxPacketSize) == 0) { |
2013 | printf("ehci: zero length endpoint open request\n"); | | 2013 | printf("ehci: zero length endpoint open request\n"); |
2014 | err = USBD_INVAL; | | 2014 | err = USBD_INVAL; |
2015 | goto bad; | | 2015 | goto bad; |
2016 | } | | 2016 | } |
2017 | epipe->u.isoc.next_frame = 0; | | 2017 | epipe->u.isoc.next_frame = 0; |
2018 | epipe->u.isoc.cur_xfers = 0; | | 2018 | epipe->u.isoc.cur_xfers = 0; |
2019 | break; | | 2019 | break; |
2020 | default: | | 2020 | default: |
2021 | USBHIST_LOG(ehcidebug, "bad xfer type %d", xfertype, 0, 0, 0); | | 2021 | USBHIST_LOG(ehcidebug, "bad xfer type %d", xfertype, 0, 0, 0); |
2022 | err = USBD_INVAL; | | 2022 | err = USBD_INVAL; |
2023 | goto bad; | | 2023 | goto bad; |
2024 | } | | 2024 | } |
2025 | return USBD_NORMAL_COMPLETION; | | 2025 | return USBD_NORMAL_COMPLETION; |
2026 | | | 2026 | |
2027 | bad: | | 2027 | bad: |
2028 | if (sqh != NULL) | | 2028 | if (sqh != NULL) |
2029 | ehci_free_sqh(sc, sqh); | | 2029 | ehci_free_sqh(sc, sqh); |
2030 | return err; | | 2030 | return err; |
2031 | } | | 2031 | } |
2032 | | | 2032 | |
2033 | /* | | 2033 | /* |
2034 | * Add an ED to the schedule. Called with USB lock held. | | 2034 | * Add an ED to the schedule. Called with USB lock held. |
2035 | */ | | 2035 | */ |
2036 | Static void | | 2036 | Static void |
2037 | ehci_add_qh(ehci_softc_t *sc, ehci_soft_qh_t *sqh, ehci_soft_qh_t *head) | | 2037 | ehci_add_qh(ehci_softc_t *sc, ehci_soft_qh_t *sqh, ehci_soft_qh_t *head) |
2038 | { | | 2038 | { |
2039 | | | 2039 | |
2040 | KASSERT(mutex_owned(&sc->sc_lock)); | | 2040 | KASSERT(mutex_owned(&sc->sc_lock)); |
2041 | | | 2041 | |
2042 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2042 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2043 | | | 2043 | |
2044 | usb_syncmem(&head->dma, head->offs + offsetof(ehci_qh_t, qh_link), | | 2044 | usb_syncmem(&head->dma, head->offs + offsetof(ehci_qh_t, qh_link), |
2045 | sizeof(head->qh.qh_link), BUS_DMASYNC_POSTWRITE); | | 2045 | sizeof(head->qh.qh_link), BUS_DMASYNC_POSTWRITE); |
2046 | | | 2046 | |
2047 | sqh->next = head->next; | | 2047 | sqh->next = head->next; |
2048 | sqh->qh.qh_link = head->qh.qh_link; | | 2048 | sqh->qh.qh_link = head->qh.qh_link; |
2049 | | | 2049 | |
2050 | usb_syncmem(&sqh->dma, sqh->offs + offsetof(ehci_qh_t, qh_link), | | 2050 | usb_syncmem(&sqh->dma, sqh->offs + offsetof(ehci_qh_t, qh_link), |
2051 | sizeof(sqh->qh.qh_link), BUS_DMASYNC_PREWRITE); | | 2051 | sizeof(sqh->qh.qh_link), BUS_DMASYNC_PREWRITE); |
2052 | | | 2052 | |
2053 | head->next = sqh; | | 2053 | head->next = sqh; |
2054 | head->qh.qh_link = htole32(sqh->physaddr | EHCI_LINK_QH); | | 2054 | head->qh.qh_link = htole32(sqh->physaddr | EHCI_LINK_QH); |
2055 | | | 2055 | |
2056 | usb_syncmem(&head->dma, head->offs + offsetof(ehci_qh_t, qh_link), | | 2056 | usb_syncmem(&head->dma, head->offs + offsetof(ehci_qh_t, qh_link), |
2057 | sizeof(head->qh.qh_link), BUS_DMASYNC_PREWRITE); | | 2057 | sizeof(head->qh.qh_link), BUS_DMASYNC_PREWRITE); |
2058 | | | 2058 | |
2059 | #ifdef EHCI_DEBUG | | 2059 | #ifdef EHCI_DEBUG |
2060 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); | | 2060 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); |
2061 | ehci_dump_sqh(sqh); | | 2061 | ehci_dump_sqh(sqh); |
2062 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); | | 2062 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); |
2063 | #endif | | 2063 | #endif |
2064 | } | | 2064 | } |
2065 | | | 2065 | |
2066 | /* | | 2066 | /* |
2067 | * Remove an ED from the schedule. Called with USB lock held. | | 2067 | * Remove an ED from the schedule. Called with USB lock held. |
2068 | */ | | 2068 | */ |
2069 | Static void | | 2069 | Static void |
2070 | ehci_rem_qh(ehci_softc_t *sc, ehci_soft_qh_t *sqh, ehci_soft_qh_t *head) | | 2070 | ehci_rem_qh(ehci_softc_t *sc, ehci_soft_qh_t *sqh, ehci_soft_qh_t *head) |
2071 | { | | 2071 | { |
2072 | ehci_soft_qh_t *p; | | 2072 | ehci_soft_qh_t *p; |
2073 | | | 2073 | |
2074 | KASSERT(mutex_owned(&sc->sc_lock)); | | 2074 | KASSERT(mutex_owned(&sc->sc_lock)); |
2075 | | | 2075 | |
2076 | /* XXX */ | | 2076 | /* XXX */ |
2077 | for (p = head; p != NULL && p->next != sqh; p = p->next) | | 2077 | for (p = head; p != NULL && p->next != sqh; p = p->next) |
2078 | ; | | 2078 | ; |
2079 | if (p == NULL) | | 2079 | if (p == NULL) |
2080 | panic("ehci_rem_qh: ED not found"); | | 2080 | panic("ehci_rem_qh: ED not found"); |
2081 | usb_syncmem(&sqh->dma, sqh->offs + offsetof(ehci_qh_t, qh_link), | | 2081 | usb_syncmem(&sqh->dma, sqh->offs + offsetof(ehci_qh_t, qh_link), |
2082 | sizeof(sqh->qh.qh_link), BUS_DMASYNC_POSTWRITE); | | 2082 | sizeof(sqh->qh.qh_link), BUS_DMASYNC_POSTWRITE); |
2083 | p->next = sqh->next; | | 2083 | p->next = sqh->next; |
2084 | p->qh.qh_link = sqh->qh.qh_link; | | 2084 | p->qh.qh_link = sqh->qh.qh_link; |
2085 | usb_syncmem(&p->dma, p->offs + offsetof(ehci_qh_t, qh_link), | | 2085 | usb_syncmem(&p->dma, p->offs + offsetof(ehci_qh_t, qh_link), |
2086 | sizeof(p->qh.qh_link), BUS_DMASYNC_PREWRITE); | | 2086 | sizeof(p->qh.qh_link), BUS_DMASYNC_PREWRITE); |
2087 | | | 2087 | |
2088 | ehci_sync_hc(sc); | | 2088 | ehci_sync_hc(sc); |
2089 | } | | 2089 | } |
2090 | | | 2090 | |
2091 | Static void | | 2091 | Static void |
2092 | ehci_set_qh_qtd(ehci_soft_qh_t *sqh, ehci_soft_qtd_t *sqtd) | | 2092 | ehci_set_qh_qtd(ehci_soft_qh_t *sqh, ehci_soft_qtd_t *sqtd) |
2093 | { | | 2093 | { |
2094 | int i; | | 2094 | int i; |
2095 | uint32_t status; | | 2095 | uint32_t status; |
2096 | | | 2096 | |
2097 | /* Save toggle bit and ping status. */ | | 2097 | /* Save toggle bit and ping status. */ |
2098 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), | | 2098 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), |
2099 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 2099 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
2100 | status = sqh->qh.qh_qtd.qtd_status & | | 2100 | status = sqh->qh.qh_qtd.qtd_status & |
2101 | htole32(EHCI_QTD_TOGGLE_MASK | | | 2101 | htole32(EHCI_QTD_TOGGLE_MASK | |
2102 | EHCI_QTD_SET_STATUS(EHCI_QTD_PINGSTATE)); | | 2102 | EHCI_QTD_SET_STATUS(EHCI_QTD_PINGSTATE)); |
2103 | /* Set HALTED to make hw leave it alone. */ | | 2103 | /* Set HALTED to make hw leave it alone. */ |
2104 | sqh->qh.qh_qtd.qtd_status = | | 2104 | sqh->qh.qh_qtd.qtd_status = |
2105 | htole32(EHCI_QTD_SET_STATUS(EHCI_QTD_HALTED)); | | 2105 | htole32(EHCI_QTD_SET_STATUS(EHCI_QTD_HALTED)); |
2106 | usb_syncmem(&sqh->dma, | | 2106 | usb_syncmem(&sqh->dma, |
2107 | sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), | | 2107 | sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), |
2108 | sizeof(sqh->qh.qh_qtd.qtd_status), | | 2108 | sizeof(sqh->qh.qh_qtd.qtd_status), |
2109 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2109 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2110 | sqh->qh.qh_curqtd = 0; | | 2110 | sqh->qh.qh_curqtd = 0; |
2111 | sqh->qh.qh_qtd.qtd_next = htole32(sqtd->physaddr); | | 2111 | sqh->qh.qh_qtd.qtd_next = htole32(sqtd->physaddr); |
2112 | sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL; | | 2112 | sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL; |
2113 | for (i = 0; i < EHCI_QTD_NBUFFERS; i++) | | 2113 | for (i = 0; i < EHCI_QTD_NBUFFERS; i++) |
2114 | sqh->qh.qh_qtd.qtd_buffer[i] = 0; | | 2114 | sqh->qh.qh_qtd.qtd_buffer[i] = 0; |
2115 | sqh->sqtd = sqtd; | | 2115 | sqh->sqtd = sqtd; |
2116 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), | | 2116 | usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), |
2117 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2117 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2118 | /* Set !HALTED && !ACTIVE to start execution, preserve some fields */ | | 2118 | /* Set !HALTED && !ACTIVE to start execution, preserve some fields */ |
2119 | sqh->qh.qh_qtd.qtd_status = status; | | 2119 | sqh->qh.qh_qtd.qtd_status = status; |
2120 | usb_syncmem(&sqh->dma, | | 2120 | usb_syncmem(&sqh->dma, |
2121 | sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), | | 2121 | sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), |
2122 | sizeof(sqh->qh.qh_qtd.qtd_status), | | 2122 | sizeof(sqh->qh.qh_qtd.qtd_status), |
2123 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2123 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2124 | } | | 2124 | } |
2125 | | | 2125 | |
2126 | /* | | 2126 | /* |
2127 | * Ensure that the HC has released all references to the QH. We do this | | 2127 | * Ensure that the HC has released all references to the QH. We do this |
2128 | * by asking for a Async Advance Doorbell interrupt and then we wait for | | 2128 | * by asking for a Async Advance Doorbell interrupt and then we wait for |
2129 | * the interrupt. | | 2129 | * the interrupt. |
2130 | * To make this easier we first obtain exclusive use of the doorbell. | | 2130 | * To make this easier we first obtain exclusive use of the doorbell. |
2131 | */ | | 2131 | */ |
2132 | Static void | | 2132 | Static void |
2133 | ehci_sync_hc(ehci_softc_t *sc) | | 2133 | ehci_sync_hc(ehci_softc_t *sc) |
2134 | { | | 2134 | { |
2135 | int error __diagused; | | 2135 | int error __diagused; |
2136 | | | 2136 | |
2137 | KASSERT(mutex_owned(&sc->sc_lock)); | | 2137 | KASSERT(mutex_owned(&sc->sc_lock)); |
2138 | | | 2138 | |
2139 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2139 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2140 | | | 2140 | |
2141 | if (sc->sc_dying) { | | 2141 | if (sc->sc_dying) { |
2142 | USBHIST_LOG(ehcidebug, "dying", 0, 0, 0, 0); | | 2142 | USBHIST_LOG(ehcidebug, "dying", 0, 0, 0, 0); |
2143 | return; | | 2143 | return; |
2144 | } | | 2144 | } |
2145 | /* ask for doorbell */ | | 2145 | /* ask for doorbell */ |
2146 | EOWRITE4(sc, EHCI_USBCMD, EOREAD4(sc, EHCI_USBCMD) | EHCI_CMD_IAAD); | | 2146 | EOWRITE4(sc, EHCI_USBCMD, EOREAD4(sc, EHCI_USBCMD) | EHCI_CMD_IAAD); |
2147 | USBHIST_LOG(ehcidebug, "cmd = 0x%08x sts = 0x%08x", | | 2147 | USBHIST_LOG(ehcidebug, "cmd = 0x%08x sts = 0x%08x", |
2148 | EOREAD4(sc, EHCI_USBCMD), EOREAD4(sc, EHCI_USBSTS), 0, 0); | | 2148 | EOREAD4(sc, EHCI_USBCMD), EOREAD4(sc, EHCI_USBSTS), 0, 0); |
2149 | | | 2149 | |
2150 | error = cv_timedwait(&sc->sc_doorbell, &sc->sc_lock, hz); /* bell wait */ | | 2150 | error = cv_timedwait(&sc->sc_doorbell, &sc->sc_lock, hz); /* bell wait */ |
2151 | | | 2151 | |
2152 | USBHIST_LOG(ehcidebug, "cmd = 0x%08x sts = 0x%08x", | | 2152 | USBHIST_LOG(ehcidebug, "cmd = 0x%08x sts = 0x%08x", |
2153 | EOREAD4(sc, EHCI_USBCMD), EOREAD4(sc, EHCI_USBSTS), 0, 0); | | 2153 | EOREAD4(sc, EHCI_USBCMD), EOREAD4(sc, EHCI_USBSTS), 0, 0); |
2154 | #ifdef DIAGNOSTIC | | 2154 | #ifdef DIAGNOSTIC |
2155 | if (error) | | 2155 | if (error) |
2156 | printf("ehci_sync_hc: cv_timedwait() = %d\n", error); | | 2156 | printf("ehci_sync_hc: cv_timedwait() = %d\n", error); |
2157 | #endif | | 2157 | #endif |
2158 | } | | 2158 | } |
2159 | | | 2159 | |
2160 | Static void | | 2160 | Static void |
2161 | ehci_rem_free_itd_chain(ehci_softc_t *sc, struct ehci_xfer *exfer) | | 2161 | ehci_rem_free_itd_chain(ehci_softc_t *sc, struct ehci_xfer *exfer) |
2162 | { | | 2162 | { |
2163 | struct ehci_soft_itd *itd, *prev; | | 2163 | struct ehci_soft_itd *itd, *prev; |
2164 | | | 2164 | |
2165 | prev = NULL; | | 2165 | prev = NULL; |
2166 | | | 2166 | |
2167 | if (exfer->ex_itdstart == NULL || exfer->ex_itdend == NULL) | | 2167 | if (exfer->ex_itdstart == NULL || exfer->ex_itdend == NULL) |
2168 | panic("ehci isoc xfer being freed, but with no itd chain\n"); | | 2168 | panic("ehci isoc xfer being freed, but with no itd chain\n"); |
2169 | | | 2169 | |
2170 | for (itd = exfer->ex_itdstart; itd != NULL; itd = itd->xfer_next) { | | 2170 | for (itd = exfer->ex_itdstart; itd != NULL; itd = itd->xfer_next) { |
2171 | prev = itd->u.frame_list.prev; | | 2171 | prev = itd->u.frame_list.prev; |
2172 | /* Unlink itd from hardware chain, or frame array */ | | 2172 | /* Unlink itd from hardware chain, or frame array */ |
2173 | if (prev == NULL) { /* We're at the table head */ | | 2173 | if (prev == NULL) { /* We're at the table head */ |
2174 | sc->sc_softitds[itd->slot] = itd->u.frame_list.next; | | 2174 | sc->sc_softitds[itd->slot] = itd->u.frame_list.next; |
2175 | sc->sc_flist[itd->slot] = itd->itd.itd_next; | | 2175 | sc->sc_flist[itd->slot] = itd->itd.itd_next; |
2176 | usb_syncmem(&sc->sc_fldma, | | 2176 | usb_syncmem(&sc->sc_fldma, |
2177 | sizeof(ehci_link_t) * itd->slot, | | 2177 | sizeof(ehci_link_t) * itd->slot, |
2178 | sizeof(ehci_link_t), | | 2178 | sizeof(ehci_link_t), |
2179 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2179 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2180 | | | 2180 | |
2181 | if (itd->u.frame_list.next != NULL) | | 2181 | if (itd->u.frame_list.next != NULL) |
2182 | itd->u.frame_list.next->u.frame_list.prev = NULL; | | 2182 | itd->u.frame_list.next->u.frame_list.prev = NULL; |
2183 | } else { | | 2183 | } else { |
2184 | /* XXX this part is untested... */ | | 2184 | /* XXX this part is untested... */ |
2185 | prev->itd.itd_next = itd->itd.itd_next; | | 2185 | prev->itd.itd_next = itd->itd.itd_next; |
2186 | usb_syncmem(&itd->dma, | | 2186 | usb_syncmem(&itd->dma, |
2187 | itd->offs + offsetof(ehci_itd_t, itd_next), | | 2187 | itd->offs + offsetof(ehci_itd_t, itd_next), |
2188 | sizeof(itd->itd.itd_next), BUS_DMASYNC_PREWRITE); | | 2188 | sizeof(itd->itd.itd_next), BUS_DMASYNC_PREWRITE); |
2189 | | | 2189 | |
2190 | prev->u.frame_list.next = itd->u.frame_list.next; | | 2190 | prev->u.frame_list.next = itd->u.frame_list.next; |
2191 | if (itd->u.frame_list.next != NULL) | | 2191 | if (itd->u.frame_list.next != NULL) |
2192 | itd->u.frame_list.next->u.frame_list.prev = prev; | | 2192 | itd->u.frame_list.next->u.frame_list.prev = prev; |
2193 | } | | 2193 | } |
2194 | } | | 2194 | } |
2195 | | | 2195 | |
2196 | prev = NULL; | | 2196 | prev = NULL; |
2197 | for (itd = exfer->ex_itdstart; itd != NULL; itd = itd->xfer_next) { | | 2197 | for (itd = exfer->ex_itdstart; itd != NULL; itd = itd->xfer_next) { |
2198 | if (prev != NULL) | | 2198 | if (prev != NULL) |
2199 | ehci_free_itd(sc, prev); | | 2199 | ehci_free_itd(sc, prev); |
2200 | prev = itd; | | 2200 | prev = itd; |
2201 | } | | 2201 | } |
2202 | if (prev) | | 2202 | if (prev) |
2203 | ehci_free_itd(sc, prev); | | 2203 | ehci_free_itd(sc, prev); |
2204 | exfer->ex_itdstart = NULL; | | 2204 | exfer->ex_itdstart = NULL; |
2205 | exfer->ex_itdend = NULL; | | 2205 | exfer->ex_itdend = NULL; |
2206 | } | | 2206 | } |
2207 | | | 2207 | |
2208 | Static void | | 2208 | Static void |
2209 | ehci_rem_free_sitd_chain(ehci_softc_t *sc, struct ehci_xfer *exfer) | | 2209 | ehci_rem_free_sitd_chain(ehci_softc_t *sc, struct ehci_xfer *exfer) |
2210 | { | | 2210 | { |
2211 | struct ehci_soft_sitd *sitd, *prev; | | 2211 | struct ehci_soft_sitd *sitd, *prev; |
2212 | | | 2212 | |
2213 | prev = NULL; | | 2213 | prev = NULL; |
2214 | | | 2214 | |
2215 | if (exfer->ex_sitdstart == NULL || exfer->ex_sitdend == NULL) | | 2215 | if (exfer->ex_sitdstart == NULL || exfer->ex_sitdend == NULL) |
2216 | panic("ehci isoc xfer being freed, but with no sitd chain\n"); | | 2216 | panic("ehci isoc xfer being freed, but with no sitd chain\n"); |
2217 | | | 2217 | |
2218 | for (sitd = exfer->ex_sitdstart; sitd != NULL; sitd = sitd->xfer_next) { | | 2218 | for (sitd = exfer->ex_sitdstart; sitd != NULL; sitd = sitd->xfer_next) { |
2219 | prev = sitd->u.frame_list.prev; | | 2219 | prev = sitd->u.frame_list.prev; |
2220 | /* Unlink sitd from hardware chain, or frame array */ | | 2220 | /* Unlink sitd from hardware chain, or frame array */ |
2221 | if (prev == NULL) { /* We're at the table head */ | | 2221 | if (prev == NULL) { /* We're at the table head */ |
2222 | sc->sc_softsitds[sitd->slot] = sitd->u.frame_list.next; | | 2222 | sc->sc_softsitds[sitd->slot] = sitd->u.frame_list.next; |
2223 | sc->sc_flist[sitd->slot] = sitd->sitd.sitd_next; | | 2223 | sc->sc_flist[sitd->slot] = sitd->sitd.sitd_next; |
2224 | usb_syncmem(&sc->sc_fldma, | | 2224 | usb_syncmem(&sc->sc_fldma, |
2225 | sizeof(ehci_link_t) * sitd->slot, | | 2225 | sizeof(ehci_link_t) * sitd->slot, |
2226 | sizeof(ehci_link_t), | | 2226 | sizeof(ehci_link_t), |
2227 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2227 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2228 | | | 2228 | |
2229 | if (sitd->u.frame_list.next != NULL) | | 2229 | if (sitd->u.frame_list.next != NULL) |
2230 | sitd->u.frame_list.next->u.frame_list.prev = NULL; | | 2230 | sitd->u.frame_list.next->u.frame_list.prev = NULL; |
2231 | } else { | | 2231 | } else { |
2232 | /* XXX this part is untested... */ | | 2232 | /* XXX this part is untested... */ |
2233 | prev->sitd.sitd_next = sitd->sitd.sitd_next; | | 2233 | prev->sitd.sitd_next = sitd->sitd.sitd_next; |
2234 | usb_syncmem(&sitd->dma, | | 2234 | usb_syncmem(&sitd->dma, |
2235 | sitd->offs + offsetof(ehci_sitd_t, sitd_next), | | 2235 | sitd->offs + offsetof(ehci_sitd_t, sitd_next), |
2236 | sizeof(sitd->sitd.sitd_next), BUS_DMASYNC_PREWRITE); | | 2236 | sizeof(sitd->sitd.sitd_next), BUS_DMASYNC_PREWRITE); |
2237 | | | 2237 | |
2238 | prev->u.frame_list.next = sitd->u.frame_list.next; | | 2238 | prev->u.frame_list.next = sitd->u.frame_list.next; |
2239 | if (sitd->u.frame_list.next != NULL) | | 2239 | if (sitd->u.frame_list.next != NULL) |
2240 | sitd->u.frame_list.next->u.frame_list.prev = prev; | | 2240 | sitd->u.frame_list.next->u.frame_list.prev = prev; |
2241 | } | | 2241 | } |
2242 | } | | 2242 | } |
2243 | | | 2243 | |
2244 | prev = NULL; | | 2244 | prev = NULL; |
2245 | for (sitd = exfer->ex_sitdstart; sitd != NULL; sitd = sitd->xfer_next) { | | 2245 | for (sitd = exfer->ex_sitdstart; sitd != NULL; sitd = sitd->xfer_next) { |
2246 | if (prev != NULL) | | 2246 | if (prev != NULL) |
2247 | ehci_free_sitd(sc, prev); | | 2247 | ehci_free_sitd(sc, prev); |
2248 | prev = sitd; | | 2248 | prev = sitd; |
2249 | } | | 2249 | } |
2250 | if (prev) | | 2250 | if (prev) |
2251 | ehci_free_sitd(sc, prev); | | 2251 | ehci_free_sitd(sc, prev); |
2252 | exfer->ex_sitdstart = NULL; | | 2252 | exfer->ex_sitdstart = NULL; |
2253 | exfer->ex_sitdend = NULL; | | 2253 | exfer->ex_sitdend = NULL; |
2254 | } | | 2254 | } |
2255 | | | 2255 | |
2256 | /***********/ | | 2256 | /***********/ |
2257 | | | 2257 | |
2258 | Static int | | 2258 | Static int |
2259 | ehci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req, | | 2259 | ehci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req, |
2260 | void *buf, int buflen) | | 2260 | void *buf, int buflen) |
2261 | { | | 2261 | { |
2262 | ehci_softc_t *sc = bus->ub_hcpriv; | | 2262 | ehci_softc_t *sc = bus->ub_hcpriv; |
2263 | usb_hub_descriptor_t hubd; | | 2263 | usb_hub_descriptor_t hubd; |
2264 | usb_port_status_t ps; | | 2264 | usb_port_status_t ps; |
2265 | uint16_t len, value, index; | | 2265 | uint16_t len, value, index; |
2266 | int l, totlen = 0; | | 2266 | int l, totlen = 0; |
2267 | int port, i; | | 2267 | int port, i; |
2268 | uint32_t v; | | 2268 | uint32_t v; |
2269 | | | 2269 | |
2270 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2270 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2271 | | | 2271 | |
2272 | if (sc->sc_dying) | | 2272 | if (sc->sc_dying) |
2273 | return -1; | | 2273 | return -1; |
2274 | | | 2274 | |
2275 | USBHIST_LOG(ehcidebug, "type=0x%02x request=%02x", | | 2275 | USBHIST_LOG(ehcidebug, "type=0x%02x request=%02x", |
2276 | req->bmRequestType, req->bRequest, 0, 0); | | 2276 | req->bmRequestType, req->bRequest, 0, 0); |
2277 | | | 2277 | |
2278 | len = UGETW(req->wLength); | | 2278 | len = UGETW(req->wLength); |
2279 | value = UGETW(req->wValue); | | 2279 | value = UGETW(req->wValue); |
2280 | index = UGETW(req->wIndex); | | 2280 | index = UGETW(req->wIndex); |
2281 | | | 2281 | |
2282 | #define C(x,y) ((x) | ((y) << 8)) | | 2282 | #define C(x,y) ((x) | ((y) << 8)) |
2283 | switch (C(req->bRequest, req->bmRequestType)) { | | 2283 | switch (C(req->bRequest, req->bmRequestType)) { |
2284 | case C(UR_GET_DESCRIPTOR, UT_READ_DEVICE): | | 2284 | case C(UR_GET_DESCRIPTOR, UT_READ_DEVICE): |
2285 | if (len == 0) | | 2285 | if (len == 0) |
2286 | break; | | 2286 | break; |
2287 | switch (value) { | | 2287 | switch (value) { |
2288 | case C(0, UDESC_DEVICE): { | | 2288 | case C(0, UDESC_DEVICE): { |
2289 | usb_device_descriptor_t devd; | | 2289 | usb_device_descriptor_t devd; |
2290 | totlen = min(buflen, sizeof(devd)); | | 2290 | totlen = min(buflen, sizeof(devd)); |
2291 | memcpy(&devd, buf, totlen); | | 2291 | memcpy(&devd, buf, totlen); |
2292 | USETW(devd.idVendor, sc->sc_id_vendor); | | 2292 | USETW(devd.idVendor, sc->sc_id_vendor); |
2293 | memcpy(buf, &devd, totlen); | | 2293 | memcpy(buf, &devd, totlen); |
2294 | break; | | 2294 | break; |
2295 | | | 2295 | |
2296 | } | | 2296 | } |
2297 | #define sd ((usb_string_descriptor_t *)buf) | | 2297 | #define sd ((usb_string_descriptor_t *)buf) |
2298 | case C(1, UDESC_STRING): | | 2298 | case C(1, UDESC_STRING): |
2299 | /* Vendor */ | | 2299 | /* Vendor */ |
2300 | totlen = usb_makestrdesc(sd, len, sc->sc_vendor); | | 2300 | totlen = usb_makestrdesc(sd, len, sc->sc_vendor); |
2301 | break; | | 2301 | break; |
2302 | case C(2, UDESC_STRING): | | 2302 | case C(2, UDESC_STRING): |
2303 | /* Product */ | | 2303 | /* Product */ |
2304 | totlen = usb_makestrdesc(sd, len, "EHCI root hub"); | | 2304 | totlen = usb_makestrdesc(sd, len, "EHCI root hub"); |
2305 | break; | | 2305 | break; |
2306 | #undef sd | | 2306 | #undef sd |
2307 | default: | | 2307 | default: |
2308 | /* default from usbroothub */ | | 2308 | /* default from usbroothub */ |
2309 | return buflen; | | 2309 | return buflen; |
2310 | } | | 2310 | } |
2311 | break; | | 2311 | break; |
2312 | | | 2312 | |
2313 | /* Hub requests */ | | 2313 | /* Hub requests */ |
2314 | case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_DEVICE): | | 2314 | case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_DEVICE): |
2315 | break; | | 2315 | break; |
2316 | case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_OTHER): | | 2316 | case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_OTHER): |
2317 | USBHIST_LOG(ehcidebug, | | 2317 | USBHIST_LOG(ehcidebug, |
2318 | "UR_CLEAR_PORT_FEATURE port=%d feature=%d", index, value, | | 2318 | "UR_CLEAR_PORT_FEATURE port=%d feature=%d", index, value, |
2319 | 0, 0); | | 2319 | 0, 0); |
2320 | if (index < 1 || index > sc->sc_noport) { | | 2320 | if (index < 1 || index > sc->sc_noport) { |
2321 | return -1; | | 2321 | return -1; |
2322 | } | | 2322 | } |
2323 | port = EHCI_PORTSC(index); | | 2323 | port = EHCI_PORTSC(index); |
2324 | v = EOREAD4(sc, port); | | 2324 | v = EOREAD4(sc, port); |
2325 | USBHIST_LOG(ehcidebug, "portsc=0x%08x", v, 0, 0, 0); | | 2325 | USBHIST_LOG(ehcidebug, "portsc=0x%08x", v, 0, 0, 0); |
2326 | v &= ~EHCI_PS_CLEAR; | | 2326 | v &= ~EHCI_PS_CLEAR; |
2327 | switch (value) { | | 2327 | switch (value) { |
2328 | case UHF_PORT_ENABLE: | | 2328 | case UHF_PORT_ENABLE: |
2329 | EOWRITE4(sc, port, v &~ EHCI_PS_PE); | | 2329 | EOWRITE4(sc, port, v &~ EHCI_PS_PE); |
2330 | break; | | 2330 | break; |
2331 | case UHF_PORT_SUSPEND: | | 2331 | case UHF_PORT_SUSPEND: |
2332 | if (!(v & EHCI_PS_SUSP)) /* not suspended */ | | 2332 | if (!(v & EHCI_PS_SUSP)) /* not suspended */ |
2333 | break; | | 2333 | break; |
2334 | v &= ~EHCI_PS_SUSP; | | 2334 | v &= ~EHCI_PS_SUSP; |
2335 | EOWRITE4(sc, port, v | EHCI_PS_FPR); | | 2335 | EOWRITE4(sc, port, v | EHCI_PS_FPR); |
2336 | /* see USB2 spec ch. 7.1.7.7 */ | | 2336 | /* see USB2 spec ch. 7.1.7.7 */ |
2337 | usb_delay_ms(&sc->sc_bus, 20); | | 2337 | usb_delay_ms(&sc->sc_bus, 20); |
2338 | EOWRITE4(sc, port, v); | | 2338 | EOWRITE4(sc, port, v); |
2339 | usb_delay_ms(&sc->sc_bus, 2); | | 2339 | usb_delay_ms(&sc->sc_bus, 2); |
2340 | #ifdef DEBUG | | 2340 | #ifdef DEBUG |
2341 | v = EOREAD4(sc, port); | | 2341 | v = EOREAD4(sc, port); |
2342 | if (v & (EHCI_PS_FPR | EHCI_PS_SUSP)) | | 2342 | if (v & (EHCI_PS_FPR | EHCI_PS_SUSP)) |
2343 | printf("ehci: resume failed: %x\n", v); | | 2343 | printf("ehci: resume failed: %x\n", v); |
2344 | #endif | | 2344 | #endif |
2345 | break; | | 2345 | break; |
2346 | case UHF_PORT_POWER: | | 2346 | case UHF_PORT_POWER: |
2347 | if (sc->sc_hasppc) | | 2347 | if (sc->sc_hasppc) |
2348 | EOWRITE4(sc, port, v &~ EHCI_PS_PP); | | 2348 | EOWRITE4(sc, port, v &~ EHCI_PS_PP); |
2349 | break; | | 2349 | break; |
2350 | case UHF_PORT_TEST: | | 2350 | case UHF_PORT_TEST: |
2351 | USBHIST_LOG(ehcidebug, "clear port test " | | 2351 | USBHIST_LOG(ehcidebug, "clear port test " |
2352 | "%d", index, 0, 0, 0); | | 2352 | "%d", index, 0, 0, 0); |
2353 | break; | | 2353 | break; |
2354 | case UHF_PORT_INDICATOR: | | 2354 | case UHF_PORT_INDICATOR: |
2355 | USBHIST_LOG(ehcidebug, "clear port ind " | | 2355 | USBHIST_LOG(ehcidebug, "clear port ind " |
2356 | "%d", index, 0, 0, 0); | | 2356 | "%d", index, 0, 0, 0); |
2357 | EOWRITE4(sc, port, v &~ EHCI_PS_PIC); | | 2357 | EOWRITE4(sc, port, v &~ EHCI_PS_PIC); |
2358 | break; | | 2358 | break; |
2359 | case UHF_C_PORT_CONNECTION: | | 2359 | case UHF_C_PORT_CONNECTION: |
2360 | EOWRITE4(sc, port, v | EHCI_PS_CSC); | | 2360 | EOWRITE4(sc, port, v | EHCI_PS_CSC); |
2361 | break; | | 2361 | break; |
2362 | case UHF_C_PORT_ENABLE: | | 2362 | case UHF_C_PORT_ENABLE: |
2363 | EOWRITE4(sc, port, v | EHCI_PS_PEC); | | 2363 | EOWRITE4(sc, port, v | EHCI_PS_PEC); |
2364 | break; | | 2364 | break; |
2365 | case UHF_C_PORT_SUSPEND: | | 2365 | case UHF_C_PORT_SUSPEND: |
2366 | /* how? */ | | 2366 | /* how? */ |
2367 | break; | | 2367 | break; |
2368 | case UHF_C_PORT_OVER_CURRENT: | | 2368 | case UHF_C_PORT_OVER_CURRENT: |
2369 | EOWRITE4(sc, port, v | EHCI_PS_OCC); | | 2369 | EOWRITE4(sc, port, v | EHCI_PS_OCC); |
2370 | break; | | 2370 | break; |
2371 | case UHF_C_PORT_RESET: | | 2371 | case UHF_C_PORT_RESET: |
2372 | sc->sc_isreset[index] = 0; | | 2372 | sc->sc_isreset[index] = 0; |
2373 | break; | | 2373 | break; |
2374 | default: | | 2374 | default: |
2375 | return -1; | | 2375 | return -1; |
2376 | } | | 2376 | } |
2377 | #if 0 | | 2377 | #if 0 |
2378 | switch(value) { | | 2378 | switch(value) { |
2379 | case UHF_C_PORT_CONNECTION: | | 2379 | case UHF_C_PORT_CONNECTION: |
2380 | case UHF_C_PORT_ENABLE: | | 2380 | case UHF_C_PORT_ENABLE: |
2381 | case UHF_C_PORT_SUSPEND: | | 2381 | case UHF_C_PORT_SUSPEND: |
2382 | case UHF_C_PORT_OVER_CURRENT: | | 2382 | case UHF_C_PORT_OVER_CURRENT: |
2383 | case UHF_C_PORT_RESET: | | 2383 | case UHF_C_PORT_RESET: |
2384 | default: | | 2384 | default: |
2385 | break; | | 2385 | break; |
2386 | } | | 2386 | } |
2387 | #endif | | 2387 | #endif |
2388 | break; | | 2388 | break; |
2389 | case C(UR_GET_DESCRIPTOR, UT_READ_CLASS_DEVICE): | | 2389 | case C(UR_GET_DESCRIPTOR, UT_READ_CLASS_DEVICE): |
2390 | if (len == 0) | | 2390 | if (len == 0) |
2391 | break; | | 2391 | break; |
2392 | if ((value & 0xff) != 0) { | | 2392 | if ((value & 0xff) != 0) { |
2393 | return -1; | | 2393 | return -1; |
2394 | } | | 2394 | } |
2395 | totlen = min(buflen, sizeof(hubd)); | | 2395 | totlen = min(buflen, sizeof(hubd)); |
2396 | memcpy(&hubd, buf, totlen); | | 2396 | memcpy(&hubd, buf, totlen); |
2397 | hubd.bNbrPorts = sc->sc_noport; | | 2397 | hubd.bNbrPorts = sc->sc_noport; |
2398 | v = EOREAD4(sc, EHCI_HCSPARAMS); | | 2398 | v = EOREAD4(sc, EHCI_HCSPARAMS); |
2399 | USETW(hubd.wHubCharacteristics, | | 2399 | USETW(hubd.wHubCharacteristics, |
2400 | EHCI_HCS_PPC(v) ? UHD_PWR_INDIVIDUAL : UHD_PWR_NO_SWITCH | | | 2400 | EHCI_HCS_PPC(v) ? UHD_PWR_INDIVIDUAL : UHD_PWR_NO_SWITCH | |
2401 | EHCI_HCS_P_INDICATOR(EREAD4(sc, EHCI_HCSPARAMS)) | | 2401 | EHCI_HCS_P_INDICATOR(EREAD4(sc, EHCI_HCSPARAMS)) |
2402 | ? UHD_PORT_IND : 0); | | 2402 | ? UHD_PORT_IND : 0); |
2403 | hubd.bPwrOn2PwrGood = 200; /* XXX can't find out? */ | | 2403 | hubd.bPwrOn2PwrGood = 200; /* XXX can't find out? */ |
2404 | for (i = 0, l = sc->sc_noport; l > 0; i++, l -= 8, v >>= 8) | | 2404 | for (i = 0, l = sc->sc_noport; l > 0; i++, l -= 8, v >>= 8) |
2405 | hubd.DeviceRemovable[i++] = 0; /* XXX can't find out? */ | | 2405 | hubd.DeviceRemovable[i++] = 0; /* XXX can't find out? */ |
2406 | hubd.bDescLength = USB_HUB_DESCRIPTOR_SIZE + i; | | 2406 | hubd.bDescLength = USB_HUB_DESCRIPTOR_SIZE + i; |
2407 | totlen = min(totlen, hubd.bDescLength); | | 2407 | totlen = min(totlen, hubd.bDescLength); |
2408 | memcpy(buf, &hubd, totlen); | | 2408 | memcpy(buf, &hubd, totlen); |
2409 | break; | | 2409 | break; |
2410 | case C(UR_GET_STATUS, UT_READ_CLASS_DEVICE): | | 2410 | case C(UR_GET_STATUS, UT_READ_CLASS_DEVICE): |
2411 | if (len != 4) { | | 2411 | if (len != 4) { |
2412 | return -1; | | 2412 | return -1; |
2413 | } | | 2413 | } |
2414 | memset(buf, 0, len); /* ? XXX */ | | 2414 | memset(buf, 0, len); /* ? XXX */ |
2415 | totlen = len; | | 2415 | totlen = len; |
2416 | break; | | 2416 | break; |
2417 | case C(UR_GET_STATUS, UT_READ_CLASS_OTHER): | | 2417 | case C(UR_GET_STATUS, UT_READ_CLASS_OTHER): |
2418 | USBHIST_LOG(ehcidebug, "get port status i=%d", index, 0, 0, 0); | | 2418 | USBHIST_LOG(ehcidebug, "get port status i=%d", index, 0, 0, 0); |
2419 | if (index < 1 || index > sc->sc_noport) { | | 2419 | if (index < 1 || index > sc->sc_noport) { |
2420 | return -1; | | 2420 | return -1; |
2421 | } | | 2421 | } |
2422 | if (len != 4) { | | 2422 | if (len != 4) { |
2423 | return -1; | | 2423 | return -1; |
2424 | } | | 2424 | } |
2425 | v = EOREAD4(sc, EHCI_PORTSC(index)); | | 2425 | v = EOREAD4(sc, EHCI_PORTSC(index)); |
2426 | USBHIST_LOG(ehcidebug, "port status=0x%04x", v, 0, 0, 0); | | 2426 | USBHIST_LOG(ehcidebug, "port status=0x%04x", v, 0, 0, 0); |
2427 | | | 2427 | |
2428 | i = UPS_HIGH_SPEED; | | 2428 | i = UPS_HIGH_SPEED; |
2429 | if (sc->sc_flags & EHCIF_ETTF) { | | 2429 | if (sc->sc_flags & EHCIF_ETTF) { |
2430 | /* | | 2430 | /* |
2431 | * If we are doing embedded transaction translation, | | 2431 | * If we are doing embedded transaction translation, |
2432 | * then directly attached LS/FS devices are reset by | | 2432 | * then directly attached LS/FS devices are reset by |
2433 | * the EHCI controller itself. PSPD is encoded | | 2433 | * the EHCI controller itself. PSPD is encoded |
2434 | * the same way as in USBSTATUS. | | 2434 | * the same way as in USBSTATUS. |
2435 | */ | | 2435 | */ |
2436 | i = __SHIFTOUT(v, EHCI_PS_PSPD) * UPS_LOW_SPEED; | | 2436 | i = __SHIFTOUT(v, EHCI_PS_PSPD) * UPS_LOW_SPEED; |
2437 | } | | 2437 | } |
2438 | if (v & EHCI_PS_CS) i |= UPS_CURRENT_CONNECT_STATUS; | | 2438 | if (v & EHCI_PS_CS) i |= UPS_CURRENT_CONNECT_STATUS; |
2439 | if (v & EHCI_PS_PE) i |= UPS_PORT_ENABLED; | | 2439 | if (v & EHCI_PS_PE) i |= UPS_PORT_ENABLED; |
2440 | if (v & EHCI_PS_SUSP) i |= UPS_SUSPEND; | | 2440 | if (v & EHCI_PS_SUSP) i |= UPS_SUSPEND; |
2441 | if (v & EHCI_PS_OCA) i |= UPS_OVERCURRENT_INDICATOR; | | 2441 | if (v & EHCI_PS_OCA) i |= UPS_OVERCURRENT_INDICATOR; |
2442 | if (v & EHCI_PS_PR) i |= UPS_RESET; | | 2442 | if (v & EHCI_PS_PR) i |= UPS_RESET; |
2443 | if (v & EHCI_PS_PP) i |= UPS_PORT_POWER; | | 2443 | if (v & EHCI_PS_PP) i |= UPS_PORT_POWER; |
2444 | if (sc->sc_vendor_port_status) | | 2444 | if (sc->sc_vendor_port_status) |
2445 | i = sc->sc_vendor_port_status(sc, v, i); | | 2445 | i = sc->sc_vendor_port_status(sc, v, i); |
2446 | USETW(ps.wPortStatus, i); | | 2446 | USETW(ps.wPortStatus, i); |
2447 | i = 0; | | 2447 | i = 0; |
2448 | if (v & EHCI_PS_CSC) i |= UPS_C_CONNECT_STATUS; | | 2448 | if (v & EHCI_PS_CSC) i |= UPS_C_CONNECT_STATUS; |
2449 | if (v & EHCI_PS_PEC) i |= UPS_C_PORT_ENABLED; | | 2449 | if (v & EHCI_PS_PEC) i |= UPS_C_PORT_ENABLED; |
2450 | if (v & EHCI_PS_OCC) i |= UPS_C_OVERCURRENT_INDICATOR; | | 2450 | if (v & EHCI_PS_OCC) i |= UPS_C_OVERCURRENT_INDICATOR; |
2451 | if (sc->sc_isreset[index]) i |= UPS_C_PORT_RESET; | | 2451 | if (sc->sc_isreset[index]) i |= UPS_C_PORT_RESET; |
2452 | USETW(ps.wPortChange, i); | | 2452 | USETW(ps.wPortChange, i); |
2453 | totlen = min(len, sizeof(ps)); | | 2453 | totlen = min(len, sizeof(ps)); |
2454 | memcpy(buf, &ps, totlen); | | 2454 | memcpy(buf, &ps, totlen); |
2455 | break; | | 2455 | break; |
2456 | case C(UR_SET_DESCRIPTOR, UT_WRITE_CLASS_DEVICE): | | 2456 | case C(UR_SET_DESCRIPTOR, UT_WRITE_CLASS_DEVICE): |
2457 | return -1; | | 2457 | return -1; |
2458 | case C(UR_SET_FEATURE, UT_WRITE_CLASS_DEVICE): | | 2458 | case C(UR_SET_FEATURE, UT_WRITE_CLASS_DEVICE): |
2459 | break; | | 2459 | break; |
2460 | case C(UR_SET_FEATURE, UT_WRITE_CLASS_OTHER): | | 2460 | case C(UR_SET_FEATURE, UT_WRITE_CLASS_OTHER): |
2461 | if (index < 1 || index > sc->sc_noport) { | | 2461 | if (index < 1 || index > sc->sc_noport) { |
2462 | return -1; | | 2462 | return -1; |
2463 | } | | 2463 | } |
2464 | port = EHCI_PORTSC(index); | | 2464 | port = EHCI_PORTSC(index); |
2465 | v = EOREAD4(sc, port); | | 2465 | v = EOREAD4(sc, port); |
2466 | USBHIST_LOG(ehcidebug, "portsc=0x%08x", v, 0, 0, 0); | | 2466 | USBHIST_LOG(ehcidebug, "portsc=0x%08x", v, 0, 0, 0); |
2467 | v &= ~EHCI_PS_CLEAR; | | 2467 | v &= ~EHCI_PS_CLEAR; |
2468 | switch(value) { | | 2468 | switch(value) { |
2469 | case UHF_PORT_ENABLE: | | 2469 | case UHF_PORT_ENABLE: |
2470 | EOWRITE4(sc, port, v | EHCI_PS_PE); | | 2470 | EOWRITE4(sc, port, v | EHCI_PS_PE); |
2471 | break; | | 2471 | break; |
2472 | case UHF_PORT_SUSPEND: | | 2472 | case UHF_PORT_SUSPEND: |
2473 | EOWRITE4(sc, port, v | EHCI_PS_SUSP); | | 2473 | EOWRITE4(sc, port, v | EHCI_PS_SUSP); |
2474 | break; | | 2474 | break; |
2475 | case UHF_PORT_RESET: | | 2475 | case UHF_PORT_RESET: |
2476 | USBHIST_LOG(ehcidebug, "reset port %d", index, 0, 0, 0); | | 2476 | USBHIST_LOG(ehcidebug, "reset port %d", index, 0, 0, 0); |
2477 | if (EHCI_PS_IS_LOWSPEED(v) | | 2477 | if (EHCI_PS_IS_LOWSPEED(v) |
2478 | && sc->sc_ncomp > 0 | | 2478 | && sc->sc_ncomp > 0 |
2479 | && !(sc->sc_flags & EHCIF_ETTF)) { | | 2479 | && !(sc->sc_flags & EHCIF_ETTF)) { |
2480 | /* | | 2480 | /* |
2481 | * Low speed device on non-ETTF controller or | | 2481 | * Low speed device on non-ETTF controller or |
2482 | * unaccompanied controller, give up ownership. | | 2482 | * unaccompanied controller, give up ownership. |
2483 | */ | | 2483 | */ |
2484 | ehci_disown(sc, index, 1); | | 2484 | ehci_disown(sc, index, 1); |
2485 | break; | | 2485 | break; |
2486 | } | | 2486 | } |
2487 | /* Start reset sequence. */ | | 2487 | /* Start reset sequence. */ |
2488 | v &= ~ (EHCI_PS_PE | EHCI_PS_PR); | | 2488 | v &= ~ (EHCI_PS_PE | EHCI_PS_PR); |
2489 | EOWRITE4(sc, port, v | EHCI_PS_PR); | | 2489 | EOWRITE4(sc, port, v | EHCI_PS_PR); |
2490 | /* Wait for reset to complete. */ | | 2490 | /* Wait for reset to complete. */ |
2491 | usb_delay_ms(&sc->sc_bus, USB_PORT_ROOT_RESET_DELAY); | | 2491 | usb_delay_ms(&sc->sc_bus, USB_PORT_ROOT_RESET_DELAY); |
2492 | if (sc->sc_dying) { | | 2492 | if (sc->sc_dying) { |
2493 | return -1; | | 2493 | return -1; |
2494 | } | | 2494 | } |
2495 | /* | | 2495 | /* |
2496 | * An embedded transaction translator will automatically | | 2496 | * An embedded transaction translator will automatically |
2497 | * terminate the reset sequence so there's no need to | | 2497 | * terminate the reset sequence so there's no need to |
2498 | * it. | | 2498 | * it. |
2499 | */ | | 2499 | */ |
2500 | v = EOREAD4(sc, port); | | 2500 | v = EOREAD4(sc, port); |
2501 | if (v & EHCI_PS_PR) { | | 2501 | if (v & EHCI_PS_PR) { |
2502 | /* Terminate reset sequence. */ | | 2502 | /* Terminate reset sequence. */ |
2503 | EOWRITE4(sc, port, v & ~EHCI_PS_PR); | | 2503 | EOWRITE4(sc, port, v & ~EHCI_PS_PR); |
2504 | /* Wait for HC to complete reset. */ | | 2504 | /* Wait for HC to complete reset. */ |
2505 | usb_delay_ms(&sc->sc_bus, | | 2505 | usb_delay_ms(&sc->sc_bus, |
2506 | EHCI_PORT_RESET_COMPLETE); | | 2506 | EHCI_PORT_RESET_COMPLETE); |
2507 | if (sc->sc_dying) { | | 2507 | if (sc->sc_dying) { |
2508 | return -1; | | 2508 | return -1; |
2509 | } | | 2509 | } |
2510 | } | | 2510 | } |
2511 | | | 2511 | |
2512 | v = EOREAD4(sc, port); | | 2512 | v = EOREAD4(sc, port); |
2513 | USBHIST_LOG(ehcidebug, | | 2513 | USBHIST_LOG(ehcidebug, |
2514 | "ehci after reset, status=0x%08x", v, 0, 0, 0); | | 2514 | "ehci after reset, status=0x%08x", v, 0, 0, 0); |
2515 | if (v & EHCI_PS_PR) { | | 2515 | if (v & EHCI_PS_PR) { |
2516 | printf("%s: port reset timeout\n", | | 2516 | printf("%s: port reset timeout\n", |
2517 | device_xname(sc->sc_dev)); | | 2517 | device_xname(sc->sc_dev)); |
2518 | return USBD_TIMEOUT; | | 2518 | return USBD_TIMEOUT; |
2519 | } | | 2519 | } |
2520 | if (!(v & EHCI_PS_PE)) { | | 2520 | if (!(v & EHCI_PS_PE)) { |
2521 | /* Not a high speed device, give up ownership.*/ | | 2521 | /* Not a high speed device, give up ownership.*/ |
2522 | ehci_disown(sc, index, 0); | | 2522 | ehci_disown(sc, index, 0); |
2523 | break; | | 2523 | break; |
2524 | } | | 2524 | } |
2525 | sc->sc_isreset[index] = 1; | | 2525 | sc->sc_isreset[index] = 1; |
2526 | USBHIST_LOG(ehcidebug, | | 2526 | USBHIST_LOG(ehcidebug, |
2527 | "ehci port %d reset, status = 0x%08x", index, v, 0, | | 2527 | "ehci port %d reset, status = 0x%08x", index, v, 0, |
2528 | 0); | | 2528 | 0); |
2529 | break; | | 2529 | break; |
2530 | case UHF_PORT_POWER: | | 2530 | case UHF_PORT_POWER: |
2531 | USBHIST_LOG(ehcidebug, | | 2531 | USBHIST_LOG(ehcidebug, |
2532 | "set port power %d (has PPC = %d)", index, | | 2532 | "set port power %d (has PPC = %d)", index, |
2533 | sc->sc_hasppc, 0, 0); | | 2533 | sc->sc_hasppc, 0, 0); |
2534 | if (sc->sc_hasppc) | | 2534 | if (sc->sc_hasppc) |
2535 | EOWRITE4(sc, port, v | EHCI_PS_PP); | | 2535 | EOWRITE4(sc, port, v | EHCI_PS_PP); |
2536 | break; | | 2536 | break; |
2537 | case UHF_PORT_TEST: | | 2537 | case UHF_PORT_TEST: |
2538 | USBHIST_LOG(ehcidebug, "set port test %d", | | 2538 | USBHIST_LOG(ehcidebug, "set port test %d", |
2539 | index, 0, 0, 0); | | 2539 | index, 0, 0, 0); |
2540 | break; | | 2540 | break; |
2541 | case UHF_PORT_INDICATOR: | | 2541 | case UHF_PORT_INDICATOR: |
2542 | USBHIST_LOG(ehcidebug, "set port ind %d", | | 2542 | USBHIST_LOG(ehcidebug, "set port ind %d", |
2543 | index, 0, 0, 0); | | 2543 | index, 0, 0, 0); |
2544 | EOWRITE4(sc, port, v | EHCI_PS_PIC); | | 2544 | EOWRITE4(sc, port, v | EHCI_PS_PIC); |
2545 | break; | | 2545 | break; |
2546 | default: | | 2546 | default: |
2547 | return -1; | | 2547 | return -1; |
2548 | } | | 2548 | } |
2549 | break; | | 2549 | break; |
2550 | case C(UR_CLEAR_TT_BUFFER, UT_WRITE_CLASS_OTHER): | | 2550 | case C(UR_CLEAR_TT_BUFFER, UT_WRITE_CLASS_OTHER): |
2551 | case C(UR_RESET_TT, UT_WRITE_CLASS_OTHER): | | 2551 | case C(UR_RESET_TT, UT_WRITE_CLASS_OTHER): |
2552 | case C(UR_GET_TT_STATE, UT_READ_CLASS_OTHER): | | 2552 | case C(UR_GET_TT_STATE, UT_READ_CLASS_OTHER): |
2553 | case C(UR_STOP_TT, UT_WRITE_CLASS_OTHER): | | 2553 | case C(UR_STOP_TT, UT_WRITE_CLASS_OTHER): |
2554 | break; | | 2554 | break; |
2555 | default: | | 2555 | default: |
2556 | /* default from usbroothub */ | | 2556 | /* default from usbroothub */ |
2557 | USBHIST_LOG(ehcidebug, "returning %d (usbroothub default)", | | 2557 | USBHIST_LOG(ehcidebug, "returning %d (usbroothub default)", |
2558 | buflen, 0, 0, 0); | | 2558 | buflen, 0, 0, 0); |
2559 | | | 2559 | |
2560 | return buflen; | | 2560 | return buflen; |
2561 | } | | 2561 | } |
2562 | | | 2562 | |
2563 | USBHIST_LOG(ehcidebug, "returning %d", totlen, 0, 0, 0); | | 2563 | USBHIST_LOG(ehcidebug, "returning %d", totlen, 0, 0, 0); |
2564 | | | 2564 | |
2565 | return totlen; | | 2565 | return totlen; |
2566 | } | | 2566 | } |
2567 | | | 2567 | |
2568 | Static void | | 2568 | Static void |
2569 | ehci_disown(ehci_softc_t *sc, int index, int lowspeed) | | 2569 | ehci_disown(ehci_softc_t *sc, int index, int lowspeed) |
2570 | { | | 2570 | { |
2571 | int port; | | 2571 | int port; |
2572 | uint32_t v; | | 2572 | uint32_t v; |
2573 | | | 2573 | |
2574 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2574 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2575 | | | 2575 | |
2576 | USBHIST_LOG(ehcidebug, "index=%d lowspeed=%d", index, lowspeed, 0, 0); | | 2576 | USBHIST_LOG(ehcidebug, "index=%d lowspeed=%d", index, lowspeed, 0, 0); |
2577 | #ifdef DIAGNOSTIC | | 2577 | #ifdef DIAGNOSTIC |
2578 | if (sc->sc_npcomp != 0) { | | 2578 | if (sc->sc_npcomp != 0) { |
2579 | int i = (index-1) / sc->sc_npcomp; | | 2579 | int i = (index-1) / sc->sc_npcomp; |
2580 | if (i >= sc->sc_ncomp) | | 2580 | if (i >= sc->sc_ncomp) |
2581 | printf("%s: strange port\n", | | 2581 | printf("%s: strange port\n", |
2582 | device_xname(sc->sc_dev)); | | 2582 | device_xname(sc->sc_dev)); |
2583 | else | | 2583 | else |
2584 | printf("%s: handing over %s speed device on " | | 2584 | printf("%s: handing over %s speed device on " |
2585 | "port %d to %s\n", | | 2585 | "port %d to %s\n", |
2586 | device_xname(sc->sc_dev), | | 2586 | device_xname(sc->sc_dev), |
2587 | lowspeed ? "low" : "full", | | 2587 | lowspeed ? "low" : "full", |
2588 | index, device_xname(sc->sc_comps[i])); | | 2588 | index, device_xname(sc->sc_comps[i])); |
2589 | } else { | | 2589 | } else { |
2590 | printf("%s: npcomp == 0\n", device_xname(sc->sc_dev)); | | 2590 | printf("%s: npcomp == 0\n", device_xname(sc->sc_dev)); |
2591 | } | | 2591 | } |
2592 | #endif | | 2592 | #endif |
2593 | port = EHCI_PORTSC(index); | | 2593 | port = EHCI_PORTSC(index); |
2594 | v = EOREAD4(sc, port) &~ EHCI_PS_CLEAR; | | 2594 | v = EOREAD4(sc, port) &~ EHCI_PS_CLEAR; |
2595 | EOWRITE4(sc, port, v | EHCI_PS_PO); | | 2595 | EOWRITE4(sc, port, v | EHCI_PS_PO); |
2596 | } | | 2596 | } |
2597 | | | 2597 | |
2598 | Static usbd_status | | 2598 | Static usbd_status |
2599 | ehci_root_intr_transfer(usbd_xfer_handle xfer) | | 2599 | ehci_root_intr_transfer(usbd_xfer_handle xfer) |
2600 | { | | 2600 | { |
2601 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 2601 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
2602 | usbd_status err; | | 2602 | usbd_status err; |
2603 | | | 2603 | |
2604 | /* Insert last in queue. */ | | 2604 | /* Insert last in queue. */ |
2605 | mutex_enter(&sc->sc_lock); | | 2605 | mutex_enter(&sc->sc_lock); |
2606 | err = usb_insert_transfer(xfer); | | 2606 | err = usb_insert_transfer(xfer); |
2607 | mutex_exit(&sc->sc_lock); | | 2607 | mutex_exit(&sc->sc_lock); |
2608 | if (err) | | 2608 | if (err) |
2609 | return err; | | 2609 | return err; |
2610 | | | 2610 | |
2611 | /* Pipe isn't running, start first */ | | 2611 | /* Pipe isn't running, start first */ |
2612 | return ehci_root_intr_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); | | 2612 | return ehci_root_intr_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); |
2613 | } | | 2613 | } |
2614 | | | 2614 | |
2615 | Static usbd_status | | 2615 | Static usbd_status |
2616 | ehci_root_intr_start(usbd_xfer_handle xfer) | | 2616 | ehci_root_intr_start(usbd_xfer_handle xfer) |
2617 | { | | 2617 | { |
2618 | usbd_pipe_handle pipe = xfer->ux_pipe; | | 2618 | usbd_pipe_handle pipe = xfer->ux_pipe; |
2619 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; | | 2619 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; |
2620 | | | 2620 | |
2621 | if (sc->sc_dying) | | 2621 | if (sc->sc_dying) |
2622 | return USBD_IOERROR; | | 2622 | return USBD_IOERROR; |
2623 | | | 2623 | |
2624 | mutex_enter(&sc->sc_lock); | | 2624 | mutex_enter(&sc->sc_lock); |
2625 | sc->sc_intrxfer = xfer; | | 2625 | sc->sc_intrxfer = xfer; |
2626 | mutex_exit(&sc->sc_lock); | | 2626 | mutex_exit(&sc->sc_lock); |
2627 | | | 2627 | |
2628 | return USBD_IN_PROGRESS; | | 2628 | return USBD_IN_PROGRESS; |
2629 | } | | 2629 | } |
2630 | | | 2630 | |
2631 | /* Abort a root interrupt request. */ | | 2631 | /* Abort a root interrupt request. */ |
2632 | Static void | | 2632 | Static void |
2633 | ehci_root_intr_abort(usbd_xfer_handle xfer) | | 2633 | ehci_root_intr_abort(usbd_xfer_handle xfer) |
2634 | { | | 2634 | { |
2635 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 2635 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
2636 | | | 2636 | |
2637 | KASSERT(mutex_owned(&sc->sc_lock)); | | 2637 | KASSERT(mutex_owned(&sc->sc_lock)); |
2638 | KASSERT(xfer->ux_pipe->up_intrxfer == xfer); | | 2638 | KASSERT(xfer->ux_pipe->up_intrxfer == xfer); |
2639 | | | 2639 | |
2640 | sc->sc_intrxfer = NULL; | | 2640 | sc->sc_intrxfer = NULL; |
2641 | | | 2641 | |
2642 | xfer->ux_status = USBD_CANCELLED; | | 2642 | xfer->ux_status = USBD_CANCELLED; |
2643 | usb_transfer_complete(xfer); | | 2643 | usb_transfer_complete(xfer); |
2644 | } | | 2644 | } |
2645 | | | 2645 | |
2646 | /* Close the root pipe. */ | | 2646 | /* Close the root pipe. */ |
2647 | Static void | | 2647 | Static void |
2648 | ehci_root_intr_close(usbd_pipe_handle pipe) | | 2648 | ehci_root_intr_close(usbd_pipe_handle pipe) |
2649 | { | | 2649 | { |
2650 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; | | 2650 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; |
2651 | | | 2651 | |
2652 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2652 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2653 | | | 2653 | |
2654 | KASSERT(mutex_owned(&sc->sc_lock)); | | 2654 | KASSERT(mutex_owned(&sc->sc_lock)); |
2655 | | | 2655 | |
2656 | sc->sc_intrxfer = NULL; | | 2656 | sc->sc_intrxfer = NULL; |
2657 | } | | 2657 | } |
2658 | | | 2658 | |
2659 | Static void | | 2659 | Static void |
2660 | ehci_root_intr_done(usbd_xfer_handle xfer) | | 2660 | ehci_root_intr_done(usbd_xfer_handle xfer) |
2661 | { | | 2661 | { |
2662 | xfer->ux_hcpriv = NULL; | | 2662 | xfer->ux_hcpriv = NULL; |
2663 | } | | 2663 | } |
2664 | | | 2664 | |
2665 | /************************/ | | 2665 | /************************/ |
2666 | | | 2666 | |
2667 | Static ehci_soft_qh_t * | | 2667 | Static ehci_soft_qh_t * |
2668 | ehci_alloc_sqh(ehci_softc_t *sc) | | 2668 | ehci_alloc_sqh(ehci_softc_t *sc) |
2669 | { | | 2669 | { |
2670 | ehci_soft_qh_t *sqh; | | 2670 | ehci_soft_qh_t *sqh; |
2671 | usbd_status err; | | 2671 | usbd_status err; |
2672 | int i, offs; | | 2672 | int i, offs; |
2673 | usb_dma_t dma; | | 2673 | usb_dma_t dma; |
2674 | | | 2674 | |
2675 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2675 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2676 | | | 2676 | |
2677 | if (sc->sc_freeqhs == NULL) { | | 2677 | if (sc->sc_freeqhs == NULL) { |
2678 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); | | 2678 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); |
2679 | err = usb_allocmem(&sc->sc_bus, EHCI_SQH_SIZE * EHCI_SQH_CHUNK, | | 2679 | err = usb_allocmem(&sc->sc_bus, EHCI_SQH_SIZE * EHCI_SQH_CHUNK, |
2680 | EHCI_PAGE_SIZE, &dma); | | 2680 | EHCI_PAGE_SIZE, &dma); |
2681 | #ifdef EHCI_DEBUG | | 2681 | #ifdef EHCI_DEBUG |
2682 | if (err) | | 2682 | if (err) |
2683 | printf("ehci_alloc_sqh: usb_allocmem()=%d\n", err); | | 2683 | printf("ehci_alloc_sqh: usb_allocmem()=%d\n", err); |
2684 | #endif | | 2684 | #endif |
2685 | if (err) | | 2685 | if (err) |
2686 | return NULL; | | 2686 | return NULL; |
2687 | for (i = 0; i < EHCI_SQH_CHUNK; i++) { | | 2687 | for (i = 0; i < EHCI_SQH_CHUNK; i++) { |
2688 | offs = i * EHCI_SQH_SIZE; | | 2688 | offs = i * EHCI_SQH_SIZE; |
2689 | sqh = KERNADDR(&dma, offs); | | 2689 | sqh = KERNADDR(&dma, offs); |
2690 | sqh->physaddr = DMAADDR(&dma, offs); | | 2690 | sqh->physaddr = DMAADDR(&dma, offs); |
2691 | sqh->dma = dma; | | 2691 | sqh->dma = dma; |
2692 | sqh->offs = offs; | | 2692 | sqh->offs = offs; |
2693 | sqh->next = sc->sc_freeqhs; | | 2693 | sqh->next = sc->sc_freeqhs; |
2694 | sc->sc_freeqhs = sqh; | | 2694 | sc->sc_freeqhs = sqh; |
2695 | } | | 2695 | } |
2696 | } | | 2696 | } |
2697 | sqh = sc->sc_freeqhs; | | 2697 | sqh = sc->sc_freeqhs; |
2698 | sc->sc_freeqhs = sqh->next; | | 2698 | sc->sc_freeqhs = sqh->next; |
2699 | memset(&sqh->qh, 0, sizeof(ehci_qh_t)); | | 2699 | memset(&sqh->qh, 0, sizeof(ehci_qh_t)); |
2700 | sqh->next = NULL; | | 2700 | sqh->next = NULL; |
2701 | return sqh; | | 2701 | return sqh; |
2702 | } | | 2702 | } |
2703 | | | 2703 | |
2704 | Static void | | 2704 | Static void |
2705 | ehci_free_sqh(ehci_softc_t *sc, ehci_soft_qh_t *sqh) | | 2705 | ehci_free_sqh(ehci_softc_t *sc, ehci_soft_qh_t *sqh) |
2706 | { | | 2706 | { |
2707 | sqh->next = sc->sc_freeqhs; | | 2707 | sqh->next = sc->sc_freeqhs; |
2708 | sc->sc_freeqhs = sqh; | | 2708 | sc->sc_freeqhs = sqh; |
2709 | } | | 2709 | } |
2710 | | | 2710 | |
2711 | Static ehci_soft_qtd_t * | | 2711 | Static ehci_soft_qtd_t * |
2712 | ehci_alloc_sqtd(ehci_softc_t *sc) | | 2712 | ehci_alloc_sqtd(ehci_softc_t *sc) |
2713 | { | | 2713 | { |
2714 | ehci_soft_qtd_t *sqtd = NULL; | | 2714 | ehci_soft_qtd_t *sqtd = NULL; |
2715 | usbd_status err; | | 2715 | usbd_status err; |
2716 | int i, offs; | | 2716 | int i, offs; |
2717 | usb_dma_t dma; | | 2717 | usb_dma_t dma; |
2718 | | | 2718 | |
2719 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2719 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2720 | | | 2720 | |
2721 | if (sc->sc_freeqtds == NULL) { | | 2721 | if (sc->sc_freeqtds == NULL) { |
2722 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); | | 2722 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); |
2723 | | | 2723 | |
2724 | err = usb_allocmem(&sc->sc_bus, EHCI_SQTD_SIZE*EHCI_SQTD_CHUNK, | | 2724 | err = usb_allocmem(&sc->sc_bus, EHCI_SQTD_SIZE*EHCI_SQTD_CHUNK, |
2725 | EHCI_PAGE_SIZE, &dma); | | 2725 | EHCI_PAGE_SIZE, &dma); |
2726 | #ifdef EHCI_DEBUG | | 2726 | #ifdef EHCI_DEBUG |
2727 | if (err) | | 2727 | if (err) |
2728 | printf("ehci_alloc_sqtd: usb_allocmem()=%d\n", err); | | 2728 | printf("ehci_alloc_sqtd: usb_allocmem()=%d\n", err); |
2729 | #endif | | 2729 | #endif |
2730 | if (err) | | 2730 | if (err) |
2731 | goto done; | | 2731 | goto done; |
2732 | | | 2732 | |
2733 | for (i = 0; i < EHCI_SQTD_CHUNK; i++) { | | 2733 | for (i = 0; i < EHCI_SQTD_CHUNK; i++) { |
2734 | offs = i * EHCI_SQTD_SIZE; | | 2734 | offs = i * EHCI_SQTD_SIZE; |
2735 | sqtd = KERNADDR(&dma, offs); | | 2735 | sqtd = KERNADDR(&dma, offs); |
2736 | sqtd->physaddr = DMAADDR(&dma, offs); | | 2736 | sqtd->physaddr = DMAADDR(&dma, offs); |
2737 | sqtd->dma = dma; | | 2737 | sqtd->dma = dma; |
2738 | sqtd->offs = offs; | | 2738 | sqtd->offs = offs; |
2739 | | | 2739 | |
2740 | sqtd->nextqtd = sc->sc_freeqtds; | | 2740 | sqtd->nextqtd = sc->sc_freeqtds; |
2741 | sc->sc_freeqtds = sqtd; | | 2741 | sc->sc_freeqtds = sqtd; |
2742 | } | | 2742 | } |
2743 | } | | 2743 | } |
2744 | | | 2744 | |
2745 | sqtd = sc->sc_freeqtds; | | 2745 | sqtd = sc->sc_freeqtds; |
2746 | sc->sc_freeqtds = sqtd->nextqtd; | | 2746 | sc->sc_freeqtds = sqtd->nextqtd; |
2747 | memset(&sqtd->qtd, 0, sizeof(ehci_qtd_t)); | | 2747 | memset(&sqtd->qtd, 0, sizeof(ehci_qtd_t)); |
2748 | sqtd->nextqtd = NULL; | | 2748 | sqtd->nextqtd = NULL; |
2749 | sqtd->xfer = NULL; | | 2749 | sqtd->xfer = NULL; |
2750 | | | 2750 | |
2751 | done: | | 2751 | done: |
2752 | return sqtd; | | 2752 | return sqtd; |
2753 | } | | 2753 | } |
2754 | | | 2754 | |
2755 | Static void | | 2755 | Static void |
2756 | ehci_free_sqtd(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd) | | 2756 | ehci_free_sqtd(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd) |
2757 | { | | 2757 | { |
2758 | | | 2758 | |
2759 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); | | 2759 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); |
2760 | | | 2760 | |
2761 | sqtd->nextqtd = sc->sc_freeqtds; | | 2761 | sqtd->nextqtd = sc->sc_freeqtds; |
2762 | sc->sc_freeqtds = sqtd; | | 2762 | sc->sc_freeqtds = sqtd; |
2763 | } | | 2763 | } |
2764 | | | 2764 | |
2765 | Static usbd_status | | 2765 | Static usbd_status |
2766 | ehci_alloc_sqtd_chain(struct ehci_pipe *epipe, ehci_softc_t *sc, | | 2766 | ehci_alloc_sqtd_chain(struct ehci_pipe *epipe, ehci_softc_t *sc, |
2767 | int alen, int rd, usbd_xfer_handle xfer, | | 2767 | int alen, int rd, usbd_xfer_handle xfer, |
2768 | ehci_soft_qtd_t **sp, ehci_soft_qtd_t **ep) | | 2768 | ehci_soft_qtd_t **sp, ehci_soft_qtd_t **ep) |
2769 | { | | 2769 | { |
2770 | ehci_soft_qtd_t *next, *cur; | | 2770 | ehci_soft_qtd_t *next, *cur; |
2771 | ehci_physaddr_t nextphys; | | 2771 | ehci_physaddr_t nextphys; |
2772 | uint32_t qtdstatus; | | 2772 | uint32_t qtdstatus; |
2773 | int len, curlen, mps; | | 2773 | int len, curlen, mps; |
2774 | int i, tog; | | 2774 | int i, tog; |
2775 | int pages, pageoffs; | | 2775 | int pages, pageoffs; |
2776 | bus_size_t curoffs; | | 2776 | bus_size_t curoffs; |
2777 | vaddr_t va, va_offs; | | 2777 | vaddr_t va, va_offs; |
2778 | usb_dma_t *dma = &xfer->ux_dmabuf; | | 2778 | usb_dma_t *dma = &xfer->ux_dmabuf; |
2779 | uint16_t flags = xfer->ux_flags; | | 2779 | uint16_t flags = xfer->ux_flags; |
2780 | paddr_t a; | | 2780 | paddr_t a; |
2781 | | | 2781 | |
2782 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2782 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2783 | | | 2783 | |
2784 | USBHIST_LOG(ehcidebug, "start len=%d", alen, 0, 0, 0); | | 2784 | USBHIST_LOG(ehcidebug, "start len=%d", alen, 0, 0, 0); |
2785 | | | 2785 | |
2786 | len = alen; | | 2786 | len = alen; |
2787 | qtdstatus = EHCI_QTD_ACTIVE | | | 2787 | qtdstatus = EHCI_QTD_ACTIVE | |
2788 | EHCI_QTD_SET_PID(rd ? EHCI_QTD_PID_IN : EHCI_QTD_PID_OUT) | | | 2788 | EHCI_QTD_SET_PID(rd ? EHCI_QTD_PID_IN : EHCI_QTD_PID_OUT) | |
2789 | EHCI_QTD_SET_CERR(3) | | 2789 | EHCI_QTD_SET_CERR(3) |
2790 | /* IOC set below */ | | 2790 | /* IOC set below */ |
2791 | /* BYTES set below */ | | 2791 | /* BYTES set below */ |
2792 | ; | | 2792 | ; |
2793 | mps = UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize); | | 2793 | mps = UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize); |
2794 | tog = epipe->nexttoggle; | | 2794 | tog = epipe->nexttoggle; |
2795 | qtdstatus |= EHCI_QTD_SET_TOGGLE(tog); | | 2795 | qtdstatus |= EHCI_QTD_SET_TOGGLE(tog); |
2796 | | | 2796 | |
2797 | cur = ehci_alloc_sqtd(sc); | | 2797 | cur = ehci_alloc_sqtd(sc); |
2798 | *sp = cur; | | 2798 | *sp = cur; |
2799 | if (cur == NULL) | | 2799 | if (cur == NULL) |
2800 | goto nomem; | | 2800 | goto nomem; |
2801 | | | 2801 | |
2802 | usb_syncmem(dma, 0, alen, | | 2802 | usb_syncmem(dma, 0, alen, |
2803 | rd ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE); | | 2803 | rd ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE); |
2804 | curoffs = 0; | | 2804 | curoffs = 0; |
2805 | for (;;) { | | 2805 | for (;;) { |
2806 | /* The EHCI hardware can handle at most 5 pages. */ | | 2806 | /* The EHCI hardware can handle at most 5 pages. */ |
2807 | va_offs = (vaddr_t)KERNADDR(dma, curoffs); | | 2807 | va_offs = (vaddr_t)KERNADDR(dma, curoffs); |
2808 | va_offs = EHCI_PAGE_OFFSET(va_offs); | | 2808 | va_offs = EHCI_PAGE_OFFSET(va_offs); |
2809 | if (len-curoffs < EHCI_QTD_MAXTRANSFER - va_offs) { | | 2809 | if (len-curoffs < EHCI_QTD_MAXTRANSFER - va_offs) { |
2810 | /* we can handle it in this QTD */ | | 2810 | /* we can handle it in this QTD */ |
2811 | curlen = len - curoffs; | | 2811 | curlen = len - curoffs; |
2812 | } else { | | 2812 | } else { |
2813 | /* must use multiple TDs, fill as much as possible. */ | | 2813 | /* must use multiple TDs, fill as much as possible. */ |
2814 | curlen = EHCI_QTD_MAXTRANSFER - va_offs; | | 2814 | curlen = EHCI_QTD_MAXTRANSFER - va_offs; |
2815 | | | 2815 | |
2816 | /* the length must be a multiple of the max size */ | | 2816 | /* the length must be a multiple of the max size */ |
2817 | curlen -= curlen % mps; | | 2817 | curlen -= curlen % mps; |
2818 | USBHIST_LOG(ehcidebug, "multiple QTDs, " | | 2818 | USBHIST_LOG(ehcidebug, "multiple QTDs, " |
2819 | "curlen=%d", curlen, 0, 0, 0); | | 2819 | "curlen=%d", curlen, 0, 0, 0); |
2820 | KASSERT(curlen != 0); | | 2820 | KASSERT(curlen != 0); |
2821 | } | | 2821 | } |
2822 | USBHIST_LOG(ehcidebug, "len=%d curlen=%d curoffs=%zu", | | 2822 | USBHIST_LOG(ehcidebug, "len=%d curlen=%d curoffs=%zu", |
2823 | len, curlen, (size_t)curoffs, 0); | | 2823 | len, curlen, (size_t)curoffs, 0); |
2824 | | | 2824 | |
2825 | /* | | 2825 | /* |
2826 | * Allocate another transfer if there's more data left, | | 2826 | * Allocate another transfer if there's more data left, |
2827 | * or if force last short transfer flag is set and we're | | 2827 | * or if force last short transfer flag is set and we're |
2828 | * allocating a multiple of the max packet size. | | 2828 | * allocating a multiple of the max packet size. |
2829 | */ | | 2829 | */ |
2830 | | | 2830 | |
2831 | if (curoffs + curlen != len || | | 2831 | if (curoffs + curlen != len || |
2832 | ((curlen % mps) == 0 && !rd && curlen != 0 && | | 2832 | ((curlen % mps) == 0 && !rd && curlen != 0 && |
2833 | (flags & USBD_FORCE_SHORT_XFER))) { | | 2833 | (flags & USBD_FORCE_SHORT_XFER))) { |
2834 | next = ehci_alloc_sqtd(sc); | | 2834 | next = ehci_alloc_sqtd(sc); |
2835 | if (next == NULL) | | 2835 | if (next == NULL) |
2836 | goto nomem; | | 2836 | goto nomem; |
2837 | nextphys = htole32(next->physaddr); | | 2837 | nextphys = htole32(next->physaddr); |
2838 | } else { | | 2838 | } else { |
2839 | next = NULL; | | 2839 | next = NULL; |
2840 | nextphys = EHCI_NULL; | | 2840 | nextphys = EHCI_NULL; |
2841 | } | | 2841 | } |
2842 | | | 2842 | |
2843 | /* Find number of pages we'll be using, insert dma addresses */ | | 2843 | /* Find number of pages we'll be using, insert dma addresses */ |
2844 | pages = EHCI_PAGE(curlen + EHCI_PAGE_SIZE -1) >> 12; | | 2844 | pages = EHCI_PAGE(curlen + EHCI_PAGE_SIZE - 1) >> 12; |
2845 | KASSERT(pages <= EHCI_QTD_NBUFFERS); | | 2845 | KASSERT(pages <= EHCI_QTD_NBUFFERS); |
2846 | pageoffs = EHCI_PAGE(curoffs); | | 2846 | pageoffs = EHCI_PAGE(curoffs); |
2847 | for (i = 0; i < pages; i++) { | | 2847 | for (i = 0; i < pages; i++) { |
2848 | a = DMAADDR(dma, pageoffs + i * EHCI_PAGE_SIZE); | | 2848 | a = DMAADDR(dma, pageoffs + i * EHCI_PAGE_SIZE); |
2849 | cur->qtd.qtd_buffer[i] = htole32(a & 0xFFFFF000); | | 2849 | cur->qtd.qtd_buffer[i] = htole32(a & 0xFFFFF000); |
2850 | /* Cast up to avoid compiler warnings */ | | 2850 | /* Cast up to avoid compiler warnings */ |
2851 | cur->qtd.qtd_buffer_hi[i] = htole32((uint64_t)a >> 32); | | 2851 | cur->qtd.qtd_buffer_hi[i] = htole32((uint64_t)a >> 32); |
2852 | } | | 2852 | } |
2853 | | | 2853 | |
2854 | /* First buffer pointer requires a page offset to start at */ | | 2854 | /* First buffer pointer requires a page offset to start at */ |
2855 | va = (vaddr_t)KERNADDR(dma, curoffs); | | 2855 | va = (vaddr_t)KERNADDR(dma, curoffs); |
2856 | cur->qtd.qtd_buffer[0] |= htole32(EHCI_PAGE_OFFSET(va)); | | 2856 | cur->qtd.qtd_buffer[0] |= htole32(EHCI_PAGE_OFFSET(va)); |
2857 | | | 2857 | |
2858 | cur->nextqtd = next; | | 2858 | cur->nextqtd = next; |
2859 | cur->qtd.qtd_next = cur->qtd.qtd_altnext = nextphys; | | 2859 | cur->qtd.qtd_next = cur->qtd.qtd_altnext = nextphys; |
2860 | cur->qtd.qtd_status = | | 2860 | cur->qtd.qtd_status = |
2861 | htole32(qtdstatus | EHCI_QTD_SET_BYTES(curlen)); | | 2861 | htole32(qtdstatus | EHCI_QTD_SET_BYTES(curlen)); |
2862 | cur->xfer = xfer; | | 2862 | cur->xfer = xfer; |
2863 | cur->len = curlen; | | 2863 | cur->len = curlen; |
2864 | | | 2864 | |
2865 | USBHIST_LOG(ehcidebug, "cbp=0x%08zx end=0x%08zx", | | 2865 | USBHIST_LOG(ehcidebug, "cbp=0x%08zx end=0x%08zx", |
2866 | (size_t)curoffs, (size_t)(curoffs + curlen), 0, 0); | | 2866 | (size_t)curoffs, (size_t)(curoffs + curlen), 0, 0); |
2867 | | | 2867 | |
2868 | /* | | 2868 | /* |
2869 | * adjust the toggle based on the number of packets in this | | 2869 | * adjust the toggle based on the number of packets in this |
2870 | * qtd | | 2870 | * qtd |
2871 | */ | | 2871 | */ |
2872 | if (((curlen + mps - 1) / mps) & 1) { | | 2872 | if (((curlen + mps - 1) / mps) & 1) { |
2873 | tog ^= 1; | | 2873 | tog ^= 1; |
2874 | qtdstatus ^= EHCI_QTD_TOGGLE_MASK; | | 2874 | qtdstatus ^= EHCI_QTD_TOGGLE_MASK; |
2875 | } | | 2875 | } |
2876 | if (next == NULL) | | 2876 | if (next == NULL) |
2877 | break; | | 2877 | break; |
2878 | usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd), | | 2878 | usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd), |
2879 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2879 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2880 | USBHIST_LOG(ehcidebug, "extend chain", 0, 0, 0, 0); | | 2880 | USBHIST_LOG(ehcidebug, "extend chain", 0, 0, 0, 0); |
2881 | if (len) | | 2881 | if (len) |
2882 | curoffs += curlen; | | 2882 | curoffs += curlen; |
2883 | cur = next; | | 2883 | cur = next; |
2884 | } | | 2884 | } |
2885 | cur->qtd.qtd_status |= htole32(EHCI_QTD_IOC); | | 2885 | cur->qtd.qtd_status |= htole32(EHCI_QTD_IOC); |
2886 | usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd), | | 2886 | usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd), |
2887 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2887 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2888 | *ep = cur; | | 2888 | *ep = cur; |
2889 | epipe->nexttoggle = tog; | | 2889 | epipe->nexttoggle = tog; |
2890 | | | 2890 | |
2891 | USBHIST_LOG(ehcidebug, "return sqtd=%p sqtdend=%p", | | 2891 | USBHIST_LOG(ehcidebug, "return sqtd=%p sqtdend=%p", |
2892 | *sp, *ep, 0, 0); | | 2892 | *sp, *ep, 0, 0); |
2893 | | | 2893 | |
2894 | return USBD_NORMAL_COMPLETION; | | 2894 | return USBD_NORMAL_COMPLETION; |
2895 | | | 2895 | |
2896 | nomem: | | 2896 | nomem: |
2897 | /* XXX free chain */ | | 2897 | /* XXX free chain */ |
2898 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); | | 2898 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); |
2899 | return USBD_NOMEM; | | 2899 | return USBD_NOMEM; |
2900 | } | | 2900 | } |
2901 | | | 2901 | |
2902 | Static void | | 2902 | Static void |
2903 | ehci_free_sqtd_chain(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd, | | 2903 | ehci_free_sqtd_chain(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd, |
2904 | ehci_soft_qtd_t *sqtdend) | | 2904 | ehci_soft_qtd_t *sqtdend) |
2905 | { | | 2905 | { |
2906 | ehci_soft_qtd_t *p; | | 2906 | ehci_soft_qtd_t *p; |
2907 | int i; | | 2907 | int i; |
2908 | | | 2908 | |
2909 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2909 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2910 | | | 2910 | |
2911 | USBHIST_LOG(ehcidebug, "sqtd=%p sqtdend=%p", | | 2911 | USBHIST_LOG(ehcidebug, "sqtd=%p sqtdend=%p", |
2912 | sqtd, sqtdend, 0, 0); | | 2912 | sqtd, sqtdend, 0, 0); |
2913 | | | 2913 | |
2914 | for (i = 0; sqtd != sqtdend; sqtd = p, i++) { | | 2914 | for (i = 0; sqtd != sqtdend; sqtd = p, i++) { |
2915 | p = sqtd->nextqtd; | | 2915 | p = sqtd->nextqtd; |
2916 | ehci_free_sqtd(sc, sqtd); | | 2916 | ehci_free_sqtd(sc, sqtd); |
2917 | } | | 2917 | } |
2918 | } | | 2918 | } |
2919 | | | 2919 | |
2920 | Static ehci_soft_itd_t * | | 2920 | Static ehci_soft_itd_t * |
2921 | ehci_alloc_itd(ehci_softc_t *sc) | | 2921 | ehci_alloc_itd(ehci_softc_t *sc) |
2922 | { | | 2922 | { |
2923 | struct ehci_soft_itd *itd, *freeitd; | | 2923 | struct ehci_soft_itd *itd, *freeitd; |
2924 | usbd_status err; | | 2924 | usbd_status err; |
2925 | int i, offs, frindex, previndex; | | 2925 | int i, offs, frindex, previndex; |
2926 | usb_dma_t dma; | | 2926 | usb_dma_t dma; |
2927 | | | 2927 | |
2928 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2928 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
2929 | | | 2929 | |
2930 | mutex_enter(&sc->sc_lock); | | 2930 | mutex_enter(&sc->sc_lock); |
2931 | | | 2931 | |
2932 | /* | | 2932 | /* |
2933 | * Find an itd that wasn't freed this frame or last frame. This can | | 2933 | * Find an itd that wasn't freed this frame or last frame. This can |
2934 | * discard itds that were freed before frindex wrapped around | | 2934 | * discard itds that were freed before frindex wrapped around |
2935 | * XXX - can this lead to thrashing? Could fix by enabling wrap-around | | 2935 | * XXX - can this lead to thrashing? Could fix by enabling wrap-around |
2936 | * interrupt and fiddling with list when that happens | | 2936 | * interrupt and fiddling with list when that happens |
2937 | */ | | 2937 | */ |
2938 | frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3; | | 2938 | frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3; |
2939 | previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize; | | 2939 | previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize; |
2940 | | | 2940 | |
2941 | freeitd = NULL; | | 2941 | freeitd = NULL; |
2942 | LIST_FOREACH(itd, &sc->sc_freeitds, u.free_list) { | | 2942 | LIST_FOREACH(itd, &sc->sc_freeitds, u.free_list) { |
2943 | if (itd == NULL) | | 2943 | if (itd == NULL) |
2944 | break; | | 2944 | break; |
2945 | if (itd->slot != frindex && itd->slot != previndex) { | | 2945 | if (itd->slot != frindex && itd->slot != previndex) { |
2946 | freeitd = itd; | | 2946 | freeitd = itd; |
2947 | break; | | 2947 | break; |
2948 | } | | 2948 | } |
2949 | } | | 2949 | } |
2950 | | | 2950 | |
2951 | if (freeitd == NULL) { | | 2951 | if (freeitd == NULL) { |
2952 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); | | 2952 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); |
2953 | err = usb_allocmem(&sc->sc_bus, EHCI_ITD_SIZE * EHCI_ITD_CHUNK, | | 2953 | err = usb_allocmem(&sc->sc_bus, EHCI_ITD_SIZE * EHCI_ITD_CHUNK, |
2954 | EHCI_PAGE_SIZE, &dma); | | 2954 | EHCI_PAGE_SIZE, &dma); |
2955 | | | 2955 | |
2956 | if (err) { | | 2956 | if (err) { |
2957 | USBHIST_LOG(ehcidebug, | | 2957 | USBHIST_LOG(ehcidebug, |
2958 | "alloc returned %d", err, 0, 0, 0); | | 2958 | "alloc returned %d", err, 0, 0, 0); |
2959 | mutex_exit(&sc->sc_lock); | | 2959 | mutex_exit(&sc->sc_lock); |
2960 | return NULL; | | 2960 | return NULL; |
2961 | } | | 2961 | } |
2962 | | | 2962 | |
2963 | for (i = 0; i < EHCI_ITD_CHUNK; i++) { | | 2963 | for (i = 0; i < EHCI_ITD_CHUNK; i++) { |
2964 | offs = i * EHCI_ITD_SIZE; | | 2964 | offs = i * EHCI_ITD_SIZE; |
2965 | itd = KERNADDR(&dma, offs); | | 2965 | itd = KERNADDR(&dma, offs); |
2966 | itd->physaddr = DMAADDR(&dma, offs); | | 2966 | itd->physaddr = DMAADDR(&dma, offs); |
2967 | itd->dma = dma; | | 2967 | itd->dma = dma; |
2968 | itd->offs = offs; | | 2968 | itd->offs = offs; |
2969 | LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list); | | 2969 | LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list); |
2970 | } | | 2970 | } |
2971 | freeitd = LIST_FIRST(&sc->sc_freeitds); | | 2971 | freeitd = LIST_FIRST(&sc->sc_freeitds); |
2972 | } | | 2972 | } |
2973 | | | 2973 | |
2974 | itd = freeitd; | | 2974 | itd = freeitd; |
2975 | LIST_REMOVE(itd, u.free_list); | | 2975 | LIST_REMOVE(itd, u.free_list); |
2976 | memset(&itd->itd, 0, sizeof(ehci_itd_t)); | | 2976 | memset(&itd->itd, 0, sizeof(ehci_itd_t)); |
2977 | usb_syncmem(&itd->dma, itd->offs + offsetof(ehci_itd_t, itd_next), | | 2977 | usb_syncmem(&itd->dma, itd->offs + offsetof(ehci_itd_t, itd_next), |
2978 | sizeof(itd->itd.itd_next), | | 2978 | sizeof(itd->itd.itd_next), |
2979 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 2979 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
2980 | | | 2980 | |
2981 | itd->u.frame_list.next = NULL; | | 2981 | itd->u.frame_list.next = NULL; |
2982 | itd->u.frame_list.prev = NULL; | | 2982 | itd->u.frame_list.prev = NULL; |
2983 | itd->xfer_next = NULL; | | 2983 | itd->xfer_next = NULL; |
2984 | itd->slot = 0; | | 2984 | itd->slot = 0; |
2985 | | | 2985 | |
2986 | mutex_exit(&sc->sc_lock); | | 2986 | mutex_exit(&sc->sc_lock); |
2987 | | | 2987 | |
2988 | return itd; | | 2988 | return itd; |
2989 | } | | 2989 | } |
2990 | | | 2990 | |
2991 | Static ehci_soft_sitd_t * | | 2991 | Static ehci_soft_sitd_t * |
2992 | ehci_alloc_sitd(ehci_softc_t *sc) | | 2992 | ehci_alloc_sitd(ehci_softc_t *sc) |
2993 | { | | 2993 | { |
2994 | struct ehci_soft_sitd *sitd, *freesitd; | | 2994 | struct ehci_soft_sitd *sitd, *freesitd; |
2995 | usbd_status err; | | 2995 | usbd_status err; |
2996 | int i, offs, frindex, previndex; | | 2996 | int i, offs, frindex, previndex; |
2997 | usb_dma_t dma; | | 2997 | usb_dma_t dma; |
2998 | | | 2998 | |
2999 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 2999 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3000 | | | 3000 | |
3001 | mutex_enter(&sc->sc_lock); | | 3001 | mutex_enter(&sc->sc_lock); |
3002 | | | 3002 | |
3003 | /* | | 3003 | /* |
3004 | * Find an sitd that wasn't freed this frame or last frame. This can | | 3004 | * Find an sitd that wasn't freed this frame or last frame. This can |
3005 | * discard sitds that were freed before frindex wrapped around | | 3005 | * discard sitds that were freed before frindex wrapped around |
3006 | * XXX - can this lead to thrashing? Could fix by enabling wrap-around | | 3006 | * XXX - can this lead to thrashing? Could fix by enabling wrap-around |
3007 | * interrupt and fiddling with list when that happens | | 3007 | * interrupt and fiddling with list when that happens |
3008 | */ | | 3008 | */ |
3009 | frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3; | | 3009 | frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3; |
3010 | previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize; | | 3010 | previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize; |
3011 | | | 3011 | |
3012 | freesitd = NULL; | | 3012 | freesitd = NULL; |
3013 | LIST_FOREACH(sitd, &sc->sc_freesitds, u.free_list) { | | 3013 | LIST_FOREACH(sitd, &sc->sc_freesitds, u.free_list) { |
3014 | if (sitd == NULL) | | 3014 | if (sitd == NULL) |
3015 | break; | | 3015 | break; |
3016 | if (sitd->slot != frindex && sitd->slot != previndex) { | | 3016 | if (sitd->slot != frindex && sitd->slot != previndex) { |
3017 | freesitd = sitd; | | 3017 | freesitd = sitd; |
3018 | break; | | 3018 | break; |
3019 | } | | 3019 | } |
3020 | } | | 3020 | } |
3021 | | | 3021 | |
3022 | if (freesitd == NULL) { | | 3022 | if (freesitd == NULL) { |
3023 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); | | 3023 | USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); |
3024 | err = usb_allocmem(&sc->sc_bus, EHCI_SITD_SIZE * EHCI_SITD_CHUNK, | | 3024 | err = usb_allocmem(&sc->sc_bus, EHCI_SITD_SIZE * EHCI_SITD_CHUNK, |
3025 | EHCI_PAGE_SIZE, &dma); | | 3025 | EHCI_PAGE_SIZE, &dma); |
3026 | | | 3026 | |
3027 | if (err) { | | 3027 | if (err) { |
3028 | USBHIST_LOG(ehcidebug, | | 3028 | USBHIST_LOG(ehcidebug, |
3029 | "alloc returned %d", err, 0, 0, 0); | | 3029 | "alloc returned %d", err, 0, 0, 0); |
3030 | mutex_exit(&sc->sc_lock); | | 3030 | mutex_exit(&sc->sc_lock); |
3031 | return NULL; | | 3031 | return NULL; |
3032 | } | | 3032 | } |
3033 | | | 3033 | |
3034 | for (i = 0; i < EHCI_SITD_CHUNK; i++) { | | 3034 | for (i = 0; i < EHCI_SITD_CHUNK; i++) { |
3035 | offs = i * EHCI_SITD_SIZE; | | 3035 | offs = i * EHCI_SITD_SIZE; |
3036 | sitd = KERNADDR(&dma, offs); | | 3036 | sitd = KERNADDR(&dma, offs); |
3037 | sitd->physaddr = DMAADDR(&dma, offs); | | 3037 | sitd->physaddr = DMAADDR(&dma, offs); |
3038 | sitd->dma = dma; | | 3038 | sitd->dma = dma; |
3039 | sitd->offs = offs; | | 3039 | sitd->offs = offs; |
3040 | LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list); | | 3040 | LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list); |
3041 | } | | 3041 | } |
3042 | freesitd = LIST_FIRST(&sc->sc_freesitds); | | 3042 | freesitd = LIST_FIRST(&sc->sc_freesitds); |
3043 | } | | 3043 | } |
3044 | | | 3044 | |
3045 | sitd = freesitd; | | 3045 | sitd = freesitd; |
3046 | LIST_REMOVE(sitd, u.free_list); | | 3046 | LIST_REMOVE(sitd, u.free_list); |
3047 | memset(&sitd->sitd, 0, sizeof(ehci_sitd_t)); | | 3047 | memset(&sitd->sitd, 0, sizeof(ehci_sitd_t)); |
3048 | usb_syncmem(&sitd->dma, sitd->offs + offsetof(ehci_sitd_t, sitd_next), | | 3048 | usb_syncmem(&sitd->dma, sitd->offs + offsetof(ehci_sitd_t, sitd_next), |
3049 | sizeof(sitd->sitd.sitd_next), BUS_DMASYNC_PREWRITE | | | 3049 | sizeof(sitd->sitd.sitd_next), BUS_DMASYNC_PREWRITE | |
3050 | BUS_DMASYNC_PREREAD); | | 3050 | BUS_DMASYNC_PREREAD); |
3051 | | | 3051 | |
3052 | sitd->u.frame_list.next = NULL; | | 3052 | sitd->u.frame_list.next = NULL; |
3053 | sitd->u.frame_list.prev = NULL; | | 3053 | sitd->u.frame_list.prev = NULL; |
3054 | sitd->xfer_next = NULL; | | 3054 | sitd->xfer_next = NULL; |
3055 | sitd->slot = 0; | | 3055 | sitd->slot = 0; |
3056 | | | 3056 | |
3057 | mutex_exit(&sc->sc_lock); | | 3057 | mutex_exit(&sc->sc_lock); |
3058 | | | 3058 | |
3059 | return sitd; | | 3059 | return sitd; |
3060 | } | | 3060 | } |
3061 | | | 3061 | |
3062 | Static void | | 3062 | Static void |
3063 | ehci_free_itd(ehci_softc_t *sc, ehci_soft_itd_t *itd) | | 3063 | ehci_free_itd(ehci_softc_t *sc, ehci_soft_itd_t *itd) |
3064 | { | | 3064 | { |
3065 | | | 3065 | |
3066 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3066 | KASSERT(mutex_owned(&sc->sc_lock)); |
3067 | | | 3067 | |
3068 | LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list); | | 3068 | LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list); |
3069 | } | | 3069 | } |
3070 | | | 3070 | |
3071 | Static void | | 3071 | Static void |
3072 | ehci_free_sitd(ehci_softc_t *sc, ehci_soft_sitd_t *sitd) | | 3072 | ehci_free_sitd(ehci_softc_t *sc, ehci_soft_sitd_t *sitd) |
3073 | { | | 3073 | { |
3074 | | | 3074 | |
3075 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3075 | KASSERT(mutex_owned(&sc->sc_lock)); |
3076 | | | 3076 | |
3077 | LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list); | | 3077 | LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list); |
3078 | } | | 3078 | } |
3079 | | | 3079 | |
3080 | /****************/ | | 3080 | /****************/ |
3081 | | | 3081 | |
3082 | /* | | 3082 | /* |
3083 | * Close a reqular pipe. | | 3083 | * Close a reqular pipe. |
3084 | * Assumes that there are no pending transactions. | | 3084 | * Assumes that there are no pending transactions. |
3085 | */ | | 3085 | */ |
3086 | Static void | | 3086 | Static void |
3087 | ehci_close_pipe(usbd_pipe_handle pipe, ehci_soft_qh_t *head) | | 3087 | ehci_close_pipe(usbd_pipe_handle pipe, ehci_soft_qh_t *head) |
3088 | { | | 3088 | { |
3089 | struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; | | 3089 | struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; |
3090 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; | | 3090 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; |
3091 | ehci_soft_qh_t *sqh = epipe->sqh; | | 3091 | ehci_soft_qh_t *sqh = epipe->sqh; |
3092 | | | 3092 | |
3093 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3093 | KASSERT(mutex_owned(&sc->sc_lock)); |
3094 | | | 3094 | |
3095 | ehci_rem_qh(sc, sqh, head); | | 3095 | ehci_rem_qh(sc, sqh, head); |
3096 | ehci_free_sqh(sc, epipe->sqh); | | 3096 | ehci_free_sqh(sc, epipe->sqh); |
3097 | } | | 3097 | } |
3098 | | | 3098 | |
3099 | /* | | 3099 | /* |
3100 | * Abort a device request. | | 3100 | * Abort a device request. |
3101 | * If this routine is called at splusb() it guarantees that the request | | 3101 | * If this routine is called at splusb() it guarantees that the request |
3102 | * will be removed from the hardware scheduling and that the callback | | 3102 | * will be removed from the hardware scheduling and that the callback |
3103 | * for it will be called with USBD_CANCELLED status. | | 3103 | * for it will be called with USBD_CANCELLED status. |
3104 | * It's impossible to guarantee that the requested transfer will not | | 3104 | * It's impossible to guarantee that the requested transfer will not |
3105 | * have happened since the hardware runs concurrently. | | 3105 | * have happened since the hardware runs concurrently. |
3106 | * If the transaction has already happened we rely on the ordinary | | 3106 | * If the transaction has already happened we rely on the ordinary |
3107 | * interrupt processing to process it. | | 3107 | * interrupt processing to process it. |
3108 | * XXX This is most probably wrong. | | 3108 | * XXX This is most probably wrong. |
3109 | * XXXMRG this doesn't make sense anymore. | | 3109 | * XXXMRG this doesn't make sense anymore. |
3110 | */ | | 3110 | */ |
3111 | Static void | | 3111 | Static void |
3112 | ehci_abort_xfer(usbd_xfer_handle xfer, usbd_status status) | | 3112 | ehci_abort_xfer(usbd_xfer_handle xfer, usbd_status status) |
3113 | { | | 3113 | { |
3114 | #define exfer EXFER(xfer) | | 3114 | #define exfer EXFER(xfer) |
3115 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; | | 3115 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; |
3116 | ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; | | 3116 | ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; |
3117 | ehci_soft_qh_t *sqh = epipe->sqh; | | 3117 | ehci_soft_qh_t *sqh = epipe->sqh; |
3118 | ehci_soft_qtd_t *sqtd; | | 3118 | ehci_soft_qtd_t *sqtd; |
3119 | ehci_physaddr_t cur; | | 3119 | ehci_physaddr_t cur; |
3120 | uint32_t qhstatus; | | 3120 | uint32_t qhstatus; |
3121 | int hit; | | 3121 | int hit; |
3122 | int wake; | | 3122 | int wake; |
3123 | | | 3123 | |
3124 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3124 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3125 | | | 3125 | |
3126 | USBHIST_LOG(ehcidebug, "xfer=%p pipe=%p", xfer, epipe, 0, 0); | | 3126 | USBHIST_LOG(ehcidebug, "xfer=%p pipe=%p", xfer, epipe, 0, 0); |
3127 | | | 3127 | |
3128 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3128 | KASSERT(mutex_owned(&sc->sc_lock)); |
3129 | ASSERT_SLEEPABLE(); | | 3129 | ASSERT_SLEEPABLE(); |
3130 | | | 3130 | |
3131 | if (sc->sc_dying) { | | 3131 | if (sc->sc_dying) { |
3132 | /* If we're dying, just do the software part. */ | | 3132 | /* If we're dying, just do the software part. */ |
3133 | xfer->ux_status = status; /* make software ignore it */ | | 3133 | xfer->ux_status = status; /* make software ignore it */ |
3134 | callout_stop(&xfer->ux_callout); | | 3134 | callout_stop(&xfer->ux_callout); |
3135 | usb_transfer_complete(xfer); | | 3135 | usb_transfer_complete(xfer); |
3136 | return; | | 3136 | return; |
3137 | } | | 3137 | } |
3138 | | | 3138 | |
3139 | /* | | 3139 | /* |
3140 | * If an abort is already in progress then just wait for it to | | 3140 | * If an abort is already in progress then just wait for it to |
3141 | * complete and return. | | 3141 | * complete and return. |
3142 | */ | | 3142 | */ |
3143 | if (xfer->ux_hcflags & UXFER_ABORTING) { | | 3143 | if (xfer->ux_hcflags & UXFER_ABORTING) { |
3144 | USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0); | | 3144 | USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0); |
3145 | #ifdef DIAGNOSTIC | | 3145 | #ifdef DIAGNOSTIC |
3146 | if (status == USBD_TIMEOUT) | | 3146 | if (status == USBD_TIMEOUT) |
3147 | printf("ehci_abort_xfer: TIMEOUT while aborting\n"); | | 3147 | printf("ehci_abort_xfer: TIMEOUT while aborting\n"); |
3148 | #endif | | 3148 | #endif |
3149 | /* Override the status which might be USBD_TIMEOUT. */ | | 3149 | /* Override the status which might be USBD_TIMEOUT. */ |
3150 | xfer->ux_status = status; | | 3150 | xfer->ux_status = status; |
3151 | USBHIST_LOG(ehcidebug, "waiting for abort to finish", | | 3151 | USBHIST_LOG(ehcidebug, "waiting for abort to finish", |
3152 | 0, 0, 0, 0); | | 3152 | 0, 0, 0, 0); |
3153 | xfer->ux_hcflags |= UXFER_ABORTWAIT; | | 3153 | xfer->ux_hcflags |= UXFER_ABORTWAIT; |
3154 | while (xfer->ux_hcflags & UXFER_ABORTING) | | 3154 | while (xfer->ux_hcflags & UXFER_ABORTING) |
3155 | cv_wait(&xfer->ux_hccv, &sc->sc_lock); | | 3155 | cv_wait(&xfer->ux_hccv, &sc->sc_lock); |
3156 | return; | | 3156 | return; |
3157 | } | | 3157 | } |
3158 | xfer->ux_hcflags |= UXFER_ABORTING; | | 3158 | xfer->ux_hcflags |= UXFER_ABORTING; |
3159 | | | 3159 | |
3160 | /* | | 3160 | /* |
3161 | * Step 1: Make interrupt routine and hardware ignore xfer. | | 3161 | * Step 1: Make interrupt routine and hardware ignore xfer. |
3162 | */ | | 3162 | */ |
3163 | xfer->ux_status = status; /* make software ignore it */ | | 3163 | xfer->ux_status = status; /* make software ignore it */ |
3164 | callout_stop(&xfer->ux_callout); | | 3164 | callout_stop(&xfer->ux_callout); |
3165 | | | 3165 | |
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_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 3169 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
3170 | qhstatus = sqh->qh.qh_qtd.qtd_status; | | 3170 | qhstatus = sqh->qh.qh_qtd.qtd_status; |
3171 | sqh->qh.qh_qtd.qtd_status = qhstatus | htole32(EHCI_QTD_HALTED); | | 3171 | sqh->qh.qh_qtd.qtd_status = qhstatus | htole32(EHCI_QTD_HALTED); |
3172 | usb_syncmem(&sqh->dma, | | 3172 | usb_syncmem(&sqh->dma, |
3173 | sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), | | 3173 | sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), |
3174 | sizeof(sqh->qh.qh_qtd.qtd_status), | | 3174 | sizeof(sqh->qh.qh_qtd.qtd_status), |
3175 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3175 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3176 | for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) { | | 3176 | for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) { |
3177 | usb_syncmem(&sqtd->dma, | | 3177 | usb_syncmem(&sqtd->dma, |
3178 | sqtd->offs + offsetof(ehci_qtd_t, qtd_status), | | 3178 | sqtd->offs + offsetof(ehci_qtd_t, qtd_status), |
3179 | sizeof(sqtd->qtd.qtd_status), | | 3179 | sizeof(sqtd->qtd.qtd_status), |
3180 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 3180 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
3181 | sqtd->qtd.qtd_status |= htole32(EHCI_QTD_HALTED); | | 3181 | sqtd->qtd.qtd_status |= htole32(EHCI_QTD_HALTED); |
3182 | usb_syncmem(&sqtd->dma, | | 3182 | usb_syncmem(&sqtd->dma, |
3183 | sqtd->offs + offsetof(ehci_qtd_t, qtd_status), | | 3183 | sqtd->offs + offsetof(ehci_qtd_t, qtd_status), |
3184 | sizeof(sqtd->qtd.qtd_status), | | 3184 | sizeof(sqtd->qtd.qtd_status), |
3185 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3185 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3186 | if (sqtd == exfer->ex_sqtdend) | | 3186 | if (sqtd == exfer->ex_sqtdend) |
3187 | break; | | 3187 | break; |
3188 | } | | 3188 | } |
3189 | | | 3189 | |
3190 | /* | | 3190 | /* |
3191 | * Step 2: Wait until we know hardware has finished any possible | | 3191 | * Step 2: Wait until we know hardware has finished any possible |
3192 | * use of the xfer. Also make sure the soft interrupt routine | | 3192 | * use of the xfer. Also make sure the soft interrupt routine |
3193 | * has run. | | 3193 | * has run. |
3194 | */ | | 3194 | */ |
3195 | ehci_sync_hc(sc); | | 3195 | ehci_sync_hc(sc); |
3196 | sc->sc_softwake = 1; | | 3196 | sc->sc_softwake = 1; |
3197 | usb_schedsoftintr(&sc->sc_bus); | | 3197 | usb_schedsoftintr(&sc->sc_bus); |
3198 | cv_wait(&sc->sc_softwake_cv, &sc->sc_lock); | | 3198 | cv_wait(&sc->sc_softwake_cv, &sc->sc_lock); |
3199 | | | 3199 | |
3200 | /* | | 3200 | /* |
3201 | * Step 3: Remove any vestiges of the xfer from the hardware. | | 3201 | * Step 3: Remove any vestiges of the xfer from the hardware. |
3202 | * The complication here is that the hardware may have executed | | 3202 | * The complication here is that the hardware may have executed |
3203 | * beyond the xfer we're trying to abort. So as we're scanning | | 3203 | * beyond the xfer we're trying to abort. So as we're scanning |
3204 | * the TDs of this xfer we check if the hardware points to | | 3204 | * the TDs of this xfer we check if the hardware points to |
3205 | * any of them. | | 3205 | * any of them. |
3206 | */ | | 3206 | */ |
3207 | | | 3207 | |
3208 | usb_syncmem(&sqh->dma, | | 3208 | usb_syncmem(&sqh->dma, |
3209 | sqh->offs + offsetof(ehci_qh_t, qh_curqtd), | | 3209 | sqh->offs + offsetof(ehci_qh_t, qh_curqtd), |
3210 | sizeof(sqh->qh.qh_curqtd), | | 3210 | sizeof(sqh->qh.qh_curqtd), |
3211 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 3211 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
3212 | cur = EHCI_LINK_ADDR(le32toh(sqh->qh.qh_curqtd)); | | 3212 | cur = EHCI_LINK_ADDR(le32toh(sqh->qh.qh_curqtd)); |
3213 | hit = 0; | | 3213 | hit = 0; |
3214 | for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) { | | 3214 | for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) { |
3215 | hit |= cur == sqtd->physaddr; | | 3215 | hit |= cur == sqtd->physaddr; |
3216 | if (sqtd == exfer->ex_sqtdend) | | 3216 | if (sqtd == exfer->ex_sqtdend) |
3217 | break; | | 3217 | break; |
3218 | } | | 3218 | } |
3219 | sqtd = sqtd->nextqtd; | | 3219 | sqtd = sqtd->nextqtd; |
3220 | /* Zap curqtd register if hardware pointed inside the xfer. */ | | 3220 | /* Zap curqtd register if hardware pointed inside the xfer. */ |
3221 | if (hit && sqtd != NULL) { | | 3221 | if (hit && sqtd != NULL) { |
3222 | USBHIST_LOG(ehcidebug, "cur=0x%08x", sqtd->physaddr, 0, 0, 0); | | 3222 | USBHIST_LOG(ehcidebug, "cur=0x%08x", sqtd->physaddr, 0, 0, 0); |
3223 | sqh->qh.qh_curqtd = htole32(sqtd->physaddr); /* unlink qTDs */ | | 3223 | sqh->qh.qh_curqtd = htole32(sqtd->physaddr); /* unlink qTDs */ |
3224 | usb_syncmem(&sqh->dma, | | 3224 | usb_syncmem(&sqh->dma, |
3225 | sqh->offs + offsetof(ehci_qh_t, qh_curqtd), | | 3225 | sqh->offs + offsetof(ehci_qh_t, qh_curqtd), |
3226 | sizeof(sqh->qh.qh_curqtd), | | 3226 | sizeof(sqh->qh.qh_curqtd), |
3227 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3227 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3228 | sqh->qh.qh_qtd.qtd_status = qhstatus; | | 3228 | sqh->qh.qh_qtd.qtd_status = qhstatus; |
3229 | usb_syncmem(&sqh->dma, | | 3229 | usb_syncmem(&sqh->dma, |
3230 | sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), | | 3230 | sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), |
3231 | sizeof(sqh->qh.qh_qtd.qtd_status), | | 3231 | sizeof(sqh->qh.qh_qtd.qtd_status), |
3232 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3232 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3233 | } else { | | 3233 | } else { |
3234 | USBHIST_LOG(ehcidebug, "no hit", 0, 0, 0, 0); | | 3234 | USBHIST_LOG(ehcidebug, "no hit", 0, 0, 0, 0); |
3235 | } | | 3235 | } |
3236 | | | 3236 | |
3237 | /* | | 3237 | /* |
3238 | * Step 4: Execute callback. | | 3238 | * Step 4: Execute callback. |
3239 | */ | | 3239 | */ |
3240 | #ifdef DIAGNOSTIC | | 3240 | #ifdef DIAGNOSTIC |
3241 | exfer->ex_isdone = 1; | | 3241 | exfer->ex_isdone = 1; |
3242 | #endif | | 3242 | #endif |
3243 | wake = xfer->ux_hcflags & UXFER_ABORTWAIT; | | 3243 | wake = xfer->ux_hcflags & UXFER_ABORTWAIT; |
3244 | xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT); | | 3244 | xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT); |
3245 | usb_transfer_complete(xfer); | | 3245 | usb_transfer_complete(xfer); |
3246 | if (wake) { | | 3246 | if (wake) { |
3247 | cv_broadcast(&xfer->ux_hccv); | | 3247 | cv_broadcast(&xfer->ux_hccv); |
3248 | } | | 3248 | } |
3249 | | | 3249 | |
3250 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3250 | KASSERT(mutex_owned(&sc->sc_lock)); |
3251 | #undef exfer | | 3251 | #undef exfer |
3252 | } | | 3252 | } |
3253 | | | 3253 | |
3254 | Static void | | 3254 | Static void |
3255 | ehci_abort_isoc_xfer(usbd_xfer_handle xfer, usbd_status status) | | 3255 | ehci_abort_isoc_xfer(usbd_xfer_handle xfer, usbd_status status) |
3256 | { | | 3256 | { |
3257 | ehci_isoc_trans_t trans_status; | | 3257 | ehci_isoc_trans_t trans_status; |
3258 | struct ehci_pipe *epipe; | | 3258 | struct ehci_pipe *epipe; |
3259 | struct ehci_xfer *exfer; | | 3259 | struct ehci_xfer *exfer; |
3260 | ehci_softc_t *sc; | | 3260 | ehci_softc_t *sc; |
3261 | struct ehci_soft_itd *itd; | | 3261 | struct ehci_soft_itd *itd; |
3262 | struct ehci_soft_sitd *sitd; | | 3262 | struct ehci_soft_sitd *sitd; |
3263 | int i, wake; | | 3263 | int i, wake; |
3264 | | | 3264 | |
3265 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3265 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3266 | | | 3266 | |
3267 | epipe = (struct ehci_pipe *) xfer->ux_pipe; | | 3267 | epipe = (struct ehci_pipe *) xfer->ux_pipe; |
3268 | exfer = EXFER(xfer); | | 3268 | exfer = EXFER(xfer); |
3269 | sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; | | 3269 | sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; |
3270 | | | 3270 | |
3271 | USBHIST_LOG(ehcidebug, "xfer %p pipe %p", xfer, epipe, 0, 0); | | 3271 | USBHIST_LOG(ehcidebug, "xfer %p pipe %p", xfer, epipe, 0, 0); |
3272 | | | 3272 | |
3273 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3273 | KASSERT(mutex_owned(&sc->sc_lock)); |
3274 | | | 3274 | |
3275 | if (sc->sc_dying) { | | 3275 | if (sc->sc_dying) { |
3276 | xfer->ux_status = status; | | 3276 | xfer->ux_status = status; |
3277 | callout_stop(&xfer->ux_callout); | | 3277 | callout_stop(&xfer->ux_callout); |
3278 | usb_transfer_complete(xfer); | | 3278 | usb_transfer_complete(xfer); |
3279 | return; | | 3279 | return; |
3280 | } | | 3280 | } |
3281 | | | 3281 | |
3282 | if (xfer->ux_hcflags & UXFER_ABORTING) { | | 3282 | if (xfer->ux_hcflags & UXFER_ABORTING) { |
3283 | USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0); | | 3283 | USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0); |
3284 | | | 3284 | |
3285 | #ifdef DIAGNOSTIC | | 3285 | #ifdef DIAGNOSTIC |
3286 | if (status == USBD_TIMEOUT) | | 3286 | if (status == USBD_TIMEOUT) |
3287 | printf("ehci_abort_isoc_xfer: TIMEOUT while aborting\n"); | | 3287 | printf("ehci_abort_isoc_xfer: TIMEOUT while aborting\n"); |
3288 | #endif | | 3288 | #endif |
3289 | | | 3289 | |
3290 | xfer->ux_status = status; | | 3290 | xfer->ux_status = status; |
3291 | USBHIST_LOG(ehcidebug, | | 3291 | USBHIST_LOG(ehcidebug, |
3292 | "waiting for abort to finish", 0, 0, 0, 0); | | 3292 | "waiting for abort to finish", 0, 0, 0, 0); |
3293 | xfer->ux_hcflags |= UXFER_ABORTWAIT; | | 3293 | xfer->ux_hcflags |= UXFER_ABORTWAIT; |
3294 | while (xfer->ux_hcflags & UXFER_ABORTING) | | 3294 | while (xfer->ux_hcflags & UXFER_ABORTING) |
3295 | cv_wait(&xfer->ux_hccv, &sc->sc_lock); | | 3295 | cv_wait(&xfer->ux_hccv, &sc->sc_lock); |
3296 | goto done; | | 3296 | goto done; |
3297 | } | | 3297 | } |
3298 | xfer->ux_hcflags |= UXFER_ABORTING; | | 3298 | xfer->ux_hcflags |= UXFER_ABORTING; |
3299 | | | 3299 | |
3300 | xfer->ux_status = status; | | 3300 | xfer->ux_status = status; |
3301 | callout_stop(&xfer->ux_callout); | | 3301 | callout_stop(&xfer->ux_callout); |
3302 | | | 3302 | |
3303 | if (xfer->ux_pipe->up_dev->ud_speed == USB_SPEED_HIGH) { | | 3303 | if (xfer->ux_pipe->up_dev->ud_speed == USB_SPEED_HIGH) { |
3304 | for (itd = exfer->ex_itdstart; itd != NULL; | | 3304 | for (itd = exfer->ex_itdstart; itd != NULL; |
3305 | itd = itd->xfer_next) { | | 3305 | itd = itd->xfer_next) { |
3306 | usb_syncmem(&itd->dma, | | 3306 | usb_syncmem(&itd->dma, |
3307 | itd->offs + offsetof(ehci_itd_t, itd_ctl), | | 3307 | itd->offs + offsetof(ehci_itd_t, itd_ctl), |
3308 | sizeof(itd->itd.itd_ctl), | | 3308 | sizeof(itd->itd.itd_ctl), |
3309 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 3309 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
3310 | | | 3310 | |
3311 | for (i = 0; i < 8; i++) { | | 3311 | for (i = 0; i < 8; i++) { |
3312 | trans_status = le32toh(itd->itd.itd_ctl[i]); | | 3312 | trans_status = le32toh(itd->itd.itd_ctl[i]); |
3313 | trans_status &= ~EHCI_ITD_ACTIVE; | | 3313 | trans_status &= ~EHCI_ITD_ACTIVE; |
3314 | itd->itd.itd_ctl[i] = htole32(trans_status); | | 3314 | itd->itd.itd_ctl[i] = htole32(trans_status); |
3315 | } | | 3315 | } |
3316 | | | 3316 | |
3317 | usb_syncmem(&itd->dma, | | 3317 | usb_syncmem(&itd->dma, |
3318 | itd->offs + offsetof(ehci_itd_t, itd_ctl), | | 3318 | itd->offs + offsetof(ehci_itd_t, itd_ctl), |
3319 | sizeof(itd->itd.itd_ctl), | | 3319 | sizeof(itd->itd.itd_ctl), |
3320 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3320 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3321 | } | | 3321 | } |
3322 | } else { | | 3322 | } else { |
3323 | for (sitd = exfer->ex_sitdstart; sitd != NULL; | | 3323 | for (sitd = exfer->ex_sitdstart; sitd != NULL; |
3324 | sitd = sitd->xfer_next) { | | 3324 | sitd = sitd->xfer_next) { |
3325 | usb_syncmem(&sitd->dma, | | 3325 | usb_syncmem(&sitd->dma, |
3326 | sitd->offs + offsetof(ehci_sitd_t, sitd_buffer), | | 3326 | sitd->offs + offsetof(ehci_sitd_t, sitd_buffer), |
3327 | sizeof(sitd->sitd.sitd_buffer), | | 3327 | sizeof(sitd->sitd.sitd_buffer), |
3328 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); | | 3328 | BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); |
3329 | | | 3329 | |
3330 | trans_status = le32toh(sitd->sitd.sitd_trans); | | 3330 | trans_status = le32toh(sitd->sitd.sitd_trans); |
3331 | trans_status &= ~EHCI_SITD_ACTIVE; | | 3331 | trans_status &= ~EHCI_SITD_ACTIVE; |
3332 | sitd->sitd.sitd_trans = htole32(trans_status); | | 3332 | sitd->sitd.sitd_trans = htole32(trans_status); |
3333 | | | 3333 | |
3334 | usb_syncmem(&sitd->dma, | | 3334 | usb_syncmem(&sitd->dma, |
3335 | sitd->offs + offsetof(ehci_sitd_t, sitd_buffer), | | 3335 | sitd->offs + offsetof(ehci_sitd_t, sitd_buffer), |
3336 | sizeof(sitd->sitd.sitd_buffer), | | 3336 | sizeof(sitd->sitd.sitd_buffer), |
3337 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3337 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3338 | } | | 3338 | } |
3339 | } | | 3339 | } |
3340 | | | 3340 | |
3341 | sc->sc_softwake = 1; | | 3341 | sc->sc_softwake = 1; |
3342 | usb_schedsoftintr(&sc->sc_bus); | | 3342 | usb_schedsoftintr(&sc->sc_bus); |
3343 | cv_wait(&sc->sc_softwake_cv, &sc->sc_lock); | | 3343 | cv_wait(&sc->sc_softwake_cv, &sc->sc_lock); |
3344 | | | 3344 | |
3345 | #ifdef DIAGNOSTIC | | 3345 | #ifdef DIAGNOSTIC |
3346 | exfer->ex_isdone = 1; | | 3346 | exfer->ex_isdone = 1; |
3347 | #endif | | 3347 | #endif |
3348 | wake = xfer->ux_hcflags & UXFER_ABORTWAIT; | | 3348 | wake = xfer->ux_hcflags & UXFER_ABORTWAIT; |
3349 | xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT); | | 3349 | xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT); |
3350 | usb_transfer_complete(xfer); | | 3350 | usb_transfer_complete(xfer); |
3351 | if (wake) { | | 3351 | if (wake) { |
3352 | cv_broadcast(&xfer->ux_hccv); | | 3352 | cv_broadcast(&xfer->ux_hccv); |
3353 | } | | 3353 | } |
3354 | | | 3354 | |
3355 | done: | | 3355 | done: |
3356 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3356 | KASSERT(mutex_owned(&sc->sc_lock)); |
3357 | return; | | 3357 | return; |
3358 | } | | 3358 | } |
3359 | | | 3359 | |
3360 | Static void | | 3360 | Static void |
3361 | ehci_timeout(void *addr) | | 3361 | ehci_timeout(void *addr) |
3362 | { | | 3362 | { |
3363 | struct ehci_xfer *exfer = addr; | | 3363 | struct ehci_xfer *exfer = addr; |
3364 | struct ehci_pipe *epipe = (struct ehci_pipe *)exfer->ex_xfer.ux_pipe; | | 3364 | struct ehci_pipe *epipe = (struct ehci_pipe *)exfer->ex_xfer.ux_pipe; |
3365 | ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; | | 3365 | ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; |
3366 | | | 3366 | |
3367 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3367 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3368 | | | 3368 | |
3369 | USBHIST_LOG(ehcidebug, "exfer %p", exfer, 0, 0, 0); | | 3369 | USBHIST_LOG(ehcidebug, "exfer %p", exfer, 0, 0, 0); |
3370 | #ifdef EHCI_DEBUG | | 3370 | #ifdef EHCI_DEBUG |
3371 | if (ehcidebug > 1) | | 3371 | if (ehcidebug > 1) |
3372 | usbd_dump_pipe(exfer->ex_xfer.ux_pipe); | | 3372 | usbd_dump_pipe(exfer->ex_xfer.ux_pipe); |
3373 | #endif | | 3373 | #endif |
3374 | | | 3374 | |
3375 | if (sc->sc_dying) { | | 3375 | if (sc->sc_dying) { |
3376 | mutex_enter(&sc->sc_lock); | | 3376 | mutex_enter(&sc->sc_lock); |
3377 | ehci_abort_xfer(&exfer->ex_xfer, USBD_TIMEOUT); | | 3377 | ehci_abort_xfer(&exfer->ex_xfer, USBD_TIMEOUT); |
3378 | mutex_exit(&sc->sc_lock); | | 3378 | mutex_exit(&sc->sc_lock); |
3379 | return; | | 3379 | return; |
3380 | } | | 3380 | } |
3381 | | | 3381 | |
3382 | /* Execute the abort in a process context. */ | | 3382 | /* Execute the abort in a process context. */ |
3383 | usb_init_task(&exfer->ex_aborttask, ehci_timeout_task, addr, | | 3383 | usb_init_task(&exfer->ex_aborttask, ehci_timeout_task, addr, |
3384 | USB_TASKQ_MPSAFE); | | 3384 | USB_TASKQ_MPSAFE); |
3385 | usb_add_task(exfer->ex_xfer.ux_pipe->up_dev, &exfer->ex_aborttask, | | 3385 | usb_add_task(exfer->ex_xfer.ux_pipe->up_dev, &exfer->ex_aborttask, |
3386 | USB_TASKQ_HC); | | 3386 | USB_TASKQ_HC); |
3387 | } | | 3387 | } |
3388 | | | 3388 | |
3389 | Static void | | 3389 | Static void |
3390 | ehci_timeout_task(void *addr) | | 3390 | ehci_timeout_task(void *addr) |
3391 | { | | 3391 | { |
3392 | usbd_xfer_handle xfer = addr; | | 3392 | usbd_xfer_handle xfer = addr; |
3393 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 3393 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
3394 | | | 3394 | |
3395 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3395 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3396 | | | 3396 | |
3397 | USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); | | 3397 | USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); |
3398 | | | 3398 | |
3399 | mutex_enter(&sc->sc_lock); | | 3399 | mutex_enter(&sc->sc_lock); |
3400 | ehci_abort_xfer(xfer, USBD_TIMEOUT); | | 3400 | ehci_abort_xfer(xfer, USBD_TIMEOUT); |
3401 | mutex_exit(&sc->sc_lock); | | 3401 | mutex_exit(&sc->sc_lock); |
3402 | } | | 3402 | } |
3403 | | | 3403 | |
3404 | /************************/ | | 3404 | /************************/ |
3405 | | | 3405 | |
3406 | Static usbd_status | | 3406 | Static usbd_status |
3407 | ehci_device_ctrl_transfer(usbd_xfer_handle xfer) | | 3407 | ehci_device_ctrl_transfer(usbd_xfer_handle xfer) |
3408 | { | | 3408 | { |
3409 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 3409 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
3410 | usbd_status err; | | 3410 | usbd_status err; |
3411 | | | 3411 | |
3412 | /* Insert last in queue. */ | | 3412 | /* Insert last in queue. */ |
3413 | mutex_enter(&sc->sc_lock); | | 3413 | mutex_enter(&sc->sc_lock); |
3414 | err = usb_insert_transfer(xfer); | | 3414 | err = usb_insert_transfer(xfer); |
3415 | mutex_exit(&sc->sc_lock); | | 3415 | mutex_exit(&sc->sc_lock); |
3416 | if (err) | | 3416 | if (err) |
3417 | return err; | | 3417 | return err; |
3418 | | | 3418 | |
3419 | /* Pipe isn't running, start first */ | | 3419 | /* Pipe isn't running, start first */ |
3420 | return ehci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); | | 3420 | return ehci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); |
3421 | } | | 3421 | } |
3422 | | | 3422 | |
3423 | Static usbd_status | | 3423 | Static usbd_status |
3424 | ehci_device_ctrl_start(usbd_xfer_handle xfer) | | 3424 | ehci_device_ctrl_start(usbd_xfer_handle xfer) |
3425 | { | | 3425 | { |
3426 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 3426 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
3427 | usbd_status err; | | 3427 | usbd_status err; |
3428 | | | 3428 | |
3429 | if (sc->sc_dying) | | 3429 | if (sc->sc_dying) |
3430 | return USBD_IOERROR; | | 3430 | return USBD_IOERROR; |
3431 | | | 3431 | |
3432 | KASSERT(xfer->ux_rqflags & URQ_REQUEST); | | 3432 | KASSERT(xfer->ux_rqflags & URQ_REQUEST); |
3433 | | | 3433 | |
3434 | err = ehci_device_request(xfer); | | 3434 | err = ehci_device_request(xfer); |
3435 | if (err) { | | 3435 | if (err) { |
3436 | return err; | | 3436 | return err; |
3437 | } | | 3437 | } |
3438 | | | 3438 | |
3439 | if (sc->sc_bus.ub_usepolling) | | 3439 | if (sc->sc_bus.ub_usepolling) |
3440 | ehci_waitintr(sc, xfer); | | 3440 | ehci_waitintr(sc, xfer); |
3441 | | | 3441 | |
3442 | return USBD_IN_PROGRESS; | | 3442 | return USBD_IN_PROGRESS; |
3443 | } | | 3443 | } |
3444 | | | 3444 | |
3445 | Static void | | 3445 | Static void |
3446 | ehci_device_ctrl_done(usbd_xfer_handle xfer) | | 3446 | ehci_device_ctrl_done(usbd_xfer_handle xfer) |
3447 | { | | 3447 | { |
3448 | struct ehci_xfer *ex = EXFER(xfer); | | 3448 | struct ehci_xfer *ex = EXFER(xfer); |
3449 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 3449 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
3450 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; | | 3450 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; |
3451 | usb_device_request_t *req = &xfer->ux_request; | | 3451 | usb_device_request_t *req = &xfer->ux_request; |
3452 | int len = UGETW(req->wLength); | | 3452 | int len = UGETW(req->wLength); |
3453 | int rd = req->bmRequestType & UT_READ; | | 3453 | int rd = req->bmRequestType & UT_READ; |
3454 | | | 3454 | |
3455 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3455 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3456 | | | 3456 | |
3457 | USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); | | 3457 | USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); |
3458 | | | 3458 | |
3459 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); | | 3459 | KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); |
3460 | KASSERT(xfer->ux_rqflags & URQ_REQUEST); | | 3460 | KASSERT(xfer->ux_rqflags & URQ_REQUEST); |
3461 | | | 3461 | |
3462 | if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { | | 3462 | if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { |
3463 | ehci_del_intr_list(sc, ex); /* remove from active list */ | | 3463 | ehci_del_intr_list(sc, ex); /* remove from active list */ |
3464 | ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); | | 3464 | ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); |
3465 | usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req), | | 3465 | usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req), |
3466 | BUS_DMASYNC_POSTWRITE); | | 3466 | BUS_DMASYNC_POSTWRITE); |
3467 | if (len) | | 3467 | if (len) |
3468 | usb_syncmem(&xfer->ux_dmabuf, 0, len, | | 3468 | usb_syncmem(&xfer->ux_dmabuf, 0, len, |
3469 | rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); | | 3469 | rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); |
3470 | } | | 3470 | } |
3471 | | | 3471 | |
3472 | USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0); | | 3472 | USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0); |
3473 | } | | 3473 | } |
3474 | | | 3474 | |
3475 | /* Abort a device control request. */ | | 3475 | /* Abort a device control request. */ |
3476 | Static void | | 3476 | Static void |
3477 | ehci_device_ctrl_abort(usbd_xfer_handle xfer) | | 3477 | ehci_device_ctrl_abort(usbd_xfer_handle xfer) |
3478 | { | | 3478 | { |
3479 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3479 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3480 | | | 3480 | |
3481 | USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); | | 3481 | USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); |
3482 | ehci_abort_xfer(xfer, USBD_CANCELLED); | | 3482 | ehci_abort_xfer(xfer, USBD_CANCELLED); |
3483 | } | | 3483 | } |
3484 | | | 3484 | |
3485 | /* Close a device control pipe. */ | | 3485 | /* Close a device control pipe. */ |
3486 | Static void | | 3486 | Static void |
3487 | ehci_device_ctrl_close(usbd_pipe_handle pipe) | | 3487 | ehci_device_ctrl_close(usbd_pipe_handle pipe) |
3488 | { | | 3488 | { |
3489 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; | | 3489 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; |
3490 | /*struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;*/ | | 3490 | /*struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;*/ |
3491 | | | 3491 | |
3492 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3492 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3493 | | | 3493 | |
3494 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3494 | KASSERT(mutex_owned(&sc->sc_lock)); |
3495 | | | 3495 | |
3496 | USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0); | | 3496 | USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0); |
3497 | | | 3497 | |
3498 | ehci_close_pipe(pipe, sc->sc_async_head); | | 3498 | ehci_close_pipe(pipe, sc->sc_async_head); |
3499 | } | | 3499 | } |
3500 | | | 3500 | |
3501 | Static usbd_status | | 3501 | Static usbd_status |
3502 | ehci_device_request(usbd_xfer_handle xfer) | | 3502 | ehci_device_request(usbd_xfer_handle xfer) |
3503 | { | | 3503 | { |
3504 | #define exfer EXFER(xfer) | | 3504 | #define exfer EXFER(xfer) |
3505 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; | | 3505 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; |
3506 | usb_device_request_t *req = &xfer->ux_request; | | 3506 | usb_device_request_t *req = &xfer->ux_request; |
3507 | usbd_device_handle dev = epipe->pipe.up_dev; | | 3507 | usbd_device_handle dev = epipe->pipe.up_dev; |
3508 | ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; | | 3508 | ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; |
3509 | ehci_soft_qtd_t *setup, *stat, *next; | | 3509 | ehci_soft_qtd_t *setup, *stat, *next; |
3510 | ehci_soft_qh_t *sqh; | | 3510 | ehci_soft_qh_t *sqh; |
3511 | int isread; | | 3511 | int isread; |
3512 | int len; | | 3512 | int len; |
3513 | usbd_status err; | | 3513 | usbd_status err; |
3514 | | | 3514 | |
3515 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3515 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3516 | | | 3516 | |
3517 | isread = req->bmRequestType & UT_READ; | | 3517 | isread = req->bmRequestType & UT_READ; |
3518 | len = UGETW(req->wLength); | | 3518 | len = UGETW(req->wLength); |
3519 | | | 3519 | |
3520 | USBHIST_LOG(ehcidebug, "type=0x%02x, request=0x%02x, " | | 3520 | USBHIST_LOG(ehcidebug, "type=0x%02x, request=0x%02x, " |
3521 | "wValue=0x%04x, wIndex=0x%04x", | | 3521 | "wValue=0x%04x, wIndex=0x%04x", |
3522 | req->bmRequestType, req->bRequest, UGETW(req->wValue), | | 3522 | req->bmRequestType, req->bRequest, UGETW(req->wValue), |
3523 | UGETW(req->wIndex)); | | 3523 | UGETW(req->wIndex)); |
3524 | USBHIST_LOG(ehcidebug, "len=%d, addr=%d, endpt=%d", | | 3524 | USBHIST_LOG(ehcidebug, "len=%d, addr=%d, endpt=%d", |
3525 | len, dev->ud_addr, | | 3525 | len, dev->ud_addr, |
3526 | epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress, 0); | | 3526 | epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress, 0); |
3527 | | | 3527 | |
3528 | setup = ehci_alloc_sqtd(sc); | | 3528 | setup = ehci_alloc_sqtd(sc); |
3529 | if (setup == NULL) { | | 3529 | if (setup == NULL) { |
3530 | err = USBD_NOMEM; | | 3530 | err = USBD_NOMEM; |
3531 | goto bad1; | | 3531 | goto bad1; |
3532 | } | | 3532 | } |
3533 | stat = ehci_alloc_sqtd(sc); | | 3533 | stat = ehci_alloc_sqtd(sc); |
3534 | if (stat == NULL) { | | 3534 | if (stat == NULL) { |
3535 | err = USBD_NOMEM; | | 3535 | err = USBD_NOMEM; |
3536 | goto bad2; | | 3536 | goto bad2; |
3537 | } | | 3537 | } |
3538 | | | 3538 | |
3539 | mutex_enter(&sc->sc_lock); | | 3539 | mutex_enter(&sc->sc_lock); |
3540 | | | 3540 | |
3541 | sqh = epipe->sqh; | | 3541 | sqh = epipe->sqh; |
3542 | | | 3542 | |
3543 | KASSERTMSG(EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)) == dev->ud_addr, | | 3543 | KASSERTMSG(EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)) == dev->ud_addr, |
3544 | "address QH %d pipe %d\n", | | 3544 | "address QH %d pipe %d\n", |
3545 | EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)), dev->ud_addr); | | 3545 | EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)), dev->ud_addr); |
3546 | KASSERTMSG(EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)) == | | 3546 | KASSERTMSG(EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)) == |
3547 | UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize), | | 3547 | UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize), |
3548 | "MPS QH %d pipe %d\n", | | 3548 | "MPS QH %d pipe %d\n", |
3549 | EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)), | | 3549 | EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)), |
3550 | UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize)); | | 3550 | UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize)); |
3551 | | | 3551 | |
3552 | /* Set up data transaction */ | | 3552 | /* Set up data transaction */ |
3553 | if (len != 0) { | | 3553 | if (len != 0) { |
3554 | ehci_soft_qtd_t *end; | | 3554 | ehci_soft_qtd_t *end; |
3555 | | | 3555 | |
3556 | /* Start toggle at 1. */ | | 3556 | /* Start toggle at 1. */ |
3557 | epipe->nexttoggle = 1; | | 3557 | epipe->nexttoggle = 1; |
3558 | err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, | | 3558 | err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, |
3559 | &next, &end); | | 3559 | &next, &end); |
3560 | if (err) | | 3560 | if (err) |
3561 | goto bad3; | | 3561 | goto bad3; |
3562 | end->qtd.qtd_status &= htole32(~EHCI_QTD_IOC); | | 3562 | end->qtd.qtd_status &= htole32(~EHCI_QTD_IOC); |
3563 | end->nextqtd = stat; | | 3563 | end->nextqtd = stat; |
3564 | end->qtd.qtd_next = end->qtd.qtd_altnext = | | 3564 | end->qtd.qtd_next = end->qtd.qtd_altnext = |
3565 | htole32(stat->physaddr); | | 3565 | htole32(stat->physaddr); |
3566 | usb_syncmem(&end->dma, end->offs, sizeof(end->qtd), | | 3566 | usb_syncmem(&end->dma, end->offs, sizeof(end->qtd), |
3567 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3567 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3568 | } else { | | 3568 | } else { |
3569 | next = stat; | | 3569 | next = stat; |
3570 | } | | 3570 | } |
3571 | | | 3571 | |
3572 | memcpy(KERNADDR(&epipe->u.ctl.reqdma, 0), req, sizeof(*req)); | | 3572 | memcpy(KERNADDR(&epipe->u.ctl.reqdma, 0), req, sizeof(*req)); |
3573 | usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req), BUS_DMASYNC_PREWRITE); | | 3573 | usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req), BUS_DMASYNC_PREWRITE); |
3574 | | | 3574 | |
3575 | /* Clear toggle */ | | 3575 | /* Clear toggle */ |
3576 | setup->qtd.qtd_status = htole32( | | 3576 | setup->qtd.qtd_status = htole32( |
3577 | EHCI_QTD_ACTIVE | | | 3577 | EHCI_QTD_ACTIVE | |
3578 | EHCI_QTD_SET_PID(EHCI_QTD_PID_SETUP) | | | 3578 | EHCI_QTD_SET_PID(EHCI_QTD_PID_SETUP) | |
3579 | EHCI_QTD_SET_CERR(3) | | | 3579 | EHCI_QTD_SET_CERR(3) | |
3580 | EHCI_QTD_SET_TOGGLE(0) | | | 3580 | EHCI_QTD_SET_TOGGLE(0) | |
3581 | EHCI_QTD_SET_BYTES(sizeof(*req)) | | 3581 | EHCI_QTD_SET_BYTES(sizeof(*req)) |
3582 | ); | | 3582 | ); |
3583 | setup->qtd.qtd_buffer[0] = htole32(DMAADDR(&epipe->u.ctl.reqdma, 0)); | | 3583 | setup->qtd.qtd_buffer[0] = htole32(DMAADDR(&epipe->u.ctl.reqdma, 0)); |
3584 | setup->qtd.qtd_buffer_hi[0] = 0; | | 3584 | setup->qtd.qtd_buffer_hi[0] = 0; |
3585 | setup->nextqtd = next; | | 3585 | setup->nextqtd = next; |
3586 | setup->qtd.qtd_next = setup->qtd.qtd_altnext = htole32(next->physaddr); | | 3586 | setup->qtd.qtd_next = setup->qtd.qtd_altnext = htole32(next->physaddr); |
3587 | setup->xfer = xfer; | | 3587 | setup->xfer = xfer; |
3588 | setup->len = sizeof(*req); | | 3588 | setup->len = sizeof(*req); |
3589 | usb_syncmem(&setup->dma, setup->offs, sizeof(setup->qtd), | | 3589 | usb_syncmem(&setup->dma, setup->offs, sizeof(setup->qtd), |
3590 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3590 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3591 | | | 3591 | |
3592 | stat->qtd.qtd_status = htole32( | | 3592 | stat->qtd.qtd_status = htole32( |
3593 | EHCI_QTD_ACTIVE | | | 3593 | EHCI_QTD_ACTIVE | |
3594 | EHCI_QTD_SET_PID(isread ? EHCI_QTD_PID_OUT : EHCI_QTD_PID_IN) | | | 3594 | EHCI_QTD_SET_PID(isread ? EHCI_QTD_PID_OUT : EHCI_QTD_PID_IN) | |
3595 | EHCI_QTD_SET_CERR(3) | | | 3595 | EHCI_QTD_SET_CERR(3) | |
3596 | EHCI_QTD_SET_TOGGLE(1) | | | 3596 | EHCI_QTD_SET_TOGGLE(1) | |
3597 | EHCI_QTD_IOC | | 3597 | EHCI_QTD_IOC |
3598 | ); | | 3598 | ); |
3599 | stat->qtd.qtd_buffer[0] = 0; /* XXX not needed? */ | | 3599 | stat->qtd.qtd_buffer[0] = 0; /* XXX not needed? */ |
3600 | stat->qtd.qtd_buffer_hi[0] = 0; /* XXX not needed? */ | | 3600 | stat->qtd.qtd_buffer_hi[0] = 0; /* XXX not needed? */ |
3601 | stat->nextqtd = NULL; | | 3601 | stat->nextqtd = NULL; |
3602 | stat->qtd.qtd_next = stat->qtd.qtd_altnext = EHCI_NULL; | | 3602 | stat->qtd.qtd_next = stat->qtd.qtd_altnext = EHCI_NULL; |
3603 | stat->xfer = xfer; | | 3603 | stat->xfer = xfer; |
3604 | stat->len = 0; | | 3604 | stat->len = 0; |
3605 | usb_syncmem(&stat->dma, stat->offs, sizeof(stat->qtd), | | 3605 | usb_syncmem(&stat->dma, stat->offs, sizeof(stat->qtd), |
3606 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); | | 3606 | BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); |
3607 | | | 3607 | |
3608 | #ifdef EHCI_DEBUG | | 3608 | #ifdef EHCI_DEBUG |
3609 | USBHIST_LOGN(ehcidebug, 5, "dump:", 0, 0, 0, 0); | | 3609 | USBHIST_LOGN(ehcidebug, 5, "dump:", 0, 0, 0, 0); |
3610 | ehci_dump_sqh(sqh); | | 3610 | ehci_dump_sqh(sqh); |
3611 | ehci_dump_sqtds(setup); | | 3611 | ehci_dump_sqtds(setup); |
3612 | #endif | | 3612 | #endif |
3613 | | | 3613 | |
3614 | exfer->ex_sqtdstart = setup; | | 3614 | exfer->ex_sqtdstart = setup; |
3615 | exfer->ex_sqtdend = stat; | | 3615 | exfer->ex_sqtdend = stat; |
3616 | #ifdef DIAGNOSTIC | | 3616 | #ifdef DIAGNOSTIC |
3617 | if (!exfer->ex_isdone) { | | 3617 | if (!exfer->ex_isdone) { |
3618 | printf("ehci_device_request: not done, exfer=%p\n", exfer); | | 3618 | printf("ehci_device_request: not done, exfer=%p\n", exfer); |
3619 | } | | 3619 | } |
3620 | exfer->ex_isdone = 0; | | 3620 | exfer->ex_isdone = 0; |
3621 | #endif | | 3621 | #endif |
3622 | | | 3622 | |
3623 | /* Insert qTD in QH list. */ | | 3623 | /* Insert qTD in QH list. */ |
3624 | ehci_set_qh_qtd(sqh, setup); /* also does usb_syncmem(sqh) */ | | 3624 | ehci_set_qh_qtd(sqh, setup); /* also does usb_syncmem(sqh) */ |
3625 | if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { | | 3625 | if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { |
3626 | callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), | | 3626 | callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), |
3627 | ehci_timeout, xfer); | | 3627 | ehci_timeout, xfer); |
3628 | } | | 3628 | } |
3629 | ehci_add_intr_list(sc, exfer); | | 3629 | ehci_add_intr_list(sc, exfer); |
3630 | xfer->ux_status = USBD_IN_PROGRESS; | | 3630 | xfer->ux_status = USBD_IN_PROGRESS; |
3631 | mutex_exit(&sc->sc_lock); | | 3631 | mutex_exit(&sc->sc_lock); |
3632 | | | 3632 | |
3633 | #ifdef EHCI_DEBUG | | 3633 | #ifdef EHCI_DEBUG |
3634 | USBHIST_LOGN(ehcidebug, 10, "status=%x, dump:", | | 3634 | USBHIST_LOGN(ehcidebug, 10, "status=%x, dump:", |
3635 | EOREAD4(sc, EHCI_USBSTS), 0, 0, 0); | | 3635 | EOREAD4(sc, EHCI_USBSTS), 0, 0, 0); |
3636 | // delay(10000); | | 3636 | // delay(10000); |
3637 | ehci_dump_regs(sc); | | 3637 | ehci_dump_regs(sc); |
3638 | ehci_dump_sqh(sc->sc_async_head); | | 3638 | ehci_dump_sqh(sc->sc_async_head); |
3639 | ehci_dump_sqh(sqh); | | 3639 | ehci_dump_sqh(sqh); |
3640 | ehci_dump_sqtds(setup); | | 3640 | ehci_dump_sqtds(setup); |
3641 | #endif | | 3641 | #endif |
3642 | | | 3642 | |
3643 | return USBD_NORMAL_COMPLETION; | | 3643 | return USBD_NORMAL_COMPLETION; |
3644 | | | 3644 | |
3645 | bad3: | | 3645 | bad3: |
3646 | mutex_exit(&sc->sc_lock); | | 3646 | mutex_exit(&sc->sc_lock); |
3647 | ehci_free_sqtd(sc, stat); | | 3647 | ehci_free_sqtd(sc, stat); |
3648 | bad2: | | 3648 | bad2: |
3649 | ehci_free_sqtd(sc, setup); | | 3649 | ehci_free_sqtd(sc, setup); |
3650 | bad1: | | 3650 | bad1: |
3651 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); | | 3651 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); |
3652 | mutex_enter(&sc->sc_lock); | | 3652 | mutex_enter(&sc->sc_lock); |
3653 | xfer->ux_status = err; | | 3653 | xfer->ux_status = err; |
3654 | usb_transfer_complete(xfer); | | 3654 | usb_transfer_complete(xfer); |
3655 | mutex_exit(&sc->sc_lock); | | 3655 | mutex_exit(&sc->sc_lock); |
3656 | return err; | | 3656 | return err; |
3657 | #undef exfer | | 3657 | #undef exfer |
3658 | } | | 3658 | } |
3659 | | | 3659 | |
3660 | /* | | 3660 | /* |
3661 | * Some EHCI chips from VIA seem to trigger interrupts before writing back the | | 3661 | * Some EHCI chips from VIA seem to trigger interrupts before writing back the |
3662 | * qTD status, or miss signalling occasionally under heavy load. If the host | | 3662 | * qTD status, or miss signalling occasionally under heavy load. If the host |
3663 | * machine is too fast, we we can miss transaction completion - when we scan | | 3663 | * machine is too fast, we we can miss transaction completion - when we scan |
3664 | * the active list the transaction still seems to be active. This generally | | 3664 | * the active list the transaction still seems to be active. This generally |
3665 | * exhibits itself as a umass stall that never recovers. | | 3665 | * exhibits itself as a umass stall that never recovers. |
3666 | * | | 3666 | * |
3667 | * We work around this behaviour by setting up this callback after any softintr | | 3667 | * We work around this behaviour by setting up this callback after any softintr |
3668 | * that completes with transactions still pending, giving us another chance to | | 3668 | * that completes with transactions still pending, giving us another chance to |
3669 | * check for completion after the writeback has taken place. | | 3669 | * check for completion after the writeback has taken place. |
3670 | */ | | 3670 | */ |
3671 | Static void | | 3671 | Static void |
3672 | ehci_intrlist_timeout(void *arg) | | 3672 | ehci_intrlist_timeout(void *arg) |
3673 | { | | 3673 | { |
3674 | ehci_softc_t *sc = arg; | | 3674 | ehci_softc_t *sc = arg; |
3675 | | | 3675 | |
3676 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3676 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3677 | | | 3677 | |
3678 | usb_schedsoftintr(&sc->sc_bus); | | 3678 | usb_schedsoftintr(&sc->sc_bus); |
3679 | } | | 3679 | } |
3680 | | | 3680 | |
3681 | /************************/ | | 3681 | /************************/ |
3682 | | | 3682 | |
3683 | Static usbd_status | | 3683 | Static usbd_status |
3684 | ehci_device_bulk_transfer(usbd_xfer_handle xfer) | | 3684 | ehci_device_bulk_transfer(usbd_xfer_handle xfer) |
3685 | { | | 3685 | { |
3686 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 3686 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
3687 | usbd_status err; | | 3687 | usbd_status err; |
3688 | | | 3688 | |
3689 | /* Insert last in queue. */ | | 3689 | /* Insert last in queue. */ |
3690 | mutex_enter(&sc->sc_lock); | | 3690 | mutex_enter(&sc->sc_lock); |
3691 | err = usb_insert_transfer(xfer); | | 3691 | err = usb_insert_transfer(xfer); |
3692 | mutex_exit(&sc->sc_lock); | | 3692 | mutex_exit(&sc->sc_lock); |
3693 | if (err) | | 3693 | if (err) |
3694 | return err; | | 3694 | return err; |
3695 | | | 3695 | |
3696 | /* Pipe isn't running, start first */ | | 3696 | /* Pipe isn't running, start first */ |
3697 | return ehci_device_bulk_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); | | 3697 | return ehci_device_bulk_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); |
3698 | } | | 3698 | } |
3699 | | | 3699 | |
3700 | Static usbd_status | | 3700 | Static usbd_status |
3701 | ehci_device_bulk_start(usbd_xfer_handle xfer) | | 3701 | ehci_device_bulk_start(usbd_xfer_handle xfer) |
3702 | { | | 3702 | { |
3703 | #define exfer EXFER(xfer) | | 3703 | #define exfer EXFER(xfer) |
3704 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; | | 3704 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; |
3705 | usbd_device_handle dev = epipe->pipe.up_dev; | | 3705 | usbd_device_handle dev = epipe->pipe.up_dev; |
3706 | ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; | | 3706 | ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; |
3707 | ehci_soft_qtd_t *data, *dataend; | | 3707 | ehci_soft_qtd_t *data, *dataend; |
3708 | ehci_soft_qh_t *sqh; | | 3708 | ehci_soft_qh_t *sqh; |
3709 | usbd_status err; | | 3709 | usbd_status err; |
3710 | int len, isread, endpt; | | 3710 | int len, isread, endpt; |
3711 | | | 3711 | |
3712 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3712 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3713 | | | 3713 | |
3714 | USBHIST_LOG(ehcidebug, "xfer=%p len=%d flags=%d", | | 3714 | USBHIST_LOG(ehcidebug, "xfer=%p len=%d flags=%d", |
3715 | xfer, xfer->ux_length, xfer->ux_flags, 0); | | 3715 | xfer, xfer->ux_length, xfer->ux_flags, 0); |
3716 | | | 3716 | |
3717 | if (sc->sc_dying) | | 3717 | if (sc->sc_dying) |
3718 | return USBD_IOERROR; | | 3718 | return USBD_IOERROR; |
3719 | | | 3719 | |
3720 | KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); | | 3720 | KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); |
3721 | | | 3721 | |
3722 | mutex_enter(&sc->sc_lock); | | 3722 | mutex_enter(&sc->sc_lock); |
3723 | | | 3723 | |
3724 | len = xfer->ux_length; | | 3724 | len = xfer->ux_length; |
3725 | endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; | | 3725 | endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; |
3726 | isread = UE_GET_DIR(endpt) == UE_DIR_IN; | | 3726 | isread = UE_GET_DIR(endpt) == UE_DIR_IN; |
3727 | sqh = epipe->sqh; | | 3727 | sqh = epipe->sqh; |
3728 | | | 3728 | |
3729 | epipe->u.bulk.length = len; | | 3729 | epipe->u.bulk.length = len; |
3730 | | | 3730 | |
3731 | err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data, | | 3731 | err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data, |
3732 | &dataend); | | 3732 | &dataend); |
3733 | if (err) { | | 3733 | if (err) { |
3734 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); | | 3734 | USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); |
3735 | xfer->ux_status = err; | | 3735 | xfer->ux_status = err; |
3736 | usb_transfer_complete(xfer); | | 3736 | usb_transfer_complete(xfer); |
3737 | mutex_exit(&sc->sc_lock); | | 3737 | mutex_exit(&sc->sc_lock); |
3738 | return err; | | 3738 | return err; |
3739 | } | | 3739 | } |
3740 | | | 3740 | |
3741 | #ifdef EHCI_DEBUG | | 3741 | #ifdef EHCI_DEBUG |
3742 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); | | 3742 | USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); |
3743 | ehci_dump_sqh(sqh); | | 3743 | ehci_dump_sqh(sqh); |
3744 | ehci_dump_sqtds(data); | | 3744 | ehci_dump_sqtds(data); |
3745 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); | | 3745 | USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); |
3746 | #endif | | 3746 | #endif |
3747 | | | 3747 | |
3748 | /* Set up interrupt info. */ | | 3748 | /* Set up interrupt info. */ |
3749 | exfer->ex_sqtdstart = data; | | 3749 | exfer->ex_sqtdstart = data; |
3750 | exfer->ex_sqtdend = dataend; | | 3750 | exfer->ex_sqtdend = dataend; |
3751 | #ifdef DIAGNOSTIC | | 3751 | #ifdef DIAGNOSTIC |
3752 | if (!exfer->ex_isdone) { | | 3752 | if (!exfer->ex_isdone) { |
3753 | printf("ehci_device_bulk_start: not done, ex=%p\n", exfer); | | 3753 | printf("ehci_device_bulk_start: not done, ex=%p\n", exfer); |
3754 | } | | 3754 | } |
3755 | exfer->ex_isdone = 0; | | 3755 | exfer->ex_isdone = 0; |
3756 | #endif | | 3756 | #endif |
3757 | | | 3757 | |
3758 | ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */ | | 3758 | ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */ |
3759 | if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { | | 3759 | if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { |
3760 | callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), | | 3760 | callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), |
3761 | ehci_timeout, xfer); | | 3761 | ehci_timeout, xfer); |
3762 | } | | 3762 | } |
3763 | ehci_add_intr_list(sc, exfer); | | 3763 | ehci_add_intr_list(sc, exfer); |
3764 | xfer->ux_status = USBD_IN_PROGRESS; | | 3764 | xfer->ux_status = USBD_IN_PROGRESS; |
3765 | mutex_exit(&sc->sc_lock); | | 3765 | mutex_exit(&sc->sc_lock); |
3766 | | | 3766 | |
3767 | #ifdef EHCI_DEBUG | | 3767 | #ifdef EHCI_DEBUG |
3768 | USBHIST_LOGN(ehcidebug, 5, "data(2)", 0, 0, 0, 0); | | 3768 | USBHIST_LOGN(ehcidebug, 5, "data(2)", 0, 0, 0, 0); |
3769 | // delay(10000); | | 3769 | // delay(10000); |
3770 | USBHIST_LOGN(ehcidebug, 5, "data(3)", 0, 0, 0, 0); | | 3770 | USBHIST_LOGN(ehcidebug, 5, "data(3)", 0, 0, 0, 0); |
3771 | ehci_dump_regs(sc); | | 3771 | ehci_dump_regs(sc); |
3772 | #if 0 | | 3772 | #if 0 |
3773 | printf("async_head:\n"); | | 3773 | printf("async_head:\n"); |
3774 | ehci_dump_sqh(sc->sc_async_head); | | 3774 | ehci_dump_sqh(sc->sc_async_head); |
3775 | #endif | | 3775 | #endif |
3776 | USBHIST_LOG(ehcidebug, "sqh:", 0, 0, 0, 0); | | 3776 | USBHIST_LOG(ehcidebug, "sqh:", 0, 0, 0, 0); |
3777 | ehci_dump_sqh(sqh); | | 3777 | ehci_dump_sqh(sqh); |
3778 | ehci_dump_sqtds(data); | | 3778 | ehci_dump_sqtds(data); |
3779 | #endif | | 3779 | #endif |
3780 | | | 3780 | |
3781 | if (sc->sc_bus.ub_usepolling) | | 3781 | if (sc->sc_bus.ub_usepolling) |
3782 | ehci_waitintr(sc, xfer); | | 3782 | ehci_waitintr(sc, xfer); |
3783 | | | 3783 | |
3784 | return USBD_IN_PROGRESS; | | 3784 | return USBD_IN_PROGRESS; |
3785 | #undef exfer | | 3785 | #undef exfer |
3786 | } | | 3786 | } |
3787 | | | 3787 | |
3788 | Static void | | 3788 | Static void |
3789 | ehci_device_bulk_abort(usbd_xfer_handle xfer) | | 3789 | ehci_device_bulk_abort(usbd_xfer_handle xfer) |
3790 | { | | 3790 | { |
3791 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3791 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3792 | | | 3792 | |
3793 | USBHIST_LOG(ehcidebug, "xfer %p", xfer, 0, 0, 0); | | 3793 | USBHIST_LOG(ehcidebug, "xfer %p", xfer, 0, 0, 0); |
3794 | ehci_abort_xfer(xfer, USBD_CANCELLED); | | 3794 | ehci_abort_xfer(xfer, USBD_CANCELLED); |
3795 | } | | 3795 | } |
3796 | | | 3796 | |
3797 | /* | | 3797 | /* |
3798 | * Close a device bulk pipe. | | 3798 | * Close a device bulk pipe. |
3799 | */ | | 3799 | */ |
3800 | Static void | | 3800 | Static void |
3801 | ehci_device_bulk_close(usbd_pipe_handle pipe) | | 3801 | ehci_device_bulk_close(usbd_pipe_handle pipe) |
3802 | { | | 3802 | { |
3803 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; | | 3803 | ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; |
3804 | struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; | | 3804 | struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; |
3805 | | | 3805 | |
3806 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3806 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3807 | | | 3807 | |
3808 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3808 | KASSERT(mutex_owned(&sc->sc_lock)); |
3809 | | | 3809 | |
3810 | USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0); | | 3810 | USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0); |
3811 | pipe->up_endpoint->ue_toggle = epipe->nexttoggle; | | 3811 | pipe->up_endpoint->ue_toggle = epipe->nexttoggle; |
3812 | ehci_close_pipe(pipe, sc->sc_async_head); | | 3812 | ehci_close_pipe(pipe, sc->sc_async_head); |
3813 | } | | 3813 | } |
3814 | | | 3814 | |
3815 | Static void | | 3815 | Static void |
3816 | ehci_device_bulk_done(usbd_xfer_handle xfer) | | 3816 | ehci_device_bulk_done(usbd_xfer_handle xfer) |
3817 | { | | 3817 | { |
3818 | struct ehci_xfer *ex = EXFER(xfer); | | 3818 | struct ehci_xfer *ex = EXFER(xfer); |
3819 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; | | 3819 | ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; |
3820 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; | | 3820 | struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; |
3821 | int endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; | | 3821 | int endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; |
3822 | int rd = UE_GET_DIR(endpt) == UE_DIR_IN; | | 3822 | int rd = UE_GET_DIR(endpt) == UE_DIR_IN; |
3823 | | | 3823 | |
3824 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); | | 3824 | USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); |
3825 | | | 3825 | |
3826 | USBHIST_LOG(ehcidebug, "xfer=%p, actlen=%d", | | 3826 | USBHIST_LOG(ehcidebug, "xfer=%p, actlen=%d", |
3827 | xfer, xfer->ux_actlen, 0, 0); | | 3827 | xfer, xfer->ux_actlen, 0, 0); |
3828 | | | 3828 | |
3829 | KASSERT(mutex_owned(&sc->sc_lock)); | | 3829 | KASSERT(mutex_owned(&sc->sc_lock)); |
3830 | | | 3830 | |
3831 | if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { | | 3831 | if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { |
3832 | ehci_del_intr_list(sc, ex); /* remove from active list */ | | 3832 | ehci_del_intr_list(sc, ex); /* remove from active list */ |
3833 | ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); | | 3833 | ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); |
3834 | usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, | | 3834 | usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, |
3835 | rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); | | 3835 | rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); |
3836 | } | | 3836 | } |
3837 | | | 3837 | |
3838 | USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0); | | 3838 | USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0); |
3839 | } | | 3839 | } |
3840 | | | 3840 | |
3841 | /************************/ | | 3841 | /************************/ |
3842 | | | 3842 | |
3843 | Static usbd_status | | 3843 | Static usbd_status |