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

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

usbdiag: more robust testing framework, added bulk in stress test, refactored remote usbdiag interface, new command for tmon

  • Property mode set to 100644
File size: 3.8 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_bulk_out)
56TRANSLATE_FUNC(usb_diag_stress_bulk_in)
57
58static usbdiag_iface_t diag_interface = {
59 .stress_bulk_out = TRANSLATE_FUNC_NAME(usb_diag_stress_bulk_out),
60 .stress_bulk_in = TRANSLATE_FUNC_NAME(usb_diag_stress_bulk_in)
61};
62
63#undef TRANSLATE_FUNC_NAME
64#undef TRANSLATE_FUNC
65
66static ddf_dev_ops_t diag_ops = {
67 .interfaces[USBDIAG_DEV_IFACE] = &diag_interface
68};
69
70static int device_init(usb_diag_dev_t *dev)
71{
72 int rc;
73 ddf_fun_t *fun = usb_device_ddf_fun_create(dev->usb_dev, fun_exposed, "tmon");
74 if (!fun) {
75 rc = ENOMEM;
76 goto err;
77 }
78
79 ddf_fun_set_ops(fun, &diag_ops);
80 dev->fun = fun;
81
82#define _MAP_EP(target, ep_no) do {\
83 usb_endpoint_mapping_t *epm = usb_device_get_mapped_ep(dev->usb_dev, USB_DIAG_EP_##ep_no);\
84 if (!epm || !epm->present) {\
85 usb_log_error("Failed to map endpoint: " #ep_no ".\n");\
86 rc = ENOENT;\
87 goto err_fun;\
88 }\
89 target = &epm->pipe;\
90 } while (0);
91
92 _MAP_EP(dev->intr_in, INTR_IN);
93 _MAP_EP(dev->intr_out, INTR_OUT);
94 _MAP_EP(dev->bulk_in, BULK_IN);
95 _MAP_EP(dev->bulk_out, BULK_OUT);
96 _MAP_EP(dev->isoch_in, ISOCH_IN);
97 _MAP_EP(dev->isoch_out, ISOCH_OUT);
98
99#undef _MAP_EP
100
101 return EOK;
102
103err_fun:
104 ddf_fun_destroy(fun);
105err:
106 return rc;
107}
108
109static void device_fini(usb_diag_dev_t *dev)
110{
111 ddf_fun_destroy(dev->fun);
112}
113
114int usb_diag_dev_create(usb_device_t *dev, usb_diag_dev_t **out_diag_dev)
115{
116 assert(dev);
117 assert(out_diag_dev);
118
119 usb_diag_dev_t *diag_dev = usb_device_data_alloc(dev, sizeof(usb_diag_dev_t));
120 if (!diag_dev)
121 return ENOMEM;
122
123 diag_dev->usb_dev = dev;
124
125 int err;
126 if ((err = device_init(diag_dev)))
127 goto err_init;
128
129 *out_diag_dev = diag_dev;
130 return EOK;
131
132err_init:
133 /* There is no usb_device_data_free. */
134 return err;
135}
136
137void usb_diag_dev_destroy(usb_diag_dev_t *dev)
138{
139 assert(dev);
140
141 device_fini(dev);
142 /* There is no usb_device_data_free. */
143}
144
145/**
146 * @}
147 */
Note: See TracBrowser for help on using the repository browser.