source: mainline/uspace/lib/usbhost/src/ddf_helpers.c@ 1845003

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

libusbhost: Implement usb iface data communication.

  • Property mode set to 100644
File size: 18.3 KB
Line 
1/*
2 * Copyright (c) 2013 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 *
34 */
35
36#include <usb_iface.h>
37#include <usb/classes/classes.h>
38#include <usb/debug.h>
39#include <usb/descriptor.h>
40#include <usb/request.h>
41#include <errno.h>
42#include <str_error.h>
43
44#include "ddf_helpers.h"
45
46#define CTRL_PIPE_MIN_PACKET_SIZE 8
47
48extern usbhc_iface_t hcd_iface;
49
50typedef struct hc_dev {
51 ddf_fun_t *hc_fun;
52 list_t devices;
53 fibril_mutex_t guard;
54} hc_dev_t;
55
56static hc_dev_t *dev_to_hc_dev(ddf_dev_t *dev)
57{
58 return ddf_dev_data_get(dev);
59}
60
61hcd_t *dev_to_hcd(ddf_dev_t *dev)
62{
63 hc_dev_t *hc_dev = dev_to_hc_dev(dev);
64 if (!hc_dev || !hc_dev->hc_fun) {
65 usb_log_error("Invalid HCD device.\n");
66 return NULL;
67 }
68 return ddf_fun_data_get(hc_dev->hc_fun);
69}
70
71typedef struct usb_dev {
72 link_t link;
73 ddf_fun_t *fun;
74 usb_address_t address;
75 usb_speed_t speed;
76 devman_handle_t hc_handle;
77} usb_dev_t;
78
79/** Register endpoint interface function.
80 * @param fun DDF function.
81 * @param address USB address of the device.
82 * @param endpoint USB endpoint number to be registered.
83 * @param transfer_type Endpoint's transfer type.
84 * @param direction USB communication direction the endpoint is capable of.
85 * @param max_packet_size Maximu size of packets the endpoint accepts.
86 * @param interval Preferred timeout between communication.
87 * @return Error code.
88 */
89static int register_endpoint(
90 ddf_fun_t *fun, usb_endpoint_t endpoint,
91 usb_transfer_type_t transfer_type, usb_direction_t direction,
92 size_t max_packet_size, unsigned interval)
93{
94 assert(fun);
95 hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
96 usb_dev_t *dev = ddf_fun_data_get(fun);
97 assert(hcd);
98 assert(dev);
99 const size_t size = max_packet_size;
100 const usb_target_t target =
101 {{.address = dev->address, .endpoint = endpoint}};
102
103 usb_log_debug("Register endpoint %d:%d %s-%s %zuB %ums.\n",
104 dev->address, endpoint, usb_str_transfer_type(transfer_type),
105 usb_str_direction(direction), max_packet_size, interval);
106
107 return hcd_add_ep(hcd, target, direction, transfer_type,
108 max_packet_size, size);
109}
110
111/** Unregister endpoint interface function.
112 * @param fun DDF function.
113 * @param address USB address of the endpoint.
114 * @param endpoint USB endpoint number.
115 * @param direction Communication direction of the enpdoint to unregister.
116 * @return Error code.
117 */
118static int unregister_endpoint(
119 ddf_fun_t *fun, usb_endpoint_t endpoint, usb_direction_t direction)
120{
121 assert(fun);
122 hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
123 usb_dev_t *dev = ddf_fun_data_get(fun);
124 assert(hcd);
125 assert(dev);
126 const usb_target_t target =
127 {{.address = dev->address, .endpoint = endpoint}};
128 usb_log_debug("Unregister endpoint %d:%d %s.\n",
129 dev->address, endpoint, usb_str_direction(direction));
130 return hcd_remove_ep(hcd, target, direction);
131}
132
133static int reserve_default_address(ddf_fun_t *fun, usb_speed_t speed)
134{
135 assert(fun);
136 hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
137 usb_dev_t *dev = ddf_fun_data_get(fun);
138 assert(hcd);
139 assert(dev);
140
141 usb_log_debug("Device %d requested default address at %s speed\n",
142 dev->address, usb_str_speed(speed));
143 return hcd_reserve_default_address(hcd, speed);
144}
145
146static int release_default_address(ddf_fun_t *fun)
147{
148 assert(fun);
149 hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
150 usb_dev_t *dev = ddf_fun_data_get(fun);
151 assert(hcd);
152 assert(dev);
153
154 usb_log_debug("Device %d released default address\n", dev->address);
155 return hcd_release_default_address(hcd);
156}
157
158static int device_enumerate(ddf_fun_t *fun, usb_device_handle_t *handle)
159{
160 assert(fun);
161 ddf_dev_t *ddf_dev = ddf_fun_get_dev(fun);
162 usb_dev_t *dev = ddf_fun_data_get(fun);
163 assert(ddf_dev);
164 assert(dev);
165 usb_address_t address = 0;
166 usb_log_debug("Device %d reported a new USB device\n", dev->address);
167 const int ret = hcd_ddf_new_device(ddf_dev, &address);
168 if (ret == EOK && handle)
169 *handle = address;
170 return ret;
171}
172
173static int device_remove(ddf_fun_t *fun, usb_device_handle_t handle)
174{
175 assert(fun);
176 ddf_dev_t *ddf_dev = ddf_fun_get_dev(fun);
177 usb_dev_t *dev = ddf_fun_data_get(fun);
178 assert(ddf_dev);
179 assert(dev);
180 usb_log_debug("Device %d reported removal of device %d\n",
181 dev->address, (int)handle);
182 return hcd_ddf_remove_device(ddf_dev, (usb_address_t)handle);
183}
184
185/** Get USB address assigned to root hub.
186 *
187 * @param[in] fun Root hub function.
188 * @param[out] address Store the address here.
189 * @return Error code.
190 */
191static int get_my_address(ddf_fun_t *fun, usb_address_t *address)
192{
193 assert(fun);
194 if (address != NULL) {
195 usb_dev_t *usb_dev = ddf_fun_data_get(fun);
196 *address = usb_dev->address;
197 }
198 return EOK;
199}
200
201/** Gets handle of the respective hc (this device, hc function).
202 *
203 * @param[in] root_hub_fun Root hub function seeking hc handle.
204 * @param[out] handle Place to write the handle.
205 * @return Error code.
206 */
207static int get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
208{
209 assert(fun);
210
211 if (handle != NULL) {
212 usb_dev_t *usb_dev = ddf_fun_data_get(fun);
213 *handle = usb_dev->hc_handle;
214 }
215 return EOK;
216}
217
218/** Gets handle of the respective hc (this device, hc function).
219 *
220 * @param[in] root_hub_fun Root hub function seeking hc handle.
221 * @param[out] handle Place to write the handle.
222 * @return Error code.
223 */
224static int get_device_handle(ddf_fun_t *fun, devman_handle_t *handle)
225{
226 assert(fun);
227 if (handle)
228 *handle = ddf_fun_get_handle(fun);
229 return EOK;
230}
231
232/** Inbound communication interface function.
233 * @param fun DDF function.
234 * @param target Communication target.
235 * @param setup_data Data to use in setup stage (control transfers).
236 * @param data Pointer to data buffer.
237 * @param size Size of the data buffer.
238 * @param callback Function to call on communication end.
239 * @param arg Argument passed to the callback function.
240 * @return Error code.
241 */
242static int dev_read(ddf_fun_t *fun, usb_endpoint_t endpoint,
243 uint64_t setup_data, uint8_t *data, size_t size,
244 usbhc_iface_transfer_in_callback_t callback, void *arg)
245{
246 assert(fun);
247 usb_dev_t *usb_dev = ddf_fun_data_get(fun);
248 assert(usb_dev);
249 const usb_target_t target = {{
250 .address = usb_dev->address,
251 .endpoint = endpoint,
252 }};
253 return hcd_send_batch(dev_to_hcd(ddf_fun_get_dev(fun)), target,
254 USB_DIRECTION_IN, data, size, setup_data, callback, NULL, arg,
255 "READ");
256}
257
258/** Outbound communication interface function.
259 * @param fun DDF function.
260 * @param target Communication target.
261 * @param setup_data Data to use in setup stage (control transfers).
262 * @param data Pointer to data buffer.
263 * @param size Size of the data buffer.
264 * @param callback Function to call on communication end.
265 * @param arg Argument passed to the callback function.
266 * @return Error code.
267 */
268static int dev_write(ddf_fun_t *fun, usb_endpoint_t endpoint,
269 uint64_t setup_data, const uint8_t *data, size_t size,
270 usbhc_iface_transfer_out_callback_t callback, void *arg)
271{
272 assert(fun);
273 usb_dev_t *usb_dev = ddf_fun_data_get(fun);
274 assert(usb_dev);
275 const usb_target_t target = {{
276 .address = usb_dev->address,
277 .endpoint = endpoint,
278 }};
279 return hcd_send_batch(dev_to_hcd(ddf_fun_get_dev(fun)),
280 target, USB_DIRECTION_OUT, (uint8_t*)data, size, setup_data, NULL,
281 callback, arg, "WRITE");
282}
283
284/** Root hub USB interface */
285static usb_iface_t usb_iface = {
286 .get_hc_handle = get_hc_handle,
287 .get_my_address = get_my_address,
288
289 .get_device_handle = get_device_handle,
290
291 .reserve_default_address = reserve_default_address,
292 .release_default_address = release_default_address,
293 .device_enumerate = device_enumerate,
294 .device_remove = device_remove,
295 .register_endpoint = register_endpoint,
296 .unregister_endpoint = unregister_endpoint,
297 .read = dev_read,
298 .write = dev_write,
299};
300
301/** Standard USB RH options (device interface) */
302static ddf_dev_ops_t usb_ops = {
303 .interfaces[USB_DEV_IFACE] = &usb_iface,
304};
305
306/** Standard USB HC options (HC interface) */
307static ddf_dev_ops_t hc_ops = {
308 .interfaces[USBHC_DEV_IFACE] = &hcd_iface,
309};
310
311#define GET_DEVICE_DESC(size) \
312{ \
313 .request_type = SETUP_REQUEST_TYPE_DEVICE_TO_HOST \
314 | (USB_REQUEST_TYPE_STANDARD << 5) \
315 | USB_REQUEST_RECIPIENT_DEVICE, \
316 .request = USB_DEVREQ_GET_DESCRIPTOR, \
317 .value = uint16_host2usb(USB_DESCTYPE_DEVICE << 8), \
318 .index = uint16_host2usb(0), \
319 .length = uint16_host2usb(size), \
320};
321
322#define SET_ADDRESS(address) \
323{ \
324 .request_type = SETUP_REQUEST_TYPE_HOST_TO_DEVICE \
325 | (USB_REQUEST_TYPE_STANDARD << 5) \
326 | USB_REQUEST_RECIPIENT_DEVICE, \
327 .request = USB_DEVREQ_SET_ADDRESS, \
328 .value = uint16_host2usb(address), \
329 .index = uint16_host2usb(0), \
330 .length = uint16_host2usb(0), \
331};
332
333int hcd_ddf_add_usb_device(ddf_dev_t *parent,
334 usb_address_t address, usb_speed_t speed, const char *name,
335 const match_id_list_t *mids)
336{
337 assert(parent);
338 hc_dev_t *hc_dev = dev_to_hc_dev(parent);
339 devman_handle_t hc_handle = ddf_fun_get_handle(hc_dev->hc_fun);
340
341 char default_name[10] = { 0 }; /* usbxyz-ss */
342 if (!name) {
343 snprintf(default_name, sizeof(default_name) - 1,
344 "usb%u-%cs", address, usb_str_speed(speed)[0]);
345 name = default_name;
346 }
347
348 //TODO more checks
349 ddf_fun_t *fun = ddf_fun_create(parent, fun_inner, name);
350 if (!fun)
351 return ENOMEM;
352 usb_dev_t *info = ddf_fun_data_alloc(fun, sizeof(usb_dev_t));
353 if (!info) {
354 ddf_fun_destroy(fun);
355 return ENOMEM;
356 }
357 info->address = address;
358 info->speed = speed;
359 info->hc_handle = hc_handle;
360 info->fun = fun;
361 link_initialize(&info->link);
362
363 ddf_fun_set_ops(fun, &usb_ops);
364 list_foreach(mids->ids, iter) {
365 match_id_t *mid = list_get_instance(iter, match_id_t, link);
366 ddf_fun_add_match_id(fun, mid->id, mid->score);
367 }
368
369 int ret = ddf_fun_bind(fun);
370 if (ret != EOK) {
371 ddf_fun_destroy(fun);
372 return ret;
373 }
374
375 list_append(&info->link, &hc_dev->devices);
376 return EOK;
377}
378
379#define ADD_MATCHID_OR_RETURN(list, sc, str, ...) \
380do { \
381 match_id_t *mid = malloc(sizeof(match_id_t)); \
382 if (!mid) { \
383 clean_match_ids(list); \
384 return ENOMEM; \
385 } \
386 char *id = NULL; \
387 int ret = asprintf(&id, str, ##__VA_ARGS__); \
388 if (ret < 0) { \
389 clean_match_ids(list); \
390 free(mid); \
391 return ENOMEM; \
392 } \
393 mid->score = sc; \
394 mid->id = id; \
395 add_match_id(list, mid); \
396} while (0)
397
398
399/* This is a copy of lib/usbdev/src/recognise.c */
400static int create_match_ids(match_id_list_t *l,
401 usb_standard_device_descriptor_t *d)
402{
403 assert(l);
404 assert(d);
405
406 if (d->vendor_id != 0) {
407 /* First, with release number. */
408 ADD_MATCHID_OR_RETURN(l, 100,
409 "usb&vendor=%#04x&product=%#04x&release=%x.%x",
410 d->vendor_id, d->product_id, (d->device_version >> 8),
411 (d->device_version & 0xff));
412
413 /* Next, without release number. */
414 ADD_MATCHID_OR_RETURN(l, 90, "usb&vendor=%#04x&product=%#04x",
415 d->vendor_id, d->product_id);
416 }
417
418 /* Class match id */
419 ADD_MATCHID_OR_RETURN(l, 50, "usb&class=%s",
420 usb_str_class(d->device_class));
421
422 /* As a last resort, try fallback driver. */
423 ADD_MATCHID_OR_RETURN(l, 10, "usb&fallback");
424
425 return EOK;
426
427}
428
429int hcd_ddf_remove_device(ddf_dev_t *device, usb_address_t id)
430{
431 assert(device);
432
433 hcd_t *hcd = dev_to_hcd(device);
434 assert(hcd);
435
436 hc_dev_t *hc_dev = dev_to_hc_dev(device);
437 assert(hc_dev);
438
439 fibril_mutex_lock(&hc_dev->guard);
440
441 usb_dev_t *victim = NULL;
442
443 list_foreach(hc_dev->devices, it) {
444 victim = list_get_instance(it, usb_dev_t, link);
445 if (victim->address == id)
446 break;
447 }
448 if (victim && victim->address == id) {
449 list_remove(&victim->link);
450 fibril_mutex_unlock(&hc_dev->guard);
451 const int ret = ddf_fun_unbind(victim->fun);
452 if (ret == EOK) {
453 ddf_fun_destroy(victim->fun);
454 hcd_release_address(hcd, id);
455 } else {
456 usb_log_warning("Failed to unbind device %d: %s\n",
457 id, str_error(ret));
458 }
459 return EOK;
460 }
461 return ENOENT;
462}
463
464int hcd_ddf_new_device(ddf_dev_t *device, usb_address_t *id)
465{
466 assert(device);
467
468 hcd_t *hcd = dev_to_hcd(device);
469 assert(hcd);
470
471 usb_speed_t speed = USB_SPEED_MAX;
472
473 /* This checks whether the default address is reserved and gets speed */
474 int ret = usb_endpoint_manager_get_info_by_address(&hcd->ep_manager,
475 USB_ADDRESS_DEFAULT, &speed);
476 if (ret != EOK) {
477 return ret;
478 }
479
480 static const usb_target_t default_target = {{
481 .address = USB_ADDRESS_DEFAULT,
482 .endpoint = 0,
483 }};
484
485 const usb_address_t address = hcd_request_address(hcd, speed);
486 if (address < 0)
487 return address;
488
489 const usb_target_t target = {{
490 .address = address,
491 .endpoint = 0,
492 }};
493
494 /* Add default pipe on default address */
495 ret = hcd_add_ep(hcd,
496 default_target, USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL,
497 CTRL_PIPE_MIN_PACKET_SIZE, CTRL_PIPE_MIN_PACKET_SIZE);
498
499 if (ret != EOK) {
500 hcd_release_address(hcd, address);
501 return ret;
502 }
503
504 /* Get max packet size for default pipe */
505 usb_standard_device_descriptor_t desc = { 0 };
506 static const usb_device_request_setup_packet_t get_device_desc_8 =
507 GET_DEVICE_DESC(CTRL_PIPE_MIN_PACKET_SIZE);
508
509 // TODO CALLBACKS
510 ssize_t got = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_IN,
511 &desc, CTRL_PIPE_MIN_PACKET_SIZE, *(uint64_t *)&get_device_desc_8,
512 "read first 8 bytes of dev descriptor");
513
514 if (got != CTRL_PIPE_MIN_PACKET_SIZE) {
515 hcd_remove_ep(hcd, default_target, USB_DIRECTION_BOTH);
516 hcd_release_address(hcd, address);
517 return got < 0 ? got : EOVERFLOW;
518 }
519
520 /* Register EP on the new address */
521 ret = hcd_add_ep(hcd, target, USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL,
522 desc.max_packet_size, desc.max_packet_size);
523 if (ret != EOK) {
524 hcd_remove_ep(hcd, default_target, USB_DIRECTION_BOTH);
525 hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
526 hcd_release_address(hcd, address);
527 return ret;
528 }
529
530 /* Set new address */
531 const usb_device_request_setup_packet_t set_address =
532 SET_ADDRESS(target.address);
533
534 got = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_OUT,
535 NULL, 0, *(uint64_t *)&set_address, "set address");
536
537 hcd_remove_ep(hcd, default_target, USB_DIRECTION_BOTH);
538
539 if (got != 0) {
540 hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
541 hcd_release_address(hcd, address);
542 return got;
543 }
544
545 /* Get std device descriptor */
546 static const usb_device_request_setup_packet_t get_device_desc =
547 GET_DEVICE_DESC(sizeof(desc));
548
549 got = hcd_send_batch_sync(hcd, target, USB_DIRECTION_IN,
550 &desc, sizeof(desc), *(uint64_t *)&get_device_desc,
551 "read device descriptor");
552 if (ret != EOK) {
553 hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
554 hcd_release_address(hcd, target.address);
555 return got < 0 ? got : EOVERFLOW;
556 }
557
558 /* Create match ids from the device descriptor */
559 match_id_list_t mids;
560 init_match_ids(&mids);
561
562 ret = create_match_ids(&mids, &desc);
563 if (ret != EOK) {
564 hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
565 hcd_release_address(hcd, target.address);
566 return ret;
567 }
568
569 /* Register device */
570 ret = hcd_ddf_add_usb_device(device, address, speed, NULL, &mids);
571 clean_match_ids(&mids);
572 if (ret != EOK) {
573 hcd_remove_ep(hcd, target, USB_DIRECTION_BOTH);
574 hcd_release_address(hcd, target.address);
575 return ret;
576 }
577 if (ret == EOK && id)
578 *id = target.address;
579
580 return ret;
581}
582
583/** Announce root hub to the DDF
584 *
585 * @param[in] device Host controller ddf device
586 * @param[in] speed roothub communication speed
587 * @return Error code
588 */
589int hcd_ddf_setup_root_hub(ddf_dev_t *device, usb_speed_t speed)
590{
591 assert(device);
592 hcd_t *hcd = dev_to_hcd(device);
593 assert(hcd);
594
595 hcd_reserve_default_address(hcd, speed);
596 const int ret = hcd_ddf_new_device(device, NULL);
597 hcd_release_default_address(hcd);
598 return ret;
599}
600
601/** Initialize hc structures.
602 *
603 * @param[in] device DDF instance of the device to use.
604 *
605 * This function does all the ddf work for hc driver.
606 */
607int hcd_ddf_setup_device(ddf_dev_t *device, ddf_fun_t **hc_fun,
608 usb_speed_t max_speed, size_t bw, bw_count_func_t bw_count)
609{
610 if (device == NULL)
611 return EBADMEM;
612
613 hc_dev_t *instance = ddf_dev_data_alloc(device, sizeof(hc_dev_t));
614 if (instance == NULL) {
615 usb_log_error("Failed to allocate HCD ddf structure.\n");
616 return ENOMEM;
617 }
618 list_initialize(&instance->devices);
619 fibril_mutex_initialize(&instance->guard);
620
621#define CHECK_RET_DEST_FREE_RETURN(ret, message...) \
622if (ret != EOK) { \
623 if (instance->hc_fun) { \
624 ddf_fun_destroy(instance->hc_fun); \
625 } \
626 usb_log_error(message); \
627 return ret; \
628} else (void)0
629
630 instance->hc_fun = ddf_fun_create(device, fun_exposed, "hc");
631 int ret = instance->hc_fun ? EOK : ENOMEM;
632 CHECK_RET_DEST_FREE_RETURN(ret,
633 "Failed to create HCD HC function: %s.\n", str_error(ret));
634 ddf_fun_set_ops(instance->hc_fun, &hc_ops);
635 hcd_t *hcd = ddf_fun_data_alloc(instance->hc_fun, sizeof(hcd_t));
636 ret = hcd ? EOK : ENOMEM;
637 CHECK_RET_DEST_FREE_RETURN(ret,
638 "Failed to allocate HCD structure: %s.\n", str_error(ret));
639
640 hcd_init(hcd, max_speed, bw, bw_count);
641
642 ret = ddf_fun_bind(instance->hc_fun);
643 CHECK_RET_DEST_FREE_RETURN(ret,
644 "Failed to bind HCD device function: %s.\n", str_error(ret));
645
646#define CHECK_RET_UNBIND_FREE_RETURN(ret, message...) \
647if (ret != EOK) { \
648 ddf_fun_unbind(instance->hc_fun); \
649 CHECK_RET_DEST_FREE_RETURN(ret, message); \
650} else (void)0
651 ret = ddf_fun_add_to_category(instance->hc_fun, USB_HC_CATEGORY);
652 CHECK_RET_UNBIND_FREE_RETURN(ret,
653 "Failed to add hc to category: %s\n", str_error(ret));
654
655 /* HC should be ok at this point (except it can't do anything) */
656 if (hc_fun)
657 *hc_fun = instance->hc_fun;
658
659 return EOK;
660}
661
662/**
663 * @}
664 */
Note: See TracBrowser for help on using the repository browser.