Tue Mar 3 10:06:01 2015 UTC ()
Convert to __BIT and friends.

No functional change.


(skrll)
diff -r1.234.2.37 -r1.234.2.38 src/sys/dev/usb/ehci.c
diff -r1.34.14.5 -r1.34.14.6 src/sys/dev/usb/ehcireg.h

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

--- src/sys/dev/usb/ehci.c 2015/03/03 06:36:53 1.234.2.37
+++ src/sys/dev/usb/ehci.c 2015/03/03 10:06:01 1.234.2.38
@@ -1,1055 +1,1055 @@ @@ -1,1055 +1,1055 @@
1/* $NetBSD: ehci.c,v 1.234.2.37 2015/03/03 06:36:53 skrll Exp $ */ 1/* $NetBSD: ehci.c,v 1.234.2.38 2015/03/03 10:06:01 skrll Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2004-2012 The NetBSD Foundation, Inc. 4 * Copyright (c) 2004-2012 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net), Charles M. Hannum, 8 * by Lennart Augustsson (lennart@augustsson.net), Charles M. Hannum,
9 * Jeremy Morse (jeremy.morse@gmail.com), Jared D. McNeill 9 * Jeremy Morse (jeremy.morse@gmail.com), Jared D. McNeill
10 * (jmcneill@invisible.ca) and Matthew R. Green (mrg@eterna.com.au). 10 * (jmcneill@invisible.ca) and Matthew R. Green (mrg@eterna.com.au).
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
15 * 1. Redistributions of source code must retain the above copyright 15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer. 16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright 17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the 18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution. 19 * documentation and/or other materials provided with the distribution.
20 * 20 *
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE. 31 * POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34/* 34/*
35 * USB Enhanced Host Controller Driver, a.k.a. USB 2.0 controller. 35 * USB Enhanced Host Controller Driver, a.k.a. USB 2.0 controller.
36 * 36 *
37 * The EHCI 1.0 spec can be found at 37 * The EHCI 1.0 spec can be found at
38 * http://www.intel.com/technology/usb/spec.htm 38 * http://www.intel.com/technology/usb/spec.htm
39 * and the USB 2.0 spec at 39 * and the USB 2.0 spec at
40 * http://www.usb.org/developers/docs/ 40 * http://www.usb.org/developers/docs/
41 * 41 *
42 */ 42 */
43 43
44/* 44/*
45 * TODO: 45 * TODO:
46 * 1) hold off explorations by companion controllers until ehci has started. 46 * 1) hold off explorations by companion controllers until ehci has started.
47 * 47 *
48 * 2) The hub driver needs to handle and schedule the transaction translator, 48 * 2) The hub driver needs to handle and schedule the transaction translator,
49 * to assign place in frame where different devices get to go. See chapter 49 * to assign place in frame where different devices get to go. See chapter
50 * on hubs in USB 2.0 for details. 50 * on hubs in USB 2.0 for details.
51 * 51 *
52 * 3) Command failures are not recovered correctly. 52 * 3) Command failures are not recovered correctly.
53 */ 53 */
54 54
55#include <sys/cdefs.h> 55#include <sys/cdefs.h>
56__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.234.2.37 2015/03/03 06:36:53 skrll Exp $"); 56__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.234.2.38 2015/03/03 10:06:01 skrll Exp $");
57 57
58#include "ohci.h" 58#include "ohci.h"
59#include "uhci.h" 59#include "uhci.h"
60#include "opt_usb.h" 60#include "opt_usb.h"
61 61
62#include <sys/param.h> 62#include <sys/param.h>
63 63
64#include <sys/bus.h> 64#include <sys/bus.h>
65#include <sys/cpu.h> 65#include <sys/cpu.h>
66#include <sys/device.h> 66#include <sys/device.h>
67#include <sys/kernel.h> 67#include <sys/kernel.h>
68#include <sys/kmem.h> 68#include <sys/kmem.h>
69#include <sys/mutex.h> 69#include <sys/mutex.h>
70#include <sys/proc.h> 70#include <sys/proc.h>
71#include <sys/queue.h> 71#include <sys/queue.h>
72#include <sys/select.h> 72#include <sys/select.h>
73#include <sys/sysctl.h> 73#include <sys/sysctl.h>
74#include <sys/systm.h> 74#include <sys/systm.h>
75 75
76#include <machine/endian.h> 76#include <machine/endian.h>
77 77
78#include <dev/usb/usb.h> 78#include <dev/usb/usb.h>
79#include <dev/usb/usbdi.h> 79#include <dev/usb/usbdi.h>
80#include <dev/usb/usbdivar.h> 80#include <dev/usb/usbdivar.h>
81#include <dev/usb/usbhist.h> 81#include <dev/usb/usbhist.h>
82#include <dev/usb/usb_mem.h> 82#include <dev/usb/usb_mem.h>
83#include <dev/usb/usb_quirks.h> 83#include <dev/usb/usb_quirks.h>
84 84
85#include <dev/usb/ehcireg.h> 85#include <dev/usb/ehcireg.h>
86#include <dev/usb/ehcivar.h> 86#include <dev/usb/ehcivar.h>
87#include <dev/usb/usbroothub.h> 87#include <dev/usb/usbroothub.h>
88 88
89 89
90#ifdef USB_DEBUG 90#ifdef USB_DEBUG
91#ifndef EHCI_DEBUG 91#ifndef EHCI_DEBUG
92#define ehcidebug 0 92#define ehcidebug 0
93#else 93#else
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#ifdef EHCI_DEBUG 1021#ifdef EHCI_DEBUG
1022 if (ex->ex_isdone) { 1022 if (ex->ex_isdone) {
1023 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); 1023 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0);
1024 ehci_dump_exfer(ex); 1024 ehci_dump_exfer(ex);
1025 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); 1025 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0);
1026 } 1026 }
1027#endif 1027#endif
1028 KASSERT(!ex->ex_isdone); 1028 KASSERT(!ex->ex_isdone);
1029 ex->ex_isdone = true; 1029 ex->ex_isdone = true;
1030#endif 1030#endif
1031 1031
1032 if (xfer->ux_status == USBD_CANCELLED || 1032 if (xfer->ux_status == USBD_CANCELLED ||
1033 xfer->ux_status == USBD_TIMEOUT) { 1033 xfer->ux_status == USBD_TIMEOUT) {
1034 USBHIST_LOG(ehcidebug, "aborted xfer=%p", xfer, 0, 0, 0); 1034 USBHIST_LOG(ehcidebug, "aborted xfer=%p", xfer, 0, 0, 0);
1035 return; 1035 return;
1036 } 1036 }
1037 1037
1038 USBHIST_LOG(ehcidebug, "xfer=%p, pipe=%p ready", xfer, epipe, 0, 0); 1038 USBHIST_LOG(ehcidebug, "xfer=%p, pipe=%p ready", xfer, epipe, 0, 0);
1039#ifdef EHCI_DEBUG 1039#ifdef EHCI_DEBUG
1040 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); 1040 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0);
1041 ehci_dump_sqtds(ex->ex_sqtdstart); 1041 ehci_dump_sqtds(ex->ex_sqtdstart);
1042 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); 1042 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0);
1043#endif 1043#endif
1044 1044
1045 /* The transfer is done, compute actual length and status. */ 1045 /* The transfer is done, compute actual length and status. */
1046 1046
1047 u_int xfertype, speed; 1047 u_int xfertype, speed;
1048 1048
1049 xfertype = UE_GET_XFERTYPE(xfer->ux_pipe->up_endpoint->ue_edesc->bmAttributes); 1049 xfertype = UE_GET_XFERTYPE(xfer->ux_pipe->up_endpoint->ue_edesc->bmAttributes);
1050 speed = xfer->ux_pipe->up_dev->ud_speed; 1050 speed = xfer->ux_pipe->up_dev->ud_speed;
1051 if (xfertype == UE_ISOCHRONOUS && speed == USB_SPEED_HIGH) { 1051 if (xfertype == UE_ISOCHRONOUS && speed == USB_SPEED_HIGH) {
1052 /* HS isoc transfer */ 1052 /* HS isoc transfer */
1053 1053
1054 struct ehci_soft_itd *itd; 1054 struct ehci_soft_itd *itd;
1055 int i, nframes, len, uframes; 1055 int i, nframes, len, uframes;
@@ -2539,2003 +2539,2003 @@ ehci_roothub_ctrl(struct usbd_bus *bus,  @@ -2539,2003 +2539,2003 @@ ehci_roothub_ctrl(struct usbd_bus *bus,
2539 break; 2539 break;
2540 default: 2540 default:
2541 return -1; 2541 return -1;
2542 } 2542 }
2543 break; 2543 break;
2544 case C(UR_CLEAR_TT_BUFFER, UT_WRITE_CLASS_OTHER): 2544 case C(UR_CLEAR_TT_BUFFER, UT_WRITE_CLASS_OTHER):
2545 case C(UR_RESET_TT, UT_WRITE_CLASS_OTHER): 2545 case C(UR_RESET_TT, UT_WRITE_CLASS_OTHER):
2546 case C(UR_GET_TT_STATE, UT_READ_CLASS_OTHER): 2546 case C(UR_GET_TT_STATE, UT_READ_CLASS_OTHER):
2547 case C(UR_STOP_TT, UT_WRITE_CLASS_OTHER): 2547 case C(UR_STOP_TT, UT_WRITE_CLASS_OTHER):
2548 break; 2548 break;
2549 default: 2549 default:
2550 /* default from usbroothub */ 2550 /* default from usbroothub */
2551 USBHIST_LOG(ehcidebug, "returning %d (usbroothub default)", 2551 USBHIST_LOG(ehcidebug, "returning %d (usbroothub default)",
2552 buflen, 0, 0, 0); 2552 buflen, 0, 0, 0);
2553 2553
2554 return buflen; 2554 return buflen;
2555 } 2555 }
2556 2556
2557 USBHIST_LOG(ehcidebug, "returning %d", totlen, 0, 0, 0); 2557 USBHIST_LOG(ehcidebug, "returning %d", totlen, 0, 0, 0);
2558 2558
2559 return totlen; 2559 return totlen;
2560} 2560}
2561 2561
2562Static void 2562Static void
2563ehci_disown(ehci_softc_t *sc, int index, int lowspeed) 2563ehci_disown(ehci_softc_t *sc, int index, int lowspeed)
2564{ 2564{
2565 int port; 2565 int port;
2566 uint32_t v; 2566 uint32_t v;
2567 2567
2568 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2568 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2569 2569
2570 USBHIST_LOG(ehcidebug, "index=%d lowspeed=%d", index, lowspeed, 0, 0); 2570 USBHIST_LOG(ehcidebug, "index=%d lowspeed=%d", index, lowspeed, 0, 0);
2571#ifdef DIAGNOSTIC 2571#ifdef DIAGNOSTIC
2572 if (sc->sc_npcomp != 0) { 2572 if (sc->sc_npcomp != 0) {
2573 int i = (index-1) / sc->sc_npcomp; 2573 int i = (index-1) / sc->sc_npcomp;
2574 if (i >= sc->sc_ncomp) 2574 if (i >= sc->sc_ncomp)
2575 printf("%s: strange port\n", 2575 printf("%s: strange port\n",
2576 device_xname(sc->sc_dev)); 2576 device_xname(sc->sc_dev));
2577 else 2577 else
2578 printf("%s: handing over %s speed device on " 2578 printf("%s: handing over %s speed device on "
2579 "port %d to %s\n", 2579 "port %d to %s\n",
2580 device_xname(sc->sc_dev), 2580 device_xname(sc->sc_dev),
2581 lowspeed ? "low" : "full", 2581 lowspeed ? "low" : "full",
2582 index, device_xname(sc->sc_comps[i])); 2582 index, device_xname(sc->sc_comps[i]));
2583 } else { 2583 } else {
2584 printf("%s: npcomp == 0\n", device_xname(sc->sc_dev)); 2584 printf("%s: npcomp == 0\n", device_xname(sc->sc_dev));
2585 } 2585 }
2586#endif 2586#endif
2587 port = EHCI_PORTSC(index); 2587 port = EHCI_PORTSC(index);
2588 v = EOREAD4(sc, port) &~ EHCI_PS_CLEAR; 2588 v = EOREAD4(sc, port) &~ EHCI_PS_CLEAR;
2589 EOWRITE4(sc, port, v | EHCI_PS_PO); 2589 EOWRITE4(sc, port, v | EHCI_PS_PO);
2590} 2590}
2591 2591
2592Static usbd_status 2592Static usbd_status
2593ehci_root_intr_transfer(usbd_xfer_handle xfer) 2593ehci_root_intr_transfer(usbd_xfer_handle xfer)
2594{ 2594{
2595 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 2595 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
2596 usbd_status err; 2596 usbd_status err;
2597 2597
2598 /* Insert last in queue. */ 2598 /* Insert last in queue. */
2599 mutex_enter(&sc->sc_lock); 2599 mutex_enter(&sc->sc_lock);
2600 err = usb_insert_transfer(xfer); 2600 err = usb_insert_transfer(xfer);
2601 mutex_exit(&sc->sc_lock); 2601 mutex_exit(&sc->sc_lock);
2602 if (err) 2602 if (err)
2603 return err; 2603 return err;
2604 2604
2605 /* Pipe isn't running, start first */ 2605 /* Pipe isn't running, start first */
2606 return ehci_root_intr_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); 2606 return ehci_root_intr_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue));
2607} 2607}
2608 2608
2609Static usbd_status 2609Static usbd_status
2610ehci_root_intr_start(usbd_xfer_handle xfer) 2610ehci_root_intr_start(usbd_xfer_handle xfer)
2611{ 2611{
2612 usbd_pipe_handle pipe = xfer->ux_pipe; 2612 usbd_pipe_handle pipe = xfer->ux_pipe;
2613 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; 2613 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
2614 2614
2615 if (sc->sc_dying) 2615 if (sc->sc_dying)
2616 return USBD_IOERROR; 2616 return USBD_IOERROR;
2617 2617
2618 mutex_enter(&sc->sc_lock); 2618 mutex_enter(&sc->sc_lock);
2619 sc->sc_intrxfer = xfer; 2619 sc->sc_intrxfer = xfer;
2620 mutex_exit(&sc->sc_lock); 2620 mutex_exit(&sc->sc_lock);
2621 2621
2622 return USBD_IN_PROGRESS; 2622 return USBD_IN_PROGRESS;
2623} 2623}
2624 2624
2625/* Abort a root interrupt request. */ 2625/* Abort a root interrupt request. */
2626Static void 2626Static void
2627ehci_root_intr_abort(usbd_xfer_handle xfer) 2627ehci_root_intr_abort(usbd_xfer_handle xfer)
2628{ 2628{
2629 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 2629 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
2630 2630
2631 KASSERT(mutex_owned(&sc->sc_lock)); 2631 KASSERT(mutex_owned(&sc->sc_lock));
2632 KASSERT(xfer->ux_pipe->up_intrxfer == xfer); 2632 KASSERT(xfer->ux_pipe->up_intrxfer == xfer);
2633 2633
2634 sc->sc_intrxfer = NULL; 2634 sc->sc_intrxfer = NULL;
2635 2635
2636 xfer->ux_status = USBD_CANCELLED; 2636 xfer->ux_status = USBD_CANCELLED;
2637 usb_transfer_complete(xfer); 2637 usb_transfer_complete(xfer);
2638} 2638}
2639 2639
2640/* Close the root pipe. */ 2640/* Close the root pipe. */
2641Static void 2641Static void
2642ehci_root_intr_close(usbd_pipe_handle pipe) 2642ehci_root_intr_close(usbd_pipe_handle pipe)
2643{ 2643{
2644 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; 2644 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
2645 2645
2646 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2646 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2647 2647
2648 KASSERT(mutex_owned(&sc->sc_lock)); 2648 KASSERT(mutex_owned(&sc->sc_lock));
2649 2649
2650 sc->sc_intrxfer = NULL; 2650 sc->sc_intrxfer = NULL;
2651} 2651}
2652 2652
2653Static void 2653Static void
2654ehci_root_intr_done(usbd_xfer_handle xfer) 2654ehci_root_intr_done(usbd_xfer_handle xfer)
2655{ 2655{
2656 xfer->ux_hcpriv = NULL; 2656 xfer->ux_hcpriv = NULL;
2657} 2657}
2658 2658
2659/************************/ 2659/************************/
2660 2660
2661Static ehci_soft_qh_t * 2661Static ehci_soft_qh_t *
2662ehci_alloc_sqh(ehci_softc_t *sc) 2662ehci_alloc_sqh(ehci_softc_t *sc)
2663{ 2663{
2664 ehci_soft_qh_t *sqh; 2664 ehci_soft_qh_t *sqh;
2665 usbd_status err; 2665 usbd_status err;
2666 int i, offs; 2666 int i, offs;
2667 usb_dma_t dma; 2667 usb_dma_t dma;
2668 2668
2669 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2669 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2670 2670
2671 if (sc->sc_freeqhs == NULL) { 2671 if (sc->sc_freeqhs == NULL) {
2672 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); 2672 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0);
2673 err = usb_allocmem(&sc->sc_bus, EHCI_SQH_SIZE * EHCI_SQH_CHUNK, 2673 err = usb_allocmem(&sc->sc_bus, EHCI_SQH_SIZE * EHCI_SQH_CHUNK,
2674 EHCI_PAGE_SIZE, &dma); 2674 EHCI_PAGE_SIZE, &dma);
2675#ifdef EHCI_DEBUG 2675#ifdef EHCI_DEBUG
2676 if (err) 2676 if (err)
2677 printf("ehci_alloc_sqh: usb_allocmem()=%d\n", err); 2677 printf("ehci_alloc_sqh: usb_allocmem()=%d\n", err);
2678#endif 2678#endif
2679 if (err) 2679 if (err)
2680 return NULL; 2680 return NULL;
2681 for (i = 0; i < EHCI_SQH_CHUNK; i++) { 2681 for (i = 0; i < EHCI_SQH_CHUNK; i++) {
2682 offs = i * EHCI_SQH_SIZE; 2682 offs = i * EHCI_SQH_SIZE;
2683 sqh = KERNADDR(&dma, offs); 2683 sqh = KERNADDR(&dma, offs);
2684 sqh->physaddr = DMAADDR(&dma, offs); 2684 sqh->physaddr = DMAADDR(&dma, offs);
2685 sqh->dma = dma; 2685 sqh->dma = dma;
2686 sqh->offs = offs; 2686 sqh->offs = offs;
2687 sqh->next = sc->sc_freeqhs; 2687 sqh->next = sc->sc_freeqhs;
2688 sc->sc_freeqhs = sqh; 2688 sc->sc_freeqhs = sqh;
2689 } 2689 }
2690 } 2690 }
2691 sqh = sc->sc_freeqhs; 2691 sqh = sc->sc_freeqhs;
2692 sc->sc_freeqhs = sqh->next; 2692 sc->sc_freeqhs = sqh->next;
2693 memset(&sqh->qh, 0, sizeof(ehci_qh_t)); 2693 memset(&sqh->qh, 0, sizeof(ehci_qh_t));
2694 sqh->next = NULL; 2694 sqh->next = NULL;
2695 return sqh; 2695 return sqh;
2696} 2696}
2697 2697
2698Static void 2698Static void
2699ehci_free_sqh(ehci_softc_t *sc, ehci_soft_qh_t *sqh) 2699ehci_free_sqh(ehci_softc_t *sc, ehci_soft_qh_t *sqh)
2700{ 2700{
2701 sqh->next = sc->sc_freeqhs; 2701 sqh->next = sc->sc_freeqhs;
2702 sc->sc_freeqhs = sqh; 2702 sc->sc_freeqhs = sqh;
2703} 2703}
2704 2704
2705Static ehci_soft_qtd_t * 2705Static ehci_soft_qtd_t *
2706ehci_alloc_sqtd(ehci_softc_t *sc) 2706ehci_alloc_sqtd(ehci_softc_t *sc)
2707{ 2707{
2708 ehci_soft_qtd_t *sqtd = NULL; 2708 ehci_soft_qtd_t *sqtd = NULL;
2709 usbd_status err; 2709 usbd_status err;
2710 int i, offs; 2710 int i, offs;
2711 usb_dma_t dma; 2711 usb_dma_t dma;
2712 2712
2713 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2713 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2714 2714
2715 if (sc->sc_freeqtds == NULL) { 2715 if (sc->sc_freeqtds == NULL) {
2716 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); 2716 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0);
2717 2717
2718 err = usb_allocmem(&sc->sc_bus, EHCI_SQTD_SIZE*EHCI_SQTD_CHUNK, 2718 err = usb_allocmem(&sc->sc_bus, EHCI_SQTD_SIZE*EHCI_SQTD_CHUNK,
2719 EHCI_PAGE_SIZE, &dma); 2719 EHCI_PAGE_SIZE, &dma);
2720#ifdef EHCI_DEBUG 2720#ifdef EHCI_DEBUG
2721 if (err) 2721 if (err)
2722 printf("ehci_alloc_sqtd: usb_allocmem()=%d\n", err); 2722 printf("ehci_alloc_sqtd: usb_allocmem()=%d\n", err);
2723#endif 2723#endif
2724 if (err) 2724 if (err)
2725 goto done; 2725 goto done;
2726 2726
2727 for (i = 0; i < EHCI_SQTD_CHUNK; i++) { 2727 for (i = 0; i < EHCI_SQTD_CHUNK; i++) {
2728 offs = i * EHCI_SQTD_SIZE; 2728 offs = i * EHCI_SQTD_SIZE;
2729 sqtd = KERNADDR(&dma, offs); 2729 sqtd = KERNADDR(&dma, offs);
2730 sqtd->physaddr = DMAADDR(&dma, offs); 2730 sqtd->physaddr = DMAADDR(&dma, offs);
2731 sqtd->dma = dma; 2731 sqtd->dma = dma;
2732 sqtd->offs = offs; 2732 sqtd->offs = offs;
2733 2733
2734 sqtd->nextqtd = sc->sc_freeqtds; 2734 sqtd->nextqtd = sc->sc_freeqtds;
2735 sc->sc_freeqtds = sqtd; 2735 sc->sc_freeqtds = sqtd;
2736 } 2736 }
2737 } 2737 }
2738 2738
2739 sqtd = sc->sc_freeqtds; 2739 sqtd = sc->sc_freeqtds;
2740 sc->sc_freeqtds = sqtd->nextqtd; 2740 sc->sc_freeqtds = sqtd->nextqtd;
2741 memset(&sqtd->qtd, 0, sizeof(ehci_qtd_t)); 2741 memset(&sqtd->qtd, 0, sizeof(ehci_qtd_t));
2742 sqtd->nextqtd = NULL; 2742 sqtd->nextqtd = NULL;
2743 sqtd->xfer = NULL; 2743 sqtd->xfer = NULL;
2744 2744
2745done: 2745done:
2746 return sqtd; 2746 return sqtd;
2747} 2747}
2748 2748
2749Static void 2749Static void
2750ehci_free_sqtd(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd) 2750ehci_free_sqtd(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd)
2751{ 2751{
2752 2752
2753 KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); 2753 KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock));
2754 2754
2755 sqtd->nextqtd = sc->sc_freeqtds; 2755 sqtd->nextqtd = sc->sc_freeqtds;
2756 sc->sc_freeqtds = sqtd; 2756 sc->sc_freeqtds = sqtd;
2757} 2757}
2758 2758
2759Static usbd_status 2759Static usbd_status
2760ehci_alloc_sqtd_chain(struct ehci_pipe *epipe, ehci_softc_t *sc, 2760ehci_alloc_sqtd_chain(struct ehci_pipe *epipe, ehci_softc_t *sc,
2761 int alen, int rd, usbd_xfer_handle xfer, 2761 int alen, int rd, usbd_xfer_handle xfer,
2762 ehci_soft_qtd_t **sp, ehci_soft_qtd_t **ep) 2762 ehci_soft_qtd_t **sp, ehci_soft_qtd_t **ep)
2763{ 2763{
2764 ehci_soft_qtd_t *next, *cur; 2764 ehci_soft_qtd_t *next, *cur;
2765 ehci_physaddr_t nextphys; 2765 ehci_physaddr_t nextphys;
2766 uint32_t qtdstatus; 2766 uint32_t qtdstatus;
2767 int len, curlen, mps; 2767 int len, curlen, mps;
2768 int i, tog; 2768 int i, tog;
2769 int pages, pageoffs; 2769 int pages, pageoffs;
2770 size_t curoffs; 2770 size_t curoffs;
2771 vaddr_t va, va_offs; 2771 vaddr_t va, va_offs;
2772 usb_dma_t *dma = &xfer->ux_dmabuf; 2772 usb_dma_t *dma = &xfer->ux_dmabuf;
2773 uint16_t flags = xfer->ux_flags; 2773 uint16_t flags = xfer->ux_flags;
2774 paddr_t a; 2774 paddr_t a;
2775 2775
2776 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2776 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2777 2777
2778 USBHIST_LOG(ehcidebug, "start len=%d", alen, 0, 0, 0); 2778 USBHIST_LOG(ehcidebug, "start len=%d", alen, 0, 0, 0);
2779 2779
2780 len = alen; 2780 len = alen;
2781 qtdstatus = EHCI_QTD_ACTIVE | 2781 qtdstatus = EHCI_QTD_ACTIVE |
2782 EHCI_QTD_SET_PID(rd ? EHCI_QTD_PID_IN : EHCI_QTD_PID_OUT) | 2782 EHCI_QTD_SET_PID(rd ? EHCI_QTD_PID_IN : EHCI_QTD_PID_OUT) |
2783 EHCI_QTD_SET_CERR(3) 2783 EHCI_QTD_SET_CERR(3)
2784 /* IOC set below */ 2784 /* IOC set below */
2785 /* BYTES set below */ 2785 /* BYTES set below */
2786 ; 2786 ;
2787 mps = UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize); 2787 mps = UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize);
2788 tog = epipe->nexttoggle; 2788 tog = epipe->nexttoggle;
2789 qtdstatus |= EHCI_QTD_SET_TOGGLE(tog); 2789 qtdstatus |= EHCI_QTD_SET_TOGGLE(tog);
2790 2790
2791 cur = ehci_alloc_sqtd(sc); 2791 cur = ehci_alloc_sqtd(sc);
2792 *sp = cur; 2792 *sp = cur;
2793 if (cur == NULL) 2793 if (cur == NULL)
2794 goto nomem; 2794 goto nomem;
2795 2795
2796 usb_syncmem(dma, 0, alen, 2796 usb_syncmem(dma, 0, alen,
2797 rd ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE); 2797 rd ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
2798 curoffs = 0; 2798 curoffs = 0;
2799 for (;;) { 2799 for (;;) {
2800 /* The EHCI hardware can handle at most 5 pages. */ 2800 /* The EHCI hardware can handle at most 5 pages. */
2801 va_offs = (vaddr_t)KERNADDR(dma, curoffs); 2801 va_offs = (vaddr_t)KERNADDR(dma, curoffs);
2802 va_offs = EHCI_PAGE_OFFSET(va_offs); 2802 va_offs = EHCI_PAGE_OFFSET(va_offs);
2803 if (len-curoffs < EHCI_QTD_MAXTRANSFER - va_offs) { 2803 if (len-curoffs < EHCI_QTD_MAXTRANSFER - va_offs) {
2804 /* we can handle it in this QTD */ 2804 /* we can handle it in this QTD */
2805 curlen = len - curoffs; 2805 curlen = len - curoffs;
2806 } else { 2806 } else {
2807 /* must use multiple TDs, fill as much as possible. */ 2807 /* must use multiple TDs, fill as much as possible. */
2808 curlen = EHCI_QTD_MAXTRANSFER - va_offs; 2808 curlen = EHCI_QTD_MAXTRANSFER - va_offs;
2809 2809
2810 /* the length must be a multiple of the max size */ 2810 /* the length must be a multiple of the max size */
2811 curlen -= curlen % mps; 2811 curlen -= curlen % mps;
2812 USBHIST_LOG(ehcidebug, "multiple QTDs, " 2812 USBHIST_LOG(ehcidebug, "multiple QTDs, "
2813 "curlen=%d", curlen, 0, 0, 0); 2813 "curlen=%d", curlen, 0, 0, 0);
2814 KASSERT(curlen != 0); 2814 KASSERT(curlen != 0);
2815 } 2815 }
2816 USBHIST_LOG(ehcidebug, "len=%d curlen=%d curoffs=%zu", 2816 USBHIST_LOG(ehcidebug, "len=%d curlen=%d curoffs=%zu",
2817 len, curlen, curoffs, 0); 2817 len, curlen, curoffs, 0);
2818 2818
2819 /* 2819 /*
2820 * Allocate another transfer if there's more data left, 2820 * Allocate another transfer if there's more data left,
2821 * or if force last short transfer flag is set and we're 2821 * or if force last short transfer flag is set and we're
2822 * allocating a multiple of the max packet size. 2822 * allocating a multiple of the max packet size.
2823 */ 2823 */
2824 2824
2825 if (curoffs + curlen != len || 2825 if (curoffs + curlen != len ||
2826 ((curlen % mps) == 0 && !rd && curlen != 0 && 2826 ((curlen % mps) == 0 && !rd && curlen != 0 &&
2827 (flags & USBD_FORCE_SHORT_XFER))) { 2827 (flags & USBD_FORCE_SHORT_XFER))) {
2828 next = ehci_alloc_sqtd(sc); 2828 next = ehci_alloc_sqtd(sc);
2829 if (next == NULL) 2829 if (next == NULL)
2830 goto nomem; 2830 goto nomem;
2831 nextphys = htole32(next->physaddr); 2831 nextphys = htole32(next->physaddr);
2832 } else { 2832 } else {
2833 next = NULL; 2833 next = NULL;
2834 nextphys = EHCI_NULL; 2834 nextphys = EHCI_NULL;
2835 } 2835 }
2836 2836
2837 /* Find number of pages we'll be using, insert dma addresses */ 2837 /* Find number of pages we'll be using, insert dma addresses */
2838 pages = EHCI_NPAGES(curlen); 2838 pages = EHCI_NPAGES(curlen);
2839 KASSERT(pages <= EHCI_QTD_NBUFFERS); 2839 KASSERT(pages <= EHCI_QTD_NBUFFERS);
2840 pageoffs = EHCI_PAGE(curoffs); 2840 pageoffs = EHCI_PAGE(curoffs);
2841 for (i = 0; i < pages; i++) { 2841 for (i = 0; i < pages; i++) {
2842 a = DMAADDR(dma, pageoffs + i * EHCI_PAGE_SIZE); 2842 a = DMAADDR(dma, pageoffs + i * EHCI_PAGE_SIZE);
2843 cur->qtd.qtd_buffer[i] = htole32(EHCI_PAGE(a)); 2843 cur->qtd.qtd_buffer[i] = htole32(EHCI_PAGE(a));
2844 /* Cast up to avoid compiler warnings */ 2844 /* Cast up to avoid compiler warnings */
2845 cur->qtd.qtd_buffer_hi[i] = htole32((uint64_t)a >> 32); 2845 cur->qtd.qtd_buffer_hi[i] = htole32((uint64_t)a >> 32);
2846 } 2846 }
2847 2847
2848 /* First buffer pointer requires a page offset to start at */ 2848 /* First buffer pointer requires a page offset to start at */
2849 va = (vaddr_t)KERNADDR(dma, curoffs); 2849 va = (vaddr_t)KERNADDR(dma, curoffs);
2850 cur->qtd.qtd_buffer[0] |= htole32(EHCI_PAGE_OFFSET(va)); 2850 cur->qtd.qtd_buffer[0] |= htole32(EHCI_PAGE_OFFSET(va));
2851 2851
2852 cur->nextqtd = next; 2852 cur->nextqtd = next;
2853 cur->qtd.qtd_next = cur->qtd.qtd_altnext = nextphys; 2853 cur->qtd.qtd_next = cur->qtd.qtd_altnext = nextphys;
2854 cur->qtd.qtd_status = 2854 cur->qtd.qtd_status =
2855 htole32(qtdstatus | EHCI_QTD_SET_BYTES(curlen)); 2855 htole32(qtdstatus | EHCI_QTD_SET_BYTES(curlen));
2856 cur->xfer = xfer; 2856 cur->xfer = xfer;
2857 cur->len = curlen; 2857 cur->len = curlen;
2858 2858
2859 USBHIST_LOG(ehcidebug, "cbp=0x%08zx end=0x%08zx", 2859 USBHIST_LOG(ehcidebug, "cbp=0x%08zx end=0x%08zx",
2860 curoffs, curoffs + curlen, 0, 0); 2860 curoffs, curoffs + curlen, 0, 0);
2861 2861
2862 /* 2862 /*
2863 * adjust the toggle based on the number of packets in this 2863 * adjust the toggle based on the number of packets in this
2864 * qtd 2864 * qtd
2865 */ 2865 */
2866 if (((curlen + mps - 1) / mps) & 1) { 2866 if (((curlen + mps - 1) / mps) & 1) {
2867 tog ^= 1; 2867 tog ^= 1;
2868 qtdstatus ^= EHCI_QTD_TOGGLE_MASK; 2868 qtdstatus ^= EHCI_QTD_TOGGLE_MASK;
2869 } 2869 }
2870 if (next == NULL) 2870 if (next == NULL)
2871 break; 2871 break;
2872 usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd), 2872 usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd),
2873 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 2873 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
2874 USBHIST_LOG(ehcidebug, "extend chain", 0, 0, 0, 0); 2874 USBHIST_LOG(ehcidebug, "extend chain", 0, 0, 0, 0);
2875 if (len) 2875 if (len)
2876 curoffs += curlen; 2876 curoffs += curlen;
2877 cur = next; 2877 cur = next;
2878 } 2878 }
2879 cur->qtd.qtd_status |= htole32(EHCI_QTD_IOC); 2879 cur->qtd.qtd_status |= htole32(EHCI_QTD_IOC);
2880 usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd), 2880 usb_syncmem(&cur->dma, cur->offs, sizeof(cur->qtd),
2881 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 2881 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
2882 *ep = cur; 2882 *ep = cur;
2883 epipe->nexttoggle = tog; 2883 epipe->nexttoggle = tog;
2884 2884
2885 USBHIST_LOG(ehcidebug, "return sqtd=%p sqtdend=%p", 2885 USBHIST_LOG(ehcidebug, "return sqtd=%p sqtdend=%p",
2886 *sp, *ep, 0, 0); 2886 *sp, *ep, 0, 0);
2887 2887
2888 return USBD_NORMAL_COMPLETION; 2888 return USBD_NORMAL_COMPLETION;
2889 2889
2890 nomem: 2890 nomem:
2891 /* XXX free chain */ 2891 /* XXX free chain */
2892 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); 2892 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0);
2893 return USBD_NOMEM; 2893 return USBD_NOMEM;
2894} 2894}
2895 2895
2896Static void 2896Static void
2897ehci_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,
2898 ehci_soft_qtd_t *sqtdend) 2898 ehci_soft_qtd_t *sqtdend)
2899{ 2899{
2900 ehci_soft_qtd_t *p; 2900 ehci_soft_qtd_t *p;
2901 int i; 2901 int i;
2902 2902
2903 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2903 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2904 2904
2905 USBHIST_LOG(ehcidebug, "sqtd=%p sqtdend=%p", 2905 USBHIST_LOG(ehcidebug, "sqtd=%p sqtdend=%p",
2906 sqtd, sqtdend, 0, 0); 2906 sqtd, sqtdend, 0, 0);
2907 2907
2908 for (i = 0; sqtd != sqtdend; sqtd = p, i++) { 2908 for (i = 0; sqtd != sqtdend; sqtd = p, i++) {
2909 p = sqtd->nextqtd; 2909 p = sqtd->nextqtd;
2910 ehci_free_sqtd(sc, sqtd); 2910 ehci_free_sqtd(sc, sqtd);
2911 } 2911 }
2912} 2912}
2913 2913
2914Static ehci_soft_itd_t * 2914Static ehci_soft_itd_t *
2915ehci_alloc_itd(ehci_softc_t *sc) 2915ehci_alloc_itd(ehci_softc_t *sc)
2916{ 2916{
2917 struct ehci_soft_itd *itd, *freeitd; 2917 struct ehci_soft_itd *itd, *freeitd;
2918 usbd_status err; 2918 usbd_status err;
2919 int i, offs, frindex, previndex; 2919 int i, offs, frindex, previndex;
2920 usb_dma_t dma; 2920 usb_dma_t dma;
2921 2921
2922 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2922 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2923 2923
2924 mutex_enter(&sc->sc_lock); 2924 mutex_enter(&sc->sc_lock);
2925 2925
2926 /* 2926 /*
2927 * Find an itd that wasn't freed this frame or last frame. This can 2927 * Find an itd that wasn't freed this frame or last frame. This can
2928 * discard itds that were freed before frindex wrapped around 2928 * discard itds that were freed before frindex wrapped around
2929 * XXX - can this lead to thrashing? Could fix by enabling wrap-around 2929 * XXX - can this lead to thrashing? Could fix by enabling wrap-around
2930 * interrupt and fiddling with list when that happens 2930 * interrupt and fiddling with list when that happens
2931 */ 2931 */
2932 frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3; 2932 frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3;
2933 previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize; 2933 previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize;
2934 2934
2935 freeitd = NULL; 2935 freeitd = NULL;
2936 LIST_FOREACH(itd, &sc->sc_freeitds, u.free_list) { 2936 LIST_FOREACH(itd, &sc->sc_freeitds, u.free_list) {
2937 if (itd == NULL) 2937 if (itd == NULL)
2938 break; 2938 break;
2939 if (itd->slot != frindex && itd->slot != previndex) { 2939 if (itd->slot != frindex && itd->slot != previndex) {
2940 freeitd = itd; 2940 freeitd = itd;
2941 break; 2941 break;
2942 } 2942 }
2943 } 2943 }
2944 2944
2945 if (freeitd == NULL) { 2945 if (freeitd == NULL) {
2946 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); 2946 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0);
2947 err = usb_allocmem(&sc->sc_bus, EHCI_ITD_SIZE * EHCI_ITD_CHUNK, 2947 err = usb_allocmem(&sc->sc_bus, EHCI_ITD_SIZE * EHCI_ITD_CHUNK,
2948 EHCI_PAGE_SIZE, &dma); 2948 EHCI_PAGE_SIZE, &dma);
2949 2949
2950 if (err) { 2950 if (err) {
2951 USBHIST_LOG(ehcidebug, 2951 USBHIST_LOG(ehcidebug,
2952 "alloc returned %d", err, 0, 0, 0); 2952 "alloc returned %d", err, 0, 0, 0);
2953 mutex_exit(&sc->sc_lock); 2953 mutex_exit(&sc->sc_lock);
2954 return NULL; 2954 return NULL;
2955 } 2955 }
2956 2956
2957 for (i = 0; i < EHCI_ITD_CHUNK; i++) { 2957 for (i = 0; i < EHCI_ITD_CHUNK; i++) {
2958 offs = i * EHCI_ITD_SIZE; 2958 offs = i * EHCI_ITD_SIZE;
2959 itd = KERNADDR(&dma, offs); 2959 itd = KERNADDR(&dma, offs);
2960 itd->physaddr = DMAADDR(&dma, offs); 2960 itd->physaddr = DMAADDR(&dma, offs);
2961 itd->dma = dma; 2961 itd->dma = dma;
2962 itd->offs = offs; 2962 itd->offs = offs;
2963 LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list); 2963 LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list);
2964 } 2964 }
2965 freeitd = LIST_FIRST(&sc->sc_freeitds); 2965 freeitd = LIST_FIRST(&sc->sc_freeitds);
2966 } 2966 }
2967 2967
2968 itd = freeitd; 2968 itd = freeitd;
2969 LIST_REMOVE(itd, u.free_list); 2969 LIST_REMOVE(itd, u.free_list);
2970 memset(&itd->itd, 0, sizeof(ehci_itd_t)); 2970 memset(&itd->itd, 0, sizeof(ehci_itd_t));
2971 usb_syncmem(&itd->dma, itd->offs + offsetof(ehci_itd_t, itd_next), 2971 usb_syncmem(&itd->dma, itd->offs + offsetof(ehci_itd_t, itd_next),
2972 sizeof(itd->itd.itd_next), 2972 sizeof(itd->itd.itd_next),
2973 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 2973 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
2974 2974
2975 itd->u.frame_list.next = NULL; 2975 itd->u.frame_list.next = NULL;
2976 itd->u.frame_list.prev = NULL; 2976 itd->u.frame_list.prev = NULL;
2977 itd->xfer_next = NULL; 2977 itd->xfer_next = NULL;
2978 itd->slot = 0; 2978 itd->slot = 0;
2979 2979
2980 mutex_exit(&sc->sc_lock); 2980 mutex_exit(&sc->sc_lock);
2981 2981
2982 return itd; 2982 return itd;
2983} 2983}
2984 2984
2985Static ehci_soft_sitd_t * 2985Static ehci_soft_sitd_t *
2986ehci_alloc_sitd(ehci_softc_t *sc) 2986ehci_alloc_sitd(ehci_softc_t *sc)
2987{ 2987{
2988 struct ehci_soft_sitd *sitd, *freesitd; 2988 struct ehci_soft_sitd *sitd, *freesitd;
2989 usbd_status err; 2989 usbd_status err;
2990 int i, offs, frindex, previndex; 2990 int i, offs, frindex, previndex;
2991 usb_dma_t dma; 2991 usb_dma_t dma;
2992 2992
2993 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 2993 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
2994 2994
2995 mutex_enter(&sc->sc_lock); 2995 mutex_enter(&sc->sc_lock);
2996 2996
2997 /* 2997 /*
2998 * Find an sitd that wasn't freed this frame or last frame. This can 2998 * Find an sitd that wasn't freed this frame or last frame. This can
2999 * discard sitds that were freed before frindex wrapped around 2999 * discard sitds that were freed before frindex wrapped around
3000 * XXX - can this lead to thrashing? Could fix by enabling wrap-around 3000 * XXX - can this lead to thrashing? Could fix by enabling wrap-around
3001 * interrupt and fiddling with list when that happens 3001 * interrupt and fiddling with list when that happens
3002 */ 3002 */
3003 frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3; 3003 frindex = (EOREAD4(sc, EHCI_FRINDEX) + 1) >> 3;
3004 previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize; 3004 previndex = (frindex != 0) ? frindex - 1 : sc->sc_flsize;
3005 3005
3006 freesitd = NULL; 3006 freesitd = NULL;
3007 LIST_FOREACH(sitd, &sc->sc_freesitds, u.free_list) { 3007 LIST_FOREACH(sitd, &sc->sc_freesitds, u.free_list) {
3008 if (sitd == NULL) 3008 if (sitd == NULL)
3009 break; 3009 break;
3010 if (sitd->slot != frindex && sitd->slot != previndex) { 3010 if (sitd->slot != frindex && sitd->slot != previndex) {
3011 freesitd = sitd; 3011 freesitd = sitd;
3012 break; 3012 break;
3013 } 3013 }
3014 } 3014 }
3015 3015
3016 if (freesitd == NULL) { 3016 if (freesitd == NULL) {
3017 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0); 3017 USBHIST_LOG(ehcidebug, "allocating chunk", 0, 0, 0, 0);
3018 err = usb_allocmem(&sc->sc_bus, EHCI_SITD_SIZE * EHCI_SITD_CHUNK, 3018 err = usb_allocmem(&sc->sc_bus, EHCI_SITD_SIZE * EHCI_SITD_CHUNK,
3019 EHCI_PAGE_SIZE, &dma); 3019 EHCI_PAGE_SIZE, &dma);
3020 3020
3021 if (err) { 3021 if (err) {
3022 USBHIST_LOG(ehcidebug, 3022 USBHIST_LOG(ehcidebug,
3023 "alloc returned %d", err, 0, 0, 0); 3023 "alloc returned %d", err, 0, 0, 0);
3024 mutex_exit(&sc->sc_lock); 3024 mutex_exit(&sc->sc_lock);
3025 return NULL; 3025 return NULL;
3026 } 3026 }
3027 3027
3028 for (i = 0; i < EHCI_SITD_CHUNK; i++) { 3028 for (i = 0; i < EHCI_SITD_CHUNK; i++) {
3029 offs = i * EHCI_SITD_SIZE; 3029 offs = i * EHCI_SITD_SIZE;
3030 sitd = KERNADDR(&dma, offs); 3030 sitd = KERNADDR(&dma, offs);
3031 sitd->physaddr = DMAADDR(&dma, offs); 3031 sitd->physaddr = DMAADDR(&dma, offs);
3032 sitd->dma = dma; 3032 sitd->dma = dma;
3033 sitd->offs = offs; 3033 sitd->offs = offs;
3034 LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list); 3034 LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list);
3035 } 3035 }
3036 freesitd = LIST_FIRST(&sc->sc_freesitds); 3036 freesitd = LIST_FIRST(&sc->sc_freesitds);
3037 } 3037 }
3038 3038
3039 sitd = freesitd; 3039 sitd = freesitd;
3040 LIST_REMOVE(sitd, u.free_list); 3040 LIST_REMOVE(sitd, u.free_list);
3041 memset(&sitd->sitd, 0, sizeof(ehci_sitd_t)); 3041 memset(&sitd->sitd, 0, sizeof(ehci_sitd_t));
3042 usb_syncmem(&sitd->dma, sitd->offs + offsetof(ehci_sitd_t, sitd_next), 3042 usb_syncmem(&sitd->dma, sitd->offs + offsetof(ehci_sitd_t, sitd_next),
3043 sizeof(sitd->sitd.sitd_next), BUS_DMASYNC_PREWRITE | 3043 sizeof(sitd->sitd.sitd_next), BUS_DMASYNC_PREWRITE |
3044 BUS_DMASYNC_PREREAD); 3044 BUS_DMASYNC_PREREAD);
3045 3045
3046 sitd->u.frame_list.next = NULL; 3046 sitd->u.frame_list.next = NULL;
3047 sitd->u.frame_list.prev = NULL; 3047 sitd->u.frame_list.prev = NULL;
3048 sitd->xfer_next = NULL; 3048 sitd->xfer_next = NULL;
3049 sitd->slot = 0; 3049 sitd->slot = 0;
3050 3050
3051 mutex_exit(&sc->sc_lock); 3051 mutex_exit(&sc->sc_lock);
3052 3052
3053 return sitd; 3053 return sitd;
3054} 3054}
3055 3055
3056Static void 3056Static void
3057ehci_free_itd(ehci_softc_t *sc, ehci_soft_itd_t *itd) 3057ehci_free_itd(ehci_softc_t *sc, ehci_soft_itd_t *itd)
3058{ 3058{
3059 3059
3060 KASSERT(mutex_owned(&sc->sc_lock)); 3060 KASSERT(mutex_owned(&sc->sc_lock));
3061 3061
3062 LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list); 3062 LIST_INSERT_HEAD(&sc->sc_freeitds, itd, u.free_list);
3063} 3063}
3064 3064
3065Static void 3065Static void
3066ehci_free_sitd(ehci_softc_t *sc, ehci_soft_sitd_t *sitd) 3066ehci_free_sitd(ehci_softc_t *sc, ehci_soft_sitd_t *sitd)
3067{ 3067{
3068 3068
3069 KASSERT(mutex_owned(&sc->sc_lock)); 3069 KASSERT(mutex_owned(&sc->sc_lock));
3070 3070
3071 LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list); 3071 LIST_INSERT_HEAD(&sc->sc_freesitds, sitd, u.free_list);
3072} 3072}
3073 3073
3074/****************/ 3074/****************/
3075 3075
3076/* 3076/*
3077 * Close a reqular pipe. 3077 * Close a reqular pipe.
3078 * Assumes that there are no pending transactions. 3078 * Assumes that there are no pending transactions.
3079 */ 3079 */
3080Static void 3080Static void
3081ehci_close_pipe(usbd_pipe_handle pipe, ehci_soft_qh_t *head) 3081ehci_close_pipe(usbd_pipe_handle pipe, ehci_soft_qh_t *head)
3082{ 3082{
3083 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; 3083 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;
3084 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; 3084 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
3085 ehci_soft_qh_t *sqh = epipe->sqh; 3085 ehci_soft_qh_t *sqh = epipe->sqh;
3086 3086
3087 KASSERT(mutex_owned(&sc->sc_lock)); 3087 KASSERT(mutex_owned(&sc->sc_lock));
3088 3088
3089 ehci_rem_qh(sc, sqh, head); 3089 ehci_rem_qh(sc, sqh, head);
3090 ehci_free_sqh(sc, epipe->sqh); 3090 ehci_free_sqh(sc, epipe->sqh);
3091} 3091}
3092 3092
3093/* 3093/*
3094 * Abort a device request. 3094 * Abort a device request.
3095 * If this routine is called at splusb() it guarantees that the request 3095 * If this routine is called at splusb() it guarantees that the request
3096 * will be removed from the hardware scheduling and that the callback 3096 * will be removed from the hardware scheduling and that the callback
3097 * for it will be called with USBD_CANCELLED status. 3097 * for it will be called with USBD_CANCELLED status.
3098 * It's impossible to guarantee that the requested transfer will not 3098 * It's impossible to guarantee that the requested transfer will not
3099 * have happened since the hardware runs concurrently. 3099 * have happened since the hardware runs concurrently.
3100 * If the transaction has already happened we rely on the ordinary 3100 * If the transaction has already happened we rely on the ordinary
3101 * interrupt processing to process it. 3101 * interrupt processing to process it.
3102 * XXX This is most probably wrong. 3102 * XXX This is most probably wrong.
3103 * XXXMRG this doesn't make sense anymore. 3103 * XXXMRG this doesn't make sense anymore.
3104 */ 3104 */
3105Static void 3105Static void
3106ehci_abort_xfer(usbd_xfer_handle xfer, usbd_status status) 3106ehci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
3107{ 3107{
3108#define exfer EXFER(xfer) 3108#define exfer EXFER(xfer)
3109 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; 3109 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe;
3110 ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; 3110 ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv;
3111 ehci_soft_qh_t *sqh = epipe->sqh; 3111 ehci_soft_qh_t *sqh = epipe->sqh;
3112 ehci_soft_qtd_t *sqtd; 3112 ehci_soft_qtd_t *sqtd;
3113 ehci_physaddr_t cur; 3113 ehci_physaddr_t cur;
3114 uint32_t qhstatus; 3114 uint32_t qhstatus;
3115 int hit; 3115 int hit;
3116 int wake; 3116 int wake;
3117 3117
3118 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3118 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3119 3119
3120 USBHIST_LOG(ehcidebug, "xfer=%p pipe=%p", xfer, epipe, 0, 0); 3120 USBHIST_LOG(ehcidebug, "xfer=%p pipe=%p", xfer, epipe, 0, 0);
3121 3121
3122 KASSERT(mutex_owned(&sc->sc_lock)); 3122 KASSERT(mutex_owned(&sc->sc_lock));
3123 ASSERT_SLEEPABLE(); 3123 ASSERT_SLEEPABLE();
3124 3124
3125 if (sc->sc_dying) { 3125 if (sc->sc_dying) {
3126 /* If we're dying, just do the software part. */ 3126 /* If we're dying, just do the software part. */
3127 xfer->ux_status = status; /* make software ignore it */ 3127 xfer->ux_status = status; /* make software ignore it */
3128 callout_stop(&xfer->ux_callout); 3128 callout_stop(&xfer->ux_callout);
3129 usb_transfer_complete(xfer); 3129 usb_transfer_complete(xfer);
3130 return; 3130 return;
3131 } 3131 }
3132 3132
3133 /* 3133 /*
3134 * If an abort is already in progress then just wait for it to 3134 * If an abort is already in progress then just wait for it to
3135 * complete and return. 3135 * complete and return.
3136 */ 3136 */
3137 if (xfer->ux_hcflags & UXFER_ABORTING) { 3137 if (xfer->ux_hcflags & UXFER_ABORTING) {
3138 USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0); 3138 USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0);
3139#ifdef DIAGNOSTIC 3139#ifdef DIAGNOSTIC
3140 if (status == USBD_TIMEOUT) 3140 if (status == USBD_TIMEOUT)
3141 printf("ehci_abort_xfer: TIMEOUT while aborting\n"); 3141 printf("ehci_abort_xfer: TIMEOUT while aborting\n");
3142#endif 3142#endif
3143 /* Override the status which might be USBD_TIMEOUT. */ 3143 /* Override the status which might be USBD_TIMEOUT. */
3144 xfer->ux_status = status; 3144 xfer->ux_status = status;
3145 USBHIST_LOG(ehcidebug, "waiting for abort to finish", 3145 USBHIST_LOG(ehcidebug, "waiting for abort to finish",
3146 0, 0, 0, 0); 3146 0, 0, 0, 0);
3147 xfer->ux_hcflags |= UXFER_ABORTWAIT; 3147 xfer->ux_hcflags |= UXFER_ABORTWAIT;
3148 while (xfer->ux_hcflags & UXFER_ABORTING) 3148 while (xfer->ux_hcflags & UXFER_ABORTING)
3149 cv_wait(&xfer->ux_hccv, &sc->sc_lock); 3149 cv_wait(&xfer->ux_hccv, &sc->sc_lock);
3150 return; 3150 return;
3151 } 3151 }
3152 xfer->ux_hcflags |= UXFER_ABORTING; 3152 xfer->ux_hcflags |= UXFER_ABORTING;
3153 3153
3154 /* 3154 /*
3155 * Step 1: Make interrupt routine and hardware ignore xfer. 3155 * Step 1: Make interrupt routine and hardware ignore xfer.
3156 */ 3156 */
3157 xfer->ux_status = status; /* make software ignore it */ 3157 xfer->ux_status = status; /* make software ignore it */
3158 callout_stop(&xfer->ux_callout); 3158 callout_stop(&xfer->ux_callout);
3159 3159
3160 usb_syncmem(&sqh->dma, 3160 usb_syncmem(&sqh->dma,
3161 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), 3161 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status),
3162 sizeof(sqh->qh.qh_qtd.qtd_status), 3162 sizeof(sqh->qh.qh_qtd.qtd_status),
3163 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 3163 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
3164 qhstatus = sqh->qh.qh_qtd.qtd_status; 3164 qhstatus = sqh->qh.qh_qtd.qtd_status;
3165 sqh->qh.qh_qtd.qtd_status = qhstatus | htole32(EHCI_QTD_HALTED); 3165 sqh->qh.qh_qtd.qtd_status = qhstatus | htole32(EHCI_QTD_HALTED);
3166 usb_syncmem(&sqh->dma, 3166 usb_syncmem(&sqh->dma,
3167 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), 3167 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status),
3168 sizeof(sqh->qh.qh_qtd.qtd_status), 3168 sizeof(sqh->qh.qh_qtd.qtd_status),
3169 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3169 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3170 for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) { 3170 for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) {
3171 usb_syncmem(&sqtd->dma, 3171 usb_syncmem(&sqtd->dma,
3172 sqtd->offs + offsetof(ehci_qtd_t, qtd_status), 3172 sqtd->offs + offsetof(ehci_qtd_t, qtd_status),
3173 sizeof(sqtd->qtd.qtd_status), 3173 sizeof(sqtd->qtd.qtd_status),
3174 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 3174 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
3175 sqtd->qtd.qtd_status |= htole32(EHCI_QTD_HALTED); 3175 sqtd->qtd.qtd_status |= htole32(EHCI_QTD_HALTED);
3176 usb_syncmem(&sqtd->dma, 3176 usb_syncmem(&sqtd->dma,
3177 sqtd->offs + offsetof(ehci_qtd_t, qtd_status), 3177 sqtd->offs + offsetof(ehci_qtd_t, qtd_status),
3178 sizeof(sqtd->qtd.qtd_status), 3178 sizeof(sqtd->qtd.qtd_status),
3179 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3179 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3180 if (sqtd == exfer->ex_sqtdend) 3180 if (sqtd == exfer->ex_sqtdend)
3181 break; 3181 break;
3182 } 3182 }
3183 3183
3184 /* 3184 /*
3185 * Step 2: Wait until we know hardware has finished any possible 3185 * Step 2: Wait until we know hardware has finished any possible
3186 * use of the xfer. Also make sure the soft interrupt routine 3186 * use of the xfer. Also make sure the soft interrupt routine
3187 * has run. 3187 * has run.
3188 */ 3188 */
3189 ehci_sync_hc(sc); 3189 ehci_sync_hc(sc);
3190 sc->sc_softwake = 1; 3190 sc->sc_softwake = 1;
3191 usb_schedsoftintr(&sc->sc_bus); 3191 usb_schedsoftintr(&sc->sc_bus);
3192 cv_wait(&sc->sc_softwake_cv, &sc->sc_lock); 3192 cv_wait(&sc->sc_softwake_cv, &sc->sc_lock);
3193 3193
3194 /* 3194 /*
3195 * Step 3: Remove any vestiges of the xfer from the hardware. 3195 * Step 3: Remove any vestiges of the xfer from the hardware.
3196 * The complication here is that the hardware may have executed 3196 * The complication here is that the hardware may have executed
3197 * beyond the xfer we're trying to abort. So as we're scanning 3197 * beyond the xfer we're trying to abort. So as we're scanning
3198 * the TDs of this xfer we check if the hardware points to 3198 * the TDs of this xfer we check if the hardware points to
3199 * any of them. 3199 * any of them.
3200 */ 3200 */
3201 3201
3202 usb_syncmem(&sqh->dma, 3202 usb_syncmem(&sqh->dma,
3203 sqh->offs + offsetof(ehci_qh_t, qh_curqtd), 3203 sqh->offs + offsetof(ehci_qh_t, qh_curqtd),
3204 sizeof(sqh->qh.qh_curqtd), 3204 sizeof(sqh->qh.qh_curqtd),
3205 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 3205 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
3206 cur = EHCI_LINK_ADDR(le32toh(sqh->qh.qh_curqtd)); 3206 cur = EHCI_LINK_ADDR(le32toh(sqh->qh.qh_curqtd));
3207 hit = 0; 3207 hit = 0;
3208 for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) { 3208 for (sqtd = exfer->ex_sqtdstart; ; sqtd = sqtd->nextqtd) {
3209 hit |= cur == sqtd->physaddr; 3209 hit |= cur == sqtd->physaddr;
3210 if (sqtd == exfer->ex_sqtdend) 3210 if (sqtd == exfer->ex_sqtdend)
3211 break; 3211 break;
3212 } 3212 }
3213 sqtd = sqtd->nextqtd; 3213 sqtd = sqtd->nextqtd;
3214 /* Zap curqtd register if hardware pointed inside the xfer. */ 3214 /* Zap curqtd register if hardware pointed inside the xfer. */
3215 if (hit && sqtd != NULL) { 3215 if (hit && sqtd != NULL) {
3216 USBHIST_LOG(ehcidebug, "cur=0x%08x", sqtd->physaddr, 0, 0, 0); 3216 USBHIST_LOG(ehcidebug, "cur=0x%08x", sqtd->physaddr, 0, 0, 0);
3217 sqh->qh.qh_curqtd = htole32(sqtd->physaddr); /* unlink qTDs */ 3217 sqh->qh.qh_curqtd = htole32(sqtd->physaddr); /* unlink qTDs */
3218 usb_syncmem(&sqh->dma, 3218 usb_syncmem(&sqh->dma,
3219 sqh->offs + offsetof(ehci_qh_t, qh_curqtd), 3219 sqh->offs + offsetof(ehci_qh_t, qh_curqtd),
3220 sizeof(sqh->qh.qh_curqtd), 3220 sizeof(sqh->qh.qh_curqtd),
3221 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3221 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3222 sqh->qh.qh_qtd.qtd_status = qhstatus; 3222 sqh->qh.qh_qtd.qtd_status = qhstatus;
3223 usb_syncmem(&sqh->dma, 3223 usb_syncmem(&sqh->dma,
3224 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status), 3224 sqh->offs + offsetof(ehci_qh_t, qh_qtd.qtd_status),
3225 sizeof(sqh->qh.qh_qtd.qtd_status), 3225 sizeof(sqh->qh.qh_qtd.qtd_status),
3226 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3226 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3227 } else { 3227 } else {
3228 USBHIST_LOG(ehcidebug, "no hit", 0, 0, 0, 0); 3228 USBHIST_LOG(ehcidebug, "no hit", 0, 0, 0, 0);
3229 } 3229 }
3230 3230
3231 /* 3231 /*
3232 * Step 4: Execute callback. 3232 * Step 4: Execute callback.
3233 */ 3233 */
3234#ifdef DIAGNOSTIC 3234#ifdef DIAGNOSTIC
3235 exfer->ex_isdone = true; 3235 exfer->ex_isdone = true;
3236#endif 3236#endif
3237 wake = xfer->ux_hcflags & UXFER_ABORTWAIT; 3237 wake = xfer->ux_hcflags & UXFER_ABORTWAIT;
3238 xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT); 3238 xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT);
3239 usb_transfer_complete(xfer); 3239 usb_transfer_complete(xfer);
3240 if (wake) { 3240 if (wake) {
3241 cv_broadcast(&xfer->ux_hccv); 3241 cv_broadcast(&xfer->ux_hccv);
3242 } 3242 }
3243 3243
3244 KASSERT(mutex_owned(&sc->sc_lock)); 3244 KASSERT(mutex_owned(&sc->sc_lock));
3245#undef exfer 3245#undef exfer
3246} 3246}
3247 3247
3248Static void 3248Static void
3249ehci_abort_isoc_xfer(usbd_xfer_handle xfer, usbd_status status) 3249ehci_abort_isoc_xfer(usbd_xfer_handle xfer, usbd_status status)
3250{ 3250{
3251 ehci_isoc_trans_t trans_status; 3251 ehci_isoc_trans_t trans_status;
3252 struct ehci_pipe *epipe; 3252 struct ehci_pipe *epipe;
3253 struct ehci_xfer *exfer; 3253 struct ehci_xfer *exfer;
3254 ehci_softc_t *sc; 3254 ehci_softc_t *sc;
3255 struct ehci_soft_itd *itd; 3255 struct ehci_soft_itd *itd;
3256 struct ehci_soft_sitd *sitd; 3256 struct ehci_soft_sitd *sitd;
3257 int i, wake; 3257 int i, wake;
3258 3258
3259 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3259 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3260 3260
3261 epipe = (struct ehci_pipe *) xfer->ux_pipe; 3261 epipe = (struct ehci_pipe *) xfer->ux_pipe;
3262 exfer = EXFER(xfer); 3262 exfer = EXFER(xfer);
3263 sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; 3263 sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv;
3264 3264
3265 USBHIST_LOG(ehcidebug, "xfer %p pipe %p", xfer, epipe, 0, 0); 3265 USBHIST_LOG(ehcidebug, "xfer %p pipe %p", xfer, epipe, 0, 0);
3266 3266
3267 KASSERT(mutex_owned(&sc->sc_lock)); 3267 KASSERT(mutex_owned(&sc->sc_lock));
3268 3268
3269 if (sc->sc_dying) { 3269 if (sc->sc_dying) {
3270 xfer->ux_status = status; 3270 xfer->ux_status = status;
3271 callout_stop(&xfer->ux_callout); 3271 callout_stop(&xfer->ux_callout);
3272 usb_transfer_complete(xfer); 3272 usb_transfer_complete(xfer);
3273 return; 3273 return;
3274 } 3274 }
3275 3275
3276 if (xfer->ux_hcflags & UXFER_ABORTING) { 3276 if (xfer->ux_hcflags & UXFER_ABORTING) {
3277 USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0); 3277 USBHIST_LOG(ehcidebug, "already aborting", 0, 0, 0, 0);
3278 3278
3279#ifdef DIAGNOSTIC 3279#ifdef DIAGNOSTIC
3280 if (status == USBD_TIMEOUT) 3280 if (status == USBD_TIMEOUT)
3281 printf("ehci_abort_isoc_xfer: TIMEOUT while aborting\n"); 3281 printf("ehci_abort_isoc_xfer: TIMEOUT while aborting\n");
3282#endif 3282#endif
3283 3283
3284 xfer->ux_status = status; 3284 xfer->ux_status = status;
3285 USBHIST_LOG(ehcidebug, 3285 USBHIST_LOG(ehcidebug,
3286 "waiting for abort to finish", 0, 0, 0, 0); 3286 "waiting for abort to finish", 0, 0, 0, 0);
3287 xfer->ux_hcflags |= UXFER_ABORTWAIT; 3287 xfer->ux_hcflags |= UXFER_ABORTWAIT;
3288 while (xfer->ux_hcflags & UXFER_ABORTING) 3288 while (xfer->ux_hcflags & UXFER_ABORTING)
3289 cv_wait(&xfer->ux_hccv, &sc->sc_lock); 3289 cv_wait(&xfer->ux_hccv, &sc->sc_lock);
3290 goto done; 3290 goto done;
3291 } 3291 }
3292 xfer->ux_hcflags |= UXFER_ABORTING; 3292 xfer->ux_hcflags |= UXFER_ABORTING;
3293 3293
3294 xfer->ux_status = status; 3294 xfer->ux_status = status;
3295 callout_stop(&xfer->ux_callout); 3295 callout_stop(&xfer->ux_callout);
3296 3296
3297 if (xfer->ux_pipe->up_dev->ud_speed == USB_SPEED_HIGH) { 3297 if (xfer->ux_pipe->up_dev->ud_speed == USB_SPEED_HIGH) {
3298 for (itd = exfer->ex_itdstart; itd != NULL; 3298 for (itd = exfer->ex_itdstart; itd != NULL;
3299 itd = itd->xfer_next) { 3299 itd = itd->xfer_next) {
3300 usb_syncmem(&itd->dma, 3300 usb_syncmem(&itd->dma,
3301 itd->offs + offsetof(ehci_itd_t, itd_ctl), 3301 itd->offs + offsetof(ehci_itd_t, itd_ctl),
3302 sizeof(itd->itd.itd_ctl), 3302 sizeof(itd->itd.itd_ctl),
3303 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 3303 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
3304 3304
3305 for (i = 0; i < 8; i++) { 3305 for (i = 0; i < 8; i++) {
3306 trans_status = le32toh(itd->itd.itd_ctl[i]); 3306 trans_status = le32toh(itd->itd.itd_ctl[i]);
3307 trans_status &= ~EHCI_ITD_ACTIVE; 3307 trans_status &= ~EHCI_ITD_ACTIVE;
3308 itd->itd.itd_ctl[i] = htole32(trans_status); 3308 itd->itd.itd_ctl[i] = htole32(trans_status);
3309 } 3309 }
3310 3310
3311 usb_syncmem(&itd->dma, 3311 usb_syncmem(&itd->dma,
3312 itd->offs + offsetof(ehci_itd_t, itd_ctl), 3312 itd->offs + offsetof(ehci_itd_t, itd_ctl),
3313 sizeof(itd->itd.itd_ctl), 3313 sizeof(itd->itd.itd_ctl),
3314 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3314 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3315 } 3315 }
3316 } else { 3316 } else {
3317 for (sitd = exfer->ex_sitdstart; sitd != NULL; 3317 for (sitd = exfer->ex_sitdstart; sitd != NULL;
3318 sitd = sitd->xfer_next) { 3318 sitd = sitd->xfer_next) {
3319 usb_syncmem(&sitd->dma, 3319 usb_syncmem(&sitd->dma,
3320 sitd->offs + offsetof(ehci_sitd_t, sitd_buffer), 3320 sitd->offs + offsetof(ehci_sitd_t, sitd_buffer),
3321 sizeof(sitd->sitd.sitd_buffer), 3321 sizeof(sitd->sitd.sitd_buffer),
3322 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 3322 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
3323 3323
3324 trans_status = le32toh(sitd->sitd.sitd_trans); 3324 trans_status = le32toh(sitd->sitd.sitd_trans);
3325 trans_status &= ~EHCI_SITD_ACTIVE; 3325 trans_status &= ~EHCI_SITD_ACTIVE;
3326 sitd->sitd.sitd_trans = htole32(trans_status); 3326 sitd->sitd.sitd_trans = htole32(trans_status);
3327 3327
3328 usb_syncmem(&sitd->dma, 3328 usb_syncmem(&sitd->dma,
3329 sitd->offs + offsetof(ehci_sitd_t, sitd_buffer), 3329 sitd->offs + offsetof(ehci_sitd_t, sitd_buffer),
3330 sizeof(sitd->sitd.sitd_buffer), 3330 sizeof(sitd->sitd.sitd_buffer),
3331 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3331 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3332 } 3332 }
3333 } 3333 }
3334 3334
3335 sc->sc_softwake = 1; 3335 sc->sc_softwake = 1;
3336 usb_schedsoftintr(&sc->sc_bus); 3336 usb_schedsoftintr(&sc->sc_bus);
3337 cv_wait(&sc->sc_softwake_cv, &sc->sc_lock); 3337 cv_wait(&sc->sc_softwake_cv, &sc->sc_lock);
3338 3338
3339#ifdef DIAGNOSTIC 3339#ifdef DIAGNOSTIC
3340 exfer->ex_isdone = true; 3340 exfer->ex_isdone = true;
3341#endif 3341#endif
3342 wake = xfer->ux_hcflags & UXFER_ABORTWAIT; 3342 wake = xfer->ux_hcflags & UXFER_ABORTWAIT;
3343 xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT); 3343 xfer->ux_hcflags &= ~(UXFER_ABORTING | UXFER_ABORTWAIT);
3344 usb_transfer_complete(xfer); 3344 usb_transfer_complete(xfer);
3345 if (wake) { 3345 if (wake) {
3346 cv_broadcast(&xfer->ux_hccv); 3346 cv_broadcast(&xfer->ux_hccv);
3347 } 3347 }
3348 3348
3349done: 3349done:
3350 KASSERT(mutex_owned(&sc->sc_lock)); 3350 KASSERT(mutex_owned(&sc->sc_lock));
3351 return; 3351 return;
3352} 3352}
3353 3353
3354Static void 3354Static void
3355ehci_timeout(void *addr) 3355ehci_timeout(void *addr)
3356{ 3356{
3357 struct ehci_xfer *exfer = addr; 3357 struct ehci_xfer *exfer = addr;
3358 struct ehci_pipe *epipe = (struct ehci_pipe *)exfer->ex_xfer.ux_pipe; 3358 struct ehci_pipe *epipe = (struct ehci_pipe *)exfer->ex_xfer.ux_pipe;
3359 ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv; 3359 ehci_softc_t *sc = epipe->pipe.up_dev->ud_bus->ub_hcpriv;
3360 3360
3361 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3361 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3362 3362
3363 USBHIST_LOG(ehcidebug, "exfer %p", exfer, 0, 0, 0); 3363 USBHIST_LOG(ehcidebug, "exfer %p", exfer, 0, 0, 0);
3364#ifdef EHCI_DEBUG 3364#ifdef EHCI_DEBUG
3365 if (ehcidebug > 1) 3365 if (ehcidebug > 1)
3366 usbd_dump_pipe(exfer->ex_xfer.ux_pipe); 3366 usbd_dump_pipe(exfer->ex_xfer.ux_pipe);
3367#endif 3367#endif
3368 3368
3369 if (sc->sc_dying) { 3369 if (sc->sc_dying) {
3370 mutex_enter(&sc->sc_lock); 3370 mutex_enter(&sc->sc_lock);
3371 ehci_abort_xfer(&exfer->ex_xfer, USBD_TIMEOUT); 3371 ehci_abort_xfer(&exfer->ex_xfer, USBD_TIMEOUT);
3372 mutex_exit(&sc->sc_lock); 3372 mutex_exit(&sc->sc_lock);
3373 return; 3373 return;
3374 } 3374 }
3375 3375
3376 /* Execute the abort in a process context. */ 3376 /* Execute the abort in a process context. */
3377 usb_init_task(&exfer->ex_aborttask, ehci_timeout_task, addr, 3377 usb_init_task(&exfer->ex_aborttask, ehci_timeout_task, addr,
3378 USB_TASKQ_MPSAFE); 3378 USB_TASKQ_MPSAFE);
3379 usb_add_task(exfer->ex_xfer.ux_pipe->up_dev, &exfer->ex_aborttask, 3379 usb_add_task(exfer->ex_xfer.ux_pipe->up_dev, &exfer->ex_aborttask,
3380 USB_TASKQ_HC); 3380 USB_TASKQ_HC);
3381} 3381}
3382 3382
3383Static void 3383Static void
3384ehci_timeout_task(void *addr) 3384ehci_timeout_task(void *addr)
3385{ 3385{
3386 usbd_xfer_handle xfer = addr; 3386 usbd_xfer_handle xfer = addr;
3387 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3387 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
3388 3388
3389 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3389 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3390 3390
3391 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); 3391 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0);
3392 3392
3393 mutex_enter(&sc->sc_lock); 3393 mutex_enter(&sc->sc_lock);
3394 ehci_abort_xfer(xfer, USBD_TIMEOUT); 3394 ehci_abort_xfer(xfer, USBD_TIMEOUT);
3395 mutex_exit(&sc->sc_lock); 3395 mutex_exit(&sc->sc_lock);
3396} 3396}
3397 3397
3398/************************/ 3398/************************/
3399 3399
3400Static usbd_status 3400Static usbd_status
3401ehci_device_ctrl_transfer(usbd_xfer_handle xfer) 3401ehci_device_ctrl_transfer(usbd_xfer_handle xfer)
3402{ 3402{
3403 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3403 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
3404 usbd_status err; 3404 usbd_status err;
3405 3405
3406 /* Insert last in queue. */ 3406 /* Insert last in queue. */
3407 mutex_enter(&sc->sc_lock); 3407 mutex_enter(&sc->sc_lock);
3408 err = usb_insert_transfer(xfer); 3408 err = usb_insert_transfer(xfer);
3409 mutex_exit(&sc->sc_lock); 3409 mutex_exit(&sc->sc_lock);
3410 if (err) 3410 if (err)
3411 return err; 3411 return err;
3412 3412
3413 /* Pipe isn't running, start first */ 3413 /* Pipe isn't running, start first */
3414 return ehci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); 3414 return ehci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue));
3415} 3415}
3416 3416
3417Static usbd_status 3417Static usbd_status
3418ehci_device_ctrl_start(usbd_xfer_handle xfer) 3418ehci_device_ctrl_start(usbd_xfer_handle xfer)
3419{ 3419{
3420 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3420 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
3421 usbd_status err; 3421 usbd_status err;
3422 3422
3423 if (sc->sc_dying) 3423 if (sc->sc_dying)
3424 return USBD_IOERROR; 3424 return USBD_IOERROR;
3425 3425
3426 KASSERT(xfer->ux_rqflags & URQ_REQUEST); 3426 KASSERT(xfer->ux_rqflags & URQ_REQUEST);
3427 3427
3428 err = ehci_device_request(xfer); 3428 err = ehci_device_request(xfer);
3429 if (err) { 3429 if (err) {
3430 return err; 3430 return err;
3431 } 3431 }
3432 3432
3433 if (sc->sc_bus.ub_usepolling) 3433 if (sc->sc_bus.ub_usepolling)
3434 ehci_waitintr(sc, xfer); 3434 ehci_waitintr(sc, xfer);
3435 3435
3436 return USBD_IN_PROGRESS; 3436 return USBD_IN_PROGRESS;
3437} 3437}
3438 3438
3439Static void 3439Static void
3440ehci_device_ctrl_done(usbd_xfer_handle xfer) 3440ehci_device_ctrl_done(usbd_xfer_handle xfer)
3441{ 3441{
3442 struct ehci_xfer *ex = EXFER(xfer); 3442 struct ehci_xfer *ex = EXFER(xfer);
3443 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3443 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
3444 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; 3444 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe;
3445 usb_device_request_t *req = &xfer->ux_request; 3445 usb_device_request_t *req = &xfer->ux_request;
3446 int len = UGETW(req->wLength); 3446 int len = UGETW(req->wLength);
3447 int rd = req->bmRequestType & UT_READ; 3447 int rd = req->bmRequestType & UT_READ;
3448 3448
3449 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3449 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3450 3450
3451 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); 3451 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0);
3452 3452
3453 KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); 3453 KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock));
3454 KASSERT(xfer->ux_rqflags & URQ_REQUEST); 3454 KASSERT(xfer->ux_rqflags & URQ_REQUEST);
3455 3455
3456 if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { 3456 if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) {
3457 ehci_del_intr_list(sc, ex); /* remove from active list */ 3457 ehci_del_intr_list(sc, ex); /* remove from active list */
3458 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); 3458 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL);
3459 usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req), 3459 usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req),
3460 BUS_DMASYNC_POSTWRITE); 3460 BUS_DMASYNC_POSTWRITE);
3461 if (len) 3461 if (len)
3462 usb_syncmem(&xfer->ux_dmabuf, 0, len, 3462 usb_syncmem(&xfer->ux_dmabuf, 0, len,
3463 rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); 3463 rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
3464 } 3464 }
3465 3465
3466 USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0); 3466 USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0);
3467} 3467}
3468 3468
3469/* Abort a device control request. */ 3469/* Abort a device control request. */
3470Static void 3470Static void
3471ehci_device_ctrl_abort(usbd_xfer_handle xfer) 3471ehci_device_ctrl_abort(usbd_xfer_handle xfer)
3472{ 3472{
3473 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3473 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3474 3474
3475 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); 3475 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0);
3476 ehci_abort_xfer(xfer, USBD_CANCELLED); 3476 ehci_abort_xfer(xfer, USBD_CANCELLED);
3477} 3477}
3478 3478
3479/* Close a device control pipe. */ 3479/* Close a device control pipe. */
3480Static void 3480Static void
3481ehci_device_ctrl_close(usbd_pipe_handle pipe) 3481ehci_device_ctrl_close(usbd_pipe_handle pipe)
3482{ 3482{
3483 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; 3483 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
3484 /*struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;*/ 3484 /*struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;*/
3485 3485
3486 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3486 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3487 3487
3488 KASSERT(mutex_owned(&sc->sc_lock)); 3488 KASSERT(mutex_owned(&sc->sc_lock));
3489 3489
3490 USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0); 3490 USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0);
3491 3491
3492 ehci_close_pipe(pipe, sc->sc_async_head); 3492 ehci_close_pipe(pipe, sc->sc_async_head);
3493} 3493}
3494 3494
3495Static usbd_status 3495Static usbd_status
3496ehci_device_request(usbd_xfer_handle xfer) 3496ehci_device_request(usbd_xfer_handle xfer)
3497{ 3497{
3498#define exfer EXFER(xfer) 3498#define exfer EXFER(xfer)
3499 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; 3499 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe;
3500 usb_device_request_t *req = &xfer->ux_request; 3500 usb_device_request_t *req = &xfer->ux_request;
3501 usbd_device_handle dev = epipe->pipe.up_dev; 3501 usbd_device_handle dev = epipe->pipe.up_dev;
3502 ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; 3502 ehci_softc_t *sc = dev->ud_bus->ub_hcpriv;
3503 ehci_soft_qtd_t *setup, *stat, *next; 3503 ehci_soft_qtd_t *setup, *stat, *next;
3504 ehci_soft_qh_t *sqh; 3504 ehci_soft_qh_t *sqh;
3505 int isread; 3505 int isread;
3506 int len; 3506 int len;
3507 usbd_status err; 3507 usbd_status err;
3508 3508
3509 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3509 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3510 3510
3511 isread = req->bmRequestType & UT_READ; 3511 isread = req->bmRequestType & UT_READ;
3512 len = UGETW(req->wLength); 3512 len = UGETW(req->wLength);
3513 3513
3514 USBHIST_LOG(ehcidebug, "type=0x%02x, request=0x%02x, " 3514 USBHIST_LOG(ehcidebug, "type=0x%02x, request=0x%02x, "
3515 "wValue=0x%04x, wIndex=0x%04x", 3515 "wValue=0x%04x, wIndex=0x%04x",
3516 req->bmRequestType, req->bRequest, UGETW(req->wValue), 3516 req->bmRequestType, req->bRequest, UGETW(req->wValue),
3517 UGETW(req->wIndex)); 3517 UGETW(req->wIndex));
3518 USBHIST_LOG(ehcidebug, "len=%d, addr=%d, endpt=%d", 3518 USBHIST_LOG(ehcidebug, "len=%d, addr=%d, endpt=%d",
3519 len, dev->ud_addr, 3519 len, dev->ud_addr,
3520 epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress, 0); 3520 epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress, 0);
3521 3521
3522 setup = ehci_alloc_sqtd(sc); 3522 setup = ehci_alloc_sqtd(sc);
3523 if (setup == NULL) { 3523 if (setup == NULL) {
3524 err = USBD_NOMEM; 3524 err = USBD_NOMEM;
3525 goto bad1; 3525 goto bad1;
3526 } 3526 }
3527 stat = ehci_alloc_sqtd(sc); 3527 stat = ehci_alloc_sqtd(sc);
3528 if (stat == NULL) { 3528 if (stat == NULL) {
3529 err = USBD_NOMEM; 3529 err = USBD_NOMEM;
3530 goto bad2; 3530 goto bad2;
3531 } 3531 }
3532 3532
3533 mutex_enter(&sc->sc_lock); 3533 mutex_enter(&sc->sc_lock);
3534 3534
3535 sqh = epipe->sqh; 3535 sqh = epipe->sqh;
3536 3536
3537 KASSERTMSG(EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)) == dev->ud_addr, 3537 KASSERTMSG(EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)) == dev->ud_addr,
3538 "address QH %d pipe %d\n", 3538 "address QH %" __PRIuBIT " pipe %d\n",
3539 EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)), dev->ud_addr); 3539 EHCI_QH_GET_ADDR(le32toh(sqh->qh.qh_endp)), dev->ud_addr);
3540 KASSERTMSG(EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)) == 3540 KASSERTMSG(EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)) ==
3541 UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize), 3541 UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize),
3542 "MPS QH %d pipe %d\n", 3542 "MPS QH %" __PRIuBIT " pipe %d\n",
3543 EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)), 3543 EHCI_QH_GET_MPL(le32toh(sqh->qh.qh_endp)),
3544 UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize)); 3544 UGETW(epipe->pipe.up_endpoint->ue_edesc->wMaxPacketSize));
3545 3545
3546 /* Set up data transaction */ 3546 /* Set up data transaction */
3547 if (len != 0) { 3547 if (len != 0) {
3548 ehci_soft_qtd_t *end; 3548 ehci_soft_qtd_t *end;
3549 3549
3550 /* Start toggle at 1. */ 3550 /* Start toggle at 1. */
3551 epipe->nexttoggle = 1; 3551 epipe->nexttoggle = 1;
3552 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, 3552 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer,
3553 &next, &end); 3553 &next, &end);
3554 if (err) 3554 if (err)
3555 goto bad3; 3555 goto bad3;
3556 end->qtd.qtd_status &= htole32(~EHCI_QTD_IOC); 3556 end->qtd.qtd_status &= htole32(~EHCI_QTD_IOC);
3557 end->nextqtd = stat; 3557 end->nextqtd = stat;
3558 end->qtd.qtd_next = end->qtd.qtd_altnext = 3558 end->qtd.qtd_next = end->qtd.qtd_altnext =
3559 htole32(stat->physaddr); 3559 htole32(stat->physaddr);
3560 usb_syncmem(&end->dma, end->offs, sizeof(end->qtd), 3560 usb_syncmem(&end->dma, end->offs, sizeof(end->qtd),
3561 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3561 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3562 } else { 3562 } else {
3563 next = stat; 3563 next = stat;
3564 } 3564 }
3565 3565
3566 memcpy(KERNADDR(&epipe->u.ctl.reqdma, 0), req, sizeof(*req)); 3566 memcpy(KERNADDR(&epipe->u.ctl.reqdma, 0), req, sizeof(*req));
3567 usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req), BUS_DMASYNC_PREWRITE); 3567 usb_syncmem(&epipe->u.ctl.reqdma, 0, sizeof(*req), BUS_DMASYNC_PREWRITE);
3568 3568
3569 /* Clear toggle */ 3569 /* Clear toggle */
3570 setup->qtd.qtd_status = htole32( 3570 setup->qtd.qtd_status = htole32(
3571 EHCI_QTD_ACTIVE | 3571 EHCI_QTD_ACTIVE |
3572 EHCI_QTD_SET_PID(EHCI_QTD_PID_SETUP) | 3572 EHCI_QTD_SET_PID(EHCI_QTD_PID_SETUP) |
3573 EHCI_QTD_SET_CERR(3) | 3573 EHCI_QTD_SET_CERR(3) |
3574 EHCI_QTD_SET_TOGGLE(0) | 3574 EHCI_QTD_SET_TOGGLE(0) |
3575 EHCI_QTD_SET_BYTES(sizeof(*req)) 3575 EHCI_QTD_SET_BYTES(sizeof(*req))
3576 ); 3576 );
3577 setup->qtd.qtd_buffer[0] = htole32(DMAADDR(&epipe->u.ctl.reqdma, 0)); 3577 setup->qtd.qtd_buffer[0] = htole32(DMAADDR(&epipe->u.ctl.reqdma, 0));
3578 setup->qtd.qtd_buffer_hi[0] = 0; 3578 setup->qtd.qtd_buffer_hi[0] = 0;
3579 setup->nextqtd = next; 3579 setup->nextqtd = next;
3580 setup->qtd.qtd_next = setup->qtd.qtd_altnext = htole32(next->physaddr); 3580 setup->qtd.qtd_next = setup->qtd.qtd_altnext = htole32(next->physaddr);
3581 setup->xfer = xfer; 3581 setup->xfer = xfer;
3582 setup->len = sizeof(*req); 3582 setup->len = sizeof(*req);
3583 usb_syncmem(&setup->dma, setup->offs, sizeof(setup->qtd), 3583 usb_syncmem(&setup->dma, setup->offs, sizeof(setup->qtd),
3584 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3584 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3585 3585
3586 stat->qtd.qtd_status = htole32( 3586 stat->qtd.qtd_status = htole32(
3587 EHCI_QTD_ACTIVE | 3587 EHCI_QTD_ACTIVE |
3588 EHCI_QTD_SET_PID(isread ? EHCI_QTD_PID_OUT : EHCI_QTD_PID_IN) | 3588 EHCI_QTD_SET_PID(isread ? EHCI_QTD_PID_OUT : EHCI_QTD_PID_IN) |
3589 EHCI_QTD_SET_CERR(3) | 3589 EHCI_QTD_SET_CERR(3) |
3590 EHCI_QTD_SET_TOGGLE(1) | 3590 EHCI_QTD_SET_TOGGLE(1) |
3591 EHCI_QTD_IOC 3591 EHCI_QTD_IOC
3592 ); 3592 );
3593 stat->qtd.qtd_buffer[0] = 0; /* XXX not needed? */ 3593 stat->qtd.qtd_buffer[0] = 0; /* XXX not needed? */
3594 stat->qtd.qtd_buffer_hi[0] = 0; /* XXX not needed? */ 3594 stat->qtd.qtd_buffer_hi[0] = 0; /* XXX not needed? */
3595 stat->nextqtd = NULL; 3595 stat->nextqtd = NULL;
3596 stat->qtd.qtd_next = stat->qtd.qtd_altnext = EHCI_NULL; 3596 stat->qtd.qtd_next = stat->qtd.qtd_altnext = EHCI_NULL;
3597 stat->xfer = xfer; 3597 stat->xfer = xfer;
3598 stat->len = 0; 3598 stat->len = 0;
3599 usb_syncmem(&stat->dma, stat->offs, sizeof(stat->qtd), 3599 usb_syncmem(&stat->dma, stat->offs, sizeof(stat->qtd),
3600 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 3600 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
3601 3601
3602#ifdef EHCI_DEBUG 3602#ifdef EHCI_DEBUG
3603 USBHIST_LOGN(ehcidebug, 5, "dump:", 0, 0, 0, 0); 3603 USBHIST_LOGN(ehcidebug, 5, "dump:", 0, 0, 0, 0);
3604 ehci_dump_sqh(sqh); 3604 ehci_dump_sqh(sqh);
3605 ehci_dump_sqtds(setup); 3605 ehci_dump_sqtds(setup);
3606#endif 3606#endif
3607 3607
3608 exfer->ex_sqtdstart = setup; 3608 exfer->ex_sqtdstart = setup;
3609 exfer->ex_sqtdend = stat; 3609 exfer->ex_sqtdend = stat;
3610 KASSERT(exfer->ex_isdone); 3610 KASSERT(exfer->ex_isdone);
3611#ifdef DIAGNOSTIC 3611#ifdef DIAGNOSTIC
3612 exfer->ex_isdone = false; 3612 exfer->ex_isdone = false;
3613#endif 3613#endif
3614 3614
3615 /* Insert qTD in QH list. */ 3615 /* Insert qTD in QH list. */
3616 ehci_set_qh_qtd(sqh, setup); /* also does usb_syncmem(sqh) */ 3616 ehci_set_qh_qtd(sqh, setup); /* also does usb_syncmem(sqh) */
3617 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { 3617 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) {
3618 callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), 3618 callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout),
3619 ehci_timeout, xfer); 3619 ehci_timeout, xfer);
3620 } 3620 }
3621 ehci_add_intr_list(sc, exfer); 3621 ehci_add_intr_list(sc, exfer);
3622 xfer->ux_status = USBD_IN_PROGRESS; 3622 xfer->ux_status = USBD_IN_PROGRESS;
3623 mutex_exit(&sc->sc_lock); 3623 mutex_exit(&sc->sc_lock);
3624 3624
3625#ifdef EHCI_DEBUG 3625#ifdef EHCI_DEBUG
3626 USBHIST_LOGN(ehcidebug, 10, "status=%x, dump:", 3626 USBHIST_LOGN(ehcidebug, 10, "status=%x, dump:",
3627 EOREAD4(sc, EHCI_USBSTS), 0, 0, 0); 3627 EOREAD4(sc, EHCI_USBSTS), 0, 0, 0);
3628// delay(10000); 3628// delay(10000);
3629 ehci_dump_regs(sc); 3629 ehci_dump_regs(sc);
3630 ehci_dump_sqh(sc->sc_async_head); 3630 ehci_dump_sqh(sc->sc_async_head);
3631 ehci_dump_sqh(sqh); 3631 ehci_dump_sqh(sqh);
3632 ehci_dump_sqtds(setup); 3632 ehci_dump_sqtds(setup);
3633#endif 3633#endif
3634 3634
3635 return USBD_NORMAL_COMPLETION; 3635 return USBD_NORMAL_COMPLETION;
3636 3636
3637 bad3: 3637 bad3:
3638 mutex_exit(&sc->sc_lock); 3638 mutex_exit(&sc->sc_lock);
3639 ehci_free_sqtd(sc, stat); 3639 ehci_free_sqtd(sc, stat);
3640 bad2: 3640 bad2:
3641 ehci_free_sqtd(sc, setup); 3641 ehci_free_sqtd(sc, setup);
3642 bad1: 3642 bad1:
3643 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); 3643 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0);
3644 mutex_enter(&sc->sc_lock); 3644 mutex_enter(&sc->sc_lock);
3645 xfer->ux_status = err; 3645 xfer->ux_status = err;
3646 usb_transfer_complete(xfer); 3646 usb_transfer_complete(xfer);
3647 mutex_exit(&sc->sc_lock); 3647 mutex_exit(&sc->sc_lock);
3648 return err; 3648 return err;
3649#undef exfer 3649#undef exfer
3650} 3650}
3651 3651
3652/* 3652/*
3653 * Some EHCI chips from VIA seem to trigger interrupts before writing back the 3653 * Some EHCI chips from VIA seem to trigger interrupts before writing back the
3654 * qTD status, or miss signalling occasionally under heavy load. If the host 3654 * qTD status, or miss signalling occasionally under heavy load. If the host
3655 * machine is too fast, we we can miss transaction completion - when we scan 3655 * machine is too fast, we we can miss transaction completion - when we scan
3656 * the active list the transaction still seems to be active. This generally 3656 * the active list the transaction still seems to be active. This generally
3657 * exhibits itself as a umass stall that never recovers. 3657 * exhibits itself as a umass stall that never recovers.
3658 * 3658 *
3659 * We work around this behaviour by setting up this callback after any softintr 3659 * We work around this behaviour by setting up this callback after any softintr
3660 * that completes with transactions still pending, giving us another chance to 3660 * that completes with transactions still pending, giving us another chance to
3661 * check for completion after the writeback has taken place. 3661 * check for completion after the writeback has taken place.
3662 */ 3662 */
3663Static void 3663Static void
3664ehci_intrlist_timeout(void *arg) 3664ehci_intrlist_timeout(void *arg)
3665{ 3665{
3666 ehci_softc_t *sc = arg; 3666 ehci_softc_t *sc = arg;
3667 3667
3668 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3668 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3669 3669
3670 usb_schedsoftintr(&sc->sc_bus); 3670 usb_schedsoftintr(&sc->sc_bus);
3671} 3671}
3672 3672
3673/************************/ 3673/************************/
3674 3674
3675Static usbd_status 3675Static usbd_status
3676ehci_device_bulk_transfer(usbd_xfer_handle xfer) 3676ehci_device_bulk_transfer(usbd_xfer_handle xfer)
3677{ 3677{
3678 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3678 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
3679 usbd_status err; 3679 usbd_status err;
3680 3680
3681 /* Insert last in queue. */ 3681 /* Insert last in queue. */
3682 mutex_enter(&sc->sc_lock); 3682 mutex_enter(&sc->sc_lock);
3683 err = usb_insert_transfer(xfer); 3683 err = usb_insert_transfer(xfer);
3684 mutex_exit(&sc->sc_lock); 3684 mutex_exit(&sc->sc_lock);
3685 if (err) 3685 if (err)
3686 return err; 3686 return err;
3687 3687
3688 /* Pipe isn't running, start first */ 3688 /* Pipe isn't running, start first */
3689 return ehci_device_bulk_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); 3689 return ehci_device_bulk_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue));
3690} 3690}
3691 3691
3692Static usbd_status 3692Static usbd_status
3693ehci_device_bulk_start(usbd_xfer_handle xfer) 3693ehci_device_bulk_start(usbd_xfer_handle xfer)
3694{ 3694{
3695#define exfer EXFER(xfer) 3695#define exfer EXFER(xfer)
3696 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; 3696 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe;
3697 usbd_device_handle dev = epipe->pipe.up_dev; 3697 usbd_device_handle dev = epipe->pipe.up_dev;
3698 ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; 3698 ehci_softc_t *sc = dev->ud_bus->ub_hcpriv;
3699 ehci_soft_qtd_t *data, *dataend; 3699 ehci_soft_qtd_t *data, *dataend;
3700 ehci_soft_qh_t *sqh; 3700 ehci_soft_qh_t *sqh;
3701 usbd_status err; 3701 usbd_status err;
3702 int len, isread, endpt; 3702 int len, isread, endpt;
3703 3703
3704 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3704 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3705 3705
3706 USBHIST_LOG(ehcidebug, "xfer=%p len=%d flags=%d", 3706 USBHIST_LOG(ehcidebug, "xfer=%p len=%d flags=%d",
3707 xfer, xfer->ux_length, xfer->ux_flags, 0); 3707 xfer, xfer->ux_length, xfer->ux_flags, 0);
3708 3708
3709 if (sc->sc_dying) 3709 if (sc->sc_dying)
3710 return USBD_IOERROR; 3710 return USBD_IOERROR;
3711 3711
3712 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); 3712 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST));
3713 3713
3714 mutex_enter(&sc->sc_lock); 3714 mutex_enter(&sc->sc_lock);
3715 3715
3716 len = xfer->ux_length; 3716 len = xfer->ux_length;
3717 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; 3717 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
3718 isread = UE_GET_DIR(endpt) == UE_DIR_IN; 3718 isread = UE_GET_DIR(endpt) == UE_DIR_IN;
3719 sqh = epipe->sqh; 3719 sqh = epipe->sqh;
3720 3720
3721 epipe->u.bulk.length = len; 3721 epipe->u.bulk.length = len;
3722 3722
3723 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data, 3723 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data,
3724 &dataend); 3724 &dataend);
3725 if (err) { 3725 if (err) {
3726 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); 3726 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0);
3727 xfer->ux_status = err; 3727 xfer->ux_status = err;
3728 usb_transfer_complete(xfer); 3728 usb_transfer_complete(xfer);
3729 mutex_exit(&sc->sc_lock); 3729 mutex_exit(&sc->sc_lock);
3730 return err; 3730 return err;
3731 } 3731 }
3732 3732
3733#ifdef EHCI_DEBUG 3733#ifdef EHCI_DEBUG
3734 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); 3734 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0);
3735 ehci_dump_sqh(sqh); 3735 ehci_dump_sqh(sqh);
3736 ehci_dump_sqtds(data); 3736 ehci_dump_sqtds(data);
3737 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); 3737 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0);
3738#endif 3738#endif
3739 3739
3740 /* Set up interrupt info. */ 3740 /* Set up interrupt info. */
3741 exfer->ex_sqtdstart = data; 3741 exfer->ex_sqtdstart = data;
3742 exfer->ex_sqtdend = dataend; 3742 exfer->ex_sqtdend = dataend;
3743 KASSERT(exfer->ex_isdone); 3743 KASSERT(exfer->ex_isdone);
3744#ifdef DIAGNOSTIC 3744#ifdef DIAGNOSTIC
3745 exfer->ex_isdone = false; 3745 exfer->ex_isdone = false;
3746#endif 3746#endif
3747 3747
3748 ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */ 3748 ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */
3749 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { 3749 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) {
3750 callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), 3750 callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout),
3751 ehci_timeout, xfer); 3751 ehci_timeout, xfer);
3752 } 3752 }
3753 ehci_add_intr_list(sc, exfer); 3753 ehci_add_intr_list(sc, exfer);
3754 xfer->ux_status = USBD_IN_PROGRESS; 3754 xfer->ux_status = USBD_IN_PROGRESS;
3755 mutex_exit(&sc->sc_lock); 3755 mutex_exit(&sc->sc_lock);
3756 3756
3757#ifdef EHCI_DEBUG 3757#ifdef EHCI_DEBUG
3758 USBHIST_LOGN(ehcidebug, 5, "data(2)", 0, 0, 0, 0); 3758 USBHIST_LOGN(ehcidebug, 5, "data(2)", 0, 0, 0, 0);
3759// delay(10000); 3759// delay(10000);
3760 USBHIST_LOGN(ehcidebug, 5, "data(3)", 0, 0, 0, 0); 3760 USBHIST_LOGN(ehcidebug, 5, "data(3)", 0, 0, 0, 0);
3761 ehci_dump_regs(sc); 3761 ehci_dump_regs(sc);
3762#if 0 3762#if 0
3763 printf("async_head:\n"); 3763 printf("async_head:\n");
3764 ehci_dump_sqh(sc->sc_async_head); 3764 ehci_dump_sqh(sc->sc_async_head);
3765#endif 3765#endif
3766 USBHIST_LOG(ehcidebug, "sqh:", 0, 0, 0, 0); 3766 USBHIST_LOG(ehcidebug, "sqh:", 0, 0, 0, 0);
3767 ehci_dump_sqh(sqh); 3767 ehci_dump_sqh(sqh);
3768 ehci_dump_sqtds(data); 3768 ehci_dump_sqtds(data);
3769#endif 3769#endif
3770 3770
3771 if (sc->sc_bus.ub_usepolling) 3771 if (sc->sc_bus.ub_usepolling)
3772 ehci_waitintr(sc, xfer); 3772 ehci_waitintr(sc, xfer);
3773 3773
3774 return USBD_IN_PROGRESS; 3774 return USBD_IN_PROGRESS;
3775#undef exfer 3775#undef exfer
3776} 3776}
3777 3777
3778Static void 3778Static void
3779ehci_device_bulk_abort(usbd_xfer_handle xfer) 3779ehci_device_bulk_abort(usbd_xfer_handle xfer)
3780{ 3780{
3781 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3781 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3782 3782
3783 USBHIST_LOG(ehcidebug, "xfer %p", xfer, 0, 0, 0); 3783 USBHIST_LOG(ehcidebug, "xfer %p", xfer, 0, 0, 0);
3784 ehci_abort_xfer(xfer, USBD_CANCELLED); 3784 ehci_abort_xfer(xfer, USBD_CANCELLED);
3785} 3785}
3786 3786
3787/* 3787/*
3788 * Close a device bulk pipe. 3788 * Close a device bulk pipe.
3789 */ 3789 */
3790Static void 3790Static void
3791ehci_device_bulk_close(usbd_pipe_handle pipe) 3791ehci_device_bulk_close(usbd_pipe_handle pipe)
3792{ 3792{
3793 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; 3793 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
3794 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; 3794 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;
3795 3795
3796 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3796 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3797 3797
3798 KASSERT(mutex_owned(&sc->sc_lock)); 3798 KASSERT(mutex_owned(&sc->sc_lock));
3799 3799
3800 USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0); 3800 USBHIST_LOG(ehcidebug, "pipe=%p", pipe, 0, 0, 0);
3801 pipe->up_endpoint->ue_toggle = epipe->nexttoggle; 3801 pipe->up_endpoint->ue_toggle = epipe->nexttoggle;
3802 ehci_close_pipe(pipe, sc->sc_async_head); 3802 ehci_close_pipe(pipe, sc->sc_async_head);
3803} 3803}
3804 3804
3805Static void 3805Static void
3806ehci_device_bulk_done(usbd_xfer_handle xfer) 3806ehci_device_bulk_done(usbd_xfer_handle xfer)
3807{ 3807{
3808 struct ehci_xfer *ex = EXFER(xfer); 3808 struct ehci_xfer *ex = EXFER(xfer);
3809 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3809 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
3810 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; 3810 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe;
3811 int endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; 3811 int endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
3812 int rd = UE_GET_DIR(endpt) == UE_DIR_IN; 3812 int rd = UE_GET_DIR(endpt) == UE_DIR_IN;
3813 3813
3814 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3814 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3815 3815
3816 USBHIST_LOG(ehcidebug, "xfer=%p, actlen=%d", 3816 USBHIST_LOG(ehcidebug, "xfer=%p, actlen=%d",
3817 xfer, xfer->ux_actlen, 0, 0); 3817 xfer, xfer->ux_actlen, 0, 0);
3818 3818
3819 KASSERT(mutex_owned(&sc->sc_lock)); 3819 KASSERT(mutex_owned(&sc->sc_lock));
3820 3820
3821 if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { 3821 if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) {
3822 ehci_del_intr_list(sc, ex); /* remove from active list */ 3822 ehci_del_intr_list(sc, ex); /* remove from active list */
3823 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); 3823 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL);
3824 usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, 3824 usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length,
3825 rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); 3825 rd ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
3826 } 3826 }
3827 3827
3828 USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0); 3828 USBHIST_LOG(ehcidebug, "length=%d", xfer->ux_actlen, 0, 0, 0);
3829} 3829}
3830 3830
3831/************************/ 3831/************************/
3832 3832
3833Static usbd_status 3833Static usbd_status
3834ehci_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)
3835{ 3835{
3836 struct ehci_soft_islot *isp; 3836 struct ehci_soft_islot *isp;
3837 int islot, lev; 3837 int islot, lev;
3838 3838
3839 /* Find a poll rate that is large enough. */ 3839 /* Find a poll rate that is large enough. */
3840 for (lev = EHCI_IPOLLRATES - 1; lev > 0; lev--) 3840 for (lev = EHCI_IPOLLRATES - 1; lev > 0; lev--)
3841 if (EHCI_ILEV_IVAL(lev) <= ival) 3841 if (EHCI_ILEV_IVAL(lev) <= ival)
3842 break; 3842 break;
3843 3843
3844 /* Pick an interrupt slot at the right level. */ 3844 /* Pick an interrupt slot at the right level. */
3845 /* XXX could do better than picking at random */ 3845 /* XXX could do better than picking at random */
3846 sc->sc_rand = (sc->sc_rand + 191) % sc->sc_flsize; 3846 sc->sc_rand = (sc->sc_rand + 191) % sc->sc_flsize;
3847 islot = EHCI_IQHIDX(lev, sc->sc_rand); 3847 islot = EHCI_IQHIDX(lev, sc->sc_rand);
3848 3848
3849 sqh->islot = islot; 3849 sqh->islot = islot;
3850 isp = &sc->sc_islots[islot]; 3850 isp = &sc->sc_islots[islot];
3851 mutex_enter(&sc->sc_lock); 3851 mutex_enter(&sc->sc_lock);
3852 ehci_add_qh(sc, sqh, isp->sqh); 3852 ehci_add_qh(sc, sqh, isp->sqh);
3853 mutex_exit(&sc->sc_lock); 3853 mutex_exit(&sc->sc_lock);
3854 3854
3855 return USBD_NORMAL_COMPLETION; 3855 return USBD_NORMAL_COMPLETION;
3856} 3856}
3857 3857
3858Static usbd_status 3858Static usbd_status
3859ehci_device_intr_transfer(usbd_xfer_handle xfer) 3859ehci_device_intr_transfer(usbd_xfer_handle xfer)
3860{ 3860{
3861 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3861 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
3862 usbd_status err; 3862 usbd_status err;
3863 3863
3864 /* Insert last in queue. */ 3864 /* Insert last in queue. */
3865 mutex_enter(&sc->sc_lock); 3865 mutex_enter(&sc->sc_lock);
3866 err = usb_insert_transfer(xfer); 3866 err = usb_insert_transfer(xfer);
3867 mutex_exit(&sc->sc_lock); 3867 mutex_exit(&sc->sc_lock);
3868 if (err) 3868 if (err)
3869 return err; 3869 return err;
3870 3870
3871 /* 3871 /*
3872 * Pipe isn't running (otherwise err would be USBD_INPROG), 3872 * Pipe isn't running (otherwise err would be USBD_INPROG),
3873 * so start it first. 3873 * so start it first.
3874 */ 3874 */
3875 return ehci_device_intr_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue)); 3875 return ehci_device_intr_start(SIMPLEQ_FIRST(&xfer->ux_pipe->up_queue));
3876} 3876}
3877 3877
3878Static usbd_status 3878Static usbd_status
3879ehci_device_intr_start(usbd_xfer_handle xfer) 3879ehci_device_intr_start(usbd_xfer_handle xfer)
3880{ 3880{
3881#define exfer EXFER(xfer) 3881#define exfer EXFER(xfer)
3882 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; 3882 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe;
3883 usbd_device_handle dev = xfer->ux_pipe->up_dev; 3883 usbd_device_handle dev = xfer->ux_pipe->up_dev;
3884 ehci_softc_t *sc = dev->ud_bus->ub_hcpriv; 3884 ehci_softc_t *sc = dev->ud_bus->ub_hcpriv;
3885 ehci_soft_qtd_t *data, *dataend; 3885 ehci_soft_qtd_t *data, *dataend;
3886 ehci_soft_qh_t *sqh; 3886 ehci_soft_qh_t *sqh;
3887 usbd_status err; 3887 usbd_status err;
3888 int len, isread, endpt; 3888 int len, isread, endpt;
3889 3889
3890 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3890 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3891 3891
3892 USBHIST_LOG(ehcidebug, "xfer=%p len=%d flags=%d", 3892 USBHIST_LOG(ehcidebug, "xfer=%p len=%d flags=%d",
3893 xfer, xfer->ux_length, xfer->ux_flags, 0); 3893 xfer, xfer->ux_length, xfer->ux_flags, 0);
3894 3894
3895 if (sc->sc_dying) 3895 if (sc->sc_dying)
3896 return USBD_IOERROR; 3896 return USBD_IOERROR;
3897 3897
3898 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); 3898 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST));
3899 3899
3900 mutex_enter(&sc->sc_lock); 3900 mutex_enter(&sc->sc_lock);
3901 3901
3902 len = xfer->ux_length; 3902 len = xfer->ux_length;
3903 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; 3903 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
3904 isread = UE_GET_DIR(endpt) == UE_DIR_IN; 3904 isread = UE_GET_DIR(endpt) == UE_DIR_IN;
3905 sqh = epipe->sqh; 3905 sqh = epipe->sqh;
3906 3906
3907 epipe->u.intr.length = len; 3907 epipe->u.intr.length = len;
3908 3908
3909 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data, 3909 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, &data,
3910 &dataend); 3910 &dataend);
3911 if (err) { 3911 if (err) {
3912 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); 3912 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0);
3913 xfer->ux_status = err; 3913 xfer->ux_status = err;
3914 usb_transfer_complete(xfer); 3914 usb_transfer_complete(xfer);
3915 mutex_exit(&sc->sc_lock); 3915 mutex_exit(&sc->sc_lock);
3916 return err; 3916 return err;
3917 } 3917 }
3918 3918
3919#ifdef EHCI_DEBUG 3919#ifdef EHCI_DEBUG
3920 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0); 3920 USBHIST_LOGN(ehcidebug, 5, "--- dump start ---", 0, 0, 0, 0);
3921 ehci_dump_sqh(sqh); 3921 ehci_dump_sqh(sqh);
3922 ehci_dump_sqtds(data); 3922 ehci_dump_sqtds(data);
3923 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0); 3923 USBHIST_LOGN(ehcidebug, 5, "--- dump end ---", 0, 0, 0, 0);
3924#endif 3924#endif
3925 3925
3926 /* Set up interrupt info. */ 3926 /* Set up interrupt info. */
3927 exfer->ex_sqtdstart = data; 3927 exfer->ex_sqtdstart = data;
3928 exfer->ex_sqtdend = dataend; 3928 exfer->ex_sqtdend = dataend;
3929 KASSERT(exfer->ex_isdone); 3929 KASSERT(exfer->ex_isdone);
3930#ifdef DIAGNOSTIC 3930#ifdef DIAGNOSTIC
3931 exfer->ex_isdone = false; 3931 exfer->ex_isdone = false;
3932#endif 3932#endif
3933 3933
3934 ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */ 3934 ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */
3935 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { 3935 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) {
3936 callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout), 3936 callout_reset(&xfer->ux_callout, mstohz(xfer->ux_timeout),
3937 ehci_timeout, xfer); 3937 ehci_timeout, xfer);
3938 } 3938 }
3939 ehci_add_intr_list(sc, exfer); 3939 ehci_add_intr_list(sc, exfer);
3940 xfer->ux_status = USBD_IN_PROGRESS; 3940 xfer->ux_status = USBD_IN_PROGRESS;
3941 mutex_exit(&sc->sc_lock); 3941 mutex_exit(&sc->sc_lock);
3942 3942
3943#ifdef EHCI_DEBUG 3943#ifdef EHCI_DEBUG
3944 USBHIST_LOGN(ehcidebug, 5, "data(2)", 0, 0, 0, 0); 3944 USBHIST_LOGN(ehcidebug, 5, "data(2)", 0, 0, 0, 0);
3945// delay(10000); 3945// delay(10000);
3946 USBHIST_LOGN(ehcidebug, 5, "data(3)", 0, 0, 0, 0); 3946 USBHIST_LOGN(ehcidebug, 5, "data(3)", 0, 0, 0, 0);
3947 ehci_dump_regs(sc); 3947 ehci_dump_regs(sc);
3948 USBHIST_LOGN(ehcidebug, 5, "sqh:", 0, 0, 0, 0); 3948 USBHIST_LOGN(ehcidebug, 5, "sqh:", 0, 0, 0, 0);
3949 ehci_dump_sqh(sqh); 3949 ehci_dump_sqh(sqh);
3950 ehci_dump_sqtds(data); 3950 ehci_dump_sqtds(data);
3951#endif 3951#endif
3952 3952
3953 if (sc->sc_bus.ub_usepolling) 3953 if (sc->sc_bus.ub_usepolling)
3954 ehci_waitintr(sc, xfer); 3954 ehci_waitintr(sc, xfer);
3955 3955
3956 return USBD_IN_PROGRESS; 3956 return USBD_IN_PROGRESS;
3957#undef exfer 3957#undef exfer
3958} 3958}
3959 3959
3960Static void 3960Static void
3961ehci_device_intr_abort(usbd_xfer_handle xfer) 3961ehci_device_intr_abort(usbd_xfer_handle xfer)
3962{ 3962{
3963 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 3963 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
3964 3964
3965 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0); 3965 USBHIST_LOG(ehcidebug, "xfer=%p", xfer, 0, 0, 0);
3966 KASSERT(xfer->ux_pipe->up_intrxfer == xfer); 3966 KASSERT(xfer->ux_pipe->up_intrxfer == xfer);
3967 3967
3968 /* 3968 /*
3969 * XXX - abort_xfer uses ehci_sync_hc, which syncs via the advance 3969 * XXX - abort_xfer uses ehci_sync_hc, which syncs via the advance
3970 * async doorbell. That's dependent on the async list, wheras 3970 * async doorbell. That's dependent on the async list, wheras
3971 * intr xfers are periodic, should not use this? 3971 * intr xfers are periodic, should not use this?
3972 */ 3972 */
3973 ehci_abort_xfer(xfer, USBD_CANCELLED); 3973 ehci_abort_xfer(xfer, USBD_CANCELLED);
3974} 3974}
3975 3975
3976Static void 3976Static void
3977ehci_device_intr_close(usbd_pipe_handle pipe) 3977ehci_device_intr_close(usbd_pipe_handle pipe)
3978{ 3978{
3979 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv; 3979 ehci_softc_t *sc = pipe->up_dev->ud_bus->ub_hcpriv;
3980 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe; 3980 struct ehci_pipe *epipe = (struct ehci_pipe *)pipe;
3981 struct ehci_soft_islot *isp; 3981 struct ehci_soft_islot *isp;
3982 3982
3983 KASSERT(mutex_owned(&sc->sc_lock)); 3983 KASSERT(mutex_owned(&sc->sc_lock));
3984 3984
3985 isp = &sc->sc_islots[epipe->sqh->islot]; 3985 isp = &sc->sc_islots[epipe->sqh->islot];
3986 ehci_close_pipe(pipe, isp->sqh); 3986 ehci_close_pipe(pipe, isp->sqh);
3987} 3987}
3988 3988
3989Static void 3989Static void
3990ehci_device_intr_done(usbd_xfer_handle xfer) 3990ehci_device_intr_done(usbd_xfer_handle xfer)
3991{ 3991{
3992#define exfer EXFER(xfer) 3992#define exfer EXFER(xfer)
3993 struct ehci_xfer *ex = EXFER(xfer); 3993 struct ehci_xfer *ex = EXFER(xfer);
3994 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 3994 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
3995 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe; 3995 struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->ux_pipe;
3996 ehci_soft_qtd_t *data, *dataend; 3996 ehci_soft_qtd_t *data, *dataend;
3997 ehci_soft_qh_t *sqh; 3997 ehci_soft_qh_t *sqh;
3998 usbd_status err; 3998 usbd_status err;
3999 int len, isread, endpt; 3999 int len, isread, endpt;
4000 4000
4001 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 4001 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
4002 4002
4003 USBHIST_LOG(ehcidebug, "xfer=%p, actlen=%d", 4003 USBHIST_LOG(ehcidebug, "xfer=%p, actlen=%d",
4004 xfer, xfer->ux_actlen, 0, 0); 4004 xfer, xfer->ux_actlen, 0, 0);
4005 4005
4006 KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock)); 4006 KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock));
4007 4007
4008 if (xfer->ux_pipe->up_repeat) { 4008 if (xfer->ux_pipe->up_repeat) {
4009 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); 4009 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL);
4010 4010
4011 len = epipe->u.intr.length; 4011 len = epipe->u.intr.length;
4012 xfer->ux_length = len; 4012 xfer->ux_length = len;
4013 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; 4013 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
4014 isread = UE_GET_DIR(endpt) == UE_DIR_IN; 4014 isread = UE_GET_DIR(endpt) == UE_DIR_IN;
4015 usb_syncmem(&xfer->ux_dmabuf, 0, len, 4015 usb_syncmem(&xfer->ux_dmabuf, 0, len,
4016 isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); 4016 isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
4017 sqh = epipe->sqh; 4017 sqh = epipe->sqh;
4018 4018
4019 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer, 4019 err = ehci_alloc_sqtd_chain(epipe, sc, len, isread, xfer,
4020 &data, &dataend); 4020 &data, &dataend);
4021 if (err) { 4021 if (err) {
4022 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0); 4022 USBHIST_LOG(ehcidebug, "no memory", 0, 0, 0, 0);
4023 xfer->ux_status = err; 4023 xfer->ux_status = err;
4024 return; 4024 return;
4025 } 4025 }
4026 4026
4027 /* Set up interrupt info. */ 4027 /* Set up interrupt info. */
4028 exfer->ex_sqtdstart = data; 4028 exfer->ex_sqtdstart = data;
4029 exfer->ex_sqtdend = dataend; 4029 exfer->ex_sqtdend = dataend;
4030 KASSERT(exfer->ex_isdone); 4030 KASSERT(exfer->ex_isdone);
4031#ifdef DIAGNOSTIC 4031#ifdef DIAGNOSTIC
4032 exfer->ex_isdone = false; 4032 exfer->ex_isdone = false;
4033#endif 4033#endif
4034 4034
4035 ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */ 4035 ehci_set_qh_qtd(sqh, data); /* also does usb_syncmem(sqh) */
4036 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) { 4036 if (xfer->ux_timeout && !sc->sc_bus.ub_usepolling) {
4037 callout_reset(&xfer->ux_callout, 4037 callout_reset(&xfer->ux_callout,
4038 mstohz(xfer->ux_timeout), ehci_timeout, xfer); 4038 mstohz(xfer->ux_timeout), ehci_timeout, xfer);
4039 } 4039 }
4040 4040
4041 xfer->ux_status = USBD_IN_PROGRESS; 4041 xfer->ux_status = USBD_IN_PROGRESS;
4042 } else if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) { 4042 } else if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(ex)) {
4043 ehci_del_intr_list(sc, ex); /* remove from active list */ 4043 ehci_del_intr_list(sc, ex); /* remove from active list */
4044 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL); 4044 ehci_free_sqtd_chain(sc, ex->ex_sqtdstart, NULL);
4045 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; 4045 endpt = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
4046 isread = UE_GET_DIR(endpt) == UE_DIR_IN; 4046 isread = UE_GET_DIR(endpt) == UE_DIR_IN;
4047 usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, 4047 usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length,
4048 isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); 4048 isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
4049 } 4049 }
4050#undef exfer 4050#undef exfer
4051} 4051}
4052 4052
4053/************************/ 4053/************************/
4054 4054
4055Static usbd_status 4055Static usbd_status
4056ehci_device_fs_isoc_transfer(usbd_xfer_handle xfer) 4056ehci_device_fs_isoc_transfer(usbd_xfer_handle xfer)
4057{ 4057{
4058 usbd_status err; 4058 usbd_status err;
4059 4059
4060 err = usb_insert_transfer(xfer); 4060 err = usb_insert_transfer(xfer);
4061 if (err && err != USBD_IN_PROGRESS) 4061 if (err && err != USBD_IN_PROGRESS)
4062 return err; 4062 return err;
4063 4063
4064 return ehci_device_fs_isoc_start(xfer); 4064 return ehci_device_fs_isoc_start(xfer);
4065} 4065}
4066 4066
4067Static usbd_status 4067Static usbd_status
4068ehci_device_fs_isoc_start(usbd_xfer_handle xfer) 4068ehci_device_fs_isoc_start(usbd_xfer_handle xfer)
4069{ 4069{
4070 struct ehci_pipe *epipe; 4070 struct ehci_pipe *epipe;
4071 usbd_device_handle dev; 4071 usbd_device_handle dev;
4072 ehci_softc_t *sc; 4072 ehci_softc_t *sc;
4073 struct ehci_xfer *exfer; 4073 struct ehci_xfer *exfer;
4074 ehci_soft_sitd_t *sitd, *prev, *start, *stop; 4074 ehci_soft_sitd_t *sitd, *prev, *start, *stop;
4075 usb_dma_t *dma_buf; 4075 usb_dma_t *dma_buf;
4076 int i, j, k, frames; 4076 int i, j, k, frames;
4077 int offs, total_length; 4077 int offs, total_length;
4078 int frindex; 4078 int frindex;
4079 u_int huba, dir; 4079 u_int huba, dir;
4080 4080
4081 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 4081 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
4082 4082
4083 start = NULL; 4083 start = NULL;
4084 prev = NULL; 4084 prev = NULL;
4085 sitd = NULL; 4085 sitd = NULL;
4086 total_length = 0; 4086 total_length = 0;
4087 exfer = (struct ehci_xfer *) xfer; 4087 exfer = (struct ehci_xfer *) xfer;
4088 sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 4088 sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
4089 dev = xfer->ux_pipe->up_dev; 4089 dev = xfer->ux_pipe->up_dev;
4090 epipe = (struct ehci_pipe *)xfer->ux_pipe; 4090 epipe = (struct ehci_pipe *)xfer->ux_pipe;
4091 4091
4092 /* 4092 /*
4093 * To allow continuous transfers, above we start all transfers 4093 * To allow continuous transfers, above we start all transfers
4094 * immediately. However, we're still going to get usbd_start_next call 4094 * immediately. However, we're still going to get usbd_start_next call
4095 * this when another xfer completes. So, check if this is already 4095 * this when another xfer completes. So, check if this is already
4096 * in progress or not 4096 * in progress or not
4097 */ 4097 */
4098 4098
4099 if (exfer->ex_sitdstart != NULL) 4099 if (exfer->ex_sitdstart != NULL)
4100 return USBD_IN_PROGRESS; 4100 return USBD_IN_PROGRESS;
4101 4101
4102 USBHIST_LOG(ehcidebug, "xfer %p len %d flags %d", 4102 USBHIST_LOG(ehcidebug, "xfer %p len %d flags %d",
4103 xfer, xfer->ux_length, xfer->ux_flags, 0); 4103 xfer, xfer->ux_length, xfer->ux_flags, 0);
4104 4104
4105 if (sc->sc_dying) 4105 if (sc->sc_dying)
4106 return USBD_IOERROR; 4106 return USBD_IOERROR;
4107 4107
4108 /* 4108 /*
4109 * To avoid complication, don't allow a request right now that'll span 4109 * To avoid complication, don't allow a request right now that'll span
4110 * the entire frame table. To within 4 frames, to allow some leeway 4110 * the entire frame table. To within 4 frames, to allow some leeway
4111 * on either side of where the hc currently is. 4111 * on either side of where the hc currently is.
4112 */ 4112 */
4113 if (epipe->pipe.up_endpoint->ue_edesc->bInterval * 4113 if (epipe->pipe.up_endpoint->ue_edesc->bInterval *
4114 xfer->ux_nframes >= sc->sc_flsize - 4) { 4114 xfer->ux_nframes >= sc->sc_flsize - 4) {
4115 printf("ehci: isoc descriptor requested that spans the entire" 4115 printf("ehci: isoc descriptor requested that spans the entire"
4116 "frametable, too many frames\n"); 4116 "frametable, too many frames\n");
4117 return USBD_INVAL; 4117 return USBD_INVAL;
4118 } 4118 }
4119 4119
4120 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); 4120 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST));
4121 KASSERT(exfer->ex_isdone); 4121 KASSERT(exfer->ex_isdone);
4122 4122
4123#ifdef DIAGNOSTIC 4123#ifdef DIAGNOSTIC
4124 exfer->ex_isdone = false; 4124 exfer->ex_isdone = false;
4125#endif 4125#endif
4126 4126
4127 /* 4127 /*
4128 * Step 1: Allocate and initialize sitds. 4128 * Step 1: Allocate and initialize sitds.
4129 */ 4129 */
4130 4130
4131 i = epipe->pipe.up_endpoint->ue_edesc->bInterval; 4131 i = epipe->pipe.up_endpoint->ue_edesc->bInterval;
4132 if (i > 16 || i == 0) { 4132 if (i > 16 || i == 0) {
4133 /* Spec page 271 says intervals > 16 are invalid */ 4133 /* Spec page 271 says intervals > 16 are invalid */
4134 USBHIST_LOG(ehcidebug, "bInterval %d invalid", 0, 0, 0, 0); 4134 USBHIST_LOG(ehcidebug, "bInterval %d invalid", 0, 0, 0, 0);
4135 4135
4136 return USBD_INVAL; 4136 return USBD_INVAL;
4137 } 4137 }
4138 4138
4139 frames = xfer->ux_nframes; 4139 frames = xfer->ux_nframes;
4140 4140
4141 if (frames == 0) { 4141 if (frames == 0) {
4142 USBHIST_LOG(ehcidebug, "frames == 0", 0, 0, 0, 0); 4142 USBHIST_LOG(ehcidebug, "frames == 0", 0, 0, 0, 0);
4143 4143
4144 return USBD_INVAL; 4144 return USBD_INVAL;
4145 } 4145 }
4146 4146
4147 dma_buf = &xfer->ux_dmabuf; 4147 dma_buf = &xfer->ux_dmabuf;
4148 offs = 0; 4148 offs = 0;
4149 4149
4150 for (i = 0; i < frames; i++) { 4150 for (i = 0; i < frames; i++) {
4151 sitd = ehci_alloc_sitd(sc); 4151 sitd = ehci_alloc_sitd(sc);
4152 4152
4153 if (prev) 4153 if (prev)
4154 prev->xfer_next = sitd; 4154 prev->xfer_next = sitd;
4155 else 4155 else
4156 start = sitd; 4156 start = sitd;
4157 4157
4158#ifdef DIAGNOSTIC 4158#ifdef DIAGNOSTIC
4159 if (xfer->ux_frlengths[i] > 0x3ff) { 4159 if (xfer->ux_frlengths[i] > 0x3ff) {
4160 printf("ehci: invalid frame length\n"); 4160 printf("ehci: invalid frame length\n");
4161 xfer->ux_frlengths[i] = 0x3ff; 4161 xfer->ux_frlengths[i] = 0x3ff;
4162 } 4162 }
4163#endif 4163#endif
4164 4164
4165 sitd->sitd.sitd_trans = htole32(EHCI_SITD_ACTIVE | 4165 sitd->sitd.sitd_trans = htole32(EHCI_SITD_ACTIVE |
4166 EHCI_SITD_SET_LEN(xfer->ux_frlengths[i])); 4166 EHCI_SITD_SET_LEN(xfer->ux_frlengths[i]));
4167 4167
4168 /* Set page0 index and offset. */ 4168 /* Set page0 index and offset. */
4169 sitd->sitd.sitd_buffer[0] = htole32(DMAADDR(dma_buf, offs)); 4169 sitd->sitd.sitd_buffer[0] = htole32(DMAADDR(dma_buf, offs));
4170 4170
4171 total_length += xfer->ux_frlengths[i]; 4171 total_length += xfer->ux_frlengths[i];
4172 offs += xfer->ux_frlengths[i]; 4172 offs += xfer->ux_frlengths[i];
4173 4173
4174 sitd->sitd.sitd_buffer[1] = 4174 sitd->sitd.sitd_buffer[1] =
4175 htole32(EHCI_SITD_SET_BPTR(DMAADDR(dma_buf, offs - 1))); 4175 htole32(EHCI_SITD_SET_BPTR(DMAADDR(dma_buf, offs - 1)));
4176 4176
4177 huba = dev->ud_myhsport->up_parent->ud_addr; 4177 huba = dev->ud_myhsport->up_parent->ud_addr;
4178 4178
4179/* if (sc->sc_flags & EHCIF_FREESCALE) { 4179/* if (sc->sc_flags & EHCIF_FREESCALE) {
4180 // Set hub address to 0 if embedded TT is used. 4180 // Set hub address to 0 if embedded TT is used.
4181 if (huba == sc->sc_addr) 4181 if (huba == sc->sc_addr)
4182 huba = 0; 4182 huba = 0;
4183 } 4183 }
4184*/ 4184*/
4185 4185
4186 k = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress; 4186 k = epipe->pipe.up_endpoint->ue_edesc->bEndpointAddress;
4187 dir = UE_GET_DIR(k) ? 1 : 0; 4187 dir = UE_GET_DIR(k) ? 1 : 0;
4188 sitd->sitd.sitd_endp = 4188 sitd->sitd.sitd_endp =
4189 htole32(EHCI_SITD_SET_ENDPT(UE_GET_ADDR(k)) | 4189 htole32(EHCI_SITD_SET_ENDPT(UE_GET_ADDR(k)) |
4190 EHCI_SITD_SET_DADDR(dev->ud_addr) | 4190 EHCI_SITD_SET_DADDR(dev->ud_addr) |
4191 EHCI_SITD_SET_PORT(dev->ud_myhsport->up_portno) | 4191 EHCI_SITD_SET_PORT(dev->ud_myhsport->up_portno) |
4192 EHCI_SITD_SET_HUBA(huba) | 4192 EHCI_SITD_SET_HUBA(huba) |
4193 EHCI_SITD_SET_DIR(dir)); 4193 EHCI_SITD_SET_DIR(dir));
4194 4194
4195 sitd->sitd.sitd_back = htole32(EHCI_LINK_TERMINATE); 4195 sitd->sitd.sitd_back = htole32(EHCI_LINK_TERMINATE);
4196 4196
4197 /* XXX */ 4197 /* XXX */
4198 u_char sa, sb; 4198 u_char sa, sb;
4199 u_int temp, tlen; 4199 u_int temp, tlen;
4200 sa = 0; 4200 sa = 0;
4201 4201
4202 if (dir == 0) { /* OUT */ 4202 if (dir == 0) { /* OUT */
4203 temp = 0; 4203 temp = 0;
4204 tlen = xfer->ux_frlengths[i]; 4204 tlen = xfer->ux_frlengths[i];
4205 if (tlen <= 188) { 4205 if (tlen <= 188) {
4206 temp |= 1; /* T-count = 1, TP = ALL */ 4206 temp |= 1; /* T-count = 1, TP = ALL */
4207 tlen = 1; 4207 tlen = 1;
4208 } else { 4208 } else {
4209 tlen += 187; 4209 tlen += 187;
4210 tlen /= 188; 4210 tlen /= 188;
4211 temp |= tlen; /* T-count = [1..6] */ 4211 temp |= tlen; /* T-count = [1..6] */
4212 temp |= 8; /* TP = Begin */ 4212 temp |= 8; /* TP = Begin */
4213 } 4213 }
4214 sitd->sitd.sitd_buffer[1] |= htole32(temp); 4214 sitd->sitd.sitd_buffer[1] |= htole32(temp);
4215 4215
4216 tlen += sa; 4216 tlen += sa;
4217 4217
4218 if (tlen >= 8) { 4218 if (tlen >= 8) {
4219 sb = 0; 4219 sb = 0;
4220 } else { 4220 } else {
4221 sb = (1 << tlen); 4221 sb = (1 << tlen);
4222 } 4222 }
4223 4223
4224 sa = (1 << sa); 4224 sa = (1 << sa);
4225 sa = (sb - sa) & 0x3F; 4225 sa = (sb - sa) & 0x3F;
4226 sb = 0; 4226 sb = 0;
4227 } else { 4227 } else {
4228 sb = (-(4 << sa)) & 0xFE; 4228 sb = (-(4 << sa)) & 0xFE;
4229 sa = (1 << sa) & 0x3F; 4229 sa = (1 << sa) & 0x3F;
4230 sa = 0x01; 4230 sa = 0x01;
4231 sb = 0xfc; 4231 sb = 0xfc;
4232 } 4232 }
4233 4233
4234 sitd->sitd.sitd_sched = htole32(EHCI_SITD_SET_SMASK(sa) | 4234 sitd->sitd.sitd_sched = htole32(EHCI_SITD_SET_SMASK(sa) |
4235 EHCI_SITD_SET_CMASK(sb)); 4235 EHCI_SITD_SET_CMASK(sb));
4236 4236
4237 prev = sitd; 4237 prev = sitd;
4238 } /* End of frame */ 4238 } /* End of frame */
4239 4239
4240 sitd->sitd.sitd_trans |= htole32(EHCI_SITD_IOC); 4240 sitd->sitd.sitd_trans |= htole32(EHCI_SITD_IOC);
4241 4241
4242 stop = sitd; 4242 stop = sitd;
4243 stop->xfer_next = NULL; 4243 stop->xfer_next = NULL;
4244 4244
4245 usb_syncmem(&exfer->ex_xfer.ux_dmabuf, 0, total_length, 4245 usb_syncmem(&exfer->ex_xfer.ux_dmabuf, 0, total_length,
4246 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); 4246 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
4247 4247
4248 /* 4248 /*
4249 * Part 2: Transfer descriptors have now been set up, now they must 4249 * Part 2: Transfer descriptors have now been set up, now they must
4250 * be scheduled into the periodic frame list. Erk. Not wanting to 4250 * be scheduled into the periodic frame list. Erk. Not wanting to
4251 * complicate matters, transfer is denied if the transfer spans 4251 * complicate matters, transfer is denied if the transfer spans
4252 * more than the period frame list. 4252 * more than the period frame list.
4253 */ 4253 */
4254 4254
4255 mutex_enter(&sc->sc_lock); 4255 mutex_enter(&sc->sc_lock);
4256 4256
4257 /* Start inserting frames */ 4257 /* Start inserting frames */
4258 if (epipe->u.isoc.cur_xfers > 0) { 4258 if (epipe->u.isoc.cur_xfers > 0) {
4259 frindex = epipe->u.isoc.next_frame; 4259 frindex = epipe->u.isoc.next_frame;
4260 } else { 4260 } else {
4261 frindex = EOREAD4(sc, EHCI_FRINDEX); 4261 frindex = EOREAD4(sc, EHCI_FRINDEX);
4262 frindex = frindex >> 3; /* Erase microframe index */ 4262 frindex = frindex >> 3; /* Erase microframe index */
4263 frindex += 2; 4263 frindex += 2;
4264 } 4264 }
4265 4265
4266 if (frindex >= sc->sc_flsize) 4266 if (frindex >= sc->sc_flsize)
4267 frindex &= (sc->sc_flsize - 1); 4267 frindex &= (sc->sc_flsize - 1);
4268 4268
4269 /* Whats the frame interval? */ 4269 /* Whats the frame interval? */
4270 i = epipe->pipe.up_endpoint->ue_edesc->bInterval; 4270 i = epipe->pipe.up_endpoint->ue_edesc->bInterval;
4271 4271
4272 sitd = start; 4272 sitd = start;
4273 for (j = 0; j < frames; j++) { 4273 for (j = 0; j < frames; j++) {
4274 if (sitd == NULL) 4274 if (sitd == NULL)
4275 panic("ehci: unexpectedly ran out of isoc sitds\n"); 4275 panic("ehci: unexpectedly ran out of isoc sitds\n");
4276 4276
4277 sitd->sitd.sitd_next = sc->sc_flist[frindex]; 4277 sitd->sitd.sitd_next = sc->sc_flist[frindex];
4278 if (sitd->sitd.sitd_next == 0) 4278 if (sitd->sitd.sitd_next == 0)
4279 /* FIXME: frindex table gets initialized to NULL 4279 /* FIXME: frindex table gets initialized to NULL
4280 * or EHCI_NULL? */ 4280 * or EHCI_NULL? */
4281 sitd->sitd.sitd_next = EHCI_NULL; 4281 sitd->sitd.sitd_next = EHCI_NULL;
4282 4282
4283 usb_syncmem(&sitd->dma, 4283 usb_syncmem(&sitd->dma,
4284 sitd->offs + offsetof(ehci_sitd_t, sitd_next), 4284 sitd->offs + offsetof(ehci_sitd_t, sitd_next),
4285 sizeof(ehci_sitd_t), 4285 sizeof(ehci_sitd_t),
4286 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 4286 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
4287 4287
4288 sc->sc_flist[frindex] = 4288 sc->sc_flist[frindex] =
4289 htole32(EHCI_LINK_SITD | sitd->physaddr); 4289 htole32(EHCI_LINK_SITD | sitd->physaddr);
4290 4290
4291 usb_syncmem(&sc->sc_fldma, 4291 usb_syncmem(&sc->sc_fldma,
4292 sizeof(ehci_link_t) * frindex, 4292 sizeof(ehci_link_t) * frindex,
4293 sizeof(ehci_link_t), 4293 sizeof(ehci_link_t),
4294 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 4294 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
4295 4295
4296 sitd->u.frame_list.next = sc->sc_softsitds[frindex]; 4296 sitd->u.frame_list.next = sc->sc_softsitds[frindex];
4297 sc->sc_softsitds[frindex] = sitd; 4297 sc->sc_softsitds[frindex] = sitd;
4298 if (sitd->u.frame_list.next != NULL) 4298 if (sitd->u.frame_list.next != NULL)
4299 sitd->u.frame_list.next->u.frame_list.prev = sitd; 4299 sitd->u.frame_list.next->u.frame_list.prev = sitd;
4300 sitd->slot = frindex; 4300 sitd->slot = frindex;
4301 sitd->u.frame_list.prev = NULL; 4301 sitd->u.frame_list.prev = NULL;
4302 4302
4303 frindex += i; 4303 frindex += i;
4304 if (frindex >= sc->sc_flsize) 4304 if (frindex >= sc->sc_flsize)
4305 frindex -= sc->sc_flsize; 4305 frindex -= sc->sc_flsize;
4306 4306
4307 sitd = sitd->xfer_next; 4307 sitd = sitd->xfer_next;
4308 } 4308 }
4309 4309
4310 epipe->u.isoc.cur_xfers++; 4310 epipe->u.isoc.cur_xfers++;
4311 epipe->u.isoc.next_frame = frindex; 4311 epipe->u.isoc.next_frame = frindex;
4312 4312
4313 exfer->ex_sitdstart = start; 4313 exfer->ex_sitdstart = start;
4314 exfer->ex_sitdend = stop; 4314 exfer->ex_sitdend = stop;
4315 4315
4316 ehci_add_intr_list(sc, exfer); 4316 ehci_add_intr_list(sc, exfer);
4317 xfer->ux_status = USBD_IN_PROGRESS; 4317 xfer->ux_status = USBD_IN_PROGRESS;
4318 xfer->ux_done = 0; 4318 xfer->ux_done = 0;
4319 4319
4320 mutex_exit(&sc->sc_lock); 4320 mutex_exit(&sc->sc_lock);
4321 4321
4322 if (sc->sc_bus.ub_usepolling) { 4322 if (sc->sc_bus.ub_usepolling) {
4323 printf("Starting ehci isoc xfer with polling. Bad idea?\n"); 4323 printf("Starting ehci isoc xfer with polling. Bad idea?\n");
4324 ehci_waitintr(sc, xfer); 4324 ehci_waitintr(sc, xfer);
4325 } 4325 }
4326 4326
4327 return USBD_IN_PROGRESS; 4327 return USBD_IN_PROGRESS;
4328} 4328}
4329 4329
4330Static void 4330Static void
4331ehci_device_fs_isoc_abort(usbd_xfer_handle xfer) 4331ehci_device_fs_isoc_abort(usbd_xfer_handle xfer)
4332{ 4332{
4333 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 4333 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
4334 4334
4335 USBHIST_LOG(ehcidebug, "xfer = %p", xfer, 0, 0, 0); 4335 USBHIST_LOG(ehcidebug, "xfer = %p", xfer, 0, 0, 0);
4336 ehci_abort_isoc_xfer(xfer, USBD_CANCELLED); 4336 ehci_abort_isoc_xfer(xfer, USBD_CANCELLED);
4337} 4337}
4338 4338
4339Static void 4339Static void
4340ehci_device_fs_isoc_close(usbd_pipe_handle pipe) 4340ehci_device_fs_isoc_close(usbd_pipe_handle pipe)
4341{ 4341{
4342 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 4342 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
4343 4343
4344 USBHIST_LOG(ehcidebug, "nothing in the pipe to free?", 0, 0, 0, 0); 4344 USBHIST_LOG(ehcidebug, "nothing in the pipe to free?", 0, 0, 0, 0);
4345} 4345}
4346 4346
4347Static void 4347Static void
4348ehci_device_fs_isoc_done(usbd_xfer_handle xfer) 4348ehci_device_fs_isoc_done(usbd_xfer_handle xfer)
4349{ 4349{
4350 struct ehci_xfer *exfer; 4350 struct ehci_xfer *exfer;
4351 ehci_softc_t *sc; 4351 ehci_softc_t *sc;
4352 struct ehci_pipe *epipe; 4352 struct ehci_pipe *epipe;
4353 4353
4354 exfer = EXFER(xfer); 4354 exfer = EXFER(xfer);
4355 sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 4355 sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
4356 epipe = (struct ehci_pipe *) xfer->ux_pipe; 4356 epipe = (struct ehci_pipe *) xfer->ux_pipe;
4357 4357
4358 KASSERT(mutex_owned(&sc->sc_lock)); 4358 KASSERT(mutex_owned(&sc->sc_lock));
4359 4359
4360 epipe->u.isoc.cur_xfers--; 4360 epipe->u.isoc.cur_xfers--;
4361 if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(exfer)) { 4361 if (xfer->ux_status != USBD_NOMEM && ehci_active_intr_list(exfer)) {
4362 ehci_del_intr_list(sc, exfer); 4362 ehci_del_intr_list(sc, exfer);
4363 ehci_rem_free_sitd_chain(sc, exfer); 4363 ehci_rem_free_sitd_chain(sc, exfer);
4364 } 4364 }
4365 4365
4366 usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, BUS_DMASYNC_POSTWRITE | 4366 usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length, BUS_DMASYNC_POSTWRITE |
4367 BUS_DMASYNC_POSTREAD); 4367 BUS_DMASYNC_POSTREAD);
4368} 4368}
4369Static usbd_status 4369Static usbd_status
4370ehci_device_isoc_transfer(usbd_xfer_handle xfer) 4370ehci_device_isoc_transfer(usbd_xfer_handle xfer)
4371{ 4371{
4372 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 4372 ehci_softc_t *sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
4373 usbd_status err; 4373 usbd_status err;
4374 4374
4375 mutex_enter(&sc->sc_lock); 4375 mutex_enter(&sc->sc_lock);
4376 err = usb_insert_transfer(xfer); 4376 err = usb_insert_transfer(xfer);
4377 mutex_exit(&sc->sc_lock); 4377 mutex_exit(&sc->sc_lock);
4378 if (err && err != USBD_IN_PROGRESS) 4378 if (err && err != USBD_IN_PROGRESS)
4379 return err; 4379 return err;
4380 4380
4381 return ehci_device_isoc_start(xfer); 4381 return ehci_device_isoc_start(xfer);
4382} 4382}
4383 4383
4384Static usbd_status 4384Static usbd_status
4385ehci_device_isoc_start(usbd_xfer_handle xfer) 4385ehci_device_isoc_start(usbd_xfer_handle xfer)
4386{ 4386{
4387 struct ehci_pipe *epipe; 4387 struct ehci_pipe *epipe;
4388 ehci_softc_t *sc; 4388 ehci_softc_t *sc;
4389 struct ehci_xfer *exfer; 4389 struct ehci_xfer *exfer;
4390 ehci_soft_itd_t *itd, *prev, *start, *stop; 4390 ehci_soft_itd_t *itd, *prev, *start, *stop;
4391 usb_dma_t *dma_buf; 4391 usb_dma_t *dma_buf;
4392 int i, j, k, frames, uframes, ufrperframe; 4392 int i, j, k, frames, uframes, ufrperframe;
4393 int trans_count, offs, total_length; 4393 int trans_count, offs, total_length;
4394 int frindex; 4394 int frindex;
4395 4395
4396 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug); 4396 USBHIST_FUNC(); USBHIST_CALLED(ehcidebug);
4397 4397
4398 start = NULL; 4398 start = NULL;
4399 prev = NULL; 4399 prev = NULL;
4400 itd = NULL; 4400 itd = NULL;
4401 trans_count = 0; 4401 trans_count = 0;
4402 total_length = 0; 4402 total_length = 0;
4403 exfer = (struct ehci_xfer *) xfer; 4403 exfer = (struct ehci_xfer *) xfer;
4404 sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv; 4404 sc = xfer->ux_pipe->up_dev->ud_bus->ub_hcpriv;
4405 epipe = (struct ehci_pipe *)xfer->ux_pipe; 4405 epipe = (struct ehci_pipe *)xfer->ux_pipe;
4406 4406
4407 /* 4407 /*
4408 * To allow continuous transfers, above we start all transfers 4408 * To allow continuous transfers, above we start all transfers
4409 * immediately. However, we're still going to get usbd_start_next call 4409 * immediately. However, we're still going to get usbd_start_next call
4410 * this when another xfer completes. So, check if this is already 4410 * this when another xfer completes. So, check if this is already
4411 * in progress or not 4411 * in progress or not
4412 */ 4412 */
4413 4413
4414 if (exfer->ex_itdstart != NULL) 4414 if (exfer->ex_itdstart != NULL)
4415 return USBD_IN_PROGRESS; 4415 return USBD_IN_PROGRESS;
4416 4416
4417 USBHIST_LOG(ehcidebug, "xfer %p len %d flags %d", 4417 USBHIST_LOG(ehcidebug, "xfer %p len %d flags %d",
4418 xfer, xfer->ux_length, xfer->ux_flags, 0); 4418 xfer, xfer->ux_length, xfer->ux_flags, 0);
4419 4419
4420 if (sc->sc_dying) 4420 if (sc->sc_dying)
4421 return USBD_IOERROR; 4421 return USBD_IOERROR;
4422 4422
4423 /* 4423 /*
4424 * To avoid complication, don't allow a request right now that'll span 4424 * To avoid complication, don't allow a request right now that'll span
4425 * the entire frame table. To within 4 frames, to allow some leeway 4425 * the entire frame table. To within 4 frames, to allow some leeway
4426 * on either side of where the hc currently is. 4426 * on either side of where the hc currently is.
4427 */ 4427 */
4428 if ((1 << (epipe->pipe.up_endpoint->ue_edesc->bInterval)) * 4428 if ((1 << (epipe->pipe.up_endpoint->ue_edesc->bInterval)) *
4429 xfer->ux_nframes >= (sc->sc_flsize - 4) * 8) { 4429 xfer->ux_nframes >= (sc->sc_flsize - 4) * 8) {
4430 USBHIST_LOG(ehcidebug, 4430 USBHIST_LOG(ehcidebug,
4431 "isoc descriptor spans entire frametable", 0, 0, 0, 0); 4431 "isoc descriptor spans entire frametable", 0, 0, 0, 0);
4432 printf("ehci: isoc descriptor requested that spans the entire frametable, too many frames\n"); 4432 printf("ehci: isoc descriptor requested that spans the entire frametable, too many frames\n");
4433 return USBD_INVAL; 4433 return USBD_INVAL;
4434 } 4434 }
4435 4435
4436 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST)); 4436 KASSERT(!(xfer->ux_rqflags & URQ_REQUEST));
4437 KASSERT(exfer->ex_isdone); 4437 KASSERT(exfer->ex_isdone);
4438#ifdef DIAGNOSTIC 4438#ifdef DIAGNOSTIC
4439 exfer->ex_isdone = false; 4439 exfer->ex_isdone = false;
4440#endif 4440#endif
4441 4441
4442 /* 4442 /*
4443 * Step 1: Allocate and initialize itds, how many do we need? 4443 * Step 1: Allocate and initialize itds, how many do we need?
4444 * One per transfer if interval >= 8 microframes, fewer if we use 4444 * One per transfer if interval >= 8 microframes, fewer if we use
4445 * multiple microframes per frame. 4445 * multiple microframes per frame.
4446 */ 4446 */
4447 4447
4448 i = epipe->pipe.up_endpoint->ue_edesc->bInterval; 4448 i = epipe->pipe.up_endpoint->ue_edesc->bInterval;
4449 if (i > 16 || i == 0) { 4449 if (i > 16 || i == 0) {
4450 /* Spec page 271 says intervals > 16 are invalid */ 4450 /* Spec page 271 says intervals > 16 are invalid */
4451 USBHIST_LOG(ehcidebug, "bInterval %d invalid", i, 0, 0, 0); 4451 USBHIST_LOG(ehcidebug, "bInterval %d invalid", i, 0, 0, 0);
4452 return USBD_INVAL; 4452 return USBD_INVAL;
4453 } 4453 }
4454 4454
4455 ufrperframe = max(1, USB_UFRAMES_PER_FRAME / (1 << (i - 1))); 4455 ufrperframe = max(1, USB_UFRAMES_PER_FRAME / (1 << (i - 1)));
4456 frames = (xfer->ux_nframes + (ufrperframe - 1)) / ufrperframe; 4456 frames = (xfer->ux_nframes + (ufrperframe - 1)) / ufrperframe;
4457 uframes = USB_UFRAMES_PER_FRAME / ufrperframe; 4457 uframes = USB_UFRAMES_PER_FRAME / ufrperframe;
4458 4458
4459 if (frames == 0) { 4459 if (frames == 0) {
4460 USBHIST_LOG(ehcidebug, "frames == 0", 0, 0, 0, 0); 4460 USBHIST_LOG(ehcidebug, "frames == 0", 0, 0, 0, 0);
4461 return USBD_INVAL; 4461 return USBD_INVAL;
4462 } 4462 }
4463 4463
4464 dma_buf = &xfer->ux_dmabuf; 4464 dma_buf = &xfer->ux_dmabuf;
4465 offs = 0; 4465 offs = 0;
4466 4466
4467 for (i = 0; i < frames; i++) { 4467 for (i = 0; i < frames; i++) {
4468 int froffs = offs; 4468 int froffs = offs;
4469 itd = ehci_alloc_itd(sc); 4469 itd = ehci_alloc_itd(sc);
4470 4470
4471 if (prev != NULL) { 4471 if (prev != NULL) {
4472 prev->itd.itd_next = 4472 prev->itd.itd_next =
4473 htole32(itd->physaddr | EHCI_LINK_ITD); 4473 htole32(itd->physaddr | EHCI_LINK_ITD);
4474 usb_syncmem(&itd->dma, 4474 usb_syncmem(&itd->dma,
4475 itd->offs + offsetof(ehci_itd_t, itd_next), 4475 itd->offs + offsetof(ehci_itd_t, itd_next),
4476 sizeof(itd->itd.itd_next), BUS_DMASYNC_POSTWRITE); 4476 sizeof(itd->itd.itd_next), BUS_DMASYNC_POSTWRITE);
4477 4477
4478 prev->xfer_next = itd; 4478 prev->xfer_next = itd;
4479 } else { 4479 } else {
4480 start = itd; 4480 start = itd;
4481 } 4481 }
4482 4482
4483 /* 4483 /*
4484 * Step 1.5, initialize uframes 4484 * Step 1.5, initialize uframes
4485 */ 4485 */
4486 for (j = 0; j < EHCI_ITD_NUFRAMES; j += uframes) { 4486 for (j = 0; j < EHCI_ITD_NUFRAMES; j += uframes) {
4487 /* Calculate which page in the list this starts in */ 4487 /* Calculate which page in the list this starts in */
4488 int addr = DMAADDR(dma_buf, froffs); 4488 int addr = DMAADDR(dma_buf, froffs);
4489 addr = EHCI_PAGE_OFFSET(addr); 4489 addr = EHCI_PAGE_OFFSET(addr);
4490 addr += (offs - froffs); 4490 addr += (offs - froffs);
4491 addr = EHCI_PAGE(addr); 4491 addr = EHCI_PAGE(addr);
4492 addr /= EHCI_PAGE_SIZE; 4492 addr /= EHCI_PAGE_SIZE;
4493 4493
4494 /* 4494 /*
4495 * This gets the initial offset into the first page, 4495 * This gets the initial offset into the first page,
4496 * looks how far further along the current uframe 4496 * looks how far further along the current uframe
4497 * offset is. Works out how many pages that is. 4497 * offset is. Works out how many pages that is.
4498 */ 4498 */
4499 4499
4500 itd->itd.itd_ctl[j] = htole32 ( EHCI_ITD_ACTIVE | 4500 itd->itd.itd_ctl[j] = htole32 ( EHCI_ITD_ACTIVE |
4501 EHCI_ITD_SET_LEN(xfer->ux_frlengths[trans_count]) | 4501 EHCI_ITD_SET_LEN(xfer->ux_frlengths[trans_count]) |
4502 EHCI_ITD_SET_PG(addr) | 4502 EHCI_ITD_SET_PG(addr) |
4503 EHCI_ITD_SET_OFFS(EHCI_PAGE_OFFSET(DMAADDR(dma_buf,offs)))); 4503 EHCI_ITD_SET_OFFS(EHCI_PAGE_OFFSET(DMAADDR(dma_buf,offs))));
4504 4504
4505 total_length += xfer->ux_frlengths[trans_count]; 4505 total_length += xfer->ux_frlengths[trans_count];
4506 offs += xfer->ux_frlengths[trans_count]; 4506 offs += xfer->ux_frlengths[trans_count];
4507 trans_count++; 4507 trans_count++;
4508 4508
4509 if (trans_count >= xfer->ux_nframes) { /*Set IOC*/ 4509 if (trans_count >= xfer->ux_nframes) { /*Set IOC*/
4510 itd->itd.itd_ctl[j] |= htole32(EHCI_ITD_IOC); 4510 itd->itd.itd_ctl[j] |= htole32(EHCI_ITD_IOC);
4511 break; 4511 break;
4512 } 4512 }
4513 } 4513 }
4514 4514
4515 /* 4515 /*
4516 * Step 1.75, set buffer pointers. To simplify matters, all 4516 * Step 1.75, set buffer pointers. To simplify matters, all
4517 * pointers are filled out for the next 7 hardware pages in 4517 * pointers are filled out for the next 7 hardware pages in
4518 * the dma block, so no need to worry what pages to cover 4518 * the dma block, so no need to worry what pages to cover
4519 * and what to not. 4519 * and what to not.
4520 */ 4520 */
4521 4521
4522 for (j = 0; j < EHCI_ITD_NBUFFERS; j++) { 4522 for (j = 0; j < EHCI_ITD_NBUFFERS; j++) {
4523 /* 4523 /*
4524 * Don't try to lookup a page that's past the end 4524 * Don't try to lookup a page that's past the end
4525 * of buffer 4525 * of buffer
4526 */ 4526 */
4527 int page_offs = EHCI_PAGE(froffs + (EHCI_PAGE_SIZE * j)); 4527 int page_offs = EHCI_PAGE(froffs + (EHCI_PAGE_SIZE * j));
4528 if (page_offs >= dma_buf->udma_block->size) 4528 if (page_offs >= dma_buf->udma_block->size)
4529 break; 4529 break;
4530 4530
4531 unsigned long long page = DMAADDR(dma_buf, page_offs); 4531 unsigned long long page = DMAADDR(dma_buf, page_offs);
4532 page = EHCI_PAGE(page); 4532 page = EHCI_PAGE(page);
4533 itd->itd.itd_bufr[j] = 4533 itd->itd.itd_bufr[j] =
4534 htole32(EHCI_ITD_SET_BPTR(page)); 4534 htole32(EHCI_ITD_SET_BPTR(page));
4535 itd->itd.itd_bufr_hi[j] = 4535 itd->itd.itd_bufr_hi[j] =
4536 htole32(page >> 32); 4536 htole32(page >> 32);
4537 } 4537 }
4538 4538
4539 /* 4539 /*
4540 * Other special values 4540 * Other special values
4541 */ 4541 */

cvs diff -r1.34.14.5 -r1.34.14.6 src/sys/dev/usb/ehcireg.h (switch to unified diff)

--- src/sys/dev/usb/ehcireg.h 2015/03/03 06:36:53 1.34.14.5
+++ src/sys/dev/usb/ehcireg.h 2015/03/03 10:06:01 1.34.14.6
@@ -1,405 +1,433 @@ @@ -1,405 +1,433 @@
1/* $NetBSD: ehcireg.h,v 1.34.14.5 2015/03/03 06:36:53 skrll Exp $ */ 1/* $NetBSD: ehcireg.h,v 1.34.14.6 2015/03/03 10:06:01 skrll Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001, 2004 The NetBSD Foundation, Inc. 4 * Copyright (c) 2001, 2004 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/* 32/*
33 * The EHCI 0.96 spec can be found at 33 * The EHCI 0.96 spec can be found at
34 * http://developer.intel.com/technology/usb/download/ehci-r096.pdf 34 * http://developer.intel.com/technology/usb/download/ehci-r096.pdf
35 * and the USB 2.0 spec at 35 * and the USB 2.0 spec at
36 * http://www.usb.org/developers/data/usb_20.zip 36 * http://www.usb.org/developers/data/usb_20.zip
37 */ 37 */
38 38
39#ifndef _DEV_PCI_EHCIREG_H_ 39#ifndef _DEV_PCI_EHCIREG_H_
40#define _DEV_PCI_EHCIREG_H_ 40#define _DEV_PCI_EHCIREG_H_
41 41
42/*** PCI config registers ***/ 42/*** PCI config registers ***/
43 43
44#define PCI_CBMEM 0x10 /* configuration base MEM */ 44#define PCI_CBMEM 0x10 /* configuration base MEM */
45 45
46#define PCI_INTERFACE_EHCI 0x20 46#define PCI_INTERFACE_EHCI 0x20
47 47
48#define PCI_USBREV 0x60 /* RO USB protocol revision */ 48#define PCI_USBREV 0x60 /* RO USB protocol revision */
49#define PCI_USBREV_MASK 0xff 49#define PCI_USBREV_MASK 0xff
50#define PCI_USBREV_PRE_1_0 0x00 50#define PCI_USBREV_PRE_1_0 0x00
51#define PCI_USBREV_1_0 0x10 51#define PCI_USBREV_1_0 0x10
52#define PCI_USBREV_1_1 0x11 52#define PCI_USBREV_1_1 0x11
53#define PCI_USBREV_2_0 0x20 53#define PCI_USBREV_2_0 0x20
54 54
55#define PCI_EHCI_FLADJ 0x61 /*RW Frame len adj, SOF=59488+6*fladj */ 55#define PCI_EHCI_FLADJ 0x61 /*RW Frame len adj, SOF=59488+6*fladj */
56 56
57#define PCI_EHCI_PORTWAKECAP 0x62 /* RW Port wake caps (opt) */ 57#define PCI_EHCI_PORTWAKECAP 0x62 /* RW Port wake caps (opt) */
58 58
59/* Regs at EECP + offset */ 59/* Regs at EECP + offset */
60#define PCI_EHCI_USBLEGSUP 0x00 60#define PCI_EHCI_USBLEGSUP 0x00
61#define EHCI_LEG_HC_OS_OWNED 0x01000000 61#define EHCI_LEG_HC_OS_OWNED 0x01000000
62#define EHCI_LEG_HC_BIOS_OWNED 0x00010000 62#define EHCI_LEG_HC_BIOS_OWNED 0x00010000
63#define PCI_EHCI_USBLEGCTLSTS 0x04 63#define PCI_EHCI_USBLEGCTLSTS 0x04
64#define EHCI_LEG_EXT_SMI_BAR 0x80000000 64#define EHCI_LEG_EXT_SMI_BAR 0x80000000
65#define EHCI_LEG_EXT_SMI_PCICMD 0x40000000 65#define EHCI_LEG_EXT_SMI_PCICMD 0x40000000
66#define EHCI_LEG_EXT_SMI_OS_CHANGE 0x20000000 66#define EHCI_LEG_EXT_SMI_OS_CHANGE 0x20000000
67 67
68#define EHCI_CAP_GET_ID(cap) ((cap) & 0xff) 68#define EHCI_CAP_GET_ID(cap) ((cap) & 0xff)
69#define EHCI_CAP_GET_NEXT(cap) (((cap) >> 8) & 0xff) 69#define EHCI_CAP_GET_NEXT(cap) (((cap) >> 8) & 0xff)
70#define EHCI_CAP_ID_LEGACY 1 70#define EHCI_CAP_ID_LEGACY 1
71 71
72/*** EHCI capability registers ***/ 72/*** EHCI capability registers ***/
73 73
74#define EHCI_CAPLENGTH 0x00 /*RO Capability register length field */ 74#define EHCI_CAPLENGTH 0x00 /*RO Capability register length field */
75/* reserved 0x01 */ 75/* reserved 0x01 */
76#define EHCI_HCIVERSION 0x02 /* RO Interface version number */ 76#define EHCI_HCIVERSION 0x02 /* RO Interface version number */
77 77
78#define EHCI_HCSPARAMS 0x04 /* RO Structural parameters */ 78#define EHCI_HCSPARAMS 0x04 /* RO Structural parameters */
79#define EHCI_HCS_N_TT(x) (((x) >> 20) & 0xf) /* # of xacts xlater ETTF */ 79#define EHCI_HCS_N_TT(x) (((x) >> 20) & 0xf) /* # of xacts xlater ETTF */
80#define EHCI_HCS_N_PTT(x) (((x) >> 20) & 0xf) /* ports per xlater ETTF */ 80#define EHCI_HCS_N_PTT(x) (((x) >> 20) & 0xf) /* ports per xlater ETTF */
81#define EHCI_HCS_DEBUGPORT(x) (((x) >> 20) & 0xf) 81#define EHCI_HCS_DEBUGPORT(x) (((x) >> 20) & 0xf)
82#define EHCI_HCS_P_INDICATOR(x) ((x) & 0x10000) 82#define EHCI_HCS_P_INDICATOR(x) ((x) & 0x10000)
83#define EHCI_HCS_N_CC(x) (((x) >> 12) & 0xf) /* # of companion ctlrs */ 83#define EHCI_HCS_N_CC(x) (((x) >> 12) & 0xf) /* # of companion ctlrs */
84#define EHCI_HCS_N_PCC(x) (((x) >> 8) & 0xf) /* # of ports per comp. */ 84#define EHCI_HCS_N_PCC(x) (((x) >> 8) & 0xf) /* # of ports per comp. */
85#define EHCI_HCS_PPC(x) ((x) & 0x10) /* port power control */ 85#define EHCI_HCS_PPC(x) ((x) & 0x10) /* port power control */
86#define EHCI_HCS_N_PORTS(x) ((x) & 0xf) /* # of ports */ 86#define EHCI_HCS_N_PORTS(x) ((x) & 0xf) /* # of ports */
87 87
88#define EHCI_HCCPARAMS 0x08 /* RO Capability parameters */ 88#define EHCI_HCCPARAMS 0x08 /* RO Capability parameters */
89#define EHCI_HCC_EECP(x) (((x) >> 8) & 0xff) /* extended ports caps */ 89#define EHCI_HCC_EECP(x) (((x) >> 8) & 0xff) /* extended ports caps */
90#define EHCI_HCC_IST(x) (((x) >> 4) & 0xf) /* isoc sched threshold */ 90#define EHCI_HCC_IST(x) (((x) >> 4) & 0xf) /* isoc sched threshold */
91#define EHCI_HCC_ASPC(x) ((x) & 0x4) /* async sched park cap */ 91#define EHCI_HCC_ASPC(x) ((x) & 0x4) /* async sched park cap */
92#define EHCI_HCC_PFLF(x) ((x) & 0x2) /* prog frame list flag */ 92#define EHCI_HCC_PFLF(x) ((x) & 0x2) /* prog frame list flag */
93#define EHCI_HCC_64BIT(x) ((x) & 0x1) /* 64 bit address cap */ 93#define EHCI_HCC_64BIT(x) ((x) & 0x1) /* 64 bit address cap */
94 94
95#define EHCI_HCSP_PORTROUTE 0x0c /*RO Companion port route description */ 95#define EHCI_HCSP_PORTROUTE 0x0c /*RO Companion port route description */
96 96
97/* EHCI operational registers. Offset given by EHCI_CAPLENGTH register */ 97/* EHCI operational registers. Offset given by EHCI_CAPLENGTH register */
98#define EHCI_USBCMD 0x00 /* RO, RW, WO Command register */ 98#define EHCI_USBCMD 0x00 /* RO, RW, WO Command register */
99#define EHCI_CMD_ITC_M 0x00ff0000 /* RW interrupt threshold ctrl */ 99#define EHCI_CMD_ITC_M 0x00ff0000 /* RW interrupt threshold ctrl */
100#define EHCI_CMD_ITC_1 0x00010000 100#define EHCI_CMD_ITC_1 0x00010000
101#define EHCI_CMD_ITC_2 0x00020000 101#define EHCI_CMD_ITC_2 0x00020000
102#define EHCI_CMD_ITC_4 0x00040000 102#define EHCI_CMD_ITC_4 0x00040000
103#define EHCI_CMD_ITC_8 0x00080000 103#define EHCI_CMD_ITC_8 0x00080000
104#define EHCI_CMD_ITC_16 0x00100000 104#define EHCI_CMD_ITC_16 0x00100000
105#define EHCI_CMD_ITC_32 0x00200000 105#define EHCI_CMD_ITC_32 0x00200000
106#define EHCI_CMD_ITC_64 0x00400000 106#define EHCI_CMD_ITC_64 0x00400000
107#define EHCI_CMD_ASPME 0x00000800 /* RW/RO async park enable */ 107#define EHCI_CMD_ASPME 0x00000800 /* RW/RO async park enable */
108#define EHCI_CMD_ASPMC 0x00000300 /* RW/RO async park count */ 108#define EHCI_CMD_ASPMC 0x00000300 /* RW/RO async park count */
109#define EHCI_CMD_LHCR 0x00000080 /* RW light host ctrl reset */ 109#define EHCI_CMD_LHCR 0x00000080 /* RW light host ctrl reset */
110#define EHCI_CMD_IAAD 0x00000040 /* RW intr on async adv door bell */ 110#define EHCI_CMD_IAAD 0x00000040 /* RW intr on async adv door bell */
111#define EHCI_CMD_ASE 0x00000020 /* RW async sched enable */ 111#define EHCI_CMD_ASE 0x00000020 /* RW async sched enable */
112#define EHCI_CMD_PSE 0x00000010 /* RW periodic sched enable */ 112#define EHCI_CMD_PSE 0x00000010 /* RW periodic sched enable */
113#define EHCI_CMD_FLS_M 0x0000000c /* RW/RO frame list size */ 113#define EHCI_CMD_FLS_M 0x0000000c /* RW/RO frame list size */
114#define EHCI_CMD_FLS(x) (((x) >> 2) & 3) /* RW/RO frame list size */ 114#define EHCI_CMD_FLS(x) (((x) >> 2) & 3) /* RW/RO frame list size */
115#define EHCI_CMD_HCRESET 0x00000002 /* RW reset */ 115#define EHCI_CMD_HCRESET 0x00000002 /* RW reset */
116#define EHCI_CMD_RS 0x00000001 /* RW run/stop */ 116#define EHCI_CMD_RS 0x00000001 /* RW run/stop */
117 117
118#define EHCI_USBSTS 0x04 /* RO, RW, RWC Status register */ 118#define EHCI_USBSTS 0x04 /* RO, RW, RWC Status register */
119#define EHCI_STS_ASS 0x00008000 /* RO async sched status */ 119#define EHCI_STS_ASS 0x00008000 /* RO async sched status */
120#define EHCI_STS_PSS 0x00004000 /* RO periodic sched status */ 120#define EHCI_STS_PSS 0x00004000 /* RO periodic sched status */
121#define EHCI_STS_REC 0x00002000 /* RO reclamation */ 121#define EHCI_STS_REC 0x00002000 /* RO reclamation */
122#define EHCI_STS_HCH 0x00001000 /* RO host controller halted */ 122#define EHCI_STS_HCH 0x00001000 /* RO host controller halted */
123#define EHCI_STS_IAA 0x00000020 /* RWC interrupt on async adv */ 123#define EHCI_STS_IAA 0x00000020 /* RWC interrupt on async adv */
124#define EHCI_STS_HSE 0x00000010 /* RWC host system error */ 124#define EHCI_STS_HSE 0x00000010 /* RWC host system error */
125#define EHCI_STS_FLR 0x00000008 /* RWC frame list rollover */ 125#define EHCI_STS_FLR 0x00000008 /* RWC frame list rollover */
126#define EHCI_STS_PCD 0x00000004 /* RWC port change detect */ 126#define EHCI_STS_PCD 0x00000004 /* RWC port change detect */
127#define EHCI_STS_ERRINT 0x00000002 /* RWC error interrupt */ 127#define EHCI_STS_ERRINT 0x00000002 /* RWC error interrupt */
128#define EHCI_STS_INT 0x00000001 /* RWC interrupt */ 128#define EHCI_STS_INT 0x00000001 /* RWC interrupt */
129#define EHCI_STS_INTRS(x) ((x) & 0x3f) 129#define EHCI_STS_INTRS(x) ((x) & 0x3f)
130 130
131#define EHCI_NORMAL_INTRS (EHCI_STS_IAA | EHCI_STS_HSE | EHCI_STS_PCD | EHCI_STS_ERRINT | EHCI_STS_INT) 131#define EHCI_NORMAL_INTRS (EHCI_STS_IAA | EHCI_STS_HSE | EHCI_STS_PCD | EHCI_STS_ERRINT | EHCI_STS_INT)
132 132
133#define EHCI_USBINTR 0x08 /* RW Interrupt register */ 133#define EHCI_USBINTR 0x08 /* RW Interrupt register */
134#define EHCI_INTR_IAAE 0x00000020 /* interrupt on async advance ena */ 134#define EHCI_INTR_IAAE 0x00000020 /* interrupt on async advance ena */
135#define EHCI_INTR_HSEE 0x00000010 /* host system error ena */ 135#define EHCI_INTR_HSEE 0x00000010 /* host system error ena */
136#define EHCI_INTR_FLRE 0x00000008 /* frame list rollover ena */ 136#define EHCI_INTR_FLRE 0x00000008 /* frame list rollover ena */
137#define EHCI_INTR_PCIE 0x00000004 /* port change ena */ 137#define EHCI_INTR_PCIE 0x00000004 /* port change ena */
138#define EHCI_INTR_UEIE 0x00000002 /* USB error intr ena */ 138#define EHCI_INTR_UEIE 0x00000002 /* USB error intr ena */
139#define EHCI_INTR_UIE 0x00000001 /* USB intr ena */ 139#define EHCI_INTR_UIE 0x00000001 /* USB intr ena */
140 140
141#define EHCI_FRINDEX 0x0c /* RW Frame Index register */ 141#define EHCI_FRINDEX 0x0c /* RW Frame Index register */
142 142
143#define EHCI_CTRLDSSEGMENT 0x10 /* RW Control Data Structure Segment */ 143#define EHCI_CTRLDSSEGMENT 0x10 /* RW Control Data Structure Segment */
144 144
145#define EHCI_PERIODICLISTBASE 0x14 /* RW Periodic List Base */ 145#define EHCI_PERIODICLISTBASE 0x14 /* RW Periodic List Base */
146#define EHCI_ASYNCLISTADDR 0x18 /* RW Async List Base */ 146#define EHCI_ASYNCLISTADDR 0x18 /* RW Async List Base */
147 147
148#define EHCI_CONFIGFLAG 0x40 /* RW Configure Flag register */ 148#define EHCI_CONFIGFLAG 0x40 /* RW Configure Flag register */
149#define EHCI_CONF_CF 0x00000001 /* RW configure flag */ 149#define EHCI_CONF_CF 0x00000001 /* RW configure flag */
150 150
151#define EHCI_PORTSC(n) (0x40+4*(n)) /* RO, RW, RWC Port Status reg */ 151#define EHCI_PORTSC(n) (0x40+4*(n)) /* RO, RW, RWC Port Status reg */
152#define EHCI_PS_PSPD 0x0C000000 /* RO port speed (ETTF) */ 152#define EHCI_PS_PSPD 0x0C000000 /* RO port speed (ETTF) */
153#define EHCI_PS_PSPD_FS 0x00000000 /* Full speed (ETTF) */ 153#define EHCI_PS_PSPD_FS 0x00000000 /* Full speed (ETTF) */
154#define EHCI_PS_PSPD_LS 0x04000000 /* Low speed (ETTF) */ 154#define EHCI_PS_PSPD_LS 0x04000000 /* Low speed (ETTF) */
155#define EHCI_PS_PSPD_HS 0x08000000 /* High speed (ETTF) */ 155#define EHCI_PS_PSPD_HS 0x08000000 /* High speed (ETTF) */
156#define EHCI_PS_WKOC_E 0x00400000 /* RW wake on over current ena */ 156#define EHCI_PS_WKOC_E 0x00400000 /* RW wake on over current ena */
157#define EHCI_PS_WKDSCNNT_E 0x00200000 /* RW wake on disconnect ena */ 157#define EHCI_PS_WKDSCNNT_E 0x00200000 /* RW wake on disconnect ena */
158#define EHCI_PS_WKCNNT_E 0x00100000 /* RW wake on connect ena */ 158#define EHCI_PS_WKCNNT_E 0x00100000 /* RW wake on connect ena */
159#define EHCI_PS_PTC 0x000f0000 /* RW port test control */ 159#define EHCI_PS_PTC 0x000f0000 /* RW port test control */
160#define EHCI_PS_PIC 0x0000c000 /* RW port indicator control */ 160#define EHCI_PS_PIC 0x0000c000 /* RW port indicator control */
161#define EHCI_PS_PO 0x00002000 /* RW port owner */ 161#define EHCI_PS_PO 0x00002000 /* RW port owner */
162#define EHCI_PS_PP 0x00001000 /* RW,RO port power */ 162#define EHCI_PS_PP 0x00001000 /* RW,RO port power */
163#define EHCI_PS_LS 0x00000c00 /* RO line status */ 163#define EHCI_PS_LS 0x00000c00 /* RO line status */
164#define EHCI_PS_IS_LOWSPEED(x) (((x) & EHCI_PS_LS) == 0x00000400) 164#define EHCI_PS_IS_LOWSPEED(x) (((x) & EHCI_PS_LS) == 0x00000400)
165#define EHCI_PS_PR 0x00000100 /* RW port reset */ 165#define EHCI_PS_PR 0x00000100 /* RW port reset */
166#define EHCI_PS_SUSP 0x00000080 /* RW suspend */ 166#define EHCI_PS_SUSP 0x00000080 /* RW suspend */
167#define EHCI_PS_FPR 0x00000040 /* RW force port resume */ 167#define EHCI_PS_FPR 0x00000040 /* RW force port resume */
168#define EHCI_PS_OCC 0x00000020 /* RWC over current change */ 168#define EHCI_PS_OCC 0x00000020 /* RWC over current change */
169#define EHCI_PS_OCA 0x00000010 /* RO over current active */ 169#define EHCI_PS_OCA 0x00000010 /* RO over current active */
170#define EHCI_PS_PEC 0x00000008 /* RWC port enable change */ 170#define EHCI_PS_PEC 0x00000008 /* RWC port enable change */
171#define EHCI_PS_PE 0x00000004 /* RW port enable */ 171#define EHCI_PS_PE 0x00000004 /* RW port enable */
172#define EHCI_PS_CSC 0x00000002 /* RWC connect status change */ 172#define EHCI_PS_CSC 0x00000002 /* RWC connect status change */
173#define EHCI_PS_CS 0x00000001 /* RO connect status */ 173#define EHCI_PS_CS 0x00000001 /* RO connect status */
174#define EHCI_PS_CLEAR (EHCI_PS_OCC|EHCI_PS_PEC|EHCI_PS_CSC) 174#define EHCI_PS_CLEAR (EHCI_PS_OCC|EHCI_PS_PEC|EHCI_PS_CSC)
175 175
176#define EHCI_PORT_RESET_COMPLETE 2 /* ms */ 176#define EHCI_PORT_RESET_COMPLETE 2 /* ms */
177 177
178#define EHCI_USBMODE 0xa8 /* USB Device mode */ 178#define EHCI_USBMODE 0xa8 /* USB Device mode */
179#define EHCI_USBMODE_SDIS __BIT(4) /* Stream disable mode 1=act */ 179#define EHCI_USBMODE_SDIS __BIT(4) /* Stream disable mode 1=act */
180#define EHCI_USBMODE_SLOM __BIT(3) /* setup lockouts on */ 180#define EHCI_USBMODE_SLOM __BIT(3) /* setup lockouts on */
181#define EHCI_USBMODE_ES __BIT(2) /* Endian Select ES=1 */ 181#define EHCI_USBMODE_ES __BIT(2) /* Endian Select ES=1 */
182#define EHCI_USBMODE_CM __BITS(0,1) /* Controller Mode */ 182#define EHCI_USBMODE_CM __BITS(0,1) /* Controller Mode */
183#define EHCI_USBMODE_CM_IDLE 0x00 /* Idle (combo host/device) */ 183#define EHCI_USBMODE_CM_IDLE 0x00 /* Idle (combo host/device) */
184#define EHCI_USBMODE_CM_DEV 0x02 /* Device Controller */ 184#define EHCI_USBMODE_CM_DEV 0x02 /* Device Controller */
185#define EHCI_USBMODE_CM_HOST 0x03 /* Host Controller */ 185#define EHCI_USBMODE_CM_HOST 0x03 /* Host Controller */
186 186
187#define EHCI_FLALIGN_ALIGN 0x1000 187#define EHCI_FLALIGN_ALIGN 0x1000
188#define EHCI_MAX_PORTS 16 /* only 4 bits available in EHCI_HCS_N_PORTS */ 188#define EHCI_MAX_PORTS 16 /* only 4 bits available in EHCI_HCS_N_PORTS */
189 189
190/* No data structure may cross a page boundary. */ 190/* No data structure may cross a page boundary. */
191#define EHCI_PAGE_SHIFT 12 191#define EHCI_PAGE_SHIFT 12
192#define EHCI_PAGE_SIZE (1 << EHCI_PAGE_SHIFT) 192#define EHCI_PAGE_SIZE (1 << EHCI_PAGE_SHIFT)
193#define EHCI_PAGE_MASK (EHCI_PAGE_SIZE - 1) 193#define EHCI_PAGE_MASK (EHCI_PAGE_SIZE - 1)
194#define EHCI_PAGE(x) ((x) & ~EHCI_PAGE_MASK) 194#define EHCI_PAGE(x) ((x) & ~EHCI_PAGE_MASK)
195#define EHCI_PAGE_OFFSET(x) ((x) & EHCI_PAGE_MASK) 195#define EHCI_PAGE_OFFSET(x) ((x) & EHCI_PAGE_MASK)
196#define EHCI_NPAGES(x) (((x) + EHCI_PAGE_MASK) >> EHCI_PAGE_SHIFT) 196#define EHCI_NPAGES(x) (((x) + EHCI_PAGE_MASK) >> EHCI_PAGE_SHIFT)
197 197
198typedef uint32_t ehci_link_t; 198typedef uint32_t ehci_link_t;
199#define EHCI_LINK_TERMINATE 0x00000001 199#define EHCI_LINK_TERMINATE __BIT(0)
200#define EHCI_LINK_TYPE(x) ((x) & 0x00000006) 200#define EHCI_LINK_TYPE(x) ((x) & 0x00000006)
201#define EHCI_LINK_ITD 0x0 201#define EHCI_LINK_ITD 0x0
202#define EHCI_LINK_QH 0x2 202#define EHCI_LINK_QH 0x2
203#define EHCI_LINK_SITD 0x4 203#define EHCI_LINK_SITD 0x4
204#define EHCI_LINK_FSTN 0x6 204#define EHCI_LINK_FSTN 0x6
205#define EHCI_LINK_ADDR(x) ((x) &~ 0x1f) 205#define EHCI_LINK_ADDR(x) ((x) &~ 0x1f)
206 206
207typedef uint32_t ehci_physaddr_t; 207typedef uint32_t ehci_physaddr_t;
208 208
209typedef uint32_t ehci_isoc_trans_t; 209typedef uint32_t ehci_isoc_trans_t;
210typedef uint32_t ehci_isoc_bufr_ptr_t; 210typedef uint32_t ehci_isoc_bufr_ptr_t;
211 211
212/* Isochronous Transfer Descriptor */ 212/* Isochronous Transfer Descriptor */
213#define EHCI_ITD_NUFRAMES USB_UFRAMES_PER_FRAME 213#define EHCI_ITD_NUFRAMES USB_UFRAMES_PER_FRAME
214#define EHCI_ITD_NBUFFERS 7 214#define EHCI_ITD_NBUFFERS 7
215typedef struct { 215typedef struct {
216 volatile ehci_link_t itd_next; 216 volatile ehci_link_t itd_next;
217 volatile ehci_isoc_trans_t itd_ctl[EHCI_ITD_NUFRAMES]; 217 volatile ehci_isoc_trans_t itd_ctl[EHCI_ITD_NUFRAMES];
218#define EHCI_ITD_GET_STATUS(x) (((x) >> 28) & 0xf) 218#define EHCI_ITD_STATUS_MASK __BITS(31,28)
219#define EHCI_ITD_SET_STATUS(x) (((x) & 0xf) << 28) 219#define EHCI_ITD_GET_STATUS(x) __SHIFTOUT((x), EHCI_ITD_STATUS_MASK)
220#define EHCI_ITD_ACTIVE 0x80000000 220#define EHCI_ITD_SET_STATUS(x) __SHIFTIN((x), EHCI_ITD_STATUS_MASK)
221#define EHCI_ITD_BUF_ERR 0x40000000 221#define EHCI_ITD_ACTIVE __BIT(31)
222#define EHCI_ITD_BABBLE 0x20000000 222#define EHCI_ITD_BUF_ERR __BIT(30)
223#define EHCI_ITD_ERROR 0x10000000 223#define EHCI_ITD_BABBLE __BIT(29)
224#define EHCI_ITD_GET_LEN(x) (((x) >> 16) & 0xfff) 224#define EHCI_ITD_ERROR __BIT(28)
225#define EHCI_ITD_SET_LEN(x) (((x) & 0xfff) << 16) 225#define EHCI_ITD_LEN_MASK __BITS(27,16)
226#define EHCI_ITD_IOC 0x8000 226#define EHCI_ITD_GET_LEN(x) __SHIFTOUT((x), EHCI_ITD_LEN_MASK)
227#define EHCI_ITD_GET_IOC(x) (((x) >> 15) & 1) 227#define EHCI_ITD_SET_LEN(x) __SHIFTIN((x), EHCI_ITD_LEN_MASK)
228#define EHCI_ITD_SET_IOC(x) (((x) << 15) & EHCI_ITD_IOC) 228#define EHCI_ITD_IOC __BIT(15)
229#define EHCI_ITD_GET_PG(x) (((x) >> 12) & 0x7) 229#define EHCI_ITD_GET_IOC(x) __SHIFTOUT((x), EHCI_ITD_IOC)
230#define EHCI_ITD_SET_PG(x) (((x) & 0x7) << 12) 230#define EHCI_ITD_SET_IOC(x) __SHIFTIN((x), EHCI_ITD_IOC)
231#define EHCI_ITD_GET_OFFS(x) (((x) >> 0) & 0xfff) 231#define EHCI_ITD_PG_MASK __BITS(14,12)
232#define EHCI_ITD_SET_OFFS(x) (((x) & 0xfff) << 0) 232#define EHCI_ITD_GET_PG(x) __SHIFTOUT((x), EHCI_ITD_PG_MASK)
 233#define EHCI_ITD_SET_PG(x) __SHIFTIN((x), EHCI_ITD_PG_MASK)
 234#define EHCI_ITD_OFFSET_MASK __BITS(11,0)
 235#define EHCI_ITD_GET_OFFS(x) __SHIFTOUT((x), EHCI_ITD_OFFSET_MASK)
 236#define EHCI_ITD_SET_OFFS(x) __SHIFTIN((x), EHCI_ITD_OFFSET_MASK)
233 volatile ehci_isoc_bufr_ptr_t itd_bufr[EHCI_ITD_NBUFFERS]; 237 volatile ehci_isoc_bufr_ptr_t itd_bufr[EHCI_ITD_NBUFFERS];
234#define EHCI_ITD_GET_BPTR(x) ((x) & 0xfffff000) 238#define EHCI_ITD_BPTR_MASK __BITS(31,12)
235#define EHCI_ITD_SET_BPTR(x) ((x) & 0xfffff000) 239#define EHCI_ITD_GET_BPTR(x) __SHIFTOUT((x), EHCI_ITD_BPTR_MASK)
236#define EHCI_ITD_GET_EP(x) (((x) >> 8) & 0xf) 240#define EHCI_ITD_SET_BPTR(x) __SHIFTIN((x), EHCI_ITD_BPTR_MASK)
237#define EHCI_ITD_SET_EP(x) (((x) & 0xf) << 8) 241#define EHCI_ITD_EP_MASK __BITS(11,8)
238#define EHCI_ITD_GET_DADDR(x) ((x) & 0x7f) 242#define EHCI_ITD_GET_EP(x) __SHIFTOUT((x), EHCI_ITD_EP_MASK)
239#define EHCI_ITD_SET_DADDR(x) ((x) & 0x7f) 243#define EHCI_ITD_SET_EP(x) __SHIFTIN((x), EHCI_ITD_EP_MASK)
240#define EHCI_ITD_GET_DIR(x) (((x) >> 11) & 1) 244#define EHCI_ITD_DADDR_MASK __BITS(6,0)
241#define EHCI_ITD_SET_DIR(x) (((x) & 1) << 11) 245#define EHCI_ITD_GET_DADDR(x) __SHIFTOUT((x), EHCI_ITD_DADDR_MASK)
242#define EHCI_ITD_GET_MAXPKT(x) ((x) & 0x7ff) 246#define EHCI_ITD_SET_DADDR(x) __SHIFTIN((x), EHCI_ITD_DADDR_MASK)
243#define EHCI_ITD_SET_MAXPKT(x) ((x) & 0x7ff) 247#define EHCI_ITD_DIR_MASK __BIT(11)
244#define EHCI_ITD_GET_MULTI(x) ((x) & 0x3) 248#define EHCI_ITD_GET_DIR(x) __SHIFTOUT((x), EHCI_ITD_DIR_MASK)
245#define EHCI_ITD_SET_MULTI(x) ((x) & 0x3) 249#define EHCI_ITD_SET_DIR(x) __SHIFTIN((x), EHCI_ITD_DIR_MASK)
 250#define EHCI_ITD_MAXPKT_MASK __BITS(10,0)
 251#define EHCI_ITD_GET_MAXPKT(x) __SHIFTOUT((x), EHCI_ITD_MAXPKT_MASK)
 252#define EHCI_ITD_SET_MAXPKT(x) __SHIFTIN((x), EHCI_ITD_MAXPKT_MASK)
 253#define EHCI_ITD_MULTI_MASK __BITS(1,0)
 254#define EHCI_ITD_GET_MULTI(x) __SHIFTOUT((x), EHCI_ITD_MULTI_MASK)
 255#define EHCI_ITD_SET_MULTI(x) __SHIFTIN((x), EHCI_ITD_MULTI_MASK)
246 volatile ehci_isoc_bufr_ptr_t itd_bufr_hi[EHCI_ITD_NBUFFERS]; 256 volatile ehci_isoc_bufr_ptr_t itd_bufr_hi[EHCI_ITD_NBUFFERS];
247} ehci_itd_t; 257} ehci_itd_t;
248#define EHCI_ITD_ALIGN 32 258#define EHCI_ITD_ALIGN 32
249 259
250/* Split Transaction Isochronous Transfer Descriptor */ 260/* Split Transaction Isochronous Transfer Descriptor */
251typedef struct { 261typedef struct {
252 volatile ehci_link_t sitd_next; 262 volatile ehci_link_t sitd_next;
253 volatile uint32_t sitd_endp; 263 volatile uint32_t sitd_endp;
254#define EHCI_SITD_SET_DIR(x) (((x) & 0x01) << 31) 264#define EHCI_SITD_DIR_MASK __BIT(31)
255#define EHCI_SITD_SET_PORT(x) (((x) & 0x7f) << 24) 265#define EHCI_SITD_PORT_MASK __BITS(30,24)
256#define EHCI_SITD_SET_HUBA(x) (((x) & 0x7f) << 16) 266#define EHCI_SITD_HUBA_MASK __BITS(22,16)
257#define EHCI_SITD_SET_ENDPT(x) (((x) & 0x0f) << 8) 267#define EHCI_SITD_ENDPT_MASK __BITS(11,8)
258#define EHCI_SITD_SET_DADDR(x) ((x) & 0x7f) 268#define EHCI_SITD_DADDR_MASK __BITS(6,0)
259 269#define EHCI_SITD_SET_DIR(x) __SHIFTIN((x), EHCI_SITD_DIR_MASK)
 270#define EHCI_SITD_SET_PORT(x) __SHIFTIN((x), EHCI_SITD_PORT_MASK)
 271#define EHCI_SITD_SET_HUBA(x) __SHIFTIN((x), EHCI_SITD_HUBA_MASK)
 272#define EHCI_SITD_SET_ENDPT(x) __SHIFTIN((x), EHCI_SITD_ENDPT_MASK)
 273#define EHCI_SITD_SET_DADDR(x) __SHIFTIN((x), EHCI_SITD_DADDR_MASK)
260 volatile uint32_t sitd_sched; 274 volatile uint32_t sitd_sched;
261#define EHCI_SITD_SET_SMASK(x) ((x) & 0xff) 275#define EHCI_SITD_SMASK_MASK __BITS(7,0)
262#define EHCI_SITD_SET_CMASK(x) (((x) & 0xff) << 8) 276#define EHCI_SITD_CMASK_MASK __BITS(15,8)
263 277#define EHCI_SITD_SET_SMASK(x) __SHIFTIN((x), EHCI_SITD_SMASK_MASK)
 278#define EHCI_SITD_SET_CMASK(x) __SHIFTIN((x), EHCI_SITD_CMASK_MASK)
264 volatile uint32_t sitd_trans; 279 volatile uint32_t sitd_trans;
265#define EHCI_SITD_IOC 0x80000000 280#define EHCI_SITD_IOC __BIT(31)
266#define EHCI_SITD_P 0x40000000 281#define EHCI_SITD_P __BIT(30)
267#define EHCI_SITD_GET_LEN(x) (((x) & 0x03ff0000) >> 16) 282#define EHCI_SITD_LENGTH_MASK __BITS(25,16)
268#define EHCI_SITD_SET_LEN(x) (((x) & 0x3ff) << 16) 283#define EHCI_SITD_GET_LEN(x) __SHIFTOUT((x), EHCI_SITD_LENGTH_MASK)
 284#define EHCI_SITD_SET_LEN(x) __SHIFTIN((x), EHCI_SITD_LENGTH_MASK)
269#define EHCI_SITD_ACTIVE 0x00000080 285#define EHCI_SITD_ACTIVE 0x00000080
270#define EHCI_SITD_ERR 0x00000040 286#define EHCI_SITD_ERR 0x00000040
271#define EHCI_SITD_BUFERR 0x00000020 287#define EHCI_SITD_BUFERR 0x00000020
272#define EHCI_SITD_BABBLE 0x00000010 288#define EHCI_SITD_BABBLE 0x00000010
273#define EHCI_SITD_XACTERR 0x00000008 289#define EHCI_SITD_XACTERR 0x00000008
274#define EHCI_SITD_MISS 0x00000004 290#define EHCI_SITD_MISS 0x00000004
275#define EHCI_SITD_SPLITXSTATE 0x00000002 291#define EHCI_SITD_SPLITXSTATE 0x00000002
276 
277 volatile uint32_t sitd_buffer[2]; 292 volatile uint32_t sitd_buffer[2];
278#define EHCI_SITD_SET_BPTR(x) ((x) & 0xfffff000) 293#define EHCI_SITD_SET_BPTR(x) ((x) & 0xfffff000)
279#define EHCI_SITD_SET_OFFS(x) ((x) & 0xfff) 294#define EHCI_SITD_SET_OFFS(x) ((x) & 0xfff)
280 295
281 volatile uint32_t sitd_back; 296 volatile uint32_t sitd_back;
282} ehci_sitd_t; 297} ehci_sitd_t;
283#define EHCI_SITD_ALIGN 32 298#define EHCI_SITD_ALIGN 32
284 299
285/* Queue Element Transfer Descriptor */ 300/* Queue Element Transfer Descriptor */
286#define EHCI_QTD_NBUFFERS 5 301#define EHCI_QTD_NBUFFERS 5
287#define EHCI_QTD_MAXTRANSFER (EHCI_QTD_NBUFFERS * EHCI_PAGE_SIZE) 302#define EHCI_QTD_MAXTRANSFER (EHCI_QTD_NBUFFERS * EHCI_PAGE_SIZE)
288typedef struct { 303typedef struct {
289 volatile ehci_link_t qtd_next; 304 volatile ehci_link_t qtd_next;
290 volatile ehci_link_t qtd_altnext; 305 volatile ehci_link_t qtd_altnext;
291 volatile uint32_t qtd_status; 306 volatile uint32_t qtd_status;
292#define EHCI_QTD_GET_STATUS(x) (((x) >> 0) & 0xff) 307#define EHCI_QTD_STATUS_MASK __BITS(7,0)
293#define EHCI_QTD_SET_STATUS(x) ((x) << 0) 308#define EHCI_QTD_GET_STATUS(x) __SHIFTOUT((x), EHCI_QTD_STATUS_MASK)
 309#define EHCI_QTD_SET_STATUS(x) __SHIFTIN((x), EHCI_QTD_STATUS_MASK)
294#define EHCI_QTD_ACTIVE 0x80 310#define EHCI_QTD_ACTIVE 0x80
295#define EHCI_QTD_HALTED 0x40 311#define EHCI_QTD_HALTED 0x40
296#define EHCI_QTD_BUFERR 0x20 312#define EHCI_QTD_BUFERR 0x20
297#define EHCI_QTD_BABBLE 0x10 313#define EHCI_QTD_BABBLE 0x10
298#define EHCI_QTD_XACTERR 0x08 314#define EHCI_QTD_XACTERR 0x08
299#define EHCI_QTD_MISSEDMICRO 0x04 315#define EHCI_QTD_MISSEDMICRO 0x04
300#define EHCI_QTD_SPLITXSTATE 0x02 316#define EHCI_QTD_SPLITXSTATE 0x02
301#define EHCI_QTD_PINGSTATE 0x01 317#define EHCI_QTD_PINGSTATE 0x01
302#define EHCI_QTD_STATERRS 0x3c 318#define EHCI_QTD_STATERRS 0x3c
303#define EHCI_QTD_GET_PID(x) (((x) >> 8) & 0x3) 319#define EHCI_QTD_PID_MASK __BITS(9,8)
304#define EHCI_QTD_SET_PID(x) ((x) << 8) 320#define EHCI_QTD_GET_PID(x) __SHIFTOUT((x), EHCI_QTD_PID_MASK)
 321#define EHCI_QTD_SET_PID(x) __SHIFTIN((x), EHCI_QTD_PID_MASK)
305#define EHCI_QTD_PID_OUT 0x0 322#define EHCI_QTD_PID_OUT 0x0
306#define EHCI_QTD_PID_IN 0x1 323#define EHCI_QTD_PID_IN 0x1
307#define EHCI_QTD_PID_SETUP 0x2 324#define EHCI_QTD_PID_SETUP 0x2
308#define EHCI_QTD_GET_CERR(x) (((x) >> 10) & 0x3) 325#define EHCI_QTD_CERR_MASK __BITS(11,10)
309#define EHCI_QTD_SET_CERR(x) ((x) << 10) 326#define EHCI_QTD_GET_CERR(x) __SHIFTOUT((x), EHCI_QTD_CERR_MASK)
310#define EHCI_QTD_GET_C_PAGE(x) (((x) >> 12) & 0x7) 327#define EHCI_QTD_SET_CERR(x) __SHIFTIN((x), EHCI_QTD_CERR_MASK)
311#define EHCI_QTD_SET_C_PAGE(x) ((x) << 12) 328#define EHCI_QTD_C_PAGE_MASK __BITS(14,12)
312#define EHCI_QTD_GET_IOC(x) (((x) >> 15) & 0x1) 329#define EHCI_QTD_GET_C_PAGE(x) __SHIFTOUT((x), EHCI_QTD_C_PAGE_MASK)
313#define EHCI_QTD_IOC 0x00008000 330#define EHCI_QTD_SET_C_PAGE(x) __SHIFTIN((x), EHCI_QTD_C_PAGE_MASK)
314#define EHCI_QTD_GET_BYTES(x) (((x) >> 16) & 0x7fff) 331#define EHCI_QTD_IOC __BIT(15)
315#define EHCI_QTD_SET_BYTES(x) ((x) << 16) 332#define EHCI_QTD_GET_IOC(x) __SHIFTOUT((x), EHCI_QTD_IOC)
316#define EHCI_QTD_GET_TOGGLE(x) (((x) >> 31) & 0x1) 333#define EHCI_QTD_BYTES_MASK __BITS(30,16)
317#define EHCI_QTD_SET_TOGGLE(x) ((x) << 31) 334#define EHCI_QTD_GET_BYTES(x) __SHIFTOUT((x), EHCI_QTD_BYTES_MASK)
318#define EHCI_QTD_TOGGLE_MASK 0x80000000 335#define EHCI_QTD_SET_BYTES(x) __SHIFTIN((x), EHCI_QTD_BYTES_MASK)
 336#define EHCI_QTD_TOGGLE_MASK __BIT(31)
 337#define EHCI_QTD_GET_TOGGLE(x) __SHIFTOUT((x), EHCI_QTD_TOGGLE_MASK)
 338#define EHCI_QTD_SET_TOGGLE(x) __SHIFTIN((x), EHCI_QTD_TOGGLE_MASK)
319 volatile ehci_physaddr_t qtd_buffer[EHCI_QTD_NBUFFERS]; 339 volatile ehci_physaddr_t qtd_buffer[EHCI_QTD_NBUFFERS];
320 volatile ehci_physaddr_t qtd_buffer_hi[EHCI_QTD_NBUFFERS]; 340 volatile ehci_physaddr_t qtd_buffer_hi[EHCI_QTD_NBUFFERS];
321} ehci_qtd_t; 341} ehci_qtd_t;
322#define EHCI_QTD_ALIGN 32 342#define EHCI_QTD_ALIGN 32
323 343
324/* Queue Head */ 344/* Queue Head */
325typedef struct { 345typedef struct {
326 volatile ehci_link_t qh_link; 346 volatile ehci_link_t qh_link;
327 volatile uint32_t qh_endp; 347 volatile uint32_t qh_endp;
328#define EHCI_QH_GET_ADDR(x) (((x) >> 0) & 0x7f) /* endpoint addr */ 348#define EHCI_QH_ADDR_MASK __BITS(6,0) /* endpoint addr */
329#define EHCI_QH_SET_ADDR(x) (x) 349#define EHCI_QH_GET_ADDR(x) __SHIFTOUT((x), EHCI_QH_ADDR_MASK)
330#define EHCI_QH_ADDRMASK 0x0000007f 350#define EHCI_QH_SET_ADDR(x) __SHIFTIN((x), EHCI_QH_ADDR_MASK)
331#define EHCI_QH_GET_INACT(x) (((x) >> 7) & 0x01) /* inactivate on next */ 351#define EHCI_QH_INACT __BIT(7) /* inactivate on next */
332#define EHCI_QH_INACT 0x00000080 352#define EHCI_QH_GET_INACT(x) __SHIFTOUT((x), EHCI_QH_INACT)
333#define EHCI_QH_GET_ENDPT(x) (((x) >> 8) & 0x0f) /* endpoint no */ 353#define EHCI_QH_ENDPT_MASK __BITS(11,8) /* endpoint no */
334#define EHCI_QH_SET_ENDPT(x) ((x) << 8) 354#define EHCI_QH_GET_ENDPT(x) __SHIFTOUT((x), EHCI_QH_ENDPT_MASK)
335#define EHCI_QH_GET_EPS(x) (((x) >> 12) & 0x03) /* endpoint speed */ 355#define EHCI_QH_SET_ENDPT(x) __SHIFTIN((x), EHCI_QH_ENDPT_MASK)
336#define EHCI_QH_SET_EPS(x) ((x) << 12) 356#define EHCI_QH_EPS_MASK __BITS(13,12) /* endpoint speed */
 357#define EHCI_QH_GET_EPS(x) __SHIFTOUT((x), EHCI_QH_EPS_MASK)
 358#define EHCI_QH_SET_EPS(x) __SHIFTIN((x), EHCI_QH_EPS_MASK)
337#define EHCI_QH_SPEED_FULL 0x0 359#define EHCI_QH_SPEED_FULL 0x0
338#define EHCI_QH_SPEED_LOW 0x1 360#define EHCI_QH_SPEED_LOW 0x1
339#define EHCI_QH_SPEED_HIGH 0x2 361#define EHCI_QH_SPEED_HIGH 0x2
340#define EHCI_QH_GET_DTC(x) (((x) >> 14) & 0x01) /* data toggle control */ 362#define EHCI_QH_DTC __BIT(14) /* data toggle control */
341#define EHCI_QH_DTC 0x00004000 363#define EHCI_QH_GET_DTC(x) __SHIFTOUT((x), EHCI_QH_DTC)
342#define EHCI_QH_GET_HRECL(x) (((x) >> 15) & 0x01) /* head of reclamation */ 364#define EHCI_QH_HRECL __BIT(15) /* head of reclamation */
343#define EHCI_QH_HRECL 0x00008000 365#define EHCI_QH_GET_HRECL(x) __SHIFTOUT((x), EHCI_QH_HRECL)
344#define EHCI_QH_GET_MPL(x) (((x) >> 16) & 0x7ff) /* max packet len */ 366#define EHCI_QH_MPL_MASK __BITS(26,16) /* max packet len */
345#define EHCI_QH_SET_MPL(x) ((x) << 16) 367#define EHCI_QH_GET_MPL(x) __SHIFTOUT((x), EHCI_QH_MPL_MASK)
346#define EHCI_QH_MPLMASK 0x07ff0000 368#define EHCI_QH_SET_MPL(x) __SHIFTIN((x), EHCI_QH_MPL_MASK)
347#define EHCI_QH_GET_CTL(x) (((x) >> 27) & 0x01) /* control endpoint */ 369#define EHCI_QH_CTL __BIT(27) /* control endpoint */
348#define EHCI_QH_CTL 0x08000000 370#define EHCI_QH_GET_CTL(x) __SHIFTOUT((x), EHCI_QH_CTL)
349#define EHCI_QH_GET_NRL(x) (((x) >> 28) & 0x0f) /* NAK reload */ 371#define EHCI_QH_NRL_MASK __BITS(31,28) /* NAK reload */
350#define EHCI_QH_SET_NRL(x) ((x) << 28) 372#define EHCI_QH_GET_NRL(x) __SHIFTOUT((x), EHCI_QH_NRL_MASK)
 373#define EHCI_QH_SET_NRL(x) __SHIFTIN((x), EHCI_QH_NRL_MASK)
351 volatile uint32_t qh_endphub; 374 volatile uint32_t qh_endphub;
352#define EHCI_QH_GET_SMASK(x) (((x) >> 0) & 0xff) /* intr sched mask */ 375#define EHCI_QH_SMASK_MASK __BITS(7,0) /* intr sched mask */
353#define EHCI_QH_SET_SMASK(x) ((x) << 0) 376#define EHCI_QH_GET_SMASK(x) __SHIFTOUT((x), EHCI_QH_SMASK_MASK)
354#define EHCI_QH_GET_CMASK(x) (((x) >> 8) & 0xff) /* split completion mask */ 377#define EHCI_QH_SET_SMASK(x) __SHIFTIN((x), EHCI_QH_SMASK_MASK)
355#define EHCI_QH_SET_CMASK(x) ((x) << 8) 378#define EHCI_QH_CMASK_MASK __BITS(15,8) /* split completion mask */
356#define EHCI_QH_GET_HUBA(x) (((x) >> 16) & 0x7f) /* hub address */ 379#define EHCI_QH_GET_CMASK(x) __SHIFTOUT((x), EHCI_QH_CMASK_MASK)
357#define EHCI_QH_SET_HUBA(x) ((x) << 16) 380#define EHCI_QH_SET_CMASK(x) __SHIFTIN((x), EHCI_QH_CMASK_MASK)
358#define EHCI_QH_GET_PORT(x) (((x) >> 23) & 0x7f) /* hub port */ 381#define EHCI_QH_HUBA_MASK __BITS(22,16) /* hub address */
359#define EHCI_QH_SET_PORT(x) ((x) << 23) 382#define EHCI_QH_GET_HUBA(x) __SHIFTOUT((x), EHCI_QH_HUBA_MASK)
360#define EHCI_QH_GET_MULT(x) (((x) >> 30) & 0x03) /* pipe multiplier */ 383#define EHCI_QH_SET_HUBA(x) __SHIFTIN((x), EHCI_QH_HUBA_MASK)
361#define EHCI_QH_SET_MULT(x) ((x) << 30) 384#define EHCI_QH_PORT_MASK __BITS(29,23) /* hub port */
 385#define EHCI_QH_GET_PORT(x) __SHIFTOUT((x), EHCI_QH_PORT_MASK)
 386#define EHCI_QH_SET_PORT(x) __SHIFTIN((x), EHCI_QH_PORT_MASK)
 387#define EHCI_QH_MULTI_MASK __BITS(31,30) /* pipe multiplier */
 388#define EHCI_QH_GET_MULT(x) __SHIFTOUT((x), EHCI_QH_MULTI_MASK)
 389#define EHCI_QH_SET_MULT(x) __SHIFTIN((x), EHCI_QH_MULTI_MASK)
362 volatile ehci_link_t qh_curqtd; 390 volatile ehci_link_t qh_curqtd;
363 ehci_qtd_t qh_qtd; 391 ehci_qtd_t qh_qtd;
364} ehci_qh_t; 392} ehci_qh_t;
365#define EHCI_QH_ALIGN 32 393#define EHCI_QH_ALIGN 32
366 394
367/* Periodic Frame Span Traversal Node */ 395/* Periodic Frame Span Traversal Node */
368typedef struct { 396typedef struct {
369 volatile ehci_link_t fstn_link; 397 volatile ehci_link_t fstn_link;
370 volatile ehci_link_t fstn_back; 398 volatile ehci_link_t fstn_back;
371} ehci_fstn_t; 399} ehci_fstn_t;
372#define EHCI_FSTN_ALIGN 32 400#define EHCI_FSTN_ALIGN 32
373 401
374/* Debug Port */ 402/* Debug Port */
375#define PCI_CAP_DEBUGPORT_OFFSET __BITS(28,16) 403#define PCI_CAP_DEBUGPORT_OFFSET __BITS(28,16)
376#define PCI_CAP_DEBUGPORT_BAR __BITS(31,29) 404#define PCI_CAP_DEBUGPORT_BAR __BITS(31,29)
377/* Debug Port Registers, offset into DEBUGPORT_BAR at DEBUGPORT_OFFSET */ 405/* Debug Port Registers, offset into DEBUGPORT_BAR at DEBUGPORT_OFFSET */
378#define EHCI_DEBUG_SC 0x00 406#define EHCI_DEBUG_SC 0x00
379/* Status/Control Register */ 407/* Status/Control Register */
380#define EHCI_DSC_DATA_LENGTH __BITS(3,0) 408#define EHCI_DSC_DATA_LENGTH __BITS(3,0)
381#define EHCI_DSC_WRITE __BIT(4) 409#define EHCI_DSC_WRITE __BIT(4)
382#define EHCI_DSC_GO __BIT(5) 410#define EHCI_DSC_GO __BIT(5)
383#define EHCI_DSC_ERROR __BIT(6) 411#define EHCI_DSC_ERROR __BIT(6)
384#define EHCI_DSC_EXCEPTION __BITS(9,7) 412#define EHCI_DSC_EXCEPTION __BITS(9,7)
385#define EHCI_DSC_EXCEPTION_NONE 0 413#define EHCI_DSC_EXCEPTION_NONE 0
386#define EHCI_DSC_EXCEPTION_XACT 1 414#define EHCI_DSC_EXCEPTION_XACT 1
387#define EHCI_DSC_EXCEPTION_HW 2 415#define EHCI_DSC_EXCEPTION_HW 2
388#define EHCI_DSC_IN_USE __BIT(10) 416#define EHCI_DSC_IN_USE __BIT(10)
389#define EHCI_DSC_DONE __BIT(16) 417#define EHCI_DSC_DONE __BIT(16)
390#define EHCI_DSC_ENABLED __BIT(28) 418#define EHCI_DSC_ENABLED __BIT(28)
391#define EHCI_DSC_OWNER __BIT(30) 419#define EHCI_DSC_OWNER __BIT(30)
392#define EHCI_DEBUG_UPR 0x04 420#define EHCI_DEBUG_UPR 0x04
393/* USB PIDs Register */ 421/* USB PIDs Register */
394#define EHCI_DPR_TOKEN __BITS(7,0) 422#define EHCI_DPR_TOKEN __BITS(7,0)
395#define EHCI_DPR_SEND __BITS(15,8) 423#define EHCI_DPR_SEND __BITS(15,8)
396#define EHCI_DPR_RECEIVED __BITS(23,16) 424#define EHCI_DPR_RECEIVED __BITS(23,16)
397/* Data Registers */ 425/* Data Registers */
398#define EHCI_DEBUG_DATA0123 0x08 426#define EHCI_DEBUG_DATA0123 0x08
399#define EHCI_DEBUG_DATA4567 0x0c 427#define EHCI_DEBUG_DATA4567 0x0c
400#define EHCI_DEBUG_DAR 0x10 428#define EHCI_DEBUG_DAR 0x10
401/* Device Address Register */ 429/* Device Address Register */
402#define EHCI_DAR_ENDPOINT __BITS(3,0) 430#define EHCI_DAR_ENDPOINT __BITS(3,0)
403#define EHCI_DAR_ADDRESS __BITS(14,8) 431#define EHCI_DAR_ADDRESS __BITS(14,8)
404 432
405#endif /* _DEV_PCI_EHCIREG_H_ */ 433#endif /* _DEV_PCI_EHCIREG_H_ */