source: mainline/uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h@ 4c25c2fb

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4c25c2fb was 0892663a, checked in by Ondřej Hlavatý <aearsis@…>, 7 years ago

usbhost: device removal and off/onlining moved into the library

Also, it is just not possible to make generic transfer abortion. So the
current semantics of endpoint unregistering is also aborting the pending
transfer. As it is not yet implemented in XHCI, and the stub in UHCI is
missing the magic, it breaks offlining interrupt devices, such as mouse.

When finishing this commit, I came across the fact we need some more
synchronization above device. Guard can protect internal structures, but
it cannot synchronize multiple calls to offline, or offline & removal
between each other - they both need to allow driver to unregister
endpoints, and as such must release the guard.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Copyright (c) 2011 Jan Vesely
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 libusbhost
30 * @{
31 */
32/** @file
33 * USB transfer transaction structures.
34 */
35
36#ifndef LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H
37#define LIBUSBHOST_HOST_USB_TRANSFER_BATCH_H
38
39#include <atomic.h>
40#include <errno.h>
41#include <stddef.h>
42#include <stdint.h>
43#include <usb/request.h>
44#include <usb/usb.h>
45#include <usbhc_iface.h>
46
47#include <usb/host/hcd.h>
48#include <usb/host/endpoint.h>
49#include <usb/host/bus.h>
50
51typedef struct endpoint endpoint_t;
52typedef struct bus bus_t;
53
54/** Structure stores additional data needed for communication with EP */
55typedef struct usb_transfer_batch {
56 /** Target for communication */
57 usb_target_t target;
58
59 /** Endpoint used for communication */
60 endpoint_t *ep;
61
62 /** Direction of the transfer */
63 usb_direction_t dir;
64
65 /** Function called on completion */
66 usbhc_iface_transfer_callback_t on_complete;
67 /** Arbitrary data for the handler */
68 void *on_complete_data;
69
70 /** Place to store SETUP data needed by control transfers */
71 union {
72 char buffer [USB_SETUP_PACKET_SIZE];
73 usb_device_request_setup_packet_t packet;
74 uint64_t packed;
75 } setup;
76
77 /** Resetting the Toggle */
78 toggle_reset_mode_t toggle_reset_mode;
79
80 /** Place for data to send/receive */
81 char *buffer;
82 /** Size of memory pointed to by buffer member */
83 size_t buffer_size;
84 /** Actually used portion of the buffer */
85 size_t transfered_size;
86
87 /** Indicates success/failure of the communication */
88 int error;
89} usb_transfer_batch_t;
90
91/**
92 * Printf formatting string for dumping usb_transfer_batch_t.
93 * [address:endpoint speed transfer_type-direction buffer_sizeB/max_packet_size]
94 * */
95#define USB_TRANSFER_BATCH_FMT "[%d:%d %s %s-%s %zuB/%zu]"
96
97/** Printf arguments for dumping usb_transfer_batch_t.
98 * @param batch USB transfer batch to be dumped.
99 */
100#define USB_TRANSFER_BATCH_ARGS(batch) \
101 ((batch).ep->device->address), ((batch).ep->endpoint), \
102 usb_str_speed((batch).ep->device->speed), \
103 usb_str_transfer_type_short((batch).ep->transfer_type), \
104 usb_str_direction((batch).dir), \
105 (batch).buffer_size, (batch).ep->max_packet_size
106
107/** Wrapper for bus operation. */
108usb_transfer_batch_t *usb_transfer_batch_create(endpoint_t *);
109
110/** Batch initializer. */
111void usb_transfer_batch_init(usb_transfer_batch_t *, endpoint_t *);
112
113/** Batch finalization. */
114void usb_transfer_batch_finish(usb_transfer_batch_t *);
115
116/** To be called from outside only when the transfer is not going to be finished
117 * (i.o.w. until successfuly scheduling)
118 */
119void usb_transfer_batch_destroy(usb_transfer_batch_t *);
120
121#endif
122
123/**
124 * @}
125 */
Note: See TracBrowser for help on using the repository browser.