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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ff16da5f was ff16da5f, checked in by Petr Mánek <petr.manek@…>, 8 years ago

usbdiag: added isochronous test

  • Property mode set to 100644
File size: 4.2 KB
Line 
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
29/** @addtogroup drvusbdiag
30 * @{
31 */
32/**
33 * @file
34 * Code for managing debug device structures.
35 */
36#include <errno.h>
37#include <str_error.h>
38#include <macros.h>
39#include <usb/debug.h>
40#include <usbdiag_iface.h>
41
42#include "device.h"
43#include "tests.h"
44
45#define NAME "usbdiag"
46
47#define TRANSLATE_FUNC_NAME(fun) translate_##fun
48#define TRANSLATE_FUNC(fun) \
49 static int TRANSLATE_FUNC_NAME(fun)(ddf_fun_t *f, int cycles, size_t size)\
50 {\
51 usb_diag_dev_t *dev = ddf_fun_to_usb_diag_dev(f);\
52 return fun(dev, cycles, size);\
53 }
54
55TRANSLATE_FUNC(usb_diag_stress_intr_out)
56TRANSLATE_FUNC(usb_diag_stress_intr_in)
57TRANSLATE_FUNC(usb_diag_stress_bulk_out)
58TRANSLATE_FUNC(usb_diag_stress_bulk_in)
59TRANSLATE_FUNC(usb_diag_stress_isoch_out)
60TRANSLATE_FUNC(usb_diag_stress_isoch_in)
61
62static usbdiag_iface_t diag_interface = {
63 .stress_intr_out = TRANSLATE_FUNC_NAME(usb_diag_stress_intr_out),
64 .stress_intr_in = TRANSLATE_FUNC_NAME(usb_diag_stress_intr_in),
65 .stress_bulk_out = TRANSLATE_FUNC_NAME(usb_diag_stress_bulk_out),
66 .stress_bulk_in = TRANSLATE_FUNC_NAME(usb_diag_stress_bulk_in),
67 .stress_isoch_out = TRANSLATE_FUNC_NAME(usb_diag_stress_isoch_out),
68 .stress_isoch_in = TRANSLATE_FUNC_NAME(usb_diag_stress_isoch_in)
69};
70
71#undef TRANSLATE_FUNC_NAME
72#undef TRANSLATE_FUNC
73
74static ddf_dev_ops_t diag_ops = {
75 .interfaces[USBDIAG_DEV_IFACE] = &diag_interface
76};
77
78static int device_init(usb_diag_dev_t *dev)
79{
80 int rc;
81 ddf_fun_t *fun = usb_device_ddf_fun_create(dev->usb_dev, fun_exposed, "tmon");
82 if (!fun) {
83 rc = ENOMEM;
84 goto err;
85 }
86
87 ddf_fun_set_ops(fun, &diag_ops);
88 dev->fun = fun;
89
90#define _MAP_EP(target, ep_no) do {\
91 usb_endpoint_mapping_t *epm = usb_device_get_mapped_ep(dev->usb_dev, USB_DIAG_EP_##ep_no);\
92 if (!epm || !epm->present) {\
93 usb_log_error("Failed to map endpoint: " #ep_no ".\n");\
94 rc = ENOENT;\
95 goto err_fun;\
96 }\
97 target = &epm->pipe;\
98 } while (0);
99
100 _MAP_EP(dev->intr_in, INTR_IN);
101 _MAP_EP(dev->intr_out, INTR_OUT);
102 _MAP_EP(dev->bulk_in, BULK_IN);
103 _MAP_EP(dev->bulk_out, BULK_OUT);
104 _MAP_EP(dev->isoch_in, ISOCH_IN);
105 _MAP_EP(dev->isoch_out, ISOCH_OUT);
106
107#undef _MAP_EP
108
109 return EOK;
110
111err_fun:
112 ddf_fun_destroy(fun);
113err:
114 return rc;
115}
116
117static void device_fini(usb_diag_dev_t *dev)
118{
119 ddf_fun_destroy(dev->fun);
120}
121
122int usb_diag_dev_create(usb_device_t *dev, usb_diag_dev_t **out_diag_dev)
123{
124 assert(dev);
125 assert(out_diag_dev);
126
127 usb_diag_dev_t *diag_dev = usb_device_data_alloc(dev, sizeof(usb_diag_dev_t));
128 if (!diag_dev)
129 return ENOMEM;
130
131 diag_dev->usb_dev = dev;
132
133 int err;
134 if ((err = device_init(diag_dev)))
135 goto err_init;
136
137 *out_diag_dev = diag_dev;
138 return EOK;
139
140err_init:
141 /* There is no usb_device_data_free. */
142 return err;
143}
144
145void usb_diag_dev_destroy(usb_diag_dev_t *dev)
146{
147 assert(dev);
148
149 device_fini(dev);
150 /* There is no usb_device_data_free. */
151}
152
153/**
154 * @}
155 */
Note: See TracBrowser for help on using the repository browser.