source: mainline/uspace/lib/drv/include/usbhc_iface.h@ 7dfc06fa

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7dfc06fa was 7dfc06fa, checked in by Vojtech Horky <vojtechhorky@…>, 15 years ago

Do not send max packet size with each transfer

See ticket #177, #121 and partly #49.

  • Property mode set to 100644
File size: 8.1 KB
Line 
1/*
2 * Copyright (c) 2010 Vojtech Horky
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 libdrv
30 * @addtogroup usb
31 * @{
32 */
33/** @file
34 * @brief USB host controller interface definition.
35 */
36
37#ifndef LIBDRV_USBHC_IFACE_H_
38#define LIBDRV_USBHC_IFACE_H_
39
40#include "ddf/driver.h"
41#include <usb/usb.h>
42#include <bool.h>
43
44
45/** IPC methods for communication with HC through DDF interface.
46 *
47 * Notes for async methods:
48 *
49 * Methods for sending data to device (OUT transactions)
50 * - e.g. IPC_M_USBHC_INTERRUPT_OUT -
51 * always use the same semantics:
52 * - first, IPC call with given method is made
53 * - argument #1 is target address
54 * - argument #2 is target endpoint
55 * - argument #3 is max packet size of the endpoint
56 * - this call is immediately followed by IPC data write (from caller)
57 * - the initial call (and the whole transaction) is answer after the
58 * transaction is scheduled by the HC and acknowledged by the device
59 * or immediately after error is detected
60 * - the answer carries only the error code
61 *
62 * Methods for retrieving data from device (IN transactions)
63 * - e.g. IPC_M_USBHC_INTERRUPT_IN -
64 * also use the same semantics:
65 * - first, IPC call with given method is made
66 * - argument #1 is target address
67 * - argument #2 is target endpoint
68 * - this call is immediately followed by IPC data read (async version)
69 * - the call is not answered until the device returns some data (or until
70 * error occurs)
71 *
72 * Some special methods (NO-DATA transactions) do not send any data. These
73 * might behave as both OUT or IN transactions because communication parts
74 * where actual buffers are exchanged are omitted.
75 **
76 * For all these methods, wrap functions exists. Important rule: functions
77 * for IN transactions have (as parameters) buffers where retrieved data
78 * will be stored. These buffers must be already allocated and shall not be
79 * touch until the transaction is completed
80 * (e.g. not before calling usb_wait_for() with appropriate handle).
81 * OUT transactions buffers can be freed immediately after call is dispatched
82 * (i.e. after return from wrapping function).
83 *
84 */
85typedef enum {
86 /** Reserve usage of default address.
87 * This call informs the host controller that the caller will be
88 * using default USB address. It is duty of the HC driver to ensure
89 * that only single entity will have it reserved.
90 * The address is returned via IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS.
91 * The caller can start using the address after receiving EOK
92 * answer.
93 */
94 IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS,
95
96 /** Release usage of default address.
97 * @see IPC_M_USBHC_RESERVE_DEFAULT_ADDRESS
98 */
99 IPC_M_USBHC_RELEASE_DEFAULT_ADDRESS,
100
101 /** Asks for address assignment by host controller.
102 * Answer:
103 * - ELIMIT - host controller run out of address
104 * - EOK - address assigned
105 * Answer arguments:
106 * - assigned address
107 *
108 * The address must be released by via IPC_M_USBHC_RELEASE_ADDRESS.
109 */
110 IPC_M_USBHC_REQUEST_ADDRESS,
111
112 /** Bind USB address with devman handle.
113 * Parameters:
114 * - USB address
115 * - devman handle
116 * Answer:
117 * - EOK - address binded
118 * - ENOENT - address is not in use
119 */
120 IPC_M_USBHC_BIND_ADDRESS,
121
122 /** Release address in use.
123 * Arguments:
124 * - address to be released
125 * Answer:
126 * - ENOENT - address not in use
127 * - EPERM - trying to release default USB address
128 */
129 IPC_M_USBHC_RELEASE_ADDRESS,
130
131
132 /** Send interrupt data to device.
133 * See explanation at usb_iface_funcs_t (OUT transaction).
134 */
135 IPC_M_USBHC_INTERRUPT_OUT,
136
137 /** Get interrupt data from device.
138 * See explanation at usb_iface_funcs_t (IN transaction).
139 */
140 IPC_M_USBHC_INTERRUPT_IN,
141
142 /** Send bulk data to device.
143 * See explanation at usb_iface_funcs_t (OUT transaction).
144 */
145 IPC_M_USBHC_BULK_OUT,
146
147 /** Get bulk data from device.
148 * See explanation at usb_iface_funcs_t (IN transaction).
149 */
150 IPC_M_USBHC_BULK_IN,
151
152 /** Issue control WRITE transfer.
153 * See explanation at usb_iface_funcs_t (OUT transaction) for
154 * call parameters.
155 * This call is immediately followed by two IPC data writes
156 * from the caller (setup packet and actual data).
157 */
158 IPC_M_USBHC_CONTROL_WRITE,
159
160 /** Issue control READ transfer.
161 * See explanation at usb_iface_funcs_t (IN transaction) for
162 * call parameters.
163 * This call is immediately followed by IPC data write from the caller
164 * (setup packet) and IPC data read (buffer that was read).
165 */
166 IPC_M_USBHC_CONTROL_READ,
167
168 /** Register endpoint attributes at host controller.
169 * This is used to reserve portion of USB bandwidth.
170 * Parameters:
171 * - USB address + endpoint number (ADDR * 256 + EP)
172 * - transfer type + direction (TYPE * 256 + DIR)
173 * - maximum packet size
174 * - interval (in milliseconds)
175 * Answer:
176 * - EOK - reservation successful
177 * - ELIMIT - not enough bandwidth to satisfy the request
178 */
179 IPC_M_USBHC_REGISTER_ENDPOINT,
180
181 /** Revert endpoint registration.
182 * Parameters:
183 * - USB address
184 * - endpoint number
185 * - data direction
186 * Answer:
187 * - EOK - endpoint unregistered
188 * - ENOENT - unknown endpoint
189 */
190 IPC_M_USBHC_UNREGISTER_ENDPOINT
191} usbhc_iface_funcs_t;
192
193/** Callback for outgoing transfer. */
194typedef void (*usbhc_iface_transfer_out_callback_t)(ddf_fun_t *,
195 int, void *);
196
197/** Callback for incoming transfer. */
198typedef void (*usbhc_iface_transfer_in_callback_t)(ddf_fun_t *,
199 int, size_t, void *);
200
201
202/** Out transfer processing function prototype. */
203typedef int (*usbhc_iface_transfer_out_t)(ddf_fun_t *, usb_target_t,
204 void *, size_t,
205 usbhc_iface_transfer_out_callback_t, void *);
206
207/** Setup transfer processing function prototype. @deprecated */
208typedef usbhc_iface_transfer_out_t usbhc_iface_transfer_setup_t;
209
210/** In transfer processing function prototype. */
211typedef int (*usbhc_iface_transfer_in_t)(ddf_fun_t *, usb_target_t,
212 void *, size_t,
213 usbhc_iface_transfer_in_callback_t, void *);
214
215/** USB host controller communication interface. */
216typedef struct {
217 int (*reserve_default_address)(ddf_fun_t *, usb_speed_t);
218 int (*release_default_address)(ddf_fun_t *);
219 int (*request_address)(ddf_fun_t *, usb_speed_t, usb_address_t *);
220 int (*bind_address)(ddf_fun_t *, usb_address_t, devman_handle_t);
221 int (*release_address)(ddf_fun_t *, usb_address_t);
222
223 int (*register_endpoint)(ddf_fun_t *, usb_address_t, usb_endpoint_t,
224 usb_transfer_type_t, usb_direction_t, size_t, unsigned int);
225 int (*unregister_endpoint)(ddf_fun_t *, usb_address_t, usb_endpoint_t,
226 usb_direction_t);
227
228 usbhc_iface_transfer_out_t interrupt_out;
229 usbhc_iface_transfer_in_t interrupt_in;
230
231 usbhc_iface_transfer_out_t bulk_out;
232 usbhc_iface_transfer_in_t bulk_in;
233
234 int (*control_write)(ddf_fun_t *, usb_target_t,
235 void *, size_t, void *, size_t,
236 usbhc_iface_transfer_out_callback_t, void *);
237
238 int (*control_read)(ddf_fun_t *, usb_target_t,
239 void *, size_t, void *, size_t,
240 usbhc_iface_transfer_in_callback_t, void *);
241} usbhc_iface_t;
242
243
244#endif
245/**
246 * @}
247 */
Note: See TracBrowser for help on using the repository browser.