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

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

usbdiag: refactoring

Reconciliated the usb_diag and usbdiag prefix in favor of the latter. Removed a ton of copy-pasta code for the burst tests in favor of single generic static burst test for every direction, which is then called by individual functions for different endpoint type. This also allowed to get rid of the ugly translation macros in device.c. Deleted unused usbdiag.h header file. Refactored the remote interface to comply with all aforementioned modifications.

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