[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;
|
---|
| 57 | endpoint_t *ep = usb_endpoint_manager_get_ep(&(*hc)->ep_manager,
|
---|
| 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);
|
---|
| 120 | usb_log_debug("Address bind %d-%d.\n", address, handle);
|
---|
| 121 | usb_device_keeper_bind(&hc->manager, address, handle);
|
---|
| 122 | return EOK;
|
---|
[41b96b4] | 123 | }
|
---|
[b0beee82] | 124 | /*----------------------------------------------------------------------------*/
|
---|
[6bec59b] | 125 | /** Release address interface function
|
---|
[41b96b4] | 126 | *
|
---|
[6bec59b] | 127 | * @param[in] fun DDF function that was called.
|
---|
[41b96b4] | 128 | * @param[in] address USB address to be released.
|
---|
| 129 | * @return Error code.
|
---|
| 130 | */
|
---|
| 131 | static int release_address(ddf_fun_t *fun, usb_address_t address)
|
---|
| 132 | {
|
---|
[1c6a45f] | 133 | assert(fun);
|
---|
| 134 | hc_t *hc = fun_to_hc(fun);
|
---|
| 135 | assert(hc);
|
---|
| 136 | usb_log_debug("Address release %d.\n", address);
|
---|
| 137 | usb_device_keeper_release(&hc->manager, address);
|
---|
| 138 | return EOK;
|
---|
[41b96b4] | 139 | }
|
---|
[1c6a45f] | 140 | /*----------------------------------------------------------------------------*/
|
---|
[41b96b4] | 141 | /** Register endpoint for bandwidth reservation.
|
---|
| 142 | *
|
---|
| 143 | * @param[in] fun Device function the action was invoked on.
|
---|
| 144 | * @param[in] address USB address of the device.
|
---|
[1998bcd] | 145 | * @param[in] ep_speed Endpoint speed (invalid means to use device one).
|
---|
[41b96b4] | 146 | * @param[in] endpoint Endpoint number.
|
---|
| 147 | * @param[in] transfer_type USB transfer type.
|
---|
| 148 | * @param[in] direction Endpoint data direction.
|
---|
| 149 | * @param[in] max_packet_size Max packet size of the endpoint.
|
---|
| 150 | * @param[in] interval Polling interval.
|
---|
| 151 | * @return Error code.
|
---|
| 152 | */
|
---|
[1998bcd] | 153 | static int register_endpoint(ddf_fun_t *fun,
|
---|
| 154 | usb_address_t address, usb_speed_t ep_speed, usb_endpoint_t endpoint,
|
---|
[41b96b4] | 155 | usb_transfer_type_t transfer_type, usb_direction_t direction,
|
---|
| 156 | size_t max_packet_size, unsigned int interval)
|
---|
| 157 | {
|
---|
[c2be0e5] | 158 | hc_t *hc = fun_to_hc(fun);
|
---|
| 159 | assert(hc);
|
---|
[0ede0c3] | 160 |
|
---|
[1998bcd] | 161 | usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, address);
|
---|
| 162 | if (speed >= USB_SPEED_MAX) {
|
---|
| 163 | speed = ep_speed;
|
---|
| 164 | }
|
---|
[86b4ee0] | 165 | const size_t size = max_packet_size;
|
---|
[6bec59b] | 166 | int ret;
|
---|
| 167 |
|
---|
[86b4ee0] | 168 | usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n",
|
---|
| 169 | address, endpoint, usb_str_transfer_type(transfer_type),
|
---|
| 170 | usb_str_speed(speed), direction, size, max_packet_size, interval);
|
---|
| 171 |
|
---|
[6bec59b] | 172 | endpoint_t *ep = malloc(sizeof(endpoint_t));
|
---|
| 173 | if (ep == NULL)
|
---|
| 174 | return ENOMEM;
|
---|
| 175 | ret = endpoint_init(ep, address, endpoint, direction,
|
---|
| 176 | transfer_type, speed, max_packet_size);
|
---|
| 177 | if (ret != EOK) {
|
---|
| 178 | free(ep);
|
---|
| 179 | return ret;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | ret = usb_endpoint_manager_register_ep(&hc->ep_manager, ep, size);
|
---|
| 183 | if (ret != EOK) {
|
---|
| 184 | endpoint_destroy(ep);
|
---|
| 185 | }
|
---|
| 186 | return ret;
|
---|
[41b96b4] | 187 | }
|
---|
[1c6a45f] | 188 | /*----------------------------------------------------------------------------*/
|
---|
[b9fa0a9] | 189 | static int unregister_endpoint(
|
---|
| 190 | ddf_fun_t *fun, usb_address_t address,
|
---|
[41b96b4] | 191 | usb_endpoint_t endpoint, usb_direction_t direction)
|
---|
| 192 | {
|
---|
[c2be0e5] | 193 | hc_t *hc = fun_to_hc(fun);
|
---|
| 194 | assert(hc);
|
---|
| 195 | usb_log_debug("Unregister endpoint %d:%d %d.\n",
|
---|
| 196 | address, endpoint, direction);
|
---|
[5876d36] | 197 | return usb_endpoint_manager_unregister_ep(&hc->ep_manager, address,
|
---|
| 198 | endpoint, direction);
|
---|
[41b96b4] | 199 | }
|
---|
[be7950e8] | 200 | /*----------------------------------------------------------------------------*/
|
---|
[41b96b4] | 201 | /** Schedule interrupt out transfer.
|
---|
| 202 | *
|
---|
| 203 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 204 | * complete regardless of the outcome.
|
---|
| 205 | * However, the callback could be called only when this function returns
|
---|
| 206 | * with success status (i.e. returns EOK).
|
---|
| 207 | *
|
---|
| 208 | * @param[in] fun Device function the action was invoked on.
|
---|
| 209 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 210 | * @param[in] data Data to be sent (in USB endianess, allocated and deallocated
|
---|
| 211 | * by the caller).
|
---|
| 212 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 213 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 214 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 215 | * @return Error code.
|
---|
| 216 | */
|
---|
[b9fa0a9] | 217 | static int interrupt_out(
|
---|
[7dfc06fa] | 218 | ddf_fun_t *fun, usb_target_t target, void *data,
|
---|
[b9fa0a9] | 219 | size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
[41b96b4] | 220 | {
|
---|
[6bec59b] | 221 | usb_transfer_batch_t *batch = NULL;
|
---|
| 222 | hc_t *hc = NULL;
|
---|
| 223 | int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
|
---|
| 224 | NULL, 0, NULL, callback, arg, "Interrupt OUT", &hc, &batch);
|
---|
| 225 | if (ret != EOK)
|
---|
| 226 | return ret;
|
---|
[1c6a45f] | 227 | batch_interrupt_out(batch);
|
---|
[6bec59b] | 228 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 229 | if (ret != EOK) {
|
---|
| 230 | batch_dispose(batch);
|
---|
| 231 | }
|
---|
[b9fa0a9] | 232 | return ret;
|
---|
[be7950e8] | 233 | }
|
---|
| 234 | /*----------------------------------------------------------------------------*/
|
---|
[41b96b4] | 235 | /** Schedule interrupt in transfer.
|
---|
| 236 | *
|
---|
| 237 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 238 | * complete regardless of the outcome.
|
---|
| 239 | * However, the callback could be called only when this function returns
|
---|
| 240 | * with success status (i.e. returns EOK).
|
---|
| 241 | *
|
---|
| 242 | * @param[in] fun Device function the action was invoked on.
|
---|
| 243 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 244 | * @param[in] data Buffer where to store the data (in USB endianess,
|
---|
| 245 | * allocated and deallocated by the caller).
|
---|
| 246 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 247 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 248 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 249 | * @return Error code.
|
---|
| 250 | */
|
---|
[b9fa0a9] | 251 | static int interrupt_in(
|
---|
[7dfc06fa] | 252 | ddf_fun_t *fun, usb_target_t target, void *data,
|
---|
[b9fa0a9] | 253 | size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
[41b96b4] | 254 | {
|
---|
[6bec59b] | 255 | usb_transfer_batch_t *batch = NULL;
|
---|
| 256 | hc_t *hc = NULL;
|
---|
| 257 | int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size,
|
---|
| 258 | NULL, 0, callback, NULL, arg, "Interrupt IN", &hc, &batch);
|
---|
| 259 | if (ret != EOK)
|
---|
| 260 | return ret;
|
---|
[1c6a45f] | 261 | batch_interrupt_in(batch);
|
---|
[6bec59b] | 262 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 263 | if (ret != EOK) {
|
---|
| 264 | batch_dispose(batch);
|
---|
| 265 | }
|
---|
[b9fa0a9] | 266 | return ret;
|
---|
[41b96b4] | 267 | }
|
---|
[be7950e8] | 268 | /*----------------------------------------------------------------------------*/
|
---|
[41b96b4] | 269 | /** Schedule bulk out transfer.
|
---|
| 270 | *
|
---|
| 271 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 272 | * complete regardless of the outcome.
|
---|
| 273 | * However, the callback could be called only when this function returns
|
---|
| 274 | * with success status (i.e. returns EOK).
|
---|
| 275 | *
|
---|
| 276 | * @param[in] fun Device function the action was invoked on.
|
---|
| 277 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 278 | * @param[in] data Data to be sent (in USB endianess, allocated and deallocated
|
---|
| 279 | * by the caller).
|
---|
| 280 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 281 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 282 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 283 | * @return Error code.
|
---|
| 284 | */
|
---|
[b9fa0a9] | 285 | static int bulk_out(
|
---|
[7dfc06fa] | 286 | ddf_fun_t *fun, usb_target_t target, void *data,
|
---|
[b9fa0a9] | 287 | size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
[41b96b4] | 288 | {
|
---|
[6bec59b] | 289 | usb_transfer_batch_t *batch = NULL;
|
---|
| 290 | hc_t *hc = NULL;
|
---|
| 291 | int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
|
---|
| 292 | NULL, 0, NULL, callback, arg, "Bulk OUT", &hc, &batch);
|
---|
| 293 | if (ret != EOK)
|
---|
| 294 | return ret;
|
---|
[1c6a45f] | 295 | batch_bulk_out(batch);
|
---|
[6bec59b] | 296 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 297 | if (ret != EOK) {
|
---|
| 298 | batch_dispose(batch);
|
---|
| 299 | }
|
---|
[b9fa0a9] | 300 | return ret;
|
---|
[be7950e8] | 301 | }
|
---|
| 302 | /*----------------------------------------------------------------------------*/
|
---|
[41b96b4] | 303 | /** Schedule bulk in transfer.
|
---|
| 304 | *
|
---|
| 305 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 306 | * complete regardless of the outcome.
|
---|
| 307 | * However, the callback could be called only when this function returns
|
---|
| 308 | * with success status (i.e. returns EOK).
|
---|
| 309 | *
|
---|
| 310 | * @param[in] fun Device function the action was invoked on.
|
---|
| 311 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 312 | * @param[in] data Buffer where to store the data (in USB endianess,
|
---|
| 313 | * allocated and deallocated by the caller).
|
---|
| 314 | * @param[in] size Size of the @p data buffer in bytes.
|
---|
| 315 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 316 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 317 | * @return Error code.
|
---|
| 318 | */
|
---|
[b9fa0a9] | 319 | static int bulk_in(
|
---|
[7dfc06fa] | 320 | ddf_fun_t *fun, usb_target_t target, void *data,
|
---|
[b9fa0a9] | 321 | size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
[41b96b4] | 322 | {
|
---|
[6bec59b] | 323 | usb_transfer_batch_t *batch = NULL;
|
---|
| 324 | hc_t *hc = NULL;
|
---|
| 325 | int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size,
|
---|
| 326 | NULL, 0, callback, NULL, arg, "Bulk IN", &hc, &batch);
|
---|
| 327 | if (ret != EOK)
|
---|
| 328 | return ret;
|
---|
[1c6a45f] | 329 | batch_bulk_in(batch);
|
---|
[6bec59b] | 330 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 331 | if (ret != EOK) {
|
---|
| 332 | batch_dispose(batch);
|
---|
| 333 | }
|
---|
[b9fa0a9] | 334 | return ret;
|
---|
[41b96b4] | 335 | }
|
---|
[be7950e8] | 336 | /*----------------------------------------------------------------------------*/
|
---|
[41b96b4] | 337 | /** Schedule control write transfer.
|
---|
| 338 | *
|
---|
| 339 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 340 | * complete regardless of the outcome.
|
---|
| 341 | * However, the callback could be called only when this function returns
|
---|
| 342 | * with success status (i.e. returns EOK).
|
---|
| 343 | *
|
---|
| 344 | * @param[in] fun Device function the action was invoked on.
|
---|
| 345 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 346 | * @param[in] setup_packet Setup packet buffer (in USB endianess, allocated
|
---|
| 347 | * and deallocated by the caller).
|
---|
| 348 | * @param[in] setup_packet_size Size of @p setup_packet buffer in bytes.
|
---|
| 349 | * @param[in] data_buffer Data buffer (in USB endianess, allocated and
|
---|
| 350 | * deallocated by the caller).
|
---|
| 351 | * @param[in] data_buffer_size Size of @p data_buffer buffer in bytes.
|
---|
| 352 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 353 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 354 | * @return Error code.
|
---|
| 355 | */
|
---|
[b9fa0a9] | 356 | static int control_write(
|
---|
[7dfc06fa] | 357 | ddf_fun_t *fun, usb_target_t target,
|
---|
[1c6a45f] | 358 | void *setup_data, size_t setup_size, void *data, size_t size,
|
---|
[41b96b4] | 359 | usbhc_iface_transfer_out_callback_t callback, void *arg)
|
---|
| 360 | {
|
---|
[6bec59b] | 361 | usb_transfer_batch_t *batch = NULL;
|
---|
| 362 | hc_t *hc = NULL;
|
---|
| 363 | int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
|
---|
| 364 | setup_data, setup_size, NULL, callback, arg, "Control WRITE",
|
---|
| 365 | &hc, &batch);
|
---|
| 366 | if (ret != EOK)
|
---|
| 367 | return ret;
|
---|
[ba038f4] | 368 | usb_endpoint_manager_reset_if_need(&hc->ep_manager, target, setup_data);
|
---|
[1c6a45f] | 369 | batch_control_write(batch);
|
---|
[6bec59b] | 370 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 371 | if (ret != EOK) {
|
---|
| 372 | batch_dispose(batch);
|
---|
| 373 | }
|
---|
[b9fa0a9] | 374 | return ret;
|
---|
[be7950e8] | 375 | }
|
---|
| 376 | /*----------------------------------------------------------------------------*/
|
---|
[41b96b4] | 377 | /** Schedule control read transfer.
|
---|
| 378 | *
|
---|
| 379 | * The callback is supposed to be called once the transfer (on the wire) is
|
---|
| 380 | * complete regardless of the outcome.
|
---|
| 381 | * However, the callback could be called only when this function returns
|
---|
| 382 | * with success status (i.e. returns EOK).
|
---|
| 383 | *
|
---|
| 384 | * @param[in] fun Device function the action was invoked on.
|
---|
| 385 | * @param[in] target Target pipe (address and endpoint number) specification.
|
---|
| 386 | * @param[in] setup_packet Setup packet buffer (in USB endianess, allocated
|
---|
| 387 | * and deallocated by the caller).
|
---|
| 388 | * @param[in] setup_packet_size Size of @p setup_packet buffer in bytes.
|
---|
| 389 | * @param[in] data_buffer Buffer where to store the data (in USB endianess,
|
---|
| 390 | * allocated and deallocated by the caller).
|
---|
| 391 | * @param[in] data_buffer_size Size of @p data_buffer buffer in bytes.
|
---|
| 392 | * @param[in] callback Callback to be issued once the transfer is complete.
|
---|
| 393 | * @param[in] arg Pass-through argument to the callback.
|
---|
| 394 | * @return Error code.
|
---|
| 395 | */
|
---|
[b9fa0a9] | 396 | static int control_read(
|
---|
[7dfc06fa] | 397 | ddf_fun_t *fun, usb_target_t target,
|
---|
[1c6a45f] | 398 | void *setup_data, size_t setup_size, void *data, size_t size,
|
---|
[41b96b4] | 399 | usbhc_iface_transfer_in_callback_t callback, void *arg)
|
---|
| 400 | {
|
---|
[6bec59b] | 401 | usb_transfer_batch_t *batch = NULL;
|
---|
| 402 | hc_t *hc = NULL;
|
---|
| 403 | int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
|
---|
| 404 | setup_data, setup_size, callback, NULL, arg, "Control READ",
|
---|
| 405 | &hc, &batch);
|
---|
| 406 | if (ret != EOK)
|
---|
| 407 | return ret;
|
---|
[1c6a45f] | 408 | batch_control_read(batch);
|
---|
[6bec59b] | 409 | ret = hc_schedule(hc, batch);
|
---|
[1c6a45f] | 410 | if (ret != EOK) {
|
---|
| 411 | batch_dispose(batch);
|
---|
| 412 | }
|
---|
[b9fa0a9] | 413 | return ret;
|
---|
[41b96b4] | 414 | }
|
---|
[be7950e8] | 415 | /*----------------------------------------------------------------------------*/
|
---|
[bab71635] | 416 | usbhc_iface_t hc_iface = {
|
---|
[41b96b4] | 417 | .request_address = request_address,
|
---|
| 418 | .bind_address = bind_address,
|
---|
| 419 | .release_address = release_address,
|
---|
| 420 |
|
---|
| 421 | .register_endpoint = register_endpoint,
|
---|
| 422 | .unregister_endpoint = unregister_endpoint,
|
---|
| 423 |
|
---|
| 424 | .interrupt_out = interrupt_out,
|
---|
| 425 | .interrupt_in = interrupt_in,
|
---|
| 426 |
|
---|
| 427 | .bulk_out = bulk_out,
|
---|
| 428 | .bulk_in = bulk_in,
|
---|
| 429 |
|
---|
| 430 | .control_write = control_write,
|
---|
[1c6a45f] | 431 | .control_read = control_read,
|
---|
[41b96b4] | 432 | };
|
---|
| 433 | /**
|
---|
| 434 | * @}
|
---|
| 435 | */
|
---|