Mon Mar 2 21:52:02 2015 UTC ()
ex_isdone / ux_state tidyup


(skrll)
diff -r1.234.2.34 -r1.234.2.35 src/sys/dev/usb/ehci.c
diff -r1.42.14.9 -r1.42.14.10 src/sys/dev/usb/ehcivar.h

cvs diff -r1.234.2.34 -r1.234.2.35 src/sys/dev/usb/ehci.c (switch to unified diff)

--- src/sys/dev/usb/ehci.c 2015/03/01 08:26:55 1.234.2.34
+++ src/sys/dev/usb/ehci.c 2015/03/02 21:52:02 1.234.2.35
@@ -1,4717 +1,4694 @@ @@ -1,4717 +1,4694 @@
1/* $NetBSD: ehci.c,v 1.234.2.34 2015/03/01 08:26:55 skrll Exp $ */ 1/* $NetBSD: ehci.c,v 1.234.2.35 2015/03/02 21:52:02 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.34 2015/03/01 08:26:55 skrll Exp $"); 56__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.234.2.35 2015/03/02 21:52:02 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
94static int ehcidebug = 0; 94static int ehcidebug = 0;
95 95
96SYSCTL_SETUP(sysctl_hw_ehci_setup, "sysctl hw.ehci setup") 96SYSCTL_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;
119fail: 119fail:
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
126struct ehci_pipe { 126struct 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
157Static usbd_status ehci_open(usbd_pipe_handle); 157Static usbd_status ehci_open(usbd_pipe_handle);
158Static void ehci_poll(struct usbd_bus *); 158Static void ehci_poll(struct usbd_bus *);
159Static void ehci_softintr(void *); 159Static void ehci_softintr(void *);
160Static int ehci_intr1(ehci_softc_t *); 160Static int ehci_intr1(ehci_softc_t *);
161Static void ehci_waitintr(ehci_softc_t *, usbd_xfer_handle); 161Static void ehci_waitintr(ehci_softc_t *, usbd_xfer_handle);
162Static void ehci_check_intr(ehci_softc_t *, struct ehci_xfer *); 162Static void ehci_check_intr(ehci_softc_t *, struct ehci_xfer *);
163Static void ehci_check_qh_intr(ehci_softc_t *, struct ehci_xfer *); 163Static void ehci_check_qh_intr(ehci_softc_t *, struct ehci_xfer *);
164Static void ehci_check_itd_intr(ehci_softc_t *, struct ehci_xfer *); 164Static void ehci_check_itd_intr(ehci_softc_t *, struct ehci_xfer *);
165Static void ehci_check_sitd_intr(ehci_softc_t *, struct ehci_xfer *); 165Static void ehci_check_sitd_intr(ehci_softc_t *, struct ehci_xfer *);
166Static void ehci_idone(struct ehci_xfer *); 166Static void ehci_idone(struct ehci_xfer *);
167Static void ehci_timeout(void *); 167Static void ehci_timeout(void *);
168Static void ehci_timeout_task(void *); 168Static void ehci_timeout_task(void *);
169Static void ehci_intrlist_timeout(void *); 169Static void ehci_intrlist_timeout(void *);
170Static void ehci_doorbell(void *); 170Static void ehci_doorbell(void *);
171Static void ehci_pcd(void *); 171Static void ehci_pcd(void *);
172 172
173Static usbd_xfer_handle ehci_allocx(struct usbd_bus *); 173Static usbd_xfer_handle ehci_allocx(struct usbd_bus *);
174Static void ehci_freex(struct usbd_bus *, usbd_xfer_handle); 174Static void ehci_freex(struct usbd_bus *, usbd_xfer_handle);
175Static void ehci_get_lock(struct usbd_bus *, kmutex_t **); 175Static void ehci_get_lock(struct usbd_bus *, kmutex_t **);
176Static int ehci_roothub_ctrl(struct usbd_bus *, 176Static int ehci_roothub_ctrl(struct usbd_bus *,
177 usb_device_request_t *, void *, int); 177 usb_device_request_t *, void *, int);
178 178
179Static usbd_status ehci_root_intr_transfer(usbd_xfer_handle); 179Static usbd_status ehci_root_intr_transfer(usbd_xfer_handle);
180Static usbd_status ehci_root_intr_start(usbd_xfer_handle); 180Static usbd_status ehci_root_intr_start(usbd_xfer_handle);
181Static void ehci_root_intr_abort(usbd_xfer_handle); 181Static void ehci_root_intr_abort(usbd_xfer_handle);
182Static void ehci_root_intr_close(usbd_pipe_handle); 182Static void ehci_root_intr_close(usbd_pipe_handle);
183Static void ehci_root_intr_done(usbd_xfer_handle); 183Static void ehci_root_intr_done(usbd_xfer_handle);
184 184
185Static usbd_status ehci_device_ctrl_transfer(usbd_xfer_handle); 185Static usbd_status ehci_device_ctrl_transfer(usbd_xfer_handle);
186Static usbd_status ehci_device_ctrl_start(usbd_xfer_handle); 186Static usbd_status ehci_device_ctrl_start(usbd_xfer_handle);
187Static void ehci_device_ctrl_abort(usbd_xfer_handle); 187Static void ehci_device_ctrl_abort(usbd_xfer_handle);
188Static void ehci_device_ctrl_close(usbd_pipe_handle); 188Static void ehci_device_ctrl_close(usbd_pipe_handle);
189Static void ehci_device_ctrl_done(usbd_xfer_handle); 189Static void ehci_device_ctrl_done(usbd_xfer_handle);
190 190
191Static usbd_status ehci_device_bulk_transfer(usbd_xfer_handle); 191Static usbd_status ehci_device_bulk_transfer(usbd_xfer_handle);
192Static usbd_status ehci_device_bulk_start(usbd_xfer_handle); 192Static usbd_status ehci_device_bulk_start(usbd_xfer_handle);
193Static void ehci_device_bulk_abort(usbd_xfer_handle); 193Static void ehci_device_bulk_abort(usbd_xfer_handle);
194Static void ehci_device_bulk_close(usbd_pipe_handle); 194Static void ehci_device_bulk_close(usbd_pipe_handle);
195Static void ehci_device_bulk_done(usbd_xfer_handle); 195Static void ehci_device_bulk_done(usbd_xfer_handle);
196 196
197Static usbd_status ehci_device_intr_transfer(usbd_xfer_handle); 197Static usbd_status ehci_device_intr_transfer(usbd_xfer_handle);
198Static usbd_status ehci_device_intr_start(usbd_xfer_handle); 198Static usbd_status ehci_device_intr_start(usbd_xfer_handle);
199Static void ehci_device_intr_abort(usbd_xfer_handle); 199Static void ehci_device_intr_abort(usbd_xfer_handle);
200Static void ehci_device_intr_close(usbd_pipe_handle); 200Static void ehci_device_intr_close(usbd_pipe_handle);
201Static void ehci_device_intr_done(usbd_xfer_handle); 201Static void ehci_device_intr_done(usbd_xfer_handle);
202 202
203Static usbd_status ehci_device_isoc_transfer(usbd_xfer_handle); 203Static usbd_status ehci_device_isoc_transfer(usbd_xfer_handle);
204Static usbd_status ehci_device_isoc_start(usbd_xfer_handle); 204Static usbd_status ehci_device_isoc_start(usbd_xfer_handle);
205Static void ehci_device_isoc_abort(usbd_xfer_handle); 205Static void ehci_device_isoc_abort(usbd_xfer_handle);
206Static void ehci_device_isoc_close(usbd_pipe_handle); 206Static void ehci_device_isoc_close(usbd_pipe_handle);
207Static void ehci_device_isoc_done(usbd_xfer_handle); 207Static void ehci_device_isoc_done(usbd_xfer_handle);
208 208
209Static usbd_status ehci_device_fs_isoc_transfer(usbd_xfer_handle); 209Static usbd_status ehci_device_fs_isoc_transfer(usbd_xfer_handle);
210Static usbd_status ehci_device_fs_isoc_start(usbd_xfer_handle); 210Static usbd_status ehci_device_fs_isoc_start(usbd_xfer_handle);
211Static void ehci_device_fs_isoc_abort(usbd_xfer_handle); 211Static void ehci_device_fs_isoc_abort(usbd_xfer_handle);
212Static void ehci_device_fs_isoc_close(usbd_pipe_handle); 212Static void ehci_device_fs_isoc_close(usbd_pipe_handle);
213Static void ehci_device_fs_isoc_done(usbd_xfer_handle); 213Static void ehci_device_fs_isoc_done(usbd_xfer_handle);
214 214
215Static void ehci_device_clear_toggle(usbd_pipe_handle); 215Static void ehci_device_clear_toggle(usbd_pipe_handle);
216Static void ehci_noop(usbd_pipe_handle); 216Static void ehci_noop(usbd_pipe_handle);
217 217
218Static void ehci_disown(ehci_softc_t *, int, int); 218Static void ehci_disown(ehci_softc_t *, int, int);
219 219
220Static ehci_soft_qh_t *ehci_alloc_sqh(ehci_softc_t *); 220Static ehci_soft_qh_t *ehci_alloc_sqh(ehci_softc_t *);
221Static void ehci_free_sqh(ehci_softc_t *, ehci_soft_qh_t *); 221Static void ehci_free_sqh(ehci_softc_t *, ehci_soft_qh_t *);
222 222
223Static ehci_soft_qtd_t *ehci_alloc_sqtd(ehci_softc_t *); 223Static ehci_soft_qtd_t *ehci_alloc_sqtd(ehci_softc_t *);
224Static void ehci_free_sqtd(ehci_softc_t *, ehci_soft_qtd_t *); 224Static void ehci_free_sqtd(ehci_softc_t *, ehci_soft_qtd_t *);
225Static usbd_status ehci_alloc_sqtd_chain(struct ehci_pipe *, 225Static 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 **);
228Static void ehci_free_sqtd_chain(ehci_softc_t *, ehci_soft_qtd_t *, 228Static void ehci_free_sqtd_chain(ehci_softc_t *, ehci_soft_qtd_t *,
229 ehci_soft_qtd_t *); 229 ehci_soft_qtd_t *);
230 230
231Static ehci_soft_itd_t *ehci_alloc_itd(ehci_softc_t *); 231Static ehci_soft_itd_t *ehci_alloc_itd(ehci_softc_t *);
232Static ehci_soft_sitd_t *ehci_alloc_sitd(ehci_softc_t *); 232Static ehci_soft_sitd_t *ehci_alloc_sitd(ehci_softc_t *);
233Static void ehci_free_itd(ehci_softc_t *, ehci_soft_itd_t *); 233Static void ehci_free_itd(ehci_softc_t *, ehci_soft_itd_t *);
234Static void ehci_free_sitd(ehci_softc_t *, ehci_soft_sitd_t *); 234Static void ehci_free_sitd(ehci_softc_t *, ehci_soft_sitd_t *);
235Static void ehci_rem_free_itd_chain(ehci_softc_t *, 235Static void ehci_rem_free_itd_chain(ehci_softc_t *,
236 struct ehci_xfer *); 236 struct ehci_xfer *);
237Static void ehci_rem_free_sitd_chain(ehci_softc_t *, 237Static void ehci_rem_free_sitd_chain(ehci_softc_t *,
238 struct ehci_xfer *); 238 struct ehci_xfer *);
239Static void ehci_abort_isoc_xfer(usbd_xfer_handle, 239Static void ehci_abort_isoc_xfer(usbd_xfer_handle,
240 usbd_status); 240 usbd_status);
241 241
242Static usbd_status ehci_device_request(usbd_xfer_handle); 242Static usbd_status ehci_device_request(usbd_xfer_handle);
243 243
244Static usbd_status ehci_device_setintr(ehci_softc_t *, ehci_soft_qh_t *, 244Static usbd_status ehci_device_setintr(ehci_softc_t *, ehci_soft_qh_t *,
245 int); 245 int);
246 246
247Static void ehci_add_qh(ehci_softc_t *, ehci_soft_qh_t *, 247Static void ehci_add_qh(ehci_softc_t *, ehci_soft_qh_t *,
248 ehci_soft_qh_t *); 248 ehci_soft_qh_t *);
249Static void ehci_rem_qh(ehci_softc_t *, ehci_soft_qh_t *, 249Static void ehci_rem_qh(ehci_softc_t *, ehci_soft_qh_t *,
250 ehci_soft_qh_t *); 250 ehci_soft_qh_t *);
251Static void ehci_set_qh_qtd(ehci_soft_qh_t *, ehci_soft_qtd_t *); 251Static void ehci_set_qh_qtd(ehci_soft_qh_t *, ehci_soft_qtd_t *);
252Static void ehci_sync_hc(ehci_softc_t *); 252Static void ehci_sync_hc(ehci_softc_t *);
253 253
254Static void ehci_close_pipe(usbd_pipe_handle, ehci_soft_qh_t *); 254Static void ehci_close_pipe(usbd_pipe_handle, ehci_soft_qh_t *);
255Static void ehci_abort_xfer(usbd_xfer_handle, usbd_status); 255Static void ehci_abort_xfer(usbd_xfer_handle, usbd_status);
256 256
257#ifdef EHCI_DEBUG 257#ifdef EHCI_DEBUG
258Static ehci_softc_t *theehci; 258Static ehci_softc_t *theehci;
259void ehci_dump(void); 259void ehci_dump(void);
260#endif 260#endif
261 261
262#ifdef EHCI_DEBUG 262#ifdef EHCI_DEBUG
263Static void ehci_dump_regs(ehci_softc_t *); 263Static void ehci_dump_regs(ehci_softc_t *);
264Static void ehci_dump_sqtds(ehci_soft_qtd_t *); 264Static void ehci_dump_sqtds(ehci_soft_qtd_t *);
265Static void ehci_dump_sqtd(ehci_soft_qtd_t *); 265Static void ehci_dump_sqtd(ehci_soft_qtd_t *);
266Static void ehci_dump_qtd(ehci_qtd_t *); 266Static void ehci_dump_qtd(ehci_qtd_t *);
267Static void ehci_dump_sqh(ehci_soft_qh_t *); 267Static void ehci_dump_sqh(ehci_soft_qh_t *);
268Static void ehci_dump_sitd(struct ehci_soft_itd *); 268Static void ehci_dump_sitd(struct ehci_soft_itd *);
269Static void ehci_dump_itd(struct ehci_soft_itd *); 269Static void ehci_dump_itd(struct ehci_soft_itd *);
270Static void ehci_dump_exfer(struct ehci_xfer *); 270Static 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
284Static const struct usbd_bus_methods ehci_bus_methods = { 284Static 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
294Static const struct usbd_pipe_methods ehci_root_intr_methods = { 294Static 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
303Static const struct usbd_pipe_methods ehci_device_ctrl_methods = { 303Static 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
312Static const struct usbd_pipe_methods ehci_device_intr_methods = { 312Static 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
321Static const struct usbd_pipe_methods ehci_device_bulk_methods = { 321Static 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
330Static const struct usbd_pipe_methods ehci_device_isoc_methods = { 330Static 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
339Static const struct usbd_pipe_methods ehci_device_fs_isoc_methods = { 339Static 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
348static const uint8_t revbits[EHCI_MAX_POLLRATE] = { 348static const uint8_t revbits[EHCI_MAX_POLLRATE] = {
3490x00,0x40,0x20,0x60,0x10,0x50,0x30,0x70,0x08,0x48,0x28,0x68,0x18,0x58,0x38,0x78, 3490x00,0x40,0x20,0x60,0x10,0x50,0x30,0x70,0x08,0x48,0x28,0x68,0x18,0x58,0x38,0x78,
3500x04,0x44,0x24,0x64,0x14,0x54,0x34,0x74,0x0c,0x4c,0x2c,0x6c,0x1c,0x5c,0x3c,0x7c, 3500x04,0x44,0x24,0x64,0x14,0x54,0x34,0x74,0x0c,0x4c,0x2c,0x6c,0x1c,0x5c,0x3c,0x7c,
3510x02,0x42,0x22,0x62,0x12,0x52,0x32,0x72,0x0a,0x4a,0x2a,0x6a,0x1a,0x5a,0x3a,0x7a, 3510x02,0x42,0x22,0x62,0x12,0x52,0x32,0x72,0x0a,0x4a,0x2a,0x6a,0x1a,0x5a,0x3a,0x7a,
3520x06,0x46,0x26,0x66,0x16,0x56,0x36,0x76,0x0e,0x4e,0x2e,0x6e,0x1e,0x5e,0x3e,0x7e, 3520x06,0x46,0x26,0x66,0x16,0x56,0x36,0x76,0x0e,0x4e,0x2e,0x6e,0x1e,0x5e,0x3e,0x7e,
3530x01,0x41,0x21,0x61,0x11,0x51,0x31,0x71,0x09,0x49,0x29,0x69,0x19,0x59,0x39,0x79, 3530x01,0x41,0x21,0x61,0x11,0x51,0x31,0x71,0x09,0x49,0x29,0x69,0x19,0x59,0x39,0x79,
3540x05,0x45,0x25,0x65,0x15,0x55,0x35,0x75,0x0d,0x4d,0x2d,0x6d,0x1d,0x5d,0x3d,0x7d, 3540x05,0x45,0x25,0x65,0x15,0x55,0x35,0x75,0x0d,0x4d,0x2d,0x6d,0x1d,0x5d,0x3d,0x7d,
3550x03,0x43,0x23,0x63,0x13,0x53,0x33,0x73,0x0b,0x4b,0x2b,0x6b,0x1b,0x5b,0x3b,0x7b, 3550x03,0x43,0x23,0x63,0x13,0x53,0x33,0x73,0x0b,0x4b,0x2b,0x6b,0x1b,0x5b,0x3b,0x7b,
3560x07,0x47,0x27,0x67,0x17,0x57,0x37,0x77,0x0f,0x4f,0x2f,0x6f,0x1f,0x5f,0x3f,0x7f, 3560x07,0x47,0x27,0x67,0x17,0x57,0x37,0x77,0x0f,0x4f,0x2f,0x6f,0x1f,0x5f,0x3f,0x7f,
357}; 357};
358 358
359int 359int
360ehci_init(ehci_softc_t *sc) 360ehci_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
614int 614int
615ehci_intr(void *v) 615ehci_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
643done: 643done:
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
648Static int 648Static int
649ehci_intr1(ehci_softc_t *sc) 649ehci_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
715Static void 715Static void
716ehci_doorbell(void *addr) 716ehci_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
725Static void 725Static void
726ehci_pcd(void *addr) 726ehci_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
759done: 759done:
760 mutex_exit(&sc->sc_lock); 760 mutex_exit(&sc->sc_lock);
761} 761}
762 762
763Static void 763Static void
764ehci_softintr(void *v) 764ehci_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. */
798Static void 798Static void
799ehci_check_intr(ehci_softc_t *sc, struct ehci_xfer *ex) 799ehci_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
821Static void 821Static void
822ehci_check_qh_intr(ehci_softc_t *sc, struct ehci_xfer *ex) 822ehci_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
910Static void 910Static void
911ehci_check_itd_intr(ehci_softc_t *sc, struct ehci_xfer *ex) 911ehci_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;
956done: 956done:
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
962void 962void
963ehci_check_sitd_intr(ehci_softc_t *sc, struct ehci_xfer *ex) 963ehci_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
1004Static void 1004Static void
1005ehci_idone(struct ehci_xfer *ex) 1005ehci_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) { 
1022 printf("ehci_idone: ex=%p is done!\n", ex); 
1023#ifdef EHCI_DEBUG 1021#ifdef EHCI_DEBUG
 1022 if (ex->ex_isdone) {
1024 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); 1023 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0);
1025 ehci_dump_exfer(ex); 1024 ehci_dump_exfer(ex);
1026 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); 1025 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0);
1027#endif 
1028 return; 
1029 } 1026 }
1030 ex->ex_isdone = 1; 1027#endif
 1028 KASSERT(!ex->ex_isdone);
 1029 ex->ex_isdone = true;
1031#endif 1030#endif
1032 1031
1033 if (xfer->ux_status == USBD_CANCELLED || 1032 if (xfer->ux_status == USBD_CANCELLED ||
1034 xfer->ux_status == USBD_TIMEOUT) { 1033 xfer->ux_status == USBD_TIMEOUT) {
1035 USBHIST_LOG(ehcidebug, "aborted xfer=%p", xfer, 0, 0, 0); 1034 USBHIST_LOG(ehcidebug, "aborted xfer=%p", xfer, 0, 0, 0);
1036 return; 1035 return;
1037 } 1036 }
1038 1037
1039 USBHIST_LOG(ehcidebug, "xfer=%p, pipe=%p ready", xfer, epipe, 0, 0); 1038 USBHIST_LOG(ehcidebug, "xfer=%p, pipe=%p ready", xfer, epipe, 0, 0);
1040#ifdef EHCI_DEBUG 1039#ifdef EHCI_DEBUG
1041 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); 1040 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0);
1042 ehci_dump_sqtds(ex->ex_sqtdstart); 1041 ehci_dump_sqtds(ex->ex_sqtdstart);
1043 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); 1042 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0);
1044#endif 1043#endif
1045 1044
1046 /* The transfer is done, compute actual length and status. */ 1045 /* The transfer is done, compute actual length and status. */
1047 1046
1048 u_int xfertype, speed; 1047 u_int xfertype, speed;
1049 1048
1050 xfertype = UE_GET_XFERTYPE(xfer->ux_pipe->up_endpoint->ue_edesc->bmAttributes); 1049 xfertype = UE_GET_XFERTYPE(xfer->ux_pipe->up_endpoint->ue_edesc->bmAttributes);
1051 speed = xfer->ux_pipe->up_dev->ud_speed; 1050 speed = xfer->ux_pipe->up_dev->ud_speed;
1052 if (xfertype == UE_ISOCHRONOUS && speed == USB_SPEED_HIGH) { 1051 if (xfertype == UE_ISOCHRONOUS && speed == USB_SPEED_HIGH) {
1053 /* HS isoc transfer */ 1052 /* HS isoc transfer */
1054 1053
1055 struct ehci_soft_itd *itd; 1054 struct ehci_soft_itd *itd;
1056 int i, nframes, len, uframes; 1055 int i, nframes, len, uframes;
1057 1056
1058 nframes = 0; 1057 nframes = 0;
1059 actlen = 0; 1058 actlen = 0;
1060 1059
1061 i = xfer->ux_pipe->up_endpoint->ue_edesc->bInterval; 1060 i = xfer->ux_pipe->up_endpoint->ue_edesc->bInterval;
1062 uframes = min(1 << (i - 1), USB_UFRAMES_PER_FRAME); 1061 uframes = min(1 << (i - 1), USB_UFRAMES_PER_FRAME);
1063 1062
1064 for (itd = ex->ex_itdstart; itd != NULL; itd = itd->xfer_next) { 1063 for (itd = ex->ex_itdstart; itd != NULL; itd = itd->xfer_next) {
1065 usb_syncmem(&itd->dma,itd->offs + offsetof(ehci_itd_t,itd_ctl), 1064 usb_syncmem(&itd->dma,itd->offs + offsetof(ehci_itd_t,itd_ctl),
1066 sizeof(itd->itd.itd_ctl), BUS_DMASYNC_POSTWRITE | 1065 sizeof(itd->itd.itd_ctl), BUS_DMASYNC_POSTWRITE |
1067 BUS_DMASYNC_POSTREAD); 1066 BUS_DMASYNC_POSTREAD);
1068 1067
1069 for (i = 0; i < EHCI_ITD_NUFRAMES; i += uframes) { 1068 for (i = 0; i < EHCI_ITD_NUFRAMES; i += uframes) {
1070 /* 1069 /*
1071 * XXX - driver didn't fill in the frame full 1070 * XXX - driver didn't fill in the frame full
1072 * of uframes. This leads to scheduling 1071 * of uframes. This leads to scheduling
1073 * inefficiencies, but working around 1072 * inefficiencies, but working around
1074 * this doubles complexity of tracking 1073 * this doubles complexity of tracking
1075 * an xfer. 1074 * an xfer.
1076 */ 1075 */
1077 if (nframes >= xfer->ux_nframes) 1076 if (nframes >= xfer->ux_nframes)
1078 break; 1077 break;
1079 1078
1080 status = le32toh(itd->itd.itd_ctl[i]); 1079 status = le32toh(itd->itd.itd_ctl[i]);
1081 len = EHCI_ITD_GET_LEN(status); 1080 len = EHCI_ITD_GET_LEN(status);
1082 if (EHCI_ITD_GET_STATUS(status) != 0) 1081 if (EHCI_ITD_GET_STATUS(status) != 0)
1083 len = 0; /*No valid data on error*/ 1082 len = 0; /*No valid data on error*/
1084 1083
1085 xfer->ux_frlengths[nframes++] = len; 1084 xfer->ux_frlengths[nframes++] = len;
1086 actlen += len; 1085 actlen += len;
1087 } 1086 }
1088 1087
1089 if (nframes >= xfer->ux_nframes) 1088 if (nframes >= xfer->ux_nframes)
1090 break; 1089 break;
1091 } 1090 }
1092 1091
1093 xfer->ux_actlen = actlen; 1092 xfer->ux_actlen = actlen;
1094 xfer->ux_status = USBD_NORMAL_COMPLETION; 1093 xfer->ux_status = USBD_NORMAL_COMPLETION;
1095 goto end; 1094 goto end;
1096 } 1095 }
1097 1096
1098 if (xfertype == UE_ISOCHRONOUS && speed == USB_SPEED_FULL) { 1097 if (xfertype == UE_ISOCHRONOUS && speed == USB_SPEED_FULL) {
1099 /* FS isoc transfer */ 1098 /* FS isoc transfer */
1100 struct ehci_soft_sitd *sitd; 1099 struct ehci_soft_sitd *sitd;
1101 int nframes, len; 1100 int nframes, len;
1102 1101
1103 nframes = 0; 1102 nframes = 0;
1104 actlen = 0; 1103 actlen = 0;
1105 1104
1106 for (sitd = ex->ex_sitdstart; sitd != NULL; sitd = sitd->xfer_next) { 1105 for (sitd = ex->ex_sitdstart; sitd != NULL; sitd = sitd->xfer_next) {
1107 usb_syncmem(&sitd->dma,sitd->offs + offsetof(ehci_sitd_t, sitd_buffer), 1106 usb_syncmem(&sitd->dma,sitd->offs + offsetof(ehci_sitd_t, sitd_buffer),
1108 sizeof(sitd->sitd.sitd_buffer), BUS_DMASYNC_POSTWRITE | 1107 sizeof(sitd->sitd.sitd_buffer), BUS_DMASYNC_POSTWRITE |
1109 BUS_DMASYNC_POSTREAD); 1108 BUS_DMASYNC_POSTREAD);
1110 1109
1111 /* 1110 /*
1112 * XXX - driver didn't fill in the frame full 1111 * XXX - driver didn't fill in the frame full
1113 * of uframes. This leads to scheduling 1112 * of uframes. This leads to scheduling
1114 * inefficiencies, but working around 1113 * inefficiencies, but working around
1115 * this doubles complexity of tracking 1114 * this doubles complexity of tracking
1116 * an xfer. 1115 * an xfer.
1117 */ 1116 */
1118 if (nframes >= xfer->ux_nframes) 1117 if (nframes >= xfer->ux_nframes)
1119 break; 1118 break;
1120 1119
1121 status = le32toh(sitd->sitd.sitd_trans); 1120 status = le32toh(sitd->sitd.sitd_trans);
1122 len = EHCI_SITD_GET_LEN(status); 1121 len = EHCI_SITD_GET_LEN(status);
1123 if (status & (EHCI_SITD_ERR|EHCI_SITD_BUFERR| 1122 if (status & (EHCI_SITD_ERR|EHCI_SITD_BUFERR|
1124 EHCI_SITD_BABBLE|EHCI_SITD_XACTERR|EHCI_SITD_MISS)) { 1123 EHCI_SITD_BABBLE|EHCI_SITD_XACTERR|EHCI_SITD_MISS)) {
1125 /* No valid data on error */ 1124 /* No valid data on error */
1126 len = xfer->ux_frlengths[nframes]; 1125 len = xfer->ux_frlengths[nframes];
1127 } 1126 }
1128 1127
1129 /* 1128 /*
1130 * frlengths[i]: # of bytes to send 1129 * frlengths[i]: # of bytes to send
1131 * len: # of bytes host didn't send 1130 * len: # of bytes host didn't send
1132 */ 1131 */
1133 xfer->ux_frlengths[nframes] -= len; 1132 xfer->ux_frlengths[nframes] -= len;
1134 /* frlengths[i]: # of bytes host sent */ 1133 /* frlengths[i]: # of bytes host sent */
1135 actlen += xfer->ux_frlengths[nframes++]; 1134 actlen += xfer->ux_frlengths[nframes++];
1136 1135
1137 if (nframes >= xfer->ux_nframes) 1136 if (nframes >= xfer->ux_nframes)
1138 break; 1137 break;
1139 } 1138 }
1140 1139
1141 xfer->ux_actlen = actlen; 1140 xfer->ux_actlen = actlen;
1142 xfer->ux_status = USBD_NORMAL_COMPLETION; 1141 xfer->ux_status = USBD_NORMAL_COMPLETION;
1143 goto end; 1142 goto end;
1144 } 1143 }
1145 KASSERT(xfertype != UE_ISOCHRONOUS); 1144 KASSERT(xfertype != UE_ISOCHRONOUS);
1146 1145
1147 /* Continue processing xfers using queue heads */ 1146 /* Continue processing xfers using queue heads */
1148 1147
1149 lsqtd = ex->ex_sqtdend; 1148 lsqtd = ex->ex_sqtdend;
1150 actlen = 0; 1149 actlen = 0;
1151 for (sqtd = ex->ex_sqtdstart; sqtd != lsqtd->nextqtd; 1150 for (sqtd = ex->ex_sqtdstart; sqtd != lsqtd->nextqtd;
1152 sqtd = sqtd->nextqtd) { 1151 sqtd = sqtd->nextqtd) {
1153 usb_syncmem(&sqtd->dma, sqtd->offs, sizeof(sqtd->qtd), 1152 usb_syncmem(&sqtd->dma, sqtd->offs, sizeof(sqtd->qtd),
1154 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 1153 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
1155 nstatus = le32toh(sqtd->qtd.qtd_status); 1154 nstatus = le32toh(sqtd->qtd.qtd_status);
1156 if (nstatus & EHCI_QTD_ACTIVE) 1155 if (nstatus & EHCI_QTD_ACTIVE)
1157 break; 1156 break;
1158 1157
1159 status = nstatus; 1158 status = nstatus;
1160 if (EHCI_QTD_GET_PID(status) != EHCI_QTD_PID_SETUP) 1159 if (EHCI_QTD_GET_PID(status) != EHCI_QTD_PID_SETUP)
1161 actlen += sqtd->len - EHCI_QTD_GET_BYTES(status); 1160 actlen += sqtd->len - EHCI_QTD_GET_BYTES(status);
1162 } 1161 }
1163 1162
1164 1163
1165 /* 1164 /*
1166 * If there are left over TDs we need to update the toggle. 1165 * If there are left over TDs we need to update the toggle.
1167 * The default pipe doesn't need it since control transfers 1166 * The default pipe doesn't need it since control transfers
1168 * start the toggle at 0 every time. 1167 * start the toggle at 0 every time.
1169 * For a short transfer we need to update the toggle for the missing 1168 * For a short transfer we need to update the toggle for the missing
1170 * packets within the qTD. 1169 * packets within the qTD.
1171 */ 1170 */
1172 if ((sqtd != lsqtd->nextqtd || EHCI_QTD_GET_BYTES(status)) && 1171 if ((sqtd != lsqtd->nextqtd || EHCI_QTD_GET_BYTES(status)) &&
1173 xfer->ux_pipe->up_dev->ud_pipe0 != xfer->ux_pipe) { 1172 xfer->ux_pipe->up_dev->ud_pipe0 != xfer->ux_pipe) {
1174 USBHIST_LOG(ehcidebug, 1173 USBHIST_LOG(ehcidebug,
1175 "toggle update status=0x%08x nstatus=0x%08x", 1174 "toggle update status=0x%08x nstatus=0x%08x",
1176 status, nstatus, 0, 0); 1175 status, nstatus, 0, 0);
1177#if 0 1176#if 0
1178 ehci_dump_sqh(epipe->sqh); 1177 ehci_dump_sqh(epipe->sqh);
1179 ehci_dump_sqtds(ex->ex_sqtdstart); 1178 ehci_dump_sqtds(ex->ex_sqtdstart);
1180#endif 1179#endif
1181 epipe->nexttoggle = EHCI_QTD_GET_TOGGLE(nstatus); 1180 epipe->nexttoggle = EHCI_QTD_GET_TOGGLE(nstatus);
1182 } 1181 }
1183 1182
1184 USBHIST_LOG(ehcidebug, "len=%d actlen=%d status=0x%08x", xfer->ux_length, 1183 USBHIST_LOG(ehcidebug, "len=%d actlen=%d status=0x%08x", xfer->ux_length,
1185 actlen, status, 0); 1184 actlen, status, 0);
1186 xfer->ux_actlen = actlen; 1185 xfer->ux_actlen = actlen;
1187 if (status & EHCI_QTD_HALTED) { 1186 if (status & EHCI_QTD_HALTED) {
1188#ifdef EHCI_DEBUG 1187#ifdef EHCI_DEBUG
1189 USBHIST_LOG(ehcidebug, "halted addr=%d endpt=0x%02x", 1188 USBHIST_LOG(ehcidebug, "halted addr=%d endpt=0x%02x",
1190 xfer->ux_pipe->up_dev->ud_addr, 1189 xfer->ux_pipe->up_dev->ud_addr,
1191 xfer->ux_pipe->up_endpoint->ue_edesc->bEndpointAddress, 0, 0); 1190 xfer->ux_pipe->up_endpoint->ue_edesc->bEndpointAddress, 0, 0);
1192 USBHIST_LOG(ehcidebug, "cerr=%d pid=%d", 1191 USBHIST_LOG(ehcidebug, "cerr=%d pid=%d",
1193 EHCI_QTD_GET_CERR(status), EHCI_QTD_GET_PID(status), 1192 EHCI_QTD_GET_CERR(status), EHCI_QTD_GET_PID(status),
1194 0, 0); 1193 0, 0);
1195 USBHIST_LOG(ehcidebug, 1194 USBHIST_LOG(ehcidebug,
1196 "active =%d halted=%d buferr=%d babble=%d", 1195 "active =%d halted=%d buferr=%d babble=%d",
1197 status & EHCI_QTD_ACTIVE ? 1 : 0, 1196 status & EHCI_QTD_ACTIVE ? 1 : 0,
1198 status & EHCI_QTD_HALTED ? 1 : 0, 1197 status & EHCI_QTD_HALTED ? 1 : 0,
1199 status & EHCI_QTD_BUFERR ? 1 : 0, 1198 status & EHCI_QTD_BUFERR ? 1 : 0,
1200 status & EHCI_QTD_BABBLE ? 1 : 0); 1199 status & EHCI_QTD_BABBLE ? 1 : 0);
1201 1200
1202 USBHIST_LOG(ehcidebug, 1201 USBHIST_LOG(ehcidebug,
1203 "xacterr=%d missed=%d split =%d ping =%d", 1202 "xacterr=%d missed=%d split =%d ping =%d",
1204 status & EHCI_QTD_XACTERR ? 1 : 0, 1203 status & EHCI_QTD_XACTERR ? 1 : 0,
1205 status & EHCI_QTD_MISSEDMICRO ? 1 : 0, 1204 status & EHCI_QTD_MISSEDMICRO ? 1 : 0,
1206 status & EHCI_QTD_SPLITXSTATE ? 1 : 0, 1205 status & EHCI_QTD_SPLITXSTATE ? 1 : 0,
1207 status & EHCI_QTD_PINGSTATE ? 1 : 0); 1206 status & EHCI_QTD_PINGSTATE ? 1 : 0);
1208 1207
1209 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); 1208 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0);
1210 ehci_dump_sqh(epipe->sqh); 1209 ehci_dump_sqh(epipe->sqh);
1211 ehci_dump_sqtds(ex->ex_sqtdstart); 1210 ehci_dump_sqtds(ex->ex_sqtdstart);
1212 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); 1211 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0);
1213#endif 1212#endif
1214 /* low&full speed has an extra error flag */ 1213 /* low&full speed has an extra error flag */
1215 if (EHCI_QH_GET_EPS(epipe->sqh->qh.qh_endp) != 1214 if (EHCI_QH_GET_EPS(epipe->sqh->qh.qh_endp) !=
1216 EHCI_QH_SPEED_HIGH) 1215 EHCI_QH_SPEED_HIGH)
1217 status &= EHCI_QTD_STATERRS | EHCI_QTD_PINGSTATE; 1216 status &= EHCI_QTD_STATERRS | EHCI_QTD_PINGSTATE;
1218 else 1217 else
1219 status &= EHCI_QTD_STATERRS; 1218 status &= EHCI_QTD_STATERRS;
1220 if (status == 0) /* no other errors means a stall */ { 1219 if (status == 0) /* no other errors means a stall */ {
1221 xfer->ux_status = USBD_STALLED; 1220 xfer->ux_status = USBD_STALLED;
1222 } else { 1221 } else {
1223 xfer->ux_status = USBD_IOERROR; /* more info XXX */ 1222 xfer->ux_status = USBD_IOERROR; /* more info XXX */
1224 } 1223 }
1225 /* XXX need to reset TT on missed microframe */ 1224 /* XXX need to reset TT on missed microframe */
1226 if (status & EHCI_QTD_MISSEDMICRO) { 1225 if (status & EHCI_QTD_MISSEDMICRO) {
1227 printf("%s: missed microframe, TT reset not " 1226 printf("%s: missed microframe, TT reset not "
1228 "implemented, hub might be inoperational\n", 1227 "implemented, hub might be inoperational\n",
1229 device_xname(sc->sc_dev)); 1228 device_xname(sc->sc_dev));
1230 } 1229 }
1231 } else { 1230 } else {
1232 xfer->ux_status = USBD_NORMAL_COMPLETION; 1231 xfer->ux_status = USBD_NORMAL_COMPLETION;
1233 } 1232 }
1234 1233
1235 end: 1234 end:
1236 /* 1235 /*
1237 * XXX transfer_complete memcpys out transfer data (for in endpoints) 1236 * XXX transfer_complete memcpys out transfer data (for in endpoints)
1238 * during this call, before methods->done is called: dma sync required 1237 * during this call, before methods->done is called: dma sync required
1239 * beforehand? 1238 * beforehand?
1240 */ 1239 */
1241 usb_transfer_complete(xfer); 1240 usb_transfer_complete(xfer);
1242 USBHIST_LOG(ehcidebug, "ex=%p done", ex, 0, 0, 0); 1241 USBHIST_LOG(ehcidebug, "ex=%p done", ex, 0, 0, 0);
1243} 1242}
1244 1243
1245/* 1244/*
1246 * Wait here until controller claims to have an interrupt. 1245 * Wait here until controller claims to have an interrupt.
1247 * Then call ehci_intr and return. Use timeout to avoid waiting 1246 * Then call ehci_intr and return. Use timeout to avoid waiting
1248 * too long. 1247 * too long.
1249 */ 1248 */
1250Static void 1249Static void
1251ehci_waitintr(ehci_softc_t *sc, usbd_xfer_handle xfer) 1250ehci_waitintr(ehci_softc_t *sc, usbd_xfer_handle xfer)
1252{ 1251{
1253 int timo; 1252 int timo;
1254 uint32_t intrs; 1253 uint32_t intrs;
1255 1254
1256 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1255 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1257 1256
1258 xfer->ux_status = USBD_IN_PROGRESS; 1257 xfer->ux_status = USBD_IN_PROGRESS;
1259 for (timo = xfer->ux_timeout; timo >= 0; timo--) { 1258 for (timo = xfer->ux_timeout; timo >= 0; timo--) {
1260 usb_delay_ms(&sc->sc_bus, 1); 1259 usb_delay_ms(&sc->sc_bus, 1);
1261 if (sc->sc_dying) 1260 if (sc->sc_dying)
1262 break; 1261 break;
1263 intrs = EHCI_STS_INTRS(EOREAD4(sc, EHCI_USBSTS)) & 1262 intrs = EHCI_STS_INTRS(EOREAD4(sc, EHCI_USBSTS)) &
1264 sc->sc_eintrs; 1263 sc->sc_eintrs;
1265 USBHIST_LOG(ehcidebug, "0x%04x", intrs, 0, 0, 0); 1264 USBHIST_LOG(ehcidebug, "0x%04x", intrs, 0, 0, 0);
1266#ifdef EHCI_DEBUG 1265#ifdef EHCI_DEBUG
1267 if (ehcidebug > 15) 1266 if (ehcidebug > 15)
1268 ehci_dump_regs(sc); 1267 ehci_dump_regs(sc);
1269#endif 1268#endif
1270 if (intrs) { 1269 if (intrs) {
1271 mutex_spin_enter(&sc->sc_intr_lock); 1270 mutex_spin_enter(&sc->sc_intr_lock);
1272 ehci_intr1(sc); 1271 ehci_intr1(sc);
1273 mutex_spin_exit(&sc->sc_intr_lock); 1272 mutex_spin_exit(&sc->sc_intr_lock);
1274 if (xfer->ux_status != USBD_IN_PROGRESS) 1273 if (xfer->ux_status != USBD_IN_PROGRESS)
1275 return; 1274 return;
1276 } 1275 }
1277 } 1276 }
1278 1277
1279 /* Timeout */ 1278 /* Timeout */
1280 USBHIST_LOG(ehcidebug, "timeout", 0, 0, 0, 0); 1279 USBHIST_LOG(ehcidebug, "timeout", 0, 0, 0, 0);
1281 xfer->ux_status = USBD_TIMEOUT; 1280 xfer->ux_status = USBD_TIMEOUT;
1282 mutex_enter(&sc->sc_lock); 1281 mutex_enter(&sc->sc_lock);
1283 usb_transfer_complete(xfer); 1282 usb_transfer_complete(xfer);
1284 mutex_exit(&sc->sc_lock); 1283 mutex_exit(&sc->sc_lock);
1285 /* XXX should free TD */ 1284 /* XXX should free TD */
1286} 1285}
1287 1286
1288Static void 1287Static void
1289ehci_poll(struct usbd_bus *bus) 1288ehci_poll(struct usbd_bus *bus)
1290{ 1289{
1291 ehci_softc_t *sc = bus->ub_hcpriv; 1290 ehci_softc_t *sc = bus->ub_hcpriv;
1292 1291
1293 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1292 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1294 1293
1295#ifdef EHCI_DEBUG 1294#ifdef EHCI_DEBUG
1296 static int last; 1295 static int last;
1297 int new; 1296 int new;
1298 new = EHCI_STS_INTRS(EOREAD4(sc, EHCI_USBSTS)); 1297 new = EHCI_STS_INTRS(EOREAD4(sc, EHCI_USBSTS));
1299 if (new != last) { 1298 if (new != last) {
1300 USBHIST_LOG(ehcidebug, "intrs=0x%04x", new, 0, 0, 0); 1299 USBHIST_LOG(ehcidebug, "intrs=0x%04x", new, 0, 0, 0);
1301 last = new; 1300 last = new;
1302 } 1301 }
1303#endif 1302#endif
1304 1303
1305 if (EOREAD4(sc, EHCI_USBSTS) & sc->sc_eintrs) { 1304 if (EOREAD4(sc, EHCI_USBSTS) & sc->sc_eintrs) {
1306 mutex_spin_enter(&sc->sc_intr_lock); 1305 mutex_spin_enter(&sc->sc_intr_lock);
1307 ehci_intr1(sc); 1306 ehci_intr1(sc);
1308 mutex_spin_exit(&sc->sc_intr_lock); 1307 mutex_spin_exit(&sc->sc_intr_lock);
1309 } 1308 }
1310} 1309}
1311 1310
1312void 1311void
1313ehci_childdet(device_t self, device_t child) 1312ehci_childdet(device_t self, device_t child)
1314{ 1313{
1315 struct ehci_softc *sc = device_private(self); 1314 struct ehci_softc *sc = device_private(self);
1316 1315
1317 KASSERT(sc->sc_child == child); 1316 KASSERT(sc->sc_child == child);
1318 sc->sc_child = NULL; 1317 sc->sc_child = NULL;
1319} 1318}
1320 1319
1321int 1320int
1322ehci_detach(struct ehci_softc *sc, int flags) 1321ehci_detach(struct ehci_softc *sc, int flags)
1323{ 1322{
1324 int rv = 0; 1323 int rv = 0;
1325 1324
1326 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1325 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1327 1326
1328 if (sc->sc_child != NULL) 1327 if (sc->sc_child != NULL)
1329 rv = config_detach(sc->sc_child, flags); 1328 rv = config_detach(sc->sc_child, flags);
1330 1329
1331 if (rv != 0) 1330 if (rv != 0)
1332 return rv; 1331 return rv;
1333 1332
1334 callout_halt(&sc->sc_tmo_intrlist, NULL); 1333 callout_halt(&sc->sc_tmo_intrlist, NULL);
1335 callout_destroy(&sc->sc_tmo_intrlist); 1334 callout_destroy(&sc->sc_tmo_intrlist);
1336 1335
1337 /* XXX free other data structures XXX */ 1336 /* XXX free other data structures XXX */
1338 if (sc->sc_softitds) 1337 if (sc->sc_softitds)
1339 kmem_free(sc->sc_softitds, 1338 kmem_free(sc->sc_softitds,
1340 sc->sc_flsize * sizeof(ehci_soft_itd_t *)); 1339 sc->sc_flsize * sizeof(ehci_soft_itd_t *));
1341 cv_destroy(&sc->sc_doorbell); 1340 cv_destroy(&sc->sc_doorbell);
1342 cv_destroy(&sc->sc_softwake_cv); 1341 cv_destroy(&sc->sc_softwake_cv);
1343 1342
1344#if 0 1343#if 0
1345 /* XXX destroyed in ehci_pci.c as it controls ehci_intr access */ 1344 /* XXX destroyed in ehci_pci.c as it controls ehci_intr access */
1346 1345
1347 softint_disestablish(sc->sc_doorbell_si); 1346 softint_disestablish(sc->sc_doorbell_si);
1348 softint_disestablish(sc->sc_pcd_si); 1347 softint_disestablish(sc->sc_pcd_si);
1349 1348
1350 mutex_destroy(&sc->sc_lock); 1349 mutex_destroy(&sc->sc_lock);
1351 mutex_destroy(&sc->sc_intr_lock); 1350 mutex_destroy(&sc->sc_intr_lock);
1352#endif 1351#endif
1353 1352
1354 pool_cache_destroy(sc->sc_xferpool); 1353 pool_cache_destroy(sc->sc_xferpool);
1355 1354
1356 EOWRITE4(sc, EHCI_CONFIGFLAG, 0); 1355 EOWRITE4(sc, EHCI_CONFIGFLAG, 0);
1357 1356
1358 return rv; 1357 return rv;
1359} 1358}
1360 1359
1361 1360
1362int 1361int
1363ehci_activate(device_t self, enum devact act) 1362ehci_activate(device_t self, enum devact act)
1364{ 1363{
1365 struct ehci_softc *sc = device_private(self); 1364 struct ehci_softc *sc = device_private(self);
1366 1365
1367 switch (act) { 1366 switch (act) {
1368 case DVACT_DEACTIVATE: 1367 case DVACT_DEACTIVATE:
1369 sc->sc_dying = 1; 1368 sc->sc_dying = 1;
1370 return 0; 1369 return 0;
1371 default: 1370 default:
1372 return EOPNOTSUPP; 1371 return EOPNOTSUPP;
1373 } 1372 }
1374} 1373}
1375 1374
1376/* 1375/*
1377 * Handle suspend/resume. 1376 * Handle suspend/resume.
1378 * 1377 *
1379 * We need to switch to polling mode here, because this routine is 1378 * We need to switch to polling mode here, because this routine is
1380 * called from an interrupt context. This is all right since we 1379 * called from an interrupt context. This is all right since we
1381 * are almost suspended anyway. 1380 * are almost suspended anyway.
1382 * 1381 *
1383 * Note that this power handler isn't to be registered directly; the 1382 * Note that this power handler isn't to be registered directly; the
1384 * bus glue needs to call out to it. 1383 * bus glue needs to call out to it.
1385 */ 1384 */
1386bool 1385bool
1387ehci_suspend(device_t dv, const pmf_qual_t *qual) 1386ehci_suspend(device_t dv, const pmf_qual_t *qual)
1388{ 1387{
1389 ehci_softc_t *sc = device_private(dv); 1388 ehci_softc_t *sc = device_private(dv);
1390 int i; 1389 int i;
1391 uint32_t cmd, hcr; 1390 uint32_t cmd, hcr;
1392 1391
1393 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1392 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1394 1393
1395 mutex_spin_enter(&sc->sc_intr_lock); 1394 mutex_spin_enter(&sc->sc_intr_lock);
1396 sc->sc_bus.ub_usepolling++; 1395 sc->sc_bus.ub_usepolling++;
1397 mutex_spin_exit(&sc->sc_intr_lock); 1396 mutex_spin_exit(&sc->sc_intr_lock);
1398 1397
1399 for (i = 1; i <= sc->sc_noport; i++) { 1398 for (i = 1; i <= sc->sc_noport; i++) {
1400 cmd = EOREAD4(sc, EHCI_PORTSC(i)) & ~EHCI_PS_CLEAR; 1399 cmd = EOREAD4(sc, EHCI_PORTSC(i)) & ~EHCI_PS_CLEAR;
1401 if ((cmd & EHCI_PS_PO) == 0 && (cmd & EHCI_PS_PE) == EHCI_PS_PE) 1400 if ((cmd & EHCI_PS_PO) == 0 && (cmd & EHCI_PS_PE) == EHCI_PS_PE)
1402 EOWRITE4(sc, EHCI_PORTSC(i), cmd | EHCI_PS_SUSP); 1401 EOWRITE4(sc, EHCI_PORTSC(i), cmd | EHCI_PS_SUSP);
1403 } 1402 }
1404 1403
1405 sc->sc_cmd = EOREAD4(sc, EHCI_USBCMD); 1404 sc->sc_cmd = EOREAD4(sc, EHCI_USBCMD);
1406 1405
1407 cmd = sc->sc_cmd & ~(EHCI_CMD_ASE | EHCI_CMD_PSE); 1406 cmd = sc->sc_cmd & ~(EHCI_CMD_ASE | EHCI_CMD_PSE);
1408 EOWRITE4(sc, EHCI_USBCMD, cmd); 1407 EOWRITE4(sc, EHCI_USBCMD, cmd);
1409 1408
1410 for (i = 0; i < 100; i++) { 1409 for (i = 0; i < 100; i++) {
1411 hcr = EOREAD4(sc, EHCI_USBSTS) & (EHCI_STS_ASS | EHCI_STS_PSS); 1410 hcr = EOREAD4(sc, EHCI_USBSTS) & (EHCI_STS_ASS | EHCI_STS_PSS);
1412 if (hcr == 0) 1411 if (hcr == 0)
1413 break; 1412 break;
1414 1413
1415 usb_delay_ms(&sc->sc_bus, 1); 1414 usb_delay_ms(&sc->sc_bus, 1);
1416 } 1415 }
1417 if (hcr != 0) 1416 if (hcr != 0)
1418 printf("%s: reset timeout\n", device_xname(dv)); 1417 printf("%s: reset timeout\n", device_xname(dv));
1419 1418
1420 cmd &= ~EHCI_CMD_RS; 1419 cmd &= ~EHCI_CMD_RS;
1421 EOWRITE4(sc, EHCI_USBCMD, cmd); 1420 EOWRITE4(sc, EHCI_USBCMD, cmd);
1422 1421
1423 for (i = 0; i < 100; i++) { 1422 for (i = 0; i < 100; i++) {
1424 hcr = EOREAD4(sc, EHCI_USBSTS) & EHCI_STS_HCH; 1423 hcr = EOREAD4(sc, EHCI_USBSTS) & EHCI_STS_HCH;
1425 if (hcr == EHCI_STS_HCH) 1424 if (hcr == EHCI_STS_HCH)
1426 break; 1425 break;
1427 1426
1428 usb_delay_ms(&sc->sc_bus, 1); 1427 usb_delay_ms(&sc->sc_bus, 1);
1429 } 1428 }
1430 if (hcr != EHCI_STS_HCH) 1429 if (hcr != EHCI_STS_HCH)
1431 printf("%s: config timeout\n", device_xname(dv)); 1430 printf("%s: config timeout\n", device_xname(dv));
1432 1431
1433 mutex_spin_enter(&sc->sc_intr_lock); 1432 mutex_spin_enter(&sc->sc_intr_lock);
1434 sc->sc_bus.ub_usepolling--; 1433 sc->sc_bus.ub_usepolling--;
1435 mutex_spin_exit(&sc->sc_intr_lock); 1434 mutex_spin_exit(&sc->sc_intr_lock);
1436 1435
1437 return true; 1436 return true;
1438} 1437}
1439 1438
1440bool 1439bool
1441ehci_resume(device_t dv, const pmf_qual_t *qual) 1440ehci_resume(device_t dv, const pmf_qual_t *qual)
1442{ 1441{
1443 ehci_softc_t *sc = device_private(dv); 1442 ehci_softc_t *sc = device_private(dv);
1444 int i; 1443 int i;
1445 uint32_t cmd, hcr; 1444 uint32_t cmd, hcr;
1446 1445
1447 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1446 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1448 1447
1449 /* restore things in case the bios sucks */ 1448 /* restore things in case the bios sucks */
1450 EOWRITE4(sc, EHCI_CTRLDSSEGMENT, 0); 1449 EOWRITE4(sc, EHCI_CTRLDSSEGMENT, 0);
1451 EOWRITE4(sc, EHCI_PERIODICLISTBASE, DMAADDR(&sc->sc_fldma, 0)); 1450 EOWRITE4(sc, EHCI_PERIODICLISTBASE, DMAADDR(&sc->sc_fldma, 0));
1452 EOWRITE4(sc, EHCI_ASYNCLISTADDR, 1451 EOWRITE4(sc, EHCI_ASYNCLISTADDR,
1453 sc->sc_async_head->physaddr | EHCI_LINK_QH); 1452 sc->sc_async_head->physaddr | EHCI_LINK_QH);
1454 1453
1455 EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs & ~EHCI_INTR_PCIE); 1454 EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs & ~EHCI_INTR_PCIE);
1456 1455
1457 EOWRITE4(sc, EHCI_USBCMD, sc->sc_cmd); 1456 EOWRITE4(sc, EHCI_USBCMD, sc->sc_cmd);
1458 1457
1459 hcr = 0; 1458 hcr = 0;
1460 for (i = 1; i <= sc->sc_noport; i++) { 1459 for (i = 1; i <= sc->sc_noport; i++) {
1461 cmd = EOREAD4(sc, EHCI_PORTSC(i)) & ~EHCI_PS_CLEAR; 1460 cmd = EOREAD4(sc, EHCI_PORTSC(i)) & ~EHCI_PS_CLEAR;
1462 if ((cmd & EHCI_PS_PO) == 0 && 1461 if ((cmd & EHCI_PS_PO) == 0 &&
1463 (cmd & EHCI_PS_SUSP) == EHCI_PS_SUSP) { 1462 (cmd & EHCI_PS_SUSP) == EHCI_PS_SUSP) {
1464 EOWRITE4(sc, EHCI_PORTSC(i), cmd | EHCI_PS_FPR); 1463 EOWRITE4(sc, EHCI_PORTSC(i), cmd | EHCI_PS_FPR);
1465 hcr = 1; 1464 hcr = 1;
1466 } 1465 }
1467 } 1466 }
1468 1467
1469 if (hcr) { 1468 if (hcr) {
1470 usb_delay_ms(&sc->sc_bus, USB_RESUME_WAIT); 1469 usb_delay_ms(&sc->sc_bus, USB_RESUME_WAIT);
1471 1470
1472 for (i = 1; i <= sc->sc_noport; i++) { 1471 for (i = 1; i <= sc->sc_noport; i++) {
1473 cmd = EOREAD4(sc, EHCI_PORTSC(i)) & ~EHCI_PS_CLEAR; 1472 cmd = EOREAD4(sc, EHCI_PORTSC(i)) & ~EHCI_PS_CLEAR;
1474 if ((cmd & EHCI_PS_PO) == 0 && 1473 if ((cmd & EHCI_PS_PO) == 0 &&
1475 (cmd & EHCI_PS_SUSP) == EHCI_PS_SUSP) 1474 (cmd & EHCI_PS_SUSP) == EHCI_PS_SUSP)
1476 EOWRITE4(sc, EHCI_PORTSC(i), 1475 EOWRITE4(sc, EHCI_PORTSC(i),
1477 cmd & ~EHCI_PS_FPR); 1476 cmd & ~EHCI_PS_FPR);
1478 } 1477 }
1479 } 1478 }
1480 1479
1481 EOWRITE4(sc, EHCI_USBCMD, sc->sc_cmd); 1480 EOWRITE4(sc, EHCI_USBCMD, sc->sc_cmd);
1482 EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs); 1481 EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs);
1483 1482
1484 for (i = 0; i < 100; i++) { 1483 for (i = 0; i < 100; i++) {
1485 hcr = EOREAD4(sc, EHCI_USBSTS) & EHCI_STS_HCH; 1484 hcr = EOREAD4(sc, EHCI_USBSTS) & EHCI_STS_HCH;
1486 if (hcr != EHCI_STS_HCH) 1485 if (hcr != EHCI_STS_HCH)
1487 break; 1486 break;
1488 1487
1489 usb_delay_ms(&sc->sc_bus, 1); 1488 usb_delay_ms(&sc->sc_bus, 1);
1490 } 1489 }
1491 if (hcr == EHCI_STS_HCH) 1490 if (hcr == EHCI_STS_HCH)
1492 printf("%s: config timeout\n", device_xname(dv)); 1491 printf("%s: config timeout\n", device_xname(dv));
1493 1492
1494 return true; 1493 return true;
1495} 1494}
1496 1495
1497/* 1496/*
1498 * Shut down the controller when the system is going down. 1497 * Shut down the controller when the system is going down.
1499 */ 1498 */
1500bool 1499bool
1501ehci_shutdown(device_t self, int flags) 1500ehci_shutdown(device_t self, int flags)
1502{ 1501{
1503 ehci_softc_t *sc = device_private(self); 1502 ehci_softc_t *sc = device_private(self);
1504 1503
1505 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1504 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1506 1505
1507 EOWRITE4(sc, EHCI_USBCMD, 0); /* Halt controller */ 1506 EOWRITE4(sc, EHCI_USBCMD, 0); /* Halt controller */
1508 EOWRITE4(sc, EHCI_USBCMD, EHCI_CMD_HCRESET); 1507 EOWRITE4(sc, EHCI_USBCMD, EHCI_CMD_HCRESET);
1509 return true; 1508 return true;
1510} 1509}
1511 1510
1512Static usbd_xfer_handle 1511Static usbd_xfer_handle
1513ehci_allocx(struct usbd_bus *bus) 1512ehci_allocx(struct usbd_bus *bus)
1514{ 1513{
1515 struct ehci_softc *sc = bus->ub_hcpriv; 1514 struct ehci_softc *sc = bus->ub_hcpriv;
1516 usbd_xfer_handle xfer; 1515 usbd_xfer_handle xfer;
1517 1516
1518 xfer = pool_cache_get(sc->sc_xferpool, PR_NOWAIT); 1517 xfer = pool_cache_get(sc->sc_xferpool, PR_NOWAIT);
1519 if (xfer != NULL) { 1518 if (xfer != NULL) {
1520 memset(xfer, 0, sizeof(struct ehci_xfer)); 1519 memset(xfer, 0, sizeof(struct ehci_xfer));
1521#ifdef DIAGNOSTIC 1520#ifdef DIAGNOSTIC
1522 EXFER(xfer)->ex_isdone = 1; 1521 EXFER(xfer)->ex_isdone = true;
1523 xfer->ux_state = XFER_BUSY; 1522 xfer->ux_state = XFER_BUSY;
1524#endif 1523#endif
1525 } 1524 }
1526 return xfer; 1525 return xfer;
1527} 1526}
1528 1527
1529Static void 1528Static void
1530ehci_freex(struct usbd_bus *bus, usbd_xfer_handle xfer) 1529ehci_freex(struct usbd_bus *bus, usbd_xfer_handle xfer)
1531{ 1530{
1532 struct ehci_softc *sc = bus->ub_hcpriv; 1531 struct ehci_softc *sc = bus->ub_hcpriv;
1533 1532
 1533 KASSERT(xfer->ux_state == XFER_BUSY);
 1534 KASSERT(EXFER(xfer)->ex_isdone);
1534#ifdef DIAGNOSTIC 1535#ifdef DIAGNOSTIC
1535 if (xfer->ux_state != XFER_BUSY) { 
1536 printf("ehci_freex: xfer=%p not busy, 0x%08x\n", xfer, 
1537 xfer->ux_state); 
1538 } 
1539 xfer->ux_state = XFER_FREE; 1536 xfer->ux_state = XFER_FREE;
1540 if (!EXFER(xfer)->ex_isdone) { 
1541 printf("ehci_freex: !isdone\n"); 
1542 } 
1543#endif 1537#endif
1544 pool_cache_put(sc->sc_xferpool, xfer); 1538 pool_cache_put(sc->sc_xferpool, xfer);
1545} 1539}
1546 1540
1547Static void 1541Static void
1548ehci_get_lock(struct usbd_bus *bus, kmutex_t **lock) 1542ehci_get_lock(struct usbd_bus *bus, kmutex_t **lock)
1549{ 1543{
1550 struct ehci_softc *sc = bus->ub_hcpriv; 1544 struct ehci_softc *sc = bus->ub_hcpriv;
1551 1545
1552 *lock = &sc->sc_lock; 1546 *lock = &sc->sc_lock;
1553} 1547}
1554 1548
1555Static void 1549Static void
1556ehci_device_clear_toggle(usbd_pipe_handle pipe) 1550ehci_device_clear_toggle(usbd_pipe_handle pipe)
1557{ 1551{
1558 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; 1552 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;
1559 1553
1560 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1554 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1561 1555
1562 USBHIST_LOG(ehcidebug, "epipe=%p status=0x%08x", 1556 USBHIST_LOG(ehcidebug, "epipe=%p status=0x%08x",
1563 epipe, epipe->sqh->qh.qh_qtd.qtd_status, 0, 0); 1557 epipe, epipe->sqh->qh.qh_qtd.qtd_status, 0, 0);
1564#ifdef EHCI_DEBUG 1558#ifdef EHCI_DEBUG
1565 if (ehcidebug) 1559 if (ehcidebug)
1566 usbd_dump_pipe(pipe); 1560 usbd_dump_pipe(pipe);
1567#endif 1561#endif
1568 epipe->nexttoggle = 0; 1562 epipe->nexttoggle = 0;
1569} 1563}
1570 1564
1571Static void 1565Static void
1572ehci_noop(usbd_pipe_handle pipe) 1566ehci_noop(usbd_pipe_handle pipe)
1573{ 1567{
1574} 1568}
1575 1569
1576#ifdef EHCI_DEBUG 1570#ifdef EHCI_DEBUG
1577/* 1571/*
1578 * Unused function - this is meant to be called from a kernel 1572 * Unused function - this is meant to be called from a kernel
1579 * debugger. 1573 * debugger.
1580 */ 1574 */
1581void 1575void
1582ehci_dump(void) 1576ehci_dump(void)
1583{ 1577{
1584 ehci_softc_t *sc = theehci; 1578 ehci_softc_t *sc = theehci;
1585 int i; 1579 int i;
1586 printf("cmd=0x%08x, sts=0x%08x, ien=0x%08x\n", 1580 printf("cmd=0x%08x, sts=0x%08x, ien=0x%08x\n",
1587 EOREAD4(sc, EHCI_USBCMD), 1581 EOREAD4(sc, EHCI_USBCMD),
1588 EOREAD4(sc, EHCI_USBSTS), 1582 EOREAD4(sc, EHCI_USBSTS),
1589 EOREAD4(sc, EHCI_USBINTR)); 1583 EOREAD4(sc, EHCI_USBINTR));
1590 printf("frindex=0x%08x ctrdsegm=0x%08x periodic=0x%08x async=0x%08x\n", 1584 printf("frindex=0x%08x ctrdsegm=0x%08x periodic=0x%08x async=0x%08x\n",
1591 EOREAD4(sc, EHCI_FRINDEX), 1585 EOREAD4(sc, EHCI_FRINDEX),
1592 EOREAD4(sc, EHCI_CTRLDSSEGMENT), 1586 EOREAD4(sc, EHCI_CTRLDSSEGMENT),
1593 EOREAD4(sc, EHCI_PERIODICLISTBASE), 1587 EOREAD4(sc, EHCI_PERIODICLISTBASE),
1594 EOREAD4(sc, EHCI_ASYNCLISTADDR)); 1588 EOREAD4(sc, EHCI_ASYNCLISTADDR));
1595 for (i = 1; i <= sc->sc_noport; i++) 1589 for (i = 1; i <= sc->sc_noport; i++)
1596 printf("port %d status=0x%08x\n", i, 1590 printf("port %d status=0x%08x\n", i,
1597 EOREAD4(sc, EHCI_PORTSC(i))); 1591 EOREAD4(sc, EHCI_PORTSC(i)));
1598} 1592}
1599 1593
1600Static void 1594Static void
1601ehci_dump_regs(ehci_softc_t *sc) 1595ehci_dump_regs(ehci_softc_t *sc)
1602{ 1596{
1603 int i; 1597 int i;
1604 1598
1605 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1599 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1606 1600
1607 USBHIST_LOG(ehcidebug, 1601 USBHIST_LOG(ehcidebug,
1608 "cmd = 0x%08x sts = 0x%08x ien = 0x%08x", 1602 "cmd = 0x%08x sts = 0x%08x ien = 0x%08x",
1609 EOREAD4(sc, EHCI_USBCMD), EOREAD4(sc, EHCI_USBSTS), 1603 EOREAD4(sc, EHCI_USBCMD), EOREAD4(sc, EHCI_USBSTS),
1610 EOREAD4(sc, EHCI_USBINTR), 0); 1604 EOREAD4(sc, EHCI_USBINTR), 0);
1611 USBHIST_LOG(ehcidebug, 1605 USBHIST_LOG(ehcidebug,
1612 "frindex = 0x%08x ctrdsegm = 0x%08x periodic = 0x%08x " 1606 "frindex = 0x%08x ctrdsegm = 0x%08x periodic = 0x%08x "
1613 "async = 0x%08x", 1607 "async = 0x%08x",
1614 EOREAD4(sc, EHCI_FRINDEX), EOREAD4(sc, EHCI_CTRLDSSEGMENT), 1608 EOREAD4(sc, EHCI_FRINDEX), EOREAD4(sc, EHCI_CTRLDSSEGMENT),
1615 EOREAD4(sc, EHCI_PERIODICLISTBASE), 1609 EOREAD4(sc, EHCI_PERIODICLISTBASE),
1616 EOREAD4(sc, EHCI_ASYNCLISTADDR)); 1610 EOREAD4(sc, EHCI_ASYNCLISTADDR));
1617 for (i = 1; i <= sc->sc_noport; i += 2) { 1611 for (i = 1; i <= sc->sc_noport; i += 2) {
1618 if (i == sc->sc_noport) { 1612 if (i == sc->sc_noport) {
1619 USBHIST_LOG(ehcidebug, 1613 USBHIST_LOG(ehcidebug,
1620 "port %d status = 0x%08x", i, 1614 "port %d status = 0x%08x", i,
1621 EOREAD4(sc, EHCI_PORTSC(i)), 0, 0); 1615 EOREAD4(sc, EHCI_PORTSC(i)), 0, 0);
1622 } else { 1616 } else {
1623 USBHIST_LOG(ehcidebug, 1617 USBHIST_LOG(ehcidebug,
1624 "port %d status = 0x%08x port %d status = 0x%08x", 1618 "port %d status = 0x%08x port %d status = 0x%08x",
1625 i, EOREAD4(sc, EHCI_PORTSC(i)), 1619 i, EOREAD4(sc, EHCI_PORTSC(i)),
1626 i+1, EOREAD4(sc, EHCI_PORTSC(i+1))); 1620 i+1, EOREAD4(sc, EHCI_PORTSC(i+1)));
1627 } 1621 }
1628 } 1622 }
1629} 1623}
1630 1624
1631#ifdef EHCI_DEBUG 1625#ifdef EHCI_DEBUG
1632#define ehci_dump_link(link, type) do { \ 1626#define ehci_dump_link(link, type) do { \
1633 USBHIST_LOG(ehcidebug, " link 0x%08x (T = %d):", \ 1627 USBHIST_LOG(ehcidebug, " link 0x%08x (T = %d):", \
1634 link, \ 1628 link, \
1635 link & EHCI_LINK_TERMINATE ? 1 : 0, 0, 0); \ 1629 link & EHCI_LINK_TERMINATE ? 1 : 0, 0, 0); \
1636 if (type) { \ 1630 if (type) { \
1637 USBHIST_LOG(ehcidebug, \ 1631 USBHIST_LOG(ehcidebug, \
1638 " ITD = %d QH = %d SITD = %d FSTN = %d",\ 1632 " ITD = %d QH = %d SITD = %d FSTN = %d",\
1639 EHCI_LINK_TYPE(link) == EHCI_LINK_ITD ? 1 : 0, \ 1633 EHCI_LINK_TYPE(link) == EHCI_LINK_ITD ? 1 : 0, \
1640 EHCI_LINK_TYPE(link) == EHCI_LINK_QH ? 1 : 0, \ 1634 EHCI_LINK_TYPE(link) == EHCI_LINK_QH ? 1 : 0, \
1641 EHCI_LINK_TYPE(link) == EHCI_LINK_SITD ? 1 : 0, \ 1635 EHCI_LINK_TYPE(link) == EHCI_LINK_SITD ? 1 : 0, \
1642 EHCI_LINK_TYPE(link) == EHCI_LINK_FSTN ? 1 : 0); \ 1636 EHCI_LINK_TYPE(link) == EHCI_LINK_FSTN ? 1 : 0); \
1643 } \ 1637 } \
1644} while(0) 1638} while(0)
1645#else 1639#else
1646#define ehci_dump_link(link, type) 1640#define ehci_dump_link(link, type)
1647#endif 1641#endif
1648 1642
1649Static void 1643Static void
1650ehci_dump_sqtds(ehci_soft_qtd_t *sqtd) 1644ehci_dump_sqtds(ehci_soft_qtd_t *sqtd)
1651{ 1645{
1652 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1646 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1653 int i; 1647 int i;
1654 uint32_t stop = 0; 1648 uint32_t stop = 0;
1655 1649
1656 for (i = 0; sqtd && i < 20 && !stop; sqtd = sqtd->nextqtd, i++) { 1650 for (i = 0; sqtd && i < 20 && !stop; sqtd = sqtd->nextqtd, i++) {
1657 ehci_dump_sqtd(sqtd); 1651 ehci_dump_sqtd(sqtd);
1658 usb_syncmem(&sqtd->dma, 1652 usb_syncmem(&sqtd->dma,
1659 sqtd->offs + offsetof(ehci_qtd_t, qtd_next), 1653 sqtd->offs + offsetof(ehci_qtd_t, qtd_next),
1660 sizeof(sqtd->qtd), 1654 sizeof(sqtd->qtd),
1661 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 1655 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
1662 stop = sqtd->qtd.qtd_next & htole32(EHCI_LINK_TERMINATE); 1656 stop = sqtd->qtd.qtd_next & htole32(EHCI_LINK_TERMINATE);
1663 usb_syncmem(&sqtd->dma, 1657 usb_syncmem(&sqtd->dma,
1664 sqtd->offs + offsetof(ehci_qtd_t, qtd_next), 1658 sqtd->offs + offsetof(ehci_qtd_t, qtd_next),
1665 sizeof(sqtd->qtd), BUS_DMASYNC_PREREAD); 1659 sizeof(sqtd->qtd), BUS_DMASYNC_PREREAD);
1666 } 1660 }
1667 if (!stop) 1661 if (!stop)
1668 USBHIST_LOG(ehcidebug, 1662 USBHIST_LOG(ehcidebug,
1669 "dump aborted, too many TDs", 0, 0, 0, 0); 1663 "dump aborted, too many TDs", 0, 0, 0, 0);
1670} 1664}
1671 1665
1672Static void 1666Static void
1673ehci_dump_sqtd(ehci_soft_qtd_t *sqtd) 1667ehci_dump_sqtd(ehci_soft_qtd_t *sqtd)
1674{ 1668{
1675 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1669 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1676 1670
1677 usb_syncmem(&sqtd->dma, sqtd->offs, 1671 usb_syncmem(&sqtd->dma, sqtd->offs,
1678 sizeof(sqtd->qtd), BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 1672 sizeof(sqtd->qtd), BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
1679 1673
1680 USBHIST_LOGN(ehcidebug, 10, 1674 USBHIST_LOGN(ehcidebug, 10,
1681 "QTD(%p) at 0x%08x:", sqtd, sqtd->physaddr, 0, 0); 1675 "QTD(%p) at 0x%08x:", sqtd, sqtd->physaddr, 0, 0);
1682 ehci_dump_qtd(&sqtd->qtd); 1676 ehci_dump_qtd(&sqtd->qtd);
1683 1677
1684 usb_syncmem(&sqtd->dma, sqtd->offs, 1678 usb_syncmem(&sqtd->dma, sqtd->offs,
1685 sizeof(sqtd->qtd), BUS_DMASYNC_PREREAD); 1679 sizeof(sqtd->qtd), BUS_DMASYNC_PREREAD);
1686} 1680}
1687 1681
1688Static void 1682Static void
1689ehci_dump_qtd(ehci_qtd_t *qtd) 1683ehci_dump_qtd(ehci_qtd_t *qtd)
1690{ 1684{
1691 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1685 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1692 1686
1693#ifdef USBHIST 1687#ifdef USBHIST
1694 uint32_t s = le32toh(qtd->qtd_status); 1688 uint32_t s = le32toh(qtd->qtd_status);
1695#endif 1689#endif
1696 1690
1697 USBHIST_LOGN(ehcidebug, 10, 1691 USBHIST_LOGN(ehcidebug, 10,
1698 " next = 0x%08x altnext = 0x%08x status = 0x%08x", 1692 " next = 0x%08x altnext = 0x%08x status = 0x%08x",
1699 qtd->qtd_next, qtd->qtd_altnext, s, 0); 1693 qtd->qtd_next, qtd->qtd_altnext, s, 0);
1700 USBHIST_LOGN(ehcidebug, 10, 1694 USBHIST_LOGN(ehcidebug, 10,
1701 " toggle = %d ioc = %d bytes = %#x " 1695 " toggle = %d ioc = %d bytes = %#x "
1702 "c_page = %#x", EHCI_QTD_GET_TOGGLE(s), EHCI_QTD_GET_IOC(s), 1696 "c_page = %#x", EHCI_QTD_GET_TOGGLE(s), EHCI_QTD_GET_IOC(s),
1703 EHCI_QTD_GET_BYTES(s), EHCI_QTD_GET_C_PAGE(s)); 1697 EHCI_QTD_GET_BYTES(s), EHCI_QTD_GET_C_PAGE(s));
1704 USBHIST_LOGN(ehcidebug, 10, 1698 USBHIST_LOGN(ehcidebug, 10,
1705 " cerr = %d pid = %d stat = %x", 1699 " cerr = %d pid = %d stat = %x",
1706 EHCI_QTD_GET_CERR(s), EHCI_QTD_GET_PID(s), EHCI_QTD_GET_STATUS(s), 1700 EHCI_QTD_GET_CERR(s), EHCI_QTD_GET_PID(s), EHCI_QTD_GET_STATUS(s),
1707 0); 1701 0);
1708 USBHIST_LOGN(ehcidebug, 10, 1702 USBHIST_LOGN(ehcidebug, 10,
1709 "active =%d halted=%d buferr=%d babble=%d", 1703 "active =%d halted=%d buferr=%d babble=%d",
1710 s & EHCI_QTD_ACTIVE ? 1 : 0, 1704 s & EHCI_QTD_ACTIVE ? 1 : 0,
1711 s & EHCI_QTD_HALTED ? 1 : 0, 1705 s & EHCI_QTD_HALTED ? 1 : 0,
1712 s & EHCI_QTD_BUFERR ? 1 : 0, 1706 s & EHCI_QTD_BUFERR ? 1 : 0,
1713 s & EHCI_QTD_BABBLE ? 1 : 0); 1707 s & EHCI_QTD_BABBLE ? 1 : 0);
1714 USBHIST_LOGN(ehcidebug, 10, 1708 USBHIST_LOGN(ehcidebug, 10,
1715 "xacterr=%d missed=%d split =%d ping =%d", 1709 "xacterr=%d missed=%d split =%d ping =%d",
1716 s & EHCI_QTD_XACTERR ? 1 : 0, 1710 s & EHCI_QTD_XACTERR ? 1 : 0,
1717 s & EHCI_QTD_MISSEDMICRO ? 1 : 0, 1711 s & EHCI_QTD_MISSEDMICRO ? 1 : 0,
1718 s & EHCI_QTD_SPLITXSTATE ? 1 : 0, 1712 s & EHCI_QTD_SPLITXSTATE ? 1 : 0,
1719 s & EHCI_QTD_PINGSTATE ? 1 : 0); 1713 s & EHCI_QTD_PINGSTATE ? 1 : 0);
1720 USBHIST_LOGN(ehcidebug, 10, 1714 USBHIST_LOGN(ehcidebug, 10,
1721 "buffer[0] = %#x buffer[1] = %#x " 1715 "buffer[0] = %#x buffer[1] = %#x "
1722 "buffer[2] = %#x buffer[3] = %#x", 1716 "buffer[2] = %#x buffer[3] = %#x",
1723 le32toh(qtd->qtd_buffer[0]), le32toh(qtd->qtd_buffer[1]), 1717 le32toh(qtd->qtd_buffer[0]), le32toh(qtd->qtd_buffer[1]),
1724 le32toh(qtd->qtd_buffer[2]), le32toh(qtd->qtd_buffer[3])); 1718 le32toh(qtd->qtd_buffer[2]), le32toh(qtd->qtd_buffer[3]));
1725 USBHIST_LOGN(ehcidebug, 10, 1719 USBHIST_LOGN(ehcidebug, 10,
1726 "buffer[4] = %#x", le32toh(qtd->qtd_buffer[4]), 0, 0, 0); 1720 "buffer[4] = %#x", le32toh(qtd->qtd_buffer[4]), 0, 0, 0);
1727} 1721}
1728 1722
1729Static void 1723Static void
1730ehci_dump_sqh(ehci_soft_qh_t *sqh) 1724ehci_dump_sqh(ehci_soft_qh_t *sqh)
1731{ 1725{
1732#ifdef USBHIST 1726#ifdef USBHIST
1733 ehci_qh_t *qh = &sqh->qh; 1727 ehci_qh_t *qh = &sqh->qh;
1734 ehci_link_t link; 1728 ehci_link_t link;
1735#endif 1729#endif
1736 uint32_t endp, endphub; 1730 uint32_t endp, endphub;
1737 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1731 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1738 1732
1739 usb_syncmem(&sqh->dma, sqh->offs, 1733 usb_syncmem(&sqh->dma, sqh->offs,
1740 sizeof(sqh->qh), BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 1734 sizeof(sqh->qh), BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
1741 1735
1742 USBHIST_LOGN(ehcidebug, 10, 1736 USBHIST_LOGN(ehcidebug, 10,
1743 "QH(%p) at %#x:", sqh, sqh->physaddr, 0, 0); 1737 "QH(%p) at %#x:", sqh, sqh->physaddr, 0, 0);
1744 link = le32toh(qh->qh_link); 1738 link = le32toh(qh->qh_link);
1745 ehci_dump_link(link, true); 1739 ehci_dump_link(link, true);
1746 1740
1747 endp = le32toh(qh->qh_endp); 1741 endp = le32toh(qh->qh_endp);
1748 USBHIST_LOGN(ehcidebug, 10, 1742 USBHIST_LOGN(ehcidebug, 10,
1749 " endp = %#x", endp, 0, 0, 0); 1743 " endp = %#x", endp, 0, 0, 0);
1750 USBHIST_LOGN(ehcidebug, 10, 1744 USBHIST_LOGN(ehcidebug, 10,
1751 " addr = 0x%02x inact = %d endpt = %d eps = %d", 1745 " addr = 0x%02x inact = %d endpt = %d eps = %d",
1752 EHCI_QH_GET_ADDR(endp), EHCI_QH_GET_INACT(endp), 1746 EHCI_QH_GET_ADDR(endp), EHCI_QH_GET_INACT(endp),
1753 EHCI_QH_GET_ENDPT(endp), EHCI_QH_GET_EPS(endp)); 1747 EHCI_QH_GET_ENDPT(endp), EHCI_QH_GET_EPS(endp));
1754 USBHIST_LOGN(ehcidebug, 10, 1748 USBHIST_LOGN(ehcidebug, 10,
1755 " dtc = %d hrecl = %d", 1749 " dtc = %d hrecl = %d",
1756 EHCI_QH_GET_DTC(endp), EHCI_QH_GET_HRECL(endp), 0, 0); 1750 EHCI_QH_GET_DTC(endp), EHCI_QH_GET_HRECL(endp), 0, 0);
1757 USBHIST_LOGN(ehcidebug, 10, 1751 USBHIST_LOGN(ehcidebug, 10,
1758 " ctl = %d nrl = %d mpl = %#x(%d)", 1752 " ctl = %d nrl = %d mpl = %#x(%d)",
1759 EHCI_QH_GET_CTL(endp),EHCI_QH_GET_NRL(endp), 1753 EHCI_QH_GET_CTL(endp),EHCI_QH_GET_NRL(endp),
1760 EHCI_QH_GET_MPL(endp), EHCI_QH_GET_MPL(endp)); 1754 EHCI_QH_GET_MPL(endp), EHCI_QH_GET_MPL(endp));
1761 1755
1762 endphub = le32toh(qh->qh_endphub); 1756 endphub = le32toh(qh->qh_endphub);
1763 USBHIST_LOGN(ehcidebug, 10, 1757 USBHIST_LOGN(ehcidebug, 10,
1764 " endphub = %#x", endphub, 0, 0, 0); 1758 " endphub = %#x", endphub, 0, 0, 0);
1765 USBHIST_LOGN(ehcidebug, 10, 1759 USBHIST_LOGN(ehcidebug, 10,
1766 " smask = 0x%02x cmask = 0x%02x", 1760 " smask = 0x%02x cmask = 0x%02x",
1767 EHCI_QH_GET_SMASK(endphub), EHCI_QH_GET_CMASK(endphub), 1, 0); 1761 EHCI_QH_GET_SMASK(endphub), EHCI_QH_GET_CMASK(endphub), 1, 0);
1768 USBHIST_LOGN(ehcidebug, 10, 1762 USBHIST_LOGN(ehcidebug, 10,
1769 " huba = 0x%02x port = %d mult = %d", 1763 " huba = 0x%02x port = %d mult = %d",
1770 EHCI_QH_GET_HUBA(endphub), EHCI_QH_GET_PORT(endphub), 1764 EHCI_QH_GET_HUBA(endphub), EHCI_QH_GET_PORT(endphub),
1771 EHCI_QH_GET_MULT(endphub), 0); 1765 EHCI_QH_GET_MULT(endphub), 0);
1772 1766
1773 link = le32toh(qh->qh_curqtd); 1767 link = le32toh(qh->qh_curqtd);
1774 ehci_dump_link(link, false); 1768 ehci_dump_link(link, false);
1775 USBHIST_LOGN(ehcidebug, 10, "Overlay qTD:", 0, 0, 0, 0); 1769 USBHIST_LOGN(ehcidebug, 10, "Overlay qTD:", 0, 0, 0, 0);
1776 ehci_dump_qtd(&qh->qh_qtd); 1770 ehci_dump_qtd(&qh->qh_qtd);
1777 1771
1778 usb_syncmem(&sqh->dma, sqh->offs, 1772 usb_syncmem(&sqh->dma, sqh->offs,
1779 sizeof(sqh->qh), BUS_DMASYNC_PREREAD); 1773 sizeof(sqh->qh), BUS_DMASYNC_PREREAD);
1780} 1774}
1781 1775
1782Static void 1776Static void
1783ehci_dump_itd(struct ehci_soft_itd *itd) 1777ehci_dump_itd(struct ehci_soft_itd *itd)
1784{ 1778{
1785 ehci_isoc_trans_t t; 1779 ehci_isoc_trans_t t;
1786 ehci_isoc_bufr_ptr_t b, b2, b3; 1780 ehci_isoc_bufr_ptr_t b, b2, b3;
1787 int i; 1781 int i;
1788 1782
1789 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1783 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1790 1784
1791 USBHIST_LOG(ehcidebug, "ITD: next phys = %#x", itd->itd.itd_next, 0, 1785 USBHIST_LOG(ehcidebug, "ITD: next phys = %#x", itd->itd.itd_next, 0,
1792 0, 0); 1786 0, 0);
1793 1787
1794 for (i = 0; i < EHCI_ITD_NUFRAMES; i++) { 1788 for (i = 0; i < EHCI_ITD_NUFRAMES; i++) {
1795 t = le32toh(itd->itd.itd_ctl[i]); 1789 t = le32toh(itd->itd.itd_ctl[i]);
1796 USBHIST_LOG(ehcidebug, "ITDctl %d: stat = %x len = %x", 1790 USBHIST_LOG(ehcidebug, "ITDctl %d: stat = %x len = %x",
1797 i, EHCI_ITD_GET_STATUS(t), EHCI_ITD_GET_LEN(t), 0); 1791 i, EHCI_ITD_GET_STATUS(t), EHCI_ITD_GET_LEN(t), 0);
1798 USBHIST_LOG(ehcidebug, " ioc = %x pg = %x offs = %x", 1792 USBHIST_LOG(ehcidebug, " ioc = %x pg = %x offs = %x",
1799 EHCI_ITD_GET_IOC(t), EHCI_ITD_GET_PG(t), 1793 EHCI_ITD_GET_IOC(t), EHCI_ITD_GET_PG(t),
1800 EHCI_ITD_GET_OFFS(t), 0); 1794 EHCI_ITD_GET_OFFS(t), 0);
1801 } 1795 }
1802 USBHIST_LOG(ehcidebug, "ITDbufr: ", 0, 0, 0, 0); 1796 USBHIST_LOG(ehcidebug, "ITDbufr: ", 0, 0, 0, 0);
1803 for (i = 0; i < EHCI_ITD_NBUFFERS; i++) 1797 for (i = 0; i < EHCI_ITD_NBUFFERS; i++)
1804 USBHIST_LOG(ehcidebug, " %x", 1798 USBHIST_LOG(ehcidebug, " %x",
1805 EHCI_ITD_GET_BPTR(le32toh(itd->itd.itd_bufr[i])), 0, 0, 0); 1799 EHCI_ITD_GET_BPTR(le32toh(itd->itd.itd_bufr[i])), 0, 0, 0);
1806 1800
1807 b = le32toh(itd->itd.itd_bufr[0]); 1801 b = le32toh(itd->itd.itd_bufr[0]);
1808 b2 = le32toh(itd->itd.itd_bufr[1]); 1802 b2 = le32toh(itd->itd.itd_bufr[1]);
1809 b3 = le32toh(itd->itd.itd_bufr[2]); 1803 b3 = le32toh(itd->itd.itd_bufr[2]);
1810 USBHIST_LOG(ehcidebug, " ep = %x daddr = %x dir = %d", 1804 USBHIST_LOG(ehcidebug, " ep = %x daddr = %x dir = %d",
1811 EHCI_ITD_GET_EP(b), EHCI_ITD_GET_DADDR(b), EHCI_ITD_GET_DIR(b2), 0); 1805 EHCI_ITD_GET_EP(b), EHCI_ITD_GET_DADDR(b), EHCI_ITD_GET_DIR(b2), 0);
1812 USBHIST_LOG(ehcidebug, " maxpkt = %x multi = %x", 1806 USBHIST_LOG(ehcidebug, " maxpkt = %x multi = %x",
1813 EHCI_ITD_GET_MAXPKT(b2), EHCI_ITD_GET_MULTI(b3), 0, 0); 1807 EHCI_ITD_GET_MAXPKT(b2), EHCI_ITD_GET_MULTI(b3), 0, 0);
1814} 1808}
1815 1809
1816Static void 1810Static void
1817ehci_dump_sitd(struct ehci_soft_itd *itd) 1811ehci_dump_sitd(struct ehci_soft_itd *itd)
1818{ 1812{
1819 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1813 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1820 1814
1821 USBHIST_LOG(ehcidebug, "SITD %p next = %p prev = %p", 1815 USBHIST_LOG(ehcidebug, "SITD %p next = %p prev = %p",
1822 itd, itd->u.frame_list.next, itd->u.frame_list.prev, 0); 1816 itd, itd->u.frame_list.next, itd->u.frame_list.prev, 0);
1823 USBHIST_LOG(ehcidebug, " xfernext=%p physaddr=%X slot=%d", 1817 USBHIST_LOG(ehcidebug, " xfernext=%p physaddr=%X slot=%d",
1824 itd->xfer_next, itd->physaddr, itd->slot, 0); 1818 itd->xfer_next, itd->physaddr, itd->slot, 0);
1825} 1819}
1826 1820
1827Static void 1821Static void
1828ehci_dump_exfer(struct ehci_xfer *ex) 1822ehci_dump_exfer(struct ehci_xfer *ex)
1829{ 1823{
1830 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1824 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1831 1825
1832 USBHIST_LOG(ehcidebug, "ex = %p sqtdstart = %p end = %p", 1826 USBHIST_LOG(ehcidebug, "ex = %p sqtdstart = %p end = %p",
1833 ex, ex->ex_sqtdstart, ex->ex_sqtdend, 0); 1827 ex, ex->ex_sqtdstart, ex->ex_sqtdend, 0);
1834 USBHIST_LOG(ehcidebug, " itdstart = %p end = %p isdone = %d", 1828 USBHIST_LOG(ehcidebug, " itdstart = %p end = %p isdone = %d",
1835 ex->ex_itdstart, ex->ex_itdend, ex->ex_isdone, 0); 1829 ex->ex_itdstart, ex->ex_itdend, ex->ex_isdone, 0);
1836} 1830}
1837#endif 1831#endif
1838 1832
1839Static usbd_status 1833Static usbd_status
1840ehci_open(usbd_pipe_handle pipe) 1834ehci_open(usbd_pipe_handle pipe)
1841{ 1835{
1842 usbd_device_handle dev = pipe->up_dev; 1836 usbd_device_handle dev = pipe->up_dev;
1843 ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; 1837 ehci_softc_t *sc = dev->ud_bus->ub_hcpriv;
1844 usb_endpoint_descriptor_t *ed = pipe->up_endpoint->ue_edesc; 1838 usb_endpoint_descriptor_t *ed = pipe->up_endpoint->ue_edesc;
1845 uint8_t rhaddr = dev->ud_bus->ub_rhaddr; 1839 uint8_t rhaddr = dev->ud_bus->ub_rhaddr;
1846 uint8_t addr = dev->ud_addr; 1840 uint8_t addr = dev->ud_addr;
1847 uint8_t xfertype = UE_GET_XFERTYPE(ed->bmAttributes); 1841 uint8_t xfertype = UE_GET_XFERTYPE(ed->bmAttributes);
1848 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; 1842 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;
1849 ehci_soft_qh_t *sqh; 1843 ehci_soft_qh_t *sqh;
1850 usbd_status err; 1844 usbd_status err;
1851 int ival, speed, naks; 1845 int ival, speed, naks;
1852 int hshubaddr, hshubport; 1846 int hshubaddr, hshubport;
1853 1847
1854 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 1848 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
1855 1849
1856 USBHIST_LOG(ehcidebug, "pipe=%p, addr=%d, endpt=%d (%d)", 1850 USBHIST_LOG(ehcidebug, "pipe=%p, addr=%d, endpt=%d (%d)",
1857 pipe, addr, ed->bEndpointAddress, rhaddr); 1851 pipe, addr, ed->bEndpointAddress, rhaddr);
1858 1852
1859 if (dev->ud_myhsport) { 1853 if (dev->ud_myhsport) {
1860 /* 1854 /*
1861 * When directly attached FS/LS device while doing embedded 1855 * When directly attached FS/LS device while doing embedded
1862 * transaction translations and we are the hub, set the hub 1856 * transaction translations and we are the hub, set the hub
1863 * address to 0 (us). 1857 * address to 0 (us).
1864 */ 1858 */
1865 if (!(sc->sc_flags & EHCIF_ETTF) 1859 if (!(sc->sc_flags & EHCIF_ETTF)
1866 || (dev->ud_myhsport->up_parent->ud_addr != rhaddr)) { 1860 || (dev->ud_myhsport->up_parent->ud_addr != rhaddr)) {
1867 hshubaddr = dev->ud_myhsport->up_parent->ud_addr; 1861 hshubaddr = dev->ud_myhsport->up_parent->ud_addr;
1868 } else { 1862 } else {
1869 hshubaddr = 0; 1863 hshubaddr = 0;
1870 } 1864 }
1871 hshubport = dev->ud_myhsport->up_portno; 1865 hshubport = dev->ud_myhsport->up_portno;
1872 } else { 1866 } else {
1873 hshubaddr = 0; 1867 hshubaddr = 0;
1874 hshubport = 0; 1868 hshubport = 0;
1875 } 1869 }
1876 1870
1877 if (sc->sc_dying) 1871 if (sc->sc_dying)
1878 return USBD_IOERROR; 1872 return USBD_IOERROR;
1879 1873
1880 /* toggle state needed for bulk endpoints */ 1874 /* toggle state needed for bulk endpoints */
1881 epipe->nexttoggle = pipe->up_endpoint->ue_toggle; 1875 epipe->nexttoggle = pipe->up_endpoint->ue_toggle;
1882 1876
1883 if (addr == rhaddr) { 1877 if (addr == rhaddr) {
1884 switch (ed->bEndpointAddress) { 1878 switch (ed->bEndpointAddress) {
1885 case USB_CONTROL_ENDPOINT: 1879 case USB_CONTROL_ENDPOINT:
1886 pipe->up_methods = &roothub_ctrl_methods; 1880 pipe->up_methods = &roothub_ctrl_methods;
1887 break; 1881 break;
1888 case UE_DIR_IN | USBROOTHUB_INTR_ENDPT: 1882 case UE_DIR_IN | USBROOTHUB_INTR_ENDPT:
1889 pipe->up_methods = &ehci_root_intr_methods; 1883 pipe->up_methods = &ehci_root_intr_methods;
1890 break; 1884 break;
1891 default: 1885 default:
1892 USBHIST_LOG(ehcidebug, 1886 USBHIST_LOG(ehcidebug,
1893 "bad bEndpointAddress 0x%02x", 1887 "bad bEndpointAddress 0x%02x",
1894 ed->bEndpointAddress, 0, 0, 0); 1888 ed->bEndpointAddress, 0, 0, 0);
1895 return USBD_INVAL; 1889 return USBD_INVAL;
1896 } 1890 }
1897 return USBD_NORMAL_COMPLETION; 1891 return USBD_NORMAL_COMPLETION;
1898 } 1892 }
1899 1893
1900 /* XXX All this stuff is only valid for async. */ 1894 /* XXX All this stuff is only valid for async. */
1901 switch (dev->ud_speed) { 1895 switch (dev->ud_speed) {
1902 case USB_SPEED_LOW: speed = EHCI_QH_SPEED_LOW; break; 1896 case USB_SPEED_LOW: speed = EHCI_QH_SPEED_LOW; break;
1903 case USB_SPEED_FULL: speed = EHCI_QH_SPEED_FULL; break; 1897 case USB_SPEED_FULL: speed = EHCI_QH_SPEED_FULL; break;
1904 case USB_SPEED_HIGH: speed = EHCI_QH_SPEED_HIGH; break; 1898 case USB_SPEED_HIGH: speed = EHCI_QH_SPEED_HIGH; break;
1905 default: panic("ehci_open: bad device speed %d", dev->ud_speed); 1899 default: panic("ehci_open: bad device speed %d", dev->ud_speed);
1906 } 1900 }
1907 if (speed == EHCI_QH_SPEED_LOW && xfertype == UE_ISOCHRONOUS) { 1901 if (speed == EHCI_QH_SPEED_LOW && xfertype == UE_ISOCHRONOUS) {
1908 USBHIST_LOG(ehcidebug, "hshubaddr=%d hshubport=%d", 1902 USBHIST_LOG(ehcidebug, "hshubaddr=%d hshubport=%d",
1909 hshubaddr, hshubport, 0, 0); 1903 hshubaddr, hshubport, 0, 0);
1910 return USBD_INVAL; 1904 return USBD_INVAL;
1911 } 1905 }
1912 1906
1913 /* 1907 /*
1914 * For interrupt transfer, nak throttling must be disabled, but for 1908 * For interrupt transfer, nak throttling must be disabled, but for
1915 * the other transfer type, nak throttling should be enabled from the 1909 * the other transfer type, nak throttling should be enabled from the
1916 * viewpoint that avoids the memory thrashing. 1910 * viewpoint that avoids the memory thrashing.
1917 */ 1911 */
1918 naks = (xfertype == UE_INTERRUPT) ? 0 1912 naks = (xfertype == UE_INTERRUPT) ? 0
1919 : ((speed == EHCI_QH_SPEED_HIGH) ? 4 : 0); 1913 : ((speed == EHCI_QH_SPEED_HIGH) ? 4 : 0);
1920 1914
1921 /* Allocate sqh for everything, save isoc xfers */ 1915 /* Allocate sqh for everything, save isoc xfers */
1922 if (xfertype != UE_ISOCHRONOUS) { 1916 if (xfertype != UE_ISOCHRONOUS) {
1923 sqh = ehci_alloc_sqh(sc); 1917 sqh = ehci_alloc_sqh(sc);
1924 if (sqh == NULL) 1918 if (sqh == NULL)
1925 return USBD_NOMEM; 1919 return USBD_NOMEM;
1926 /* qh_link filled when the QH is added */ 1920 /* qh_link filled when the QH is added */
1927 sqh->qh.qh_endp = htole32( 1921 sqh->qh.qh_endp = htole32(
1928 EHCI_QH_SET_ADDR(addr) | 1922 EHCI_QH_SET_ADDR(addr) |
1929 EHCI_QH_SET_ENDPT(UE_GET_ADDR(ed->bEndpointAddress)) | 1923 EHCI_QH_SET_ENDPT(UE_GET_ADDR(ed->bEndpointAddress)) |
1930 EHCI_QH_SET_EPS(speed) | 1924 EHCI_QH_SET_EPS(speed) |
1931 EHCI_QH_DTC | 1925 EHCI_QH_DTC |
1932 EHCI_QH_SET_MPL(UGETW(ed->wMaxPacketSize)) | 1926 EHCI_QH_SET_MPL(UGETW(ed->wMaxPacketSize)) |
1933 (speed != EHCI_QH_SPEED_HIGH && xfertype == UE_CONTROL ? 1927 (speed != EHCI_QH_SPEED_HIGH && xfertype == UE_CONTROL ?
1934 EHCI_QH_CTL : 0) | 1928 EHCI_QH_CTL : 0) |
1935 EHCI_QH_SET_NRL(naks) 1929 EHCI_QH_SET_NRL(naks)
1936 ); 1930 );
1937 sqh->qh.qh_endphub = htole32( 1931 sqh->qh.qh_endphub = htole32(
1938 EHCI_QH_SET_MULT(1) | 1932 EHCI_QH_SET_MULT(1) |
1939 EHCI_QH_SET_SMASK(xfertype == UE_INTERRUPT ? 0x02 : 0) 1933 EHCI_QH_SET_SMASK(xfertype == UE_INTERRUPT ? 0x02 : 0)
1940 ); 1934 );
1941 if (speed != EHCI_QH_SPEED_HIGH) 1935 if (speed != EHCI_QH_SPEED_HIGH)
1942 sqh->qh.qh_endphub |= htole32( 1936 sqh->qh.qh_endphub |= htole32(
1943 EHCI_QH_SET_PORT(hshubport) | 1937 EHCI_QH_SET_PORT(hshubport) |
1944 EHCI_QH_SET_HUBA(hshubaddr) | 1938 EHCI_QH_SET_HUBA(hshubaddr) |
1945 EHCI_QH_SET_CMASK(0x08) /* XXX */ 1939 EHCI_QH_SET_CMASK(0x08) /* XXX */
1946 ); 1940 );
1947 sqh->qh.qh_curqtd = EHCI_NULL; 1941 sqh->qh.qh_curqtd = EHCI_NULL;
1948 /* Fill the overlay qTD */ 1942 /* Fill the overlay qTD */
1949 sqh->qh.qh_qtd.qtd_next = EHCI_NULL; 1943 sqh->qh.qh_qtd.qtd_next = EHCI_NULL;
1950 sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL; 1944 sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL;
1951 sqh->qh.qh_qtd.qtd_status = htole32(0); 1945 sqh->qh.qh_qtd.qtd_status = htole32(0);
1952 1946
1953 usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), 1947 usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh),
1954 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 1948 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
1955 epipe->sqh = sqh; 1949 epipe->sqh = sqh;
1956 } else { 1950 } else {
1957 sqh = NULL; 1951 sqh = NULL;
1958 } /*xfertype == UE_ISOC*/ 1952 } /*xfertype == UE_ISOC*/
1959 1953
1960 switch (xfertype) { 1954 switch (xfertype) {
1961 case UE_CONTROL: 1955 case UE_CONTROL:
1962 err = usb_allocmem(&sc->sc_bus, sizeof(usb_device_request_t), 1956 err = usb_allocmem(&sc->sc_bus, sizeof(usb_device_request_t),
1963 0, &epipe->u.ctl.reqdma); 1957 0, &epipe->u.ctl.reqdma);
1964#ifdef EHCI_DEBUG 1958#ifdef EHCI_DEBUG
1965 if (err) 1959 if (err)
1966 printf("ehci_open: usb_allocmem()=%d\n", err); 1960 printf("ehci_open: usb_allocmem()=%d\n", err);
1967#endif 1961#endif
1968 if (err) 1962 if (err)
1969 goto bad; 1963 goto bad;
1970 pipe->up_methods = &ehci_device_ctrl_methods; 1964 pipe->up_methods = &ehci_device_ctrl_methods;
1971 mutex_enter(&sc->sc_lock); 1965 mutex_enter(&sc->sc_lock);
1972 ehci_add_qh(sc, sqh, sc->sc_async_head); 1966 ehci_add_qh(sc, sqh, sc->sc_async_head);
1973 mutex_exit(&sc->sc_lock); 1967 mutex_exit(&sc->sc_lock);
1974 break; 1968 break;
1975 case UE_BULK: 1969 case UE_BULK:
1976 pipe->up_methods = &ehci_device_bulk_methods; 1970 pipe->up_methods = &ehci_device_bulk_methods;
1977 mutex_enter(&sc->sc_lock); 1971 mutex_enter(&sc->sc_lock);
1978 ehci_add_qh(sc, sqh, sc->sc_async_head); 1972 ehci_add_qh(sc, sqh, sc->sc_async_head);
1979 mutex_exit(&sc->sc_lock); 1973 mutex_exit(&sc->sc_lock);
1980 break; 1974 break;
1981 case UE_INTERRUPT: 1975 case UE_INTERRUPT:
1982 pipe->up_methods = &ehci_device_intr_methods; 1976 pipe->up_methods = &ehci_device_intr_methods;
1983 ival = pipe->up_interval; 1977 ival = pipe->up_interval;
1984 if (ival == USBD_DEFAULT_INTERVAL) { 1978 if (ival == USBD_DEFAULT_INTERVAL) {
1985 if (speed == EHCI_QH_SPEED_HIGH) { 1979 if (speed == EHCI_QH_SPEED_HIGH) {
1986 if (ed->bInterval > 16) { 1980 if (ed->bInterval > 16) {
1987 /* 1981 /*
1988 * illegal with high-speed, but there 1982 * illegal with high-speed, but there
1989 * were documentation bugs in the spec, 1983 * were documentation bugs in the spec,
1990 * so be generous 1984 * so be generous
1991 */ 1985 */
1992 ival = 256; 1986 ival = 256;
1993 } else 1987 } else
1994 ival = (1 << (ed->bInterval - 1)) / 8; 1988 ival = (1 << (ed->bInterval - 1)) / 8;
1995 } else 1989 } else
1996 ival = ed->bInterval; 1990 ival = ed->bInterval;
1997 } 1991 }
1998 err = ehci_device_setintr(sc, sqh, ival); 1992 err = ehci_device_setintr(sc, sqh, ival);
1999 if (err) 1993 if (err)
2000 goto bad; 1994 goto bad;
2001 break; 1995 break;
2002 case UE_ISOCHRONOUS: 1996 case UE_ISOCHRONOUS:
2003 if (speed == EHCI_QH_SPEED_HIGH) 1997 if (speed == EHCI_QH_SPEED_HIGH)
2004 pipe->up_methods = &ehci_device_isoc_methods; 1998 pipe->up_methods = &ehci_device_isoc_methods;
2005 else 1999 else
2006 pipe->up_methods = &ehci_device_fs_isoc_methods; 2000 pipe->up_methods = &ehci_device_fs_isoc_methods;
2007 if (ed->bInterval == 0 || ed->bInterval > 16) { 2001 if (ed->bInterval == 0 || ed->bInterval > 16) {
2008 printf("ehci: opening pipe with invalid bInterval\n"); 2002 printf("ehci: opening pipe with invalid bInterval\n");
2009 err = USBD_INVAL; 2003 err = USBD_INVAL;
2010 goto bad; 2004 goto bad;
2011 } 2005 }
2012 if (UGETW(ed->wMaxPacketSize) == 0) { 2006 if (UGETW(ed->wMaxPacketSize) == 0) {
2013 printf("ehci: zero length endpoint open request\n"); 2007 printf("ehci: zero length endpoint open request\n");
2014 err = USBD_INVAL; 2008 err = USBD_INVAL;
2015 goto bad; 2009 goto bad;
2016 } 2010 }
2017 epipe->u.isoc.next_frame = 0; 2011 epipe->u.isoc.next_frame = 0;
2018 epipe->u.isoc.cur_xfers = 0; 2012 epipe->u.isoc.cur_xfers = 0;
2019 break; 2013 break;
2020 default: 2014 default:
2021 USBHIST_LOG(ehcidebug, "bad xfer type %d", xfertype, 0, 0, 0); 2015 USBHIST_LOG(ehcidebug, "bad xfer type %d", xfertype, 0, 0, 0);
2022 err = USBD_INVAL; 2016 err = USBD_INVAL;
2023 goto bad; 2017 goto bad;
2024 } 2018 }
2025 return USBD_NORMAL_COMPLETION; 2019 return USBD_NORMAL_COMPLETION;
2026 2020
2027 bad: 2021 bad:
2028 if (sqh != NULL) 2022 if (sqh != NULL)
2029 ehci_free_sqh(sc, sqh); 2023 ehci_free_sqh(sc, sqh);
2030 return err; 2024 return err;
2031} 2025}
2032 2026
2033/* 2027/*
2034 * Add an ED to the schedule. Called with USB lock held. 2028 * Add an ED to the schedule. Called with USB lock held.
2035 */ 2029 */
2036Static void 2030Static void
2037ehci_add_qh(ehci_softc_t *sc, ehci_soft_qh_t *sqh, ehci_soft_qh_t *head) 2031ehci_add_qh(ehci_softc_t *sc, ehci_soft_qh_t *sqh, ehci_soft_qh_t *head)
2038{ 2032{
2039 2033
2040 KASSERT(mutex_owned(&sc->sc_lock)); 2034 KASSERT(mutex_owned(&sc->sc_lock));
2041 2035
2042 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2036 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2043 2037
2044 usb_syncmem(&head->dma, head->offs + offsetof(ehci_qh_t, qh_link), 2038 usb_syncmem(&head->dma, head->offs + offsetof(ehci_qh_t, qh_link),
2045 sizeof(head->qh.qh_link), BUS_DMASYNC_POSTWRITE); 2039 sizeof(head->qh.qh_link), BUS_DMASYNC_POSTWRITE);
2046 2040
2047 sqh->next = head->next; 2041 sqh->next = head->next;
2048 sqh->qh.qh_link = head->qh.qh_link; 2042 sqh->qh.qh_link = head->qh.qh_link;
2049 2043
2050 usb_syncmem(&sqh->dma, sqh->offs + offsetof(ehci_qh_t, qh_link), 2044 usb_syncmem(&sqh->dma, sqh->offs + offsetof(ehci_qh_t, qh_link),
2051 sizeof(sqh->qh.qh_link), BUS_DMASYNC_PREWRITE); 2045 sizeof(sqh->qh.qh_link), BUS_DMASYNC_PREWRITE);
2052 2046
2053 head->next = sqh; 2047 head->next = sqh;
2054 head->qh.qh_link = htole32(sqh->physaddr | EHCI_LINK_QH); 2048 head->qh.qh_link = htole32(sqh->physaddr | EHCI_LINK_QH);
2055 2049
2056 usb_syncmem(&head->dma, head->offs + offsetof(ehci_qh_t, qh_link), 2050 usb_syncmem(&head->dma, head->offs + offsetof(ehci_qh_t, qh_link),
2057 sizeof(head->qh.qh_link), BUS_DMASYNC_PREWRITE); 2051 sizeof(head->qh.qh_link), BUS_DMASYNC_PREWRITE);
2058 2052
2059#ifdef EHCI_DEBUG 2053#ifdef EHCI_DEBUG
2060 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); 2054 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0);
2061 ehci_dump_sqh(sqh); 2055 ehci_dump_sqh(sqh);
2062 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); 2056 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0);
2063#endif 2057#endif
2064} 2058}
2065 2059
2066/* 2060/*
2067 * Remove an ED from the schedule. Called with USB lock held. 2061 * Remove an ED from the schedule. Called with USB lock held.
2068 */ 2062 */
2069Static void 2063Static void
2070ehci_rem_qh(ehci_softc_t *sc, ehci_soft_qh_t *sqh, ehci_soft_qh_t *head) 2064ehci_rem_qh(ehci_softc_t *sc, ehci_soft_qh_t *sqh, ehci_soft_qh_t *head)
2071{ 2065{
2072 ehci_soft_qh_t *p; 2066 ehci_soft_qh_t *p;
2073 2067
2074 KASSERT(mutex_owned(&sc->sc_lock)); 2068 KASSERT(mutex_owned(&sc->sc_lock));
2075 2069
2076 /* XXX */ 2070 /* XXX */
2077 for (p = head; p != NULL && p->next != sqh; p = p->next) 2071 for (p = head; p != NULL && p->next != sqh; p = p->next)
2078 ; 2072 ;
2079 if (p == NULL) 2073 if (p == NULL)
2080 panic("ehci_rem_qh: ED not found"); 2074 panic("ehci_rem_qh: ED not found");
2081 usb_syncmem(&sqh->dma, sqh->offs + offsetof(ehci_qh_t, qh_link), 2075 usb_syncmem(&sqh->dma, sqh->offs + offsetof(ehci_qh_t, qh_link),
2082 sizeof(sqh->qh.qh_link), BUS_DMASYNC_POSTWRITE); 2076 sizeof(sqh->qh.qh_link), BUS_DMASYNC_POSTWRITE);
2083 p->next = sqh->next; 2077 p->next = sqh->next;
2084 p->qh.qh_link = sqh->qh.qh_link; 2078 p->qh.qh_link = sqh->qh.qh_link;
2085 usb_syncmem(&p->dma, p->offs + offsetof(ehci_qh_t, qh_link), 2079 usb_syncmem(&p->dma, p->offs + offsetof(ehci_qh_t, qh_link),
2086 sizeof(p->qh.qh_link), BUS_DMASYNC_PREWRITE); 2080 sizeof(p->qh.qh_link), BUS_DMASYNC_PREWRITE);
2087 2081
2088 ehci_sync_hc(sc); 2082 ehci_sync_hc(sc);
2089} 2083}
2090 2084
2091Static void 2085Static void
2092ehci_set_qh_qtd(ehci_soft_qh_t *sqh, ehci_soft_qtd_t *sqtd) 2086ehci_set_qh_qtd(ehci_soft_qh_t *sqh, ehci_soft_qtd_t *sqtd)
2093{ 2087{
2094 int i; 2088 int i;
2095 uint32_t status; 2089 uint32_t status;
2096 2090
2097 /* Save toggle bit and ping status. */ 2091 /* Save toggle bit and ping status. */
2098 usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), 2092 usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh),
2099 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 2093 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
2100 status = sqh->qh.qh_qtd.qtd_status & 2094 status = sqh->qh.qh_qtd.qtd_status &
2101 htole32(EHCI_QTD_TOGGLE_MASK | 2095 htole32(EHCI_QTD_TOGGLE_MASK |
2102 EHCI_QTD_SET_STATUS(EHCI_QTD_PINGSTATE)); 2096 EHCI_QTD_SET_STATUS(EHCI_QTD_PINGSTATE));
2103 /* Set HALTED to make hw leave it alone. */ 2097 /* Set HALTED to make hw leave it alone. */
2104 sqh->qh.qh_qtd.qtd_status = 2098 sqh->qh.qh_qtd.qtd_status =
2105 htole32(EHCI_QTD_SET_STATUS(EHCI_QTD_HALTED)); 2099 htole32(EHCI_QTD_SET_STATUS(EHCI_QTD_HALTED));
2106 usb_syncmem(&sqh->dma, 2100 usb_syncmem(&sqh->dma,
2107 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), 2101 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status),
2108 sizeof(sqh->qh.qh_qtd.qtd_status), 2102 sizeof(sqh->qh.qh_qtd.qtd_status),
2109 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 2103 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
2110 sqh->qh.qh_curqtd = 0; 2104 sqh->qh.qh_curqtd = 0;
2111 sqh->qh.qh_qtd.qtd_next = htole32(sqtd->physaddr); 2105 sqh->qh.qh_qtd.qtd_next = htole32(sqtd->physaddr);
2112 sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL; 2106 sqh->qh.qh_qtd.qtd_altnext = EHCI_NULL;
2113 for (i = 0; i < EHCI_QTD_NBUFFERS; i++) 2107 for (i = 0; i < EHCI_QTD_NBUFFERS; i++)
2114 sqh->qh.qh_qtd.qtd_buffer[i] = 0; 2108 sqh->qh.qh_qtd.qtd_buffer[i] = 0;
2115 sqh->sqtd = sqtd; 2109 sqh->sqtd = sqtd;
2116 usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh), 2110 usb_syncmem(&sqh->dma, sqh->offs, sizeof(sqh->qh),
2117 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 2111 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
2118 /* Set !HALTED && !ACTIVE to start execution, preserve some fields */ 2112 /* Set !HALTED && !ACTIVE to start execution, preserve some fields */
2119 sqh->qh.qh_qtd.qtd_status = status; 2113 sqh->qh.qh_qtd.qtd_status = status;
2120 usb_syncmem(&sqh->dma, 2114 usb_syncmem(&sqh->dma,
2121 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), 2115 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status),
2122 sizeof(sqh->qh.qh_qtd.qtd_status), 2116 sizeof(sqh->qh.qh_qtd.qtd_status),
2123 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 2117 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
2124} 2118}
2125 2119
2126/* 2120/*
2127 * Ensure that the HC has released all references to the QH. We do this 2121 * 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 2122 * by asking for a Async Advance Doorbell interrupt and then we wait for
2129 * the interrupt. 2123 * the interrupt.
2130 * To make this easier we first obtain exclusive use of the doorbell. 2124 * To make this easier we first obtain exclusive use of the doorbell.
2131 */ 2125 */
2132Static void 2126Static void
2133ehci_sync_hc(ehci_softc_t *sc) 2127ehci_sync_hc(ehci_softc_t *sc)
2134{ 2128{
2135 int error __diagused; 2129 int error __diagused;
2136 2130
2137 KASSERT(mutex_owned(&sc->sc_lock)); 2131 KASSERT(mutex_owned(&sc->sc_lock));
2138 2132
2139 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2133 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2140 2134
2141 if (sc->sc_dying) { 2135 if (sc->sc_dying) {
2142 USBHIST_LOG(ehcidebug, "dying", 0, 0, 0, 0); 2136 USBHIST_LOG(ehcidebug, "dying", 0, 0, 0, 0);
2143 return; 2137 return;
2144 } 2138 }
2145 /* ask for doorbell */ 2139 /* ask for doorbell */
2146 EOWRITE4(sc, EHCI_USBCMD, EOREAD4(sc, EHCI_USBCMD) | EHCI_CMD_IAAD); 2140 EOWRITE4(sc, EHCI_USBCMD, EOREAD4(sc, EHCI_USBCMD) | EHCI_CMD_IAAD);
2147 USBHIST_LOG(ehcidebug, "cmd = 0x%08x sts = 0x%08x", 2141 USBHIST_LOG(ehcidebug, "cmd = 0x%08x sts = 0x%08x",
2148 EOREAD4(sc, EHCI_USBCMD), EOREAD4(sc, EHCI_USBSTS), 0, 0); 2142 EOREAD4(sc, EHCI_USBCMD), EOREAD4(sc, EHCI_USBSTS), 0, 0);
2149 2143
2150 error = cv_timedwait(&sc->sc_doorbell, &sc->sc_lock, hz); /* bell wait */ 2144 error = cv_timedwait(&sc->sc_doorbell, &sc->sc_lock, hz); /* bell wait */
2151 2145
2152 USBHIST_LOG(ehcidebug, "cmd = 0x%08x sts = 0x%08x", 2146 USBHIST_LOG(ehcidebug, "cmd = 0x%08x sts = 0x%08x",
2153 EOREAD4(sc, EHCI_USBCMD), EOREAD4(sc, EHCI_USBSTS), 0, 0); 2147 EOREAD4(sc, EHCI_USBCMD), EOREAD4(sc, EHCI_USBSTS), 0, 0);
2154#ifdef DIAGNOSTIC 2148#ifdef DIAGNOSTIC
2155 if (error) 2149 if (error)
2156 printf("ehci_sync_hc: cv_timedwait() = %d\n", error); 2150 printf("ehci_sync_hc: cv_timedwait() = %d\n", error);
2157#endif 2151#endif
2158} 2152}
2159 2153
2160Static void 2154Static void
2161ehci_rem_free_itd_chain(ehci_softc_t *sc, struct ehci_xfer *exfer) 2155ehci_rem_free_itd_chain(ehci_softc_t *sc, struct ehci_xfer *exfer)
2162{ 2156{
2163 struct ehci_soft_itd *itd, *prev; 2157 struct ehci_soft_itd *itd, *prev;
2164 2158
2165 prev = NULL; 2159 prev = NULL;
2166 2160
2167 if (exfer->ex_itdstart == NULL || exfer->ex_itdend == NULL) 2161 if (exfer->ex_itdstart == NULL || exfer->ex_itdend == NULL)
2168 panic("ehci isoc xfer being freed, but with no itd chain\n"); 2162 panic("ehci isoc xfer being freed, but with no itd chain\n");
2169 2163
2170 for (itd = exfer->ex_itdstart; itd != NULL; itd = itd->xfer_next) { 2164 for (itd = exfer->ex_itdstart; itd != NULL; itd = itd->xfer_next) {
2171 prev = itd->u.frame_list.prev; 2165 prev = itd->u.frame_list.prev;
2172 /* Unlink itd from hardware chain, or frame array */ 2166 /* Unlink itd from hardware chain, or frame array */
2173 if (prev == NULL) { /* We're at the table head */ 2167 if (prev == NULL) { /* We're at the table head */
2174 sc->sc_softitds[itd->slot] = itd->u.frame_list.next; 2168 sc->sc_softitds[itd->slot] = itd->u.frame_list.next;
2175 sc->sc_flist[itd->slot] = itd->itd.itd_next; 2169 sc->sc_flist[itd->slot] = itd->itd.itd_next;
2176 usb_syncmem(&sc->sc_fldma, 2170 usb_syncmem(&sc->sc_fldma,
2177 sizeof(ehci_link_t) * itd->slot, 2171 sizeof(ehci_link_t) * itd->slot,
2178 sizeof(ehci_link_t), 2172 sizeof(ehci_link_t),
2179 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 2173 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
2180 2174
2181 if (itd->u.frame_list.next != NULL) 2175 if (itd->u.frame_list.next != NULL)
2182 itd->u.frame_list.next->u.frame_list.prev = NULL; 2176 itd->u.frame_list.next->u.frame_list.prev = NULL;
2183 } else { 2177 } else {
2184 /* XXX this part is untested... */ 2178 /* XXX this part is untested... */
2185 prev->itd.itd_next = itd->itd.itd_next; 2179 prev->itd.itd_next = itd->itd.itd_next;
2186 usb_syncmem(&itd->dma, 2180 usb_syncmem(&itd->dma,
2187 itd->offs + offsetof(ehci_itd_t, itd_next), 2181 itd->offs + offsetof(ehci_itd_t, itd_next),
2188 sizeof(itd->itd.itd_next), BUS_DMASYNC_PREWRITE); 2182 sizeof(itd->itd.itd_next), BUS_DMASYNC_PREWRITE);
2189 2183
2190 prev->u.frame_list.next = itd->u.frame_list.next; 2184 prev->u.frame_list.next = itd->u.frame_list.next;
2191 if (itd->u.frame_list.next != NULL) 2185 if (itd->u.frame_list.next != NULL)
2192 itd->u.frame_list.next->u.frame_list.prev = prev; 2186 itd->u.frame_list.next->u.frame_list.prev = prev;
2193 } 2187 }
2194 } 2188 }
2195 2189
2196 prev = NULL; 2190 prev = NULL;
2197 for (itd = exfer->ex_itdstart; itd != NULL; itd = itd->xfer_next) { 2191 for (itd = exfer->ex_itdstart; itd != NULL; itd = itd->xfer_next) {
2198 if (prev != NULL) 2192 if (prev != NULL)
2199 ehci_free_itd(sc, prev); 2193 ehci_free_itd(sc, prev);
2200 prev = itd; 2194 prev = itd;
2201 } 2195 }
2202 if (prev) 2196 if (prev)
2203 ehci_free_itd(sc, prev); 2197 ehci_free_itd(sc, prev);
2204 exfer->ex_itdstart = NULL; 2198 exfer->ex_itdstart = NULL;
2205 exfer->ex_itdend = NULL; 2199 exfer->ex_itdend = NULL;
2206} 2200}
2207 2201
2208Static void 2202Static void
2209ehci_rem_free_sitd_chain(ehci_softc_t *sc, struct ehci_xfer *exfer) 2203ehci_rem_free_sitd_chain(ehci_softc_t *sc, struct ehci_xfer *exfer)
2210{ 2204{
2211 struct ehci_soft_sitd *sitd, *prev; 2205 struct ehci_soft_sitd *sitd, *prev;
2212 2206
2213 prev = NULL; 2207 prev = NULL;
2214 2208
2215 if (exfer->ex_sitdstart == NULL || exfer->ex_sitdend == NULL) 2209 if (exfer->ex_sitdstart == NULL || exfer->ex_sitdend == NULL)
2216 panic("ehci isoc xfer being freed, but with no sitd chain\n"); 2210 panic("ehci isoc xfer being freed, but with no sitd chain\n");
2217 2211
2218 for (sitd = exfer->ex_sitdstart; sitd != NULL; sitd = sitd->xfer_next) { 2212 for (sitd = exfer->ex_sitdstart; sitd != NULL; sitd = sitd->xfer_next) {
2219 prev = sitd->u.frame_list.prev; 2213 prev = sitd->u.frame_list.prev;
2220 /* Unlink sitd from hardware chain, or frame array */ 2214 /* Unlink sitd from hardware chain, or frame array */
2221 if (prev == NULL) { /* We're at the table head */ 2215 if (prev == NULL) { /* We're at the table head */
2222 sc->sc_softsitds[sitd->slot] = sitd->u.frame_list.next; 2216 sc->sc_softsitds[sitd->slot] = sitd->u.frame_list.next;
2223 sc->sc_flist[sitd->slot] = sitd->sitd.sitd_next; 2217 sc->sc_flist[sitd->slot] = sitd->sitd.sitd_next;
2224 usb_syncmem(&sc->sc_fldma, 2218 usb_syncmem(&sc->sc_fldma,
2225 sizeof(ehci_link_t) * sitd->slot, 2219 sizeof(ehci_link_t) * sitd->slot,
2226 sizeof(ehci_link_t), 2220 sizeof(ehci_link_t),
2227 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 2221 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
2228 2222
2229 if (sitd->u.frame_list.next != NULL) 2223 if (sitd->u.frame_list.next != NULL)
2230 sitd->u.frame_list.next->u.frame_list.prev = NULL; 2224 sitd->u.frame_list.next->u.frame_list.prev = NULL;
2231 } else { 2225 } else {
2232 /* XXX this part is untested... */ 2226 /* XXX this part is untested... */
2233 prev->sitd.sitd_next = sitd->sitd.sitd_next; 2227 prev->sitd.sitd_next = sitd->sitd.sitd_next;
2234 usb_syncmem(&sitd->dma, 2228 usb_syncmem(&sitd->dma,
2235 sitd->offs + offsetof(ehci_sitd_t, sitd_next), 2229 sitd->offs + offsetof(ehci_sitd_t, sitd_next),
2236 sizeof(sitd->sitd.sitd_next), BUS_DMASYNC_PREWRITE); 2230 sizeof(sitd->sitd.sitd_next), BUS_DMASYNC_PREWRITE);
2237 2231
2238 prev->u.frame_list.next = sitd->u.frame_list.next; 2232 prev->u.frame_list.next = sitd->u.frame_list.next;
2239 if (sitd->u.frame_list.next != NULL) 2233 if (sitd->u.frame_list.next != NULL)
2240 sitd->u.frame_list.next->u.frame_list.prev = prev; 2234 sitd->u.frame_list.next->u.frame_list.prev = prev;
2241 } 2235 }
2242 } 2236 }
2243 2237
2244 prev = NULL; 2238 prev = NULL;
2245 for (sitd = exfer->ex_sitdstart; sitd != NULL; sitd = sitd->xfer_next) { 2239 for (sitd = exfer->ex_sitdstart; sitd != NULL; sitd = sitd->xfer_next) {
2246 if (prev != NULL) 2240 if (prev != NULL)
2247 ehci_free_sitd(sc, prev); 2241 ehci_free_sitd(sc, prev);
2248 prev = sitd; 2242 prev = sitd;
2249 } 2243 }
2250 if (prev) 2244 if (prev)
2251 ehci_free_sitd(sc, prev); 2245 ehci_free_sitd(sc, prev);
2252 exfer->ex_sitdstart = NULL; 2246 exfer->ex_sitdstart = NULL;
2253 exfer->ex_sitdend = NULL; 2247 exfer->ex_sitdend = NULL;
2254} 2248}
2255 2249
2256/***********/ 2250/***********/
2257 2251
2258Static int 2252Static int
2259ehci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req, 2253ehci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req,
2260 void *buf, int buflen) 2254 void *buf, int buflen)
2261{ 2255{
2262 ehci_softc_t *sc = bus->ub_hcpriv; 2256 ehci_softc_t *sc = bus->ub_hcpriv;
2263 usb_hub_descriptor_t hubd; 2257 usb_hub_descriptor_t hubd;
2264 usb_port_status_t ps; 2258 usb_port_status_t ps;
2265 uint16_t len, value, index; 2259 uint16_t len, value, index;
2266 int l, totlen = 0; 2260 int l, totlen = 0;
2267 int port, i; 2261 int port, i;
2268 uint32_t v; 2262 uint32_t v;
2269 2263
2270 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2264 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2271 2265
2272 if (sc->sc_dying) 2266 if (sc->sc_dying)
2273 return -1; 2267 return -1;
2274 2268
2275 USBHIST_LOG(ehcidebug, "type=0x%02x request=%02x", 2269 USBHIST_LOG(ehcidebug, "type=0x%02x request=%02x",
2276 req->bmRequestType, req->bRequest, 0, 0); 2270 req->bmRequestType, req->bRequest, 0, 0);
2277 2271
2278 len = UGETW(req->wLength); 2272 len = UGETW(req->wLength);
2279 value = UGETW(req->wValue); 2273 value = UGETW(req->wValue);
2280 index = UGETW(req->wIndex); 2274 index = UGETW(req->wIndex);
2281 2275
2282#define C(x,y) ((x) | ((y) << 8)) 2276#define C(x,y) ((x) | ((y) << 8))
2283 switch (C(req->bRequest, req->bmRequestType)) { 2277 switch (C(req->bRequest, req->bmRequestType)) {
2284 case C(UR_GET_DESCRIPTOR, UT_READ_DEVICE): 2278 case C(UR_GET_DESCRIPTOR, UT_READ_DEVICE):
2285 if (len == 0) 2279 if (len == 0)
2286 break; 2280 break;
2287 switch (value) { 2281 switch (value) {
2288 case C(0, UDESC_DEVICE): { 2282 case C(0, UDESC_DEVICE): {
2289 usb_device_descriptor_t devd; 2283 usb_device_descriptor_t devd;
2290 totlen = min(buflen, sizeof(devd)); 2284 totlen = min(buflen, sizeof(devd));
2291 memcpy(&devd, buf, totlen); 2285 memcpy(&devd, buf, totlen);
2292 USETW(devd.idVendor, sc->sc_id_vendor); 2286 USETW(devd.idVendor, sc->sc_id_vendor);
2293 memcpy(buf, &devd, totlen); 2287 memcpy(buf, &devd, totlen);
2294 break; 2288 break;
2295 2289
2296 } 2290 }
2297#define sd ((usb_string_descriptor_t *)buf) 2291#define sd ((usb_string_descriptor_t *)buf)
2298 case C(1, UDESC_STRING): 2292 case C(1, UDESC_STRING):
2299 /* Vendor */ 2293 /* Vendor */
2300 totlen = usb_makestrdesc(sd, len, sc->sc_vendor); 2294 totlen = usb_makestrdesc(sd, len, sc->sc_vendor);
2301 break; 2295 break;
2302 case C(2, UDESC_STRING): 2296 case C(2, UDESC_STRING):
2303 /* Product */ 2297 /* Product */
2304 totlen = usb_makestrdesc(sd, len, "EHCI root hub"); 2298 totlen = usb_makestrdesc(sd, len, "EHCI root hub");
2305 break; 2299 break;
2306#undef sd 2300#undef sd
2307 default: 2301 default:
2308 /* default from usbroothub */ 2302 /* default from usbroothub */
2309 return buflen; 2303 return buflen;
2310 } 2304 }
2311 break; 2305 break;
2312 2306
2313 /* Hub requests */ 2307 /* Hub requests */
2314 case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_DEVICE): 2308 case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_DEVICE):
2315 break; 2309 break;
2316 case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_OTHER): 2310 case C(UR_CLEAR_FEATURE, UT_WRITE_CLASS_OTHER):
2317 USBHIST_LOG(ehcidebug, 2311 USBHIST_LOG(ehcidebug,
2318 "UR_CLEAR_PORT_FEATURE port=%d feature=%d", index, value, 2312 "UR_CLEAR_PORT_FEATURE port=%d feature=%d", index, value,
2319 0, 0); 2313 0, 0);
2320 if (index < 1 || index > sc->sc_noport) { 2314 if (index < 1 || index > sc->sc_noport) {
2321 return -1; 2315 return -1;
2322 } 2316 }
2323 port = EHCI_PORTSC(index); 2317 port = EHCI_PORTSC(index);
2324 v = EOREAD4(sc, port); 2318 v = EOREAD4(sc, port);
2325 USBHIST_LOG(ehcidebug, "portsc=0x%08x", v, 0, 0, 0); 2319 USBHIST_LOG(ehcidebug, "portsc=0x%08x", v, 0, 0, 0);
2326 v &= ~EHCI_PS_CLEAR; 2320 v &= ~EHCI_PS_CLEAR;
2327 switch (value) { 2321 switch (value) {
2328 case UHF_PORT_ENABLE: 2322 case UHF_PORT_ENABLE:
2329 EOWRITE4(sc, port, v &~ EHCI_PS_PE); 2323 EOWRITE4(sc, port, v &~ EHCI_PS_PE);
2330 break; 2324 break;
2331 case UHF_PORT_SUSPEND: 2325 case UHF_PORT_SUSPEND:
2332 if (!(v & EHCI_PS_SUSP)) /* not suspended */ 2326 if (!(v & EHCI_PS_SUSP)) /* not suspended */
2333 break; 2327 break;
2334 v &= ~EHCI_PS_SUSP; 2328 v &= ~EHCI_PS_SUSP;
2335 EOWRITE4(sc, port, v | EHCI_PS_FPR); 2329 EOWRITE4(sc, port, v | EHCI_PS_FPR);
2336 /* see USB2 spec ch. 7.1.7.7 */ 2330 /* see USB2 spec ch. 7.1.7.7 */
2337 usb_delay_ms(&sc->sc_bus, 20); 2331 usb_delay_ms(&sc->sc_bus, 20);
2338 EOWRITE4(sc, port, v); 2332 EOWRITE4(sc, port, v);
2339 usb_delay_ms(&sc->sc_bus, 2); 2333 usb_delay_ms(&sc->sc_bus, 2);
2340#ifdef DEBUG 2334#ifdef DEBUG
2341 v = EOREAD4(sc, port); 2335 v = EOREAD4(sc, port);
2342 if (v & (EHCI_PS_FPR | EHCI_PS_SUSP)) 2336 if (v & (EHCI_PS_FPR | EHCI_PS_SUSP))
2343 printf("ehci: resume failed: %x\n", v); 2337 printf("ehci: resume failed: %x\n", v);
2344#endif 2338#endif
2345 break; 2339 break;
2346 case UHF_PORT_POWER: 2340 case UHF_PORT_POWER:
2347 if (sc->sc_hasppc) 2341 if (sc->sc_hasppc)
2348 EOWRITE4(sc, port, v &~ EHCI_PS_PP); 2342 EOWRITE4(sc, port, v &~ EHCI_PS_PP);
2349 break; 2343 break;
2350 case UHF_PORT_TEST: 2344 case UHF_PORT_TEST:
2351 USBHIST_LOG(ehcidebug, "clear port test " 2345 USBHIST_LOG(ehcidebug, "clear port test "
2352 "%d", index, 0, 0, 0); 2346 "%d", index, 0, 0, 0);
2353 break; 2347 break;
2354 case UHF_PORT_INDICATOR: 2348 case UHF_PORT_INDICATOR:
2355 USBHIST_LOG(ehcidebug, "clear port ind " 2349 USBHIST_LOG(ehcidebug, "clear port ind "
2356 "%d", index, 0, 0, 0); 2350 "%d", index, 0, 0, 0);
2357 EOWRITE4(sc, port, v &~ EHCI_PS_PIC); 2351 EOWRITE4(sc, port, v &~ EHCI_PS_PIC);
2358 break; 2352 break;
2359 case UHF_C_PORT_CONNECTION: 2353 case UHF_C_PORT_CONNECTION:
2360 EOWRITE4(sc, port, v | EHCI_PS_CSC); 2354 EOWRITE4(sc, port, v | EHCI_PS_CSC);
2361 break; 2355 break;
2362 case UHF_C_PORT_ENABLE: 2356 case UHF_C_PORT_ENABLE:
2363 EOWRITE4(sc, port, v | EHCI_PS_PEC); 2357 EOWRITE4(sc, port, v | EHCI_PS_PEC);
2364 break; 2358 break;
2365 case UHF_C_PORT_SUSPEND: 2359 case UHF_C_PORT_SUSPEND:
2366 /* how? */ 2360 /* how? */
2367 break; 2361 break;
2368 case UHF_C_PORT_OVER_CURRENT: 2362 case UHF_C_PORT_OVER_CURRENT:
2369 EOWRITE4(sc, port, v | EHCI_PS_OCC); 2363 EOWRITE4(sc, port, v | EHCI_PS_OCC);
2370 break; 2364 break;
2371 case UHF_C_PORT_RESET: 2365 case UHF_C_PORT_RESET:
2372 sc->sc_isreset[index] = 0; 2366 sc->sc_isreset[index] = 0;
2373 break; 2367 break;
2374 default: 2368 default:
2375 return -1; 2369 return -1;
2376 } 2370 }
2377#if 0 2371#if 0
2378 switch(value) { 2372 switch(value) {
2379 case UHF_C_PORT_CONNECTION: 2373 case UHF_C_PORT_CONNECTION:
2380 case UHF_C_PORT_ENABLE: 2374 case UHF_C_PORT_ENABLE:
2381 case UHF_C_PORT_SUSPEND: 2375 case UHF_C_PORT_SUSPEND:
2382 case UHF_C_PORT_OVER_CURRENT: 2376 case UHF_C_PORT_OVER_CURRENT:
2383 case UHF_C_PORT_RESET: 2377 case UHF_C_PORT_RESET:
2384 default: 2378 default:
2385 break; 2379 break;
2386 } 2380 }
2387#endif 2381#endif
2388 break; 2382 break;
2389 case C(UR_GET_DESCRIPTOR, UT_READ_CLASS_DEVICE): 2383 case C(UR_GET_DESCRIPTOR, UT_READ_CLASS_DEVICE):
2390 if (len == 0) 2384 if (len == 0)
2391 break; 2385 break;
2392 if ((value & 0xff) != 0) { 2386 if ((value & 0xff) != 0) {
2393 return -1; 2387 return -1;
2394 } 2388 }
2395 totlen = min(buflen, sizeof(hubd)); 2389 totlen = min(buflen, sizeof(hubd));
2396 memcpy(&hubd, buf, totlen); 2390 memcpy(&hubd, buf, totlen);
2397 hubd.bNbrPorts = sc->sc_noport; 2391 hubd.bNbrPorts = sc->sc_noport;
2398 v = EOREAD4(sc, EHCI_HCSPARAMS); 2392 v = EOREAD4(sc, EHCI_HCSPARAMS);
2399 USETW(hubd.wHubCharacteristics, 2393 USETW(hubd.wHubCharacteristics,
2400 EHCI_HCS_PPC(v) ? UHD_PWR_INDIVIDUAL : UHD_PWR_NO_SWITCH | 2394 EHCI_HCS_PPC(v) ? UHD_PWR_INDIVIDUAL : UHD_PWR_NO_SWITCH |
2401 EHCI_HCS_P_INDICATOR(EREAD4(sc, EHCI_HCSPARAMS)) 2395 EHCI_HCS_P_INDICATOR(EREAD4(sc, EHCI_HCSPARAMS))
2402 ? UHD_PORT_IND : 0); 2396 ? UHD_PORT_IND : 0);
2403 hubd.bPwrOn2PwrGood = 200; /* XXX can't find out? */ 2397 hubd.bPwrOn2PwrGood = 200; /* XXX can't find out? */
2404 for (i = 0, l = sc->sc_noport; l > 0; i++, l -= 8, v >>= 8) 2398 for (i = 0, l = sc->sc_noport; l > 0; i++, l -= 8, v >>= 8)
2405 hubd.DeviceRemovable[i++] = 0; /* XXX can't find out? */ 2399 hubd.DeviceRemovable[i++] = 0; /* XXX can't find out? */
2406 hubd.bDescLength = USB_HUB_DESCRIPTOR_SIZE + i; 2400 hubd.bDescLength = USB_HUB_DESCRIPTOR_SIZE + i;
2407 totlen = min(totlen, hubd.bDescLength); 2401 totlen = min(totlen, hubd.bDescLength);
2408 memcpy(buf, &hubd, totlen); 2402 memcpy(buf, &hubd, totlen);
2409 break; 2403 break;
2410 case C(UR_GET_STATUS, UT_READ_CLASS_DEVICE): 2404 case C(UR_GET_STATUS, UT_READ_CLASS_DEVICE):
2411 if (len != 4) { 2405 if (len != 4) {
2412 return -1; 2406 return -1;
2413 } 2407 }
2414 memset(buf, 0, len); /* ? XXX */ 2408 memset(buf, 0, len); /* ? XXX */
2415 totlen = len; 2409 totlen = len;
2416 break; 2410 break;
2417 case C(UR_GET_STATUS, UT_READ_CLASS_OTHER): 2411 case C(UR_GET_STATUS, UT_READ_CLASS_OTHER):
2418 USBHIST_LOG(ehcidebug, "get port status i=%d", index, 0, 0, 0); 2412 USBHIST_LOG(ehcidebug, "get port status i=%d", index, 0, 0, 0);
2419 if (index < 1 || index > sc->sc_noport) { 2413 if (index < 1 || index > sc->sc_noport) {
2420 return -1; 2414 return -1;
2421 } 2415 }
2422 if (len != 4) { 2416 if (len != 4) {
2423 return -1; 2417 return -1;
2424 } 2418 }
2425 v = EOREAD4(sc, EHCI_PORTSC(index)); 2419 v = EOREAD4(sc, EHCI_PORTSC(index));
2426 USBHIST_LOG(ehcidebug, "port status=0x%04x", v, 0, 0, 0); 2420 USBHIST_LOG(ehcidebug, "port status=0x%04x", v, 0, 0, 0);
2427 2421
2428 i = UPS_HIGH_SPEED; 2422 i = UPS_HIGH_SPEED;
2429 if (sc->sc_flags & EHCIF_ETTF) { 2423 if (sc->sc_flags & EHCIF_ETTF) {
2430 /* 2424 /*
2431 * If we are doing embedded transaction translation, 2425 * If we are doing embedded transaction translation,
2432 * then directly attached LS/FS devices are reset by 2426 * then directly attached LS/FS devices are reset by
2433 * the EHCI controller itself. PSPD is encoded 2427 * the EHCI controller itself. PSPD is encoded
2434 * the same way as in USBSTATUS. 2428 * the same way as in USBSTATUS.
2435 */ 2429 */
2436 i = __SHIFTOUT(v, EHCI_PS_PSPD) * UPS_LOW_SPEED; 2430 i = __SHIFTOUT(v, EHCI_PS_PSPD) * UPS_LOW_SPEED;
2437 } 2431 }
2438 if (v & EHCI_PS_CS) i |= UPS_CURRENT_CONNECT_STATUS; 2432 if (v & EHCI_PS_CS) i |= UPS_CURRENT_CONNECT_STATUS;
2439 if (v & EHCI_PS_PE) i |= UPS_PORT_ENABLED; 2433 if (v & EHCI_PS_PE) i |= UPS_PORT_ENABLED;
2440 if (v & EHCI_PS_SUSP) i |= UPS_SUSPEND; 2434 if (v & EHCI_PS_SUSP) i |= UPS_SUSPEND;
2441 if (v & EHCI_PS_OCA) i |= UPS_OVERCURRENT_INDICATOR; 2435 if (v & EHCI_PS_OCA) i |= UPS_OVERCURRENT_INDICATOR;
2442 if (v & EHCI_PS_PR) i |= UPS_RESET; 2436 if (v & EHCI_PS_PR) i |= UPS_RESET;
2443 if (v & EHCI_PS_PP) i |= UPS_PORT_POWER; 2437 if (v & EHCI_PS_PP) i |= UPS_PORT_POWER;
2444 if (sc->sc_vendor_port_status) 2438 if (sc->sc_vendor_port_status)
2445 i = sc->sc_vendor_port_status(sc, v, i); 2439 i = sc->sc_vendor_port_status(sc, v, i);
2446 USETW(ps.wPortStatus, i); 2440 USETW(ps.wPortStatus, i);
2447 i = 0; 2441 i = 0;
2448 if (v & EHCI_PS_CSC) i |= UPS_C_CONNECT_STATUS; 2442 if (v & EHCI_PS_CSC) i |= UPS_C_CONNECT_STATUS;
2449 if (v & EHCI_PS_PEC) i |= UPS_C_PORT_ENABLED; 2443 if (v & EHCI_PS_PEC) i |= UPS_C_PORT_ENABLED;
2450 if (v & EHCI_PS_OCC) i |= UPS_C_OVERCURRENT_INDICATOR; 2444 if (v & EHCI_PS_OCC) i |= UPS_C_OVERCURRENT_INDICATOR;
2451 if (sc->sc_isreset[index]) i |= UPS_C_PORT_RESET; 2445 if (sc->sc_isreset[index]) i |= UPS_C_PORT_RESET;
2452 USETW(ps.wPortChange, i); 2446 USETW(ps.wPortChange, i);
2453 totlen = min(len, sizeof(ps)); 2447 totlen = min(len, sizeof(ps));
2454 memcpy(buf, &ps, totlen); 2448 memcpy(buf, &ps, totlen);
2455 break; 2449 break;
2456 case C(UR_SET_DESCRIPTOR, UT_WRITE_CLASS_DEVICE): 2450 case C(UR_SET_DESCRIPTOR, UT_WRITE_CLASS_DEVICE):
2457 return -1; 2451 return -1;
2458 case C(UR_SET_FEATURE, UT_WRITE_CLASS_DEVICE): 2452 case C(UR_SET_FEATURE, UT_WRITE_CLASS_DEVICE):
2459 break; 2453 break;
2460 case C(UR_SET_FEATURE, UT_WRITE_CLASS_OTHER): 2454 case C(UR_SET_FEATURE, UT_WRITE_CLASS_OTHER):
2461 if (index < 1 || index > sc->sc_noport) { 2455 if (index < 1 || index > sc->sc_noport) {
2462 return -1; 2456 return -1;
2463 } 2457 }
2464 port = EHCI_PORTSC(index); 2458 port = EHCI_PORTSC(index);
2465 v = EOREAD4(sc, port); 2459 v = EOREAD4(sc, port);
2466 USBHIST_LOG(ehcidebug, "portsc=0x%08x", v, 0, 0, 0); 2460 USBHIST_LOG(ehcidebug, "portsc=0x%08x", v, 0, 0, 0);
2467 v &= ~EHCI_PS_CLEAR; 2461 v &= ~EHCI_PS_CLEAR;
2468 switch(value) { 2462 switch(value) {
2469 case UHF_PORT_ENABLE: 2463 case UHF_PORT_ENABLE:
2470 EOWRITE4(sc, port, v | EHCI_PS_PE); 2464 EOWRITE4(sc, port, v | EHCI_PS_PE);
2471 break; 2465 break;
2472 case UHF_PORT_SUSPEND: 2466 case UHF_PORT_SUSPEND:
2473 EOWRITE4(sc, port, v | EHCI_PS_SUSP); 2467 EOWRITE4(sc, port, v | EHCI_PS_SUSP);
2474 break; 2468 break;
2475 case UHF_PORT_RESET: 2469 case UHF_PORT_RESET:
2476 USBHIST_LOG(ehcidebug, "reset port %d", index, 0, 0, 0); 2470 USBHIST_LOG(ehcidebug, "reset port %d", index, 0, 0, 0);
2477 if (EHCI_PS_IS_LOWSPEED(v) 2471 if (EHCI_PS_IS_LOWSPEED(v)
2478 && sc->sc_ncomp > 0 2472 && sc->sc_ncomp > 0
2479 && !(sc->sc_flags & EHCIF_ETTF)) { 2473 && !(sc->sc_flags & EHCIF_ETTF)) {
2480 /* 2474 /*
2481 * Low speed device on non-ETTF controller or 2475 * Low speed device on non-ETTF controller or
2482 * unaccompanied controller, give up ownership. 2476 * unaccompanied controller, give up ownership.
2483 */ 2477 */
2484 ehci_disown(sc, index, 1); 2478 ehci_disown(sc, index, 1);
2485 break; 2479 break;
2486 } 2480 }
2487 /* Start reset sequence. */ 2481 /* Start reset sequence. */
2488 v &= ~ (EHCI_PS_PE | EHCI_PS_PR); 2482 v &= ~ (EHCI_PS_PE | EHCI_PS_PR);
2489 EOWRITE4(sc, port, v | EHCI_PS_PR); 2483 EOWRITE4(sc, port, v | EHCI_PS_PR);
2490 /* Wait for reset to complete. */ 2484 /* Wait for reset to complete. */
2491 usb_delay_ms(&sc->sc_bus, USB_PORT_ROOT_RESET_DELAY); 2485 usb_delay_ms(&sc->sc_bus, USB_PORT_ROOT_RESET_DELAY);
2492 if (sc->sc_dying) { 2486 if (sc->sc_dying) {
2493 return -1; 2487 return -1;
2494 } 2488 }
2495 /* 2489 /*
2496 * An embedded transaction translator will automatically 2490 * An embedded transaction translator will automatically
2497 * terminate the reset sequence so there's no need to 2491 * terminate the reset sequence so there's no need to
2498 * it. 2492 * it.
2499 */ 2493 */
2500 v = EOREAD4(sc, port); 2494 v = EOREAD4(sc, port);
2501 if (v & EHCI_PS_PR) { 2495 if (v & EHCI_PS_PR) {
2502 /* Terminate reset sequence. */ 2496 /* Terminate reset sequence. */
2503 EOWRITE4(sc, port, v & ~EHCI_PS_PR); 2497 EOWRITE4(sc, port, v & ~EHCI_PS_PR);
2504 /* Wait for HC to complete reset. */ 2498 /* Wait for HC to complete reset. */
2505 usb_delay_ms(&sc->sc_bus, 2499 usb_delay_ms(&sc->sc_bus,
2506 EHCI_PORT_RESET_COMPLETE); 2500 EHCI_PORT_RESET_COMPLETE);
2507 if (sc->sc_dying) { 2501 if (sc->sc_dying) {
2508 return -1; 2502 return -1;
2509 } 2503 }
2510 } 2504 }
2511 2505
2512 v = EOREAD4(sc, port); 2506 v = EOREAD4(sc, port);
2513 USBHIST_LOG(ehcidebug, 2507 USBHIST_LOG(ehcidebug,
2514 "ehci after reset, status=0x%08x", v, 0, 0, 0); 2508 "ehci after reset, status=0x%08x", v, 0, 0, 0);
2515 if (v & EHCI_PS_PR) { 2509 if (v & EHCI_PS_PR) {
2516 printf("%s: port reset timeout\n", 2510 printf("%s: port reset timeout\n",
2517 device_xname(sc->sc_dev)); 2511 device_xname(sc->sc_dev));
2518 return USBD_TIMEOUT; 2512 return USBD_TIMEOUT;
2519 } 2513 }
2520 if (!(v & EHCI_PS_PE)) { 2514 if (!(v & EHCI_PS_PE)) {
2521 /* Not a high speed device, give up ownership.*/ 2515 /* Not a high speed device, give up ownership.*/
2522 ehci_disown(sc, index, 0); 2516 ehci_disown(sc, index, 0);
2523 break; 2517 break;
2524 } 2518 }
2525 sc->sc_isreset[index] = 1; 2519 sc->sc_isreset[index] = 1;
2526 USBHIST_LOG(ehcidebug, 2520 USBHIST_LOG(ehcidebug,
2527 "ehci port %d reset, status = 0x%08x", index, v, 0, 2521 "ehci port %d reset, status = 0x%08x", index, v, 0,
2528 0); 2522 0);
2529 break; 2523 break;
2530 case UHF_PORT_POWER: 2524 case UHF_PORT_POWER:
2531 USBHIST_LOG(ehcidebug, 2525 USBHIST_LOG(ehcidebug,
2532 "set port power %d (has PPC = %d)", index, 2526 "set port power %d (has PPC = %d)", index,
2533 sc->sc_hasppc, 0, 0); 2527 sc->sc_hasppc, 0, 0);
2534 if (sc->sc_hasppc) 2528 if (sc->sc_hasppc)
2535 EOWRITE4(sc, port, v | EHCI_PS_PP); 2529 EOWRITE4(sc, port, v | EHCI_PS_PP);
2536 break; 2530 break;
2537 case UHF_PORT_TEST: 2531 case UHF_PORT_TEST:
2538 USBHIST_LOG(ehcidebug, "set port test %d", 2532 USBHIST_LOG(ehcidebug, "set port test %d",
2539 index, 0, 0, 0); 2533 index, 0, 0, 0);
2540 break; 2534 break;
2541 case UHF_PORT_INDICATOR: 2535 case UHF_PORT_INDICATOR:
2542 USBHIST_LOG(ehcidebug, "set port ind %d", 2536 USBHIST_LOG(ehcidebug, "set port ind %d",
2543 index, 0, 0, 0); 2537 index, 0, 0, 0);
2544 EOWRITE4(sc, port, v | EHCI_PS_PIC); 2538 EOWRITE4(sc, port, v | EHCI_PS_PIC);
2545 break; 2539 break;
2546 default: 2540 default:
2547 return -1; 2541 return -1;
2548 } 2542 }
2549 break; 2543 break;
2550 case C(UR_CLEAR_TT_BUFFER, UT_WRITE_CLASS_OTHER): 2544 case C(UR_CLEAR_TT_BUFFER, UT_WRITE_CLASS_OTHER):
2551 case C(UR_RESET_TT, UT_WRITE_CLASS_OTHER): 2545 case C(UR_RESET_TT, UT_WRITE_CLASS_OTHER):
2552 case C(UR_GET_TT_STATE, UT_READ_CLASS_OTHER): 2546 case C(UR_GET_TT_STATE, UT_READ_CLASS_OTHER):
2553 case C(UR_STOP_TT, UT_WRITE_CLASS_OTHER): 2547 case C(UR_STOP_TT, UT_WRITE_CLASS_OTHER):
2554 break; 2548 break;
2555 default: 2549 default:
2556 /* default from usbroothub */ 2550 /* default from usbroothub */
2557 USBHIST_LOG(ehcidebug, "returning %d (usbroothub default)", 2551 USBHIST_LOG(ehcidebug, "returning %d (usbroothub default)",
2558 buflen, 0, 0, 0); 2552 buflen, 0, 0, 0);
2559 2553
2560 return buflen; 2554 return buflen;
2561 } 2555 }
2562 2556
2563 USBHIST_LOG(ehcidebug, "returning %d", totlen, 0, 0, 0); 2557 USBHIST_LOG(ehcidebug, "returning %d", totlen, 0, 0, 0);
2564 2558
2565 return totlen; 2559 return totlen;
2566} 2560}
2567 2561
2568Static void 2562Static void
2569ehci_disown(ehci_softc_t *sc, int index, int lowspeed) 2563ehci_disown(ehci_softc_t *sc, int index, int lowspeed)
2570{ 2564{
2571 int port; 2565 int port;
2572 uint32_t v; 2566 uint32_t v;
2573 2567
2574 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2568 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2575 2569
2576 USBHIST_LOG(ehcidebug, "index=%d lowspeed=%d", index, lowspeed, 0, 0); 2570 USBHIST_LOG(ehcidebug, "index=%d lowspeed=%d", index, lowspeed, 0, 0);
2577#ifdef DIAGNOSTIC 2571#ifdef DIAGNOSTIC
2578 if (sc->sc_npcomp != 0) { 2572 if (sc->sc_npcomp != 0) {
2579 int i = (index-1) / sc->sc_npcomp; 2573 int i = (index-1) / sc->sc_npcomp;
2580 if (i >= sc->sc_ncomp) 2574 if (i >= sc->sc_ncomp)
2581 printf("%s: strange port\n", 2575 printf("%s: strange port\n",
2582 device_xname(sc->sc_dev)); 2576 device_xname(sc->sc_dev));
2583 else 2577 else
2584 printf("%s: handing over %s speed device on " 2578 printf("%s: handing over %s speed device on "
2585 "port %d to %s\n", 2579 "port %d to %s\n",
2586 device_xname(sc->sc_dev), 2580 device_xname(sc->sc_dev),
2587 lowspeed ? "low" : "full", 2581 lowspeed ? "low" : "full",
2588 index, device_xname(sc->sc_comps[i])); 2582 index, device_xname(sc->sc_comps[i]));
2589 } else { 2583 } else {
2590 printf("%s: npcomp == 0\n", device_xname(sc->sc_dev)); 2584 printf("%s: npcomp == 0\n", device_xname(sc->sc_dev));
2591 } 2585 }
2592#endif 2586#endif
2593 port = EHCI_PORTSC(index); 2587 port = EHCI_PORTSC(index);
2594 v = EOREAD4(sc, port) &~ EHCI_PS_CLEAR; 2588 v = EOREAD4(sc, port) &~ EHCI_PS_CLEAR;
2595 EOWRITE4(sc, port, v | EHCI_PS_PO); 2589 EOWRITE4(sc, port, v | EHCI_PS_PO);
2596} 2590}
2597 2591
2598Static usbd_status 2592Static usbd_status
2599ehci_root_intr_transfer(usbd_xfer_handle xfer) 2593ehci_root_intr_transfer(usbd_xfer_handle xfer)
2600{ 2594{
2601 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 2595 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
2602 usbd_status err; 2596 usbd_status err;
2603 2597
2604 /* Insert last in queue. */ 2598 /* Insert last in queue. */
2605 mutex_enter(&sc->sc_lock); 2599 mutex_enter(&sc->sc_lock);
2606 err = usb_insert_transfer(xfer); 2600 err = usb_insert_transfer(xfer);
2607 mutex_exit(&sc->sc_lock); 2601 mutex_exit(&sc->sc_lock);
2608 if (err) 2602 if (err)
2609 return err; 2603 return err;
2610 2604
2611 /* Pipe isn't running, start first */ 2605 /* Pipe isn't running, start first */
2612 return ehci_root_intr_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); 2606 return ehci_root_intr_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue));
2613} 2607}
2614 2608
2615Static usbd_status 2609Static usbd_status
2616ehci_root_intr_start(usbd_xfer_handle xfer) 2610ehci_root_intr_start(usbd_xfer_handle xfer)
2617{ 2611{
2618 usbd_pipe_handle pipe = xfer->ux_pipe; 2612 usbd_pipe_handle pipe = xfer->ux_pipe;
2619 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; 2613 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
2620 2614
2621 if (sc->sc_dying) 2615 if (sc->sc_dying)
2622 return USBD_IOERROR; 2616 return USBD_IOERROR;
2623 2617
2624 mutex_enter(&sc->sc_lock); 2618 mutex_enter(&sc->sc_lock);
2625 sc->sc_intrxfer = xfer; 2619 sc->sc_intrxfer = xfer;
2626 mutex_exit(&sc->sc_lock); 2620 mutex_exit(&sc->sc_lock);
2627 2621
2628 return USBD_IN_PROGRESS; 2622 return USBD_IN_PROGRESS;
2629} 2623}
2630 2624
2631/* Abort a root interrupt request. */ 2625/* Abort a root interrupt request. */
2632Static void 2626Static void
2633ehci_root_intr_abort(usbd_xfer_handle xfer) 2627ehci_root_intr_abort(usbd_xfer_handle xfer)
2634{ 2628{
2635 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 2629 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
2636 2630
2637 KASSERT(mutex_owned(&sc->sc_lock)); 2631 KASSERT(mutex_owned(&sc->sc_lock));
2638 KASSERT(xfer->ux_pipe->up_intrxfer == xfer); 2632 KASSERT(xfer->ux_pipe->up_intrxfer == xfer);
2639 2633
2640 sc->sc_intrxfer = NULL; 2634 sc->sc_intrxfer = NULL;
2641 2635
2642 xfer->ux_status = USBD_CANCELLED; 2636 xfer->ux_status = USBD_CANCELLED;
2643 usb_transfer_complete(xfer); 2637 usb_transfer_complete(xfer);
2644} 2638}
2645 2639
2646/* Close the root pipe. */ 2640/* Close the root pipe. */
2647Static void 2641Static void
2648ehci_root_intr_close(usbd_pipe_handle pipe) 2642ehci_root_intr_close(usbd_pipe_handle pipe)
2649{ 2643{
2650 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; 2644 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
2651 2645
2652 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2646 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2653 2647
2654 KASSERT(mutex_owned(&sc->sc_lock)); 2648 KASSERT(mutex_owned(&sc->sc_lock));
2655 2649
2656 sc->sc_intrxfer = NULL; 2650 sc->sc_intrxfer = NULL;
2657} 2651}
2658 2652
2659Static void 2653Static void
2660ehci_root_intr_done(usbd_xfer_handle xfer) 2654ehci_root_intr_done(usbd_xfer_handle xfer)
2661{ 2655{
2662 xfer->ux_hcpriv = NULL; 2656 xfer->ux_hcpriv = NULL;
2663} 2657}
2664 2658
2665/************************/ 2659/************************/
2666 2660
2667Static ehci_soft_qh_t * 2661Static ehci_soft_qh_t *
2668ehci_alloc_sqh(ehci_softc_t *sc) 2662ehci_alloc_sqh(ehci_softc_t *sc)
2669{ 2663{
2670 ehci_soft_qh_t *sqh; 2664 ehci_soft_qh_t *sqh;
2671 usbd_status err; 2665 usbd_status err;
2672 int i, offs; 2666 int i, offs;
2673 usb_dma_t dma; 2667 usb_dma_t dma;
2674 2668
2675 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2669 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2676 2670
2677 if (sc->sc_freeqhs == NULL) { 2671 if (sc->sc_freeqhs == NULL) {
2678 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); 2672 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0);
2679 err = usb_allocmem(&sc->sc_bus, EHCI_SQH_SIZE * EHCI_SQH_CHUNK, 2673 err = usb_allocmem(&sc->sc_bus, EHCI_SQH_SIZE * EHCI_SQH_CHUNK,
2680 EHCI_PAGE_SIZE, &dma); 2674 EHCI_PAGE_SIZE, &dma);
2681#ifdef EHCI_DEBUG 2675#ifdef EHCI_DEBUG
2682 if (err) 2676 if (err)
2683 printf("ehci_alloc_sqh: usb_allocmem()=%d\n", err); 2677 printf("ehci_alloc_sqh: usb_allocmem()=%d\n", err);
2684#endif 2678#endif
2685 if (err) 2679 if (err)
2686 return NULL; 2680 return NULL;
2687 for (i = 0; i < EHCI_SQH_CHUNK; i++) { 2681 for (i = 0; i < EHCI_SQH_CHUNK; i++) {
2688 offs = i * EHCI_SQH_SIZE; 2682 offs = i * EHCI_SQH_SIZE;
2689 sqh = KERNADDR(&dma, offs); 2683 sqh = KERNADDR(&dma, offs);
2690 sqh->physaddr = DMAADDR(&dma, offs); 2684 sqh->physaddr = DMAADDR(&dma, offs);
2691 sqh->dma = dma; 2685 sqh->dma = dma;
2692 sqh->offs = offs; 2686 sqh->offs = offs;
2693 sqh->next = sc->sc_freeqhs; 2687 sqh->next = sc->sc_freeqhs;
2694 sc->sc_freeqhs = sqh; 2688 sc->sc_freeqhs = sqh;
2695 } 2689 }
2696 } 2690 }
2697 sqh = sc->sc_freeqhs; 2691 sqh = sc->sc_freeqhs;
2698 sc->sc_freeqhs = sqh->next; 2692 sc->sc_freeqhs = sqh->next;
2699 memset(&sqh->qh, 0, sizeof(ehci_qh_t)); 2693 memset(&sqh->qh, 0, sizeof(ehci_qh_t));
2700 sqh->next = NULL; 2694 sqh->next = NULL;
2701 return sqh; 2695 return sqh;
2702} 2696}
2703 2697
2704Static void 2698Static void
2705ehci_free_sqh(ehci_softc_t *sc, ehci_soft_qh_t *sqh) 2699ehci_free_sqh(ehci_softc_t *sc, ehci_soft_qh_t *sqh)
2706{ 2700{
2707 sqh->next = sc->sc_freeqhs; 2701 sqh->next = sc->sc_freeqhs;
2708 sc->sc_freeqhs = sqh; 2702 sc->sc_freeqhs = sqh;
2709} 2703}
2710 2704
2711Static ehci_soft_qtd_t * 2705Static ehci_soft_qtd_t *
2712ehci_alloc_sqtd(ehci_softc_t *sc) 2706ehci_alloc_sqtd(ehci_softc_t *sc)
2713{ 2707{
2714 ehci_soft_qtd_t *sqtd = NULL; 2708 ehci_soft_qtd_t *sqtd = NULL;
2715 usbd_status err; 2709 usbd_status err;
2716 int i, offs; 2710 int i, offs;
2717 usb_dma_t dma; 2711 usb_dma_t dma;
2718 2712
2719 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2713 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2720 2714
2721 if (sc->sc_freeqtds == NULL) { 2715 if (sc->sc_freeqtds == NULL) {
2722 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); 2716 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0);
2723 2717
2724 err = usb_allocmem(&sc->sc_bus, EHCI_SQTD_SIZE*EHCI_SQTD_CHUNK, 2718 err = usb_allocmem(&sc->sc_bus, EHCI_SQTD_SIZE*EHCI_SQTD_CHUNK,
2725 EHCI_PAGE_SIZE, &dma); 2719 EHCI_PAGE_SIZE, &dma);
2726#ifdef EHCI_DEBUG 2720#ifdef EHCI_DEBUG
2727 if (err) 2721 if (err)
2728 printf("ehci_alloc_sqtd: usb_allocmem()=%d\n", err); 2722 printf("ehci_alloc_sqtd: usb_allocmem()=%d\n", err);
2729#endif 2723#endif
2730 if (err) 2724 if (err)
2731 goto done; 2725 goto done;
2732 2726
2733 for (i = 0; i < EHCI_SQTD_CHUNK; i++) { 2727 for (i = 0; i < EHCI_SQTD_CHUNK; i++) {
2734 offs = i * EHCI_SQTD_SIZE; 2728 offs = i * EHCI_SQTD_SIZE;
2735 sqtd = KERNADDR(&dma, offs); 2729 sqtd = KERNADDR(&dma, offs);
2736 sqtd->physaddr = DMAADDR(&dma, offs); 2730 sqtd->physaddr = DMAADDR(&dma, offs);
2737 sqtd->dma = dma; 2731 sqtd->dma = dma;
2738 sqtd->offs = offs; 2732 sqtd->offs = offs;
2739 2733
2740 sqtd->nextqtd = sc->sc_freeqtds; 2734 sqtd->nextqtd = sc->sc_freeqtds;
2741 sc->sc_freeqtds = sqtd; 2735 sc->sc_freeqtds = sqtd;
2742 } 2736 }
2743 } 2737 }
2744 2738
2745 sqtd = sc->sc_freeqtds; 2739 sqtd = sc->sc_freeqtds;
2746 sc->sc_freeqtds = sqtd->nextqtd; 2740 sc->sc_freeqtds = sqtd->nextqtd;
2747 memset(&sqtd->qtd, 0, sizeof(ehci_qtd_t)); 2741 memset(&sqtd->qtd, 0, sizeof(ehci_qtd_t));
2748 sqtd->nextqtd = NULL; 2742 sqtd->nextqtd = NULL;
2749 sqtd->xfer = NULL; 2743 sqtd->xfer = NULL;
2750 2744
2751done: 2745done:
2752 return sqtd; 2746 return sqtd;
2753} 2747}
2754 2748
2755Static void 2749Static void
2756ehci_free_sqtd(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd) 2750ehci_free_sqtd(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd)
2757{ 2751{
2758 2752
2759 KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); 2753 KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock));
2760 2754
2761 sqtd->nextqtd = sc->sc_freeqtds; 2755 sqtd->nextqtd = sc->sc_freeqtds;
2762 sc->sc_freeqtds = sqtd; 2756 sc->sc_freeqtds = sqtd;
2763} 2757}
2764 2758
2765Static usbd_status 2759Static usbd_status
2766ehci_alloc_sqtd_chain(struct ehci_pipe *epipe, ehci_softc_t *sc, 2760ehci_alloc_sqtd_chain(struct ehci_pipe *epipe, ehci_softc_t *sc,
2767 int alen, int rd, usbd_xfer_handle xfer, 2761 int alen, int rd, usbd_xfer_handle xfer,
2768 ehci_soft_qtd_t **sp, ehci_soft_qtd_t **ep) 2762 ehci_soft_qtd_t **sp, ehci_soft_qtd_t **ep)
2769{ 2763{
2770 ehci_soft_qtd_t *next, *cur; 2764 ehci_soft_qtd_t *next, *cur;
2771 ehci_physaddr_t nextphys; 2765 ehci_physaddr_t nextphys;
2772 uint32_t qtdstatus; 2766 uint32_t qtdstatus;
2773 int len, curlen, mps; 2767 int len, curlen, mps;
2774 int i, tog; 2768 int i, tog;
2775 int pages, pageoffs; 2769 int pages, pageoffs;
2776 bus_size_t curoffs; 2770 bus_size_t curoffs;
2777 vaddr_t va, va_offs; 2771 vaddr_t va, va_offs;
2778 usb_dma_t *dma = &xfer->ux_dmabuf; 2772 usb_dma_t *dma = &xfer->ux_dmabuf;
2779 uint16_t flags = xfer->ux_flags; 2773 uint16_t flags = xfer->ux_flags;
2780 paddr_t a; 2774 paddr_t a;
2781 2775
2782 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2776 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2783 2777
2784 USBHIST_LOG(ehcidebug, "start len=%d", alen, 0, 0, 0); 2778 USBHIST_LOG(ehcidebug, "start len=%d", alen, 0, 0, 0);
2785 2779
2786 len = alen; 2780 len = alen;
2787 qtdstatus = EHCI_QTD_ACTIVE | 2781 qtdstatus = EHCI_QTD_ACTIVE |
2788 EHCI_QTD_SET_PID(rd ? EHCI_QTD_PID_IN : EHCI_QTD_PID_OUT) | 2782 EHCI_QTD_SET_PID(rd ? EHCI_QTD_PID_IN : EHCI_QTD_PID_OUT) |
2789 EHCI_QTD_SET_CERR(3) 2783 EHCI_QTD_SET_CERR(3)
2790 /* IOC set below */ 2784 /* IOC set below */
2791 /* BYTES set below */ 2785 /* BYTES set below */
2792 ; 2786 ;
2793 mps = UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize); 2787 mps = UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize);
2794 tog = epipe->nexttoggle; 2788 tog = epipe->nexttoggle;
2795 qtdstatus |= EHCI_QTD_SET_TOGGLE(tog); 2789 qtdstatus |= EHCI_QTD_SET_TOGGLE(tog);
2796 2790
2797 cur = ehci_alloc_sqtd(sc); 2791 cur = ehci_alloc_sqtd(sc);
2798 *sp = cur; 2792 *sp = cur;
2799 if (cur == NULL) 2793 if (cur == NULL)
2800 goto nomem; 2794 goto nomem;
2801 2795
2802 usb_syncmem(dma, 0, alen, 2796 usb_syncmem(dma, 0, alen,
2803 rd ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE); 2797 rd ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
2804 curoffs = 0; 2798 curoffs = 0;
2805 for (;;) { 2799 for (;;) {
2806 /* The EHCI hardware can handle at most 5 pages. */ 2800 /* The EHCI hardware can handle at most 5 pages. */
2807 va_offs = (vaddr_t)KERNADDR(dma, curoffs); 2801 va_offs = (vaddr_t)KERNADDR(dma, curoffs);
2808 va_offs = EHCI_PAGE_OFFSET(va_offs); 2802 va_offs = EHCI_PAGE_OFFSET(va_offs);
2809 if (len-curoffs < EHCI_QTD_MAXTRANSFER - va_offs) { 2803 if (len-curoffs < EHCI_QTD_MAXTRANSFER - va_offs) {
2810 /* we can handle it in this QTD */ 2804 /* we can handle it in this QTD */
2811 curlen = len - curoffs; 2805 curlen = len - curoffs;
2812 } else { 2806 } else {
2813 /* must use multiple TDs, fill as much as possible. */ 2807 /* must use multiple TDs, fill as much as possible. */
2814 curlen = EHCI_QTD_MAXTRANSFER - va_offs; 2808 curlen = EHCI_QTD_MAXTRANSFER - va_offs;
2815 2809
2816 /* the length must be a multiple of the max size */ 2810 /* the length must be a multiple of the max size */
2817 curlen -= curlen % mps; 2811 curlen -= curlen % mps;
2818 USBHIST_LOG(ehcidebug, "multiple QTDs, " 2812 USBHIST_LOG(ehcidebug, "multiple QTDs, "
2819 "curlen=%d", curlen, 0, 0, 0); 2813 "curlen=%d", curlen, 0, 0, 0);
2820 KASSERT(curlen != 0); 2814 KASSERT(curlen != 0);
2821 } 2815 }
2822 USBHIST_LOG(ehcidebug, "len=%d curlen=%d curoffs=%zu", 2816 USBHIST_LOG(ehcidebug, "len=%d curlen=%d curoffs=%zu",
2823 len, curlen, (size_t)curoffs, 0); 2817 len, curlen, (size_t)curoffs, 0);
2824 2818
2825 /* 2819 /*
2826 * Allocate another transfer if there's more data left, 2820 * Allocate another transfer if there's more data left,
2827 * or if force last short transfer flag is set and we're 2821 * or if force last short transfer flag is set and we're
2828 * allocating a multiple of the max packet size. 2822 * allocating a multiple of the max packet size.
2829 */ 2823 */
2830 2824
2831 if (curoffs + curlen != len || 2825 if (curoffs + curlen != len ||
2832 ((curlen % mps) == 0 && !rd && curlen != 0 && 2826 ((curlen % mps) == 0 && !rd && curlen != 0 &&
2833 (flags & USBD_FORCE_SHORT_XFER))) { 2827 (flags & USBD_FORCE_SHORT_XFER))) {
2834 next = ehci_alloc_sqtd(sc); 2828 next = ehci_alloc_sqtd(sc);
2835 if (next == NULL) 2829 if (next == NULL)
2836 goto nomem; 2830 goto nomem;
2837 nextphys = htole32(next->physaddr); 2831 nextphys = htole32(next->physaddr);
2838 } else { 2832 } else {
2839 next = NULL; 2833 next = NULL;
2840 nextphys = EHCI_NULL; 2834 nextphys = EHCI_NULL;
2841 } 2835 }
2842 2836
2843 /* Find number of pages we'll be using, insert dma addresses */ 2837 /* Find number of pages we'll be using, insert dma addresses */
2844 pages = EHCI_PAGE(curlen + EHCI_PAGE_SIZE - 1) >> 12; 2838 pages = EHCI_PAGE(curlen + EHCI_PAGE_SIZE - 1) >> 12;
2845 KASSERT(pages <= EHCI_QTD_NBUFFERS); 2839 KASSERT(pages <= EHCI_QTD_NBUFFERS);
2846 pageoffs = EHCI_PAGE(curoffs); 2840 pageoffs = EHCI_PAGE(curoffs);
2847 for (i = 0; i < pages; i++) { 2841 for (i = 0; i < pages; i++) {
2848 a = DMAADDR(dma, pageoffs + i * EHCI_PAGE_SIZE); 2842 a = DMAADDR(dma, pageoffs + i * EHCI_PAGE_SIZE);
2849 cur->qtd.qtd_buffer[i] = htole32(a & 0xFFFFF000); 2843 cur->qtd.qtd_buffer[i] = htole32(a & 0xFFFFF000);
2850 /* Cast up to avoid compiler warnings */ 2844 /* Cast up to avoid compiler warnings */
2851 cur->qtd.qtd_buffer_hi[i] = htole32((uint64_t)a >> 32); 2845 cur->qtd.qtd_buffer_hi[i] = htole32((uint64_t)a >> 32);
2852 } 2846 }
2853 2847
2854 /* First buffer pointer requires a page offset to start at */ 2848 /* First buffer pointer requires a page offset to start at */
2855 va = (vaddr_t)KERNADDR(dma, curoffs); 2849 va = (vaddr_t)KERNADDR(dma, curoffs);
2856 cur->qtd.qtd_buffer[0] |= htole32(EHCI_PAGE_OFFSET(va)); 2850 cur->qtd.qtd_buffer[0] |= htole32(EHCI_PAGE_OFFSET(va));
2857 2851
2858 cur->nextqtd = next; 2852 cur->nextqtd = next;
2859 cur->qtd.qtd_next = cur->qtd.qtd_altnext = nextphys; 2853 cur->qtd.qtd_next = cur->qtd.qtd_altnext = nextphys;
2860 cur->qtd.qtd_status = 2854 cur->qtd.qtd_status =
2861 htole32(qtdstatus | EHCI_QTD_SET_BYTES(curlen)); 2855 htole32(qtdstatus | EHCI_QTD_SET_BYTES(curlen));
2862 cur->xfer = xfer; 2856 cur->xfer = xfer;
2863 cur->len = curlen; 2857 cur->len = curlen;
2864 2858
2865 USBHIST_LOG(ehcidebug, "cbp=0x%08zx end=0x%08zx", 2859 USBHIST_LOG(ehcidebug, "cbp=0x%08zx end=0x%08zx",
2866 (size_t)curoffs, (size_t)(curoffs + curlen), 0, 0); 2860 (size_t)curoffs, (size_t)(curoffs + curlen), 0, 0);
2867 2861
2868 /* 2862 /*
2869 * adjust the toggle based on the number of packets in this 2863 * adjust the toggle based on the number of packets in this
2870 * qtd 2864 * qtd
2871 */ 2865 */
2872 if (((curlen + mps - 1) / mps) & 1) { 2866 if (((curlen + mps - 1) / mps) & 1) {
2873 tog ^= 1; 2867 tog ^= 1;
2874 qtdstatus ^= EHCI_QTD_TOGGLE_MASK; 2868 qtdstatus ^= EHCI_QTD_TOGGLE_MASK;
2875 } 2869 }
2876 if (next == NULL) 2870 if (next == NULL)
2877 break; 2871 break;
2878 usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd), 2872 usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd),
2879 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 2873 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
2880 USBHIST_LOG(ehcidebug, "extend chain", 0, 0, 0, 0); 2874 USBHIST_LOG(ehcidebug, "extend chain", 0, 0, 0, 0);
2881 if (len) 2875 if (len)
2882 curoffs += curlen; 2876 curoffs += curlen;
2883 cur = next; 2877 cur = next;
2884 } 2878 }
2885 cur->qtd.qtd_status |= htole32(EHCI_QTD_IOC); 2879 cur->qtd.qtd_status |= htole32(EHCI_QTD_IOC);
2886 usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd), 2880 usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd),
2887 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 2881 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
2888 *ep = cur; 2882 *ep = cur;
2889 epipe->nexttoggle = tog; 2883 epipe->nexttoggle = tog;
2890 2884
2891 USBHIST_LOG(ehcidebug, "return sqtd=%p sqtdend=%p", 2885 USBHIST_LOG(ehcidebug, "return sqtd=%p sqtdend=%p",
2892 *sp, *ep, 0, 0); 2886 *sp, *ep, 0, 0);
2893 2887
2894 return USBD_NORMAL_COMPLETION; 2888 return USBD_NORMAL_COMPLETION;
2895 2889
2896 nomem: 2890 nomem:
2897 /* XXX free chain */ 2891 /* XXX free chain */
2898 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); 2892 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0);
2899 return USBD_NOMEM; 2893 return USBD_NOMEM;
2900} 2894}
2901 2895
2902Static void 2896Static void
2903ehci_free_sqtd_chain(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd, 2897ehci_free_sqtd_chain(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd,
2904 ehci_soft_qtd_t *sqtdend) 2898 ehci_soft_qtd_t *sqtdend)
2905{ 2899{
2906 ehci_soft_qtd_t *p; 2900 ehci_soft_qtd_t *p;
2907 int i; 2901 int i;
2908 2902
2909 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2903 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2910 2904
2911 USBHIST_LOG(ehcidebug, "sqtd=%p sqtdend=%p", 2905 USBHIST_LOG(ehcidebug, "sqtd=%p sqtdend=%p",
2912 sqtd, sqtdend, 0, 0); 2906 sqtd, sqtdend, 0, 0);
2913 2907
2914 for (i = 0; sqtd != sqtdend; sqtd = p, i++) { 2908 for (i = 0; sqtd != sqtdend; sqtd = p, i++) {
2915 p = sqtd->nextqtd; 2909 p = sqtd->nextqtd;
2916 ehci_free_sqtd(sc, sqtd); 2910 ehci_free_sqtd(sc, sqtd);
2917 } 2911 }
2918} 2912}
2919 2913
2920Static ehci_soft_itd_t * 2914Static ehci_soft_itd_t *
2921ehci_alloc_itd(ehci_softc_t *sc) 2915ehci_alloc_itd(ehci_softc_t *sc)
2922{ 2916{
2923 struct ehci_soft_itd *itd, *freeitd; 2917 struct ehci_soft_itd *itd, *freeitd;
2924 usbd_status err; 2918 usbd_status err;
2925 int i, offs, frindex, previndex; 2919 int i, offs, frindex, previndex;
2926 usb_dma_t dma; 2920 usb_dma_t dma;
2927 2921
2928 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2922 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2929 2923
2930 mutex_enter(&sc->sc_lock); 2924 mutex_enter(&sc->sc_lock);
2931 2925
2932 /* 2926 /*
2933 * Find an itd that wasn't freed this frame or last frame. This can 2927 * Find an itd that wasn't freed this frame or last frame. This can
2934 * discard itds that were freed before frindex wrapped around 2928 * discard itds that were freed before frindex wrapped around
2935 * XXX - can this lead to thrashing? Could fix by enabling wrap-around 2929 * XXX - can this lead to thrashing? Could fix by enabling wrap-around
2936 * interrupt and fiddling with list when that happens 2930 * interrupt and fiddling with list when that happens
2937 */ 2931 */
2938 frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3; 2932 frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3;
2939 previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize; 2933 previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize;
2940 2934
2941 freeitd = NULL; 2935 freeitd = NULL;
2942 LIST_FOREACH(itd, &sc->sc_freeitds, u.free_list) { 2936 LIST_FOREACH(itd, &sc->sc_freeitds, u.free_list) {
2943 if (itd == NULL) 2937 if (itd == NULL)
2944 break; 2938 break;
2945 if (itd->slot != frindex && itd->slot != previndex) { 2939 if (itd->slot != frindex && itd->slot != previndex) {
2946 freeitd = itd; 2940 freeitd = itd;
2947 break; 2941 break;
2948 } 2942 }
2949 } 2943 }
2950 2944
2951 if (freeitd == NULL) { 2945 if (freeitd == NULL) {
2952 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); 2946 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0);
2953 err = usb_allocmem(&sc->sc_bus, EHCI_ITD_SIZE * EHCI_ITD_CHUNK, 2947 err = usb_allocmem(&sc->sc_bus, EHCI_ITD_SIZE * EHCI_ITD_CHUNK,
2954 EHCI_PAGE_SIZE, &dma); 2948 EHCI_PAGE_SIZE, &dma);
2955 2949
2956 if (err) { 2950 if (err) {
2957 USBHIST_LOG(ehcidebug, 2951 USBHIST_LOG(ehcidebug,
2958 "alloc returned %d", err, 0, 0, 0); 2952 "alloc returned %d", err, 0, 0, 0);
2959 mutex_exit(&sc->sc_lock); 2953 mutex_exit(&sc->sc_lock);
2960 return NULL; 2954 return NULL;
2961 } 2955 }
2962 2956
2963 for (i = 0; i < EHCI_ITD_CHUNK; i++) { 2957 for (i = 0; i < EHCI_ITD_CHUNK; i++) {
2964 offs = i * EHCI_ITD_SIZE; 2958 offs = i * EHCI_ITD_SIZE;
2965 itd = KERNADDR(&dma, offs); 2959 itd = KERNADDR(&dma, offs);
2966 itd->physaddr = DMAADDR(&dma, offs); 2960 itd->physaddr = DMAADDR(&dma, offs);
2967 itd->dma = dma; 2961 itd->dma = dma;
2968 itd->offs = offs; 2962 itd->offs = offs;
2969 LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list); 2963 LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list);
2970 } 2964 }
2971 freeitd = LIST_FIRST(&sc->sc_freeitds); 2965 freeitd = LIST_FIRST(&sc->sc_freeitds);
2972 } 2966 }
2973 2967
2974 itd = freeitd; 2968 itd = freeitd;
2975 LIST_REMOVE(itd, u.free_list); 2969 LIST_REMOVE(itd, u.free_list);
2976 memset(&itd->itd, 0, sizeof(ehci_itd_t)); 2970 memset(&itd->itd, 0, sizeof(ehci_itd_t));
2977 usb_syncmem(&itd->dma, itd->offs + offsetof(ehci_itd_t, itd_next), 2971 usb_syncmem(&itd->dma, itd->offs + offsetof(ehci_itd_t, itd_next),
2978 sizeof(itd->itd.itd_next), 2972 sizeof(itd->itd.itd_next),
2979 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 2973 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
2980 2974
2981 itd->u.frame_list.next = NULL; 2975 itd->u.frame_list.next = NULL;
2982 itd->u.frame_list.prev = NULL; 2976 itd->u.frame_list.prev = NULL;
2983 itd->xfer_next = NULL; 2977 itd->xfer_next = NULL;
2984 itd->slot = 0; 2978 itd->slot = 0;
2985 2979
2986 mutex_exit(&sc->sc_lock); 2980 mutex_exit(&sc->sc_lock);
2987 2981
2988 return itd; 2982 return itd;
2989} 2983}
2990 2984
2991Static ehci_soft_sitd_t * 2985Static ehci_soft_sitd_t *
2992ehci_alloc_sitd(ehci_softc_t *sc) 2986ehci_alloc_sitd(ehci_softc_t *sc)
2993{ 2987{
2994 struct ehci_soft_sitd *sitd, *freesitd; 2988 struct ehci_soft_sitd *sitd, *freesitd;
2995 usbd_status err; 2989 usbd_status err;
2996 int i, offs, frindex, previndex; 2990 int i, offs, frindex, previndex;
2997 usb_dma_t dma; 2991 usb_dma_t dma;
2998 2992
2999 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2993 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3000 2994
3001 mutex_enter(&sc->sc_lock); 2995 mutex_enter(&sc->sc_lock);
3002 2996
3003 /* 2997 /*
3004 * Find an sitd that wasn't freed this frame or last frame. This can 2998 * Find an sitd that wasn't freed this frame or last frame. This can
3005 * discard sitds that were freed before frindex wrapped around 2999 * discard sitds that were freed before frindex wrapped around
3006 * XXX - can this lead to thrashing? Could fix by enabling wrap-around 3000 * XXX - can this lead to thrashing? Could fix by enabling wrap-around
3007 * interrupt and fiddling with list when that happens 3001 * interrupt and fiddling with list when that happens
3008 */ 3002 */
3009 frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3; 3003 frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3;
3010 previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize; 3004 previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize;
3011 3005
3012 freesitd = NULL; 3006 freesitd = NULL;
3013 LIST_FOREACH(sitd, &sc->sc_freesitds, u.free_list) { 3007 LIST_FOREACH(sitd, &sc->sc_freesitds, u.free_list) {
3014 if (sitd == NULL) 3008 if (sitd == NULL)
3015 break; 3009 break;
3016 if (sitd->slot != frindex && sitd->slot != previndex) { 3010 if (sitd->slot != frindex && sitd->slot != previndex) {
3017 freesitd = sitd; 3011 freesitd = sitd;
3018 break; 3012 break;
3019 } 3013 }
3020 } 3014 }
3021 3015
3022 if (freesitd == NULL) { 3016 if (freesitd == NULL) {
3023 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); 3017 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0);
3024 err = usb_allocmem(&sc->sc_bus, EHCI_SITD_SIZE * EHCI_SITD_CHUNK, 3018 err = usb_allocmem(&sc->sc_bus, EHCI_SITD_SIZE * EHCI_SITD_CHUNK,
3025 EHCI_PAGE_SIZE, &dma); 3019 EHCI_PAGE_SIZE, &dma);
3026 3020
3027 if (err) { 3021 if (err) {
3028 USBHIST_LOG(ehcidebug, 3022 USBHIST_LOG(ehcidebug,
3029 "alloc returned %d", err, 0, 0, 0); 3023 "alloc returned %d", err, 0, 0, 0);
3030 mutex_exit(&sc->sc_lock); 3024 mutex_exit(&sc->sc_lock);
3031 return NULL; 3025 return NULL;
3032 } 3026 }
3033 3027
3034 for (i = 0; i < EHCI_SITD_CHUNK; i++) { 3028 for (i = 0; i < EHCI_SITD_CHUNK; i++) {
3035 offs = i * EHCI_SITD_SIZE; 3029 offs = i * EHCI_SITD_SIZE;
3036 sitd = KERNADDR(&dma, offs); 3030 sitd = KERNADDR(&dma, offs);
3037 sitd->physaddr = DMAADDR(&dma, offs); 3031 sitd->physaddr = DMAADDR(&dma, offs);
3038 sitd->dma = dma; 3032 sitd->dma = dma;
3039 sitd->offs = offs; 3033 sitd->offs = offs;
3040 LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list); 3034 LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list);
3041 } 3035 }
3042 freesitd = LIST_FIRST(&sc->sc_freesitds); 3036 freesitd = LIST_FIRST(&sc->sc_freesitds);
3043 } 3037 }
3044 3038
3045 sitd = freesitd; 3039 sitd = freesitd;
3046 LIST_REMOVE(sitd, u.free_list); 3040 LIST_REMOVE(sitd, u.free_list);
3047 memset(&sitd->sitd, 0, sizeof(ehci_sitd_t)); 3041 memset(&sitd->sitd, 0, sizeof(ehci_sitd_t));
3048 usb_syncmem(&sitd->dma, sitd->offs + offsetof(ehci_sitd_t, sitd_next), 3042 usb_syncmem(&sitd->dma, sitd->offs + offsetof(ehci_sitd_t, sitd_next),
3049 sizeof(sitd->sitd.sitd_next), BUS_DMASYNC_PREWRITE | 3043 sizeof(sitd->sitd.sitd_next), BUS_DMASYNC_PREWRITE |
3050 BUS_DMASYNC_PREREAD); 3044 BUS_DMASYNC_PREREAD);
3051 3045
3052 sitd->u.frame_list.next = NULL; 3046 sitd->u.frame_list.next = NULL;
3053 sitd->u.frame_list.prev = NULL; 3047 sitd->u.frame_list.prev = NULL;
3054 sitd->xfer_next = NULL; 3048 sitd->xfer_next = NULL;
3055 sitd->slot = 0; 3049 sitd->slot = 0;
3056 3050
3057 mutex_exit(&sc->sc_lock); 3051 mutex_exit(&sc->sc_lock);
3058 3052
3059 return sitd; 3053 return sitd;
3060} 3054}
3061 3055
3062Static void 3056Static void
3063ehci_free_itd(ehci_softc_t *sc, ehci_soft_itd_t *itd) 3057ehci_free_itd(ehci_softc_t *sc, ehci_soft_itd_t *itd)
3064{ 3058{
3065 3059
3066 KASSERT(mutex_owned(&sc->sc_lock)); 3060 KASSERT(mutex_owned(&sc->sc_lock));
3067 3061
3068 LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list); 3062 LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list);
3069} 3063}
3070 3064
3071Static void 3065Static void
3072ehci_free_sitd(ehci_softc_t *sc, ehci_soft_sitd_t *sitd) 3066ehci_free_sitd(ehci_softc_t *sc, ehci_soft_sitd_t *sitd)
3073{ 3067{
3074 3068
3075 KASSERT(mutex_owned(&sc->sc_lock)); 3069 KASSERT(mutex_owned(&sc->sc_lock));
3076 3070
3077 LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list); 3071 LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list);
3078} 3072}
3079 3073
3080/****************/ 3074/****************/
3081 3075
3082/* 3076/*
3083 * Close a reqular pipe. 3077 * Close a reqular pipe.
3084 * Assumes that there are no pending transactions. 3078 * Assumes that there are no pending transactions.
3085 */ 3079 */
3086Static void 3080Static void
3087ehci_close_pipe(usbd_pipe_handle pipe, ehci_soft_qh_t *head) 3081ehci_close_pipe(usbd_pipe_handle pipe, ehci_soft_qh_t *head)
3088{ 3082{
3089 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; 3083 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;
3090 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; 3084 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
3091 ehci_soft_qh_t *sqh = epipe->sqh; 3085 ehci_soft_qh_t *sqh = epipe->sqh;
3092 3086
3093 KASSERT(mutex_owned(&sc->sc_lock)); 3087 KASSERT(mutex_owned(&sc->sc_lock));
3094 3088
3095 ehci_rem_qh(sc, sqh, head); 3089 ehci_rem_qh(sc, sqh, head);
3096 ehci_free_sqh(sc, epipe->sqh); 3090 ehci_free_sqh(sc, epipe->sqh);
3097} 3091}
3098 3092
3099/* 3093/*
3100 * Abort a device request. 3094 * Abort a device request.
3101 * If this routine is called at splusb() it guarantees that the request 3095 * If this routine is called at splusb() it guarantees that the request
3102 * will be removed from the hardware scheduling and that the callback 3096 * will be removed from the hardware scheduling and that the callback
3103 * for it will be called with USBD_CANCELLED status. 3097 * for it will be called with USBD_CANCELLED status.
3104 * It's impossible to guarantee that the requested transfer will not 3098 * It's impossible to guarantee that the requested transfer will not
3105 * have happened since the hardware runs concurrently. 3099 * have happened since the hardware runs concurrently.
3106 * If the transaction has already happened we rely on the ordinary 3100 * If the transaction has already happened we rely on the ordinary
3107 * interrupt processing to process it. 3101 * interrupt processing to process it.
3108 * XXX This is most probably wrong. 3102 * XXX This is most probably wrong.
3109 * XXXMRG this doesn't make sense anymore. 3103 * XXXMRG this doesn't make sense anymore.
3110 */ 3104 */
3111Static void 3105Static void
3112ehci_abort_xfer(usbd_xfer_handle xfer, usbd_status status) 3106ehci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
3113{ 3107{
3114#define exfer EXFER(xfer) 3108#define exfer EXFER(xfer)
3115 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; 3109 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe;
3116 ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; 3110 ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv;
3117 ehci_soft_qh_t *sqh = epipe->sqh; 3111 ehci_soft_qh_t *sqh = epipe->sqh;
3118 ehci_soft_qtd_t *sqtd; 3112 ehci_soft_qtd_t *sqtd;
3119 ehci_physaddr_t cur; 3113 ehci_physaddr_t cur;
3120 uint32_t qhstatus; 3114 uint32_t qhstatus;
3121 int hit; 3115 int hit;
3122 int wake; 3116 int wake;
3123 3117
3124 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3118 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3125 3119
3126 USBHIST_LOG(ehcidebug, "xfer=%p pipe=%p", xfer, epipe, 0, 0); 3120 USBHIST_LOG(ehcidebug, "xfer=%p pipe=%p", xfer, epipe, 0, 0);
3127 3121
3128 KASSERT(mutex_owned(&sc->sc_lock)); 3122 KASSERT(mutex_owned(&sc->sc_lock));
3129 ASSERT_SLEEPABLE(); 3123 ASSERT_SLEEPABLE();
3130 3124
3131 if (sc->sc_dying) { 3125 if (sc->sc_dying) {
3132 /* If we're dying, just do the software part. */ 3126 /* If we're dying, just do the software part. */
3133 xfer->ux_status = status; /* make software ignore it */ 3127 xfer->ux_status = status; /* make software ignore it */
3134 callout_stop(&xfer->ux_callout); 3128 callout_stop(&xfer->ux_callout);
3135 usb_transfer_complete(xfer); 3129 usb_transfer_complete(xfer);
3136 return; 3130 return;
3137 } 3131 }
3138 3132
3139 /* 3133 /*
3140 * If an abort is already in progress then just wait for it to 3134 * If an abort is already in progress then just wait for it to
3141 * complete and return. 3135 * complete and return.
3142 */ 3136 */
3143 if (xfer->ux_hcflags & UXFER_ABORTING) { 3137 if (xfer->ux_hcflags & UXFER_ABORTING) {
3144 USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0); 3138 USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0);
3145#ifdef DIAGNOSTIC 3139#ifdef DIAGNOSTIC
3146 if (status == USBD_TIMEOUT) 3140 if (status == USBD_TIMEOUT)
3147 printf("ehci_abort_xfer: TIMEOUT while aborting\n"); 3141 printf("ehci_abort_xfer: TIMEOUT while aborting\n");
3148#endif 3142#endif
3149 /* Override the status which might be USBD_TIMEOUT. */ 3143 /* Override the status which might be USBD_TIMEOUT. */
3150 xfer->ux_status = status; 3144 xfer->ux_status = status;
3151 USBHIST_LOG(ehcidebug, "waiting for abort to finish", 3145 USBHIST_LOG(ehcidebug, "waiting for abort to finish",
3152 0, 0, 0, 0); 3146 0, 0, 0, 0);
3153 xfer->ux_hcflags |= UXFER_ABORTWAIT; 3147 xfer->ux_hcflags |= UXFER_ABORTWAIT;
3154 while (xfer->ux_hcflags & UXFER_ABORTING) 3148 while (xfer->ux_hcflags & UXFER_ABORTING)
3155 cv_wait(&xfer->ux_hccv, &sc->sc_lock); 3149 cv_wait(&xfer->ux_hccv, &sc->sc_lock);
3156 return; 3150 return;
3157 } 3151 }
3158 xfer->ux_hcflags |= UXFER_ABORTING; 3152 xfer->ux_hcflags |= UXFER_ABORTING;
3159 3153
3160 /* 3154 /*
3161 * Step 1: Make interrupt routine and hardware ignore xfer. 3155 * Step 1: Make interrupt routine and hardware ignore xfer.
3162 */ 3156 */
3163 xfer->ux_status = status; /* make software ignore it */ 3157 xfer->ux_status = status; /* make software ignore it */
3164 callout_stop(&xfer->ux_callout); 3158 callout_stop(&xfer->ux_callout);
3165 3159
3166 usb_syncmem(&sqh->dma, 3160 usb_syncmem(&sqh->dma,
3167 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), 3161 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status),
3168 sizeof(sqh->qh.qh_qtd.qtd_status), 3162 sizeof(sqh->qh.qh_qtd.qtd_status),
3169 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 3163 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
3170 qhstatus = sqh->qh.qh_qtd.qtd_status; 3164 qhstatus = sqh->qh.qh_qtd.qtd_status;
3171 sqh->qh.qh_qtd.qtd_status = qhstatus | htole32(EHCI_QTD_HALTED); 3165 sqh->qh.qh_qtd.qtd_status = qhstatus | htole32(EHCI_QTD_HALTED);
3172 usb_syncmem(&sqh->dma, 3166 usb_syncmem(&sqh->dma,
3173 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), 3167 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status),
3174 sizeof(sqh->qh.qh_qtd.qtd_status), 3168 sizeof(sqh->qh.qh_qtd.qtd_status),
3175 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3169 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3176 for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) { 3170 for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) {
3177 usb_syncmem(&sqtd->dma, 3171 usb_syncmem(&sqtd->dma,
3178 sqtd->offs + offsetof(ehci_qtd_t, qtd_status), 3172 sqtd->offs + offsetof(ehci_qtd_t, qtd_status),
3179 sizeof(sqtd->qtd.qtd_status), 3173 sizeof(sqtd->qtd.qtd_status),
3180 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 3174 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
3181 sqtd->qtd.qtd_status |= htole32(EHCI_QTD_HALTED); 3175 sqtd->qtd.qtd_status |= htole32(EHCI_QTD_HALTED);
3182 usb_syncmem(&sqtd->dma, 3176 usb_syncmem(&sqtd->dma,
3183 sqtd->offs + offsetof(ehci_qtd_t, qtd_status), 3177 sqtd->offs + offsetof(ehci_qtd_t, qtd_status),
3184 sizeof(sqtd->qtd.qtd_status), 3178 sizeof(sqtd->qtd.qtd_status),
3185 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3179 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3186 if (sqtd == exfer->ex_sqtdend) 3180 if (sqtd == exfer->ex_sqtdend)
3187 break; 3181 break;
3188 } 3182 }
3189 3183
3190 /* 3184 /*
3191 * Step 2: Wait until we know hardware has finished any possible 3185 * Step 2: Wait until we know hardware has finished any possible
3192 * use of the xfer. Also make sure the soft interrupt routine 3186 * use of the xfer. Also make sure the soft interrupt routine
3193 * has run. 3187 * has run.
3194 */ 3188 */
3195 ehci_sync_hc(sc); 3189 ehci_sync_hc(sc);
3196 sc->sc_softwake = 1; 3190 sc->sc_softwake = 1;
3197 usb_schedsoftintr(&sc->sc_bus); 3191 usb_schedsoftintr(&sc->sc_bus);
3198 cv_wait(&sc->sc_softwake_cv, &sc->sc_lock); 3192 cv_wait(&sc->sc_softwake_cv, &sc->sc_lock);
3199 3193
3200 /* 3194 /*
3201 * Step 3: Remove any vestiges of the xfer from the hardware. 3195 * Step 3: Remove any vestiges of the xfer from the hardware.
3202 * The complication here is that the hardware may have executed 3196 * The complication here is that the hardware may have executed
3203 * beyond the xfer we're trying to abort. So as we're scanning 3197 * beyond the xfer we're trying to abort. So as we're scanning
3204 * the TDs of this xfer we check if the hardware points to 3198 * the TDs of this xfer we check if the hardware points to
3205 * any of them. 3199 * any of them.
3206 */ 3200 */
3207 3201
3208 usb_syncmem(&sqh->dma, 3202 usb_syncmem(&sqh->dma,
3209 sqh->offs + offsetof(ehci_qh_t, qh_curqtd), 3203 sqh->offs + offsetof(ehci_qh_t, qh_curqtd),
3210 sizeof(sqh->qh.qh_curqtd), 3204 sizeof(sqh->qh.qh_curqtd),
3211 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 3205 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
3212 cur = EHCI_LINK_ADDR(le32toh(sqh->qh.qh_curqtd)); 3206 cur = EHCI_LINK_ADDR(le32toh(sqh->qh.qh_curqtd));
3213 hit = 0; 3207 hit = 0;
3214 for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) { 3208 for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) {
3215 hit |= cur == sqtd->physaddr; 3209 hit |= cur == sqtd->physaddr;
3216 if (sqtd == exfer->ex_sqtdend) 3210 if (sqtd == exfer->ex_sqtdend)
3217 break; 3211 break;
3218 } 3212 }
3219 sqtd = sqtd->nextqtd; 3213 sqtd = sqtd->nextqtd;
3220 /* Zap curqtd register if hardware pointed inside the xfer. */ 3214 /* Zap curqtd register if hardware pointed inside the xfer. */
3221 if (hit && sqtd != NULL) { 3215 if (hit && sqtd != NULL) {
3222 USBHIST_LOG(ehcidebug, "cur=0x%08x", sqtd->physaddr, 0, 0, 0); 3216 USBHIST_LOG(ehcidebug, "cur=0x%08x", sqtd->physaddr, 0, 0, 0);
3223 sqh->qh.qh_curqtd = htole32(sqtd->physaddr); /* unlink qTDs */ 3217 sqh->qh.qh_curqtd = htole32(sqtd->physaddr); /* unlink qTDs */
3224 usb_syncmem(&sqh->dma, 3218 usb_syncmem(&sqh->dma,
3225 sqh->offs + offsetof(ehci_qh_t, qh_curqtd), 3219 sqh->offs + offsetof(ehci_qh_t, qh_curqtd),
3226 sizeof(sqh->qh.qh_curqtd), 3220 sizeof(sqh->qh.qh_curqtd),
3227 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3221 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3228 sqh->qh.qh_qtd.qtd_status = qhstatus; 3222 sqh->qh.qh_qtd.qtd_status = qhstatus;
3229 usb_syncmem(&sqh->dma, 3223 usb_syncmem(&sqh->dma,
3230 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), 3224 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status),
3231 sizeof(sqh->qh.qh_qtd.qtd_status), 3225 sizeof(sqh->qh.qh_qtd.qtd_status),
3232 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3226 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3233 } else { 3227 } else {
3234 USBHIST_LOG(ehcidebug, "no hit", 0, 0, 0, 0); 3228 USBHIST_LOG(ehcidebug, "no hit", 0, 0, 0, 0);
3235 } 3229 }
3236 3230
3237 /* 3231 /*
3238 * Step 4: Execute callback. 3232 * Step 4: Execute callback.
3239 */ 3233 */
3240#ifdef DIAGNOSTIC 3234#ifdef DIAGNOSTIC
3241 exfer->ex_isdone = 1; 3235 exfer->ex_isdone = true;
3242#endif 3236#endif
3243 wake = xfer->ux_hcflags & UXFER_ABORTWAIT; 3237 wake = xfer->ux_hcflags & UXFER_ABORTWAIT;
3244 xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT); 3238 xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT);
3245 usb_transfer_complete(xfer); 3239 usb_transfer_complete(xfer);
3246 if (wake) { 3240 if (wake) {
3247 cv_broadcast(&xfer->ux_hccv); 3241 cv_broadcast(&xfer->ux_hccv);
3248 } 3242 }
3249 3243
3250 KASSERT(mutex_owned(&sc->sc_lock)); 3244 KASSERT(mutex_owned(&sc->sc_lock));
3251#undef exfer 3245#undef exfer
3252} 3246}
3253 3247
3254Static void 3248Static void
3255ehci_abort_isoc_xfer(usbd_xfer_handle xfer, usbd_status status) 3249ehci_abort_isoc_xfer(usbd_xfer_handle xfer, usbd_status status)
3256{ 3250{
3257 ehci_isoc_trans_t trans_status; 3251 ehci_isoc_trans_t trans_status;
3258 struct ehci_pipe *epipe; 3252 struct ehci_pipe *epipe;
3259 struct ehci_xfer *exfer; 3253 struct ehci_xfer *exfer;
3260 ehci_softc_t *sc; 3254 ehci_softc_t *sc;
3261 struct ehci_soft_itd *itd; 3255 struct ehci_soft_itd *itd;
3262 struct ehci_soft_sitd *sitd; 3256 struct ehci_soft_sitd *sitd;
3263 int i, wake; 3257 int i, wake;
3264 3258
3265 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3259 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3266 3260
3267 epipe = (struct ehci_pipe *) xfer->ux_pipe; 3261 epipe = (struct ehci_pipe *) xfer->ux_pipe;
3268 exfer = EXFER(xfer); 3262 exfer = EXFER(xfer);
3269 sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; 3263 sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv;
3270 3264
3271 USBHIST_LOG(ehcidebug, "xfer %p pipe %p", xfer, epipe, 0, 0); 3265 USBHIST_LOG(ehcidebug, "xfer %p pipe %p", xfer, epipe, 0, 0);
3272 3266
3273 KASSERT(mutex_owned(&sc->sc_lock)); 3267 KASSERT(mutex_owned(&sc->sc_lock));
3274 3268
3275 if (sc->sc_dying) { 3269 if (sc->sc_dying) {
3276 xfer->ux_status = status; 3270 xfer->ux_status = status;
3277 callout_stop(&xfer->ux_callout); 3271 callout_stop(&xfer->ux_callout);
3278 usb_transfer_complete(xfer); 3272 usb_transfer_complete(xfer);
3279 return; 3273 return;
3280 } 3274 }
3281 3275
3282 if (xfer->ux_hcflags & UXFER_ABORTING) { 3276 if (xfer->ux_hcflags & UXFER_ABORTING) {
3283 USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0); 3277 USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0);
3284 3278
3285#ifdef DIAGNOSTIC 3279#ifdef DIAGNOSTIC
3286 if (status == USBD_TIMEOUT) 3280 if (status == USBD_TIMEOUT)
3287 printf("ehci_abort_isoc_xfer: TIMEOUT while aborting\n"); 3281 printf("ehci_abort_isoc_xfer: TIMEOUT while aborting\n");
3288#endif 3282#endif
3289 3283
3290 xfer->ux_status = status; 3284 xfer->ux_status = status;
3291 USBHIST_LOG(ehcidebug, 3285 USBHIST_LOG(ehcidebug,
3292 "waiting for abort to finish", 0, 0, 0, 0); 3286 "waiting for abort to finish", 0, 0, 0, 0);
3293 xfer->ux_hcflags |= UXFER_ABORTWAIT; 3287 xfer->ux_hcflags |= UXFER_ABORTWAIT;
3294 while (xfer->ux_hcflags & UXFER_ABORTING) 3288 while (xfer->ux_hcflags & UXFER_ABORTING)
3295 cv_wait(&xfer->ux_hccv, &sc->sc_lock); 3289 cv_wait(&xfer->ux_hccv, &sc->sc_lock);
3296 goto done; 3290 goto done;
3297 } 3291 }
3298 xfer->ux_hcflags |= UXFER_ABORTING; 3292 xfer->ux_hcflags |= UXFER_ABORTING;
3299 3293
3300 xfer->ux_status = status; 3294 xfer->ux_status = status;
3301 callout_stop(&xfer->ux_callout); 3295 callout_stop(&xfer->ux_callout);
3302 3296
3303 if (xfer->ux_pipe->up_dev->ud_speed == USB_SPEED_HIGH) { 3297 if (xfer->ux_pipe->up_dev->ud_speed == USB_SPEED_HIGH) {
3304 for (itd = exfer->ex_itdstart; itd != NULL; 3298 for (itd = exfer->ex_itdstart; itd != NULL;
3305 itd = itd->xfer_next) { 3299 itd = itd->xfer_next) {
3306 usb_syncmem(&itd->dma, 3300 usb_syncmem(&itd->dma,
3307 itd->offs + offsetof(ehci_itd_t, itd_ctl), 3301 itd->offs + offsetof(ehci_itd_t, itd_ctl),
3308 sizeof(itd->itd.itd_ctl), 3302 sizeof(itd->itd.itd_ctl),
3309 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 3303 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
3310 3304
3311 for (i = 0; i < 8; i++) { 3305 for (i = 0; i < 8; i++) {
3312 trans_status = le32toh(itd->itd.itd_ctl[i]); 3306 trans_status = le32toh(itd->itd.itd_ctl[i]);
3313 trans_status &= ~EHCI_ITD_ACTIVE; 3307 trans_status &= ~EHCI_ITD_ACTIVE;
3314 itd->itd.itd_ctl[i] = htole32(trans_status); 3308 itd->itd.itd_ctl[i] = htole32(trans_status);
3315 } 3309 }
3316 3310
3317 usb_syncmem(&itd->dma, 3311 usb_syncmem(&itd->dma,
3318 itd->offs + offsetof(ehci_itd_t, itd_ctl), 3312 itd->offs + offsetof(ehci_itd_t, itd_ctl),
3319 sizeof(itd->itd.itd_ctl), 3313 sizeof(itd->itd.itd_ctl),
3320 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3314 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3321 } 3315 }
3322 } else { 3316 } else {
3323 for (sitd = exfer->ex_sitdstart; sitd != NULL; 3317 for (sitd = exfer->ex_sitdstart; sitd != NULL;
3324 sitd = sitd->xfer_next) { 3318 sitd = sitd->xfer_next) {
3325 usb_syncmem(&sitd->dma, 3319 usb_syncmem(&sitd->dma,
3326 sitd->offs + offsetof(ehci_sitd_t, sitd_buffer), 3320 sitd->offs + offsetof(ehci_sitd_t, sitd_buffer),
3327 sizeof(sitd->sitd.sitd_buffer), 3321 sizeof(sitd->sitd.sitd_buffer),
3328 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 3322 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
3329 3323
3330 trans_status = le32toh(sitd->sitd.sitd_trans); 3324 trans_status = le32toh(sitd->sitd.sitd_trans);
3331 trans_status &= ~EHCI_SITD_ACTIVE; 3325 trans_status &= ~EHCI_SITD_ACTIVE;
3332 sitd->sitd.sitd_trans = htole32(trans_status); 3326 sitd->sitd.sitd_trans = htole32(trans_status);
3333 3327
3334 usb_syncmem(&sitd->dma, 3328 usb_syncmem(&sitd->dma,
3335 sitd->offs + offsetof(ehci_sitd_t, sitd_buffer), 3329 sitd->offs + offsetof(ehci_sitd_t, sitd_buffer),
3336 sizeof(sitd->sitd.sitd_buffer), 3330 sizeof(sitd->sitd.sitd_buffer),
3337 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3331 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3338 } 3332 }
3339 } 3333 }
3340 3334
3341 sc->sc_softwake = 1; 3335 sc->sc_softwake = 1;
3342 usb_schedsoftintr(&sc->sc_bus); 3336 usb_schedsoftintr(&sc->sc_bus);
3343 cv_wait(&sc->sc_softwake_cv, &sc->sc_lock); 3337 cv_wait(&sc->sc_softwake_cv, &sc->sc_lock);
3344 3338
3345#ifdef DIAGNOSTIC 3339#ifdef DIAGNOSTIC
3346 exfer->ex_isdone = 1; 3340 exfer->ex_isdone = true;
3347#endif 3341#endif
3348 wake = xfer->ux_hcflags & UXFER_ABORTWAIT; 3342 wake = xfer->ux_hcflags & UXFER_ABORTWAIT;
3349 xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT); 3343 xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT);
3350 usb_transfer_complete(xfer); 3344 usb_transfer_complete(xfer);
3351 if (wake) { 3345 if (wake) {
3352 cv_broadcast(&xfer->ux_hccv); 3346 cv_broadcast(&xfer->ux_hccv);
3353 } 3347 }
3354 3348
3355done: 3349done:
3356 KASSERT(mutex_owned(&sc->sc_lock)); 3350 KASSERT(mutex_owned(&sc->sc_lock));
3357 return; 3351 return;
3358} 3352}
3359 3353
3360Static void 3354Static void
3361ehci_timeout(void *addr) 3355ehci_timeout(void *addr)
3362{ 3356{
3363 struct ehci_xfer *exfer = addr; 3357 struct ehci_xfer *exfer = addr;
3364 struct ehci_pipe *epipe = (struct ehci_pipe *)exfer->ex_xfer.ux_pipe; 3358 struct ehci_pipe *epipe = (struct ehci_pipe *)exfer->ex_xfer.ux_pipe;
3365 ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; 3359 ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv;
3366 3360
3367 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3361 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3368 3362
3369 USBHIST_LOG(ehcidebug, "exfer %p", exfer, 0, 0, 0); 3363 USBHIST_LOG(ehcidebug, "exfer %p", exfer, 0, 0, 0);
3370#ifdef EHCI_DEBUG 3364#ifdef EHCI_DEBUG
3371 if (ehcidebug > 1) 3365 if (ehcidebug > 1)
3372 usbd_dump_pipe(exfer->ex_xfer.ux_pipe); 3366 usbd_dump_pipe(exfer->ex_xfer.ux_pipe);
3373#endif 3367#endif
3374 3368
3375 if (sc->sc_dying) { 3369 if (sc->sc_dying) {
3376 mutex_enter(&sc->sc_lock); 3370 mutex_enter(&sc->sc_lock);
3377 ehci_abort_xfer(&exfer->ex_xfer, USBD_TIMEOUT); 3371 ehci_abort_xfer(&exfer->ex_xfer, USBD_TIMEOUT);
3378 mutex_exit(&sc->sc_lock); 3372 mutex_exit(&sc->sc_lock);
3379 return; 3373 return;
3380 } 3374 }
3381 3375
3382 /* Execute the abort in a process context. */ 3376 /* Execute the abort in a process context. */
3383 usb_init_task(&exfer->ex_aborttask, ehci_timeout_task, addr, 3377 usb_init_task(&exfer->ex_aborttask, ehci_timeout_task, addr,
3384 USB_TASKQ_MPSAFE); 3378 USB_TASKQ_MPSAFE);
3385 usb_add_task(exfer->ex_xfer.ux_pipe->up_dev, &exfer->ex_aborttask, 3379 usb_add_task(exfer->ex_xfer.ux_pipe->up_dev, &exfer->ex_aborttask,
3386 USB_TASKQ_HC); 3380 USB_TASKQ_HC);
3387} 3381}
3388 3382
3389Static void 3383Static void
3390ehci_timeout_task(void *addr) 3384ehci_timeout_task(void *addr)
3391{ 3385{
3392 usbd_xfer_handle xfer = addr; 3386 usbd_xfer_handle xfer = addr;
3393 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3387 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
3394 3388
3395 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3389 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3396 3390
3397 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); 3391 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0);
3398 3392
3399 mutex_enter(&sc->sc_lock); 3393 mutex_enter(&sc->sc_lock);
3400 ehci_abort_xfer(xfer, USBD_TIMEOUT); 3394 ehci_abort_xfer(xfer, USBD_TIMEOUT);
3401 mutex_exit(&sc->sc_lock); 3395 mutex_exit(&sc->sc_lock);
3402} 3396}
3403 3397
3404/************************/ 3398/************************/
3405 3399
3406Static usbd_status 3400Static usbd_status
3407ehci_device_ctrl_transfer(usbd_xfer_handle xfer) 3401ehci_device_ctrl_transfer(usbd_xfer_handle xfer)
3408{ 3402{
3409 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3403 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
3410 usbd_status err; 3404 usbd_status err;
3411 3405
3412 /* Insert last in queue. */ 3406 /* Insert last in queue. */
3413 mutex_enter(&sc->sc_lock); 3407 mutex_enter(&sc->sc_lock);
3414 err = usb_insert_transfer(xfer); 3408 err = usb_insert_transfer(xfer);
3415 mutex_exit(&sc->sc_lock); 3409 mutex_exit(&sc->sc_lock);
3416 if (err) 3410 if (err)
3417 return err; 3411 return err;
3418 3412
3419 /* Pipe isn't running, start first */ 3413 /* Pipe isn't running, start first */
3420 return ehci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); 3414 return ehci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue));
3421} 3415}
3422 3416
3423Static usbd_status 3417Static usbd_status
3424ehci_device_ctrl_start(usbd_xfer_handle xfer) 3418ehci_device_ctrl_start(usbd_xfer_handle xfer)
3425{ 3419{
3426 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3420 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
3427 usbd_status err; 3421 usbd_status err;
3428 3422
3429 if (sc->sc_dying) 3423 if (sc->sc_dying)
3430 return USBD_IOERROR; 3424 return USBD_IOERROR;
3431 3425
3432 KASSERT(xfer->ux_rqflags & URQ_REQUEST); 3426 KASSERT(xfer->ux_rqflags & URQ_REQUEST);
3433 3427
3434 err = ehci_device_request(xfer); 3428 err = ehci_device_request(xfer);
3435 if (err) { 3429 if (err) {
3436 return err; 3430 return err;
3437 } 3431 }
3438 3432
3439 if (sc->sc_bus.ub_usepolling) 3433 if (sc->sc_bus.ub_usepolling)
3440 ehci_waitintr(sc, xfer); 3434 ehci_waitintr(sc, xfer);
3441 3435
3442 return USBD_IN_PROGRESS; 3436 return USBD_IN_PROGRESS;
3443} 3437}
3444 3438
3445Static void 3439Static void
3446ehci_device_ctrl_done(usbd_xfer_handle xfer) 3440ehci_device_ctrl_done(usbd_xfer_handle xfer)
3447{ 3441{
3448 struct ehci_xfer *ex = EXFER(xfer); 3442 struct ehci_xfer *ex = EXFER(xfer);
3449 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3443 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
3450 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; 3444 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe;
3451 usb_device_request_t *req = &xfer->ux_request; 3445 usb_device_request_t *req = &xfer->ux_request;
3452 int len = UGETW(req->wLength); 3446 int len = UGETW(req->wLength);
3453 int rd = req->bmRequestType & UT_READ; 3447 int rd = req->bmRequestType & UT_READ;
3454 3448
3455 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3449 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3456 3450
3457 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); 3451 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0);
3458 3452
3459 KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); 3453 KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock));
3460 KASSERT(xfer->ux_rqflags & URQ_REQUEST); 3454 KASSERT(xfer->ux_rqflags & URQ_REQUEST);
3461 3455
3462 if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { 3456 if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) {
3463 ehci_del_intr_list(sc, ex); /* remove from active list */ 3457 ehci_del_intr_list(sc, ex); /* remove from active list */
3464 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); 3458 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL);
3465 usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req), 3459 usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req),
3466 BUS_DMASYNC_POSTWRITE); 3460 BUS_DMASYNC_POSTWRITE);
3467 if (len) 3461 if (len)
3468 usb_syncmem(&xfer->ux_dmabuf, 0, len, 3462 usb_syncmem(&xfer->ux_dmabuf, 0, len,
3469 rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); 3463 rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
3470 } 3464 }
3471 3465
3472 USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0); 3466 USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0);
3473} 3467}
3474 3468
3475/* Abort a device control request. */ 3469/* Abort a device control request. */
3476Static void 3470Static void
3477ehci_device_ctrl_abort(usbd_xfer_handle xfer) 3471ehci_device_ctrl_abort(usbd_xfer_handle xfer)
3478{ 3472{
3479 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3473 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3480 3474
3481 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); 3475 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0);
3482 ehci_abort_xfer(xfer, USBD_CANCELLED); 3476 ehci_abort_xfer(xfer, USBD_CANCELLED);
3483} 3477}
3484 3478
3485/* Close a device control pipe. */ 3479/* Close a device control pipe. */
3486Static void 3480Static void
3487ehci_device_ctrl_close(usbd_pipe_handle pipe) 3481ehci_device_ctrl_close(usbd_pipe_handle pipe)
3488{ 3482{
3489 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; 3483 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
3490 /*struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;*/ 3484 /*struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;*/
3491 3485
3492 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3486 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3493 3487
3494 KASSERT(mutex_owned(&sc->sc_lock)); 3488 KASSERT(mutex_owned(&sc->sc_lock));
3495 3489
3496 USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0); 3490 USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0);
3497 3491
3498 ehci_close_pipe(pipe, sc->sc_async_head); 3492 ehci_close_pipe(pipe, sc->sc_async_head);
3499} 3493}
3500 3494
3501Static usbd_status 3495Static usbd_status
3502ehci_device_request(usbd_xfer_handle xfer) 3496ehci_device_request(usbd_xfer_handle xfer)
3503{ 3497{
3504#define exfer EXFER(xfer) 3498#define exfer EXFER(xfer)
3505 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; 3499 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe;
3506 usb_device_request_t *req = &xfer->ux_request; 3500 usb_device_request_t *req = &xfer->ux_request;
3507 usbd_device_handle dev = epipe->pipe.up_dev; 3501 usbd_device_handle dev = epipe->pipe.up_dev;
3508 ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; 3502 ehci_softc_t *sc = dev->ud_bus->ub_hcpriv;
3509 ehci_soft_qtd_t *setup, *stat, *next; 3503 ehci_soft_qtd_t *setup, *stat, *next;
3510 ehci_soft_qh_t *sqh; 3504 ehci_soft_qh_t *sqh;
3511 int isread; 3505 int isread;
3512 int len; 3506 int len;
3513 usbd_status err; 3507 usbd_status err;
3514 3508
3515 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3509 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3516 3510
3517 isread = req->bmRequestType & UT_READ; 3511 isread = req->bmRequestType & UT_READ;
3518 len = UGETW(req->wLength); 3512 len = UGETW(req->wLength);
3519 3513
3520 USBHIST_LOG(ehcidebug, "type=0x%02x, request=0x%02x, " 3514 USBHIST_LOG(ehcidebug, "type=0x%02x, request=0x%02x, "
3521 "wValue=0x%04x, wIndex=0x%04x", 3515 "wValue=0x%04x, wIndex=0x%04x",
3522 req->bmRequestType, req->bRequest, UGETW(req->wValue), 3516 req->bmRequestType, req->bRequest, UGETW(req->wValue),
3523 UGETW(req->wIndex)); 3517 UGETW(req->wIndex));
3524 USBHIST_LOG(ehcidebug, "len=%d, addr=%d, endpt=%d", 3518 USBHIST_LOG(ehcidebug, "len=%d, addr=%d, endpt=%d",
3525 len, dev->ud_addr, 3519 len, dev->ud_addr,
3526 epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress, 0); 3520 epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress, 0);
3527 3521
3528 setup = ehci_alloc_sqtd(sc); 3522 setup = ehci_alloc_sqtd(sc);
3529 if (setup == NULL) { 3523 if (setup == NULL) {
3530 err = USBD_NOMEM; 3524 err = USBD_NOMEM;
3531 goto bad1; 3525 goto bad1;
3532 } 3526 }
3533 stat = ehci_alloc_sqtd(sc); 3527 stat = ehci_alloc_sqtd(sc);
3534 if (stat == NULL) { 3528 if (stat == NULL) {
3535 err = USBD_NOMEM; 3529 err = USBD_NOMEM;
3536 goto bad2; 3530 goto bad2;
3537 } 3531 }
3538 3532
3539 mutex_enter(&sc->sc_lock); 3533 mutex_enter(&sc->sc_lock);
3540 3534
3541 sqh = epipe->sqh; 3535 sqh = epipe->sqh;
3542 3536
3543 KASSERTMSG(EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)) == dev->ud_addr, 3537 KASSERTMSG(EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)) == dev->ud_addr,
3544 "address QH %d pipe %d\n", 3538 "address QH %d pipe %d\n",
3545 EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)), dev->ud_addr); 3539 EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)), dev->ud_addr);
3546 KASSERTMSG(EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)) == 3540 KASSERTMSG(EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)) ==
3547 UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize), 3541 UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize),
3548 "MPS QH %d pipe %d\n", 3542 "MPS QH %d pipe %d\n",
3549 EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)), 3543 EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)),
3550 UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize)); 3544 UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize));
3551 3545
3552 /* Set up data transaction */ 3546 /* Set up data transaction */
3553 if (len != 0) { 3547 if (len != 0) {
3554 ehci_soft_qtd_t *end; 3548 ehci_soft_qtd_t *end;
3555 3549
3556 /* Start toggle at 1. */ 3550 /* Start toggle at 1. */
3557 epipe->nexttoggle = 1; 3551 epipe->nexttoggle = 1;
3558 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, 3552 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer,
3559 &next, &end); 3553 &next, &end);
3560 if (err) 3554 if (err)
3561 goto bad3; 3555 goto bad3;
3562 end->qtd.qtd_status &= htole32(~EHCI_QTD_IOC); 3556 end->qtd.qtd_status &= htole32(~EHCI_QTD_IOC);
3563 end->nextqtd = stat; 3557 end->nextqtd = stat;
3564 end->qtd.qtd_next = end->qtd.qtd_altnext = 3558 end->qtd.qtd_next = end->qtd.qtd_altnext =
3565 htole32(stat->physaddr); 3559 htole32(stat->physaddr);
3566 usb_syncmem(&end->dma, end->offs, sizeof(end->qtd), 3560 usb_syncmem(&end->dma, end->offs, sizeof(end->qtd),
3567 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3561 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3568 } else { 3562 } else {
3569 next = stat; 3563 next = stat;
3570 } 3564 }
3571 3565
3572 memcpy(KERNADDR(&epipe->u.ctl.reqdma, 0), req, sizeof(*req)); 3566 memcpy(KERNADDR(&epipe->u.ctl.reqdma, 0), req, sizeof(*req));
3573 usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req), BUS_DMASYNC_PREWRITE); 3567 usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req), BUS_DMASYNC_PREWRITE);
3574 3568
3575 /* Clear toggle */ 3569 /* Clear toggle */
3576 setup->qtd.qtd_status = htole32( 3570 setup->qtd.qtd_status = htole32(
3577 EHCI_QTD_ACTIVE | 3571 EHCI_QTD_ACTIVE |
3578 EHCI_QTD_SET_PID(EHCI_QTD_PID_SETUP) | 3572 EHCI_QTD_SET_PID(EHCI_QTD_PID_SETUP) |
3579 EHCI_QTD_SET_CERR(3) | 3573 EHCI_QTD_SET_CERR(3) |
3580 EHCI_QTD_SET_TOGGLE(0) | 3574 EHCI_QTD_SET_TOGGLE(0) |
3581 EHCI_QTD_SET_BYTES(sizeof(*req)) 3575 EHCI_QTD_SET_BYTES(sizeof(*req))
3582 ); 3576 );
3583 setup->qtd.qtd_buffer[0] = htole32(DMAADDR(&epipe->u.ctl.reqdma, 0)); 3577 setup->qtd.qtd_buffer[0] = htole32(DMAADDR(&epipe->u.ctl.reqdma, 0));
3584 setup->qtd.qtd_buffer_hi[0] = 0; 3578 setup->qtd.qtd_buffer_hi[0] = 0;
3585 setup->nextqtd = next; 3579 setup->nextqtd = next;
3586 setup->qtd.qtd_next = setup->qtd.qtd_altnext = htole32(next->physaddr); 3580 setup->qtd.qtd_next = setup->qtd.qtd_altnext = htole32(next->physaddr);
3587 setup->xfer = xfer; 3581 setup->xfer = xfer;
3588 setup->len = sizeof(*req); 3582 setup->len = sizeof(*req);
3589 usb_syncmem(&setup->dma, setup->offs, sizeof(setup->qtd), 3583 usb_syncmem(&setup->dma, setup->offs, sizeof(setup->qtd),
3590 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3584 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3591 3585
3592 stat->qtd.qtd_status = htole32( 3586 stat->qtd.qtd_status = htole32(
3593 EHCI_QTD_ACTIVE | 3587 EHCI_QTD_ACTIVE |
3594 EHCI_QTD_SET_PID(isread ? EHCI_QTD_PID_OUT : EHCI_QTD_PID_IN) | 3588 EHCI_QTD_SET_PID(isread ? EHCI_QTD_PID_OUT : EHCI_QTD_PID_IN) |
3595 EHCI_QTD_SET_CERR(3) | 3589 EHCI_QTD_SET_CERR(3) |
3596 EHCI_QTD_SET_TOGGLE(1) | 3590 EHCI_QTD_SET_TOGGLE(1) |
3597 EHCI_QTD_IOC 3591 EHCI_QTD_IOC
3598 ); 3592 );
3599 stat->qtd.qtd_buffer[0] = 0; /* XXX not needed? */ 3593 stat->qtd.qtd_buffer[0] = 0; /* XXX not needed? */
3600 stat->qtd.qtd_buffer_hi[0] = 0; /* XXX not needed? */ 3594 stat->qtd.qtd_buffer_hi[0] = 0; /* XXX not needed? */
3601 stat->nextqtd = NULL; 3595 stat->nextqtd = NULL;
3602 stat->qtd.qtd_next = stat->qtd.qtd_altnext = EHCI_NULL; 3596 stat->qtd.qtd_next = stat->qtd.qtd_altnext = EHCI_NULL;
3603 stat->xfer = xfer; 3597 stat->xfer = xfer;
3604 stat->len = 0; 3598 stat->len = 0;
3605 usb_syncmem(&stat->dma, stat->offs, sizeof(stat->qtd), 3599 usb_syncmem(&stat->dma, stat->offs, sizeof(stat->qtd),
3606 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3600 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3607 3601
3608#ifdef EHCI_DEBUG 3602#ifdef EHCI_DEBUG
3609 USBHIST_LOGN(ehcidebug, 5, "dump:", 0, 0, 0, 0); 3603 USBHIST_LOGN(ehcidebug, 5, "dump:", 0, 0, 0, 0);
3610 ehci_dump_sqh(sqh); 3604 ehci_dump_sqh(sqh);
3611 ehci_dump_sqtds(setup); 3605 ehci_dump_sqtds(setup);
3612#endif 3606#endif
3613 3607
3614 exfer->ex_sqtdstart = setup; 3608 exfer->ex_sqtdstart = setup;
3615 exfer->ex_sqtdend = stat; 3609 exfer->ex_sqtdend = stat;
 3610 KASSERT(exfer->ex_isdone);
3616#ifdef DIAGNOSTIC 3611#ifdef DIAGNOSTIC
3617 if (!exfer->ex_isdone) { 3612 exfer->ex_isdone = false;
3618 printf("ehci_device_request: not done, exfer=%p\n", exfer); 
3619 } 
3620 exfer->ex_isdone = 0; 
3621#endif 3613#endif
3622 3614
3623 /* Insert qTD in QH list. */ 3615 /* Insert qTD in QH list. */
3624 ehci_set_qh_qtd(sqh, setup); /* also does usb_syncmem(sqh) */ 3616 ehci_set_qh_qtd(sqh, setup); /* also does usb_syncmem(sqh) */
3625 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { 3617 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) {
3626 callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), 3618 callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout),
3627 ehci_timeout, xfer); 3619 ehci_timeout, xfer);
3628 } 3620 }
3629 ehci_add_intr_list(sc, exfer); 3621 ehci_add_intr_list(sc, exfer);
3630 xfer->ux_status = USBD_IN_PROGRESS; 3622 xfer->ux_status = USBD_IN_PROGRESS;
3631 mutex_exit(&sc->sc_lock); 3623 mutex_exit(&sc->sc_lock);
3632 3624
3633#ifdef EHCI_DEBUG 3625#ifdef EHCI_DEBUG
3634 USBHIST_LOGN(ehcidebug, 10, "status=%x, dump:", 3626 USBHIST_LOGN(ehcidebug, 10, "status=%x, dump:",
3635 EOREAD4(sc, EHCI_USBSTS), 0, 0, 0); 3627 EOREAD4(sc, EHCI_USBSTS), 0, 0, 0);
3636// delay(10000); 3628// delay(10000);
3637 ehci_dump_regs(sc); 3629 ehci_dump_regs(sc);
3638 ehci_dump_sqh(sc->sc_async_head); 3630 ehci_dump_sqh(sc->sc_async_head);
3639 ehci_dump_sqh(sqh); 3631 ehci_dump_sqh(sqh);
3640 ehci_dump_sqtds(setup); 3632 ehci_dump_sqtds(setup);
3641#endif 3633#endif
3642 3634
3643 return USBD_NORMAL_COMPLETION; 3635 return USBD_NORMAL_COMPLETION;
3644 3636
3645 bad3: 3637 bad3:
3646 mutex_exit(&sc->sc_lock); 3638 mutex_exit(&sc->sc_lock);
3647 ehci_free_sqtd(sc, stat); 3639 ehci_free_sqtd(sc, stat);
3648 bad2: 3640 bad2:
3649 ehci_free_sqtd(sc, setup); 3641 ehci_free_sqtd(sc, setup);
3650 bad1: 3642 bad1:
3651 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); 3643 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0);
3652 mutex_enter(&sc->sc_lock); 3644 mutex_enter(&sc->sc_lock);
3653 xfer->ux_status = err; 3645 xfer->ux_status = err;
3654 usb_transfer_complete(xfer); 3646 usb_transfer_complete(xfer);
3655 mutex_exit(&sc->sc_lock); 3647 mutex_exit(&sc->sc_lock);
3656 return err; 3648 return err;
3657#undef exfer 3649#undef exfer
3658} 3650}
3659 3651
3660/* 3652/*
3661 * Some EHCI chips from VIA seem to trigger interrupts before writing back the 3653 * Some EHCI chips from VIA seem to trigger interrupts before writing back the
3662 * qTD status, or miss signalling occasionally under heavy load. If the host 3654 * qTD status, or miss signalling occasionally under heavy load. If the host
3663 * machine is too fast, we we can miss transaction completion - when we scan 3655 * machine is too fast, we we can miss transaction completion - when we scan
3664 * the active list the transaction still seems to be active. This generally 3656 * the active list the transaction still seems to be active. This generally
3665 * exhibits itself as a umass stall that never recovers. 3657 * exhibits itself as a umass stall that never recovers.
3666 * 3658 *
3667 * We work around this behaviour by setting up this callback after any softintr 3659 * We work around this behaviour by setting up this callback after any softintr
3668 * that completes with transactions still pending, giving us another chance to 3660 * that completes with transactions still pending, giving us another chance to
3669 * check for completion after the writeback has taken place. 3661 * check for completion after the writeback has taken place.
3670 */ 3662 */
3671Static void 3663Static void
3672ehci_intrlist_timeout(void *arg) 3664ehci_intrlist_timeout(void *arg)
3673{ 3665{
3674 ehci_softc_t *sc = arg; 3666 ehci_softc_t *sc = arg;
3675 3667
3676 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3668 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3677 3669
3678 usb_schedsoftintr(&sc->sc_bus); 3670 usb_schedsoftintr(&sc->sc_bus);
3679} 3671}
3680 3672
3681/************************/ 3673/************************/
3682 3674
3683Static usbd_status 3675Static usbd_status
3684ehci_device_bulk_transfer(usbd_xfer_handle xfer) 3676ehci_device_bulk_transfer(usbd_xfer_handle xfer)
3685{ 3677{
3686 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3678 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
3687 usbd_status err; 3679 usbd_status err;
3688 3680
3689 /* Insert last in queue. */ 3681 /* Insert last in queue. */
3690 mutex_enter(&sc->sc_lock); 3682 mutex_enter(&sc->sc_lock);
3691 err = usb_insert_transfer(xfer); 3683 err = usb_insert_transfer(xfer);
3692 mutex_exit(&sc->sc_lock); 3684 mutex_exit(&sc->sc_lock);
3693 if (err) 3685 if (err)
3694 return err; 3686 return err;
3695 3687
3696 /* Pipe isn't running, start first */ 3688 /* Pipe isn't running, start first */
3697 return ehci_device_bulk_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); 3689 return ehci_device_bulk_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue));
3698} 3690}
3699 3691
3700Static usbd_status 3692Static usbd_status
3701ehci_device_bulk_start(usbd_xfer_handle xfer) 3693ehci_device_bulk_start(usbd_xfer_handle xfer)
3702{ 3694{
3703#define exfer EXFER(xfer) 3695#define exfer EXFER(xfer)
3704 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; 3696 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe;
3705 usbd_device_handle dev = epipe->pipe.up_dev; 3697 usbd_device_handle dev = epipe->pipe.up_dev;
3706 ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; 3698 ehci_softc_t *sc = dev->ud_bus->ub_hcpriv;
3707 ehci_soft_qtd_t *data, *dataend; 3699 ehci_soft_qtd_t *data, *dataend;
3708 ehci_soft_qh_t *sqh; 3700 ehci_soft_qh_t *sqh;
3709 usbd_status err; 3701 usbd_status err;
3710 int len, isread, endpt; 3702 int len, isread, endpt;
3711 3703
3712 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3704 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3713 3705
3714 USBHIST_LOG(ehcidebug, "xfer=%p len=%d flags=%d", 3706 USBHIST_LOG(ehcidebug, "xfer=%p len=%d flags=%d",
3715 xfer, xfer->ux_length, xfer->ux_flags, 0); 3707 xfer, xfer->ux_length, xfer->ux_flags, 0);
3716 3708
3717 if (sc->sc_dying) 3709 if (sc->sc_dying)
3718 return USBD_IOERROR; 3710 return USBD_IOERROR;
3719 3711
3720 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); 3712 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST));
3721 3713
3722 mutex_enter(&sc->sc_lock); 3714 mutex_enter(&sc->sc_lock);
3723 3715
3724 len = xfer->ux_length; 3716 len = xfer->ux_length;
3725 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; 3717 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
3726 isread = UE_GET_DIR(endpt) == UE_DIR_IN; 3718 isread = UE_GET_DIR(endpt) == UE_DIR_IN;
3727 sqh = epipe->sqh; 3719 sqh = epipe->sqh;
3728 3720
3729 epipe->u.bulk.length = len; 3721 epipe->u.bulk.length = len;
3730 3722
3731 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data, 3723 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data,
3732 &dataend); 3724 &dataend);
3733 if (err) { 3725 if (err) {
3734 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); 3726 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0);
3735 xfer->ux_status = err; 3727 xfer->ux_status = err;
3736 usb_transfer_complete(xfer); 3728 usb_transfer_complete(xfer);
3737 mutex_exit(&sc->sc_lock); 3729 mutex_exit(&sc->sc_lock);
3738 return err; 3730 return err;
3739 } 3731 }
3740 3732
3741#ifdef EHCI_DEBUG 3733#ifdef EHCI_DEBUG
3742 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); 3734 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0);
3743 ehci_dump_sqh(sqh); 3735 ehci_dump_sqh(sqh);
3744 ehci_dump_sqtds(data); 3736 ehci_dump_sqtds(data);
3745 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); 3737 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0);
3746#endif 3738#endif
3747 3739
3748 /* Set up interrupt info. */ 3740 /* Set up interrupt info. */
3749 exfer->ex_sqtdstart = data; 3741 exfer->ex_sqtdstart = data;
3750 exfer->ex_sqtdend = dataend; 3742 exfer->ex_sqtdend = dataend;
 3743 KASSERT(exfer->ex_isdone);
3751#ifdef DIAGNOSTIC 3744#ifdef DIAGNOSTIC
3752 if (!exfer->ex_isdone) { 3745 exfer->ex_isdone = false;
3753 printf("ehci_device_bulk_start: not done, ex=%p\n", exfer); 
3754 } 
3755 exfer->ex_isdone = 0; 
3756#endif 3746#endif
3757 3747
3758 ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */ 3748 ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */
3759 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { 3749 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) {
3760 callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), 3750 callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout),
3761 ehci_timeout, xfer); 3751 ehci_timeout, xfer);
3762 } 3752 }
3763 ehci_add_intr_list(sc, exfer); 3753 ehci_add_intr_list(sc, exfer);
3764 xfer->ux_status = USBD_IN_PROGRESS; 3754 xfer->ux_status = USBD_IN_PROGRESS;
3765 mutex_exit(&sc->sc_lock); 3755 mutex_exit(&sc->sc_lock);
3766 3756
3767#ifdef EHCI_DEBUG 3757#ifdef EHCI_DEBUG
3768 USBHIST_LOGN(ehcidebug, 5, "data(2)", 0, 0, 0, 0); 3758 USBHIST_LOGN(ehcidebug, 5, "data(2)", 0, 0, 0, 0);
3769// delay(10000); 3759// delay(10000);
3770 USBHIST_LOGN(ehcidebug, 5, "data(3)", 0, 0, 0, 0); 3760 USBHIST_LOGN(ehcidebug, 5, "data(3)", 0, 0, 0, 0);
3771 ehci_dump_regs(sc); 3761 ehci_dump_regs(sc);
3772#if 0 3762#if 0
3773 printf("async_head:\n"); 3763 printf("async_head:\n");
3774 ehci_dump_sqh(sc->sc_async_head); 3764 ehci_dump_sqh(sc->sc_async_head);
3775#endif 3765#endif
3776 USBHIST_LOG(ehcidebug, "sqh:", 0, 0, 0, 0); 3766 USBHIST_LOG(ehcidebug, "sqh:", 0, 0, 0, 0);
3777 ehci_dump_sqh(sqh); 3767 ehci_dump_sqh(sqh);
3778 ehci_dump_sqtds(data); 3768 ehci_dump_sqtds(data);
3779#endif 3769#endif
3780 3770
3781 if (sc->sc_bus.ub_usepolling) 3771 if (sc->sc_bus.ub_usepolling)
3782 ehci_waitintr(sc, xfer); 3772 ehci_waitintr(sc, xfer);
3783 3773
3784 return USBD_IN_PROGRESS; 3774 return USBD_IN_PROGRESS;
3785#undef exfer 3775#undef exfer
3786} 3776}
3787 3777
3788Static void 3778Static void
3789ehci_device_bulk_abort(usbd_xfer_handle xfer) 3779ehci_device_bulk_abort(usbd_xfer_handle xfer)
3790{ 3780{
3791 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3781 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3792 3782
3793 USBHIST_LOG(ehcidebug, "xfer %p", xfer, 0, 0, 0); 3783 USBHIST_LOG(ehcidebug, "xfer %p", xfer, 0, 0, 0);
3794 ehci_abort_xfer(xfer, USBD_CANCELLED); 3784 ehci_abort_xfer(xfer, USBD_CANCELLED);
3795} 3785}
3796 3786
3797/* 3787/*
3798 * Close a device bulk pipe. 3788 * Close a device bulk pipe.
3799 */ 3789 */
3800Static void 3790Static void
3801ehci_device_bulk_close(usbd_pipe_handle pipe) 3791ehci_device_bulk_close(usbd_pipe_handle pipe)
3802{ 3792{
3803 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; 3793 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
3804 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; 3794 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;
3805 3795
3806 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3796 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3807 3797
3808 KASSERT(mutex_owned(&sc->sc_lock)); 3798 KASSERT(mutex_owned(&sc->sc_lock));
3809 3799
3810 USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0); 3800 USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0);
3811 pipe->up_endpoint->ue_toggle = epipe->nexttoggle; 3801 pipe->up_endpoint->ue_toggle = epipe->nexttoggle;
3812 ehci_close_pipe(pipe, sc->sc_async_head); 3802 ehci_close_pipe(pipe, sc->sc_async_head);
3813} 3803}
3814 3804
3815Static void 3805Static void
3816ehci_device_bulk_done(usbd_xfer_handle xfer) 3806ehci_device_bulk_done(usbd_xfer_handle xfer)
3817{ 3807{
3818 struct ehci_xfer *ex = EXFER(xfer); 3808 struct ehci_xfer *ex = EXFER(xfer);
3819 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3809 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
3820 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; 3810 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe;
3821 int endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; 3811 int endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
3822 int rd = UE_GET_DIR(endpt) == UE_DIR_IN; 3812 int rd = UE_GET_DIR(endpt) == UE_DIR_IN;
3823 3813
3824 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3814 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3825 3815
3826 USBHIST_LOG(ehcidebug, "xfer=%p, actlen=%d", 3816 USBHIST_LOG(ehcidebug, "xfer=%p, actlen=%d",
3827 xfer, xfer->ux_actlen, 0, 0); 3817 xfer, xfer->ux_actlen, 0, 0);
3828 3818
3829 KASSERT(mutex_owned(&sc->sc_lock)); 3819 KASSERT(mutex_owned(&sc->sc_lock));
3830 3820
3831 if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { 3821 if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) {
3832 ehci_del_intr_list(sc, ex); /* remove from active list */ 3822 ehci_del_intr_list(sc, ex); /* remove from active list */
3833 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); 3823 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL);
3834 usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, 3824 usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length,
3835 rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); 3825 rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
3836 } 3826 }
3837 3827
3838 USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0); 3828 USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0);
3839} 3829}
3840 3830
3841/************************/ 3831/************************/
3842 3832
3843Static usbd_status 3833Static usbd_status
3844ehci_device_setintr(ehci_softc_t *sc, ehci_soft_qh_t *sqh, int ival) 3834ehci_device_setintr(ehci_softc_t *sc, ehci_soft_qh_t *sqh, int ival)
3845{ 3835{
3846 struct ehci_soft_islot *isp; 3836 struct ehci_soft_islot *isp;
3847 int islot, lev; 3837 int islot, lev;
3848 3838
3849 /* Find a poll rate that is large enough. */ 3839 /* Find a poll rate that is large enough. */
3850 for (lev = EHCI_IPOLLRATES - 1; lev > 0; lev--) 3840 for (lev = EHCI_IPOLLRATES - 1; lev > 0; lev--)
3851 if (EHCI_ILEV_IVAL(lev) <= ival) 3841 if (EHCI_ILEV_IVAL(lev) <= ival)
3852 break; 3842 break;
3853 3843
3854 /* Pick an interrupt slot at the right level. */ 3844 /* Pick an interrupt slot at the right level. */
3855 /* XXX could do better than picking at random */ 3845 /* XXX could do better than picking at random */
3856 sc->sc_rand = (sc->sc_rand + 191) % sc->sc_flsize; 3846 sc->sc_rand = (sc->sc_rand + 191) % sc->sc_flsize;
3857 islot = EHCI_IQHIDX(lev, sc->sc_rand); 3847 islot = EHCI_IQHIDX(lev, sc->sc_rand);
3858 3848
3859 sqh->islot = islot; 3849 sqh->islot = islot;
3860 isp = &sc->sc_islots[islot]; 3850 isp = &sc->sc_islots[islot];
3861 mutex_enter(&sc->sc_lock); 3851 mutex_enter(&sc->sc_lock);
3862 ehci_add_qh(sc, sqh, isp->sqh); 3852 ehci_add_qh(sc, sqh, isp->sqh);
3863 mutex_exit(&sc->sc_lock); 3853 mutex_exit(&sc->sc_lock);
3864 3854
3865 return USBD_NORMAL_COMPLETION; 3855 return USBD_NORMAL_COMPLETION;
3866} 3856}
3867 3857
3868Static usbd_status 3858Static usbd_status
3869ehci_device_intr_transfer(usbd_xfer_handle xfer) 3859ehci_device_intr_transfer(usbd_xfer_handle xfer)
3870{ 3860{
3871 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3861 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
3872 usbd_status err; 3862 usbd_status err;
3873 3863
3874 /* Insert last in queue. */ 3864 /* Insert last in queue. */
3875 mutex_enter(&sc->sc_lock); 3865 mutex_enter(&sc->sc_lock);
3876 err = usb_insert_transfer(xfer); 3866 err = usb_insert_transfer(xfer);
3877 mutex_exit(&sc->sc_lock); 3867 mutex_exit(&sc->sc_lock);
3878 if (err) 3868 if (err)
3879 return err; 3869 return err;
3880 3870
3881 /* 3871 /*
3882 * Pipe isn't running (otherwise err would be USBD_INPROG), 3872 * Pipe isn't running (otherwise err would be USBD_INPROG),
3883 * so start it first. 3873 * so start it first.
3884 */ 3874 */
3885 return ehci_device_intr_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); 3875 return ehci_device_intr_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue));
3886} 3876}
3887 3877
3888Static usbd_status 3878Static usbd_status
3889ehci_device_intr_start(usbd_xfer_handle xfer) 3879ehci_device_intr_start(usbd_xfer_handle xfer)
3890{ 3880{
3891#define exfer EXFER(xfer) 3881#define exfer EXFER(xfer)
3892 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; 3882 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe;
3893 usbd_device_handle dev = xfer->ux_pipe->up_dev; 3883 usbd_device_handle dev = xfer->ux_pipe->up_dev;
3894 ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; 3884 ehci_softc_t *sc = dev->ud_bus->ub_hcpriv;
3895 ehci_soft_qtd_t *data, *dataend; 3885 ehci_soft_qtd_t *data, *dataend;
3896 ehci_soft_qh_t *sqh; 3886 ehci_soft_qh_t *sqh;
3897 usbd_status err; 3887 usbd_status err;
3898 int len, isread, endpt; 3888 int len, isread, endpt;
3899 3889
3900 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3890 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3901 3891
3902 USBHIST_LOG(ehcidebug, "xfer=%p len=%d flags=%d", 3892 USBHIST_LOG(ehcidebug, "xfer=%p len=%d flags=%d",
3903 xfer, xfer->ux_length, xfer->ux_flags, 0); 3893 xfer, xfer->ux_length, xfer->ux_flags, 0);
3904 3894
3905 if (sc->sc_dying) 3895 if (sc->sc_dying)
3906 return USBD_IOERROR; 3896 return USBD_IOERROR;
3907 3897
3908 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); 3898 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST));
3909 3899
3910 mutex_enter(&sc->sc_lock); 3900 mutex_enter(&sc->sc_lock);
3911 3901
3912 len = xfer->ux_length; 3902 len = xfer->ux_length;
3913 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; 3903 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
3914 isread = UE_GET_DIR(endpt) == UE_DIR_IN; 3904 isread = UE_GET_DIR(endpt) == UE_DIR_IN;
3915 sqh = epipe->sqh; 3905 sqh = epipe->sqh;
3916 3906
3917 epipe->u.intr.length = len; 3907 epipe->u.intr.length = len;
3918 3908
3919 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data, 3909 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data,
3920 &dataend); 3910 &dataend);
3921 if (err) { 3911 if (err) {
3922 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); 3912 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0);
3923 xfer->ux_status = err; 3913 xfer->ux_status = err;
3924 usb_transfer_complete(xfer); 3914 usb_transfer_complete(xfer);
3925 mutex_exit(&sc->sc_lock); 3915 mutex_exit(&sc->sc_lock);
3926 return err; 3916 return err;
3927 } 3917 }
3928 3918
3929#ifdef EHCI_DEBUG 3919#ifdef EHCI_DEBUG
3930 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); 3920 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0);
3931 ehci_dump_sqh(sqh); 3921 ehci_dump_sqh(sqh);
3932 ehci_dump_sqtds(data); 3922 ehci_dump_sqtds(data);
3933 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); 3923 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0);
3934#endif 3924#endif
3935 3925
3936 /* Set up interrupt info. */ 3926 /* Set up interrupt info. */
3937 exfer->ex_sqtdstart = data; 3927 exfer->ex_sqtdstart = data;
3938 exfer->ex_sqtdend = dataend; 3928 exfer->ex_sqtdend = dataend;
 3929 KASSERT(exfer->ex_isdone);
3939#ifdef DIAGNOSTIC 3930#ifdef DIAGNOSTIC
3940 if (!exfer->ex_isdone) { 3931 exfer->ex_isdone = false;
3941 printf("ehci_device_intr_start: not done, ex=%p\n", exfer); 
3942 } 
3943 exfer->ex_isdone = 0; 
3944#endif 3932#endif
3945 3933
3946 ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */ 3934 ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */
3947 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { 3935 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) {
3948 callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), 3936 callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout),
3949 ehci_timeout, xfer); 3937 ehci_timeout, xfer);
3950 } 3938 }
3951 ehci_add_intr_list(sc, exfer); 3939 ehci_add_intr_list(sc, exfer);
3952 xfer->ux_status = USBD_IN_PROGRESS; 3940 xfer->ux_status = USBD_IN_PROGRESS;
3953 mutex_exit(&sc->sc_lock); 3941 mutex_exit(&sc->sc_lock);
3954 3942
3955#ifdef EHCI_DEBUG 3943#ifdef EHCI_DEBUG
3956 USBHIST_LOGN(ehcidebug, 5, "data(2)", 0, 0, 0, 0); 3944 USBHIST_LOGN(ehcidebug, 5, "data(2)", 0, 0, 0, 0);
3957// delay(10000); 3945// delay(10000);
3958 USBHIST_LOGN(ehcidebug, 5, "data(3)", 0, 0, 0, 0); 3946 USBHIST_LOGN(ehcidebug, 5, "data(3)", 0, 0, 0, 0);
3959 ehci_dump_regs(sc); 3947 ehci_dump_regs(sc);
3960 USBHIST_LOGN(ehcidebug, 5, "sqh:", 0, 0, 0, 0); 3948 USBHIST_LOGN(ehcidebug, 5, "sqh:", 0, 0, 0, 0);
3961 ehci_dump_sqh(sqh); 3949 ehci_dump_sqh(sqh);
3962 ehci_dump_sqtds(data); 3950 ehci_dump_sqtds(data);
3963#endif 3951#endif
3964 3952
3965 if (sc->sc_bus.ub_usepolling) 3953 if (sc->sc_bus.ub_usepolling)
3966 ehci_waitintr(sc, xfer); 3954 ehci_waitintr(sc, xfer);
3967 3955
3968 return USBD_IN_PROGRESS; 3956 return USBD_IN_PROGRESS;
3969#undef exfer 3957#undef exfer
3970} 3958}
3971 3959
3972Static void 3960Static void
3973ehci_device_intr_abort(usbd_xfer_handle xfer) 3961ehci_device_intr_abort(usbd_xfer_handle xfer)
3974{ 3962{
3975 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3963 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3976 3964
3977 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); 3965 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0);
3978 KASSERT(xfer->ux_pipe->up_intrxfer == xfer); 3966 KASSERT(xfer->ux_pipe->up_intrxfer == xfer);
3979 3967
3980 /* 3968 /*
3981 * XXX - abort_xfer uses ehci_sync_hc, which syncs via the advance 3969 * XXX - abort_xfer uses ehci_sync_hc, which syncs via the advance
3982 * async doorbell. That's dependent on the async list, wheras 3970 * async doorbell. That's dependent on the async list, wheras
3983 * intr xfers are periodic, should not use this? 3971 * intr xfers are periodic, should not use this?
3984 */ 3972 */
3985 ehci_abort_xfer(xfer, USBD_CANCELLED); 3973 ehci_abort_xfer(xfer, USBD_CANCELLED);
3986} 3974}
3987 3975
3988Static void 3976Static void
3989ehci_device_intr_close(usbd_pipe_handle pipe) 3977ehci_device_intr_close(usbd_pipe_handle pipe)
3990{ 3978{
3991 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; 3979 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
3992 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; 3980 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;
3993 struct ehci_soft_islot *isp; 3981 struct ehci_soft_islot *isp;
3994 3982
3995 KASSERT(mutex_owned(&sc->sc_lock)); 3983 KASSERT(mutex_owned(&sc->sc_lock));
3996 3984
3997 isp = &sc->sc_islots[epipe->sqh->islot]; 3985 isp = &sc->sc_islots[epipe->sqh->islot];
3998 ehci_close_pipe(pipe, isp->sqh); 3986 ehci_close_pipe(pipe, isp->sqh);
3999} 3987}
4000 3988
4001Static void 3989Static void
4002ehci_device_intr_done(usbd_xfer_handle xfer) 3990ehci_device_intr_done(usbd_xfer_handle xfer)
4003{ 3991{
4004#define exfer EXFER(xfer) 3992#define exfer EXFER(xfer)
4005 struct ehci_xfer *ex = EXFER(xfer); 3993 struct ehci_xfer *ex = EXFER(xfer);
4006 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3994 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
4007 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; 3995 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe;
4008 ehci_soft_qtd_t *data, *dataend; 3996 ehci_soft_qtd_t *data, *dataend;
4009 ehci_soft_qh_t *sqh; 3997 ehci_soft_qh_t *sqh;
4010 usbd_status err; 3998 usbd_status err;
4011 int len, isread, endpt; 3999 int len, isread, endpt;
4012 4000
4013 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 4001 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
4014 4002
4015 USBHIST_LOG(ehcidebug, "xfer=%p, actlen=%d", 4003 USBHIST_LOG(ehcidebug, "xfer=%p, actlen=%d",
4016 xfer, xfer->ux_actlen, 0, 0); 4004 xfer, xfer->ux_actlen, 0, 0);
4017 4005
4018 KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); 4006 KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock));
4019 4007
4020 if (xfer->ux_pipe->up_repeat) { 4008 if (xfer->ux_pipe->up_repeat) {
4021 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); 4009 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL);
4022 4010
4023 len = epipe->u.intr.length; 4011 len = epipe->u.intr.length;
4024 xfer->ux_length = len; 4012 xfer->ux_length = len;
4025 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; 4013 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
4026 isread = UE_GET_DIR(endpt) == UE_DIR_IN; 4014 isread = UE_GET_DIR(endpt) == UE_DIR_IN;
4027 usb_syncmem(&xfer->ux_dmabuf, 0, len, 4015 usb_syncmem(&xfer->ux_dmabuf, 0, len,
4028 isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); 4016 isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
4029 sqh = epipe->sqh; 4017 sqh = epipe->sqh;
4030 4018
4031 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, 4019 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer,
4032 &data, &dataend); 4020 &data, &dataend);
4033 if (err) { 4021 if (err) {
4034 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); 4022 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0);
4035 xfer->ux_status = err; 4023 xfer->ux_status = err;
4036 return; 4024 return;
4037 } 4025 }
4038 4026
4039 /* Set up interrupt info. */ 4027 /* Set up interrupt info. */
4040 exfer->ex_sqtdstart = data; 4028 exfer->ex_sqtdstart = data;
4041 exfer->ex_sqtdend = dataend; 4029 exfer->ex_sqtdend = dataend;
 4030 KASSERT(exfer->ex_isdone);
4042#ifdef DIAGNOSTIC 4031#ifdef DIAGNOSTIC
4043 if (!exfer->ex_isdone) { 4032 exfer->ex_isdone = false;
4044 USBHIST_LOG(ehcidebug, "marked not done, ex = %p", 
4045 exfer, 0, 0, 0); 
4046 printf("ehci_device_intr_done: not done, ex=%p\n", 
4047 exfer); 
4048 } 
4049 exfer->ex_isdone = 0; 
4050#endif 4033#endif
4051 4034
4052 ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */ 4035 ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */
4053 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { 4036 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) {
4054 callout_reset(&xfer->ux_callout, 4037 callout_reset(&xfer->ux_callout,
4055 mstohz(xfer->ux_timeout), ehci_timeout, xfer); 4038 mstohz(xfer->ux_timeout), ehci_timeout, xfer);
4056 } 4039 }
4057 4040
4058 xfer->ux_status = USBD_IN_PROGRESS; 4041 xfer->ux_status = USBD_IN_PROGRESS;
4059 } else if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { 4042 } else if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) {
4060 ehci_del_intr_list(sc, ex); /* remove from active list */ 4043 ehci_del_intr_list(sc, ex); /* remove from active list */
4061 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); 4044 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL);
4062 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; 4045 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
4063 isread = UE_GET_DIR(endpt) == UE_DIR_IN; 4046 isread = UE_GET_DIR(endpt) == UE_DIR_IN;
4064 usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, 4047 usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length,
4065 isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); 4048 isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
4066 } 4049 }
4067#undef exfer 4050#undef exfer
4068} 4051}
4069 4052
4070/************************/ 4053/************************/
4071 4054
4072Static usbd_status 4055Static usbd_status
4073ehci_device_fs_isoc_transfer(usbd_xfer_handle xfer) 4056ehci_device_fs_isoc_transfer(usbd_xfer_handle xfer)
4074{ 4057{
4075 usbd_status err; 4058 usbd_status err;
4076 4059
4077 err = usb_insert_transfer(xfer); 4060 err = usb_insert_transfer(xfer);
4078 if (err && err != USBD_IN_PROGRESS) 4061 if (err && err != USBD_IN_PROGRESS)
4079 return err; 4062 return err;
4080 4063
4081 return ehci_device_fs_isoc_start(xfer); 4064 return ehci_device_fs_isoc_start(xfer);
4082} 4065}
4083 4066
4084Static usbd_status 4067Static usbd_status
4085ehci_device_fs_isoc_start(usbd_xfer_handle xfer) 4068ehci_device_fs_isoc_start(usbd_xfer_handle xfer)
4086{ 4069{
4087 struct ehci_pipe *epipe; 4070 struct ehci_pipe *epipe;
4088 usbd_device_handle dev; 4071 usbd_device_handle dev;
4089 ehci_softc_t *sc; 4072 ehci_softc_t *sc;
4090 struct ehci_xfer *exfer; 4073 struct ehci_xfer *exfer;
4091 ehci_soft_sitd_t *sitd, *prev, *start, *stop; 4074 ehci_soft_sitd_t *sitd, *prev, *start, *stop;
4092 usb_dma_t *dma_buf; 4075 usb_dma_t *dma_buf;
4093 int i, j, k, frames; 4076 int i, j, k, frames;
4094 int offs, total_length; 4077 int offs, total_length;
4095 int frindex; 4078 int frindex;
4096 u_int huba, dir; 4079 u_int huba, dir;
4097 4080
4098 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 4081 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
4099 4082
4100 start = NULL; 4083 start = NULL;
4101 prev = NULL; 4084 prev = NULL;
4102 sitd = NULL; 4085 sitd = NULL;
4103 total_length = 0; 4086 total_length = 0;
4104 exfer = (struct ehci_xfer *) xfer; 4087 exfer = (struct ehci_xfer *) xfer;
4105 sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 4088 sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
4106 dev = xfer->ux_pipe->up_dev; 4089 dev = xfer->ux_pipe->up_dev;
4107 epipe = (struct ehci_pipe *)xfer->ux_pipe; 4090 epipe = (struct ehci_pipe *)xfer->ux_pipe;
4108 4091
4109 /* 4092 /*
4110 * To allow continuous transfers, above we start all transfers 4093 * To allow continuous transfers, above we start all transfers
4111 * immediately. However, we're still going to get usbd_start_next call 4094 * immediately. However, we're still going to get usbd_start_next call
4112 * this when another xfer completes. So, check if this is already 4095 * this when another xfer completes. So, check if this is already
4113 * in progress or not 4096 * in progress or not
4114 */ 4097 */
4115 4098
4116 if (exfer->ex_sitdstart != NULL) 4099 if (exfer->ex_sitdstart != NULL)
4117 return USBD_IN_PROGRESS; 4100 return USBD_IN_PROGRESS;
4118 4101
4119 USBHIST_LOG(ehcidebug, "xfer %p len %d flags %d", 4102 USBHIST_LOG(ehcidebug, "xfer %p len %d flags %d",
4120 xfer, xfer->ux_length, xfer->ux_flags, 0); 4103 xfer, xfer->ux_length, xfer->ux_flags, 0);
4121 4104
4122 if (sc->sc_dying) 4105 if (sc->sc_dying)
4123 return USBD_IOERROR; 4106 return USBD_IOERROR;
4124 4107
4125 /* 4108 /*
4126 * To avoid complication, don't allow a request right now that'll span 4109 * To avoid complication, don't allow a request right now that'll span
4127 * the entire frame table. To within 4 frames, to allow some leeway 4110 * the entire frame table. To within 4 frames, to allow some leeway
4128 * on either side of where the hc currently is. 4111 * on either side of where the hc currently is.
4129 */ 4112 */
4130 if (epipe->pipe.up_endpoint->ue_edesc->bInterval * 4113 if (epipe->pipe.up_endpoint->ue_edesc->bInterval *
4131 xfer->ux_nframes >= sc->sc_flsize - 4) { 4114 xfer->ux_nframes >= sc->sc_flsize - 4) {
4132 printf("ehci: isoc descriptor requested that spans the entire" 4115 printf("ehci: isoc descriptor requested that spans the entire"
4133 "frametable, too many frames\n"); 4116 "frametable, too many frames\n");
4134 return USBD_INVAL; 4117 return USBD_INVAL;
4135 } 4118 }
4136 4119
4137 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); 4120 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST));
 4121 KASSERT(exfer->ex_isdone);
4138 4122
4139#ifdef DIAGNOSTIC 4123#ifdef DIAGNOSTIC
4140 if (!exfer->ex_isdone) 4124 exfer->ex_isdone = false;
4141 printf("ehci_device_fs_isoc_start: not done, ex = %p\n", exfer); 
4142 exfer->ex_isdone = 0; 
4143#endif 4125#endif
4144 4126
4145 /* 4127 /*
4146 * Step 1: Allocate and initialize sitds. 4128 * Step 1: Allocate and initialize sitds.
4147 */ 4129 */
4148 4130
4149 i = epipe->pipe.up_endpoint->ue_edesc->bInterval; 4131 i = epipe->pipe.up_endpoint->ue_edesc->bInterval;
4150 if (i > 16 || i == 0) { 4132 if (i > 16 || i == 0) {
4151 /* Spec page 271 says intervals > 16 are invalid */ 4133 /* Spec page 271 says intervals > 16 are invalid */
4152 USBHIST_LOG(ehcidebug, "bInterval %d invalid", 0, 0, 0, 0); 4134 USBHIST_LOG(ehcidebug, "bInterval %d invalid", 0, 0, 0, 0);
4153 4135
4154 return USBD_INVAL; 4136 return USBD_INVAL;
4155 } 4137 }
4156 4138
4157 frames = xfer->ux_nframes; 4139 frames = xfer->ux_nframes;
4158 4140
4159 if (frames == 0) { 4141 if (frames == 0) {
4160 USBHIST_LOG(ehcidebug, "frames == 0", 0, 0, 0, 0); 4142 USBHIST_LOG(ehcidebug, "frames == 0", 0, 0, 0, 0);
4161 4143
4162 return USBD_INVAL; 4144 return USBD_INVAL;
4163 } 4145 }
4164 4146
4165 dma_buf = &xfer->ux_dmabuf; 4147 dma_buf = &xfer->ux_dmabuf;
4166 offs = 0; 4148 offs = 0;
4167 4149
4168 for (i = 0; i < frames; i++) { 4150 for (i = 0; i < frames; i++) {
4169 sitd = ehci_alloc_sitd(sc); 4151 sitd = ehci_alloc_sitd(sc);
4170 4152
4171 if (prev) 4153 if (prev)
4172 prev->xfer_next = sitd; 4154 prev->xfer_next = sitd;
4173 else 4155 else
4174 start = sitd; 4156 start = sitd;
4175 4157
4176#ifdef DIAGNOSTIC 4158#ifdef DIAGNOSTIC
4177 if (xfer->ux_frlengths[i] > 0x3ff) { 4159 if (xfer->ux_frlengths[i] > 0x3ff) {
4178 printf("ehci: invalid frame length\n"); 4160 printf("ehci: invalid frame length\n");
4179 xfer->ux_frlengths[i] = 0x3ff; 4161 xfer->ux_frlengths[i] = 0x3ff;
4180 } 4162 }
4181#endif 4163#endif
4182 4164
4183 sitd->sitd.sitd_trans = htole32(EHCI_SITD_ACTIVE | 4165 sitd->sitd.sitd_trans = htole32(EHCI_SITD_ACTIVE |
4184 EHCI_SITD_SET_LEN(xfer->ux_frlengths[i])); 4166 EHCI_SITD_SET_LEN(xfer->ux_frlengths[i]));
4185 4167
4186 /* Set page0 index and offset. */ 4168 /* Set page0 index and offset. */
4187 sitd->sitd.sitd_buffer[0] = htole32(DMAADDR(dma_buf, offs)); 4169 sitd->sitd.sitd_buffer[0] = htole32(DMAADDR(dma_buf, offs));
4188 4170
4189 total_length += xfer->ux_frlengths[i]; 4171 total_length += xfer->ux_frlengths[i];
4190 offs += xfer->ux_frlengths[i]; 4172 offs += xfer->ux_frlengths[i];
4191 4173
4192 sitd->sitd.sitd_buffer[1] = 4174 sitd->sitd.sitd_buffer[1] =
4193 htole32(EHCI_SITD_SET_BPTR(DMAADDR(dma_buf, offs - 1))); 4175 htole32(EHCI_SITD_SET_BPTR(DMAADDR(dma_buf, offs - 1)));
4194 4176
4195 huba = dev->ud_myhsport->up_parent->ud_addr; 4177 huba = dev->ud_myhsport->up_parent->ud_addr;
4196 4178
4197/* if (sc->sc_flags & EHCIF_FREESCALE) { 4179/* if (sc->sc_flags & EHCIF_FREESCALE) {
4198 // Set hub address to 0 if embedded TT is used. 4180 // Set hub address to 0 if embedded TT is used.
4199 if (huba == sc->sc_addr) 4181 if (huba == sc->sc_addr)
4200 huba = 0; 4182 huba = 0;
4201 } 4183 }
4202*/ 4184*/
4203 4185
4204 k = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; 4186 k = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
4205 dir = UE_GET_DIR(k) ? 1 : 0; 4187 dir = UE_GET_DIR(k) ? 1 : 0;
4206 sitd->sitd.sitd_endp = 4188 sitd->sitd.sitd_endp =
4207 htole32(EHCI_SITD_SET_ENDPT(UE_GET_ADDR(k)) | 4189 htole32(EHCI_SITD_SET_ENDPT(UE_GET_ADDR(k)) |
4208 EHCI_SITD_SET_DADDR(dev->ud_addr) | 4190 EHCI_SITD_SET_DADDR(dev->ud_addr) |
4209 EHCI_SITD_SET_PORT(dev->ud_myhsport->up_portno) | 4191 EHCI_SITD_SET_PORT(dev->ud_myhsport->up_portno) |
4210 EHCI_SITD_SET_HUBA(huba) | 4192 EHCI_SITD_SET_HUBA(huba) |
4211 EHCI_SITD_SET_DIR(dir)); 4193 EHCI_SITD_SET_DIR(dir));
4212 4194
4213 sitd->sitd.sitd_back = htole32(EHCI_LINK_TERMINATE); 4195 sitd->sitd.sitd_back = htole32(EHCI_LINK_TERMINATE);
4214 4196
4215 /* XXX */ 4197 /* XXX */
4216 u_char sa, sb; 4198 u_char sa, sb;
4217 u_int temp, tlen; 4199 u_int temp, tlen;
4218 sa = 0; 4200 sa = 0;
4219 4201
4220 if (dir == 0) { /* OUT */ 4202 if (dir == 0) { /* OUT */
4221 temp = 0; 4203 temp = 0;
4222 tlen = xfer->ux_frlengths[i]; 4204 tlen = xfer->ux_frlengths[i];
4223 if (tlen <= 188) { 4205 if (tlen <= 188) {
4224 temp |= 1; /* T-count = 1, TP = ALL */ 4206 temp |= 1; /* T-count = 1, TP = ALL */
4225 tlen = 1; 4207 tlen = 1;
4226 } else { 4208 } else {
4227 tlen += 187; 4209 tlen += 187;
4228 tlen /= 188; 4210 tlen /= 188;
4229 temp |= tlen; /* T-count = [1..6] */ 4211 temp |= tlen; /* T-count = [1..6] */
4230 temp |= 8; /* TP = Begin */ 4212 temp |= 8; /* TP = Begin */
4231 } 4213 }
4232 sitd->sitd.sitd_buffer[1] |= htole32(temp); 4214 sitd->sitd.sitd_buffer[1] |= htole32(temp);
4233 4215
4234 tlen += sa; 4216 tlen += sa;
4235 4217
4236 if (tlen >= 8) { 4218 if (tlen >= 8) {
4237 sb = 0; 4219 sb = 0;
4238 } else { 4220 } else {
4239 sb = (1 << tlen); 4221 sb = (1 << tlen);
4240 } 4222 }
4241 4223
4242 sa = (1 << sa); 4224 sa = (1 << sa);
4243 sa = (sb - sa) & 0x3F; 4225 sa = (sb - sa) & 0x3F;
4244 sb = 0; 4226 sb = 0;
4245 } else { 4227 } else {
4246 sb = (-(4 << sa)) & 0xFE; 4228 sb = (-(4 << sa)) & 0xFE;
4247 sa = (1 << sa) & 0x3F; 4229 sa = (1 << sa) & 0x3F;
4248 sa = 0x01; 4230 sa = 0x01;
4249 sb = 0xfc; 4231 sb = 0xfc;
4250 } 4232 }
4251 4233
4252 sitd->sitd.sitd_sched = htole32(EHCI_SITD_SET_SMASK(sa) | 4234 sitd->sitd.sitd_sched = htole32(EHCI_SITD_SET_SMASK(sa) |
4253 EHCI_SITD_SET_CMASK(sb)); 4235 EHCI_SITD_SET_CMASK(sb));
4254 4236
4255 prev = sitd; 4237 prev = sitd;
4256 } /* End of frame */ 4238 } /* End of frame */
4257 4239
4258 sitd->sitd.sitd_trans |= htole32(EHCI_SITD_IOC); 4240 sitd->sitd.sitd_trans |= htole32(EHCI_SITD_IOC);
4259 4241
4260 stop = sitd; 4242 stop = sitd;
4261 stop->xfer_next = NULL; 4243 stop->xfer_next = NULL;
4262 4244
4263 usb_syncmem(&exfer->ex_xfer.ux_dmabuf, 0, total_length, 4245 usb_syncmem(&exfer->ex_xfer.ux_dmabuf, 0, total_length,
4264 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); 4246 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
4265 4247
4266 /* 4248 /*
4267 * Part 2: Transfer descriptors have now been set up, now they must 4249 * Part 2: Transfer descriptors have now been set up, now they must
4268 * be scheduled into the periodic frame list. Erk. Not wanting to 4250 * be scheduled into the periodic frame list. Erk. Not wanting to
4269 * complicate matters, transfer is denied if the transfer spans 4251 * complicate matters, transfer is denied if the transfer spans
4270 * more than the period frame list. 4252 * more than the period frame list.
4271 */ 4253 */
4272 4254
4273 mutex_enter(&sc->sc_lock); 4255 mutex_enter(&sc->sc_lock);
4274 4256
4275 /* Start inserting frames */ 4257 /* Start inserting frames */
4276 if (epipe->u.isoc.cur_xfers > 0) { 4258 if (epipe->u.isoc.cur_xfers > 0) {
4277 frindex = epipe->u.isoc.next_frame; 4259 frindex = epipe->u.isoc.next_frame;
4278 } else { 4260 } else {
4279 frindex = EOREAD4(sc, EHCI_FRINDEX); 4261 frindex = EOREAD4(sc, EHCI_FRINDEX);
4280 frindex = frindex >> 3; /* Erase microframe index */ 4262 frindex = frindex >> 3; /* Erase microframe index */
4281 frindex += 2; 4263 frindex += 2;
4282 } 4264 }
4283 4265
4284 if (frindex >= sc->sc_flsize) 4266 if (frindex >= sc->sc_flsize)
4285 frindex &= (sc->sc_flsize - 1); 4267 frindex &= (sc->sc_flsize - 1);
4286 4268
4287 /* Whats the frame interval? */ 4269 /* Whats the frame interval? */
4288 i = epipe->pipe.up_endpoint->ue_edesc->bInterval; 4270 i = epipe->pipe.up_endpoint->ue_edesc->bInterval;
4289 4271
4290 sitd = start; 4272 sitd = start;
4291 for (j = 0; j < frames; j++) { 4273 for (j = 0; j < frames; j++) {
4292 if (sitd == NULL) 4274 if (sitd == NULL)
4293 panic("ehci: unexpectedly ran out of isoc sitds\n"); 4275 panic("ehci: unexpectedly ran out of isoc sitds\n");
4294 4276
4295 sitd->sitd.sitd_next = sc->sc_flist[frindex]; 4277 sitd->sitd.sitd_next = sc->sc_flist[frindex];
4296 if (sitd->sitd.sitd_next == 0) 4278 if (sitd->sitd.sitd_next == 0)
4297 /* FIXME: frindex table gets initialized to NULL 4279 /* FIXME: frindex table gets initialized to NULL
4298 * or EHCI_NULL? */ 4280 * or EHCI_NULL? */
4299 sitd->sitd.sitd_next = EHCI_NULL; 4281 sitd->sitd.sitd_next = EHCI_NULL;
4300 4282
4301 usb_syncmem(&sitd->dma, 4283 usb_syncmem(&sitd->dma,
4302 sitd->offs + offsetof(ehci_sitd_t, sitd_next), 4284 sitd->offs + offsetof(ehci_sitd_t, sitd_next),
4303 sizeof(ehci_sitd_t), 4285 sizeof(ehci_sitd_t),
4304 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 4286 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
4305 4287
4306 sc->sc_flist[frindex] = 4288 sc->sc_flist[frindex] =
4307 htole32(EHCI_LINK_SITD | sitd->physaddr); 4289 htole32(EHCI_LINK_SITD | sitd->physaddr);
4308 4290
4309 usb_syncmem(&sc->sc_fldma, 4291 usb_syncmem(&sc->sc_fldma,
4310 sizeof(ehci_link_t) * frindex, 4292 sizeof(ehci_link_t) * frindex,
4311 sizeof(ehci_link_t), 4293 sizeof(ehci_link_t),
4312 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 4294 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
4313 4295
4314 sitd->u.frame_list.next = sc->sc_softsitds[frindex]; 4296 sitd->u.frame_list.next = sc->sc_softsitds[frindex];
4315 sc->sc_softsitds[frindex] = sitd; 4297 sc->sc_softsitds[frindex] = sitd;
4316 if (sitd->u.frame_list.next != NULL) 4298 if (sitd->u.frame_list.next != NULL)
4317 sitd->u.frame_list.next->u.frame_list.prev = sitd; 4299 sitd->u.frame_list.next->u.frame_list.prev = sitd;
4318 sitd->slot = frindex; 4300 sitd->slot = frindex;
4319 sitd->u.frame_list.prev = NULL; 4301 sitd->u.frame_list.prev = NULL;
4320 4302
4321 frindex += i; 4303 frindex += i;
4322 if (frindex >= sc->sc_flsize) 4304 if (frindex >= sc->sc_flsize)
4323 frindex -= sc->sc_flsize; 4305 frindex -= sc->sc_flsize;
4324 4306
4325 sitd = sitd->xfer_next; 4307 sitd = sitd->xfer_next;
4326 } 4308 }
4327 4309
4328 epipe->u.isoc.cur_xfers++; 4310 epipe->u.isoc.cur_xfers++;
4329 epipe->u.isoc.next_frame = frindex; 4311 epipe->u.isoc.next_frame = frindex;
4330 4312
4331 exfer->ex_sitdstart = start; 4313 exfer->ex_sitdstart = start;
4332 exfer->ex_sitdend = stop; 4314 exfer->ex_sitdend = stop;
4333 4315
4334 ehci_add_intr_list(sc, exfer); 4316 ehci_add_intr_list(sc, exfer);
4335 xfer->ux_status = USBD_IN_PROGRESS; 4317 xfer->ux_status = USBD_IN_PROGRESS;
4336 xfer->ux_done = 0; 4318 xfer->ux_done = 0;
4337 4319
4338 mutex_exit(&sc->sc_lock); 4320 mutex_exit(&sc->sc_lock);
4339 4321
4340 if (sc->sc_bus.ub_usepolling) { 4322 if (sc->sc_bus.ub_usepolling) {
4341 printf("Starting ehci isoc xfer with polling. Bad idea?\n"); 4323 printf("Starting ehci isoc xfer with polling. Bad idea?\n");
4342 ehci_waitintr(sc, xfer); 4324 ehci_waitintr(sc, xfer);
4343 } 4325 }
4344 4326
4345 return USBD_IN_PROGRESS; 4327 return USBD_IN_PROGRESS;
4346} 4328}
4347 4329
4348Static void 4330Static void
4349ehci_device_fs_isoc_abort(usbd_xfer_handle xfer) 4331ehci_device_fs_isoc_abort(usbd_xfer_handle xfer)
4350{ 4332{
4351 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 4333 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
4352 4334
4353 USBHIST_LOG(ehcidebug, "xfer = %p", xfer, 0, 0, 0); 4335 USBHIST_LOG(ehcidebug, "xfer = %p", xfer, 0, 0, 0);
4354 ehci_abort_isoc_xfer(xfer, USBD_CANCELLED); 4336 ehci_abort_isoc_xfer(xfer, USBD_CANCELLED);
4355} 4337}
4356 4338
4357Static void 4339Static void
4358ehci_device_fs_isoc_close(usbd_pipe_handle pipe) 4340ehci_device_fs_isoc_close(usbd_pipe_handle pipe)
4359{ 4341{
4360 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 4342 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
4361 4343
4362 USBHIST_LOG(ehcidebug, "nothing in the pipe to free?", 0, 0, 0, 0); 4344 USBHIST_LOG(ehcidebug, "nothing in the pipe to free?", 0, 0, 0, 0);
4363} 4345}
4364 4346
4365Static void 4347Static void
4366ehci_device_fs_isoc_done(usbd_xfer_handle xfer) 4348ehci_device_fs_isoc_done(usbd_xfer_handle xfer)
4367{ 4349{
4368 struct ehci_xfer *exfer; 4350 struct ehci_xfer *exfer;
4369 ehci_softc_t *sc; 4351 ehci_softc_t *sc;
4370 struct ehci_pipe *epipe; 4352 struct ehci_pipe *epipe;
4371 4353
4372 exfer = EXFER(xfer); 4354 exfer = EXFER(xfer);
4373 sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 4355 sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
4374 epipe = (struct ehci_pipe *) xfer->ux_pipe; 4356 epipe = (struct ehci_pipe *) xfer->ux_pipe;
4375 4357
4376 KASSERT(mutex_owned(&sc->sc_lock)); 4358 KASSERT(mutex_owned(&sc->sc_lock));
4377 4359
4378 epipe->u.isoc.cur_xfers--; 4360 epipe->u.isoc.cur_xfers--;
4379 if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(exfer)) { 4361 if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(exfer)) {
4380 ehci_del_intr_list(sc, exfer); 4362 ehci_del_intr_list(sc, exfer);
4381 ehci_rem_free_sitd_chain(sc, exfer); 4363 ehci_rem_free_sitd_chain(sc, exfer);
4382 } 4364 }
4383 4365
4384 usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, BUS_DMASYNC_POSTWRITE | 4366 usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, BUS_DMASYNC_POSTWRITE |
4385 BUS_DMASYNC_POSTREAD); 4367 BUS_DMASYNC_POSTREAD);
4386} 4368}
4387Static usbd_status 4369Static usbd_status
4388ehci_device_isoc_transfer(usbd_xfer_handle xfer) 4370ehci_device_isoc_transfer(usbd_xfer_handle xfer)
4389{ 4371{
4390 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 4372 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
4391 usbd_status err; 4373 usbd_status err;
4392 4374
4393 mutex_enter(&sc->sc_lock); 4375 mutex_enter(&sc->sc_lock);
4394 err = usb_insert_transfer(xfer); 4376 err = usb_insert_transfer(xfer);
4395 mutex_exit(&sc->sc_lock); 4377 mutex_exit(&sc->sc_lock);
4396 if (err && err != USBD_IN_PROGRESS) 4378 if (err && err != USBD_IN_PROGRESS)
4397 return err; 4379 return err;
4398 4380
4399 return ehci_device_isoc_start(xfer); 4381 return ehci_device_isoc_start(xfer);
4400} 4382}
4401 4383
4402Static usbd_status 4384Static usbd_status
4403ehci_device_isoc_start(usbd_xfer_handle xfer) 4385ehci_device_isoc_start(usbd_xfer_handle xfer)
4404{ 4386{
4405 struct ehci_pipe *epipe; 4387 struct ehci_pipe *epipe;
4406 ehci_softc_t *sc; 4388 ehci_softc_t *sc;
4407 struct ehci_xfer *exfer; 4389 struct ehci_xfer *exfer;
4408 ehci_soft_itd_t *itd, *prev, *start, *stop; 4390 ehci_soft_itd_t *itd, *prev, *start, *stop;
4409 usb_dma_t *dma_buf; 4391 usb_dma_t *dma_buf;
4410 int i, j, k, frames, uframes, ufrperframe; 4392 int i, j, k, frames, uframes, ufrperframe;
4411 int trans_count, offs, total_length; 4393 int trans_count, offs, total_length;
4412 int frindex; 4394 int frindex;
4413 4395
4414 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 4396 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
4415 4397
4416 start = NULL; 4398 start = NULL;
4417 prev = NULL; 4399 prev = NULL;
4418 itd = NULL; 4400 itd = NULL;
4419 trans_count = 0; 4401 trans_count = 0;
4420 total_length = 0; 4402 total_length = 0;
4421 exfer = (struct ehci_xfer *) xfer; 4403 exfer = (struct ehci_xfer *) xfer;
4422 sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 4404 sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
4423 epipe = (struct ehci_pipe *)xfer->ux_pipe; 4405 epipe = (struct ehci_pipe *)xfer->ux_pipe;
4424 4406
4425 /* 4407 /*
4426 * To allow continuous transfers, above we start all transfers 4408 * To allow continuous transfers, above we start all transfers
4427 * immediately. However, we're still going to get usbd_start_next call 4409 * immediately. However, we're still going to get usbd_start_next call
4428 * this when another xfer completes. So, check if this is already 4410 * this when another xfer completes. So, check if this is already
4429 * in progress or not 4411 * in progress or not
4430 */ 4412 */
4431 4413
4432 if (exfer->ex_itdstart != NULL) 4414 if (exfer->ex_itdstart != NULL)
4433 return USBD_IN_PROGRESS; 4415 return USBD_IN_PROGRESS;
4434 4416
4435 USBHIST_LOG(ehcidebug, "xfer %p len %d flags %d", 4417 USBHIST_LOG(ehcidebug, "xfer %p len %d flags %d",
4436 xfer, xfer->ux_length, xfer->ux_flags, 0); 4418 xfer, xfer->ux_length, xfer->ux_flags, 0);
4437 4419
4438 if (sc->sc_dying) 4420 if (sc->sc_dying)
4439 return USBD_IOERROR; 4421 return USBD_IOERROR;
4440 4422
4441 /* 4423 /*
4442 * To avoid complication, don't allow a request right now that'll span 4424 * To avoid complication, don't allow a request right now that'll span
4443 * the entire frame table. To within 4 frames, to allow some leeway 4425 * the entire frame table. To within 4 frames, to allow some leeway
4444 * on either side of where the hc currently is. 4426 * on either side of where the hc currently is.
4445 */ 4427 */
4446 if ((1 << (epipe->pipe.up_endpoint->ue_edesc->bInterval)) * 4428 if ((1 << (epipe->pipe.up_endpoint->ue_edesc->bInterval)) *
4447 xfer->ux_nframes >= (sc->sc_flsize - 4) * 8) { 4429 xfer->ux_nframes >= (sc->sc_flsize - 4) * 8) {
4448 USBHIST_LOG(ehcidebug, 4430 USBHIST_LOG(ehcidebug,
4449 "isoc descriptor spans entire frametable", 0, 0, 0, 0); 4431 "isoc descriptor spans entire frametable", 0, 0, 0, 0);
4450 printf("ehci: isoc descriptor requested that spans the entire frametable, too many frames\n"); 4432 printf("ehci: isoc descriptor requested that spans the entire frametable, too many frames\n");
4451 return USBD_INVAL; 4433 return USBD_INVAL;
4452 } 4434 }
4453 4435
4454 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); 4436 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST));
4455 4437 KASSERT(exfer->ex_isdone);
4456#ifdef DIAGNOSTIC 4438#ifdef DIAGNOSTIC
4457 if (!exfer->ex_isdone) { 4439 exfer->ex_isdone = false;
4458 USBHIST_LOG(ehcidebug, "marked not done, ex = %p", exfer, 
4459 0, 0, 0); 
4460 printf("ehci_device_isoc_start: not done, ex = %p\n", exfer); 
4461 } 
4462 exfer->ex_isdone = 0; 
4463#endif 4440#endif
4464 4441
4465 /* 4442 /*
4466 * Step 1: Allocate and initialize itds, how many do we need? 4443 * Step 1: Allocate and initialize itds, how many do we need?
4467 * One per transfer if interval >= 8 microframes, fewer if we use 4444 * One per transfer if interval >= 8 microframes, fewer if we use
4468 * multiple microframes per frame. 4445 * multiple microframes per frame.
4469 */ 4446 */
4470 4447
4471 i = epipe->pipe.up_endpoint->ue_edesc->bInterval; 4448 i = epipe->pipe.up_endpoint->ue_edesc->bInterval;
4472 if (i > 16 || i == 0) { 4449 if (i > 16 || i == 0) {
4473 /* Spec page 271 says intervals > 16 are invalid */ 4450 /* Spec page 271 says intervals > 16 are invalid */
4474 USBHIST_LOG(ehcidebug, "bInterval %d invalid", i, 0, 0, 0); 4451 USBHIST_LOG(ehcidebug, "bInterval %d invalid", i, 0, 0, 0);
4475 return USBD_INVAL; 4452 return USBD_INVAL;
4476 } 4453 }
4477 4454
4478 ufrperframe = max(1, USB_UFRAMES_PER_FRAME / (1 << (i - 1))); 4455 ufrperframe = max(1, USB_UFRAMES_PER_FRAME / (1 << (i - 1)));
4479 frames = (xfer->ux_nframes + (ufrperframe - 1)) / ufrperframe; 4456 frames = (xfer->ux_nframes + (ufrperframe - 1)) / ufrperframe;
4480 uframes = USB_UFRAMES_PER_FRAME / ufrperframe; 4457 uframes = USB_UFRAMES_PER_FRAME / ufrperframe;
4481 4458
4482 if (frames == 0) { 4459 if (frames == 0) {
4483 USBHIST_LOG(ehcidebug, "frames == 0", 0, 0, 0, 0); 4460 USBHIST_LOG(ehcidebug, "frames == 0", 0, 0, 0, 0);
4484 return USBD_INVAL; 4461 return USBD_INVAL;
4485 } 4462 }
4486 4463
4487 dma_buf = &xfer->ux_dmabuf; 4464 dma_buf = &xfer->ux_dmabuf;
4488 offs = 0; 4465 offs = 0;
4489 4466
4490 for (i = 0; i < frames; i++) { 4467 for (i = 0; i < frames; i++) {
4491 int froffs = offs; 4468 int froffs = offs;
4492 itd = ehci_alloc_itd(sc); 4469 itd = ehci_alloc_itd(sc);
4493 4470
4494 if (prev != NULL) { 4471 if (prev != NULL) {
4495 prev->itd.itd_next = 4472 prev->itd.itd_next =
4496 htole32(itd->physaddr | EHCI_LINK_ITD); 4473 htole32(itd->physaddr | EHCI_LINK_ITD);
4497 usb_syncmem(&itd->dma, 4474 usb_syncmem(&itd->dma,
4498 itd->offs + offsetof(ehci_itd_t, itd_next), 4475 itd->offs + offsetof(ehci_itd_t, itd_next),
4499 sizeof(itd->itd.itd_next), BUS_DMASYNC_POSTWRITE); 4476 sizeof(itd->itd.itd_next), BUS_DMASYNC_POSTWRITE);
4500 4477
4501 prev->xfer_next = itd; 4478 prev->xfer_next = itd;
4502 } else { 4479 } else {
4503 start = itd; 4480 start = itd;
4504 } 4481 }
4505 4482
4506 /* 4483 /*
4507 * Step 1.5, initialize uframes 4484 * Step 1.5, initialize uframes
4508 */ 4485 */
4509 for (j = 0; j < EHCI_ITD_NUFRAMES; j += uframes) { 4486 for (j = 0; j < EHCI_ITD_NUFRAMES; j += uframes) {
4510 /* Calculate which page in the list this starts in */ 4487 /* Calculate which page in the list this starts in */
4511 int addr = DMAADDR(dma_buf, froffs); 4488 int addr = DMAADDR(dma_buf, froffs);
4512 addr = EHCI_PAGE_OFFSET(addr); 4489 addr = EHCI_PAGE_OFFSET(addr);
4513 addr += (offs - froffs); 4490 addr += (offs - froffs);
4514 addr = EHCI_PAGE(addr); 4491 addr = EHCI_PAGE(addr);
4515 addr /= EHCI_PAGE_SIZE; 4492 addr /= EHCI_PAGE_SIZE;
4516 4493
4517 /* 4494 /*
4518 * This gets the initial offset into the first page, 4495 * This gets the initial offset into the first page,
4519 * looks how far further along the current uframe 4496 * looks how far further along the current uframe
4520 * offset is. Works out how many pages that is. 4497 * offset is. Works out how many pages that is.
4521 */ 4498 */
4522 4499
4523 itd->itd.itd_ctl[j] = htole32 ( EHCI_ITD_ACTIVE | 4500 itd->itd.itd_ctl[j] = htole32 ( EHCI_ITD_ACTIVE |
4524 EHCI_ITD_SET_LEN(xfer->ux_frlengths[trans_count]) | 4501 EHCI_ITD_SET_LEN(xfer->ux_frlengths[trans_count]) |
4525 EHCI_ITD_SET_PG(addr) | 4502 EHCI_ITD_SET_PG(addr) |
4526 EHCI_ITD_SET_OFFS(EHCI_PAGE_OFFSET(DMAADDR(dma_buf,offs)))); 4503 EHCI_ITD_SET_OFFS(EHCI_PAGE_OFFSET(DMAADDR(dma_buf,offs))));
4527 4504
4528 total_length += xfer->ux_frlengths[trans_count]; 4505 total_length += xfer->ux_frlengths[trans_count];
4529 offs += xfer->ux_frlengths[trans_count]; 4506 offs += xfer->ux_frlengths[trans_count];
4530 trans_count++; 4507 trans_count++;
4531 4508
4532 if (trans_count >= xfer->ux_nframes) { /*Set IOC*/ 4509 if (trans_count >= xfer->ux_nframes) { /*Set IOC*/
4533 itd->itd.itd_ctl[j] |= htole32(EHCI_ITD_IOC); 4510 itd->itd.itd_ctl[j] |= htole32(EHCI_ITD_IOC);
4534 break; 4511 break;
4535 } 4512 }
4536 } 4513 }
4537 4514
4538 /* 4515 /*
4539 * Step 1.75, set buffer pointers. To simplify matters, all 4516 * Step 1.75, set buffer pointers. To simplify matters, all
4540 * pointers are filled out for the next 7 hardware pages in 4517 * pointers are filled out for the next 7 hardware pages in
4541 * the dma block, so no need to worry what pages to cover 4518 * the dma block, so no need to worry what pages to cover
4542 * and what to not. 4519 * and what to not.
4543 */ 4520 */
4544 4521
4545 for (j = 0; j < EHCI_ITD_NBUFFERS; j++) { 4522 for (j = 0; j < EHCI_ITD_NBUFFERS; j++) {
4546 /* 4523 /*
4547 * Don't try to lookup a page that's past the end 4524 * Don't try to lookup a page that's past the end
4548 * of buffer 4525 * of buffer
4549 */ 4526 */
4550 int page_offs = EHCI_PAGE(froffs + (EHCI_PAGE_SIZE * j)); 4527 int page_offs = EHCI_PAGE(froffs + (EHCI_PAGE_SIZE * j));
4551 if (page_offs >= dma_buf->udma_block->size) 4528 if (page_offs >= dma_buf->udma_block->size)
4552 break; 4529 break;
4553 4530
4554 unsigned long long page = DMAADDR(dma_buf, page_offs); 4531 unsigned long long page = DMAADDR(dma_buf, page_offs);
4555 page = EHCI_PAGE(page); 4532 page = EHCI_PAGE(page);
4556 itd->itd.itd_bufr[j] = 4533 itd->itd.itd_bufr[j] =
4557 htole32(EHCI_ITD_SET_BPTR(page)); 4534 htole32(EHCI_ITD_SET_BPTR(page));
4558 itd->itd.itd_bufr_hi[j] = 4535 itd->itd.itd_bufr_hi[j] =
4559 htole32(page >> 32); 4536 htole32(page >> 32);
4560 } 4537 }
4561 4538
4562 /* 4539 /*
4563 * Other special values 4540 * Other special values
4564 */ 4541 */
4565 4542
4566 k = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; 4543 k = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
4567 itd->itd.itd_bufr[0] |= htole32(EHCI_ITD_SET_EP(UE_GET_ADDR(k)) | 4544 itd->itd.itd_bufr[0] |= htole32(EHCI_ITD_SET_EP(UE_GET_ADDR(k)) |
4568 EHCI_ITD_SET_DADDR(epipe->pipe.up_dev->ud_addr)); 4545 EHCI_ITD_SET_DADDR(epipe->pipe.up_dev->ud_addr));
4569 4546
4570 k = (UE_GET_DIR(epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress)) 4547 k = (UE_GET_DIR(epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress))
4571 ? 1 : 0; 4548 ? 1 : 0;
4572 j = UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize); 4549 j = UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize);
4573 itd->itd.itd_bufr[1] |= htole32(EHCI_ITD_SET_DIR(k) | 4550 itd->itd.itd_bufr[1] |= htole32(EHCI_ITD_SET_DIR(k) |
4574 EHCI_ITD_SET_MAXPKT(UE_GET_SIZE(j))); 4551 EHCI_ITD_SET_MAXPKT(UE_GET_SIZE(j)));
4575 4552
4576 /* FIXME: handle invalid trans */ 4553 /* FIXME: handle invalid trans */
4577 itd->itd.itd_bufr[2] |= 4554 itd->itd.itd_bufr[2] |=
4578 htole32(EHCI_ITD_SET_MULTI(UE_GET_TRANS(j)+1)); 4555 htole32(EHCI_ITD_SET_MULTI(UE_GET_TRANS(j)+1));
4579 4556
4580 usb_syncmem(&itd->dma, 4557 usb_syncmem(&itd->dma,
4581 itd->offs + offsetof(ehci_itd_t, itd_next), 4558 itd->offs + offsetof(ehci_itd_t, itd_next),
4582 sizeof(ehci_itd_t), 4559 sizeof(ehci_itd_t),
4583 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 4560 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
4584 4561
4585 prev = itd; 4562 prev = itd;
4586 } /* End of frame */ 4563 } /* End of frame */
4587 4564
4588 stop = itd; 4565 stop = itd;
4589 stop->xfer_next = NULL; 4566 stop->xfer_next = NULL;
4590 4567
4591 usb_syncmem(&exfer->ex_xfer.ux_dmabuf, 0, total_length, 4568 usb_syncmem(&exfer->ex_xfer.ux_dmabuf, 0, total_length,
4592 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); 4569 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
4593 4570
4594 /* 4571 /*
4595 * Part 2: Transfer descriptors have now been set up, now they must 4572 * Part 2: Transfer descriptors have now been set up, now they must
4596 * be scheduled into the period frame list. Erk. Not wanting to 4573 * be scheduled into the period frame list. Erk. Not wanting to
4597 * complicate matters, transfer is denied if the transfer spans 4574 * complicate matters, transfer is denied if the transfer spans
4598 * more than the period frame list. 4575 * more than the period frame list.
4599 */ 4576 */
4600 4577
4601 mutex_enter(&sc->sc_lock); 4578 mutex_enter(&sc->sc_lock);
4602 4579
4603 /* Start inserting frames */ 4580 /* Start inserting frames */
4604 if (epipe->u.isoc.cur_xfers > 0) { 4581 if (epipe->u.isoc.cur_xfers > 0) {
4605 frindex = epipe->u.isoc.next_frame; 4582 frindex = epipe->u.isoc.next_frame;
4606 } else { 4583 } else {
4607 frindex = EOREAD4(sc, EHCI_FRINDEX); 4584 frindex = EOREAD4(sc, EHCI_FRINDEX);
4608 frindex = frindex >> 3; /* Erase microframe index */ 4585 frindex = frindex >> 3; /* Erase microframe index */
4609 frindex += 2; 4586 frindex += 2;
4610 } 4587 }
4611 4588
4612 if (frindex >= sc->sc_flsize) 4589 if (frindex >= sc->sc_flsize)
4613 frindex &= (sc->sc_flsize - 1); 4590 frindex &= (sc->sc_flsize - 1);
4614 4591
4615 /* What's the frame interval? */ 4592 /* What's the frame interval? */
4616 i = (1 << (epipe->pipe.up_endpoint->ue_edesc->bInterval - 1)); 4593 i = (1 << (epipe->pipe.up_endpoint->ue_edesc->bInterval - 1));
4617 if (i / USB_UFRAMES_PER_FRAME == 0) 4594 if (i / USB_UFRAMES_PER_FRAME == 0)
4618 i = 1; 4595 i = 1;
4619 else 4596 else
4620 i /= USB_UFRAMES_PER_FRAME; 4597 i /= USB_UFRAMES_PER_FRAME;
4621 4598
4622 itd = start; 4599 itd = start;
4623 for (j = 0; j < frames; j++) { 4600 for (j = 0; j < frames; j++) {
4624 if (itd == NULL) 4601 if (itd == NULL)
4625 panic("ehci: unexpectedly ran out of isoc itds, isoc_start\n"); 4602 panic("ehci: unexpectedly ran out of isoc itds, isoc_start\n");
4626 4603
4627 itd->itd.itd_next = sc->sc_flist[frindex]; 4604 itd->itd.itd_next = sc->sc_flist[frindex];
4628 if (itd->itd.itd_next == 0) 4605 if (itd->itd.itd_next == 0)
4629 /* FIXME: frindex table gets initialized to NULL 4606 /* FIXME: frindex table gets initialized to NULL
4630 * or EHCI_NULL? */ 4607 * or EHCI_NULL? */
4631 itd->itd.itd_next = EHCI_NULL; 4608 itd->itd.itd_next = EHCI_NULL;
4632 4609
4633 usb_syncmem(&itd->dma, 4610 usb_syncmem(&itd->dma,
4634 itd->offs + offsetof(ehci_itd_t, itd_next), 4611 itd->offs + offsetof(ehci_itd_t, itd_next),
4635 sizeof(itd->itd.itd_next), 4612 sizeof(itd->itd.itd_next),
4636 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 4613 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
4637 4614
4638 sc->sc_flist[frindex] = htole32(EHCI_LINK_ITD | itd->physaddr); 4615 sc->sc_flist[frindex] = htole32(EHCI_LINK_ITD | itd->physaddr);
4639 4616
4640 usb_syncmem(&sc->sc_fldma, 4617 usb_syncmem(&sc->sc_fldma,
4641 sizeof(ehci_link_t) * frindex, 4618 sizeof(ehci_link_t) * frindex,
4642 sizeof(ehci_link_t), 4619 sizeof(ehci_link_t),
4643 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 4620 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
4644 4621
4645 itd->u.frame_list.next = sc->sc_softitds[frindex]; 4622 itd->u.frame_list.next = sc->sc_softitds[frindex];
4646 sc->sc_softitds[frindex] = itd; 4623 sc->sc_softitds[frindex] = itd;
4647 if (itd->u.frame_list.next != NULL) 4624 if (itd->u.frame_list.next != NULL)
4648 itd->u.frame_list.next->u.frame_list.prev = itd; 4625 itd->u.frame_list.next->u.frame_list.prev = itd;
4649 itd->slot = frindex; 4626 itd->slot = frindex;
4650 itd->u.frame_list.prev = NULL; 4627 itd->u.frame_list.prev = NULL;
4651 4628
4652 frindex += i; 4629 frindex += i;
4653 if (frindex >= sc->sc_flsize) 4630 if (frindex >= sc->sc_flsize)
4654 frindex -= sc->sc_flsize; 4631 frindex -= sc->sc_flsize;
4655 4632
4656 itd = itd->xfer_next; 4633 itd = itd->xfer_next;
4657 } 4634 }
4658 4635
4659 epipe->u.isoc.cur_xfers++; 4636 epipe->u.isoc.cur_xfers++;
4660 epipe->u.isoc.next_frame = frindex; 4637 epipe->u.isoc.next_frame = frindex;
4661 4638
4662 exfer->ex_itdstart = start; 4639 exfer->ex_itdstart = start;
4663 exfer->ex_itdend = stop; 4640 exfer->ex_itdend = stop;
4664 4641
4665 ehci_add_intr_list(sc, exfer); 4642 ehci_add_intr_list(sc, exfer);
4666 xfer->ux_status = USBD_IN_PROGRESS; 4643 xfer->ux_status = USBD_IN_PROGRESS;
4667 xfer->ux_done = 0; 4644 xfer->ux_done = 0;
4668 mutex_exit(&sc->sc_lock); 4645 mutex_exit(&sc->sc_lock);
4669 4646
4670 if (sc->sc_bus.ub_usepolling) { 4647 if (sc->sc_bus.ub_usepolling) {
4671 printf("Starting ehci isoc xfer with polling. Bad idea?\n"); 4648 printf("Starting ehci isoc xfer with polling. Bad idea?\n");
4672 ehci_waitintr(sc, xfer); 4649 ehci_waitintr(sc, xfer);
4673 } 4650 }
4674 4651
4675 return USBD_IN_PROGRESS; 4652 return USBD_IN_PROGRESS;
4676} 4653}
4677 4654
4678Static void 4655Static void
4679ehci_device_isoc_abort(usbd_xfer_handle xfer) 4656ehci_device_isoc_abort(usbd_xfer_handle xfer)
4680{ 4657{
4681 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 4658 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
4682 4659
4683 USBHIST_LOG(ehcidebug, "xfer = %p", xfer, 0, 0, 0); 4660 USBHIST_LOG(ehcidebug, "xfer = %p", xfer, 0, 0, 0);
4684 ehci_abort_isoc_xfer(xfer, USBD_CANCELLED); 4661 ehci_abort_isoc_xfer(xfer, USBD_CANCELLED);
4685} 4662}
4686 4663
4687Static void 4664Static void
4688ehci_device_isoc_close(usbd_pipe_handle pipe) 4665ehci_device_isoc_close(usbd_pipe_handle pipe)
4689{ 4666{
4690 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 4667 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
4691 4668
4692 USBHIST_LOG(ehcidebug, "nothing in the pipe to free?", 0, 0, 0, 0); 4669 USBHIST_LOG(ehcidebug, "nothing in the pipe to free?", 0, 0, 0, 0);
4693} 4670}
4694 4671
4695Static void 4672Static void
4696ehci_device_isoc_done(usbd_xfer_handle xfer) 4673ehci_device_isoc_done(usbd_xfer_handle xfer)
4697{ 4674{
4698 struct ehci_xfer *exfer; 4675 struct ehci_xfer *exfer;
4699 ehci_softc_t *sc; 4676 ehci_softc_t *sc;
4700 struct ehci_pipe *epipe; 4677 struct ehci_pipe *epipe;
4701 4678
4702 exfer = EXFER(xfer); 4679 exfer = EXFER(xfer);
4703 sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 4680 sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
4704 epipe = (struct ehci_pipe *) xfer->ux_pipe; 4681 epipe = (struct ehci_pipe *) xfer->ux_pipe;
4705 4682
4706 KASSERT(mutex_owned(&sc->sc_lock)); 4683 KASSERT(mutex_owned(&sc->sc_lock));
4707 4684
4708 epipe->u.isoc.cur_xfers--; 4685 epipe->u.isoc.cur_xfers--;
4709 if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(exfer)) { 4686 if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(exfer)) {
4710 ehci_del_intr_list(sc, exfer); 4687 ehci_del_intr_list(sc, exfer);
4711 ehci_rem_free_itd_chain(sc, exfer); 4688 ehci_rem_free_itd_chain(sc, exfer);
4712 } 4689 }
4713 4690
4714 usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, BUS_DMASYNC_POSTWRITE | 4691 usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, BUS_DMASYNC_POSTWRITE |
4715 BUS_DMASYNC_POSTREAD); 4692 BUS_DMASYNC_POSTREAD);
4716 4693
4717} 4694}

cvs diff -r1.42.14.9 -r1.42.14.10 src/sys/dev/usb/ehcivar.h (switch to unified diff)

--- src/sys/dev/usb/ehcivar.h 2015/02/01 08:29:46 1.42.14.9
+++ src/sys/dev/usb/ehcivar.h 2015/03/02 21:52:02 1.42.14.10
@@ -1,224 +1,224 @@ @@ -1,224 +1,224 @@
1/* $NetBSD: ehcivar.h,v 1.42.14.9 2015/02/01 08:29:46 skrll Exp $ */ 1/* $NetBSD: ehcivar.h,v 1.42.14.10 2015/03/02 21:52:02 skrll Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 4 * Copyright (c) 2001 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). 8 * by Lennart Augustsson (lennart@augustsson.net).
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#ifndef _EHCIVAR_H_ 32#ifndef _EHCIVAR_H_
33#define _EHCIVAR_H_ 33#define _EHCIVAR_H_
34 34
35#include <sys/pool.h> 35#include <sys/pool.h>
36 36
37typedef struct ehci_soft_qtd { 37typedef struct ehci_soft_qtd {
38 ehci_qtd_t qtd; 38 ehci_qtd_t qtd;
39 struct ehci_soft_qtd *nextqtd; /* mirrors nextqtd in TD */ 39 struct ehci_soft_qtd *nextqtd; /* mirrors nextqtd in TD */
40 ehci_physaddr_t physaddr; 40 ehci_physaddr_t physaddr;
41 usb_dma_t dma; /* qTD's DMA infos */ 41 usb_dma_t dma; /* qTD's DMA infos */
42 int offs; /* qTD's offset in usb_dma_t */ 42 int offs; /* qTD's offset in usb_dma_t */
43 usbd_xfer_handle xfer; 43 usbd_xfer_handle xfer;
44 LIST_ENTRY(ehci_soft_qtd) hnext; 44 LIST_ENTRY(ehci_soft_qtd) hnext;
45 uint16_t len; 45 uint16_t len;
46} ehci_soft_qtd_t; 46} ehci_soft_qtd_t;
47#define EHCI_SQTD_ALIGN MAX(EHCI_QTD_ALIGN, CACHE_LINE_SIZE) 47#define EHCI_SQTD_ALIGN MAX(EHCI_QTD_ALIGN, CACHE_LINE_SIZE)
48#define EHCI_SQTD_SIZE ((sizeof(struct ehci_soft_qtd) + EHCI_SQTD_ALIGN - 1) & -EHCI_SQTD_ALIGN) 48#define EHCI_SQTD_SIZE ((sizeof(struct ehci_soft_qtd) + EHCI_SQTD_ALIGN - 1) & -EHCI_SQTD_ALIGN)
49#define EHCI_SQTD_CHUNK (EHCI_PAGE_SIZE / EHCI_SQTD_SIZE) 49#define EHCI_SQTD_CHUNK (EHCI_PAGE_SIZE / EHCI_SQTD_SIZE)
50 50
51typedef struct ehci_soft_qh { 51typedef struct ehci_soft_qh {
52 ehci_qh_t qh; 52 ehci_qh_t qh;
53 struct ehci_soft_qh *next; 53 struct ehci_soft_qh *next;
54 struct ehci_soft_qtd *sqtd; 54 struct ehci_soft_qtd *sqtd;
55 ehci_physaddr_t physaddr; 55 ehci_physaddr_t physaddr;
56 usb_dma_t dma; /* QH's DMA infos */ 56 usb_dma_t dma; /* QH's DMA infos */
57 int offs; /* QH's offset in usb_dma_t */ 57 int offs; /* QH's offset in usb_dma_t */
58 int islot; 58 int islot;
59} ehci_soft_qh_t; 59} ehci_soft_qh_t;
60#define EHCI_SQH_SIZE ((sizeof(struct ehci_soft_qh) + EHCI_QH_ALIGN - 1) / EHCI_QH_ALIGN * EHCI_QH_ALIGN) 60#define EHCI_SQH_SIZE ((sizeof(struct ehci_soft_qh) + EHCI_QH_ALIGN - 1) / EHCI_QH_ALIGN * EHCI_QH_ALIGN)
61#define EHCI_SQH_CHUNK (EHCI_PAGE_SIZE / EHCI_SQH_SIZE) 61#define EHCI_SQH_CHUNK (EHCI_PAGE_SIZE / EHCI_SQH_SIZE)
62 62
63typedef struct ehci_soft_itd { 63typedef struct ehci_soft_itd {
64 union { 64 union {
65 ehci_itd_t itd; 65 ehci_itd_t itd;
66 ehci_sitd_t sitd; 66 ehci_sitd_t sitd;
67 }; 67 };
68 union { 68 union {
69 struct { 69 struct {
70 /* soft_itds links in a periodic frame */ 70 /* soft_itds links in a periodic frame */
71 struct ehci_soft_itd *next; 71 struct ehci_soft_itd *next;
72 struct ehci_soft_itd *prev; 72 struct ehci_soft_itd *prev;
73 } frame_list; 73 } frame_list;
74 /* circular list of free itds */ 74 /* circular list of free itds */
75 LIST_ENTRY(ehci_soft_itd) free_list; 75 LIST_ENTRY(ehci_soft_itd) free_list;
76 } u; 76 } u;
77 struct ehci_soft_itd *xfer_next; /* Next soft_itd in xfer */ 77 struct ehci_soft_itd *xfer_next; /* Next soft_itd in xfer */
78 ehci_physaddr_t physaddr; 78 ehci_physaddr_t physaddr;
79 usb_dma_t dma; 79 usb_dma_t dma;
80 int offs; 80 int offs;
81 int slot; 81 int slot;
82 struct timeval t; /* store free time */ 82 struct timeval t; /* store free time */
83} ehci_soft_itd_t; 83} ehci_soft_itd_t;
84#define EHCI_ITD_SIZE ((sizeof(struct ehci_soft_itd) + EHCI_QH_ALIGN - 1) / EHCI_ITD_ALIGN * EHCI_ITD_ALIGN) 84#define EHCI_ITD_SIZE ((sizeof(struct ehci_soft_itd) + EHCI_QH_ALIGN - 1) / EHCI_ITD_ALIGN * EHCI_ITD_ALIGN)
85#define EHCI_ITD_CHUNK (EHCI_PAGE_SIZE / EHCI_ITD_SIZE) 85#define EHCI_ITD_CHUNK (EHCI_PAGE_SIZE / EHCI_ITD_SIZE)
86 86
87#define ehci_soft_sitd_t ehci_soft_itd_t 87#define ehci_soft_sitd_t ehci_soft_itd_t
88#define ehci_soft_sitd ehci_soft_itd 88#define ehci_soft_sitd ehci_soft_itd
89#define sc_softsitds sc_softitds 89#define sc_softsitds sc_softitds
90#define EHCI_SITD_SIZE ((sizeof(struct ehci_soft_sitd) + EHCI_QH_ALIGN - 1) / EHCI_SITD_ALIGN * EHCI_SITD_ALIGN) 90#define EHCI_SITD_SIZE ((sizeof(struct ehci_soft_sitd) + EHCI_QH_ALIGN - 1) / EHCI_SITD_ALIGN * EHCI_SITD_ALIGN)
91#define EHCI_SITD_CHUNK (EHCI_PAGE_SIZE / EHCI_SITD_SIZE) 91#define EHCI_SITD_CHUNK (EHCI_PAGE_SIZE / EHCI_SITD_SIZE)
92 92
93struct ehci_xfer { 93struct ehci_xfer {
94 struct usbd_xfer ex_xfer; 94 struct usbd_xfer ex_xfer;
95 struct usb_task ex_aborttask; 95 struct usb_task ex_aborttask;
96 TAILQ_ENTRY(ehci_xfer) ex_next; /* list of active xfers */ 96 TAILQ_ENTRY(ehci_xfer) ex_next; /* list of active xfers */
97 union { 97 union {
98 /* ctrl/bulk/intr */ 98 /* ctrl/bulk/intr */
99 struct { 99 struct {
100 ehci_soft_qtd_t *ex_sqtdstart; 100 ehci_soft_qtd_t *ex_sqtdstart;
101 ehci_soft_qtd_t *ex_sqtdend; 101 ehci_soft_qtd_t *ex_sqtdend;
102 }; 102 };
103 /* isoc */ 103 /* isoc */
104 struct { 104 struct {
105 ehci_soft_itd_t *ex_itdstart; 105 ehci_soft_itd_t *ex_itdstart;
106 ehci_soft_itd_t *ex_itdend; 106 ehci_soft_itd_t *ex_itdend;
107 }; 107 };
108 /* split isoc */ 108 /* split isoc */
109 struct { 109 struct {
110 ehci_soft_sitd_t *ex_sitdstart; 110 ehci_soft_sitd_t *ex_sitdstart;
111 ehci_soft_sitd_t *ex_sitdend; 111 ehci_soft_sitd_t *ex_sitdend;
112 }; 112 };
113 }; 113 };
114 int ex_isdone; /* used only when DIAGNOSTIC is defined */ 114 bool ex_isdone; /* used only when DIAGNOSTIC is defined */
115}; 115};
116#define EXFER(xfer) ((struct ehci_xfer *)(xfer)) 116#define EXFER(xfer) ((struct ehci_xfer *)(xfer))
117 117
118/* Information about an entry in the interrupt list. */ 118/* Information about an entry in the interrupt list. */
119struct ehci_soft_islot { 119struct ehci_soft_islot {
120 ehci_soft_qh_t *sqh; /* Queue Head. */ 120 ehci_soft_qh_t *sqh; /* Queue Head. */
121}; 121};
122 122
123#define EHCI_FRAMELIST_MAXCOUNT 1024 123#define EHCI_FRAMELIST_MAXCOUNT 1024
124#define EHCI_IPOLLRATES 8 /* Poll rates (1ms, 2, 4, 8 .. 128) */ 124#define EHCI_IPOLLRATES 8 /* Poll rates (1ms, 2, 4, 8 .. 128) */
125#define EHCI_INTRQHS ((1 << EHCI_IPOLLRATES) - 1) 125#define EHCI_INTRQHS ((1 << EHCI_IPOLLRATES) - 1)
126#define EHCI_MAX_POLLRATE (1 << (EHCI_IPOLLRATES - 1)) 126#define EHCI_MAX_POLLRATE (1 << (EHCI_IPOLLRATES - 1))
127#define EHCI_IQHIDX(lev, pos) \ 127#define EHCI_IQHIDX(lev, pos) \
128 ((((pos) & ((1 << (lev)) - 1)) | (1 << (lev))) - 1) 128 ((((pos) & ((1 << (lev)) - 1)) | (1 << (lev))) - 1)
129#define EHCI_ILEV_IVAL(lev) (1 << (lev)) 129#define EHCI_ILEV_IVAL(lev) (1 << (lev))
130 130
131 131
132#define EHCI_HASH_SIZE 128 132#define EHCI_HASH_SIZE 128
133#define EHCI_COMPANION_MAX 8 133#define EHCI_COMPANION_MAX 8
134 134
135#define EHCI_FREE_LIST_INTERVAL 100 135#define EHCI_FREE_LIST_INTERVAL 100
136 136
137typedef struct ehci_softc { 137typedef struct ehci_softc {
138 device_t sc_dev; 138 device_t sc_dev;
139 kmutex_t sc_lock; 139 kmutex_t sc_lock;
140 kmutex_t sc_intr_lock; 140 kmutex_t sc_intr_lock;
141 kcondvar_t sc_doorbell; 141 kcondvar_t sc_doorbell;
142 void *sc_doorbell_si; 142 void *sc_doorbell_si;
143 void *sc_pcd_si; 143 void *sc_pcd_si;
144 struct usbd_bus sc_bus; 144 struct usbd_bus sc_bus;
145 bus_space_tag_t iot; 145 bus_space_tag_t iot;
146 bus_space_handle_t ioh; 146 bus_space_handle_t ioh;
147 bus_size_t sc_size; 147 bus_size_t sc_size;
148 u_int sc_offs; /* offset to operational regs */ 148 u_int sc_offs; /* offset to operational regs */
149 int sc_flags; /* misc flags */ 149 int sc_flags; /* misc flags */
150#define EHCIF_DROPPED_INTR_WORKAROUND 0x01 150#define EHCIF_DROPPED_INTR_WORKAROUND 0x01
151#define EHCIF_ETTF 0x02 /* Emb. Transaction Translater func. */ 151#define EHCIF_ETTF 0x02 /* Emb. Transaction Translater func. */
152 152
153 char sc_vendor[32]; /* vendor string for root hub */ 153 char sc_vendor[32]; /* vendor string for root hub */
154 int sc_id_vendor; /* vendor ID for root hub */ 154 int sc_id_vendor; /* vendor ID for root hub */
155 155
156 uint32_t sc_cmd; /* shadow of cmd reg during suspend */ 156 uint32_t sc_cmd; /* shadow of cmd reg during suspend */
157 157
158 u_int sc_ncomp; 158 u_int sc_ncomp;
159 u_int sc_npcomp; 159 u_int sc_npcomp;
160 device_t sc_comps[EHCI_COMPANION_MAX]; 160 device_t sc_comps[EHCI_COMPANION_MAX];
161 161
162 usb_dma_t sc_fldma; 162 usb_dma_t sc_fldma;
163 ehci_link_t *sc_flist; 163 ehci_link_t *sc_flist;
164 u_int sc_flsize; 164 u_int sc_flsize;
165 u_int sc_rand; /* XXX need proper intr scheduling */ 165 u_int sc_rand; /* XXX need proper intr scheduling */
166 166
167 struct ehci_soft_islot sc_islots[EHCI_INTRQHS]; 167 struct ehci_soft_islot sc_islots[EHCI_INTRQHS];
168 168
169 /* jcmm - an array matching sc_flist, but with software pointers, 169 /* jcmm - an array matching sc_flist, but with software pointers,
170 * not hardware address pointers 170 * not hardware address pointers
171 */ 171 */
172 struct ehci_soft_itd **sc_softitds; 172 struct ehci_soft_itd **sc_softitds;
173 173
174 TAILQ_HEAD(, ehci_xfer) sc_intrhead; 174 TAILQ_HEAD(, ehci_xfer) sc_intrhead;
175 175
176 ehci_soft_qh_t *sc_freeqhs; 176 ehci_soft_qh_t *sc_freeqhs;
177 ehci_soft_qtd_t *sc_freeqtds; 177 ehci_soft_qtd_t *sc_freeqtds;
178 LIST_HEAD(sc_freeitds, ehci_soft_itd) sc_freeitds; 178 LIST_HEAD(sc_freeitds, ehci_soft_itd) sc_freeitds;
179 LIST_HEAD(sc_freesitds, ehci_soft_sitd) sc_freesitds; 179 LIST_HEAD(sc_freesitds, ehci_soft_sitd) sc_freesitds;
180 180
181 int sc_noport; 181 int sc_noport;
182 uint8_t sc_hasppc; /* has Port Power Control */ 182 uint8_t sc_hasppc; /* has Port Power Control */
183 usbd_xfer_handle sc_intrxfer; 183 usbd_xfer_handle sc_intrxfer;
184 char sc_isreset[EHCI_MAX_PORTS]; 184 char sc_isreset[EHCI_MAX_PORTS];
185 char sc_softwake; 185 char sc_softwake;
186 kcondvar_t sc_softwake_cv; 186 kcondvar_t sc_softwake_cv;
187 187
188 uint32_t sc_eintrs; 188 uint32_t sc_eintrs;
189 ehci_soft_qh_t *sc_async_head; 189 ehci_soft_qh_t *sc_async_head;
190 190
191 pool_cache_t sc_xferpool; /* free xfer pool */ 191 pool_cache_t sc_xferpool; /* free xfer pool */
192 192
193 struct callout sc_tmo_intrlist; 193 struct callout sc_tmo_intrlist;
194 194
195 device_t sc_child; /* /dev/usb# device */ 195 device_t sc_child; /* /dev/usb# device */
196 char sc_dying; 196 char sc_dying;
197 197
198 void (*sc_vendor_init)(struct ehci_softc *); 198 void (*sc_vendor_init)(struct ehci_softc *);
199 int (*sc_vendor_port_status)(struct ehci_softc *, uint32_t, int); 199 int (*sc_vendor_port_status)(struct ehci_softc *, uint32_t, int);
200} ehci_softc_t; 200} ehci_softc_t;
201 201
202#define EREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (a)) 202#define EREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (a))
203#define EREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (a)) 203#define EREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (a))
204#define EREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (a)) 204#define EREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (a))
205#define EWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (a), (x)) 205#define EWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (a), (x))
206#define EWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (a), (x)) 206#define EWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (a), (x))
207#define EWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (a), (x)) 207#define EWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (a), (x))
208#define EOREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a)) 208#define EOREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
209#define EOREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a)) 209#define EOREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
210#define EOREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a)) 210#define EOREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
211#define EOWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x)) 211#define EOWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
212#define EOWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x)) 212#define EOWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
213#define EOWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x)) 213#define EOWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
214 214
215int ehci_init(ehci_softc_t *); 215int ehci_init(ehci_softc_t *);
216int ehci_intr(void *); 216int ehci_intr(void *);
217int ehci_detach(ehci_softc_t *, int); 217int ehci_detach(ehci_softc_t *, int);
218int ehci_activate(device_t, enum devact); 218int ehci_activate(device_t, enum devact);
219void ehci_childdet(device_t, device_t); 219void ehci_childdet(device_t, device_t);
220bool ehci_suspend(device_t, const pmf_qual_t *); 220bool ehci_suspend(device_t, const pmf_qual_t *);
221bool ehci_resume(device_t, const pmf_qual_t *); 221bool ehci_resume(device_t, const pmf_qual_t *);
222bool ehci_shutdown(device_t, int); 222bool ehci_shutdown(device_t, int);
223 223
224#endif /* _EHCIVAR_H_ */ 224#endif /* _EHCIVAR_H_ */