| @@ -1,1774 +1,2113 @@ | | | @@ -1,1774 +1,2113 @@ |
1 | /* $NetBSD: xhci.c,v 1.138 2021/01/05 18:00:21 skrll Exp $ */ | | 1 | /* $NetBSD: xhci.c,v 1.139 2021/05/23 11:49:45 riastradh Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2013 Jonathan A. Kollasch | | 4 | * Copyright (c) 2013 Jonathan A. Kollasch |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
15 | * | | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | | 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
20 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | | 20 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | | 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | | 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | | 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | | 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
25 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | | 25 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | /* | | 29 | /* |
30 | * USB rev 2.0 and rev 3.1 specification | | 30 | * USB rev 2.0 and rev 3.1 specification |
31 | * http://www.usb.org/developers/docs/ | | 31 | * http://www.usb.org/developers/docs/ |
32 | * xHCI rev 1.1 specification | | 32 | * xHCI rev 1.1 specification |
33 | * http://www.intel.com/technology/usb/spec.htm | | 33 | * http://www.intel.com/technology/usb/spec.htm |
34 | */ | | 34 | */ |
35 | | | 35 | |
36 | #include <sys/cdefs.h> | | 36 | #include <sys/cdefs.h> |
37 | __KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.138 2021/01/05 18:00:21 skrll Exp $"); | | 37 | __KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.139 2021/05/23 11:49:45 riastradh Exp $"); |
38 | | | 38 | |
39 | #ifdef _KERNEL_OPT | | 39 | #ifdef _KERNEL_OPT |
40 | #include "opt_usb.h" | | 40 | #include "opt_usb.h" |
41 | #endif | | 41 | #endif |
42 | | | 42 | |
43 | #include <sys/param.h> | | 43 | #include <sys/param.h> |
44 | #include <sys/systm.h> | | 44 | #include <sys/systm.h> |
45 | #include <sys/kernel.h> | | 45 | #include <sys/kernel.h> |
46 | #include <sys/kmem.h> | | 46 | #include <sys/kmem.h> |
47 | #include <sys/device.h> | | 47 | #include <sys/device.h> |
48 | #include <sys/select.h> | | 48 | #include <sys/select.h> |
49 | #include <sys/proc.h> | | 49 | #include <sys/proc.h> |
50 | #include <sys/queue.h> | | 50 | #include <sys/queue.h> |
51 | #include <sys/mutex.h> | | 51 | #include <sys/mutex.h> |
52 | #include <sys/condvar.h> | | 52 | #include <sys/condvar.h> |
53 | #include <sys/bus.h> | | 53 | #include <sys/bus.h> |
54 | #include <sys/cpu.h> | | 54 | #include <sys/cpu.h> |
55 | #include <sys/sysctl.h> | | 55 | #include <sys/sysctl.h> |
56 | | | 56 | |
57 | #include <machine/endian.h> | | 57 | #include <machine/endian.h> |
58 | | | 58 | |
59 | #include <dev/usb/usb.h> | | 59 | #include <dev/usb/usb.h> |
60 | #include <dev/usb/usbdi.h> | | 60 | #include <dev/usb/usbdi.h> |
61 | #include <dev/usb/usbdivar.h> | | 61 | #include <dev/usb/usbdivar.h> |
62 | #include <dev/usb/usbdi_util.h> | | 62 | #include <dev/usb/usbdi_util.h> |
63 | #include <dev/usb/usbhist.h> | | 63 | #include <dev/usb/usbhist.h> |
64 | #include <dev/usb/usb_mem.h> | | 64 | #include <dev/usb/usb_mem.h> |
65 | #include <dev/usb/usb_quirks.h> | | 65 | #include <dev/usb/usb_quirks.h> |
66 | | | 66 | |
67 | #include <dev/usb/xhcireg.h> | | 67 | #include <dev/usb/xhcireg.h> |
68 | #include <dev/usb/xhcivar.h> | | 68 | #include <dev/usb/xhcivar.h> |
69 | #include <dev/usb/usbroothub.h> | | 69 | #include <dev/usb/usbroothub.h> |
70 | | | 70 | |
71 | | | 71 | |
72 | #ifdef USB_DEBUG | | 72 | #ifdef USB_DEBUG |
73 | #ifndef XHCI_DEBUG | | 73 | #ifndef XHCI_DEBUG |
74 | #define xhcidebug 0 | | 74 | #define xhcidebug 0 |
75 | #else /* !XHCI_DEBUG */ | | 75 | #else /* !XHCI_DEBUG */ |
76 | #define HEXDUMP(a, b, c) \ | | 76 | #define HEXDUMP(a, b, c) \ |
77 | do { \ | | 77 | do { \ |
78 | if (xhcidebug > 0) \ | | 78 | if (xhcidebug > 0) \ |
79 | hexdump(printf, a, b, c); \ | | 79 | hexdump(printf, a, b, c); \ |
80 | } while (/*CONSTCOND*/0) | | 80 | } while (/*CONSTCOND*/0) |
81 | static int xhcidebug = 0; | | 81 | static int xhcidebug = 0; |
82 | | | 82 | |
83 | SYSCTL_SETUP(sysctl_hw_xhci_setup, "sysctl hw.xhci setup") | | 83 | SYSCTL_SETUP(sysctl_hw_xhci_setup, "sysctl hw.xhci setup") |
84 | { | | 84 | { |
85 | int err; | | 85 | int err; |
86 | const struct sysctlnode *rnode; | | 86 | const struct sysctlnode *rnode; |
87 | const struct sysctlnode *cnode; | | 87 | const struct sysctlnode *cnode; |
88 | | | 88 | |
89 | err = sysctl_createv(clog, 0, NULL, &rnode, | | 89 | err = sysctl_createv(clog, 0, NULL, &rnode, |
90 | CTLFLAG_PERMANENT, CTLTYPE_NODE, "xhci", | | 90 | CTLFLAG_PERMANENT, CTLTYPE_NODE, "xhci", |
91 | SYSCTL_DESCR("xhci global controls"), | | 91 | SYSCTL_DESCR("xhci global controls"), |
92 | NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL); | | 92 | NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL); |
93 | | | 93 | |
94 | if (err) | | 94 | if (err) |
95 | goto fail; | | 95 | goto fail; |
96 | | | 96 | |
97 | /* control debugging printfs */ | | 97 | /* control debugging printfs */ |
98 | err = sysctl_createv(clog, 0, &rnode, &cnode, | | 98 | err = sysctl_createv(clog, 0, &rnode, &cnode, |
99 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, | | 99 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, |
100 | "debug", SYSCTL_DESCR("Enable debugging output"), | | 100 | "debug", SYSCTL_DESCR("Enable debugging output"), |
101 | NULL, 0, &xhcidebug, sizeof(xhcidebug), CTL_CREATE, CTL_EOL); | | 101 | NULL, 0, &xhcidebug, sizeof(xhcidebug), CTL_CREATE, CTL_EOL); |
102 | if (err) | | 102 | if (err) |
103 | goto fail; | | 103 | goto fail; |
104 | | | 104 | |
105 | return; | | 105 | return; |
106 | fail: | | 106 | fail: |
107 | aprint_error("%s: sysctl_createv failed (err = %d)\n", __func__, err); | | 107 | aprint_error("%s: sysctl_createv failed (err = %d)\n", __func__, err); |
108 | } | | 108 | } |
109 | | | 109 | |
110 | #endif /* !XHCI_DEBUG */ | | 110 | #endif /* !XHCI_DEBUG */ |
111 | #endif /* USB_DEBUG */ | | 111 | #endif /* USB_DEBUG */ |
112 | | | 112 | |
113 | #ifndef HEXDUMP | | 113 | #ifndef HEXDUMP |
114 | #define HEXDUMP(a, b, c) | | 114 | #define HEXDUMP(a, b, c) |
115 | #endif | | 115 | #endif |
116 | | | 116 | |
117 | #define DPRINTF(FMT,A,B,C,D) USBHIST_LOG(xhcidebug,FMT,A,B,C,D) | | 117 | #define DPRINTF(FMT,A,B,C,D) USBHIST_LOG(xhcidebug,FMT,A,B,C,D) |
118 | #define DPRINTFN(N,FMT,A,B,C,D) USBHIST_LOGN(xhcidebug,N,FMT,A,B,C,D) | | 118 | #define DPRINTFN(N,FMT,A,B,C,D) USBHIST_LOGN(xhcidebug,N,FMT,A,B,C,D) |
119 | #define XHCIHIST_FUNC() USBHIST_FUNC() | | 119 | #define XHCIHIST_FUNC() USBHIST_FUNC() |
120 | #define XHCIHIST_CALLED(name) USBHIST_CALLED(xhcidebug) | | 120 | #define XHCIHIST_CALLED(name) USBHIST_CALLED(xhcidebug) |
121 | #define XHCIHIST_CALLARGS(FMT,A,B,C,D) \ | | 121 | #define XHCIHIST_CALLARGS(FMT,A,B,C,D) \ |
122 | USBHIST_CALLARGS(xhcidebug,FMT,A,B,C,D) | | 122 | USBHIST_CALLARGS(xhcidebug,FMT,A,B,C,D) |
123 | | | 123 | |
124 | #define XHCI_DCI_SLOT 0 | | 124 | #define XHCI_DCI_SLOT 0 |
125 | #define XHCI_DCI_EP_CONTROL 1 | | 125 | #define XHCI_DCI_EP_CONTROL 1 |
126 | | | 126 | |
127 | #define XHCI_ICI_INPUT_CONTROL 0 | | 127 | #define XHCI_ICI_INPUT_CONTROL 0 |
128 | | | 128 | |
129 | struct xhci_pipe { | | 129 | struct xhci_pipe { |
130 | struct usbd_pipe xp_pipe; | | 130 | struct usbd_pipe xp_pipe; |
131 | struct usb_task xp_async_task; | | 131 | struct usb_task xp_async_task; |
132 | int16_t xp_isoc_next; /* next frame */ | | 132 | int16_t xp_isoc_next; /* next frame */ |
133 | uint8_t xp_maxb; /* max burst */ | | 133 | uint8_t xp_maxb; /* max burst */ |
134 | uint8_t xp_mult; | | 134 | uint8_t xp_mult; |
135 | }; | | 135 | }; |
136 | | | 136 | |
137 | #define XHCI_COMMAND_RING_TRBS 256 | | 137 | #define XHCI_COMMAND_RING_TRBS 256 |
138 | #define XHCI_EVENT_RING_TRBS 256 | | 138 | #define XHCI_EVENT_RING_TRBS 256 |
139 | #define XHCI_EVENT_RING_SEGMENTS 1 | | 139 | #define XHCI_EVENT_RING_SEGMENTS 1 |
140 | #define XHCI_TRB_3_ED_BIT XHCI_TRB_3_ISP_BIT | | 140 | #define XHCI_TRB_3_ED_BIT XHCI_TRB_3_ISP_BIT |
141 | | | 141 | |
142 | static usbd_status xhci_open(struct usbd_pipe *); | | 142 | static usbd_status xhci_open(struct usbd_pipe *); |
143 | static void xhci_close_pipe(struct usbd_pipe *); | | 143 | static void xhci_close_pipe(struct usbd_pipe *); |
144 | static int xhci_intr1(struct xhci_softc * const); | | 144 | static int xhci_intr1(struct xhci_softc * const); |
145 | static void xhci_softintr(void *); | | 145 | static void xhci_softintr(void *); |
146 | static void xhci_poll(struct usbd_bus *); | | 146 | static void xhci_poll(struct usbd_bus *); |
147 | static struct usbd_xfer *xhci_allocx(struct usbd_bus *, unsigned int); | | 147 | static struct usbd_xfer *xhci_allocx(struct usbd_bus *, unsigned int); |
148 | static void xhci_freex(struct usbd_bus *, struct usbd_xfer *); | | 148 | static void xhci_freex(struct usbd_bus *, struct usbd_xfer *); |
149 | static void xhci_abortx(struct usbd_xfer *); | | 149 | static void xhci_abortx(struct usbd_xfer *); |
150 | static bool xhci_dying(struct usbd_bus *); | | 150 | static bool xhci_dying(struct usbd_bus *); |
151 | static void xhci_get_lock(struct usbd_bus *, kmutex_t **); | | 151 | static void xhci_get_lock(struct usbd_bus *, kmutex_t **); |
152 | static usbd_status xhci_new_device(device_t, struct usbd_bus *, int, int, int, | | 152 | static usbd_status xhci_new_device(device_t, struct usbd_bus *, int, int, int, |
153 | struct usbd_port *); | | 153 | struct usbd_port *); |
154 | static int xhci_roothub_ctrl(struct usbd_bus *, usb_device_request_t *, | | 154 | static int xhci_roothub_ctrl(struct usbd_bus *, usb_device_request_t *, |
155 | void *, int); | | 155 | void *, int); |
156 | | | 156 | |
157 | static usbd_status xhci_configure_endpoint(struct usbd_pipe *); | | 157 | static usbd_status xhci_configure_endpoint(struct usbd_pipe *); |
158 | //static usbd_status xhci_unconfigure_endpoint(struct usbd_pipe *); | | 158 | //static usbd_status xhci_unconfigure_endpoint(struct usbd_pipe *); |
159 | static usbd_status xhci_reset_endpoint(struct usbd_pipe *); | | 159 | static usbd_status xhci_reset_endpoint(struct usbd_pipe *); |
160 | static usbd_status xhci_stop_endpoint(struct usbd_pipe *); | | 160 | static usbd_status xhci_stop_endpoint(struct usbd_pipe *); |
161 | | | 161 | |
162 | static void xhci_host_dequeue(struct xhci_ring * const); | | 162 | static void xhci_host_dequeue(struct xhci_ring * const); |
163 | static usbd_status xhci_set_dequeue(struct usbd_pipe *); | | 163 | static usbd_status xhci_set_dequeue(struct usbd_pipe *); |
164 | | | 164 | |
165 | static usbd_status xhci_do_command(struct xhci_softc * const, | | 165 | static usbd_status xhci_do_command(struct xhci_softc * const, |
166 | struct xhci_soft_trb * const, int); | | 166 | struct xhci_soft_trb * const, int); |
167 | static usbd_status xhci_do_command_locked(struct xhci_softc * const, | | 167 | static usbd_status xhci_do_command_locked(struct xhci_softc * const, |
168 | struct xhci_soft_trb * const, int); | | 168 | struct xhci_soft_trb * const, int); |
169 | static usbd_status xhci_init_slot(struct usbd_device *, uint32_t); | | 169 | static usbd_status xhci_init_slot(struct usbd_device *, uint32_t); |
170 | static void xhci_free_slot(struct xhci_softc *, struct xhci_slot *); | | 170 | static void xhci_free_slot(struct xhci_softc *, struct xhci_slot *); |
171 | static usbd_status xhci_set_address(struct usbd_device *, uint32_t, bool); | | 171 | static usbd_status xhci_set_address(struct usbd_device *, uint32_t, bool); |
172 | static usbd_status xhci_enable_slot(struct xhci_softc * const, | | 172 | static usbd_status xhci_enable_slot(struct xhci_softc * const, |
173 | uint8_t * const); | | 173 | uint8_t * const); |
174 | static usbd_status xhci_disable_slot(struct xhci_softc * const, uint8_t); | | 174 | static usbd_status xhci_disable_slot(struct xhci_softc * const, uint8_t); |
175 | static usbd_status xhci_address_device(struct xhci_softc * const, | | 175 | static usbd_status xhci_address_device(struct xhci_softc * const, |
176 | uint64_t, uint8_t, bool); | | 176 | uint64_t, uint8_t, bool); |
177 | static void xhci_set_dcba(struct xhci_softc * const, uint64_t, int); | | 177 | static void xhci_set_dcba(struct xhci_softc * const, uint64_t, int); |
178 | static usbd_status xhci_update_ep0_mps(struct xhci_softc * const, | | 178 | static usbd_status xhci_update_ep0_mps(struct xhci_softc * const, |
179 | struct xhci_slot * const, u_int); | | 179 | struct xhci_slot * const, u_int); |
180 | static usbd_status xhci_ring_init(struct xhci_softc * const, | | 180 | static usbd_status xhci_ring_init(struct xhci_softc * const, |
181 | struct xhci_ring **, size_t, size_t); | | 181 | struct xhci_ring **, size_t, size_t); |
182 | static void xhci_ring_free(struct xhci_softc * const, | | 182 | static void xhci_ring_free(struct xhci_softc * const, |
183 | struct xhci_ring ** const); | | 183 | struct xhci_ring ** const); |
184 | | | 184 | |
185 | static void xhci_setup_ctx(struct usbd_pipe *); | | 185 | static void xhci_setup_ctx(struct usbd_pipe *); |
186 | static void xhci_setup_route(struct usbd_pipe *, uint32_t *); | | 186 | static void xhci_setup_route(struct usbd_pipe *, uint32_t *); |
187 | static void xhci_setup_tthub(struct usbd_pipe *, uint32_t *); | | 187 | static void xhci_setup_tthub(struct usbd_pipe *, uint32_t *); |
188 | static void xhci_setup_maxburst(struct usbd_pipe *, uint32_t *); | | 188 | static void xhci_setup_maxburst(struct usbd_pipe *, uint32_t *); |
189 | static uint32_t xhci_bival2ival(uint32_t, uint32_t); | | 189 | static uint32_t xhci_bival2ival(uint32_t, uint32_t); |
190 | | | 190 | |
191 | static void xhci_noop(struct usbd_pipe *); | | 191 | static void xhci_noop(struct usbd_pipe *); |
192 | | | 192 | |
193 | static usbd_status xhci_root_intr_transfer(struct usbd_xfer *); | | 193 | static usbd_status xhci_root_intr_transfer(struct usbd_xfer *); |
194 | static usbd_status xhci_root_intr_start(struct usbd_xfer *); | | 194 | static usbd_status xhci_root_intr_start(struct usbd_xfer *); |
195 | static void xhci_root_intr_abort(struct usbd_xfer *); | | 195 | static void xhci_root_intr_abort(struct usbd_xfer *); |
196 | static void xhci_root_intr_close(struct usbd_pipe *); | | 196 | static void xhci_root_intr_close(struct usbd_pipe *); |
197 | static void xhci_root_intr_done(struct usbd_xfer *); | | 197 | static void xhci_root_intr_done(struct usbd_xfer *); |
198 | | | 198 | |
199 | static usbd_status xhci_device_ctrl_transfer(struct usbd_xfer *); | | 199 | static usbd_status xhci_device_ctrl_transfer(struct usbd_xfer *); |
200 | static usbd_status xhci_device_ctrl_start(struct usbd_xfer *); | | 200 | static usbd_status xhci_device_ctrl_start(struct usbd_xfer *); |
201 | static void xhci_device_ctrl_abort(struct usbd_xfer *); | | 201 | static void xhci_device_ctrl_abort(struct usbd_xfer *); |
202 | static void xhci_device_ctrl_close(struct usbd_pipe *); | | 202 | static void xhci_device_ctrl_close(struct usbd_pipe *); |
203 | static void xhci_device_ctrl_done(struct usbd_xfer *); | | 203 | static void xhci_device_ctrl_done(struct usbd_xfer *); |
204 | | | 204 | |
205 | static usbd_status xhci_device_isoc_transfer(struct usbd_xfer *); | | 205 | static usbd_status xhci_device_isoc_transfer(struct usbd_xfer *); |
206 | static usbd_status xhci_device_isoc_enter(struct usbd_xfer *); | | 206 | static usbd_status xhci_device_isoc_enter(struct usbd_xfer *); |
207 | static void xhci_device_isoc_abort(struct usbd_xfer *); | | 207 | static void xhci_device_isoc_abort(struct usbd_xfer *); |
208 | static void xhci_device_isoc_close(struct usbd_pipe *); | | 208 | static void xhci_device_isoc_close(struct usbd_pipe *); |
209 | static void xhci_device_isoc_done(struct usbd_xfer *); | | 209 | static void xhci_device_isoc_done(struct usbd_xfer *); |
210 | | | 210 | |
211 | static usbd_status xhci_device_intr_transfer(struct usbd_xfer *); | | 211 | static usbd_status xhci_device_intr_transfer(struct usbd_xfer *); |
212 | static usbd_status xhci_device_intr_start(struct usbd_xfer *); | | 212 | static usbd_status xhci_device_intr_start(struct usbd_xfer *); |
213 | static void xhci_device_intr_abort(struct usbd_xfer *); | | 213 | static void xhci_device_intr_abort(struct usbd_xfer *); |
214 | static void xhci_device_intr_close(struct usbd_pipe *); | | 214 | static void xhci_device_intr_close(struct usbd_pipe *); |
215 | static void xhci_device_intr_done(struct usbd_xfer *); | | 215 | static void xhci_device_intr_done(struct usbd_xfer *); |
216 | | | 216 | |
217 | static usbd_status xhci_device_bulk_transfer(struct usbd_xfer *); | | 217 | static usbd_status xhci_device_bulk_transfer(struct usbd_xfer *); |
218 | static usbd_status xhci_device_bulk_start(struct usbd_xfer *); | | 218 | static usbd_status xhci_device_bulk_start(struct usbd_xfer *); |
219 | static void xhci_device_bulk_abort(struct usbd_xfer *); | | 219 | static void xhci_device_bulk_abort(struct usbd_xfer *); |
220 | static void xhci_device_bulk_close(struct usbd_pipe *); | | 220 | static void xhci_device_bulk_close(struct usbd_pipe *); |
221 | static void xhci_device_bulk_done(struct usbd_xfer *); | | 221 | static void xhci_device_bulk_done(struct usbd_xfer *); |
222 | | | 222 | |
223 | static const struct usbd_bus_methods xhci_bus_methods = { | | 223 | static const struct usbd_bus_methods xhci_bus_methods = { |
224 | .ubm_open = xhci_open, | | 224 | .ubm_open = xhci_open, |
225 | .ubm_softint = xhci_softintr, | | 225 | .ubm_softint = xhci_softintr, |
226 | .ubm_dopoll = xhci_poll, | | 226 | .ubm_dopoll = xhci_poll, |
227 | .ubm_allocx = xhci_allocx, | | 227 | .ubm_allocx = xhci_allocx, |
228 | .ubm_freex = xhci_freex, | | 228 | .ubm_freex = xhci_freex, |
229 | .ubm_abortx = xhci_abortx, | | 229 | .ubm_abortx = xhci_abortx, |
230 | .ubm_dying = xhci_dying, | | 230 | .ubm_dying = xhci_dying, |
231 | .ubm_getlock = xhci_get_lock, | | 231 | .ubm_getlock = xhci_get_lock, |
232 | .ubm_newdev = xhci_new_device, | | 232 | .ubm_newdev = xhci_new_device, |
233 | .ubm_rhctrl = xhci_roothub_ctrl, | | 233 | .ubm_rhctrl = xhci_roothub_ctrl, |
234 | }; | | 234 | }; |
235 | | | 235 | |
236 | static const struct usbd_pipe_methods xhci_root_intr_methods = { | | 236 | static const struct usbd_pipe_methods xhci_root_intr_methods = { |
237 | .upm_transfer = xhci_root_intr_transfer, | | 237 | .upm_transfer = xhci_root_intr_transfer, |
238 | .upm_start = xhci_root_intr_start, | | 238 | .upm_start = xhci_root_intr_start, |
239 | .upm_abort = xhci_root_intr_abort, | | 239 | .upm_abort = xhci_root_intr_abort, |
240 | .upm_close = xhci_root_intr_close, | | 240 | .upm_close = xhci_root_intr_close, |
241 | .upm_cleartoggle = xhci_noop, | | 241 | .upm_cleartoggle = xhci_noop, |
242 | .upm_done = xhci_root_intr_done, | | 242 | .upm_done = xhci_root_intr_done, |
243 | }; | | 243 | }; |
244 | | | 244 | |
245 | | | 245 | |
246 | static const struct usbd_pipe_methods xhci_device_ctrl_methods = { | | 246 | static const struct usbd_pipe_methods xhci_device_ctrl_methods = { |
247 | .upm_transfer = xhci_device_ctrl_transfer, | | 247 | .upm_transfer = xhci_device_ctrl_transfer, |
248 | .upm_start = xhci_device_ctrl_start, | | 248 | .upm_start = xhci_device_ctrl_start, |
249 | .upm_abort = xhci_device_ctrl_abort, | | 249 | .upm_abort = xhci_device_ctrl_abort, |
250 | .upm_close = xhci_device_ctrl_close, | | 250 | .upm_close = xhci_device_ctrl_close, |
251 | .upm_cleartoggle = xhci_noop, | | 251 | .upm_cleartoggle = xhci_noop, |
252 | .upm_done = xhci_device_ctrl_done, | | 252 | .upm_done = xhci_device_ctrl_done, |
253 | }; | | 253 | }; |
254 | | | 254 | |
255 | static const struct usbd_pipe_methods xhci_device_isoc_methods = { | | 255 | static const struct usbd_pipe_methods xhci_device_isoc_methods = { |
256 | .upm_transfer = xhci_device_isoc_transfer, | | 256 | .upm_transfer = xhci_device_isoc_transfer, |
257 | .upm_abort = xhci_device_isoc_abort, | | 257 | .upm_abort = xhci_device_isoc_abort, |
258 | .upm_close = xhci_device_isoc_close, | | 258 | .upm_close = xhci_device_isoc_close, |
259 | .upm_cleartoggle = xhci_noop, | | 259 | .upm_cleartoggle = xhci_noop, |
260 | .upm_done = xhci_device_isoc_done, | | 260 | .upm_done = xhci_device_isoc_done, |
261 | }; | | 261 | }; |
262 | | | 262 | |
263 | static const struct usbd_pipe_methods xhci_device_bulk_methods = { | | 263 | static const struct usbd_pipe_methods xhci_device_bulk_methods = { |
264 | .upm_transfer = xhci_device_bulk_transfer, | | 264 | .upm_transfer = xhci_device_bulk_transfer, |
265 | .upm_start = xhci_device_bulk_start, | | 265 | .upm_start = xhci_device_bulk_start, |
266 | .upm_abort = xhci_device_bulk_abort, | | 266 | .upm_abort = xhci_device_bulk_abort, |
267 | .upm_close = xhci_device_bulk_close, | | 267 | .upm_close = xhci_device_bulk_close, |
268 | .upm_cleartoggle = xhci_noop, | | 268 | .upm_cleartoggle = xhci_noop, |
269 | .upm_done = xhci_device_bulk_done, | | 269 | .upm_done = xhci_device_bulk_done, |
270 | }; | | 270 | }; |
271 | | | 271 | |
272 | static const struct usbd_pipe_methods xhci_device_intr_methods = { | | 272 | static const struct usbd_pipe_methods xhci_device_intr_methods = { |
273 | .upm_transfer = xhci_device_intr_transfer, | | 273 | .upm_transfer = xhci_device_intr_transfer, |
274 | .upm_start = xhci_device_intr_start, | | 274 | .upm_start = xhci_device_intr_start, |
275 | .upm_abort = xhci_device_intr_abort, | | 275 | .upm_abort = xhci_device_intr_abort, |
276 | .upm_close = xhci_device_intr_close, | | 276 | .upm_close = xhci_device_intr_close, |
277 | .upm_cleartoggle = xhci_noop, | | 277 | .upm_cleartoggle = xhci_noop, |
278 | .upm_done = xhci_device_intr_done, | | 278 | .upm_done = xhci_device_intr_done, |
279 | }; | | 279 | }; |
280 | | | 280 | |
281 | static inline uint32_t | | 281 | static inline uint32_t |
282 | xhci_read_1(const struct xhci_softc * const sc, bus_size_t offset) | | 282 | xhci_read_1(const struct xhci_softc * const sc, bus_size_t offset) |
283 | { | | 283 | { |
284 | return bus_space_read_1(sc->sc_iot, sc->sc_ioh, offset); | | 284 | return bus_space_read_1(sc->sc_iot, sc->sc_ioh, offset); |
285 | } | | 285 | } |
286 | | | 286 | |
287 | static inline uint32_t | | 287 | static inline uint32_t |
288 | xhci_read_2(const struct xhci_softc * const sc, bus_size_t offset) | | 288 | xhci_read_2(const struct xhci_softc * const sc, bus_size_t offset) |
289 | { | | 289 | { |
290 | return bus_space_read_2(sc->sc_iot, sc->sc_ioh, offset); | | 290 | return bus_space_read_2(sc->sc_iot, sc->sc_ioh, offset); |
291 | } | | 291 | } |
292 | | | 292 | |
293 | static inline uint32_t | | 293 | static inline uint32_t |
294 | xhci_read_4(const struct xhci_softc * const sc, bus_size_t offset) | | 294 | xhci_read_4(const struct xhci_softc * const sc, bus_size_t offset) |
295 | { | | 295 | { |
296 | return bus_space_read_4(sc->sc_iot, sc->sc_ioh, offset); | | 296 | return bus_space_read_4(sc->sc_iot, sc->sc_ioh, offset); |
297 | } | | 297 | } |
298 | | | 298 | |
299 | static inline void | | 299 | static inline void |
300 | xhci_write_1(const struct xhci_softc * const sc, bus_size_t offset, | | 300 | xhci_write_1(const struct xhci_softc * const sc, bus_size_t offset, |
301 | uint32_t value) | | 301 | uint32_t value) |
302 | { | | 302 | { |
303 | bus_space_write_1(sc->sc_iot, sc->sc_ioh, offset, value); | | 303 | bus_space_write_1(sc->sc_iot, sc->sc_ioh, offset, value); |
304 | } | | 304 | } |
305 | | | 305 | |
306 | #if 0 /* unused */ | | 306 | #if 0 /* unused */ |
307 | static inline void | | 307 | static inline void |
308 | xhci_write_4(const struct xhci_softc * const sc, bus_size_t offset, | | 308 | xhci_write_4(const struct xhci_softc * const sc, bus_size_t offset, |
309 | uint32_t value) | | 309 | uint32_t value) |
310 | { | | 310 | { |
311 | bus_space_write_4(sc->sc_iot, sc->sc_ioh, offset, value); | | 311 | bus_space_write_4(sc->sc_iot, sc->sc_ioh, offset, value); |
312 | } | | 312 | } |
313 | #endif /* unused */ | | 313 | #endif /* unused */ |
314 | | | 314 | |
315 | static inline void | | 315 | static inline void |
316 | xhci_barrier(const struct xhci_softc * const sc, int flags) | | 316 | xhci_barrier(const struct xhci_softc * const sc, int flags) |
317 | { | | 317 | { |
318 | bus_space_barrier(sc->sc_iot, sc->sc_ioh, 0, sc->sc_ios, flags); | | 318 | bus_space_barrier(sc->sc_iot, sc->sc_ioh, 0, sc->sc_ios, flags); |
319 | } | | 319 | } |
320 | | | 320 | |
321 | static inline uint32_t | | 321 | static inline uint32_t |
322 | xhci_cap_read_4(const struct xhci_softc * const sc, bus_size_t offset) | | 322 | xhci_cap_read_4(const struct xhci_softc * const sc, bus_size_t offset) |
323 | { | | 323 | { |
324 | return bus_space_read_4(sc->sc_iot, sc->sc_cbh, offset); | | 324 | return bus_space_read_4(sc->sc_iot, sc->sc_cbh, offset); |
325 | } | | 325 | } |
326 | | | 326 | |
327 | static inline uint32_t | | 327 | static inline uint32_t |
328 | xhci_op_read_4(const struct xhci_softc * const sc, bus_size_t offset) | | 328 | xhci_op_read_4(const struct xhci_softc * const sc, bus_size_t offset) |
329 | { | | 329 | { |
330 | return bus_space_read_4(sc->sc_iot, sc->sc_obh, offset); | | 330 | return bus_space_read_4(sc->sc_iot, sc->sc_obh, offset); |
331 | } | | 331 | } |
332 | | | 332 | |
333 | static inline void | | 333 | static inline void |
334 | xhci_op_write_4(const struct xhci_softc * const sc, bus_size_t offset, | | 334 | xhci_op_write_4(const struct xhci_softc * const sc, bus_size_t offset, |
335 | uint32_t value) | | 335 | uint32_t value) |
336 | { | | 336 | { |
337 | bus_space_write_4(sc->sc_iot, sc->sc_obh, offset, value); | | 337 | bus_space_write_4(sc->sc_iot, sc->sc_obh, offset, value); |
338 | } | | 338 | } |
339 | | | 339 | |
340 | static inline uint64_t | | 340 | static inline uint64_t |
341 | xhci_op_read_8(const struct xhci_softc * const sc, bus_size_t offset) | | 341 | xhci_op_read_8(const struct xhci_softc * const sc, bus_size_t offset) |
342 | { | | 342 | { |
343 | uint64_t value; | | 343 | uint64_t value; |
344 | | | 344 | |
345 | if (XHCI_HCC_AC64(sc->sc_hcc)) { | | 345 | if (XHCI_HCC_AC64(sc->sc_hcc)) { |
346 | #ifdef XHCI_USE_BUS_SPACE_8 | | 346 | #ifdef XHCI_USE_BUS_SPACE_8 |
347 | value = bus_space_read_8(sc->sc_iot, sc->sc_obh, offset); | | 347 | value = bus_space_read_8(sc->sc_iot, sc->sc_obh, offset); |
348 | #else | | 348 | #else |
349 | value = bus_space_read_4(sc->sc_iot, sc->sc_obh, offset); | | 349 | value = bus_space_read_4(sc->sc_iot, sc->sc_obh, offset); |
350 | value |= (uint64_t)bus_space_read_4(sc->sc_iot, sc->sc_obh, | | 350 | value |= (uint64_t)bus_space_read_4(sc->sc_iot, sc->sc_obh, |
351 | offset + 4) << 32; | | 351 | offset + 4) << 32; |
352 | #endif | | 352 | #endif |
353 | } else { | | 353 | } else { |
354 | value = bus_space_read_4(sc->sc_iot, sc->sc_obh, offset); | | 354 | value = bus_space_read_4(sc->sc_iot, sc->sc_obh, offset); |
355 | } | | 355 | } |
356 | | | 356 | |
357 | return value; | | 357 | return value; |
358 | } | | 358 | } |
359 | | | 359 | |
360 | static inline void | | 360 | static inline void |
361 | xhci_op_write_8(const struct xhci_softc * const sc, bus_size_t offset, | | 361 | xhci_op_write_8(const struct xhci_softc * const sc, bus_size_t offset, |
362 | uint64_t value) | | 362 | uint64_t value) |
363 | { | | 363 | { |
364 | if (XHCI_HCC_AC64(sc->sc_hcc)) { | | 364 | if (XHCI_HCC_AC64(sc->sc_hcc)) { |
365 | #ifdef XHCI_USE_BUS_SPACE_8 | | 365 | #ifdef XHCI_USE_BUS_SPACE_8 |
366 | bus_space_write_8(sc->sc_iot, sc->sc_obh, offset, value); | | 366 | bus_space_write_8(sc->sc_iot, sc->sc_obh, offset, value); |
367 | #else | | 367 | #else |
368 | bus_space_write_4(sc->sc_iot, sc->sc_obh, offset + 0, | | 368 | bus_space_write_4(sc->sc_iot, sc->sc_obh, offset + 0, |
369 | (value >> 0) & 0xffffffff); | | 369 | (value >> 0) & 0xffffffff); |
370 | bus_space_write_4(sc->sc_iot, sc->sc_obh, offset + 4, | | 370 | bus_space_write_4(sc->sc_iot, sc->sc_obh, offset + 4, |
371 | (value >> 32) & 0xffffffff); | | 371 | (value >> 32) & 0xffffffff); |
372 | #endif | | 372 | #endif |
373 | } else { | | 373 | } else { |
374 | bus_space_write_4(sc->sc_iot, sc->sc_obh, offset, value); | | 374 | bus_space_write_4(sc->sc_iot, sc->sc_obh, offset, value); |
375 | } | | 375 | } |
376 | } | | 376 | } |
377 | | | 377 | |
378 | static inline uint32_t | | 378 | static inline uint32_t |
379 | xhci_rt_read_4(const struct xhci_softc * const sc, bus_size_t offset) | | 379 | xhci_rt_read_4(const struct xhci_softc * const sc, bus_size_t offset) |
380 | { | | 380 | { |
381 | return bus_space_read_4(sc->sc_iot, sc->sc_rbh, offset); | | 381 | return bus_space_read_4(sc->sc_iot, sc->sc_rbh, offset); |
382 | } | | 382 | } |
383 | | | 383 | |
384 | static inline void | | 384 | static inline void |
385 | xhci_rt_write_4(const struct xhci_softc * const sc, bus_size_t offset, | | 385 | xhci_rt_write_4(const struct xhci_softc * const sc, bus_size_t offset, |
386 | uint32_t value) | | 386 | uint32_t value) |
387 | { | | 387 | { |
388 | bus_space_write_4(sc->sc_iot, sc->sc_rbh, offset, value); | | 388 | bus_space_write_4(sc->sc_iot, sc->sc_rbh, offset, value); |
389 | } | | 389 | } |
390 | | | 390 | |
391 | #if 0 /* unused */ | | | |
392 | static inline uint64_t | | 391 | static inline uint64_t |
393 | xhci_rt_read_8(const struct xhci_softc * const sc, bus_size_t offset) | | 392 | xhci_rt_read_8(const struct xhci_softc * const sc, bus_size_t offset) |
394 | { | | 393 | { |
395 | uint64_t value; | | 394 | uint64_t value; |
396 | | | 395 | |
397 | if (XHCI_HCC_AC64(sc->sc_hcc)) { | | 396 | if (XHCI_HCC_AC64(sc->sc_hcc)) { |
398 | #ifdef XHCI_USE_BUS_SPACE_8 | | 397 | #ifdef XHCI_USE_BUS_SPACE_8 |
399 | value = bus_space_read_8(sc->sc_iot, sc->sc_rbh, offset); | | 398 | value = bus_space_read_8(sc->sc_iot, sc->sc_rbh, offset); |
400 | #else | | 399 | #else |
401 | value = bus_space_read_4(sc->sc_iot, sc->sc_rbh, offset); | | 400 | value = bus_space_read_4(sc->sc_iot, sc->sc_rbh, offset); |
402 | value |= (uint64_t)bus_space_read_4(sc->sc_iot, sc->sc_rbh, | | 401 | value |= (uint64_t)bus_space_read_4(sc->sc_iot, sc->sc_rbh, |
403 | offset + 4) << 32; | | 402 | offset + 4) << 32; |
404 | #endif | | 403 | #endif |
405 | } else { | | 404 | } else { |
406 | value = bus_space_read_4(sc->sc_iot, sc->sc_rbh, offset); | | 405 | value = bus_space_read_4(sc->sc_iot, sc->sc_rbh, offset); |
407 | } | | 406 | } |
408 | | | 407 | |
409 | return value; | | 408 | return value; |
410 | } | | 409 | } |
411 | #endif /* unused */ | | | |
412 | | | 410 | |
413 | static inline void | | 411 | static inline void |
414 | xhci_rt_write_8(const struct xhci_softc * const sc, bus_size_t offset, | | 412 | xhci_rt_write_8(const struct xhci_softc * const sc, bus_size_t offset, |
415 | uint64_t value) | | 413 | uint64_t value) |
416 | { | | 414 | { |
417 | if (XHCI_HCC_AC64(sc->sc_hcc)) { | | 415 | if (XHCI_HCC_AC64(sc->sc_hcc)) { |
418 | #ifdef XHCI_USE_BUS_SPACE_8 | | 416 | #ifdef XHCI_USE_BUS_SPACE_8 |
419 | bus_space_write_8(sc->sc_iot, sc->sc_rbh, offset, value); | | 417 | bus_space_write_8(sc->sc_iot, sc->sc_rbh, offset, value); |
420 | #else | | 418 | #else |
421 | bus_space_write_4(sc->sc_iot, sc->sc_rbh, offset + 0, | | 419 | bus_space_write_4(sc->sc_iot, sc->sc_rbh, offset + 0, |
422 | (value >> 0) & 0xffffffff); | | 420 | (value >> 0) & 0xffffffff); |
423 | bus_space_write_4(sc->sc_iot, sc->sc_rbh, offset + 4, | | 421 | bus_space_write_4(sc->sc_iot, sc->sc_rbh, offset + 4, |
424 | (value >> 32) & 0xffffffff); | | 422 | (value >> 32) & 0xffffffff); |
425 | #endif | | 423 | #endif |
426 | } else { | | 424 | } else { |
427 | bus_space_write_4(sc->sc_iot, sc->sc_rbh, offset, value); | | 425 | bus_space_write_4(sc->sc_iot, sc->sc_rbh, offset, value); |
428 | } | | 426 | } |
429 | } | | 427 | } |
430 | | | 428 | |
431 | #if 0 /* unused */ | | 429 | #if 0 /* unused */ |
432 | static inline uint32_t | | 430 | static inline uint32_t |
433 | xhci_db_read_4(const struct xhci_softc * const sc, bus_size_t offset) | | 431 | xhci_db_read_4(const struct xhci_softc * const sc, bus_size_t offset) |
434 | { | | 432 | { |
435 | return bus_space_read_4(sc->sc_iot, sc->sc_dbh, offset); | | 433 | return bus_space_read_4(sc->sc_iot, sc->sc_dbh, offset); |
436 | } | | 434 | } |
437 | #endif /* unused */ | | 435 | #endif /* unused */ |
438 | | | 436 | |
439 | static inline void | | 437 | static inline void |
440 | xhci_db_write_4(const struct xhci_softc * const sc, bus_size_t offset, | | 438 | xhci_db_write_4(const struct xhci_softc * const sc, bus_size_t offset, |
441 | uint32_t value) | | 439 | uint32_t value) |
442 | { | | 440 | { |
443 | bus_space_write_4(sc->sc_iot, sc->sc_dbh, offset, value); | | 441 | bus_space_write_4(sc->sc_iot, sc->sc_dbh, offset, value); |
444 | } | | 442 | } |
445 | | | 443 | |
446 | /* --- */ | | 444 | /* --- */ |
447 | | | 445 | |
448 | static inline uint8_t | | 446 | static inline uint8_t |
449 | xhci_ep_get_type(usb_endpoint_descriptor_t * const ed) | | 447 | xhci_ep_get_type(usb_endpoint_descriptor_t * const ed) |
450 | { | | 448 | { |
451 | u_int eptype = 0; | | 449 | u_int eptype = 0; |
452 | | | 450 | |
453 | switch (UE_GET_XFERTYPE(ed->bmAttributes)) { | | 451 | switch (UE_GET_XFERTYPE(ed->bmAttributes)) { |
454 | case UE_CONTROL: | | 452 | case UE_CONTROL: |
455 | eptype = 0x0; | | 453 | eptype = 0x0; |
456 | break; | | 454 | break; |
457 | case UE_ISOCHRONOUS: | | 455 | case UE_ISOCHRONOUS: |
458 | eptype = 0x1; | | 456 | eptype = 0x1; |
459 | break; | | 457 | break; |
460 | case UE_BULK: | | 458 | case UE_BULK: |
461 | eptype = 0x2; | | 459 | eptype = 0x2; |
462 | break; | | 460 | break; |
463 | case UE_INTERRUPT: | | 461 | case UE_INTERRUPT: |
464 | eptype = 0x3; | | 462 | eptype = 0x3; |
465 | break; | | 463 | break; |
466 | } | | 464 | } |
467 | | | 465 | |
468 | if ((UE_GET_XFERTYPE(ed->bmAttributes) == UE_CONTROL) || | | 466 | if ((UE_GET_XFERTYPE(ed->bmAttributes) == UE_CONTROL) || |
469 | (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN)) | | 467 | (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN)) |
470 | return eptype | 0x4; | | 468 | return eptype | 0x4; |
471 | else | | 469 | else |
472 | return eptype; | | 470 | return eptype; |
473 | } | | 471 | } |
474 | | | 472 | |
475 | static u_int | | 473 | static u_int |
476 | xhci_ep_get_dci(usb_endpoint_descriptor_t * const ed) | | 474 | xhci_ep_get_dci(usb_endpoint_descriptor_t * const ed) |
477 | { | | 475 | { |
478 | /* xHCI 1.0 section 4.5.1 */ | | 476 | /* xHCI 1.0 section 4.5.1 */ |
479 | u_int epaddr = UE_GET_ADDR(ed->bEndpointAddress); | | 477 | u_int epaddr = UE_GET_ADDR(ed->bEndpointAddress); |
480 | u_int in = 0; | | 478 | u_int in = 0; |
481 | | | 479 | |
482 | if ((UE_GET_XFERTYPE(ed->bmAttributes) == UE_CONTROL) || | | 480 | if ((UE_GET_XFERTYPE(ed->bmAttributes) == UE_CONTROL) || |
483 | (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN)) | | 481 | (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN)) |
484 | in = 1; | | 482 | in = 1; |
485 | | | 483 | |
486 | return epaddr * 2 + in; | | 484 | return epaddr * 2 + in; |
487 | } | | 485 | } |
488 | | | 486 | |
489 | static inline u_int | | 487 | static inline u_int |
490 | xhci_dci_to_ici(const u_int i) | | 488 | xhci_dci_to_ici(const u_int i) |
491 | { | | 489 | { |
492 | return i + 1; | | 490 | return i + 1; |
493 | } | | 491 | } |
494 | | | 492 | |
495 | static inline void * | | 493 | static inline void * |
496 | xhci_slot_get_dcv(struct xhci_softc * const sc, struct xhci_slot * const xs, | | 494 | xhci_slot_get_dcv(struct xhci_softc * const sc, struct xhci_slot * const xs, |
497 | const u_int dci) | | 495 | const u_int dci) |
498 | { | | 496 | { |
499 | return KERNADDR(&xs->xs_dc_dma, sc->sc_ctxsz * dci); | | 497 | return KERNADDR(&xs->xs_dc_dma, sc->sc_ctxsz * dci); |
500 | } | | 498 | } |
501 | | | 499 | |
502 | #if 0 /* unused */ | | 500 | #if 0 /* unused */ |
503 | static inline bus_addr_t | | 501 | static inline bus_addr_t |
504 | xhci_slot_get_dcp(struct xhci_softc * const sc, struct xhci_slot * const xs, | | 502 | xhci_slot_get_dcp(struct xhci_softc * const sc, struct xhci_slot * const xs, |
505 | const u_int dci) | | 503 | const u_int dci) |
506 | { | | 504 | { |
507 | return DMAADDR(&xs->xs_dc_dma, sc->sc_ctxsz * dci); | | 505 | return DMAADDR(&xs->xs_dc_dma, sc->sc_ctxsz * dci); |
508 | } | | 506 | } |
509 | #endif /* unused */ | | 507 | #endif /* unused */ |
510 | | | 508 | |
511 | static inline void * | | 509 | static inline void * |
512 | xhci_slot_get_icv(struct xhci_softc * const sc, struct xhci_slot * const xs, | | 510 | xhci_slot_get_icv(struct xhci_softc * const sc, struct xhci_slot * const xs, |
513 | const u_int ici) | | 511 | const u_int ici) |
514 | { | | 512 | { |
515 | return KERNADDR(&xs->xs_ic_dma, sc->sc_ctxsz * ici); | | 513 | return KERNADDR(&xs->xs_ic_dma, sc->sc_ctxsz * ici); |
516 | } | | 514 | } |
517 | | | 515 | |
518 | static inline bus_addr_t | | 516 | static inline bus_addr_t |
519 | xhci_slot_get_icp(struct xhci_softc * const sc, struct xhci_slot * const xs, | | 517 | xhci_slot_get_icp(struct xhci_softc * const sc, struct xhci_slot * const xs, |
520 | const u_int ici) | | 518 | const u_int ici) |
521 | { | | 519 | { |
522 | return DMAADDR(&xs->xs_ic_dma, sc->sc_ctxsz * ici); | | 520 | return DMAADDR(&xs->xs_ic_dma, sc->sc_ctxsz * ici); |
523 | } | | 521 | } |
524 | | | 522 | |
525 | static inline struct xhci_trb * | | 523 | static inline struct xhci_trb * |
526 | xhci_ring_trbv(struct xhci_ring * const xr, u_int idx) | | 524 | xhci_ring_trbv(struct xhci_ring * const xr, u_int idx) |
527 | { | | 525 | { |
528 | return KERNADDR(&xr->xr_dma, XHCI_TRB_SIZE * idx); | | 526 | return KERNADDR(&xr->xr_dma, XHCI_TRB_SIZE * idx); |
529 | } | | 527 | } |
530 | | | 528 | |
531 | static inline bus_addr_t | | 529 | static inline bus_addr_t |
532 | xhci_ring_trbp(struct xhci_ring * const xr, u_int idx) | | 530 | xhci_ring_trbp(struct xhci_ring * const xr, u_int idx) |
533 | { | | 531 | { |
534 | return DMAADDR(&xr->xr_dma, XHCI_TRB_SIZE * idx); | | 532 | return DMAADDR(&xr->xr_dma, XHCI_TRB_SIZE * idx); |
535 | } | | 533 | } |
536 | | | 534 | |
537 | static inline void | | 535 | static inline void |
538 | xhci_xfer_put_trb(struct xhci_xfer * const xx, u_int idx, | | 536 | xhci_xfer_put_trb(struct xhci_xfer * const xx, u_int idx, |
539 | uint64_t parameter, uint32_t status, uint32_t control) | | 537 | uint64_t parameter, uint32_t status, uint32_t control) |
540 | { | | 538 | { |
541 | KASSERTMSG(idx < xx->xx_ntrb, "idx=%u xx_ntrb=%u", idx, xx->xx_ntrb); | | 539 | KASSERTMSG(idx < xx->xx_ntrb, "idx=%u xx_ntrb=%u", idx, xx->xx_ntrb); |
542 | xx->xx_trb[idx].trb_0 = parameter; | | 540 | xx->xx_trb[idx].trb_0 = parameter; |
543 | xx->xx_trb[idx].trb_2 = status; | | 541 | xx->xx_trb[idx].trb_2 = status; |
544 | xx->xx_trb[idx].trb_3 = control; | | 542 | xx->xx_trb[idx].trb_3 = control; |
545 | } | | 543 | } |
546 | | | 544 | |
547 | static inline void | | 545 | static inline void |
548 | xhci_trb_put(struct xhci_trb * const trb, uint64_t parameter, uint32_t status, | | 546 | xhci_trb_put(struct xhci_trb * const trb, uint64_t parameter, uint32_t status, |
549 | uint32_t control) | | 547 | uint32_t control) |
550 | { | | 548 | { |
551 | trb->trb_0 = htole64(parameter); | | 549 | trb->trb_0 = htole64(parameter); |
552 | trb->trb_2 = htole32(status); | | 550 | trb->trb_2 = htole32(status); |
553 | trb->trb_3 = htole32(control); | | 551 | trb->trb_3 = htole32(control); |
554 | } | | 552 | } |
555 | | | 553 | |
556 | static int | | 554 | static int |
557 | xhci_trb_get_idx(struct xhci_ring *xr, uint64_t trb_0, int *idx) | | 555 | xhci_trb_get_idx(struct xhci_ring *xr, uint64_t trb_0, int *idx) |
558 | { | | 556 | { |
559 | /* base address of TRBs */ | | 557 | /* base address of TRBs */ |
560 | bus_addr_t trbp = xhci_ring_trbp(xr, 0); | | 558 | bus_addr_t trbp = xhci_ring_trbp(xr, 0); |
561 | | | 559 | |
562 | /* trb_0 range sanity check */ | | 560 | /* trb_0 range sanity check */ |
563 | if (trb_0 == 0 || trb_0 < trbp || | | 561 | if (trb_0 == 0 || trb_0 < trbp || |
564 | (trb_0 - trbp) % sizeof(struct xhci_trb) != 0 || | | 562 | (trb_0 - trbp) % sizeof(struct xhci_trb) != 0 || |
565 | (trb_0 - trbp) / sizeof(struct xhci_trb) >= xr->xr_ntrb) { | | 563 | (trb_0 - trbp) / sizeof(struct xhci_trb) >= xr->xr_ntrb) { |
566 | return 1; | | 564 | return 1; |
567 | } | | 565 | } |
568 | *idx = (trb_0 - trbp) / sizeof(struct xhci_trb); | | 566 | *idx = (trb_0 - trbp) / sizeof(struct xhci_trb); |
569 | return 0; | | 567 | return 0; |
570 | } | | 568 | } |
571 | | | 569 | |
572 | static unsigned int | | 570 | static unsigned int |
573 | xhci_get_epstate(struct xhci_softc * const sc, struct xhci_slot * const xs, | | 571 | xhci_get_epstate(struct xhci_softc * const sc, struct xhci_slot * const xs, |
574 | u_int dci) | | 572 | u_int dci) |
575 | { | | 573 | { |
576 | uint32_t *cp; | | 574 | uint32_t *cp; |
577 | | | 575 | |
578 | usb_syncmem(&xs->xs_dc_dma, 0, sc->sc_pgsz, BUS_DMASYNC_POSTREAD); | | 576 | usb_syncmem(&xs->xs_dc_dma, 0, sc->sc_pgsz, BUS_DMASYNC_POSTREAD); |
579 | cp = xhci_slot_get_dcv(sc, xs, dci); | | 577 | cp = xhci_slot_get_dcv(sc, xs, dci); |
580 | return XHCI_EPCTX_0_EPSTATE_GET(le32toh(cp[0])); | | 578 | return XHCI_EPCTX_0_EPSTATE_GET(le32toh(cp[0])); |
581 | } | | 579 | } |
582 | | | 580 | |
583 | static inline unsigned int | | 581 | static inline unsigned int |
584 | xhci_ctlrport2bus(struct xhci_softc * const sc, unsigned int ctlrport) | | 582 | xhci_ctlrport2bus(struct xhci_softc * const sc, unsigned int ctlrport) |
585 | { | | 583 | { |
586 | const unsigned int port = ctlrport - 1; | | 584 | const unsigned int port = ctlrport - 1; |
587 | const uint8_t bit = __BIT(port % NBBY); | | 585 | const uint8_t bit = __BIT(port % NBBY); |
588 | | | 586 | |
589 | return __SHIFTOUT(sc->sc_ctlrportbus[port / NBBY], bit); | | 587 | return __SHIFTOUT(sc->sc_ctlrportbus[port / NBBY], bit); |
590 | } | | 588 | } |
591 | | | 589 | |
592 | /* | | 590 | /* |
593 | * Return the roothub port for a controller port. Both are 1..n. | | 591 | * Return the roothub port for a controller port. Both are 1..n. |
594 | */ | | 592 | */ |
595 | static inline unsigned int | | 593 | static inline unsigned int |
596 | xhci_ctlrport2rhport(struct xhci_softc * const sc, unsigned int ctrlport) | | 594 | xhci_ctlrport2rhport(struct xhci_softc * const sc, unsigned int ctrlport) |
597 | { | | 595 | { |
598 | | | 596 | |
599 | return sc->sc_ctlrportmap[ctrlport - 1]; | | 597 | return sc->sc_ctlrportmap[ctrlport - 1]; |
600 | } | | 598 | } |
601 | | | 599 | |
602 | /* | | 600 | /* |
603 | * Return the controller port for a bus roothub port. Both are 1..n. | | 601 | * Return the controller port for a bus roothub port. Both are 1..n. |
604 | */ | | 602 | */ |
605 | static inline unsigned int | | 603 | static inline unsigned int |
606 | xhci_rhport2ctlrport(struct xhci_softc * const sc, unsigned int bn, | | 604 | xhci_rhport2ctlrport(struct xhci_softc * const sc, unsigned int bn, |
607 | unsigned int rhport) | | 605 | unsigned int rhport) |
608 | { | | 606 | { |
609 | | | 607 | |
610 | return sc->sc_rhportmap[bn][rhport - 1]; | | 608 | return sc->sc_rhportmap[bn][rhport - 1]; |
611 | } | | 609 | } |
612 | | | 610 | |
613 | /* --- */ | | 611 | /* --- */ |
614 | | | 612 | |
615 | void | | 613 | void |
616 | xhci_childdet(device_t self, device_t child) | | 614 | xhci_childdet(device_t self, device_t child) |
617 | { | | 615 | { |
618 | struct xhci_softc * const sc = device_private(self); | | 616 | struct xhci_softc * const sc = device_private(self); |
619 | | | 617 | |
620 | KASSERT((sc->sc_child == child) || (sc->sc_child2 == child)); | | 618 | KASSERT((sc->sc_child == child) || (sc->sc_child2 == child)); |
621 | if (child == sc->sc_child2) | | 619 | if (child == sc->sc_child2) |
622 | sc->sc_child2 = NULL; | | 620 | sc->sc_child2 = NULL; |
623 | else if (child == sc->sc_child) | | 621 | else if (child == sc->sc_child) |
624 | sc->sc_child = NULL; | | 622 | sc->sc_child = NULL; |
625 | } | | 623 | } |
626 | | | 624 | |
627 | int | | 625 | int |
628 | xhci_detach(struct xhci_softc *sc, int flags) | | 626 | xhci_detach(struct xhci_softc *sc, int flags) |
629 | { | | 627 | { |
630 | int rv = 0; | | 628 | int rv = 0; |
631 | | | 629 | |
632 | if (sc->sc_child2 != NULL) { | | 630 | if (sc->sc_child2 != NULL) { |
633 | rv = config_detach(sc->sc_child2, flags); | | 631 | rv = config_detach(sc->sc_child2, flags); |
634 | if (rv != 0) | | 632 | if (rv != 0) |
635 | return rv; | | 633 | return rv; |
636 | KASSERT(sc->sc_child2 == NULL); | | 634 | KASSERT(sc->sc_child2 == NULL); |
637 | } | | 635 | } |
638 | | | 636 | |
639 | if (sc->sc_child != NULL) { | | 637 | if (sc->sc_child != NULL) { |
640 | rv = config_detach(sc->sc_child, flags); | | 638 | rv = config_detach(sc->sc_child, flags); |
641 | if (rv != 0) | | 639 | if (rv != 0) |
642 | return rv; | | 640 | return rv; |
643 | KASSERT(sc->sc_child == NULL); | | 641 | KASSERT(sc->sc_child == NULL); |
644 | } | | 642 | } |
645 | | | 643 | |
646 | /* XXX unconfigure/free slots */ | | 644 | /* XXX unconfigure/free slots */ |
647 | | | 645 | |
648 | /* verify: */ | | 646 | /* verify: */ |
649 | xhci_rt_write_4(sc, XHCI_IMAN(0), 0); | | 647 | xhci_rt_write_4(sc, XHCI_IMAN(0), 0); |
650 | xhci_op_write_4(sc, XHCI_USBCMD, 0); | | 648 | xhci_op_write_4(sc, XHCI_USBCMD, 0); |
651 | /* do we need to wait for stop? */ | | 649 | /* do we need to wait for stop? */ |
652 | | | 650 | |
653 | xhci_op_write_8(sc, XHCI_CRCR, 0); | | 651 | xhci_op_write_8(sc, XHCI_CRCR, 0); |
654 | xhci_ring_free(sc, &sc->sc_cr); | | 652 | xhci_ring_free(sc, &sc->sc_cr); |
655 | cv_destroy(&sc->sc_command_cv); | | 653 | cv_destroy(&sc->sc_command_cv); |
656 | cv_destroy(&sc->sc_cmdbusy_cv); | | 654 | cv_destroy(&sc->sc_cmdbusy_cv); |
657 | | | 655 | |
658 | xhci_rt_write_4(sc, XHCI_ERSTSZ(0), 0); | | 656 | xhci_rt_write_4(sc, XHCI_ERSTSZ(0), 0); |
659 | xhci_rt_write_8(sc, XHCI_ERSTBA(0), 0); | | 657 | xhci_rt_write_8(sc, XHCI_ERSTBA(0), 0); |
660 | xhci_rt_write_8(sc, XHCI_ERDP(0), 0 | XHCI_ERDP_BUSY); | | 658 | xhci_rt_write_8(sc, XHCI_ERDP(0), 0 | XHCI_ERDP_BUSY); |
661 | xhci_ring_free(sc, &sc->sc_er); | | 659 | xhci_ring_free(sc, &sc->sc_er); |
662 | | | 660 | |
663 | usb_freemem(&sc->sc_bus, &sc->sc_eventst_dma); | | 661 | usb_freemem(&sc->sc_bus, &sc->sc_eventst_dma); |
664 | | | 662 | |
665 | xhci_op_write_8(sc, XHCI_DCBAAP, 0); | | 663 | xhci_op_write_8(sc, XHCI_DCBAAP, 0); |
666 | usb_freemem(&sc->sc_bus, &sc->sc_dcbaa_dma); | | 664 | usb_freemem(&sc->sc_bus, &sc->sc_dcbaa_dma); |
667 | | | 665 | |
668 | kmem_free(sc->sc_slots, sizeof(*sc->sc_slots) * sc->sc_maxslots); | | 666 | kmem_free(sc->sc_slots, sizeof(*sc->sc_slots) * sc->sc_maxslots); |
669 | | | 667 | |
670 | kmem_free(sc->sc_ctlrportbus, | | 668 | kmem_free(sc->sc_ctlrportbus, |
671 | howmany(sc->sc_maxports * sizeof(uint8_t), NBBY)); | | 669 | howmany(sc->sc_maxports * sizeof(uint8_t), NBBY)); |
672 | kmem_free(sc->sc_ctlrportmap, sc->sc_maxports * sizeof(int)); | | 670 | kmem_free(sc->sc_ctlrportmap, sc->sc_maxports * sizeof(int)); |
673 | | | 671 | |
674 | for (size_t j = 0; j < __arraycount(sc->sc_rhportmap); j++) { | | 672 | for (size_t j = 0; j < __arraycount(sc->sc_rhportmap); j++) { |
675 | kmem_free(sc->sc_rhportmap[j], sc->sc_maxports * sizeof(int)); | | 673 | kmem_free(sc->sc_rhportmap[j], sc->sc_maxports * sizeof(int)); |
676 | } | | 674 | } |
677 | | | 675 | |
678 | mutex_destroy(&sc->sc_lock); | | 676 | mutex_destroy(&sc->sc_lock); |
679 | mutex_destroy(&sc->sc_intr_lock); | | 677 | mutex_destroy(&sc->sc_intr_lock); |
680 | | | 678 | |
681 | pool_cache_destroy(sc->sc_xferpool); | | 679 | pool_cache_destroy(sc->sc_xferpool); |
682 | | | 680 | |
683 | return rv; | | 681 | return rv; |
684 | } | | 682 | } |
685 | | | 683 | |
686 | int | | 684 | int |
687 | xhci_activate(device_t self, enum devact act) | | 685 | xhci_activate(device_t self, enum devact act) |
688 | { | | 686 | { |
689 | struct xhci_softc * const sc = device_private(self); | | 687 | struct xhci_softc * const sc = device_private(self); |
690 | | | 688 | |
691 | switch (act) { | | 689 | switch (act) { |
692 | case DVACT_DEACTIVATE: | | 690 | case DVACT_DEACTIVATE: |
693 | sc->sc_dying = true; | | 691 | sc->sc_dying = true; |
694 | return 0; | | 692 | return 0; |
695 | default: | | 693 | default: |
696 | return EOPNOTSUPP; | | 694 | return EOPNOTSUPP; |
697 | } | | 695 | } |
698 | } | | 696 | } |
699 | | | 697 | |
700 | bool | | 698 | bool |
701 | xhci_suspend(device_t dv, const pmf_qual_t *qual) | | 699 | xhci_suspend(device_t self, const pmf_qual_t *qual) |
702 | { | | 700 | { |
703 | return false; | | 701 | struct xhci_softc * const sc = device_private(self); |
| | | 702 | size_t i, j, bn; |
| | | 703 | int port; |
| | | 704 | uint32_t v; |
| | | 705 | |
| | | 706 | XHCIHIST_FUNC(); XHCIHIST_CALLED(); |
| | | 707 | |
| | | 708 | /* |
| | | 709 | * First, suspend all the ports: |
| | | 710 | * |
| | | 711 | * xHCI Requirements Specification 1.2, May 2019, Sec. 4.15: |
| | | 712 | * Suspend-Resume, pp. 276-283 |
| | | 713 | * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf#page=276 |
| | | 714 | */ |
| | | 715 | for (bn = 0; bn < 2; bn++) { |
| | | 716 | for (i = 1; i <= sc->sc_rhportcount[bn]; i++) { |
| | | 717 | /* 4.15.1: Port Suspend. */ |
| | | 718 | port = XHCI_PORTSC(xhci_rhport2ctlrport(sc, bn, i)); |
| | | 719 | |
| | | 720 | /* |
| | | 721 | * `System software places individual ports |
| | | 722 | * into suspend mode by writing a ``3'' into |
| | | 723 | * the appropriate PORTSC register Port Link |
| | | 724 | * State (PLS) field (refer to Section 5.4.8). |
| | | 725 | * Software should only set the PLS field to |
| | | 726 | * ``3'' when the port is in the Enabled |
| | | 727 | * state.' |
| | | 728 | * |
| | | 729 | * `Software should not attempt to suspend a |
| | | 730 | * port unless the port reports that it is in |
| | | 731 | * the enabled (PED = ``1''; PLS < ``3'') |
| | | 732 | * state (refer to Section 5.4.8 for more |
| | | 733 | * information about PED and PLS).' |
| | | 734 | */ |
| | | 735 | v = xhci_op_read_4(sc, port); |
| | | 736 | if (((v & XHCI_PS_PED) == 0) || |
| | | 737 | XHCI_PS_PLS_GET(v) >= XHCI_PS_PLS_U3) |
| | | 738 | continue; |
| | | 739 | v &= ~(XHCI_PS_PLS_MASK | XHCI_PS_CLEAR); |
| | | 740 | v |= XHCI_PS_LWS | XHCI_PS_PLS_SET(XHCI_PS_PLS_SETU3); |
| | | 741 | xhci_op_write_4(sc, port, v); |
| | | 742 | |
| | | 743 | /* |
| | | 744 | * `When the PLS field is written with U3 |
| | | 745 | * (``3''), the status of the PLS bit will not |
| | | 746 | * change to the target U state U3 until the |
| | | 747 | * suspend signaling has completed to the |
| | | 748 | * attached device (which may be as long as |
| | | 749 | * 10ms.).' |
| | | 750 | * |
| | | 751 | * `Software is required to wait for U3 |
| | | 752 | * transitions to complete before it puts the |
| | | 753 | * xHC into a low power state, and before |
| | | 754 | * resuming the port.' |
| | | 755 | * |
| | | 756 | * XXX Take advantage of the technique to |
| | | 757 | * reduce polling on host controllers that |
| | | 758 | * support the U3C capability. |
| | | 759 | */ |
| | | 760 | for (j = 0; j < XHCI_WAIT_PLS_U3; j++) { |
| | | 761 | v = xhci_op_read_4(sc, port); |
| | | 762 | if (XHCI_PS_PLS_GET(v) == XHCI_PS_PLS_U3) |
| | | 763 | break; |
| | | 764 | usb_delay_ms(&sc->sc_bus, 1); |
| | | 765 | } |
| | | 766 | if (j == XHCI_WAIT_PLS_U3) { |
| | | 767 | device_printf(self, |
| | | 768 | "suspend timeout on bus %zu port %zu\n", |
| | | 769 | bn, i); |
| | | 770 | return false; |
| | | 771 | } |
| | | 772 | } |
| | | 773 | } |
| | | 774 | |
| | | 775 | /* |
| | | 776 | * xHCI Requirements Specification 1.2, May 2019, Sec. 4.23.2: |
| | | 777 | * xHCI Power Management, p. 342 |
| | | 778 | * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf#page=342 |
| | | 779 | */ |
| | | 780 | |
| | | 781 | /* |
| | | 782 | * `1. Stop all USB activity by issuing Stop Endpoint Commands |
| | | 783 | * for Busy endpoints in the Running state. If the Force |
| | | 784 | * Save Context Capability (FSC = ``0'') is not supported, |
| | | 785 | * then Stop Endpoint Commands shall be issued for all Idle |
| | | 786 | * endpoints in the Running state as well. The Stop |
| | | 787 | * Endpoint Command causes the xHC to update the respective |
| | | 788 | * Endpoint or Stream Contexts in system memory, e.g. the |
| | | 789 | * TR Dequeue Pointer, DCS, etc. fields. Refer to |
| | | 790 | * Implementation Note "0".' |
| | | 791 | * |
| | | 792 | * XXX Not entirely sure if this is necessary for us; also it |
| | | 793 | * probably has to happen before suspending the ports. |
| | | 794 | */ |
| | | 795 | |
| | | 796 | /* |
| | | 797 | * `2. Ensure that the Command Ring is in the Stopped state |
| | | 798 | * (CRR = ``0'') or Idle (i.e. the Command Transfer Ring is |
| | | 799 | * empty), and all Command Completion Events associated |
| | | 800 | * with them have been received.' |
| | | 801 | * |
| | | 802 | * XXX |
| | | 803 | */ |
| | | 804 | |
| | | 805 | /* `3. Stop the controller by setting Run/Stop (R/S) = ``0''.' */ |
| | | 806 | xhci_op_write_4(sc, XHCI_USBCMD, |
| | | 807 | xhci_op_read_4(sc, XHCI_USBCMD) & ~XHCI_CMD_RS); |
| | | 808 | |
| | | 809 | /* |
| | | 810 | * `4. Read the Operational Runtime, and VTIO registers in the |
| | | 811 | * following order: USBCMD, DNCTRL, DCBAAP, CONFIG, ERSTSZ, |
| | | 812 | * ERSTBA, ERDP, IMAN, IMOD, and VTIO and save their |
| | | 813 | * state.' |
| | | 814 | * |
| | | 815 | * (We don't use VTIO here (XXX for now?).) |
| | | 816 | */ |
| | | 817 | sc->sc_regs.usbcmd = xhci_op_read_4(sc, XHCI_USBCMD); |
| | | 818 | sc->sc_regs.dnctrl = xhci_op_read_4(sc, XHCI_DNCTRL); |
| | | 819 | sc->sc_regs.dcbaap = xhci_op_read_8(sc, XHCI_DCBAAP); |
| | | 820 | sc->sc_regs.config = xhci_op_read_4(sc, XHCI_CONFIG); |
| | | 821 | sc->sc_regs.erstsz0 = xhci_rt_read_4(sc, XHCI_ERSTSZ(0)); |
| | | 822 | sc->sc_regs.erstba0 = xhci_rt_read_8(sc, XHCI_ERSTBA(0)); |
| | | 823 | sc->sc_regs.erdp0 = xhci_rt_read_8(sc, XHCI_ERDP(0)); |
| | | 824 | sc->sc_regs.iman0 = xhci_rt_read_4(sc, XHCI_IMAN(0)); |
| | | 825 | sc->sc_regs.imod0 = xhci_rt_read_4(sc, XHCI_IMOD(0)); |
| | | 826 | |
| | | 827 | /* |
| | | 828 | * `5. Set the Controller Save State (CSS) flag in the USBCMD |
| | | 829 | * register (5.4.1)...' |
| | | 830 | */ |
| | | 831 | xhci_op_write_4(sc, XHCI_USBCMD, |
| | | 832 | xhci_op_read_4(sc, XHCI_USBCMD) | XHCI_CMD_CSS); |
| | | 833 | |
| | | 834 | /* |
| | | 835 | * `...and wait for the Save State Status (SSS) flag in the |
| | | 836 | * USBSTS register (5.4.2) to transition to ``0''.' |
| | | 837 | */ |
| | | 838 | for (i = 0; i < XHCI_WAIT_SSS; i++) { |
| | | 839 | if ((xhci_op_read_4(sc, XHCI_USBSTS) & XHCI_STS_SSS) == 0) |
| | | 840 | break; |
| | | 841 | usb_delay_ms(&sc->sc_bus, 1); |
| | | 842 | } |
| | | 843 | if (i >= XHCI_WAIT_SSS) { |
| | | 844 | device_printf(self, "suspend timeout, USBSTS.SSS\n"); |
| | | 845 | /* |
| | | 846 | * Just optimistically go on and check SRE anyway -- |
| | | 847 | * what's the worst that could happen? |
| | | 848 | */ |
| | | 849 | } |
| | | 850 | |
| | | 851 | /* |
| | | 852 | * `Note: After a Save or Restore operation completes, the |
| | | 853 | * Save/Restore Error (SRE) flag in the USBSTS register should |
| | | 854 | * be checked to ensure that the operation completed |
| | | 855 | * successfully.' |
| | | 856 | */ |
| | | 857 | if (xhci_op_read_4(sc, XHCI_USBSTS) & XHCI_STS_SRE) { |
| | | 858 | device_printf(self, "suspend error, USBSTS.SRE\n"); |
| | | 859 | return false; |
| | | 860 | } |
| | | 861 | |
| | | 862 | return true; |
704 | } | | 863 | } |
705 | | | 864 | |
706 | bool | | 865 | bool |
707 | xhci_resume(device_t dv, const pmf_qual_t *qual) | | 866 | xhci_resume(device_t self, const pmf_qual_t *qual) |
708 | { | | 867 | { |
709 | return false; | | 868 | struct xhci_softc * const sc = device_private(self); |
| | | 869 | size_t i, j, bn, dci; |
| | | 870 | int port; |
| | | 871 | uint32_t v; |
| | | 872 | |
| | | 873 | XHCIHIST_FUNC(); XHCIHIST_CALLED(); |
| | | 874 | |
| | | 875 | /* |
| | | 876 | * xHCI Requirements Specification 1.2, May 2019, Sec. 4.23.2: |
| | | 877 | * xHCI Power Management, p. 343 |
| | | 878 | * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf#page=343 |
| | | 879 | */ |
| | | 880 | |
| | | 881 | /* |
| | | 882 | * `4. Restore the Operational Runtime, and VTIO registers with |
| | | 883 | * their previously saved state in the following order: |
| | | 884 | * DNCTRL, DCBAAP, CONFIG, ERSTSZ, ERSTBA, ERDP, IMAN, |
| | | 885 | * IMOD, and VTIO.' |
| | | 886 | * |
| | | 887 | * (We don't use VTIO here (for now?).) |
| | | 888 | */ |
| | | 889 | xhci_op_write_4(sc, XHCI_USBCMD, sc->sc_regs.usbcmd); |
| | | 890 | xhci_op_write_4(sc, XHCI_DNCTRL, sc->sc_regs.dnctrl); |
| | | 891 | xhci_op_write_8(sc, XHCI_DCBAAP, sc->sc_regs.dcbaap); |
| | | 892 | xhci_op_write_4(sc, XHCI_CONFIG, sc->sc_regs.config); |
| | | 893 | xhci_rt_write_4(sc, XHCI_ERSTSZ(0), sc->sc_regs.erstsz0); |
| | | 894 | xhci_rt_write_8(sc, XHCI_ERSTBA(0), sc->sc_regs.erstba0); |
| | | 895 | xhci_rt_write_8(sc, XHCI_ERDP(0), sc->sc_regs.erdp0); |
| | | 896 | xhci_rt_write_4(sc, XHCI_IMAN(0), sc->sc_regs.iman0); |
| | | 897 | xhci_rt_write_4(sc, XHCI_IMOD(0), sc->sc_regs.imod0); |
| | | 898 | |
| | | 899 | memset(&sc->sc_regs, 0, sizeof(sc->sc_regs)); /* paranoia */ |
| | | 900 | |
| | | 901 | /* |
| | | 902 | * `5. Set the Controller Restore State (CRS) flag in the |
| | | 903 | * USBCMD register (5.4.1) to ``1''...' |
| | | 904 | */ |
| | | 905 | xhci_op_write_4(sc, XHCI_USBCMD, |
| | | 906 | xhci_op_read_4(sc, XHCI_USBCMD) | XHCI_CMD_CRS); |
| | | 907 | |
| | | 908 | /* |
| | | 909 | * `...and wait for the Restore State Status (RSS) in the |
| | | 910 | * USBSTS register (5.4.2) to transition to ``0''.' |
| | | 911 | */ |
| | | 912 | for (i = 0; i < XHCI_WAIT_RSS; i++) { |
| | | 913 | if ((xhci_op_read_4(sc, XHCI_USBSTS) & XHCI_STS_RSS) == 0) |
| | | 914 | break; |
| | | 915 | usb_delay_ms(&sc->sc_bus, 1); |
| | | 916 | } |
| | | 917 | if (i >= XHCI_WAIT_RSS) { |
| | | 918 | device_printf(self, "suspend timeout, USBSTS.RSS\n"); |
| | | 919 | return false; |
| | | 920 | } |
| | | 921 | |
| | | 922 | /* |
| | | 923 | * `6. Reinitialize the Command Ring, i.e. so its Cycle bits |
| | | 924 | * are consistent with the RCS values to be written to the |
| | | 925 | * CRCR.' |
| | | 926 | * |
| | | 927 | * XXX Hope just zeroing it is good enough! |
| | | 928 | */ |
| | | 929 | xhci_host_dequeue(sc->sc_cr); |
| | | 930 | |
| | | 931 | /* |
| | | 932 | * `7. Write the CRCR with the address and RCS value of the |
| | | 933 | * reinitialized Command Ring. Note that this write will |
| | | 934 | * cause the Command Ring to restart at the address |
| | | 935 | * specified by the CRCR.' |
| | | 936 | */ |
| | | 937 | xhci_op_write_8(sc, XHCI_CRCR, xhci_ring_trbp(sc->sc_cr, 0) | |
| | | 938 | sc->sc_cr->xr_cs); |
| | | 939 | |
| | | 940 | /* |
| | | 941 | * `8. Enable the controller by setting Run/Stop (R/S) = |
| | | 942 | * ``1''.' |
| | | 943 | */ |
| | | 944 | xhci_op_write_4(sc, XHCI_USBCMD, |
| | | 945 | xhci_op_read_4(sc, XHCI_USBCMD) | XHCI_CMD_RS); |
| | | 946 | |
| | | 947 | /* |
| | | 948 | * `9. Software shall walk the USB topology and initialize each |
| | | 949 | * of the xHC PORTSC, PORTPMSC, and PORTLI registers, and |
| | | 950 | * external hub ports attached to USB devices.' |
| | | 951 | * |
| | | 952 | * This follows the procedure in 4.15 `Suspend-Resume', 4.15.2 |
| | | 953 | * `Port Resume', 4.15.2.1 `Host Initiated'. |
| | | 954 | * |
| | | 955 | * XXX We should maybe batch up initiating the state |
| | | 956 | * transitions, and then wait for them to complete all at once. |
| | | 957 | */ |
| | | 958 | for (bn = 0; bn < 2; bn++) { |
| | | 959 | for (i = 1; i <= sc->sc_rhportcount[bn]; i++) { |
| | | 960 | port = XHCI_PORTSC(xhci_rhport2ctlrport(sc, bn, i)); |
| | | 961 | |
| | | 962 | /* `When a port is in the U3 state: ...' */ |
| | | 963 | v = xhci_op_read_4(sc, port); |
| | | 964 | if (XHCI_PS_PLS_GET(v) != XHCI_PS_PLS_U3) |
| | | 965 | continue; |
| | | 966 | |
| | | 967 | /* |
| | | 968 | * `For a USB2 protocol port, software shall |
| | | 969 | * write a ``15'' (Resume) to the PLS field to |
| | | 970 | * initiate resume signaling. The port shall |
| | | 971 | * transition to the Resume substate and the |
| | | 972 | * xHC shall transmit the resume signaling |
| | | 973 | * within 1ms (T_URSM). Software shall ensure |
| | | 974 | * that resume is signaled for at least 20ms |
| | | 975 | * (T_DRSMDN). Software shall start timing |
| | | 976 | * T_DRSMDN from the write of ``15'' (Resume) |
| | | 977 | * to PLS.' |
| | | 978 | */ |
| | | 979 | if (bn == 1) { |
| | | 980 | KASSERT(sc->sc_bus2.ub_revision == USBREV_2_0); |
| | | 981 | v &= ~(XHCI_PS_PLS_MASK | XHCI_PS_CLEAR); |
| | | 982 | v |= XHCI_PS_LWS; |
| | | 983 | v |= XHCI_PS_PLS_SET(XHCI_PS_PLS_SETRESUME); |
| | | 984 | xhci_op_write_4(sc, port, v); |
| | | 985 | usb_delay_ms(&sc->sc_bus, 20); |
| | | 986 | } else { |
| | | 987 | KASSERT(sc->sc_bus.ub_revision > USBREV_2_0); |
| | | 988 | } |
| | | 989 | |
| | | 990 | /* |
| | | 991 | * `For a USB3 protocol port [and a USB2 |
| | | 992 | * protocol port after transitioning to |
| | | 993 | * Resume], software shall write a ``0'' (U0) |
| | | 994 | * to the PLS field...' |
| | | 995 | */ |
| | | 996 | v = xhci_op_read_4(sc, port); |
| | | 997 | v &= ~(XHCI_PS_PLS_MASK | XHCI_PS_CLEAR); |
| | | 998 | v |= XHCI_PS_LWS | XHCI_PS_PLS_SET(XHCI_PS_PLS_SETU0); |
| | | 999 | xhci_op_write_4(sc, port, v); |
| | | 1000 | |
| | | 1001 | for (j = 0; j < XHCI_WAIT_PLS_U0; j++) { |
| | | 1002 | v = xhci_op_read_4(sc, port); |
| | | 1003 | if (XHCI_PS_PLS_GET(v) == XHCI_PS_PLS_U0) |
| | | 1004 | break; |
| | | 1005 | usb_delay_ms(&sc->sc_bus, 1); |
| | | 1006 | } |
| | | 1007 | if (j == XHCI_WAIT_PLS_U0) { |
| | | 1008 | device_printf(self, |
| | | 1009 | "resume timeout on bus %zu port %zu\n", |
| | | 1010 | bn, i); |
| | | 1011 | return false; |
| | | 1012 | } |
| | | 1013 | } |
| | | 1014 | } |
| | | 1015 | |
| | | 1016 | /* |
| | | 1017 | * `10. Restart each of the previously Running endpoints by |
| | | 1018 | * ringing their doorbells.' |
| | | 1019 | */ |
| | | 1020 | for (i = 0; i < sc->sc_maxslots; i++) { |
| | | 1021 | struct xhci_slot *xs = &sc->sc_slots[i]; |
| | | 1022 | |
| | | 1023 | /* Skip if the slot is not in use. */ |
| | | 1024 | if (xs->xs_idx == 0) |
| | | 1025 | continue; |
| | | 1026 | |
| | | 1027 | for (dci = XHCI_DCI_SLOT; dci <= XHCI_MAX_DCI; dci++) { |
| | | 1028 | /* Skip if the endpoint is not Running. */ |
| | | 1029 | if (xhci_get_epstate(sc, xs, dci) != |
| | | 1030 | XHCI_EPSTATE_RUNNING) |
| | | 1031 | continue; |
| | | 1032 | |
| | | 1033 | /* Ring the doorbell. */ |
| | | 1034 | xhci_db_write_4(sc, XHCI_DOORBELL(xs->xs_idx), dci); |
| | | 1035 | } |
| | | 1036 | } |
| | | 1037 | |
| | | 1038 | /* |
| | | 1039 | * `Note: After a Save or Restore operation completes, the |
| | | 1040 | * Save/Restore Error (SRE) flag in the USBSTS register should |
| | | 1041 | * be checked to ensure that the operation completed |
| | | 1042 | * successfully.' |
| | | 1043 | */ |
| | | 1044 | if (xhci_op_read_4(sc, XHCI_USBSTS) & XHCI_STS_SRE) { |
| | | 1045 | device_printf(self, "resume error, USBSTS.SRE\n"); |
| | | 1046 | return false; |
| | | 1047 | } |
| | | 1048 | |
| | | 1049 | return true; |
710 | } | | 1050 | } |
711 | | | 1051 | |
712 | bool | | 1052 | bool |
713 | xhci_shutdown(device_t self, int flags) | | 1053 | xhci_shutdown(device_t self, int flags) |
714 | { | | 1054 | { |
715 | return false; | | 1055 | return false; |
716 | } | | 1056 | } |
717 | | | 1057 | |
718 | static int | | 1058 | static int |
719 | xhci_hc_reset(struct xhci_softc * const sc) | | 1059 | xhci_hc_reset(struct xhci_softc * const sc) |
720 | { | | 1060 | { |
721 | uint32_t usbcmd, usbsts; | | 1061 | uint32_t usbcmd, usbsts; |
722 | int i; | | 1062 | int i; |
723 | | | 1063 | |
724 | /* Check controller not ready */ | | 1064 | /* Check controller not ready */ |
725 | for (i = 0; i < XHCI_WAIT_CNR; i++) { | | 1065 | for (i = 0; i < XHCI_WAIT_CNR; i++) { |
726 | usbsts = xhci_op_read_4(sc, XHCI_USBSTS); | | 1066 | usbsts = xhci_op_read_4(sc, XHCI_USBSTS); |
727 | if ((usbsts & XHCI_STS_CNR) == 0) | | 1067 | if ((usbsts & XHCI_STS_CNR) == 0) |
728 | break; | | 1068 | break; |
729 | usb_delay_ms(&sc->sc_bus, 1); | | 1069 | usb_delay_ms(&sc->sc_bus, 1); |
730 | } | | 1070 | } |
731 | if (i >= XHCI_WAIT_CNR) { | | 1071 | if (i >= XHCI_WAIT_CNR) { |
732 | aprint_error_dev(sc->sc_dev, "controller not ready timeout\n"); | | 1072 | aprint_error_dev(sc->sc_dev, "controller not ready timeout\n"); |
733 | return EIO; | | 1073 | return EIO; |
734 | } | | 1074 | } |
735 | | | 1075 | |
736 | /* Halt controller */ | | 1076 | /* Halt controller */ |
737 | usbcmd = 0; | | 1077 | usbcmd = 0; |
738 | xhci_op_write_4(sc, XHCI_USBCMD, usbcmd); | | 1078 | xhci_op_write_4(sc, XHCI_USBCMD, usbcmd); |
739 | usb_delay_ms(&sc->sc_bus, 1); | | 1079 | usb_delay_ms(&sc->sc_bus, 1); |
740 | | | 1080 | |
741 | /* Reset controller */ | | 1081 | /* Reset controller */ |
742 | usbcmd = XHCI_CMD_HCRST; | | 1082 | usbcmd = XHCI_CMD_HCRST; |
743 | xhci_op_write_4(sc, XHCI_USBCMD, usbcmd); | | 1083 | xhci_op_write_4(sc, XHCI_USBCMD, usbcmd); |
744 | for (i = 0; i < XHCI_WAIT_HCRST; i++) { | | 1084 | for (i = 0; i < XHCI_WAIT_HCRST; i++) { |
745 | /* | | 1085 | /* |
746 | * Wait 1ms first. Existing Intel xHCI requies 1ms delay to | | 1086 | * Wait 1ms first. Existing Intel xHCI requies 1ms delay to |
747 | * prevent system hang (Errata). | | 1087 | * prevent system hang (Errata). |
748 | */ | | 1088 | */ |
749 | usb_delay_ms(&sc->sc_bus, 1); | | 1089 | usb_delay_ms(&sc->sc_bus, 1); |
750 | usbcmd = xhci_op_read_4(sc, XHCI_USBCMD); | | 1090 | usbcmd = xhci_op_read_4(sc, XHCI_USBCMD); |
751 | if ((usbcmd & XHCI_CMD_HCRST) == 0) | | 1091 | if ((usbcmd & XHCI_CMD_HCRST) == 0) |
752 | break; | | 1092 | break; |
753 | } | | 1093 | } |
754 | if (i >= XHCI_WAIT_HCRST) { | | 1094 | if (i >= XHCI_WAIT_HCRST) { |
755 | aprint_error_dev(sc->sc_dev, "host controller reset timeout\n"); | | 1095 | aprint_error_dev(sc->sc_dev, "host controller reset timeout\n"); |
756 | return EIO; | | 1096 | return EIO; |
757 | } | | 1097 | } |
758 | | | 1098 | |
759 | /* Check controller not ready */ | | 1099 | /* Check controller not ready */ |
760 | for (i = 0; i < XHCI_WAIT_CNR; i++) { | | 1100 | for (i = 0; i < XHCI_WAIT_CNR; i++) { |
761 | usbsts = xhci_op_read_4(sc, XHCI_USBSTS); | | 1101 | usbsts = xhci_op_read_4(sc, XHCI_USBSTS); |
762 | if ((usbsts & XHCI_STS_CNR) == 0) | | 1102 | if ((usbsts & XHCI_STS_CNR) == 0) |
763 | break; | | 1103 | break; |
764 | usb_delay_ms(&sc->sc_bus, 1); | | 1104 | usb_delay_ms(&sc->sc_bus, 1); |
765 | } | | 1105 | } |
766 | if (i >= XHCI_WAIT_CNR) { | | 1106 | if (i >= XHCI_WAIT_CNR) { |
767 | aprint_error_dev(sc->sc_dev, | | 1107 | aprint_error_dev(sc->sc_dev, |
768 | "controller not ready timeout after reset\n"); | | 1108 | "controller not ready timeout after reset\n"); |
769 | return EIO; | | 1109 | return EIO; |
770 | } | | 1110 | } |
771 | | | 1111 | |
772 | return 0; | | 1112 | return 0; |
773 | } | | 1113 | } |
774 | | | 1114 | |
775 | | | | |
776 | /* 7.2 xHCI Support Protocol Capability */ | | 1115 | /* 7.2 xHCI Support Protocol Capability */ |
777 | static void | | 1116 | static void |
778 | xhci_id_protocols(struct xhci_softc *sc, bus_size_t ecp) | | 1117 | xhci_id_protocols(struct xhci_softc *sc, bus_size_t ecp) |
779 | { | | 1118 | { |
780 | XHCIHIST_FUNC(); XHCIHIST_CALLED(); | | 1119 | XHCIHIST_FUNC(); XHCIHIST_CALLED(); |
781 | | | 1120 | |
782 | /* XXX Cache this lot */ | | 1121 | /* XXX Cache this lot */ |
783 | | | 1122 | |
784 | const uint32_t w0 = xhci_read_4(sc, ecp); | | 1123 | const uint32_t w0 = xhci_read_4(sc, ecp); |
785 | const uint32_t w4 = xhci_read_4(sc, ecp + 4); | | 1124 | const uint32_t w4 = xhci_read_4(sc, ecp + 4); |
786 | const uint32_t w8 = xhci_read_4(sc, ecp + 8); | | 1125 | const uint32_t w8 = xhci_read_4(sc, ecp + 8); |
787 | const uint32_t wc = xhci_read_4(sc, ecp + 0xc); | | 1126 | const uint32_t wc = xhci_read_4(sc, ecp + 0xc); |
788 | | | 1127 | |
789 | aprint_debug_dev(sc->sc_dev, | | 1128 | aprint_debug_dev(sc->sc_dev, |
790 | " SP: 0x%08x 0x%08x 0x%08x 0x%08x\n", w0, w4, w8, wc); | | 1129 | " SP: 0x%08x 0x%08x 0x%08x 0x%08x\n", w0, w4, w8, wc); |
791 | | | 1130 | |
792 | if (w4 != XHCI_XECP_USBID) | | 1131 | if (w4 != XHCI_XECP_USBID) |
793 | return; | | 1132 | return; |
794 | | | 1133 | |
795 | const int major = XHCI_XECP_SP_W0_MAJOR(w0); | | 1134 | const int major = XHCI_XECP_SP_W0_MAJOR(w0); |
796 | const int minor = XHCI_XECP_SP_W0_MINOR(w0); | | 1135 | const int minor = XHCI_XECP_SP_W0_MINOR(w0); |
797 | const uint8_t cpo = XHCI_XECP_SP_W8_CPO(w8); | | 1136 | const uint8_t cpo = XHCI_XECP_SP_W8_CPO(w8); |
798 | const uint8_t cpc = XHCI_XECP_SP_W8_CPC(w8); | | 1137 | const uint8_t cpc = XHCI_XECP_SP_W8_CPC(w8); |
799 | | | 1138 | |
800 | const uint16_t mm = __SHIFTOUT(w0, __BITS(31, 16)); | | 1139 | const uint16_t mm = __SHIFTOUT(w0, __BITS(31, 16)); |
801 | switch (mm) { | | 1140 | switch (mm) { |
802 | case 0x0200: | | 1141 | case 0x0200: |
803 | case 0x0300: | | 1142 | case 0x0300: |
804 | case 0x0301: | | 1143 | case 0x0301: |
805 | case 0x0310: | | 1144 | case 0x0310: |
806 | aprint_debug_dev(sc->sc_dev, " %s ports %d - %d\n", | | 1145 | aprint_debug_dev(sc->sc_dev, " %s ports %d - %d\n", |
807 | major == 3 ? "ss" : "hs", cpo, cpo + cpc -1); | | 1146 | major == 3 ? "ss" : "hs", cpo, cpo + cpc -1); |
808 | break; | | 1147 | break; |
809 | default: | | 1148 | default: |
810 | aprint_error_dev(sc->sc_dev, " unknown major/minor (%d/%d)\n", | | 1149 | aprint_error_dev(sc->sc_dev, " unknown major/minor (%d/%d)\n", |
811 | major, minor); | | 1150 | major, minor); |
812 | return; | | 1151 | return; |
813 | } | | 1152 | } |
814 | | | 1153 | |
815 | const size_t bus = (major == 3) ? 0 : 1; | | 1154 | const size_t bus = (major == 3) ? 0 : 1; |
816 | | | 1155 | |
817 | /* Index arrays with 0..n-1 where ports are numbered 1..n */ | | 1156 | /* Index arrays with 0..n-1 where ports are numbered 1..n */ |
818 | for (size_t cp = cpo - 1; cp < cpo + cpc - 1; cp++) { | | 1157 | for (size_t cp = cpo - 1; cp < cpo + cpc - 1; cp++) { |
819 | if (sc->sc_ctlrportmap[cp] != 0) { | | 1158 | if (sc->sc_ctlrportmap[cp] != 0) { |
820 | aprint_error_dev(sc->sc_dev, "controller port %zu " | | 1159 | aprint_error_dev(sc->sc_dev, "controller port %zu " |
821 | "already assigned", cp); | | 1160 | "already assigned", cp); |
822 | continue; | | 1161 | continue; |
823 | } | | 1162 | } |
824 | | | 1163 | |
825 | sc->sc_ctlrportbus[cp / NBBY] |= | | 1164 | sc->sc_ctlrportbus[cp / NBBY] |= |
826 | bus == 0 ? 0 : __BIT(cp % NBBY); | | 1165 | bus == 0 ? 0 : __BIT(cp % NBBY); |
827 | | | 1166 | |
828 | const size_t rhp = sc->sc_rhportcount[bus]++; | | 1167 | const size_t rhp = sc->sc_rhportcount[bus]++; |
829 | | | 1168 | |
830 | KASSERTMSG(sc->sc_rhportmap[bus][rhp] == 0, | | 1169 | KASSERTMSG(sc->sc_rhportmap[bus][rhp] == 0, |
831 | "bus %zu rhp %zu is %d", bus, rhp, | | 1170 | "bus %zu rhp %zu is %d", bus, rhp, |
832 | sc->sc_rhportmap[bus][rhp]); | | 1171 | sc->sc_rhportmap[bus][rhp]); |
833 | | | 1172 | |
834 | sc->sc_rhportmap[bus][rhp] = cp + 1; | | 1173 | sc->sc_rhportmap[bus][rhp] = cp + 1; |
835 | sc->sc_ctlrportmap[cp] = rhp + 1; | | 1174 | sc->sc_ctlrportmap[cp] = rhp + 1; |
836 | } | | 1175 | } |
837 | } | | 1176 | } |
838 | | | 1177 | |
839 | /* Process extended capabilities */ | | 1178 | /* Process extended capabilities */ |
840 | static void | | 1179 | static void |
841 | xhci_ecp(struct xhci_softc *sc) | | 1180 | xhci_ecp(struct xhci_softc *sc) |
842 | { | | 1181 | { |
843 | XHCIHIST_FUNC(); XHCIHIST_CALLED(); | | 1182 | XHCIHIST_FUNC(); XHCIHIST_CALLED(); |
844 | | | 1183 | |
845 | bus_size_t ecp = XHCI_HCC_XECP(sc->sc_hcc) * 4; | | 1184 | bus_size_t ecp = XHCI_HCC_XECP(sc->sc_hcc) * 4; |
846 | while (ecp != 0) { | | 1185 | while (ecp != 0) { |
847 | uint32_t ecr = xhci_read_4(sc, ecp); | | 1186 | uint32_t ecr = xhci_read_4(sc, ecp); |
848 | aprint_debug_dev(sc->sc_dev, "ECR: 0x%08x\n", ecr); | | 1187 | aprint_debug_dev(sc->sc_dev, "ECR: 0x%08x\n", ecr); |
849 | switch (XHCI_XECP_ID(ecr)) { | | 1188 | switch (XHCI_XECP_ID(ecr)) { |
850 | case XHCI_ID_PROTOCOLS: { | | 1189 | case XHCI_ID_PROTOCOLS: { |
851 | xhci_id_protocols(sc, ecp); | | 1190 | xhci_id_protocols(sc, ecp); |
852 | break; | | 1191 | break; |
853 | } | | 1192 | } |
854 | case XHCI_ID_USB_LEGACY: { | | 1193 | case XHCI_ID_USB_LEGACY: { |
855 | uint8_t bios_sem; | | 1194 | uint8_t bios_sem; |
856 | | | 1195 | |
857 | /* Take host controller ownership from BIOS */ | | 1196 | /* Take host controller ownership from BIOS */ |
858 | bios_sem = xhci_read_1(sc, ecp + XHCI_XECP_BIOS_SEM); | | 1197 | bios_sem = xhci_read_1(sc, ecp + XHCI_XECP_BIOS_SEM); |
859 | if (bios_sem) { | | 1198 | if (bios_sem) { |
860 | /* sets xHCI to be owned by OS */ | | 1199 | /* sets xHCI to be owned by OS */ |
861 | xhci_write_1(sc, ecp + XHCI_XECP_OS_SEM, 1); | | 1200 | xhci_write_1(sc, ecp + XHCI_XECP_OS_SEM, 1); |
862 | aprint_debug_dev(sc->sc_dev, | | 1201 | aprint_debug_dev(sc->sc_dev, |
863 | "waiting for BIOS to give up control\n"); | | 1202 | "waiting for BIOS to give up control\n"); |
864 | for (int i = 0; i < 5000; i++) { | | 1203 | for (int i = 0; i < 5000; i++) { |
865 | bios_sem = xhci_read_1(sc, ecp + | | 1204 | bios_sem = xhci_read_1(sc, ecp + |
866 | XHCI_XECP_BIOS_SEM); | | 1205 | XHCI_XECP_BIOS_SEM); |
867 | if (bios_sem == 0) | | 1206 | if (bios_sem == 0) |
868 | break; | | 1207 | break; |
869 | DELAY(1000); | | 1208 | DELAY(1000); |
870 | } | | 1209 | } |
871 | if (bios_sem) { | | 1210 | if (bios_sem) { |
872 | aprint_error_dev(sc->sc_dev, | | 1211 | aprint_error_dev(sc->sc_dev, |
873 | "timed out waiting for BIOS\n"); | | 1212 | "timed out waiting for BIOS\n"); |
874 | } | | 1213 | } |
875 | } | | 1214 | } |
876 | break; | | 1215 | break; |
877 | } | | 1216 | } |
878 | default: | | 1217 | default: |
879 | break; | | 1218 | break; |
880 | } | | 1219 | } |
881 | ecr = xhci_read_4(sc, ecp); | | 1220 | ecr = xhci_read_4(sc, ecp); |
882 | if (XHCI_XECP_NEXT(ecr) == 0) { | | 1221 | if (XHCI_XECP_NEXT(ecr) == 0) { |
883 | ecp = 0; | | 1222 | ecp = 0; |
884 | } else { | | 1223 | } else { |
885 | ecp += XHCI_XECP_NEXT(ecr) * 4; | | 1224 | ecp += XHCI_XECP_NEXT(ecr) * 4; |
886 | } | | 1225 | } |
887 | } | | 1226 | } |
888 | } | | 1227 | } |
889 | | | 1228 | |
890 | #define XHCI_HCCPREV1_BITS \ | | 1229 | #define XHCI_HCCPREV1_BITS \ |
891 | "\177\020" /* New bitmask */ \ | | 1230 | "\177\020" /* New bitmask */ \ |
892 | "f\020\020XECP\0" \ | | 1231 | "f\020\020XECP\0" \ |
893 | "f\014\4MAXPSA\0" \ | | 1232 | "f\014\4MAXPSA\0" \ |
894 | "b\013CFC\0" \ | | 1233 | "b\013CFC\0" \ |
895 | "b\012SEC\0" \ | | 1234 | "b\012SEC\0" \ |
896 | "b\011SBD\0" \ | | 1235 | "b\011SBD\0" \ |
897 | "b\010FSE\0" \ | | 1236 | "b\010FSE\0" \ |
898 | "b\7NSS\0" \ | | 1237 | "b\7NSS\0" \ |
899 | "b\6LTC\0" \ | | 1238 | "b\6LTC\0" \ |
900 | "b\5LHRC\0" \ | | 1239 | "b\5LHRC\0" \ |
901 | "b\4PIND\0" \ | | 1240 | "b\4PIND\0" \ |
902 | "b\3PPC\0" \ | | 1241 | "b\3PPC\0" \ |
903 | "b\2CZC\0" \ | | 1242 | "b\2CZC\0" \ |
904 | "b\1BNC\0" \ | | 1243 | "b\1BNC\0" \ |
905 | "b\0AC64\0" \ | | 1244 | "b\0AC64\0" \ |
906 | "\0" | | 1245 | "\0" |
907 | #define XHCI_HCCV1_x_BITS \ | | 1246 | #define XHCI_HCCV1_x_BITS \ |
908 | "\177\020" /* New bitmask */ \ | | 1247 | "\177\020" /* New bitmask */ \ |
909 | "f\020\020XECP\0" \ | | 1248 | "f\020\020XECP\0" \ |
910 | "f\014\4MAXPSA\0" \ | | 1249 | "f\014\4MAXPSA\0" \ |
911 | "b\013CFC\0" \ | | 1250 | "b\013CFC\0" \ |
912 | "b\012SEC\0" \ | | 1251 | "b\012SEC\0" \ |
913 | "b\011SPC\0" \ | | 1252 | "b\011SPC\0" \ |
914 | "b\010PAE\0" \ | | 1253 | "b\010PAE\0" \ |
915 | "b\7NSS\0" \ | | 1254 | "b\7NSS\0" \ |
916 | "b\6LTC\0" \ | | 1255 | "b\6LTC\0" \ |
917 | "b\5LHRC\0" \ | | 1256 | "b\5LHRC\0" \ |
918 | "b\4PIND\0" \ | | 1257 | "b\4PIND\0" \ |
919 | "b\3PPC\0" \ | | 1258 | "b\3PPC\0" \ |
920 | "b\2CSZ\0" \ | | 1259 | "b\2CSZ\0" \ |
921 | "b\1BNC\0" \ | | 1260 | "b\1BNC\0" \ |
922 | "b\0AC64\0" \ | | 1261 | "b\0AC64\0" \ |
923 | "\0" | | 1262 | "\0" |
924 | | | 1263 | |
925 | #define XHCI_HCC2_BITS \ | | 1264 | #define XHCI_HCC2_BITS \ |
926 | "\177\020" /* New bitmask */ \ | | 1265 | "\177\020" /* New bitmask */ \ |
927 | "b\7ETC_TSC\0" \ | | 1266 | "b\7ETC_TSC\0" \ |
928 | "b\6ETC\0" \ | | 1267 | "b\6ETC\0" \ |
929 | "b\5CIC\0" \ | | 1268 | "b\5CIC\0" \ |
930 | "b\4LEC\0" \ | | 1269 | "b\4LEC\0" \ |
931 | "b\3CTC\0" \ | | 1270 | "b\3CTC\0" \ |
932 | "b\2FSC\0" \ | | 1271 | "b\2FSC\0" \ |
933 | "b\1CMC\0" \ | | 1272 | "b\1CMC\0" \ |
934 | "b\0U3C\0" \ | | 1273 | "b\0U3C\0" \ |
935 | "\0" | | 1274 | "\0" |
936 | | | 1275 | |
937 | void | | 1276 | void |
938 | xhci_start(struct xhci_softc *sc) | | 1277 | xhci_start(struct xhci_softc *sc) |
939 | { | | 1278 | { |
940 | xhci_rt_write_4(sc, XHCI_IMAN(0), XHCI_IMAN_INTR_ENA); | | 1279 | xhci_rt_write_4(sc, XHCI_IMAN(0), XHCI_IMAN_INTR_ENA); |
941 | if ((sc->sc_quirks & XHCI_QUIRK_INTEL) != 0) | | 1280 | if ((sc->sc_quirks & XHCI_QUIRK_INTEL) != 0) |
942 | /* Intel xhci needs interrupt rate moderated. */ | | 1281 | /* Intel xhci needs interrupt rate moderated. */ |
943 | xhci_rt_write_4(sc, XHCI_IMOD(0), XHCI_IMOD_DEFAULT_LP); | | 1282 | xhci_rt_write_4(sc, XHCI_IMOD(0), XHCI_IMOD_DEFAULT_LP); |
944 | else | | 1283 | else |
945 | xhci_rt_write_4(sc, XHCI_IMOD(0), 0); | | 1284 | xhci_rt_write_4(sc, XHCI_IMOD(0), 0); |
946 | aprint_debug_dev(sc->sc_dev, "current IMOD %u\n", | | 1285 | aprint_debug_dev(sc->sc_dev, "current IMOD %u\n", |
947 | xhci_rt_read_4(sc, XHCI_IMOD(0))); | | 1286 | xhci_rt_read_4(sc, XHCI_IMOD(0))); |
948 | | | 1287 | |
949 | /* Go! */ | | 1288 | /* Go! */ |
950 | xhci_op_write_4(sc, XHCI_USBCMD, XHCI_CMD_INTE|XHCI_CMD_RS); | | 1289 | xhci_op_write_4(sc, XHCI_USBCMD, XHCI_CMD_INTE|XHCI_CMD_RS); |
951 | aprint_debug_dev(sc->sc_dev, "USBCMD 0x%08"PRIx32"\n", | | 1290 | aprint_debug_dev(sc->sc_dev, "USBCMD 0x%08"PRIx32"\n", |
952 | xhci_op_read_4(sc, XHCI_USBCMD)); | | 1291 | xhci_op_read_4(sc, XHCI_USBCMD)); |
953 | } | | 1292 | } |
954 | | | 1293 | |
955 | int | | 1294 | int |
956 | xhci_init(struct xhci_softc *sc) | | 1295 | xhci_init(struct xhci_softc *sc) |
957 | { | | 1296 | { |
958 | bus_size_t bsz; | | 1297 | bus_size_t bsz; |
959 | uint32_t hcs1, hcs2, hcs3, dboff, rtsoff; | | 1298 | uint32_t hcs1, hcs2, hcs3, dboff, rtsoff; |
960 | uint32_t pagesize, config; | | 1299 | uint32_t pagesize, config; |
961 | int i = 0; | | 1300 | int i = 0; |
962 | uint16_t hciversion; | | 1301 | uint16_t hciversion; |
963 | uint8_t caplength; | | 1302 | uint8_t caplength; |
964 | | | 1303 | |
965 | XHCIHIST_FUNC(); XHCIHIST_CALLED(); | | 1304 | XHCIHIST_FUNC(); XHCIHIST_CALLED(); |
966 | | | 1305 | |
967 | /* Set up the bus struct for the usb 3 and usb 2 buses */ | | 1306 | /* Set up the bus struct for the usb 3 and usb 2 buses */ |
968 | sc->sc_bus.ub_methods = &xhci_bus_methods; | | 1307 | sc->sc_bus.ub_methods = &xhci_bus_methods; |
969 | sc->sc_bus.ub_pipesize = sizeof(struct xhci_pipe); | | 1308 | sc->sc_bus.ub_pipesize = sizeof(struct xhci_pipe); |
970 | sc->sc_bus.ub_usedma = true; | | 1309 | sc->sc_bus.ub_usedma = true; |
971 | sc->sc_bus.ub_hcpriv = sc; | | 1310 | sc->sc_bus.ub_hcpriv = sc; |
972 | | | 1311 | |
973 | sc->sc_bus2.ub_methods = &xhci_bus_methods; | | 1312 | sc->sc_bus2.ub_methods = &xhci_bus_methods; |
974 | sc->sc_bus2.ub_pipesize = sizeof(struct xhci_pipe); | | 1313 | sc->sc_bus2.ub_pipesize = sizeof(struct xhci_pipe); |
975 | sc->sc_bus2.ub_revision = USBREV_2_0; | | 1314 | sc->sc_bus2.ub_revision = USBREV_2_0; |
976 | sc->sc_bus2.ub_usedma = true; | | 1315 | sc->sc_bus2.ub_usedma = true; |
977 | sc->sc_bus2.ub_hcpriv = sc; | | 1316 | sc->sc_bus2.ub_hcpriv = sc; |
978 | sc->sc_bus2.ub_dmatag = sc->sc_bus.ub_dmatag; | | 1317 | sc->sc_bus2.ub_dmatag = sc->sc_bus.ub_dmatag; |
979 | | | 1318 | |
980 | caplength = xhci_read_1(sc, XHCI_CAPLENGTH); | | 1319 | caplength = xhci_read_1(sc, XHCI_CAPLENGTH); |
981 | hciversion = xhci_read_2(sc, XHCI_HCIVERSION); | | 1320 | hciversion = xhci_read_2(sc, XHCI_HCIVERSION); |
982 | | | 1321 | |
983 | if (hciversion < XHCI_HCIVERSION_0_96 || | | 1322 | if (hciversion < XHCI_HCIVERSION_0_96 || |
984 | hciversion >= 0x0200) { | | 1323 | hciversion >= 0x0200) { |
985 | aprint_normal_dev(sc->sc_dev, | | 1324 | aprint_normal_dev(sc->sc_dev, |
986 | "xHCI version %x.%x not known to be supported\n", | | 1325 | "xHCI version %x.%x not known to be supported\n", |
987 | (hciversion >> 8) & 0xff, (hciversion >> 0) & 0xff); | | 1326 | (hciversion >> 8) & 0xff, (hciversion >> 0) & 0xff); |
988 | } else { | | 1327 | } else { |
989 | aprint_verbose_dev(sc->sc_dev, "xHCI version %x.%x\n", | | 1328 | aprint_verbose_dev(sc->sc_dev, "xHCI version %x.%x\n", |
990 | (hciversion >> 8) & 0xff, (hciversion >> 0) & 0xff); | | 1329 | (hciversion >> 8) & 0xff, (hciversion >> 0) & 0xff); |
991 | } | | 1330 | } |
992 | | | 1331 | |
993 | if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, 0, caplength, | | 1332 | if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, 0, caplength, |
994 | &sc->sc_cbh) != 0) { | | 1333 | &sc->sc_cbh) != 0) { |
995 | aprint_error_dev(sc->sc_dev, "capability subregion failure\n"); | | 1334 | aprint_error_dev(sc->sc_dev, "capability subregion failure\n"); |
996 | return ENOMEM; | | 1335 | return ENOMEM; |
997 | } | | 1336 | } |
998 | | | 1337 | |
999 | hcs1 = xhci_cap_read_4(sc, XHCI_HCSPARAMS1); | | 1338 | hcs1 = xhci_cap_read_4(sc, XHCI_HCSPARAMS1); |
1000 | sc->sc_maxslots = XHCI_HCS1_MAXSLOTS(hcs1); | | 1339 | sc->sc_maxslots = XHCI_HCS1_MAXSLOTS(hcs1); |
1001 | sc->sc_maxintrs = XHCI_HCS1_MAXINTRS(hcs1); | | 1340 | sc->sc_maxintrs = XHCI_HCS1_MAXINTRS(hcs1); |
1002 | sc->sc_maxports = XHCI_HCS1_MAXPORTS(hcs1); | | 1341 | sc->sc_maxports = XHCI_HCS1_MAXPORTS(hcs1); |
1003 | hcs2 = xhci_cap_read_4(sc, XHCI_HCSPARAMS2); | | 1342 | hcs2 = xhci_cap_read_4(sc, XHCI_HCSPARAMS2); |
1004 | hcs3 = xhci_cap_read_4(sc, XHCI_HCSPARAMS3); | | 1343 | hcs3 = xhci_cap_read_4(sc, XHCI_HCSPARAMS3); |
1005 | aprint_debug_dev(sc->sc_dev, | | 1344 | aprint_debug_dev(sc->sc_dev, |
1006 | "hcs1=%"PRIx32" hcs2=%"PRIx32" hcs3=%"PRIx32"\n", hcs1, hcs2, hcs3); | | 1345 | "hcs1=%"PRIx32" hcs2=%"PRIx32" hcs3=%"PRIx32"\n", hcs1, hcs2, hcs3); |
1007 | | | 1346 | |
1008 | sc->sc_hcc = xhci_cap_read_4(sc, XHCI_HCCPARAMS); | | 1347 | sc->sc_hcc = xhci_cap_read_4(sc, XHCI_HCCPARAMS); |
1009 | sc->sc_ctxsz = XHCI_HCC_CSZ(sc->sc_hcc) ? 64 : 32; | | 1348 | sc->sc_ctxsz = XHCI_HCC_CSZ(sc->sc_hcc) ? 64 : 32; |
1010 | | | 1349 | |
1011 | char sbuf[128]; | | 1350 | char sbuf[128]; |
1012 | if (hciversion < XHCI_HCIVERSION_1_0) | | 1351 | if (hciversion < XHCI_HCIVERSION_1_0) |
1013 | snprintb(sbuf, sizeof(sbuf), XHCI_HCCPREV1_BITS, sc->sc_hcc); | | 1352 | snprintb(sbuf, sizeof(sbuf), XHCI_HCCPREV1_BITS, sc->sc_hcc); |
1014 | else | | 1353 | else |
1015 | snprintb(sbuf, sizeof(sbuf), XHCI_HCCV1_x_BITS, sc->sc_hcc); | | 1354 | snprintb(sbuf, sizeof(sbuf), XHCI_HCCV1_x_BITS, sc->sc_hcc); |
1016 | aprint_debug_dev(sc->sc_dev, "hcc=%s\n", sbuf); | | 1355 | aprint_debug_dev(sc->sc_dev, "hcc=%s\n", sbuf); |
1017 | aprint_debug_dev(sc->sc_dev, "xECP %" __PRIxBITS "\n", | | 1356 | aprint_debug_dev(sc->sc_dev, "xECP %" __PRIxBITS "\n", |
1018 | XHCI_HCC_XECP(sc->sc_hcc) * 4); | | 1357 | XHCI_HCC_XECP(sc->sc_hcc) * 4); |
1019 | if (hciversion >= XHCI_HCIVERSION_1_1) { | | 1358 | if (hciversion >= XHCI_HCIVERSION_1_1) { |
1020 | sc->sc_hcc2 = xhci_cap_read_4(sc, XHCI_HCCPARAMS2); | | 1359 | sc->sc_hcc2 = xhci_cap_read_4(sc, XHCI_HCCPARAMS2); |
1021 | snprintb(sbuf, sizeof(sbuf), XHCI_HCC2_BITS, sc->sc_hcc2); | | 1360 | snprintb(sbuf, sizeof(sbuf), XHCI_HCC2_BITS, sc->sc_hcc2); |
1022 | aprint_debug_dev(sc->sc_dev, "hcc2=%s\n", sbuf); | | 1361 | aprint_debug_dev(sc->sc_dev, "hcc2=%s\n", sbuf); |
1023 | } | | 1362 | } |
1024 | | | 1363 | |
1025 | /* default all ports to bus 0, i.e. usb 3 */ | | 1364 | /* default all ports to bus 0, i.e. usb 3 */ |
1026 | sc->sc_ctlrportbus = kmem_zalloc( | | 1365 | sc->sc_ctlrportbus = kmem_zalloc( |
1027 | howmany(sc->sc_maxports * sizeof(uint8_t), NBBY), KM_SLEEP); | | 1366 | howmany(sc->sc_maxports * sizeof(uint8_t), NBBY), KM_SLEEP); |
1028 | sc->sc_ctlrportmap = kmem_zalloc(sc->sc_maxports * sizeof(int), KM_SLEEP); | | 1367 | sc->sc_ctlrportmap = kmem_zalloc(sc->sc_maxports * sizeof(int), KM_SLEEP); |
1029 | | | 1368 | |
1030 | /* controller port to bus roothub port map */ | | 1369 | /* controller port to bus roothub port map */ |
1031 | for (size_t j = 0; j < __arraycount(sc->sc_rhportmap); j++) { | | 1370 | for (size_t j = 0; j < __arraycount(sc->sc_rhportmap); j++) { |
1032 | sc->sc_rhportmap[j] = kmem_zalloc(sc->sc_maxports * sizeof(int), KM_SLEEP); | | 1371 | sc->sc_rhportmap[j] = kmem_zalloc(sc->sc_maxports * sizeof(int), KM_SLEEP); |
1033 | } | | 1372 | } |
1034 | | | 1373 | |
1035 | /* | | 1374 | /* |
1036 | * Process all Extended Capabilities | | 1375 | * Process all Extended Capabilities |
1037 | */ | | 1376 | */ |
1038 | xhci_ecp(sc); | | 1377 | xhci_ecp(sc); |
1039 | | | 1378 | |
1040 | bsz = XHCI_PORTSC(sc->sc_maxports); | | 1379 | bsz = XHCI_PORTSC(sc->sc_maxports); |
1041 | if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, caplength, bsz, | | 1380 | if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, caplength, bsz, |
1042 | &sc->sc_obh) != 0) { | | 1381 | &sc->sc_obh) != 0) { |
1043 | aprint_error_dev(sc->sc_dev, "operational subregion failure\n"); | | 1382 | aprint_error_dev(sc->sc_dev, "operational subregion failure\n"); |
1044 | return ENOMEM; | | 1383 | return ENOMEM; |
1045 | } | | 1384 | } |
1046 | | | 1385 | |
1047 | dboff = xhci_cap_read_4(sc, XHCI_DBOFF); | | 1386 | dboff = xhci_cap_read_4(sc, XHCI_DBOFF); |
1048 | if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, dboff, | | 1387 | if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, dboff, |
1049 | sc->sc_maxslots * 4, &sc->sc_dbh) != 0) { | | 1388 | sc->sc_maxslots * 4, &sc->sc_dbh) != 0) { |
1050 | aprint_error_dev(sc->sc_dev, "doorbell subregion failure\n"); | | 1389 | aprint_error_dev(sc->sc_dev, "doorbell subregion failure\n"); |
1051 | return ENOMEM; | | 1390 | return ENOMEM; |
1052 | } | | 1391 | } |
1053 | | | 1392 | |
1054 | rtsoff = xhci_cap_read_4(sc, XHCI_RTSOFF); | | 1393 | rtsoff = xhci_cap_read_4(sc, XHCI_RTSOFF); |
1055 | if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, rtsoff, | | 1394 | if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, rtsoff, |
1056 | sc->sc_maxintrs * 0x20, &sc->sc_rbh) != 0) { | | 1395 | sc->sc_maxintrs * 0x20, &sc->sc_rbh) != 0) { |
1057 | aprint_error_dev(sc->sc_dev, "runtime subregion failure\n"); | | 1396 | aprint_error_dev(sc->sc_dev, "runtime subregion failure\n"); |
1058 | return ENOMEM; | | 1397 | return ENOMEM; |
1059 | } | | 1398 | } |
1060 | | | 1399 | |
1061 | int rv; | | 1400 | int rv; |
1062 | rv = xhci_hc_reset(sc); | | 1401 | rv = xhci_hc_reset(sc); |
1063 | if (rv != 0) { | | 1402 | if (rv != 0) { |
1064 | return rv; | | 1403 | return rv; |
1065 | } | | 1404 | } |
1066 | | | 1405 | |
1067 | if (sc->sc_vendor_init) | | 1406 | if (sc->sc_vendor_init) |
1068 | sc->sc_vendor_init(sc); | | 1407 | sc->sc_vendor_init(sc); |
1069 | | | 1408 | |
1070 | pagesize = xhci_op_read_4(sc, XHCI_PAGESIZE); | | 1409 | pagesize = xhci_op_read_4(sc, XHCI_PAGESIZE); |
1071 | aprint_debug_dev(sc->sc_dev, "PAGESIZE 0x%08x\n", pagesize); | | 1410 | aprint_debug_dev(sc->sc_dev, "PAGESIZE 0x%08x\n", pagesize); |
1072 | pagesize = ffs(pagesize); | | 1411 | pagesize = ffs(pagesize); |
1073 | if (pagesize == 0) { | | 1412 | if (pagesize == 0) { |
1074 | aprint_error_dev(sc->sc_dev, "pagesize is 0\n"); | | 1413 | aprint_error_dev(sc->sc_dev, "pagesize is 0\n"); |
1075 | return EIO; | | 1414 | return EIO; |
1076 | } | | 1415 | } |
1077 | sc->sc_pgsz = 1 << (12 + (pagesize - 1)); | | 1416 | sc->sc_pgsz = 1 << (12 + (pagesize - 1)); |
1078 | aprint_debug_dev(sc->sc_dev, "sc_pgsz 0x%08x\n", (uint32_t)sc->sc_pgsz); | | 1417 | aprint_debug_dev(sc->sc_dev, "sc_pgsz 0x%08x\n", (uint32_t)sc->sc_pgsz); |
1079 | aprint_debug_dev(sc->sc_dev, "sc_maxslots 0x%08x\n", | | 1418 | aprint_debug_dev(sc->sc_dev, "sc_maxslots 0x%08x\n", |
1080 | (uint32_t)sc->sc_maxslots); | | 1419 | (uint32_t)sc->sc_maxslots); |
1081 | aprint_debug_dev(sc->sc_dev, "sc_maxports %d\n", sc->sc_maxports); | | 1420 | aprint_debug_dev(sc->sc_dev, "sc_maxports %d\n", sc->sc_maxports); |
1082 | | | 1421 | |
1083 | int err; | | 1422 | int err; |
1084 | sc->sc_maxspbuf = XHCI_HCS2_MAXSPBUF(hcs2); | | 1423 | sc->sc_maxspbuf = XHCI_HCS2_MAXSPBUF(hcs2); |
1085 | aprint_debug_dev(sc->sc_dev, "sc_maxspbuf %d\n", sc->sc_maxspbuf); | | 1424 | aprint_debug_dev(sc->sc_dev, "sc_maxspbuf %d\n", sc->sc_maxspbuf); |
1086 | if (sc->sc_maxspbuf != 0) { | | 1425 | if (sc->sc_maxspbuf != 0) { |
1087 | err = usb_allocmem(&sc->sc_bus, | | 1426 | err = usb_allocmem(&sc->sc_bus, |
1088 | sizeof(uint64_t) * sc->sc_maxspbuf, sizeof(uint64_t), | | 1427 | sizeof(uint64_t) * sc->sc_maxspbuf, sizeof(uint64_t), |
1089 | USBMALLOC_COHERENT | USBMALLOC_ZERO, | | 1428 | USBMALLOC_COHERENT | USBMALLOC_ZERO, |
1090 | &sc->sc_spbufarray_dma); | | 1429 | &sc->sc_spbufarray_dma); |
1091 | if (err) { | | 1430 | if (err) { |
1092 | aprint_error_dev(sc->sc_dev, | | 1431 | aprint_error_dev(sc->sc_dev, |
1093 | "spbufarray init fail, err %d\n", err); | | 1432 | "spbufarray init fail, err %d\n", err); |
1094 | return ENOMEM; | | 1433 | return ENOMEM; |
1095 | } | | 1434 | } |
1096 | | | 1435 | |
1097 | sc->sc_spbuf_dma = kmem_zalloc(sizeof(*sc->sc_spbuf_dma) * | | 1436 | sc->sc_spbuf_dma = kmem_zalloc(sizeof(*sc->sc_spbuf_dma) * |
1098 | sc->sc_maxspbuf, KM_SLEEP); | | 1437 | sc->sc_maxspbuf, KM_SLEEP); |
1099 | uint64_t *spbufarray = KERNADDR(&sc->sc_spbufarray_dma, 0); | | 1438 | uint64_t *spbufarray = KERNADDR(&sc->sc_spbufarray_dma, 0); |
1100 | for (i = 0; i < sc->sc_maxspbuf; i++) { | | 1439 | for (i = 0; i < sc->sc_maxspbuf; i++) { |
1101 | usb_dma_t * const dma = &sc->sc_spbuf_dma[i]; | | 1440 | usb_dma_t * const dma = &sc->sc_spbuf_dma[i]; |
1102 | /* allocate contexts */ | | 1441 | /* allocate contexts */ |
1103 | err = usb_allocmem(&sc->sc_bus, sc->sc_pgsz, | | 1442 | err = usb_allocmem(&sc->sc_bus, sc->sc_pgsz, |
1104 | sc->sc_pgsz, USBMALLOC_COHERENT | USBMALLOC_ZERO, | | 1443 | sc->sc_pgsz, USBMALLOC_COHERENT | USBMALLOC_ZERO, |
1105 | dma); | | 1444 | dma); |
1106 | if (err) { | | 1445 | if (err) { |
1107 | aprint_error_dev(sc->sc_dev, | | 1446 | aprint_error_dev(sc->sc_dev, |
1108 | "spbufarray_dma init fail, err %d\n", err); | | 1447 | "spbufarray_dma init fail, err %d\n", err); |
1109 | rv = ENOMEM; | | 1448 | rv = ENOMEM; |
1110 | goto bad1; | | 1449 | goto bad1; |
1111 | } | | 1450 | } |
1112 | spbufarray[i] = htole64(DMAADDR(dma, 0)); | | 1451 | spbufarray[i] = htole64(DMAADDR(dma, 0)); |
1113 | usb_syncmem(dma, 0, sc->sc_pgsz, | | 1452 | usb_syncmem(dma, 0, sc->sc_pgsz, |
1114 | BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); | | 1453 | BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); |
1115 | } | | 1454 | } |
1116 | | | 1455 | |
1117 | usb_syncmem(&sc->sc_spbufarray_dma, 0, | | 1456 | usb_syncmem(&sc->sc_spbufarray_dma, 0, |
1118 | sizeof(uint64_t) * sc->sc_maxspbuf, BUS_DMASYNC_PREWRITE); | | 1457 | sizeof(uint64_t) * sc->sc_maxspbuf, BUS_DMASYNC_PREWRITE); |
1119 | } | | 1458 | } |
1120 | | | 1459 | |
1121 | config = xhci_op_read_4(sc, XHCI_CONFIG); | | 1460 | config = xhci_op_read_4(sc, XHCI_CONFIG); |
1122 | config &= ~0xFF; | | 1461 | config &= ~0xFF; |
1123 | config |= sc->sc_maxslots & 0xFF; | | 1462 | config |= sc->sc_maxslots & 0xFF; |
1124 | xhci_op_write_4(sc, XHCI_CONFIG, config); | | 1463 | xhci_op_write_4(sc, XHCI_CONFIG, config); |
1125 | | | 1464 | |
1126 | err = xhci_ring_init(sc, &sc->sc_cr, XHCI_COMMAND_RING_TRBS, | | 1465 | err = xhci_ring_init(sc, &sc->sc_cr, XHCI_COMMAND_RING_TRBS, |
1127 | XHCI_COMMAND_RING_SEGMENTS_ALIGN); | | 1466 | XHCI_COMMAND_RING_SEGMENTS_ALIGN); |
1128 | if (err) { | | 1467 | if (err) { |
1129 | aprint_error_dev(sc->sc_dev, "command ring init fail, err %d\n", | | 1468 | aprint_error_dev(sc->sc_dev, "command ring init fail, err %d\n", |
1130 | err); | | 1469 | err); |
1131 | rv = ENOMEM; | | 1470 | rv = ENOMEM; |
1132 | goto bad1; | | 1471 | goto bad1; |
1133 | } | | 1472 | } |
1134 | | | 1473 | |
1135 | err = xhci_ring_init(sc, &sc->sc_er, XHCI_EVENT_RING_TRBS, | | 1474 | err = xhci_ring_init(sc, &sc->sc_er, XHCI_EVENT_RING_TRBS, |
1136 | XHCI_EVENT_RING_SEGMENTS_ALIGN); | | 1475 | XHCI_EVENT_RING_SEGMENTS_ALIGN); |
1137 | if (err) { | | 1476 | if (err) { |
1138 | aprint_error_dev(sc->sc_dev, "event ring init fail, err %d\n", | | 1477 | aprint_error_dev(sc->sc_dev, "event ring init fail, err %d\n", |
1139 | err); | | 1478 | err); |
1140 | rv = ENOMEM; | | 1479 | rv = ENOMEM; |
1141 | goto bad2; | | 1480 | goto bad2; |
1142 | } | | 1481 | } |
1143 | | | 1482 | |
1144 | usb_dma_t *dma; | | 1483 | usb_dma_t *dma; |
1145 | size_t size; | | 1484 | size_t size; |
1146 | size_t align; | | 1485 | size_t align; |
1147 | | | 1486 | |
1148 | dma = &sc->sc_eventst_dma; | | 1487 | dma = &sc->sc_eventst_dma; |
1149 | size = roundup2(XHCI_EVENT_RING_SEGMENTS * XHCI_ERSTE_SIZE, | | 1488 | size = roundup2(XHCI_EVENT_RING_SEGMENTS * XHCI_ERSTE_SIZE, |
1150 | XHCI_EVENT_RING_SEGMENT_TABLE_ALIGN); | | 1489 | XHCI_EVENT_RING_SEGMENT_TABLE_ALIGN); |
1151 | KASSERTMSG(size <= (512 * 1024), "eventst size %zu too large", size); | | 1490 | KASSERTMSG(size <= (512 * 1024), "eventst size %zu too large", size); |
1152 | align = XHCI_EVENT_RING_SEGMENT_TABLE_ALIGN; | | 1491 | align = XHCI_EVENT_RING_SEGMENT_TABLE_ALIGN; |
1153 | err = usb_allocmem(&sc->sc_bus, size, align, | | 1492 | err = usb_allocmem(&sc->sc_bus, size, align, |
1154 | USBMALLOC_COHERENT | USBMALLOC_ZERO, dma); | | 1493 | USBMALLOC_COHERENT | USBMALLOC_ZERO, dma); |
1155 | if (err) { | | 1494 | if (err) { |
1156 | aprint_error_dev(sc->sc_dev, "eventst init fail, err %d\n", | | 1495 | aprint_error_dev(sc->sc_dev, "eventst init fail, err %d\n", |
1157 | err); | | 1496 | err); |
1158 | rv = ENOMEM; | | 1497 | rv = ENOMEM; |
1159 | goto bad3; | | 1498 | goto bad3; |
1160 | } | | 1499 | } |
1161 | | | 1500 | |
1162 | aprint_debug_dev(sc->sc_dev, "eventst: 0x%016jx %p %zx\n", | | 1501 | aprint_debug_dev(sc->sc_dev, "eventst: 0x%016jx %p %zx\n", |
1163 | (uintmax_t)DMAADDR(&sc->sc_eventst_dma, 0), | | 1502 | (uintmax_t)DMAADDR(&sc->sc_eventst_dma, 0), |
1164 | KERNADDR(&sc->sc_eventst_dma, 0), | | 1503 | KERNADDR(&sc->sc_eventst_dma, 0), |
1165 | sc->sc_eventst_dma.udma_block->size); | | 1504 | sc->sc_eventst_dma.udma_block->size); |
1166 | | | 1505 | |
1167 | dma = &sc->sc_dcbaa_dma; | | 1506 | dma = &sc->sc_dcbaa_dma; |
1168 | size = (1 + sc->sc_maxslots) * sizeof(uint64_t); | | 1507 | size = (1 + sc->sc_maxslots) * sizeof(uint64_t); |
1169 | KASSERTMSG(size <= 2048, "dcbaa size %zu too large", size); | | 1508 | KASSERTMSG(size <= 2048, "dcbaa size %zu too large", size); |
1170 | align = XHCI_DEVICE_CONTEXT_BASE_ADDRESS_ARRAY_ALIGN; | | 1509 | align = XHCI_DEVICE_CONTEXT_BASE_ADDRESS_ARRAY_ALIGN; |
1171 | err = usb_allocmem(&sc->sc_bus, size, align, | | 1510 | err = usb_allocmem(&sc->sc_bus, size, align, |
1172 | USBMALLOC_COHERENT | USBMALLOC_ZERO, dma); | | 1511 | USBMALLOC_COHERENT | USBMALLOC_ZERO, dma); |
1173 | if (err) { | | 1512 | if (err) { |
1174 | aprint_error_dev(sc->sc_dev, "dcbaa init fail, err %d\n", err); | | 1513 | aprint_error_dev(sc->sc_dev, "dcbaa init fail, err %d\n", err); |
1175 | rv = ENOMEM; | | 1514 | rv = ENOMEM; |
1176 | goto bad4; | | 1515 | goto bad4; |
1177 | } | | 1516 | } |
1178 | aprint_debug_dev(sc->sc_dev, "dcbaa: 0x%016jx %p %zx\n", | | 1517 | aprint_debug_dev(sc->sc_dev, "dcbaa: 0x%016jx %p %zx\n", |
1179 | (uintmax_t)DMAADDR(&sc->sc_dcbaa_dma, 0), | | 1518 | (uintmax_t)DMAADDR(&sc->sc_dcbaa_dma, 0), |
1180 | KERNADDR(&sc->sc_dcbaa_dma, 0), | | 1519 | KERNADDR(&sc->sc_dcbaa_dma, 0), |
1181 | sc->sc_dcbaa_dma.udma_block->size); | | 1520 | sc->sc_dcbaa_dma.udma_block->size); |
1182 | | | 1521 | |
1183 | if (sc->sc_maxspbuf != 0) { | | 1522 | if (sc->sc_maxspbuf != 0) { |
1184 | /* | | 1523 | /* |
1185 | * DCBA entry 0 hold the scratchbuf array pointer. | | 1524 | * DCBA entry 0 hold the scratchbuf array pointer. |
1186 | */ | | 1525 | */ |
1187 | *(uint64_t *)KERNADDR(dma, 0) = | | 1526 | *(uint64_t *)KERNADDR(dma, 0) = |
1188 | htole64(DMAADDR(&sc->sc_spbufarray_dma, 0)); | | 1527 | htole64(DMAADDR(&sc->sc_spbufarray_dma, 0)); |
1189 | usb_syncmem(dma, 0, size, BUS_DMASYNC_PREWRITE); | | 1528 | usb_syncmem(dma, 0, size, BUS_DMASYNC_PREWRITE); |
1190 | } | | 1529 | } |
1191 | | | 1530 | |
1192 | sc->sc_slots = kmem_zalloc(sizeof(*sc->sc_slots) * sc->sc_maxslots, | | 1531 | sc->sc_slots = kmem_zalloc(sizeof(*sc->sc_slots) * sc->sc_maxslots, |
1193 | KM_SLEEP); | | 1532 | KM_SLEEP); |
1194 | if (sc->sc_slots == NULL) { | | 1533 | if (sc->sc_slots == NULL) { |
1195 | aprint_error_dev(sc->sc_dev, "slots init fail, err %d\n", err); | | 1534 | aprint_error_dev(sc->sc_dev, "slots init fail, err %d\n", err); |
1196 | rv = ENOMEM; | | 1535 | rv = ENOMEM; |
1197 | goto bad; | | 1536 | goto bad; |
1198 | } | | 1537 | } |
1199 | | | 1538 | |
1200 | sc->sc_xferpool = pool_cache_init(sizeof(struct xhci_xfer), 0, 0, 0, | | 1539 | sc->sc_xferpool = pool_cache_init(sizeof(struct xhci_xfer), 0, 0, 0, |
1201 | "xhcixfer", NULL, IPL_USB, NULL, NULL, NULL); | | 1540 | "xhcixfer", NULL, IPL_USB, NULL, NULL, NULL); |
1202 | if (sc->sc_xferpool == NULL) { | | 1541 | if (sc->sc_xferpool == NULL) { |
1203 | aprint_error_dev(sc->sc_dev, "pool_cache init fail, err %d\n", | | 1542 | aprint_error_dev(sc->sc_dev, "pool_cache init fail, err %d\n", |
1204 | err); | | 1543 | err); |
1205 | rv = ENOMEM; | | 1544 | rv = ENOMEM; |
1206 | goto bad; | | 1545 | goto bad; |
1207 | } | | 1546 | } |
1208 | | | 1547 | |
1209 | cv_init(&sc->sc_command_cv, "xhcicmd"); | | 1548 | cv_init(&sc->sc_command_cv, "xhcicmd"); |
1210 | cv_init(&sc->sc_cmdbusy_cv, "xhcicmdq"); | | 1549 | cv_init(&sc->sc_cmdbusy_cv, "xhcicmdq"); |
1211 | mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB); | | 1550 | mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB); |
1212 | mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_USB); | | 1551 | mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_USB); |
1213 | | | 1552 | |
1214 | struct xhci_erste *erst; | | 1553 | struct xhci_erste *erst; |
1215 | erst = KERNADDR(&sc->sc_eventst_dma, 0); | | 1554 | erst = KERNADDR(&sc->sc_eventst_dma, 0); |
1216 | erst[0].erste_0 = htole64(xhci_ring_trbp(sc->sc_er, 0)); | | 1555 | erst[0].erste_0 = htole64(xhci_ring_trbp(sc->sc_er, 0)); |
1217 | erst[0].erste_2 = htole32(sc->sc_er->xr_ntrb); | | 1556 | erst[0].erste_2 = htole32(sc->sc_er->xr_ntrb); |
1218 | erst[0].erste_3 = htole32(0); | | 1557 | erst[0].erste_3 = htole32(0); |
1219 | usb_syncmem(&sc->sc_eventst_dma, 0, | | 1558 | usb_syncmem(&sc->sc_eventst_dma, 0, |
1220 | XHCI_ERSTE_SIZE * XHCI_EVENT_RING_SEGMENTS, BUS_DMASYNC_PREWRITE); | | 1559 | XHCI_ERSTE_SIZE * XHCI_EVENT_RING_SEGMENTS, BUS_DMASYNC_PREWRITE); |
1221 | | | 1560 | |
1222 | xhci_rt_write_4(sc, XHCI_ERSTSZ(0), XHCI_EVENT_RING_SEGMENTS); | | 1561 | xhci_rt_write_4(sc, XHCI_ERSTSZ(0), XHCI_EVENT_RING_SEGMENTS); |
1223 | xhci_rt_write_8(sc, XHCI_ERSTBA(0), DMAADDR(&sc->sc_eventst_dma, 0)); | | 1562 | xhci_rt_write_8(sc, XHCI_ERSTBA(0), DMAADDR(&sc->sc_eventst_dma, 0)); |
1224 | xhci_rt_write_8(sc, XHCI_ERDP(0), xhci_ring_trbp(sc->sc_er, 0) | | | 1563 | xhci_rt_write_8(sc, XHCI_ERDP(0), xhci_ring_trbp(sc->sc_er, 0) | |
1225 | XHCI_ERDP_BUSY); | | 1564 | XHCI_ERDP_BUSY); |
1226 | | | 1565 | |
1227 | xhci_op_write_8(sc, XHCI_DCBAAP, DMAADDR(&sc->sc_dcbaa_dma, 0)); | | 1566 | xhci_op_write_8(sc, XHCI_DCBAAP, DMAADDR(&sc->sc_dcbaa_dma, 0)); |
1228 | xhci_op_write_8(sc, XHCI_CRCR, xhci_ring_trbp(sc->sc_cr, 0) | | | 1567 | xhci_op_write_8(sc, XHCI_CRCR, xhci_ring_trbp(sc->sc_cr, 0) | |
1229 | sc->sc_cr->xr_cs); | | 1568 | sc->sc_cr->xr_cs); |
1230 | | | 1569 | |
1231 | xhci_barrier(sc, BUS_SPACE_BARRIER_WRITE); | | 1570 | xhci_barrier(sc, BUS_SPACE_BARRIER_WRITE); |
1232 | | | 1571 | |
1233 | HEXDUMP("eventst", KERNADDR(&sc->sc_eventst_dma, 0), | | 1572 | HEXDUMP("eventst", KERNADDR(&sc->sc_eventst_dma, 0), |
1234 | XHCI_ERSTE_SIZE * XHCI_EVENT_RING_SEGMENTS); | | 1573 | XHCI_ERSTE_SIZE * XHCI_EVENT_RING_SEGMENTS); |
1235 | | | 1574 | |
1236 | if ((sc->sc_quirks & XHCI_DEFERRED_START) == 0) | | 1575 | if ((sc->sc_quirks & XHCI_DEFERRED_START) == 0) |
1237 | xhci_start(sc); | | 1576 | xhci_start(sc); |
1238 | | | 1577 | |
1239 | return 0; | | 1578 | return 0; |
1240 | | | 1579 | |
1241 | bad: | | 1580 | bad: |
1242 | if (sc->sc_xferpool) { | | 1581 | if (sc->sc_xferpool) { |
1243 | pool_cache_destroy(sc->sc_xferpool); | | 1582 | pool_cache_destroy(sc->sc_xferpool); |
1244 | sc->sc_xferpool = NULL; | | 1583 | sc->sc_xferpool = NULL; |
1245 | } | | 1584 | } |
1246 | | | 1585 | |
1247 | if (sc->sc_slots) { | | 1586 | if (sc->sc_slots) { |
1248 | kmem_free(sc->sc_slots, sizeof(*sc->sc_slots) * | | 1587 | kmem_free(sc->sc_slots, sizeof(*sc->sc_slots) * |
1249 | sc->sc_maxslots); | | 1588 | sc->sc_maxslots); |
1250 | sc->sc_slots = NULL; | | 1589 | sc->sc_slots = NULL; |
1251 | } | | 1590 | } |
1252 | | | 1591 | |
1253 | usb_freemem(&sc->sc_bus, &sc->sc_dcbaa_dma); | | 1592 | usb_freemem(&sc->sc_bus, &sc->sc_dcbaa_dma); |
1254 | bad4: | | 1593 | bad4: |
1255 | usb_freemem(&sc->sc_bus, &sc->sc_eventst_dma); | | 1594 | usb_freemem(&sc->sc_bus, &sc->sc_eventst_dma); |
1256 | bad3: | | 1595 | bad3: |
1257 | xhci_ring_free(sc, &sc->sc_er); | | 1596 | xhci_ring_free(sc, &sc->sc_er); |
1258 | bad2: | | 1597 | bad2: |
1259 | xhci_ring_free(sc, &sc->sc_cr); | | 1598 | xhci_ring_free(sc, &sc->sc_cr); |
1260 | i = sc->sc_maxspbuf; | | 1599 | i = sc->sc_maxspbuf; |
1261 | bad1: | | 1600 | bad1: |
1262 | for (int j = 0; j < i; j++) | | 1601 | for (int j = 0; j < i; j++) |
1263 | usb_freemem(&sc->sc_bus, &sc->sc_spbuf_dma[j]); | | 1602 | usb_freemem(&sc->sc_bus, &sc->sc_spbuf_dma[j]); |
1264 | usb_freemem(&sc->sc_bus, &sc->sc_spbufarray_dma); | | 1603 | usb_freemem(&sc->sc_bus, &sc->sc_spbufarray_dma); |
1265 | | | 1604 | |
1266 | return rv; | | 1605 | return rv; |
1267 | } | | 1606 | } |
1268 | | | 1607 | |
1269 | static inline bool | | 1608 | static inline bool |
1270 | xhci_polling_p(struct xhci_softc * const sc) | | 1609 | xhci_polling_p(struct xhci_softc * const sc) |
1271 | { | | 1610 | { |
1272 | return sc->sc_bus.ub_usepolling || sc->sc_bus2.ub_usepolling; | | 1611 | return sc->sc_bus.ub_usepolling || sc->sc_bus2.ub_usepolling; |
1273 | } | | 1612 | } |
1274 | | | 1613 | |
1275 | int | | 1614 | int |
1276 | xhci_intr(void *v) | | 1615 | xhci_intr(void *v) |
1277 | { | | 1616 | { |
1278 | struct xhci_softc * const sc = v; | | 1617 | struct xhci_softc * const sc = v; |
1279 | int ret = 0; | | 1618 | int ret = 0; |
1280 | | | 1619 | |
1281 | XHCIHIST_FUNC(); XHCIHIST_CALLED(); | | 1620 | XHCIHIST_FUNC(); XHCIHIST_CALLED(); |
1282 | | | 1621 | |
1283 | if (sc == NULL) | | 1622 | if (sc == NULL) |
1284 | return 0; | | 1623 | return 0; |
1285 | | | 1624 | |
1286 | mutex_spin_enter(&sc->sc_intr_lock); | | 1625 | mutex_spin_enter(&sc->sc_intr_lock); |
1287 | | | 1626 | |
1288 | if (sc->sc_dying || !device_has_power(sc->sc_dev)) | | 1627 | if (sc->sc_dying || !device_has_power(sc->sc_dev)) |
1289 | goto done; | | 1628 | goto done; |
1290 | | | 1629 | |
1291 | /* If we get an interrupt while polling, then just ignore it. */ | | 1630 | /* If we get an interrupt while polling, then just ignore it. */ |
1292 | if (xhci_polling_p(sc)) { | | 1631 | if (xhci_polling_p(sc)) { |
1293 | #ifdef DIAGNOSTIC | | 1632 | #ifdef DIAGNOSTIC |
1294 | DPRINTFN(16, "ignored interrupt while polling", 0, 0, 0, 0); | | 1633 | DPRINTFN(16, "ignored interrupt while polling", 0, 0, 0, 0); |
1295 | #endif | | 1634 | #endif |
1296 | goto done; | | 1635 | goto done; |
1297 | } | | 1636 | } |
1298 | | | 1637 | |
1299 | ret = xhci_intr1(sc); | | 1638 | ret = xhci_intr1(sc); |
1300 | if (ret) { | | 1639 | if (ret) { |
1301 | KASSERT(sc->sc_child || sc->sc_child2); | | 1640 | KASSERT(sc->sc_child || sc->sc_child2); |
1302 | | | 1641 | |
1303 | /* | | 1642 | /* |
1304 | * One of child busses could be already detached. It doesn't | | 1643 | * One of child busses could be already detached. It doesn't |
1305 | * matter on which of the two the softintr is scheduled. | | 1644 | * matter on which of the two the softintr is scheduled. |
1306 | */ | | 1645 | */ |
1307 | if (sc->sc_child) | | 1646 | if (sc->sc_child) |
1308 | usb_schedsoftintr(&sc->sc_bus); | | 1647 | usb_schedsoftintr(&sc->sc_bus); |
1309 | else | | 1648 | else |
1310 | usb_schedsoftintr(&sc->sc_bus2); | | 1649 | usb_schedsoftintr(&sc->sc_bus2); |
1311 | } | | 1650 | } |
1312 | done: | | 1651 | done: |
1313 | mutex_spin_exit(&sc->sc_intr_lock); | | 1652 | mutex_spin_exit(&sc->sc_intr_lock); |
1314 | return ret; | | 1653 | return ret; |
1315 | } | | 1654 | } |
1316 | | | 1655 | |
1317 | int | | 1656 | int |
1318 | xhci_intr1(struct xhci_softc * const sc) | | 1657 | xhci_intr1(struct xhci_softc * const sc) |
1319 | { | | 1658 | { |
1320 | uint32_t usbsts; | | 1659 | uint32_t usbsts; |
1321 | uint32_t iman; | | 1660 | uint32_t iman; |
1322 | | | 1661 | |
1323 | XHCIHIST_FUNC(); | | 1662 | XHCIHIST_FUNC(); |
1324 | | | 1663 | |
1325 | usbsts = xhci_op_read_4(sc, XHCI_USBSTS); | | 1664 | usbsts = xhci_op_read_4(sc, XHCI_USBSTS); |
1326 | XHCIHIST_CALLARGS("USBSTS 0x%08jx", usbsts, 0, 0, 0); | | 1665 | XHCIHIST_CALLARGS("USBSTS 0x%08jx", usbsts, 0, 0, 0); |
1327 | if ((usbsts & (XHCI_STS_HSE | XHCI_STS_EINT | XHCI_STS_PCD | | | 1666 | if ((usbsts & (XHCI_STS_HSE | XHCI_STS_EINT | XHCI_STS_PCD | |
1328 | XHCI_STS_HCE)) == 0) { | | 1667 | XHCI_STS_HCE)) == 0) { |
1329 | DPRINTFN(16, "ignored intr not for %jd", | | 1668 | DPRINTFN(16, "ignored intr not for %jd", |
1330 | device_unit(sc->sc_dev), 0, 0, 0); | | 1669 | device_unit(sc->sc_dev), 0, 0, 0); |
1331 | return 0; | | 1670 | return 0; |
1332 | } | | 1671 | } |
1333 | | | 1672 | |
1334 | /* | | 1673 | /* |
1335 | * Clear EINT and other transient flags, to not misenterpret | | 1674 | * Clear EINT and other transient flags, to not misenterpret |
1336 | * next shared interrupt. Also, to avoid race, EINT must be cleared | | 1675 | * next shared interrupt. Also, to avoid race, EINT must be cleared |
1337 | * before XHCI_IMAN_INTR_PEND is cleared. | | 1676 | * before XHCI_IMAN_INTR_PEND is cleared. |
1338 | */ | | 1677 | */ |
1339 | xhci_op_write_4(sc, XHCI_USBSTS, usbsts & XHCI_STS_RSVDP0); | | 1678 | xhci_op_write_4(sc, XHCI_USBSTS, usbsts & XHCI_STS_RSVDP0); |
1340 | | | 1679 | |
1341 | #ifdef XHCI_DEBUG | | 1680 | #ifdef XHCI_DEBUG |
1342 | usbsts = xhci_op_read_4(sc, XHCI_USBSTS); | | 1681 | usbsts = xhci_op_read_4(sc, XHCI_USBSTS); |
1343 | DPRINTFN(16, "USBSTS 0x%08jx", usbsts, 0, 0, 0); | | 1682 | DPRINTFN(16, "USBSTS 0x%08jx", usbsts, 0, 0, 0); |
1344 | #endif | | 1683 | #endif |
1345 | | | 1684 | |
1346 | iman = xhci_rt_read_4(sc, XHCI_IMAN(0)); | | 1685 | iman = xhci_rt_read_4(sc, XHCI_IMAN(0)); |
1347 | DPRINTFN(16, "IMAN0 0x%08jx", iman, 0, 0, 0); | | 1686 | DPRINTFN(16, "IMAN0 0x%08jx", iman, 0, 0, 0); |
1348 | iman |= XHCI_IMAN_INTR_PEND; | | 1687 | iman |= XHCI_IMAN_INTR_PEND; |
1349 | xhci_rt_write_4(sc, XHCI_IMAN(0), iman); | | 1688 | xhci_rt_write_4(sc, XHCI_IMAN(0), iman); |
1350 | | | 1689 | |
1351 | #ifdef XHCI_DEBUG | | 1690 | #ifdef XHCI_DEBUG |
1352 | iman = xhci_rt_read_4(sc, XHCI_IMAN(0)); | | 1691 | iman = xhci_rt_read_4(sc, XHCI_IMAN(0)); |
1353 | DPRINTFN(16, "IMAN0 0x%08jx", iman, 0, 0, 0); | | 1692 | DPRINTFN(16, "IMAN0 0x%08jx", iman, 0, 0, 0); |
1354 | usbsts = xhci_op_read_4(sc, XHCI_USBSTS); | | 1693 | usbsts = xhci_op_read_4(sc, XHCI_USBSTS); |
1355 | DPRINTFN(16, "USBSTS 0x%08jx", usbsts, 0, 0, 0); | | 1694 | DPRINTFN(16, "USBSTS 0x%08jx", usbsts, 0, 0, 0); |
1356 | #endif | | 1695 | #endif |
1357 | | | 1696 | |
1358 | return 1; | | 1697 | return 1; |
1359 | } | | 1698 | } |
1360 | | | 1699 | |
1361 | /* | | 1700 | /* |
1362 | * 3 port speed types used in USB stack | | 1701 | * 3 port speed types used in USB stack |
1363 | * | | 1702 | * |
1364 | * usbdi speed | | 1703 | * usbdi speed |
1365 | * definition: USB_SPEED_* in usb.h | | 1704 | * definition: USB_SPEED_* in usb.h |
1366 | * They are used in struct usbd_device in USB stack. | | 1705 | * They are used in struct usbd_device in USB stack. |
1367 | * ioctl interface uses these values too. | | 1706 | * ioctl interface uses these values too. |
1368 | * port_status speed | | 1707 | * port_status speed |
1369 | * definition: UPS_*_SPEED in usb.h | | 1708 | * definition: UPS_*_SPEED in usb.h |
1370 | * They are used in usb_port_status_t and valid only for USB 2.0. | | 1709 | * They are used in usb_port_status_t and valid only for USB 2.0. |
1371 | * Speed value is always 0 for Super Speed or more, and dwExtPortStatus | | 1710 | * Speed value is always 0 for Super Speed or more, and dwExtPortStatus |
1372 | * of usb_port_status_ext_t indicates port speed. | | 1711 | * of usb_port_status_ext_t indicates port speed. |
1373 | * Note that some 3.0 values overlap with 2.0 values. | | 1712 | * Note that some 3.0 values overlap with 2.0 values. |
1374 | * (e.g. 0x200 means UPS_POER_POWER_SS in SS and | | 1713 | * (e.g. 0x200 means UPS_POER_POWER_SS in SS and |
1375 | * means UPS_LOW_SPEED in HS.) | | 1714 | * means UPS_LOW_SPEED in HS.) |
1376 | * port status returned from hub also uses these values. | | 1715 | * port status returned from hub also uses these values. |
1377 | * On NetBSD UPS_OTHER_SPEED indicates port speed is super speed | | 1716 | * On NetBSD UPS_OTHER_SPEED indicates port speed is super speed |
1378 | * or more. | | 1717 | * or more. |
1379 | * xspeed: | | 1718 | * xspeed: |
1380 | * definition: Protocol Speed ID (PSI) (xHCI 1.1 7.2.1) | | 1719 | * definition: Protocol Speed ID (PSI) (xHCI 1.1 7.2.1) |
1381 | * They are used in only slot context and PORTSC reg of xhci. | | 1720 | * They are used in only slot context and PORTSC reg of xhci. |
1382 | * The difference between usbdi speed and xspeed is | | 1721 | * The difference between usbdi speed and xspeed is |
1383 | * that FS and LS values are swapped. | | 1722 | * that FS and LS values are swapped. |
1384 | */ | | 1723 | */ |
1385 | | | 1724 | |
1386 | /* convert usbdi speed to xspeed */ | | 1725 | /* convert usbdi speed to xspeed */ |
1387 | static int | | 1726 | static int |
1388 | xhci_speed2xspeed(int speed) | | 1727 | xhci_speed2xspeed(int speed) |
1389 | { | | 1728 | { |
1390 | switch (speed) { | | 1729 | switch (speed) { |
1391 | case USB_SPEED_LOW: return 2; | | 1730 | case USB_SPEED_LOW: return 2; |
1392 | case USB_SPEED_FULL: return 1; | | 1731 | case USB_SPEED_FULL: return 1; |
1393 | default: return speed; | | 1732 | default: return speed; |
1394 | } | | 1733 | } |
1395 | } | | 1734 | } |
1396 | | | 1735 | |
1397 | #if 0 | | 1736 | #if 0 |
1398 | /* convert xspeed to usbdi speed */ | | 1737 | /* convert xspeed to usbdi speed */ |
1399 | static int | | 1738 | static int |
1400 | xhci_xspeed2speed(int xspeed) | | 1739 | xhci_xspeed2speed(int xspeed) |
1401 | { | | 1740 | { |
1402 | switch (xspeed) { | | 1741 | switch (xspeed) { |
1403 | case 1: return USB_SPEED_FULL; | | 1742 | case 1: return USB_SPEED_FULL; |
1404 | case 2: return USB_SPEED_LOW; | | 1743 | case 2: return USB_SPEED_LOW; |
1405 | default: return xspeed; | | 1744 | default: return xspeed; |
1406 | } | | 1745 | } |
1407 | } | | 1746 | } |
1408 | #endif | | 1747 | #endif |
1409 | | | 1748 | |
1410 | /* convert xspeed to port status speed */ | | 1749 | /* convert xspeed to port status speed */ |
1411 | static int | | 1750 | static int |
1412 | xhci_xspeed2psspeed(int xspeed) | | 1751 | xhci_xspeed2psspeed(int xspeed) |
1413 | { | | 1752 | { |
1414 | switch (xspeed) { | | 1753 | switch (xspeed) { |
1415 | case 0: return 0; | | 1754 | case 0: return 0; |
1416 | case 1: return UPS_FULL_SPEED; | | 1755 | case 1: return UPS_FULL_SPEED; |
1417 | case 2: return UPS_LOW_SPEED; | | 1756 | case 2: return UPS_LOW_SPEED; |
1418 | case 3: return UPS_HIGH_SPEED; | | 1757 | case 3: return UPS_HIGH_SPEED; |
1419 | default: return UPS_OTHER_SPEED; | | 1758 | default: return UPS_OTHER_SPEED; |
1420 | } | | 1759 | } |
1421 | } | | 1760 | } |
1422 | | | 1761 | |
1423 | /* | | 1762 | /* |
1424 | * Construct input contexts and issue TRB to open pipe. | | 1763 | * Construct input contexts and issue TRB to open pipe. |
1425 | */ | | 1764 | */ |
1426 | static usbd_status | | 1765 | static usbd_status |
1427 | xhci_configure_endpoint(struct usbd_pipe *pipe) | | 1766 | xhci_configure_endpoint(struct usbd_pipe *pipe) |
1428 | { | | 1767 | { |
1429 | struct xhci_softc * const sc = XHCI_PIPE2SC(pipe); | | 1768 | struct xhci_softc * const sc = XHCI_PIPE2SC(pipe); |
1430 | struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv; | | 1769 | struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv; |
1431 | #ifdef USB_DEBUG | | 1770 | #ifdef USB_DEBUG |
1432 | const u_int dci = xhci_ep_get_dci(pipe->up_endpoint->ue_edesc); | | 1771 | const u_int dci = xhci_ep_get_dci(pipe->up_endpoint->ue_edesc); |
1433 | #endif | | 1772 | #endif |
1434 | struct xhci_soft_trb trb; | | 1773 | struct xhci_soft_trb trb; |
1435 | usbd_status err; | | 1774 | usbd_status err; |
1436 | | | 1775 | |
1437 | XHCIHIST_FUNC(); | | 1776 | XHCIHIST_FUNC(); |
1438 | XHCIHIST_CALLARGS("slot %ju dci %ju epaddr 0x%02jx attr 0x%02jx", | | 1777 | XHCIHIST_CALLARGS("slot %ju dci %ju epaddr 0x%02jx attr 0x%02jx", |
1439 | xs->xs_idx, dci, pipe->up_endpoint->ue_edesc->bEndpointAddress, | | 1778 | xs->xs_idx, dci, pipe->up_endpoint->ue_edesc->bEndpointAddress, |
1440 | pipe->up_endpoint->ue_edesc->bmAttributes); | | 1779 | pipe->up_endpoint->ue_edesc->bmAttributes); |
1441 | | | 1780 | |
1442 | /* XXX ensure input context is available? */ | | 1781 | /* XXX ensure input context is available? */ |
1443 | | | 1782 | |
1444 | memset(xhci_slot_get_icv(sc, xs, 0), 0, sc->sc_pgsz); | | 1783 | memset(xhci_slot_get_icv(sc, xs, 0), 0, sc->sc_pgsz); |
1445 | | | 1784 | |
1446 | /* set up context */ | | 1785 | /* set up context */ |
1447 | xhci_setup_ctx(pipe); | | 1786 | xhci_setup_ctx(pipe); |
1448 | | | 1787 | |
1449 | HEXDUMP("input control context", xhci_slot_get_icv(sc, xs, 0), | | 1788 | HEXDUMP("input control context", xhci_slot_get_icv(sc, xs, 0), |
1450 | sc->sc_ctxsz * 1); | | 1789 | sc->sc_ctxsz * 1); |
1451 | HEXDUMP("input endpoint context", xhci_slot_get_icv(sc, xs, | | 1790 | HEXDUMP("input endpoint context", xhci_slot_get_icv(sc, xs, |
1452 | xhci_dci_to_ici(dci)), sc->sc_ctxsz * 1); | | 1791 | xhci_dci_to_ici(dci)), sc->sc_ctxsz * 1); |
1453 | | | 1792 | |
1454 | trb.trb_0 = xhci_slot_get_icp(sc, xs, 0); | | 1793 | trb.trb_0 = xhci_slot_get_icp(sc, xs, 0); |
1455 | trb.trb_2 = 0; | | 1794 | trb.trb_2 = 0; |
1456 | trb.trb_3 = XHCI_TRB_3_SLOT_SET(xs->xs_idx) | | | 1795 | trb.trb_3 = XHCI_TRB_3_SLOT_SET(xs->xs_idx) | |
1457 | XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_CONFIGURE_EP); | | 1796 | XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_CONFIGURE_EP); |
1458 | | | 1797 | |
1459 | err = xhci_do_command(sc, &trb, USBD_DEFAULT_TIMEOUT); | | 1798 | err = xhci_do_command(sc, &trb, USBD_DEFAULT_TIMEOUT); |
1460 | | | 1799 | |
1461 | usb_syncmem(&xs->xs_dc_dma, 0, sc->sc_pgsz, BUS_DMASYNC_POSTREAD); | | 1800 | usb_syncmem(&xs->xs_dc_dma, 0, sc->sc_pgsz, BUS_DMASYNC_POSTREAD); |
1462 | HEXDUMP("output context", xhci_slot_get_dcv(sc, xs, dci), | | 1801 | HEXDUMP("output context", xhci_slot_get_dcv(sc, xs, dci), |
1463 | sc->sc_ctxsz * 1); | | 1802 | sc->sc_ctxsz * 1); |
1464 | | | 1803 | |
1465 | return err; | | 1804 | return err; |
1466 | } | | 1805 | } |
1467 | | | 1806 | |
1468 | #if 0 | | 1807 | #if 0 |
1469 | static usbd_status | | 1808 | static usbd_status |
1470 | xhci_unconfigure_endpoint(struct usbd_pipe *pipe) | | 1809 | xhci_unconfigure_endpoint(struct usbd_pipe *pipe) |
1471 | { | | 1810 | { |
1472 | #ifdef USB_DEBUG | | 1811 | #ifdef USB_DEBUG |
1473 | struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv; | | 1812 | struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv; |
1474 | #endif | | 1813 | #endif |
1475 | | | 1814 | |
1476 | XHCIHIST_FUNC(); | | 1815 | XHCIHIST_FUNC(); |
1477 | XHCIHIST_CALLARGS("slot %ju", xs->xs_idx, 0, 0, 0); | | 1816 | XHCIHIST_CALLARGS("slot %ju", xs->xs_idx, 0, 0, 0); |
1478 | | | 1817 | |
1479 | return USBD_NORMAL_COMPLETION; | | 1818 | return USBD_NORMAL_COMPLETION; |
1480 | } | | 1819 | } |
1481 | #endif | | 1820 | #endif |
1482 | | | 1821 | |
1483 | /* 4.6.8, 6.4.3.7 */ | | 1822 | /* 4.6.8, 6.4.3.7 */ |
1484 | static usbd_status | | 1823 | static usbd_status |
1485 | xhci_reset_endpoint_locked(struct usbd_pipe *pipe) | | 1824 | xhci_reset_endpoint_locked(struct usbd_pipe *pipe) |
1486 | { | | 1825 | { |
1487 | struct xhci_softc * const sc = XHCI_PIPE2SC(pipe); | | 1826 | struct xhci_softc * const sc = XHCI_PIPE2SC(pipe); |
1488 | struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv; | | 1827 | struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv; |
1489 | const u_int dci = xhci_ep_get_dci(pipe->up_endpoint->ue_edesc); | | 1828 | const u_int dci = xhci_ep_get_dci(pipe->up_endpoint->ue_edesc); |
1490 | struct xhci_soft_trb trb; | | 1829 | struct xhci_soft_trb trb; |
1491 | usbd_status err; | | 1830 | usbd_status err; |
1492 | | | 1831 | |
1493 | XHCIHIST_FUNC(); | | 1832 | XHCIHIST_FUNC(); |
1494 | XHCIHIST_CALLARGS("slot %ju dci %ju", xs->xs_idx, dci, 0, 0); | | 1833 | XHCIHIST_CALLARGS("slot %ju dci %ju", xs->xs_idx, dci, 0, 0); |
1495 | | | 1834 | |
1496 | KASSERT(mutex_owned(&sc->sc_lock)); | | 1835 | KASSERT(mutex_owned(&sc->sc_lock)); |
1497 | | | 1836 | |
1498 | trb.trb_0 = 0; | | 1837 | trb.trb_0 = 0; |
1499 | trb.trb_2 = 0; | | 1838 | trb.trb_2 = 0; |
1500 | trb.trb_3 = XHCI_TRB_3_SLOT_SET(xs->xs_idx) | | | 1839 | trb.trb_3 = XHCI_TRB_3_SLOT_SET(xs->xs_idx) | |
1501 | XHCI_TRB_3_EP_SET(dci) | | | 1840 | XHCI_TRB_3_EP_SET(dci) | |
1502 | XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_RESET_EP); | | 1841 | XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_RESET_EP); |
1503 | | | 1842 | |
1504 | err = xhci_do_command_locked(sc, &trb, USBD_DEFAULT_TIMEOUT); | | 1843 | err = xhci_do_command_locked(sc, &trb, USBD_DEFAULT_TIMEOUT); |
1505 | | | 1844 | |
1506 | return err; | | 1845 | return err; |
1507 | } | | 1846 | } |
1508 | | | 1847 | |
1509 | static usbd_status | | 1848 | static usbd_status |
1510 | xhci_reset_endpoint(struct usbd_pipe *pipe) | | 1849 | xhci_reset_endpoint(struct usbd_pipe *pipe) |
1511 | { | | 1850 | { |
1512 | struct xhci_softc * const sc = XHCI_PIPE2SC(pipe); | | 1851 | struct xhci_softc * const sc = XHCI_PIPE2SC(pipe); |
1513 | | | 1852 | |
1514 | mutex_enter(&sc->sc_lock); | | 1853 | mutex_enter(&sc->sc_lock); |
1515 | usbd_status ret = xhci_reset_endpoint_locked(pipe); | | 1854 | usbd_status ret = xhci_reset_endpoint_locked(pipe); |
1516 | mutex_exit(&sc->sc_lock); | | 1855 | mutex_exit(&sc->sc_lock); |
1517 | | | 1856 | |
1518 | return ret; | | 1857 | return ret; |
1519 | } | | 1858 | } |
1520 | | | 1859 | |
1521 | /* | | 1860 | /* |
1522 | * 4.6.9, 6.4.3.8 | | 1861 | * 4.6.9, 6.4.3.8 |
1523 | * Stop execution of TDs on xfer ring. | | 1862 | * Stop execution of TDs on xfer ring. |
1524 | * Should be called with sc_lock held. | | 1863 | * Should be called with sc_lock held. |
1525 | */ | | 1864 | */ |
1526 | static usbd_status | | 1865 | static usbd_status |
1527 | xhci_stop_endpoint(struct usbd_pipe *pipe) | | 1866 | xhci_stop_endpoint(struct usbd_pipe *pipe) |
1528 | { | | 1867 | { |
1529 | struct xhci_softc * const sc = XHCI_PIPE2SC(pipe); | | 1868 | struct xhci_softc * const sc = XHCI_PIPE2SC(pipe); |
1530 | struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv; | | 1869 | struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv; |
1531 | struct xhci_soft_trb trb; | | 1870 | struct xhci_soft_trb trb; |
1532 | usbd_status err; | | 1871 | usbd_status err; |
1533 | const u_int dci = xhci_ep_get_dci(pipe->up_endpoint->ue_edesc); | | 1872 | const u_int dci = xhci_ep_get_dci(pipe->up_endpoint->ue_edesc); |
1534 | | | 1873 | |
1535 | XHCIHIST_FUNC(); | | 1874 | XHCIHIST_FUNC(); |
1536 | XHCIHIST_CALLARGS("slot %ju dci %ju", xs->xs_idx, dci, 0, 0); | | 1875 | XHCIHIST_CALLARGS("slot %ju dci %ju", xs->xs_idx, dci, 0, 0); |
1537 | | | 1876 | |
1538 | KASSERT(mutex_owned(&sc->sc_lock)); | | 1877 | KASSERT(mutex_owned(&sc->sc_lock)); |
1539 | | | 1878 | |
1540 | trb.trb_0 = 0; | | 1879 | trb.trb_0 = 0; |
1541 | trb.trb_2 = 0; | | 1880 | trb.trb_2 = 0; |
1542 | trb.trb_3 = XHCI_TRB_3_SLOT_SET(xs->xs_idx) | | | 1881 | trb.trb_3 = XHCI_TRB_3_SLOT_SET(xs->xs_idx) | |
1543 | XHCI_TRB_3_EP_SET(dci) | | | 1882 | XHCI_TRB_3_EP_SET(dci) | |
1544 | XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_STOP_EP); | | 1883 | XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_STOP_EP); |
1545 | | | 1884 | |
1546 | err = xhci_do_command_locked(sc, &trb, USBD_DEFAULT_TIMEOUT); | | 1885 | err = xhci_do_command_locked(sc, &trb, USBD_DEFAULT_TIMEOUT); |
1547 | | | 1886 | |
1548 | return err; | | 1887 | return err; |
1549 | } | | 1888 | } |
1550 | | | 1889 | |
1551 | /* | | 1890 | /* |
1552 | * Set TR Dequeue Pointer. | | 1891 | * Set TR Dequeue Pointer. |
1553 | * xHCI 1.1 4.6.10 6.4.3.9 | | 1892 | * xHCI 1.1 4.6.10 6.4.3.9 |
1554 | * Purge all of the TRBs on ring and reinitialize ring. | | 1893 | * Purge all of the TRBs on ring and reinitialize ring. |
1555 | * Set TR dequeue Pointr to 0 and Cycle State to 1. | | 1894 | * Set TR dequeue Pointr to 0 and Cycle State to 1. |
1556 | * EPSTATE of endpoint must be ERROR or STOPPED, otherwise CONTEXT_STATE | | 1895 | * EPSTATE of endpoint must be ERROR or STOPPED, otherwise CONTEXT_STATE |
1557 | * error will be generated. | | 1896 | * error will be generated. |
1558 | */ | | 1897 | */ |
1559 | static usbd_status | | 1898 | static usbd_status |
1560 | xhci_set_dequeue_locked(struct usbd_pipe *pipe) | | 1899 | xhci_set_dequeue_locked(struct usbd_pipe *pipe) |
1561 | { | | 1900 | { |
1562 | struct xhci_softc * const sc = XHCI_PIPE2SC(pipe); | | 1901 | struct xhci_softc * const sc = XHCI_PIPE2SC(pipe); |
1563 | struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv; | | 1902 | struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv; |
1564 | const u_int dci = xhci_ep_get_dci(pipe->up_endpoint->ue_edesc); | | 1903 | const u_int dci = xhci_ep_get_dci(pipe->up_endpoint->ue_edesc); |
1565 | struct xhci_ring * const xr = xs->xs_xr[dci]; | | 1904 | struct xhci_ring * const xr = xs->xs_xr[dci]; |
1566 | struct xhci_soft_trb trb; | | 1905 | struct xhci_soft_trb trb; |
1567 | usbd_status err; | | 1906 | usbd_status err; |
1568 | | | 1907 | |
1569 | XHCIHIST_FUNC(); | | 1908 | XHCIHIST_FUNC(); |
1570 | XHCIHIST_CALLARGS("slot %ju dci %ju", xs->xs_idx, dci, 0, 0); | | 1909 | XHCIHIST_CALLARGS("slot %ju dci %ju", xs->xs_idx, dci, 0, 0); |
1571 | | | 1910 | |
1572 | KASSERT(mutex_owned(&sc->sc_lock)); | | 1911 | KASSERT(mutex_owned(&sc->sc_lock)); |
1573 | KASSERT(xr != NULL); | | 1912 | KASSERT(xr != NULL); |
1574 | | | 1913 | |
1575 | xhci_host_dequeue(xr); | | 1914 | xhci_host_dequeue(xr); |
1576 | | | 1915 | |
1577 | /* set DCS */ | | 1916 | /* set DCS */ |
1578 | trb.trb_0 = xhci_ring_trbp(xr, 0) | 1; /* XXX */ | | 1917 | trb.trb_0 = xhci_ring_trbp(xr, 0) | 1; /* XXX */ |
1579 | trb.trb_2 = 0; | | 1918 | trb.trb_2 = 0; |
1580 | trb.trb_3 = XHCI_TRB_3_SLOT_SET(xs->xs_idx) | | | 1919 | trb.trb_3 = XHCI_TRB_3_SLOT_SET(xs->xs_idx) | |
1581 | XHCI_TRB_3_EP_SET(dci) | | | 1920 | XHCI_TRB_3_EP_SET(dci) | |
1582 | XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_SET_TR_DEQUEUE); | | 1921 | XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_SET_TR_DEQUEUE); |
1583 | | | 1922 | |
1584 | err = xhci_do_command_locked(sc, &trb, USBD_DEFAULT_TIMEOUT); | | 1923 | err = xhci_do_command_locked(sc, &trb, USBD_DEFAULT_TIMEOUT); |
1585 | | | 1924 | |
1586 | return err; | | 1925 | return err; |
1587 | } | | 1926 | } |
1588 | | | 1927 | |
1589 | static usbd_status | | 1928 | static usbd_status |
1590 | xhci_set_dequeue(struct usbd_pipe *pipe) | | 1929 | xhci_set_dequeue(struct usbd_pipe *pipe) |
1591 | { | | 1930 | { |
1592 | struct xhci_softc * const sc = XHCI_PIPE2SC(pipe); | | 1931 | struct xhci_softc * const sc = XHCI_PIPE2SC(pipe); |
1593 | | | 1932 | |
1594 | mutex_enter(&sc->sc_lock); | | 1933 | mutex_enter(&sc->sc_lock); |
1595 | usbd_status ret = xhci_set_dequeue_locked(pipe); | | 1934 | usbd_status ret = xhci_set_dequeue_locked(pipe); |
1596 | mutex_exit(&sc->sc_lock); | | 1935 | mutex_exit(&sc->sc_lock); |
1597 | | | 1936 | |
1598 | return ret; | | 1937 | return ret; |
1599 | } | | 1938 | } |
1600 | | | 1939 | |
1601 | /* | | 1940 | /* |
1602 | * Open new pipe: called from usbd_setup_pipe_flags. | | 1941 | * Open new pipe: called from usbd_setup_pipe_flags. |
1603 | * Fills methods of pipe. | | 1942 | * Fills methods of pipe. |
1604 | * If pipe is not for ep0, calls configure_endpoint. | | 1943 | * If pipe is not for ep0, calls configure_endpoint. |
1605 | */ | | 1944 | */ |
1606 | static usbd_status | | 1945 | static usbd_status |
1607 | xhci_open(struct usbd_pipe *pipe) | | 1946 | xhci_open(struct usbd_pipe *pipe) |
1608 | { | | 1947 | { |
1609 | struct usbd_device * const dev = pipe->up_dev; | | 1948 | struct usbd_device * const dev = pipe->up_dev; |
1610 | struct xhci_pipe * const xpipe = (struct xhci_pipe *)pipe; | | 1949 | struct xhci_pipe * const xpipe = (struct xhci_pipe *)pipe; |
1611 | struct xhci_softc * const sc = XHCI_BUS2SC(dev->ud_bus); | | 1950 | struct xhci_softc * const sc = XHCI_BUS2SC(dev->ud_bus); |
1612 | struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv; | | 1951 | struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv; |
1613 | usb_endpoint_descriptor_t * const ed = pipe->up_endpoint->ue_edesc; | | 1952 | usb_endpoint_descriptor_t * const ed = pipe->up_endpoint->ue_edesc; |
1614 | const u_int dci = xhci_ep_get_dci(ed); | | 1953 | const u_int dci = xhci_ep_get_dci(ed); |
1615 | const uint8_t xfertype = UE_GET_XFERTYPE(ed->bmAttributes); | | 1954 | const uint8_t xfertype = UE_GET_XFERTYPE(ed->bmAttributes); |
1616 | usbd_status err; | | 1955 | usbd_status err; |
1617 | | | 1956 | |
1618 | XHCIHIST_FUNC(); | | 1957 | XHCIHIST_FUNC(); |
1619 | XHCIHIST_CALLARGS("addr %jd depth %jd port %jd speed %jd", dev->ud_addr, | | 1958 | XHCIHIST_CALLARGS("addr %jd depth %jd port %jd speed %jd", dev->ud_addr, |
1620 | dev->ud_depth, dev->ud_powersrc->up_portno, dev->ud_speed); | | 1959 | dev->ud_depth, dev->ud_powersrc->up_portno, dev->ud_speed); |
1621 | DPRINTFN(1, " dci %ju type 0x%02jx epaddr 0x%02jx attr 0x%02jx", | | 1960 | DPRINTFN(1, " dci %ju type 0x%02jx epaddr 0x%02jx attr 0x%02jx", |
1622 | xhci_ep_get_dci(ed), ed->bDescriptorType, ed->bEndpointAddress, | | 1961 | xhci_ep_get_dci(ed), ed->bDescriptorType, ed->bEndpointAddress, |
1623 | ed->bmAttributes); | | 1962 | ed->bmAttributes); |
1624 | DPRINTFN(1, " mps %ju ival %ju", UGETW(ed->wMaxPacketSize), | | 1963 | DPRINTFN(1, " mps %ju ival %ju", UGETW(ed->wMaxPacketSize), |
1625 | ed->bInterval, 0, 0); | | 1964 | ed->bInterval, 0, 0); |
1626 | | | 1965 | |
1627 | if (sc->sc_dying) | | 1966 | if (sc->sc_dying) |
1628 | return USBD_IOERROR; | | 1967 | return USBD_IOERROR; |
1629 | | | 1968 | |
1630 | /* Root Hub */ | | 1969 | /* Root Hub */ |
1631 | if (dev->ud_depth == 0 && dev->ud_powersrc->up_portno == 0) { | | 1970 | if (dev->ud_depth == 0 && dev->ud_powersrc->up_portno == 0) { |
1632 | switch (ed->bEndpointAddress) { | | 1971 | switch (ed->bEndpointAddress) { |
1633 | case USB_CONTROL_ENDPOINT: | | 1972 | case USB_CONTROL_ENDPOINT: |
1634 | pipe->up_methods = &roothub_ctrl_methods; | | 1973 | pipe->up_methods = &roothub_ctrl_methods; |
1635 | break; | | 1974 | break; |
1636 | case UE_DIR_IN | USBROOTHUB_INTR_ENDPT: | | 1975 | case UE_DIR_IN | USBROOTHUB_INTR_ENDPT: |
1637 | pipe->up_methods = &xhci_root_intr_methods; | | 1976 | pipe->up_methods = &xhci_root_intr_methods; |
1638 | break; | | 1977 | break; |
1639 | default: | | 1978 | default: |
1640 | pipe->up_methods = NULL; | | 1979 | pipe->up_methods = NULL; |
1641 | DPRINTFN(0, "bad bEndpointAddress 0x%02jx", | | 1980 | DPRINTFN(0, "bad bEndpointAddress 0x%02jx", |
1642 | ed->bEndpointAddress, 0, 0, 0); | | 1981 | ed->bEndpointAddress, 0, 0, 0); |
1643 | return USBD_INVAL; | | 1982 | return USBD_INVAL; |
1644 | } | | 1983 | } |
1645 | return USBD_NORMAL_COMPLETION; | | 1984 | return USBD_NORMAL_COMPLETION; |
1646 | } | | 1985 | } |
1647 | | | 1986 | |
1648 | switch (xfertype) { | | 1987 | switch (xfertype) { |
1649 | case UE_CONTROL: | | 1988 | case UE_CONTROL: |
1650 | pipe->up_methods = &xhci_device_ctrl_methods; | | 1989 | pipe->up_methods = &xhci_device_ctrl_methods; |
1651 | break; | | 1990 | break; |
1652 | case UE_ISOCHRONOUS: | | 1991 | case UE_ISOCHRONOUS: |
1653 | pipe->up_methods = &xhci_device_isoc_methods; | | 1992 | pipe->up_methods = &xhci_device_isoc_methods; |
1654 | pipe->up_serialise = false; | | 1993 | pipe->up_serialise = false; |
1655 | xpipe->xp_isoc_next = -1; | | 1994 | xpipe->xp_isoc_next = -1; |
1656 | break; | | 1995 | break; |
1657 | case UE_BULK: | | 1996 | case UE_BULK: |
1658 | pipe->up_methods = &xhci_device_bulk_methods; | | 1997 | pipe->up_methods = &xhci_device_bulk_methods; |
1659 | break; | | 1998 | break; |
1660 | case UE_INTERRUPT: | | 1999 | case UE_INTERRUPT: |
1661 | pipe->up_methods = &xhci_device_intr_methods; | | 2000 | pipe->up_methods = &xhci_device_intr_methods; |
1662 | break; | | 2001 | break; |
1663 | default: | | 2002 | default: |
1664 | return USBD_IOERROR; | | 2003 | return USBD_IOERROR; |
1665 | break; | | 2004 | break; |
1666 | } | | 2005 | } |
1667 | | | 2006 | |
1668 | KASSERT(xs != NULL); | | 2007 | KASSERT(xs != NULL); |
1669 | KASSERT(xs->xs_xr[dci] == NULL); | | 2008 | KASSERT(xs->xs_xr[dci] == NULL); |
1670 | | | 2009 | |
1671 | /* allocate transfer ring */ | | 2010 | /* allocate transfer ring */ |
1672 | err = xhci_ring_init(sc, &xs->xs_xr[dci], XHCI_TRANSFER_RING_TRBS, | | 2011 | err = xhci_ring_init(sc, &xs->xs_xr[dci], XHCI_TRANSFER_RING_TRBS, |
1673 | XHCI_TRB_ALIGN); | | 2012 | XHCI_TRB_ALIGN); |
1674 | if (err) { | | 2013 | if (err) { |
1675 | DPRINTFN(1, "ring alloc failed %jd", err, 0, 0, 0); | | 2014 | DPRINTFN(1, "ring alloc failed %jd", err, 0, 0, 0); |
1676 | return err; | | 2015 | return err; |
1677 | } | | 2016 | } |
1678 | | | 2017 | |
1679 | if (ed->bEndpointAddress != USB_CONTROL_ENDPOINT) | | 2018 | if (ed->bEndpointAddress != USB_CONTROL_ENDPOINT) |
1680 | return xhci_configure_endpoint(pipe); | | 2019 | return xhci_configure_endpoint(pipe); |
1681 | | | 2020 | |
1682 | return USBD_NORMAL_COMPLETION; | | 2021 | return USBD_NORMAL_COMPLETION; |
1683 | } | | 2022 | } |
1684 | | | 2023 | |
1685 | /* | | 2024 | /* |
1686 | * Closes pipe, called from usbd_kill_pipe via close methods. | | 2025 | * Closes pipe, called from usbd_kill_pipe via close methods. |
1687 | * If the endpoint to be closed is ep0, disable_slot. | | 2026 | * If the endpoint to be closed is ep0, disable_slot. |
1688 | * Should be called with sc_lock held. | | 2027 | * Should be called with sc_lock held. |
1689 | */ | | 2028 | */ |
1690 | static void | | 2029 | static void |
1691 | xhci_close_pipe(struct usbd_pipe *pipe) | | 2030 | xhci_close_pipe(struct usbd_pipe *pipe) |
1692 | { | | 2031 | { |
1693 | struct xhci_softc * const sc = XHCI_PIPE2SC(pipe); | | 2032 | struct xhci_softc * const sc = XHCI_PIPE2SC(pipe); |
1694 | struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv; | | 2033 | struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv; |
1695 | usb_endpoint_descriptor_t * const ed = pipe->up_endpoint->ue_edesc; | | 2034 | usb_endpoint_descriptor_t * const ed = pipe->up_endpoint->ue_edesc; |
1696 | const u_int dci = xhci_ep_get_dci(ed); | | 2035 | const u_int dci = xhci_ep_get_dci(ed); |
1697 | struct xhci_soft_trb trb; | | 2036 | struct xhci_soft_trb trb; |
1698 | uint32_t *cp; | | 2037 | uint32_t *cp; |
1699 | | | 2038 | |
1700 | XHCIHIST_FUNC(); | | 2039 | XHCIHIST_FUNC(); |
1701 | | | 2040 | |
1702 | if (sc->sc_dying) | | 2041 | if (sc->sc_dying) |
1703 | return; | | 2042 | return; |
1704 | | | 2043 | |
1705 | /* xs is uninitialized before xhci_init_slot */ | | 2044 | /* xs is uninitialized before xhci_init_slot */ |
1706 | if (xs == NULL || xs->xs_idx == 0) | | 2045 | if (xs == NULL || xs->xs_idx == 0) |
1707 | return; | | 2046 | return; |
1708 | | | 2047 | |
1709 | XHCIHIST_CALLARGS("pipe %#jx slot %ju dci %ju", | | 2048 | XHCIHIST_CALLARGS("pipe %#jx slot %ju dci %ju", |
1710 | (uintptr_t)pipe, xs->xs_idx, dci, 0); | | 2049 | (uintptr_t)pipe, xs->xs_idx, dci, 0); |
1711 | | | 2050 | |
1712 | KASSERTMSG(!cpu_intr_p() && !cpu_softintr_p(), "called from intr ctx"); | | 2051 | KASSERTMSG(!cpu_intr_p() && !cpu_softintr_p(), "called from intr ctx"); |
1713 | KASSERT(mutex_owned(&sc->sc_lock)); | | 2052 | KASSERT(mutex_owned(&sc->sc_lock)); |
1714 | | | 2053 | |
1715 | if (pipe->up_dev->ud_depth == 0) | | 2054 | if (pipe->up_dev->ud_depth == 0) |
1716 | return; | | 2055 | return; |
1717 | | | 2056 | |
1718 | if (dci == XHCI_DCI_EP_CONTROL) { | | 2057 | if (dci == XHCI_DCI_EP_CONTROL) { |
1719 | DPRINTFN(4, "closing ep0", 0, 0, 0, 0); | | 2058 | DPRINTFN(4, "closing ep0", 0, 0, 0, 0); |
1720 | /* This frees all rings */ | | 2059 | /* This frees all rings */ |
1721 | xhci_disable_slot(sc, xs->xs_idx); | | 2060 | xhci_disable_slot(sc, xs->xs_idx); |
1722 | return; | | 2061 | return; |
1723 | } | | 2062 | } |
1724 | | | 2063 | |
1725 | if (xhci_get_epstate(sc, xs, dci) != XHCI_EPSTATE_STOPPED) | | 2064 | if (xhci_get_epstate(sc, xs, dci) != XHCI_EPSTATE_STOPPED) |
1726 | (void)xhci_stop_endpoint(pipe); | | 2065 | (void)xhci_stop_endpoint(pipe); |
1727 | | | 2066 | |
1728 | /* | | 2067 | /* |
1729 | * set appropriate bit to be dropped. | | 2068 | * set appropriate bit to be dropped. |
1730 | * don't set DC bit to 1, otherwise all endpoints | | 2069 | * don't set DC bit to 1, otherwise all endpoints |
1731 | * would be deconfigured. | | 2070 | * would be deconfigured. |
1732 | */ | | 2071 | */ |
1733 | cp = xhci_slot_get_icv(sc, xs, XHCI_ICI_INPUT_CONTROL); | | 2072 | cp = xhci_slot_get_icv(sc, xs, XHCI_ICI_INPUT_CONTROL); |
1734 | cp[0] = htole32(XHCI_INCTX_0_DROP_MASK(dci)); | | 2073 | cp[0] = htole32(XHCI_INCTX_0_DROP_MASK(dci)); |
1735 | cp[1] = htole32(0); | | 2074 | cp[1] = htole32(0); |
1736 | | | 2075 | |
1737 | /* XXX should be most significant one, not dci? */ | | 2076 | /* XXX should be most significant one, not dci? */ |
1738 | cp = xhci_slot_get_icv(sc, xs, xhci_dci_to_ici(XHCI_DCI_SLOT)); | | 2077 | cp = xhci_slot_get_icv(sc, xs, xhci_dci_to_ici(XHCI_DCI_SLOT)); |
1739 | cp[0] = htole32(XHCI_SCTX_0_CTX_NUM_SET(dci)); | | 2078 | cp[0] = htole32(XHCI_SCTX_0_CTX_NUM_SET(dci)); |
1740 | | | 2079 | |
1741 | /* configure ep context performs an implicit dequeue */ | | 2080 | /* configure ep context performs an implicit dequeue */ |
1742 | xhci_host_dequeue(xs->xs_xr[dci]); | | 2081 | xhci_host_dequeue(xs->xs_xr[dci]); |
1743 | | | 2082 | |
1744 | /* sync input contexts before they are read from memory */ | | 2083 | /* sync input contexts before they are read from memory */ |
1745 | usb_syncmem(&xs->xs_ic_dma, 0, sc->sc_pgsz, BUS_DMASYNC_PREWRITE); | | 2084 | usb_syncmem(&xs->xs_ic_dma, 0, sc->sc_pgsz, BUS_DMASYNC_PREWRITE); |
1746 | | | 2085 | |
1747 | trb.trb_0 = xhci_slot_get_icp(sc, xs, 0); | | 2086 | trb.trb_0 = xhci_slot_get_icp(sc, xs, 0); |
1748 | trb.trb_2 = 0; | | 2087 | trb.trb_2 = 0; |
1749 | trb.trb_3 = XHCI_TRB_3_SLOT_SET(xs->xs_idx) | | | 2088 | trb.trb_3 = XHCI_TRB_3_SLOT_SET(xs->xs_idx) | |
1750 | XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_CONFIGURE_EP); | | 2089 | XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_CONFIGURE_EP); |
1751 | | | 2090 | |
1752 | (void)xhci_do_command_locked(sc, &trb, USBD_DEFAULT_TIMEOUT); | | 2091 | (void)xhci_do_command_locked(sc, &trb, USBD_DEFAULT_TIMEOUT); |
1753 | usb_syncmem(&xs->xs_dc_dma, 0, sc->sc_pgsz, BUS_DMASYNC_POSTREAD); | | 2092 | usb_syncmem(&xs->xs_dc_dma, 0, sc->sc_pgsz, BUS_DMASYNC_POSTREAD); |
1754 | | | 2093 | |
1755 | xhci_ring_free(sc, &xs->xs_xr[dci]); | | 2094 | xhci_ring_free(sc, &xs->xs_xr[dci]); |
1756 | } | | 2095 | } |
1757 | | | 2096 | |
1758 | /* | | 2097 | /* |
1759 | * Abort transfer. | | 2098 | * Abort transfer. |
1760 | * Should be called with sc_lock held. | | 2099 | * Should be called with sc_lock held. |
1761 | */ | | 2100 | */ |
1762 | static void | | 2101 | static void |
1763 | xhci_abortx(struct usbd_xfer *xfer) | | 2102 | xhci_abortx(struct usbd_xfer *xfer) |
1764 | { | | 2103 | { |
1765 | XHCIHIST_FUNC(); | | 2104 | XHCIHIST_FUNC(); |
1766 | struct xhci_softc * const sc = XHCI_XFER2SC(xfer); | | 2105 | struct xhci_softc * const sc = XHCI_XFER2SC(xfer); |
1767 | struct xhci_slot * const xs = xfer->ux_pipe->up_dev->ud_hcpriv; | | 2106 | struct xhci_slot * const xs = xfer->ux_pipe->up_dev->ud_hcpriv; |
1768 | const u_int dci = xhci_ep_get_dci(xfer->ux_pipe->up_endpoint->ue_edesc); | | 2107 | const u_int dci = xhci_ep_get_dci(xfer->ux_pipe->up_endpoint->ue_edesc); |
1769 | | | 2108 | |
1770 | XHCIHIST_CALLARGS("xfer %#jx pipe %#jx", | | 2109 | XHCIHIST_CALLARGS("xfer %#jx pipe %#jx", |
1771 | (uintptr_t)xfer, (uintptr_t)xfer->ux_pipe, 0, 0); | | 2110 | (uintptr_t)xfer, (uintptr_t)xfer->ux_pipe, 0, 0); |
1772 | | | 2111 | |
1773 | KASSERT(mutex_owned(&sc->sc_lock)); | | 2112 | KASSERT(mutex_owned(&sc->sc_lock)); |
1774 | ASSERT_SLEEPABLE(); | | 2113 | ASSERT_SLEEPABLE(); |