1 | /*
|
---|
2 | * Copyright (c) 2017 Petr Manek
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup drvusbxhci
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | * @brief The host controller endpoint management.
|
---|
34 | */
|
---|
35 |
|
---|
36 | #include <usb/host/endpoint.h>
|
---|
37 | #include <usb/descriptor.h>
|
---|
38 |
|
---|
39 | #include <errno.h>
|
---|
40 | #include <macros.h>
|
---|
41 | #include <str_error.h>
|
---|
42 |
|
---|
43 | #include "hc.h"
|
---|
44 | #include "bus.h"
|
---|
45 | #include "commands.h"
|
---|
46 | #include "device.h"
|
---|
47 | #include "endpoint.h"
|
---|
48 | #include "streams.h"
|
---|
49 |
|
---|
50 | static errno_t alloc_transfer_ds(xhci_endpoint_t *);
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Initialize new XHCI endpoint.
|
---|
54 | * @param[in] xhci_ep Allocated XHCI endpoint to initialize.
|
---|
55 | * @param[in] dev Device, to which the endpoint belongs.
|
---|
56 | * @param[in] desc USB endpoint descriptor carrying configuration data.
|
---|
57 | *
|
---|
58 | * @return Error code.
|
---|
59 | */
|
---|
60 | static errno_t xhci_endpoint_init(xhci_endpoint_t *xhci_ep, device_t *dev,
|
---|
61 | const usb_endpoint_descriptors_t *desc)
|
---|
62 | {
|
---|
63 | errno_t rc;
|
---|
64 | assert(xhci_ep);
|
---|
65 |
|
---|
66 | endpoint_t *ep = &xhci_ep->base;
|
---|
67 |
|
---|
68 | endpoint_init(ep, dev, desc);
|
---|
69 |
|
---|
70 | fibril_mutex_initialize(&xhci_ep->guard);
|
---|
71 |
|
---|
72 | xhci_ep->max_burst = desc->companion.max_burst + 1;
|
---|
73 |
|
---|
74 | if (ep->transfer_type == USB_TRANSFER_BULK)
|
---|
75 | xhci_ep->max_streams = 1 << (USB_SSC_MAX_STREAMS(desc->companion));
|
---|
76 | else
|
---|
77 | xhci_ep->max_streams = 1;
|
---|
78 |
|
---|
79 | if (ep->transfer_type == USB_TRANSFER_ISOCHRONOUS)
|
---|
80 | xhci_ep->mult = USB_SSC_MULT(desc->companion) + 1;
|
---|
81 | else
|
---|
82 | xhci_ep->mult = 1;
|
---|
83 |
|
---|
84 | /*
|
---|
85 | * In USB 3, the semantics of wMaxPacketSize changed. Now the number of
|
---|
86 | * packets per service interval is determined from max_burst and mult.
|
---|
87 | */
|
---|
88 | if (dev->speed >= USB_SPEED_SUPER) {
|
---|
89 | ep->packets_per_uframe = xhci_ep->max_burst * xhci_ep->mult;
|
---|
90 | if (ep->transfer_type == USB_TRANSFER_ISOCHRONOUS
|
---|
91 | || ep->transfer_type == USB_TRANSFER_INTERRUPT) {
|
---|
92 | ep->max_transfer_size = ep->max_packet_size * ep->packets_per_uframe;
|
---|
93 | }
|
---|
94 | else {
|
---|
95 | ep->max_transfer_size = 200 * PAGE_SIZE;
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | xhci_ep->interval = desc->endpoint.poll_interval;
|
---|
100 |
|
---|
101 | /*
|
---|
102 | * Only Low/Full speed interrupt endpoints have interval as a linear field,
|
---|
103 | * others have 2-based log of it.
|
---|
104 | */
|
---|
105 | if (dev->speed >= USB_SPEED_HIGH
|
---|
106 | || ep->transfer_type != USB_TRANSFER_INTERRUPT) {
|
---|
107 | xhci_ep->interval = 1 << (xhci_ep->interval - 1);
|
---|
108 | }
|
---|
109 |
|
---|
110 | /* Full speed devices have interval in frames */
|
---|
111 | if (dev->speed <= USB_SPEED_FULL) {
|
---|
112 | xhci_ep->interval *= 8;
|
---|
113 | }
|
---|
114 |
|
---|
115 | if (xhci_ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS)
|
---|
116 | isoch_init(xhci_ep, desc);
|
---|
117 |
|
---|
118 | if ((rc = alloc_transfer_ds(xhci_ep)))
|
---|
119 | goto err;
|
---|
120 |
|
---|
121 | /* Driver can handle non-contiguous buffers */
|
---|
122 | ep->transfer_buffer_policy &= ~DMA_POLICY_CONTIGUOUS;
|
---|
123 |
|
---|
124 | /* Driver can handle buffers crossing boundaries */
|
---|
125 | ep->transfer_buffer_policy &= ~DMA_POLICY_NOT_CROSSING;
|
---|
126 |
|
---|
127 | /* Some xHCs can handle 64-bit addresses */
|
---|
128 | xhci_bus_t *bus = bus_to_xhci_bus(ep->device->bus);
|
---|
129 | if (bus->hc->ac64)
|
---|
130 | ep->transfer_buffer_policy &= ~DMA_POLICY_4GiB;
|
---|
131 |
|
---|
132 | return EOK;
|
---|
133 |
|
---|
134 | err:
|
---|
135 | return rc;
|
---|
136 | }
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Create a new xHCI endpoint structure.
|
---|
140 | *
|
---|
141 | * Bus callback.
|
---|
142 | */
|
---|
143 | endpoint_t *xhci_endpoint_create(device_t *dev,
|
---|
144 | const usb_endpoint_descriptors_t *desc)
|
---|
145 | {
|
---|
146 | const usb_transfer_type_t type = USB_ED_GET_TRANSFER_TYPE(desc->endpoint);
|
---|
147 |
|
---|
148 | xhci_endpoint_t *ep = calloc(1, sizeof(xhci_endpoint_t)
|
---|
149 | + (type == USB_TRANSFER_ISOCHRONOUS) * sizeof(*ep->isoch));
|
---|
150 | if (!ep)
|
---|
151 | return NULL;
|
---|
152 |
|
---|
153 | if (xhci_endpoint_init(ep, dev, desc)) {
|
---|
154 | free(ep);
|
---|
155 | return NULL;
|
---|
156 | }
|
---|
157 |
|
---|
158 | return &ep->base;
|
---|
159 | }
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * Finalize XHCI endpoint.
|
---|
163 | * @param[in] xhci_ep XHCI endpoint to finalize.
|
---|
164 | */
|
---|
165 | static void xhci_endpoint_fini(xhci_endpoint_t *xhci_ep)
|
---|
166 | {
|
---|
167 | assert(xhci_ep);
|
---|
168 |
|
---|
169 | xhci_endpoint_free_transfer_ds(xhci_ep);
|
---|
170 |
|
---|
171 | // TODO: Something missed?
|
---|
172 | }
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * Destroy given xHCI endpoint structure.
|
---|
176 | *
|
---|
177 | * Bus callback.
|
---|
178 | */
|
---|
179 | void xhci_endpoint_destroy(endpoint_t *ep)
|
---|
180 | {
|
---|
181 | xhci_endpoint_t *xhci_ep = xhci_endpoint_get(ep);
|
---|
182 |
|
---|
183 | xhci_endpoint_fini(xhci_ep);
|
---|
184 | free(xhci_ep);
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * Register an andpoint to the xHC.
|
---|
190 | *
|
---|
191 | * Bus callback.
|
---|
192 | */
|
---|
193 | errno_t xhci_endpoint_register(endpoint_t *ep_base)
|
---|
194 | {
|
---|
195 | errno_t err;
|
---|
196 | xhci_endpoint_t *ep = xhci_endpoint_get(ep_base);
|
---|
197 |
|
---|
198 | if (ep_base->endpoint != 0 && (err = hc_add_endpoint(ep)))
|
---|
199 | return err;
|
---|
200 |
|
---|
201 | endpoint_set_online(ep_base, &ep->guard);
|
---|
202 | return EOK;
|
---|
203 | }
|
---|
204 |
|
---|
205 | /**
|
---|
206 | * Abort a transfer on an endpoint.
|
---|
207 | */
|
---|
208 | static void endpoint_abort(endpoint_t *ep)
|
---|
209 | {
|
---|
210 | xhci_device_t *dev = xhci_device_get(ep->device);
|
---|
211 | xhci_endpoint_t *xhci_ep = xhci_endpoint_get(ep);
|
---|
212 |
|
---|
213 | /* This function can only abort endpoints without streams. */
|
---|
214 | assert(xhci_ep->primary_stream_data_array == NULL);
|
---|
215 |
|
---|
216 | fibril_mutex_lock(&xhci_ep->guard);
|
---|
217 |
|
---|
218 | endpoint_set_offline_locked(ep);
|
---|
219 |
|
---|
220 | if (!ep->active_batch) {
|
---|
221 | fibril_mutex_unlock(&xhci_ep->guard);
|
---|
222 | return;
|
---|
223 | }
|
---|
224 |
|
---|
225 | /* First, offer the batch a short chance to be finished. */
|
---|
226 | endpoint_wait_timeout_locked(ep, 10000);
|
---|
227 |
|
---|
228 | if (!ep->active_batch) {
|
---|
229 | fibril_mutex_unlock(&xhci_ep->guard);
|
---|
230 | return;
|
---|
231 | }
|
---|
232 |
|
---|
233 | usb_transfer_batch_t * const batch = ep->active_batch;
|
---|
234 |
|
---|
235 | const errno_t err = hc_stop_endpoint(xhci_ep);
|
---|
236 | if (err) {
|
---|
237 | usb_log_error("Failed to stop endpoint %u of device "
|
---|
238 | XHCI_DEV_FMT ": %s", ep->endpoint, XHCI_DEV_ARGS(*dev),
|
---|
239 | str_error(err));
|
---|
240 | }
|
---|
241 |
|
---|
242 | fibril_mutex_unlock(&xhci_ep->guard);
|
---|
243 |
|
---|
244 | batch->error = EINTR;
|
---|
245 | batch->transferred_size = 0;
|
---|
246 | usb_transfer_batch_finish(batch);
|
---|
247 | return;
|
---|
248 | }
|
---|
249 |
|
---|
250 | /**
|
---|
251 | * Unregister an endpoint. If the device is still available, inform the xHC
|
---|
252 | * about it.
|
---|
253 | *
|
---|
254 | * Bus callback.
|
---|
255 | */
|
---|
256 | void xhci_endpoint_unregister(endpoint_t *ep_base)
|
---|
257 | {
|
---|
258 | errno_t err;
|
---|
259 | xhci_endpoint_t *ep = xhci_endpoint_get(ep_base);
|
---|
260 | xhci_device_t *dev = xhci_device_get(ep_base->device);
|
---|
261 |
|
---|
262 | endpoint_abort(ep_base);
|
---|
263 |
|
---|
264 | /* If device slot is still available, drop the endpoint. */
|
---|
265 | if (ep_base->endpoint != 0 && dev->slot_id) {
|
---|
266 |
|
---|
267 | if ((err = hc_drop_endpoint(ep))) {
|
---|
268 | usb_log_error("Failed to drop endpoint " XHCI_EP_FMT ": %s",
|
---|
269 | XHCI_EP_ARGS(*ep), str_error(err));
|
---|
270 | }
|
---|
271 | } else {
|
---|
272 | usb_log_debug("Not going to drop endpoint " XHCI_EP_FMT " because"
|
---|
273 | " the slot has already been disabled.", XHCI_EP_ARGS(*ep));
|
---|
274 | }
|
---|
275 | }
|
---|
276 |
|
---|
277 | /**
|
---|
278 | * Determine the type of a XHCI endpoint.
|
---|
279 | * @param[in] ep XHCI endpoint to query.
|
---|
280 | *
|
---|
281 | * @return EP_TYPE_[CONTROL|ISOCH|BULK|INTERRUPT]_[IN|OUT]
|
---|
282 | */
|
---|
283 | int xhci_endpoint_type(xhci_endpoint_t *ep)
|
---|
284 | {
|
---|
285 | const bool in = ep->base.direction == USB_DIRECTION_IN;
|
---|
286 |
|
---|
287 | switch (ep->base.transfer_type) {
|
---|
288 | case USB_TRANSFER_CONTROL:
|
---|
289 | return EP_TYPE_CONTROL;
|
---|
290 |
|
---|
291 | case USB_TRANSFER_ISOCHRONOUS:
|
---|
292 | return in ? EP_TYPE_ISOCH_IN
|
---|
293 | : EP_TYPE_ISOCH_OUT;
|
---|
294 |
|
---|
295 | case USB_TRANSFER_BULK:
|
---|
296 | return in ? EP_TYPE_BULK_IN
|
---|
297 | : EP_TYPE_BULK_OUT;
|
---|
298 |
|
---|
299 | case USB_TRANSFER_INTERRUPT:
|
---|
300 | return in ? EP_TYPE_INTERRUPT_IN
|
---|
301 | : EP_TYPE_INTERRUPT_OUT;
|
---|
302 | }
|
---|
303 |
|
---|
304 | return EP_TYPE_INVALID;
|
---|
305 | }
|
---|
306 |
|
---|
307 | /**
|
---|
308 | * Allocate transfer data structures for XHCI endpoint not using streams.
|
---|
309 | * @param[in] xhci_ep XHCI endpoint to allocate data structures for.
|
---|
310 | *
|
---|
311 | * @return Error code.
|
---|
312 | */
|
---|
313 | static errno_t alloc_transfer_ds(xhci_endpoint_t *xhci_ep)
|
---|
314 | {
|
---|
315 | /* Can't use XHCI_EP_FMT because the endpoint may not have device. */
|
---|
316 | usb_log_debug("Allocating main transfer ring for endpoint " XHCI_EP_FMT,
|
---|
317 | XHCI_EP_ARGS(*xhci_ep));
|
---|
318 |
|
---|
319 | xhci_ep->primary_stream_data_array = NULL;
|
---|
320 | xhci_ep->primary_stream_data_size = 0;
|
---|
321 |
|
---|
322 | errno_t err;
|
---|
323 | if ((err = xhci_trb_ring_init(&xhci_ep->ring, 0))) {
|
---|
324 | return err;
|
---|
325 | }
|
---|
326 |
|
---|
327 | if (xhci_ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS) {
|
---|
328 | if ((err = isoch_alloc_transfers(xhci_ep))) {
|
---|
329 | xhci_trb_ring_fini(&xhci_ep->ring);
|
---|
330 | return err;
|
---|
331 | }
|
---|
332 | }
|
---|
333 |
|
---|
334 | return EOK;
|
---|
335 | }
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * Free transfer data structures for XHCI endpoint.
|
---|
339 | * @param[in] xhci_ep XHCI endpoint to free data structures for.
|
---|
340 | */
|
---|
341 | void xhci_endpoint_free_transfer_ds(xhci_endpoint_t *xhci_ep)
|
---|
342 | {
|
---|
343 | if (xhci_ep->primary_stream_data_size) {
|
---|
344 | xhci_stream_free_ds(xhci_ep);
|
---|
345 | } else {
|
---|
346 | usb_log_debug("Freeing main transfer ring of endpoint " XHCI_EP_FMT,
|
---|
347 | XHCI_EP_ARGS(*xhci_ep));
|
---|
348 | xhci_trb_ring_fini(&xhci_ep->ring);
|
---|
349 | }
|
---|
350 |
|
---|
351 | if (xhci_ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS)
|
---|
352 | isoch_fini(xhci_ep);
|
---|
353 | }
|
---|
354 |
|
---|
355 | xhci_trb_ring_t *xhci_endpoint_get_ring(xhci_endpoint_t *ep, uint32_t stream_id)
|
---|
356 | {
|
---|
357 | if (ep->primary_stream_data_size == 0)
|
---|
358 | return stream_id == 0 ? &ep->ring : NULL;
|
---|
359 |
|
---|
360 | xhci_stream_data_t *stream_data = xhci_get_stream_ctx_data(ep, stream_id);
|
---|
361 | if (stream_data == NULL) {
|
---|
362 | usb_log_warning("No transfer ring was found for stream %u.", stream_id);
|
---|
363 | return NULL;
|
---|
364 | }
|
---|
365 |
|
---|
366 | return &stream_data->ring;
|
---|
367 | }
|
---|
368 |
|
---|
369 | /**
|
---|
370 | * Configure endpoint context of a control endpoint.
|
---|
371 | * @param[in] ep XHCI control endpoint.
|
---|
372 | * @param[in] ctx Endpoint context to configure.
|
---|
373 | */
|
---|
374 | static void setup_control_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx)
|
---|
375 | {
|
---|
376 | XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(ep));
|
---|
377 | XHCI_EP_MAX_PACKET_SIZE_SET(*ctx, ep->base.max_packet_size);
|
---|
378 | XHCI_EP_MAX_BURST_SIZE_SET(*ctx, ep->max_burst - 1);
|
---|
379 | XHCI_EP_MULT_SET(*ctx, ep->mult - 1);
|
---|
380 | XHCI_EP_ERROR_COUNT_SET(*ctx, 3);
|
---|
381 | XHCI_EP_TR_DPTR_SET(*ctx, ep->ring.dequeue);
|
---|
382 | XHCI_EP_DCS_SET(*ctx, 1);
|
---|
383 | }
|
---|
384 |
|
---|
385 | /**
|
---|
386 | * Configure endpoint context of a bulk endpoint.
|
---|
387 | * @param[in] ep XHCI bulk endpoint.
|
---|
388 | * @param[in] ctx Endpoint context to configure.
|
---|
389 | */
|
---|
390 | static void setup_bulk_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx)
|
---|
391 | {
|
---|
392 | XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(ep));
|
---|
393 | XHCI_EP_MAX_PACKET_SIZE_SET(*ctx, ep->base.max_packet_size);
|
---|
394 | XHCI_EP_MAX_BURST_SIZE_SET(*ctx, ep->max_burst - 1);
|
---|
395 | XHCI_EP_ERROR_COUNT_SET(*ctx, 3);
|
---|
396 |
|
---|
397 | XHCI_EP_MAX_P_STREAMS_SET(*ctx, 0);
|
---|
398 | XHCI_EP_TR_DPTR_SET(*ctx, ep->ring.dequeue);
|
---|
399 | XHCI_EP_DCS_SET(*ctx, 1);
|
---|
400 | }
|
---|
401 |
|
---|
402 | /**
|
---|
403 | * Configure endpoint context of a isochronous endpoint.
|
---|
404 | * @param[in] ep XHCI isochronous endpoint.
|
---|
405 | * @param[in] ctx Endpoint context to configure.
|
---|
406 | */
|
---|
407 | static void setup_isoch_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx)
|
---|
408 | {
|
---|
409 | XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(ep));
|
---|
410 | XHCI_EP_MAX_PACKET_SIZE_SET(*ctx, ep->base.max_packet_size & 0x07FF);
|
---|
411 | XHCI_EP_MAX_BURST_SIZE_SET(*ctx, ep->max_burst - 1);
|
---|
412 | XHCI_EP_MULT_SET(*ctx, ep->mult - 1);
|
---|
413 | XHCI_EP_ERROR_COUNT_SET(*ctx, 0);
|
---|
414 | XHCI_EP_TR_DPTR_SET(*ctx, ep->ring.dequeue);
|
---|
415 | XHCI_EP_DCS_SET(*ctx, 1);
|
---|
416 | XHCI_EP_INTERVAL_SET(*ctx, fnzb32(ep->interval) % 32);
|
---|
417 |
|
---|
418 | XHCI_EP_MAX_ESIT_PAYLOAD_LO_SET(*ctx, ep->isoch->max_size & 0xFFFF);
|
---|
419 | XHCI_EP_MAX_ESIT_PAYLOAD_HI_SET(*ctx, (ep->isoch->max_size >> 16) & 0xFF);
|
---|
420 | }
|
---|
421 |
|
---|
422 | /**
|
---|
423 | * Configure endpoint context of a interrupt endpoint.
|
---|
424 | * @param[in] ep XHCI interrupt endpoint.
|
---|
425 | * @param[in] ctx Endpoint context to configure.
|
---|
426 | */
|
---|
427 | static void setup_interrupt_ep_ctx(xhci_endpoint_t *ep, xhci_ep_ctx_t *ctx)
|
---|
428 | {
|
---|
429 | XHCI_EP_TYPE_SET(*ctx, xhci_endpoint_type(ep));
|
---|
430 | XHCI_EP_MAX_PACKET_SIZE_SET(*ctx, ep->base.max_packet_size & 0x07FF);
|
---|
431 | XHCI_EP_MAX_BURST_SIZE_SET(*ctx, ep->max_burst - 1);
|
---|
432 | XHCI_EP_MULT_SET(*ctx, 0);
|
---|
433 | XHCI_EP_ERROR_COUNT_SET(*ctx, 3);
|
---|
434 | XHCI_EP_TR_DPTR_SET(*ctx, ep->ring.dequeue);
|
---|
435 | XHCI_EP_DCS_SET(*ctx, 1);
|
---|
436 | XHCI_EP_INTERVAL_SET(*ctx, fnzb32(ep->interval) % 32);
|
---|
437 | // TODO: max ESIT payload
|
---|
438 | }
|
---|
439 |
|
---|
440 | /** Type of endpoint context configuration function. */
|
---|
441 | typedef void (*setup_ep_ctx_helper)(xhci_endpoint_t *, xhci_ep_ctx_t *);
|
---|
442 |
|
---|
443 | /**
|
---|
444 | * Static array, which maps USB endpoint types to their respective endpoint
|
---|
445 | * context configuration functions.
|
---|
446 | */
|
---|
447 | static const setup_ep_ctx_helper setup_ep_ctx_helpers[] = {
|
---|
448 | [USB_TRANSFER_CONTROL] = setup_control_ep_ctx,
|
---|
449 | [USB_TRANSFER_ISOCHRONOUS] = setup_isoch_ep_ctx,
|
---|
450 | [USB_TRANSFER_BULK] = setup_bulk_ep_ctx,
|
---|
451 | [USB_TRANSFER_INTERRUPT] = setup_interrupt_ep_ctx,
|
---|
452 | };
|
---|
453 |
|
---|
454 | /** Configure endpoint context of XHCI endpoint.
|
---|
455 | * @param[in] ep Associated XHCI endpoint.
|
---|
456 | * @param[in] ep_ctx Endpoint context to configure.
|
---|
457 | */
|
---|
458 | void xhci_setup_endpoint_context(xhci_endpoint_t *ep, xhci_ep_ctx_t *ep_ctx)
|
---|
459 | {
|
---|
460 | assert(ep);
|
---|
461 | assert(ep_ctx);
|
---|
462 |
|
---|
463 | usb_transfer_type_t tt = ep->base.transfer_type;
|
---|
464 |
|
---|
465 | memset(ep_ctx, 0, sizeof(*ep_ctx));
|
---|
466 | setup_ep_ctx_helpers[tt](ep, ep_ctx);
|
---|
467 | }
|
---|
468 |
|
---|
469 | /**
|
---|
470 | * Clear endpoint halt condition by resetting the endpoint and skipping the
|
---|
471 | * offending transfer.
|
---|
472 | */
|
---|
473 | errno_t xhci_endpoint_clear_halt(xhci_endpoint_t *ep, uint32_t stream_id)
|
---|
474 | {
|
---|
475 | errno_t err;
|
---|
476 |
|
---|
477 | if ((err = hc_reset_endpoint(ep)))
|
---|
478 | return err;
|
---|
479 |
|
---|
480 | if ((err = hc_reset_ring(ep, stream_id)))
|
---|
481 | return err;
|
---|
482 |
|
---|
483 | return EOK;
|
---|
484 | }
|
---|
485 |
|
---|
486 | /**
|
---|
487 | * @}
|
---|
488 | */
|
---|