source: mainline/uspace/drv/bus/usb/usbdiag/device.c@ 2aaba7e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2aaba7e was a1732929, checked in by Ondřej Hlavatý <aearsis@…>, 8 years ago

usb: unified logging

Use logger instead of printf. Logger adds newlines automatically.

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[6c8a221c]1/*
2 * Copyright (c) 2017 Petr Manek
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
[b7e1458]29/** @addtogroup drvusbdiag
[6c8a221c]30 * @{
31 */
32/**
33 * @file
34 * Code for managing debug device structures.
35 */
36#include <errno.h>
[6a1211c]37#include <str_error.h>
38#include <macros.h>
[6c8a221c]39#include <usb/debug.h>
[41ebc36]40#include <usbdiag_iface.h>
[6c8a221c]41
42#include "device.h"
[fd312d5]43#include "tests.h"
[6c8a221c]44
[b7e1458]45#define NAME "usbdiag"
[6c8a221c]46
[41ebc36]47static usbdiag_iface_t diag_interface = {
[b7b7898]48 .burst_intr_in = usbdiag_burst_test_intr_in,
49 .burst_intr_out = usbdiag_burst_test_intr_out,
50 .burst_bulk_in = usbdiag_burst_test_bulk_in,
51 .burst_bulk_out = usbdiag_burst_test_bulk_out,
52 .burst_isoch_in = usbdiag_burst_test_isoch_in,
[2523293]53 .burst_isoch_out = usbdiag_burst_test_isoch_out,
54 .data_intr_in = usbdiag_data_test_intr_in,
55 .data_intr_out = usbdiag_data_test_intr_out,
56 .data_bulk_in = usbdiag_data_test_bulk_in,
57 .data_bulk_out = usbdiag_data_test_bulk_out,
58 .data_isoch_in = usbdiag_data_test_isoch_in,
59 .data_isoch_out = usbdiag_data_test_isoch_out
[64d138b]60};
61
62static ddf_dev_ops_t diag_ops = {
63 .interfaces[USBDIAG_DEV_IFACE] = &diag_interface
64};
65
[b7b7898]66static int device_init(usbdiag_dev_t *dev)
[6c8a221c]67{
[6a1211c]68 int rc;
[64d138b]69 ddf_fun_t *fun = usb_device_ddf_fun_create(dev->usb_dev, fun_exposed, "tmon");
[6a1211c]70 if (!fun) {
71 rc = ENOMEM;
72 goto err;
73 }
[64d138b]74
75 ddf_fun_set_ops(fun, &diag_ops);
76 dev->fun = fun;
[6a1211c]77
[fd312d5]78#define _MAP_EP(target, ep_no) do {\
[b7b7898]79 usb_endpoint_mapping_t *epm = usb_device_get_mapped_ep(dev->usb_dev, USBDIAG_EP_##ep_no);\
[fd312d5]80 if (!epm || !epm->present) {\
[a1732929]81 usb_log_error("Failed to map endpoint: " #ep_no ".");\
[fd312d5]82 rc = ENOENT;\
83 goto err_fun;\
84 }\
85 target = &epm->pipe;\
86 } while (0);
87
88 _MAP_EP(dev->intr_in, INTR_IN);
89 _MAP_EP(dev->intr_out, INTR_OUT);
90 _MAP_EP(dev->bulk_in, BULK_IN);
91 _MAP_EP(dev->bulk_out, BULK_OUT);
92 _MAP_EP(dev->isoch_in, ISOCH_IN);
93 _MAP_EP(dev->isoch_out, ISOCH_OUT);
94
95#undef _MAP_EP
[6a1211c]96
[6c8a221c]97 return EOK;
[6a1211c]98
99err_fun:
100 ddf_fun_destroy(fun);
101err:
102 return rc;
[6c8a221c]103}
104
[b7b7898]105static void device_fini(usbdiag_dev_t *dev)
[6c8a221c]106{
[64d138b]107 ddf_fun_destroy(dev->fun);
[6c8a221c]108}
109
[b7b7898]110int usbdiag_dev_create(usb_device_t *dev, usbdiag_dev_t **out_diag_dev)
[6c8a221c]111{
112 assert(dev);
[b7e1458]113 assert(out_diag_dev);
[6c8a221c]114
[b7b7898]115 usbdiag_dev_t *diag_dev = usb_device_data_alloc(dev, sizeof(usbdiag_dev_t));
[b7e1458]116 if (!diag_dev)
[6c8a221c]117 return ENOMEM;
118
[b7e1458]119 diag_dev->usb_dev = dev;
[6c8a221c]120
121 int err;
[b7e1458]122 if ((err = device_init(diag_dev)))
[6c8a221c]123 goto err_init;
124
[b7e1458]125 *out_diag_dev = diag_dev;
[6c8a221c]126 return EOK;
127
128err_init:
129 /* There is no usb_device_data_free. */
130 return err;
131}
132
[b7b7898]133void usbdiag_dev_destroy(usbdiag_dev_t *dev)
[6c8a221c]134{
135 assert(dev);
136
137 device_fini(dev);
138 /* There is no usb_device_data_free. */
139}
140
141/**
142 * @}
143 */
Note: See TracBrowser for help on using the repository browser.