[41b96b4] | 1 | /*
|
---|
[6bec59b] | 2 | * Copyright (c) 2011 Vojtech Horky, Jan Vesely
|
---|
[41b96b4] | 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 | /** @addtogroup drvusbohci
|
---|
| 29 | * @{
|
---|
| 30 | */
|
---|
| 31 | /** @file
|
---|
[6bec59b] | 32 | * @brief OHCI driver hc interface implementation
|
---|
[41b96b4] | 33 | */
|
---|
| 34 | #include <ddf/driver.h>
|
---|
| 35 | #include <errno.h>
|
---|
| 36 |
|
---|
| 37 | #include <usb/debug.h>
|
---|
[6bec59b] | 38 | #include <usb/host/endpoint.h>
|
---|
[41b96b4] | 39 |
|
---|
| 40 | #include "iface.h"
|
---|
[bab71635] | 41 | #include "hc.h"
|
---|
[41b96b4] | 42 |
|
---|
[6bec59b] | 43 | static inline int setup_batch(
|
---|
| 44 | ddf_fun_t *fun, usb_target_t target, usb_direction_t direction,
|
---|
| 45 | void *data, size_t size, void * setup_data, size_t setup_size,
|
---|
| 46 | usbhc_iface_transfer_in_callback_t in,
|
---|
| 47 | usbhc_iface_transfer_out_callback_t out, void *arg, const char* name,
|
---|
| 48 | hc_t **hc, usb_transfer_batch_t **batch)
|
---|
| 49 | {
|
---|
| 50 | assert(hc);
|
---|
| 51 | assert(batch);
|
---|
| 52 | assert(fun);
|
---|
| 53 | *hc = fun_to_hc(fun);
|
---|
| 54 | assert(*hc);
|
---|
[41b96b4] | 55 |
|
---|
[6bec59b] | 56 | size_t res_bw;
|
---|
[592369ae] | 57 | endpoint_t *ep = hc_get_endpoint(*hc,
|
---|
[6bec59b] | 58 | target.address, target.endpoint, direction, &res_bw);
|
---|
| 59 | if (ep == NULL) {
|
---|
| 60 | usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
|
---|
| 61 | target.address, target.endpoint, name);
|
---|
| 62 | return ENOENT;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[0ede0c3] | 65 | usb_log_debug("%s %d:%d %zu(%zu).\n",
|
---|
| 66 | name, target.address, target.endpoint, size, ep->max_packet_size);
|
---|
| 67 |
|
---|
[6bec59b] | 68 | const size_t bw = bandwidth_count_usb11(
|
---|
| 69 | ep->speed, ep->transfer_type, size, ep->max_packet_size);
|
---|
| 70 | if (res_bw < bw) {
|
---|
| 71 | usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
|
---|
| 72 | "but only %zu is reserved.\n",
|
---|
[86b4ee0] | 73 | target.address, target.endpoint, name, bw, res_bw);
|
---|
[6bec59b] | 74 | return ENOSPC;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[a19a2d7] | 77 | *batch = batch_get(
|
---|
| 78 | fun, ep, data, size, setup_data, setup_size, in, out, arg);
|
---|
| 79 | if (!*batch)
|
---|
[6bec59b] | 80 | return ENOMEM;
|
---|
[1c6a45f] | 81 | return EOK;
|
---|
[41b96b4] | 82 | }
|
---|
[b0beee82] | 83 | /*----------------------------------------------------------------------------*/
|
---|
[6bec59b] | 84 | /** Request address interface function
|
---|
[41b96b4] | 85 | *
|
---|
[6bec59b] | 86 | * @param[in] fun DDF function that was called.
|
---|
| 87 | * @param[in] speed Speed to associate with the new default address.
|
---|
| 88 | * @param[out] address Place to write a new address.
|
---|
[41b96b4] | 89 | * @return Error code.
|
---|
| 90 | */
|
---|
[b9fa0a9] | 91 | static int request_address(
|
---|
| 92 | ddf_fun_t *fun, usb_speed_t speed, usb_address_t *address)
|
---|
[41b96b4] | 93 | {
|
---|
[1c6a45f] | 94 | assert(fun);
|
---|
| 95 | hc_t *hc = fun_to_hc(fun);
|
---|
| 96 | assert(hc);
|
---|
| 97 | assert(address);
|
---|
[41b96b4] | 98 |
|
---|
[1c6a45f] | 99 | usb_log_debug("Address request with speed %d.\n", speed);
|
---|
| 100 | *address = device_keeper_get_free_address(&hc->manager, speed);
|
---|
| 101 | usb_log_debug("Address request with result: %d.\n", *address);
|
---|
| 102 | if (*address <= 0)
|
---|
| 103 | return *address;
|
---|
| 104 | return EOK;
|
---|
[41b96b4] | 105 | }
|
---|
[b0beee82] | 106 | /*----------------------------------------------------------------------------*/
|
---|
[6bec59b] | 107 | /** Bind address interface function
|
---|
[41b96b4] | 108 | *
|
---|
[6bec59b] | 109 | * @param[in] fun DDF function that was called.
|
---|
| 110 | * @param[in] address Address of the device
|
---|
| 111 | * @param[in] handle Devman handle of the device driver.
|
---|
[41b96b4] | 112 | * @return Error code.
|
---|
| 113 | */
|
---|
[b9fa0a9] | 114 | static int bind_address(
|
---|
[6bec59b] | 115 | ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)
|
---|
[41b96b4] | 116 | {
|
---|
[1c6a45f] | 117 | assert(fun);
|
---|
| 118 | hc_t *hc = fun_to_hc(fun);
|
---|
| 119 | assert(hc);
|
---|
[4125b7d] | 120 | usb_log_debug("Address bind %d-%" PRIun ".\n", address, handle);
|
---|
[1c6a45f] | 121 | usb_device_keeper_bind(&hc->manager, address, handle);
|
---|
| 122 | return EOK;
|
---|
[41b96b4] | 123 | }
|
---|
[df25ab6] | 124 |
|
---|
| 125 |
|
---|
| 126 | /** Find device handle by address interface function.
|
---|
| 127 | *
|
---|
| 128 | * @param[in] fun DDF function that was called.
|
---|
| 129 | * @param[in] address Address in question.
|
---|
| 130 | * @param[out] handle Where to store device handle if found.
|
---|
| 131 | * @return Error code.
|
---|
| 132 | */
|
---|
| 133 | static int find_by_address(ddf_fun_t *fun, usb_address_t address,
|
---|
| 134 | devman_handle_t *handle)
|
---|
| 135 | {
|
---|
| 136 | assert(fun);
|
---|
| 137 | hc_t *hc = fun_to_hc(fun);
|
---|
| 138 | assert(hc);
|
---|
| 139 | bool found =
|
---|
| 140 | usb_device_keeper_find_by_address(&hc->manager, address, handle);
|
---|
| 141 | return found ? EOK : ENOENT;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
[b0beee82] | 144 | /*----------------------------------------------------------------------------*/
|
---|
[6bec59b] | 145 | /** Release address interface function
|
---|
[41b96b4] | 146 | *
|
---|
[6bec59b] | 147 | * @param[in] fun DDF function that was called.
|
---|
[41b96b4] | 148 | * @param[in] address USB address to be released.
|
---|
| 149 | * @return Error code.
|
---|
| 150 | */
|
---|
| 151 | static int release_address(ddf_fun_t *fun, usb_address_t address)
|
---|
| 152 | {
|
---|
[1c6a45f] | 153 | assert(fun);
|
---|
| 154 | hc_t *hc = fun_to_hc(fun);
|
---|
| 155 | assert(hc);
|
---|
| 156 | usb_log_debug("Address release %d.\n", address);
|
---|
| 157 | usb_device_keeper_release(&hc->manager, address);
|
---|
| 158 | return EOK;
|
---|
[41b96b4] | 159 | }
|
---|
[1c6a45f] | 160 | /*----------------------------------------------------------------------------*/
|
---|
[41b96b4] | 161 | /** Register endpoint for bandwidth reservation.
|
---|
| 162 | *
|
---|
| 163 | * @param[in] fun Device function the action was invoked on.
|
---|
| 164 | * @param[in] address USB address of the device.
|
---|
[1998bcd] | 165 | * @param[in] ep_speed Endpoint speed (invalid means to use device one).
|
---|
[41b96b4] | 166 | * @param[in] endpoint Endpoint number.
|
---|
| 167 | * @param[in] transfer_type USB transfer type.
|
---|
| 168 | * @param[in] direction Endpoint data direction.
|
---|
| 169 | * @param[in] max_packet_size Max packet size of the endpoint.
|
---|
| 170 | * @param[in] interval Polling interval.
|
---|
| 171 | * @return Error code.
|
---|
| 172 | */
|
---|
[1998bcd] | 173 | static int register_endpoint(ddf_fun_t *fun,
|
---|
| 174 | usb_address_t address, usb_speed_t ep_speed, usb_endpoint_t endpoint,
|
---|
[41b96b4] | 175 | usb_transfer_type_t transfer_type, usb_direction_t direction,
|
---|
| 176 | size_t max_packet_size, unsigned int interval)
|
---|
| 177 | {
|
---|
[c2be0e5] | 178 | hc_t *hc = fun_to_hc(fun);
|
---|
| 179 | assert(hc);
|
---|
[0ede0c3] | 180 |
|
---|
[1998bcd] | 181 | usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, address);
|
---|
| 182 | if (speed >= USB_SPEED_MAX) {
|
---|
| 183 | speed = ep_speed;
|
---|
| 184 | }
|
---|
[86b4ee0] | 185 | const size_t size = max_packet_size;
|
---|
[6bec59b] | 186 |
|
---|
[86b4ee0] | 187 | usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n",
|
---|
| 188 | address, endpoint, usb_str_transfer_type(transfer_type),
|
---|
| 189 | usb_str_speed(speed), direction, size, max_packet_size, interval);
|
---|
| 190 |
|
---|
[6bb0f43] | 191 | return hc_add_endpoint(hc, address, endpoint, speed, transfer_type,
|
---|
| 192 | direction, max_packet_size, size, interval);
|
---|
[41b96b4] | 193 | }
|
---|
[1c6a45f] | 194 | /*----------------------------------------------------------------------------*/
|
---|
[b9fa0a9] | 195 | static int unregister_endpoint(
|
---|
| 196 | ddf_fun_t *fun, usb_address_t address,
|
---|
[41b96b4] | 197 | usb_endpoint_t endpoint, usb_direction_t direction)
|
---|
| 198 | {
|
---|
[c2be0e5] | 199 | hc_t *hc = fun_to_hc(fun);
|
---|
| 200 | assert(hc);
|
---|
| 201 | usb_log_debug("Unregister endpoint %d:%d %d.\n",
|
---|
| 202 | address, endpoint, direction);
|
---|
[6bb0f43] | 203 | return hc_remove_endpoint(hc, address, endpoint, direction);
|
---|
[41b96b4] | 204 | }
|
---|
[be7950e8] | 205 | /*----------------------------------------------------------------------------*/
|
---|
[41b96b4] | 206 | /** Schedule interrupt out transfer.
|
---|
| 207 | *
|
---|
| 208 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 209 | * complete regardless of the outcome.
|
---|
| 210 | * However, the callback could be called only when this function returns
|
---|
| 211 | * with success status (i.e. returns EOK).
|
---|
| 212 | *
|
---|
| 213 | * @param[in] fun Device function the action was invoked on.
|
---|
| 214 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 215 | * @param[in] data Data to be sent (in USB endianess, allocated and deallocated
|
---|
| 216 | * by the caller).
|
---|
| 217 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 218 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 219 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 220 | * @return Error code.
|
---|
| 221 | */
|
---|
[b9fa0a9] | 222 | static int interrupt_out(
|
---|
[7dfc06fa] | 223 | ddf_fun_t *fun, usb_target_t target, void *data,
|
---|
[b9fa0a9] | 224 | size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
[41b96b4] | 225 | {
|
---|
[6bec59b] | 226 | usb_transfer_batch_t *batch = NULL;
|
---|
| 227 | hc_t *hc = NULL;
|
---|
| 228 | int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
|
---|
| 229 | NULL, 0, NULL, callback, arg, "Interrupt OUT", &hc, &batch);
|
---|
| 230 | if (ret != EOK)
|
---|
| 231 | return ret;
|
---|
[1c6a45f] | 232 | batch_interrupt_out(batch);
|
---|
[6bec59b] | 233 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 234 | if (ret != EOK) {
|
---|
[2cc6e97] | 235 | usb_transfer_batch_dispose(batch);
|
---|
[1c6a45f] | 236 | }
|
---|
[b9fa0a9] | 237 | return ret;
|
---|
[be7950e8] | 238 | }
|
---|
| 239 | /*----------------------------------------------------------------------------*/
|
---|
[41b96b4] | 240 | /** Schedule interrupt in transfer.
|
---|
| 241 | *
|
---|
| 242 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 243 | * complete regardless of the outcome.
|
---|
| 244 | * However, the callback could be called only when this function returns
|
---|
| 245 | * with success status (i.e. returns EOK).
|
---|
| 246 | *
|
---|
| 247 | * @param[in] fun Device function the action was invoked on.
|
---|
| 248 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 249 | * @param[in] data Buffer where to store the data (in USB endianess,
|
---|
| 250 | * allocated and deallocated by the caller).
|
---|
| 251 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 252 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 253 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 254 | * @return Error code.
|
---|
| 255 | */
|
---|
[b9fa0a9] | 256 | static int interrupt_in(
|
---|
[7dfc06fa] | 257 | ddf_fun_t *fun, usb_target_t target, void *data,
|
---|
[b9fa0a9] | 258 | size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
[41b96b4] | 259 | {
|
---|
[6bec59b] | 260 | usb_transfer_batch_t *batch = NULL;
|
---|
| 261 | hc_t *hc = NULL;
|
---|
| 262 | int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size,
|
---|
| 263 | NULL, 0, callback, NULL, arg, "Interrupt IN", &hc, &batch);
|
---|
| 264 | if (ret != EOK)
|
---|
| 265 | return ret;
|
---|
[1c6a45f] | 266 | batch_interrupt_in(batch);
|
---|
[6bec59b] | 267 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 268 | if (ret != EOK) {
|
---|
[2cc6e97] | 269 | usb_transfer_batch_dispose(batch);
|
---|
[1c6a45f] | 270 | }
|
---|
[b9fa0a9] | 271 | return ret;
|
---|
[41b96b4] | 272 | }
|
---|
[be7950e8] | 273 | /*----------------------------------------------------------------------------*/
|
---|
[41b96b4] | 274 | /** Schedule bulk out transfer.
|
---|
| 275 | *
|
---|
| 276 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 277 | * complete regardless of the outcome.
|
---|
| 278 | * However, the callback could be called only when this function returns
|
---|
| 279 | * with success status (i.e. returns EOK).
|
---|
| 280 | *
|
---|
| 281 | * @param[in] fun Device function the action was invoked on.
|
---|
| 282 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 283 | * @param[in] data Data to be sent (in USB endianess, allocated and deallocated
|
---|
| 284 | * by the caller).
|
---|
| 285 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 286 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 287 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 288 | * @return Error code.
|
---|
| 289 | */
|
---|
[b9fa0a9] | 290 | static int bulk_out(
|
---|
[7dfc06fa] | 291 | ddf_fun_t *fun, usb_target_t target, void *data,
|
---|
[b9fa0a9] | 292 | size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
[41b96b4] | 293 | {
|
---|
[6bec59b] | 294 | usb_transfer_batch_t *batch = NULL;
|
---|
| 295 | hc_t *hc = NULL;
|
---|
| 296 | int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
|
---|
| 297 | NULL, 0, NULL, callback, arg, "Bulk OUT", &hc, &batch);
|
---|
| 298 | if (ret != EOK)
|
---|
| 299 | return ret;
|
---|
[1c6a45f] | 300 | batch_bulk_out(batch);
|
---|
[6bec59b] | 301 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 302 | if (ret != EOK) {
|
---|
[2cc6e97] | 303 | usb_transfer_batch_dispose(batch);
|
---|
[1c6a45f] | 304 | }
|
---|
[b9fa0a9] | 305 | return ret;
|
---|
[be7950e8] | 306 | }
|
---|
| 307 | /*----------------------------------------------------------------------------*/
|
---|
[41b96b4] | 308 | /** Schedule bulk in transfer.
|
---|
| 309 | *
|
---|
| 310 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 311 | * complete regardless of the outcome.
|
---|
| 312 | * However, the callback could be called only when this function returns
|
---|
| 313 | * with success status (i.e. returns EOK).
|
---|
| 314 | *
|
---|
| 315 | * @param[in] fun Device function the action was invoked on.
|
---|
| 316 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 317 | * @param[in] data Buffer where to store the data (in USB endianess,
|
---|
| 318 | * allocated and deallocated by the caller).
|
---|
| 319 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 320 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 321 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 322 | * @return Error code.
|
---|
| 323 | */
|
---|
[b9fa0a9] | 324 | static int bulk_in(
|
---|
[7dfc06fa] | 325 | ddf_fun_t *fun, usb_target_t target, void *data,
|
---|
[b9fa0a9] | 326 | size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
[41b96b4] | 327 | {
|
---|
[6bec59b] | 328 | usb_transfer_batch_t *batch = NULL;
|
---|
| 329 | hc_t *hc = NULL;
|
---|
| 330 | int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size,
|
---|
| 331 | NULL, 0, callback, NULL, arg, "Bulk IN", &hc, &batch);
|
---|
| 332 | if (ret != EOK)
|
---|
| 333 | return ret;
|
---|
[1c6a45f] | 334 | batch_bulk_in(batch);
|
---|
[6bec59b] | 335 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 336 | if (ret != EOK) {
|
---|
[2cc6e97] | 337 | usb_transfer_batch_dispose(batch);
|
---|
[1c6a45f] | 338 | }
|
---|
[b9fa0a9] | 339 | return ret;
|
---|
[41b96b4] | 340 | }
|
---|
[be7950e8] | 341 | /*----------------------------------------------------------------------------*/
|
---|
[41b96b4] | 342 | /** Schedule control write transfer.
|
---|
| 343 | *
|
---|
| 344 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 345 | * complete regardless of the outcome.
|
---|
| 346 | * However, the callback could be called only when this function returns
|
---|
| 347 | * with success status (i.e. returns EOK).
|
---|
| 348 | *
|
---|
| 349 | * @param[in] fun Device function the action was invoked on.
|
---|
| 350 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 351 | * @param[in] setup_packet Setup packet buffer (in USB endianess, allocated
|
---|
| 352 | * and deallocated by the caller).
|
---|
[6bb0f43] | 353 | * @param[in] setup_size Size of @p setup_packet buffer in bytes.
|
---|
[41b96b4] | 354 | * @param[in] data_buffer Data buffer (in USB endianess, allocated and
|
---|
| 355 | * deallocated by the caller).
|
---|
[6bb0f43] | 356 | * @param[in] size Size of @p data_buffer buffer in bytes.
|
---|
[41b96b4] | 357 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 358 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 359 | * @return Error code.
|
---|
| 360 | */
|
---|
[b9fa0a9] | 361 | static int control_write(
|
---|
[7dfc06fa] | 362 | ddf_fun_t *fun, usb_target_t target,
|
---|
[1c6a45f] | 363 | void *setup_data, size_t setup_size, void *data, size_t size,
|
---|
[41b96b4] | 364 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 365 | {
|
---|
[6bec59b] | 366 | usb_transfer_batch_t *batch = NULL;
|
---|
| 367 | hc_t *hc = NULL;
|
---|
| 368 | int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
|
---|
| 369 | setup_data, setup_size, NULL, callback, arg, "Control WRITE",
|
---|
| 370 | &hc, &batch);
|
---|
| 371 | if (ret != EOK)
|
---|
| 372 | return ret;
|
---|
[ba038f4] | 373 | usb_endpoint_manager_reset_if_need(&hc->ep_manager, target, setup_data);
|
---|
[1c6a45f] | 374 | batch_control_write(batch);
|
---|
[6bec59b] | 375 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 376 | if (ret != EOK) {
|
---|
[2cc6e97] | 377 | usb_transfer_batch_dispose(batch);
|
---|
[1c6a45f] | 378 | }
|
---|
[b9fa0a9] | 379 | return ret;
|
---|
[be7950e8] | 380 | }
|
---|
| 381 | /*----------------------------------------------------------------------------*/
|
---|
[41b96b4] | 382 | /** Schedule control read transfer.
|
---|
| 383 | *
|
---|
| 384 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 385 | * complete regardless of the outcome.
|
---|
| 386 | * However, the callback could be called only when this function returns
|
---|
| 387 | * with success status (i.e. returns EOK).
|
---|
| 388 | *
|
---|
| 389 | * @param[in] fun Device function the action was invoked on.
|
---|
| 390 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 391 | * @param[in] setup_packet Setup packet buffer (in USB endianess, allocated
|
---|
| 392 | * and deallocated by the caller).
|
---|
[6bb0f43] | 393 | * @param[in] setup_size Size of @p setup_packet buffer in bytes.
|
---|
[41b96b4] | 394 | * @param[in] data_buffer Buffer where to store the data (in USB endianess,
|
---|
| 395 | * allocated and deallocated by the caller).
|
---|
[6bb0f43] | 396 | * @param[in] size Size of @p data_buffer buffer in bytes.
|
---|
[41b96b4] | 397 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 398 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 399 | * @return Error code.
|
---|
| 400 | */
|
---|
[b9fa0a9] | 401 | static int control_read(
|
---|
[7dfc06fa] | 402 | ddf_fun_t *fun, usb_target_t target,
|
---|
[1c6a45f] | 403 | void *setup_data, size_t setup_size, void *data, size_t size,
|
---|
[41b96b4] | 404 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 405 | {
|
---|
[6bec59b] | 406 | usb_transfer_batch_t *batch = NULL;
|
---|
| 407 | hc_t *hc = NULL;
|
---|
| 408 | int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
|
---|
| 409 | setup_data, setup_size, callback, NULL, arg, "Control READ",
|
---|
| 410 | &hc, &batch);
|
---|
| 411 | if (ret != EOK)
|
---|
| 412 | return ret;
|
---|
[1c6a45f] | 413 | batch_control_read(batch);
|
---|
[6bec59b] | 414 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 415 | if (ret != EOK) {
|
---|
[2cc6e97] | 416 | usb_transfer_batch_dispose(batch);
|
---|
[1c6a45f] | 417 | }
|
---|
[b9fa0a9] | 418 | return ret;
|
---|
[41b96b4] | 419 | }
|
---|
[be7950e8] | 420 | /*----------------------------------------------------------------------------*/
|
---|
[bab71635] | 421 | usbhc_iface_t hc_iface = {
|
---|
[41b96b4] | 422 | .request_address = request_address,
|
---|
| 423 | .bind_address = bind_address,
|
---|
[df25ab6] | 424 | .find_by_address = find_by_address,
|
---|
[41b96b4] | 425 | .release_address = release_address,
|
---|
| 426 |
|
---|
| 427 | .register_endpoint = register_endpoint,
|
---|
| 428 | .unregister_endpoint = unregister_endpoint,
|
---|
| 429 |
|
---|
| 430 | .interrupt_out = interrupt_out,
|
---|
| 431 | .interrupt_in = interrupt_in,
|
---|
| 432 |
|
---|
| 433 | .bulk_out = bulk_out,
|
---|
| 434 | .bulk_in = bulk_in,
|
---|
| 435 |
|
---|
| 436 | .control_write = control_write,
|
---|
[1c6a45f] | 437 | .control_read = control_read,
|
---|
[41b96b4] | 438 | };
|
---|
| 439 | /**
|
---|
| 440 | * @}
|
---|
| 441 | */
|
---|