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

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

usbdiag: bound interrupt endpoint tests to the remote interface

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