source: mainline/uspace/drv/uhci-hcd/iface.c@ 2e6bbcf

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2e6bbcf was 2e6bbcf, checked in by Jan Vesely <jano.vesely@…>, 15 years ago

Use one function to setup all transfers.

  • Property mode set to 100644
File size: 20.2 KB
RevLine 
[4317827]1/*
[c56dbe0]2 * Copyright (c) 2011 Vojtech Horky, Jan Vesely
[4317827]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 */
[17ceb72]28/** @addtogroup drvusbuhcihc
[c56dbe0]29 * @{
30 */
31/** @file
[17ceb72]32 * @brief UHCI driver hc interface implementation
[c56dbe0]33 */
[eb1a2f4]34#include <ddf/driver.h>
[1c6a45f]35#include <errno.h>
[c56dbe0]36
[1669a73]37#include <usb/debug.h>
[8dc762e0]38#include <usb/host/endpoint.h>
[1669a73]39
[3515533]40#include "iface.h"
[c01cd32]41#include "hc.h"
[b4875e67]42
[2e6bbcf]43static 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);
55
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
65 const size_t bw = bandwidth_count_usb11(
66 ep->speed, ep->transfer_type, size, ep->max_packet_size);
67 if (res_bw < bw) {
68 usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
69 "but only %zu is reserved.\n",
70 name, target.address, target.endpoint, bw, res_bw);
71 return ENOSPC;
72 }
73 usb_log_debug("%s %d:%d %zu(%zu).\n",
74 name, target.address, target.endpoint, size, ep->max_packet_size);
75
76 assert(ep->speed ==
77 usb_device_keeper_get_speed(&(*hc)->manager, target.address));
78// assert(ep->max_packet_size == max_packet_size);
79// assert(ep->transfer_type == USB_TRANSFER_CONTROL);
80
81 *batch =
82 batch_get(fun, ep, data, size, setup_data, setup_size,
83 in, out, arg);
84 if (!batch)
85 return ENOMEM;
86 return EOK;
87}
88
89
[a7e2f0d]90/** Reserve default address interface function
91 *
92 * @param[in] fun DDF function that was called.
93 * @param[in] speed Speed to associate with the new default address.
94 * @return Error code.
95 */
[eb1a2f4]96static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
[86b39f7e]97{
[eb1a2f4]98 assert(fun);
[c01cd32]99 hc_t *hc = fun_to_hc(fun);
[86b39f7e]100 assert(hc);
[1a93bb0]101 usb_log_debug("Default address request with speed %d.\n", speed);
[62ed5bc]102 usb_device_keeper_reserve_default_address(&hc->manager, speed);
[86b39f7e]103 return EOK;
[fb8927d]104#if 0
105 endpoint_t *ep = malloc(sizeof(endpoint_t));
106 if (ep == NULL)
107 return ENOMEM;
108 const size_t max_packet_size = speed == USB_SPEED_LOW ? 8 : 64;
109 endpoint_init(ep, USB_TRANSFER_CONTROL, speed, max_packet_size);
110 int ret;
111try_retgister:
112 ret = usb_endpoint_manager_register_ep(&hc->ep_manager,
113 USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH, ep, endpoint_destroy, 0);
114 if (ret == EEXISTS) {
115 async_usleep(1000);
116 goto try_retgister;
117 }
118 if (ret != EOK) {
119 endpoint_destroy(ep);
120 }
121 return ret;
122#endif
[86b39f7e]123}
124/*----------------------------------------------------------------------------*/
[a7e2f0d]125/** Release default address interface function
126 *
127 * @param[in] fun DDF function that was called.
128 * @return Error code.
129 */
[eb1a2f4]130static int release_default_address(ddf_fun_t *fun)
[86b39f7e]131{
[eb1a2f4]132 assert(fun);
[c01cd32]133 hc_t *hc = fun_to_hc(fun);
[86b39f7e]134 assert(hc);
[1a93bb0]135 usb_log_debug("Default address release.\n");
[fb8927d]136// return usb_endpoint_manager_unregister_ep(&hc->ep_manager,
137// USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH);
[62ed5bc]138 usb_device_keeper_release_default_address(&hc->manager);
[86b39f7e]139 return EOK;
140}
141/*----------------------------------------------------------------------------*/
[a7e2f0d]142/** Request address interface function
143 *
144 * @param[in] fun DDF function that was called.
145 * @param[in] speed Speed to associate with the new default address.
146 * @param[out] address Place to write a new address.
147 * @return Error code.
148 */
[b9fa0a9]149static int request_address(
150 ddf_fun_t *fun, usb_speed_t speed, usb_address_t *address)
[86b39f7e]151{
[eb1a2f4]152 assert(fun);
[c01cd32]153 hc_t *hc = fun_to_hc(fun);
[86b39f7e]154 assert(hc);
[1a93bb0]155 assert(address);
156
157 usb_log_debug("Address request with speed %d.\n", speed);
[62ed5bc]158 *address = device_keeper_get_free_address(&hc->manager, speed);
[1a93bb0]159 usb_log_debug("Address request with result: %d.\n", *address);
[86b39f7e]160 if (*address <= 0)
[1c6a45f]161 return *address;
[86b39f7e]162 return EOK;
163}
164/*----------------------------------------------------------------------------*/
[a7e2f0d]165/** Bind address interface function
166 *
167 * @param[in] fun DDF function that was called.
168 * @param[in] address Address of the device
169 * @param[in] handle Devman handle of the device driver.
170 * @return Error code.
171 */
[86b39f7e]172static int bind_address(
[eb1a2f4]173 ddf_fun_t *fun, usb_address_t address, devman_handle_t handle)
[86b39f7e]174{
[eb1a2f4]175 assert(fun);
[c01cd32]176 hc_t *hc = fun_to_hc(fun);
[86b39f7e]177 assert(hc);
[1a93bb0]178 usb_log_debug("Address bind %d-%d.\n", address, handle);
[62ed5bc]179 usb_device_keeper_bind(&hc->manager, address, handle);
[86b39f7e]180 return EOK;
181}
182/*----------------------------------------------------------------------------*/
[a7e2f0d]183/** Release address interface function
184 *
185 * @param[in] fun DDF function that was called.
186 * @param[in] address USB address to be released.
187 * @return Error code.
188 */
[eb1a2f4]189static int release_address(ddf_fun_t *fun, usb_address_t address)
[86b39f7e]190{
[eb1a2f4]191 assert(fun);
[c01cd32]192 hc_t *hc = fun_to_hc(fun);
[86b39f7e]193 assert(hc);
[1a93bb0]194 usb_log_debug("Address release %d.\n", address);
[62ed5bc]195 usb_device_keeper_release(&hc->manager, address);
[86b39f7e]196 return EOK;
[4317827]197}
[3515533]198/*----------------------------------------------------------------------------*/
[8870230]199static int register_endpoint(
200 ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint,
201 usb_transfer_type_t transfer_type, usb_direction_t direction,
202 size_t max_packet_size, unsigned int interval)
203{
[a1313b8c]204 hc_t *hc = fun_to_hc(fun);
205 assert(hc);
206 const usb_speed_t speed =
207 usb_device_keeper_get_speed(&hc->manager, address);
[8dc762e0]208 const size_t size =
209 (transfer_type == USB_TRANSFER_INTERRUPT
210 || transfer_type == USB_TRANSFER_ISOCHRONOUS) ?
211 max_packet_size : 0;
[1e70157]212 int ret;
[6ce42e85]213
214 endpoint_t *ep = malloc(sizeof(endpoint_t));
215 if (ep == NULL)
216 return ENOMEM;
[0aae4a6a]217 ret = endpoint_init(ep, address, endpoint, direction,
218 transfer_type, speed, max_packet_size);
[1e70157]219 if (ret != EOK) {
220 free(ep);
221 return ret;
222 }
[a1313b8c]223
224 usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n",
225 address, endpoint, usb_str_transfer_type(transfer_type),
226 usb_str_speed(speed), direction, size, max_packet_size, interval);
[6ce42e85]227
[92d6868]228 ret = usb_endpoint_manager_register_ep(&hc->ep_manager, ep, size);
[6ce42e85]229 if (ret != EOK) {
230 endpoint_destroy(ep);
[1e70157]231 } else {
[f567bcf]232 usb_device_keeper_add_ep(&hc->manager, address, ep);
[6ce42e85]233 }
234 return ret;
[8870230]235}
236/*----------------------------------------------------------------------------*/
237static int unregister_endpoint(
238 ddf_fun_t *fun, usb_address_t address,
239 usb_endpoint_t endpoint, usb_direction_t direction)
240{
[a1313b8c]241 hc_t *hc = fun_to_hc(fun);
242 assert(hc);
243 usb_log_debug("Unregister endpoint %d:%d %d.\n",
244 address, endpoint, direction);
[6ce42e85]245 return usb_endpoint_manager_unregister_ep(&hc->ep_manager, address,
246 endpoint, direction);
[8870230]247}
248/*----------------------------------------------------------------------------*/
[a7e2f0d]249/** Interrupt out transaction interface function
250 *
251 * @param[in] fun DDF function that was called.
252 * @param[in] target USB device to write to.
253 * @param[in] max_packet_size maximum size of data packet the device accepts
254 * @param[in] data Source of data.
255 * @param[in] size Size of data source.
256 * @param[in] callback Function to call on transaction completion
257 * @param[in] arg Additional for callback function.
258 * @return Error code.
259 */
[b9fa0a9]260static int interrupt_out(
261 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
262 size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
[4317827]263{
[2e6bbcf]264 usb_transfer_batch_t *batch = NULL;
265 hc_t *hc = NULL;
266 int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
267 NULL, 0, NULL, callback, arg, "Interrupt OUT", &hc, &batch);
268 if (ret != EOK)
269 return ret;
270#if 0
[1a93bb0]271 assert(fun);
[c01cd32]272 hc_t *hc = fun_to_hc(fun);
[1a93bb0]273 assert(hc);
[fe10e72]274
[48563a3]275 usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n",
276 target.address, target.endpoint, size, max_packet_size);
277
[391d55b]278 size_t res_bw;
[8dc762e0]279 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
[391d55b]280 target.address, target.endpoint, USB_DIRECTION_OUT, &res_bw);
[6ce42e85]281 if (ep == NULL) {
282 usb_log_error("Endpoint(%d:%d) not registered for INT OUT.\n",
283 target.address, target.endpoint);
284 return ENOENT;
285 }
[391d55b]286 const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,
287 size, ep->max_packet_size);
[8f30c2e]288 if (res_bw < bw) {
[2e6bbcf]289 usb_log_error("Endpoint(%d:%d) INT OUT needs %zu bw "
[391d55b]290 "but only %zu is reserved.\n",
291 target.address, target.endpoint, bw, res_bw);
[2e6bbcf]292 return ENOSPC;
[391d55b]293 }
[2e6bbcf]294
[6ce42e85]295 assert(ep->speed ==
296 usb_device_keeper_get_speed(&hc->manager, target.address));
297 assert(ep->max_packet_size == max_packet_size);
298 assert(ep->transfer_type == USB_TRANSFER_INTERRUPT);
299
[b9fa0a9]300 usb_transfer_batch_t *batch =
[feb10c88]301 batch_get(fun, ep, data, size, NULL, 0, NULL, callback, arg);
[83c439c]302 if (!batch)
[7e62b62]303 return ENOMEM;
[2e6bbcf]304#endif
[5620bd4]305 batch_interrupt_out(batch);
[2e6bbcf]306 ret = hc_schedule(hc, batch);
[3bd96bb]307 if (ret != EOK) {
308 batch_dispose(batch);
309 }
[b9fa0a9]310 return ret;
[4317827]311}
[3515533]312/*----------------------------------------------------------------------------*/
[a7e2f0d]313/** Interrupt in transaction interface function
314 *
315 * @param[in] fun DDF function that was called.
316 * @param[in] target USB device to write to.
317 * @param[in] max_packet_size maximum size of data packet the device accepts
318 * @param[out] data Data destination.
319 * @param[in] size Size of data source.
320 * @param[in] callback Function to call on transaction completion
321 * @param[in] arg Additional for callback function.
322 * @return Error code.
323 */
[b9fa0a9]324static int interrupt_in(
325 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
326 size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
[4317827]327{
[2e6bbcf]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, "Interrupt IN", &hc, &batch);
332 if (ret != EOK)
333 return ret;
334#if 0
[1a93bb0]335 assert(fun);
[c01cd32]336 hc_t *hc = fun_to_hc(fun);
[1a93bb0]337 assert(hc);
[6ce42e85]338
[48563a3]339 usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n",
340 target.address, target.endpoint, size, max_packet_size);
[fe10e72]341
[391d55b]342 size_t res_bw;
[8dc762e0]343 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
[391d55b]344 target.address, target.endpoint, USB_DIRECTION_IN, &res_bw);
[6ce42e85]345 if (ep == NULL) {
346 usb_log_error("Endpoint(%d:%d) not registered for INT IN.\n",
[391d55b]347 target.address, target.endpoint);
[2e6bbcf]348 return ENOSPC;
[6ce42e85]349 }
[391d55b]350 const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,
351 size, ep->max_packet_size);
[8f30c2e]352 if (res_bw < bw) {
[391d55b]353 usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw "
354 "but only %zu bw is reserved.\n",
355 target.address, target.endpoint, bw, res_bw);
356 return ENOENT;
357 }
358
[6ce42e85]359 assert(ep->speed ==
360 usb_device_keeper_get_speed(&hc->manager, target.address));
361 assert(ep->max_packet_size == max_packet_size);
362 assert(ep->transfer_type == USB_TRANSFER_INTERRUPT);
363
[b9fa0a9]364 usb_transfer_batch_t *batch =
[feb10c88]365 batch_get(fun, ep, data, size, NULL, 0, callback, NULL, arg);
[83c439c]366 if (!batch)
[7e62b62]367 return ENOMEM;
[2e6bbcf]368#endif
[5620bd4]369 batch_interrupt_in(batch);
[2e6bbcf]370 ret = hc_schedule(hc, batch);
[3bd96bb]371 if (ret != EOK) {
372 batch_dispose(batch);
373 }
[b9fa0a9]374 return ret;
[4317827]375}
[3515533]376/*----------------------------------------------------------------------------*/
[a7e2f0d]377/** Bulk out transaction interface function
378 *
379 * @param[in] fun DDF function that was called.
380 * @param[in] target USB device to write to.
381 * @param[in] max_packet_size maximum size of data packet the device accepts
382 * @param[in] data Source of data.
383 * @param[in] size Size of data source.
384 * @param[in] callback Function to call on transaction completion
385 * @param[in] arg Additional for callback function.
386 * @return Error code.
387 */
[b9fa0a9]388static int bulk_out(
389 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
390 size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
[0e06a14]391{
[2e6bbcf]392 usb_transfer_batch_t *batch = NULL;
393 hc_t *hc = NULL;
394 int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
395 NULL, 0, NULL, callback, arg, "Bulk OUT", &hc, &batch);
396 if (ret != EOK)
397 return ret;
398#if 0
[0e06a14]399 assert(fun);
[c01cd32]400 hc_t *hc = fun_to_hc(fun);
[0e06a14]401 assert(hc);
402
403 usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n",
404 target.address, target.endpoint, size, max_packet_size);
405
[8dc762e0]406 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
[6ce42e85]407 target.address, target.endpoint, USB_DIRECTION_OUT, NULL);
408 if (ep == NULL) {
409 usb_log_error("Endpoint(%d:%d) not registered for BULK OUT.\n",
410 target.address, target.endpoint);
411 return ENOENT;
412 }
413 assert(ep->speed ==
414 usb_device_keeper_get_speed(&hc->manager, target.address));
415 assert(ep->max_packet_size == max_packet_size);
416 assert(ep->transfer_type == USB_TRANSFER_BULK);
417
[b9fa0a9]418 usb_transfer_batch_t *batch =
[feb10c88]419 batch_get(fun, ep, data, size, NULL, 0, NULL, callback, arg);
[0e06a14]420 if (!batch)
421 return ENOMEM;
[2e6bbcf]422#endif
[5620bd4]423 batch_bulk_out(batch);
[2e6bbcf]424 ret = hc_schedule(hc, batch);
[3bd96bb]425 if (ret != EOK) {
426 batch_dispose(batch);
427 }
[b9fa0a9]428 return ret;
[0e06a14]429}
430/*----------------------------------------------------------------------------*/
[a7e2f0d]431/** Bulk in transaction interface function
432 *
433 * @param[in] fun DDF function that was called.
434 * @param[in] target USB device to write to.
435 * @param[in] max_packet_size maximum size of data packet the device accepts
436 * @param[out] data Data destination.
437 * @param[in] size Size of data source.
438 * @param[in] callback Function to call on transaction completion
439 * @param[in] arg Additional for callback function.
440 * @return Error code.
441 */
[b9fa0a9]442static int bulk_in(
443 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size, void *data,
444 size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
[0e06a14]445{
[2e6bbcf]446 usb_transfer_batch_t *batch = NULL;
447 hc_t *hc = NULL;
448 int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size,
449 NULL, 0, callback, NULL, arg, "Bulk IN", &hc, &batch);
450 if (ret != EOK)
451 return ret;
452#if 0
[0e06a14]453 assert(fun);
[c01cd32]454 hc_t *hc = fun_to_hc(fun);
[0e06a14]455 assert(hc);
[2e6bbcf]456
[0e06a14]457 usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
458 target.address, target.endpoint, size, max_packet_size);
459
[8dc762e0]460 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
[6ce42e85]461 target.address, target.endpoint, USB_DIRECTION_IN, NULL);
462 if (ep == NULL) {
463 usb_log_error("Endpoint(%d:%d) not registered for BULK IN.\n",
464 target.address, target.endpoint);
465 return ENOENT;
466 }
467 assert(ep->speed ==
468 usb_device_keeper_get_speed(&hc->manager, target.address));
469 assert(ep->max_packet_size == max_packet_size);
470 assert(ep->transfer_type == USB_TRANSFER_BULK);
471
[b9fa0a9]472 usb_transfer_batch_t *batch =
[feb10c88]473 batch_get(fun, ep, data, size, NULL, 0, callback, NULL, arg);
[0e06a14]474 if (!batch)
475 return ENOMEM;
[2e6bbcf]476#endif
[5620bd4]477 batch_bulk_in(batch);
[2e6bbcf]478 ret = hc_schedule(hc, batch);
[3bd96bb]479 if (ret != EOK) {
480 batch_dispose(batch);
481 }
[b9fa0a9]482 return ret;
[0e06a14]483}
484/*----------------------------------------------------------------------------*/
[a7e2f0d]485/** Control write transaction interface function
486 *
487 * @param[in] fun DDF function that was called.
488 * @param[in] target USB device to write to.
489 * @param[in] max_packet_size maximum size of data packet the device accepts.
[c61338a]490 * @param[in] setup_data Data to send with SETUP transfer.
491 * @param[in] setup_size Size of data to send with SETUP transfer (always 8B).
[a7e2f0d]492 * @param[in] data Source of data.
493 * @param[in] size Size of data source.
494 * @param[in] callback Function to call on transaction completion.
495 * @param[in] arg Additional for callback function.
496 * @return Error code.
497 */
[b9fa0a9]498static int control_write(
499 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size,
[a72620d]500 void *setup_data, size_t setup_size, void *data, size_t size,
501 usbhc_iface_transfer_out_callback_t callback, void *arg)
502{
[2e6bbcf]503 usb_transfer_batch_t *batch = NULL;
504 hc_t *hc = NULL;
505 int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
506 setup_data, setup_size, NULL, callback, arg, "Control WRITE",
507 &hc, &batch);
508 if (ret != EOK)
509 return ret;
510#if 0
[1a93bb0]511 assert(fun);
[c01cd32]512 hc_t *hc = fun_to_hc(fun);
[1a93bb0]513 assert(hc);
[8f30c2e]514
515 usb_log_debug("Control WRITE %d:%d %zu(%zu).\n",
516 target.address, target.endpoint, size, max_packet_size);
517
[8dc762e0]518 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
[6ce42e85]519 target.address, target.endpoint, USB_DIRECTION_BOTH, NULL);
520 if (ep == NULL) {
[8f30c2e]521 usb_log_error("Endpoint(%d:%d) not registered for CONTROL.\n",
[6ce42e85]522 target.address, target.endpoint);
[8f30c2e]523 return ENOENT;
[6ce42e85]524 }
[8f30c2e]525 assert(ep->speed ==
526 usb_device_keeper_get_speed(&hc->manager, target.address));
527 assert(ep->max_packet_size == max_packet_size);
528 assert(ep->transfer_type == USB_TRANSFER_CONTROL);
[f241b05b]529
[5620bd4]530 if (setup_size != 8)
531 return EINVAL;
532
[b9fa0a9]533 usb_transfer_batch_t *batch =
[feb10c88]534 batch_get(fun, ep, data, size, setup_data, setup_size,
535 NULL, callback, arg);
[83c439c]536 if (!batch)
[f241b05b]537 return ENOMEM;
[2e6bbcf]538#endif
[62ed5bc]539 usb_device_keeper_reset_if_need(&hc->manager, target, setup_data);
[83c439c]540 batch_control_write(batch);
[2e6bbcf]541 ret = hc_schedule(hc, batch);
[3bd96bb]542 if (ret != EOK) {
543 batch_dispose(batch);
544 }
[b9fa0a9]545 return ret;
[a72620d]546}
547/*----------------------------------------------------------------------------*/
[a7e2f0d]548/** Control read transaction interface function
549 *
550 * @param[in] fun DDF function that was called.
551 * @param[in] target USB device to write to.
552 * @param[in] max_packet_size maximum size of data packet the device accepts.
553 * @param[in] setup_data Data to send with SETUP packet.
554 * @param[in] setup_size Size of data to send with SETUP packet (should be 8B).
555 * @param[out] data Source of data.
556 * @param[in] size Size of data source.
557 * @param[in] callback Function to call on transaction completion.
558 * @param[in] arg Additional for callback function.
559 * @return Error code.
560 */
[b9fa0a9]561static int control_read(
562 ddf_fun_t *fun, usb_target_t target, size_t max_packet_size,
[a72620d]563 void *setup_data, size_t setup_size, void *data, size_t size,
564 usbhc_iface_transfer_in_callback_t callback, void *arg)
565{
[2e6bbcf]566 usb_transfer_batch_t *batch = NULL;
567 hc_t *hc = NULL;
568 int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
569 setup_data, setup_size, callback, NULL, arg, "Control READ",
570 &hc, &batch);
571 if (ret != EOK)
572 return ret;
573#if 0
[1a93bb0]574 assert(fun);
[c01cd32]575 hc_t *hc = fun_to_hc(fun);
[1a93bb0]576 assert(hc);
[f241b05b]577
[8f30c2e]578 usb_log_debug("Control READ %d:%d %zu(%zu).\n",
579 target.address, target.endpoint, size, max_packet_size);
580
[8dc762e0]581 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
[6ce42e85]582 target.address, target.endpoint, USB_DIRECTION_BOTH, NULL);
583 if (ep == NULL) {
[8f30c2e]584 usb_log_error("Endpoint(%d:%d) not registered for CONTROL.\n",
585 target.address, target.endpoint);
586 return ENOENT;
[6ce42e85]587 }
[8f30c2e]588 assert(ep->speed ==
589 usb_device_keeper_get_speed(&hc->manager, target.address));
590 assert(ep->max_packet_size == max_packet_size);
591 assert(ep->transfer_type == USB_TRANSFER_CONTROL);
592
[b9fa0a9]593 usb_transfer_batch_t *batch =
[feb10c88]594 batch_get(fun, ep, data, size, setup_data, setup_size,
595 callback, NULL, arg);
[83c439c]596 if (!batch)
[f241b05b]597 return ENOMEM;
[2e6bbcf]598#endif
[83c439c]599 batch_control_read(batch);
[2e6bbcf]600 ret = hc_schedule(hc, batch);
[3bd96bb]601 if (ret != EOK) {
602 batch_dispose(batch);
603 }
[b9fa0a9]604 return ret;
[a72620d]605}
[9e80904]606/*----------------------------------------------------------------------------*/
[c01cd32]607usbhc_iface_t hc_iface = {
[86b39f7e]608 .reserve_default_address = reserve_default_address,
609 .release_default_address = release_default_address,
610 .request_address = request_address,
611 .bind_address = bind_address,
612 .release_address = release_address,
[3515533]613
[8870230]614 .register_endpoint = register_endpoint,
615 .unregister_endpoint = unregister_endpoint,
616
[4317827]617 .interrupt_out = interrupt_out,
618 .interrupt_in = interrupt_in,
[3515533]619
[0e06a14]620 .bulk_out = bulk_out,
[1c6a45f]621 .bulk_in = bulk_in,
[0e06a14]622
[a72620d]623 .control_write = control_write,
[1c6a45f]624 .control_read = control_read,
[4317827]625};
[c56dbe0]626/**
627 * @}
628 */
Note: See TracBrowser for help on using the repository browser.