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

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

usb: remove misleading usb_device_get_mapped_ep

Even though this method may seem very convenient to use, it's actually
wrong. The devices are usually not required to have strict endpoint
numbers. That's why the mapping mechanism exists. Therefore, it's just
not possible to rely on fixed endpoint mapping.

There could be similar method, that would take the transfer type and
direction, but it's much better to ask for the complete mapping then.

  • Property mode set to 100644
File size: 3.9 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 .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
60};
61
62static ddf_dev_ops_t diag_ops = {
63 .interfaces[USBDIAG_DEV_IFACE] = &diag_interface
64};
65
66static int device_init(usbdiag_dev_t *dev, const usb_endpoint_description_t **endpoints)
67{
68 int rc;
69 ddf_fun_t *fun = usb_device_ddf_fun_create(dev->usb_dev, fun_exposed, "tmon");
70 if (!fun) {
71 rc = ENOMEM;
72 goto err;
73 }
74
75 ddf_fun_set_ops(fun, &diag_ops);
76 dev->fun = fun;
77
78#define _MAP_EP(target, ep_no) do {\
79 usb_endpoint_mapping_t *epm = usb_device_get_mapped_ep_desc(dev->usb_dev, endpoints[USBDIAG_EP_##ep_no]);\
80 if (!epm || !epm->present) {\
81 usb_log_error("Failed to map endpoint: " #ep_no ".");\
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
96
97 return EOK;
98
99err_fun:
100 ddf_fun_destroy(fun);
101err:
102 return rc;
103}
104
105static void device_fini(usbdiag_dev_t *dev)
106{
107 ddf_fun_destroy(dev->fun);
108}
109
110int usbdiag_dev_create(usb_device_t *dev, usbdiag_dev_t **out_diag_dev, const usb_endpoint_description_t **endpoints)
111{
112 assert(dev);
113 assert(out_diag_dev);
114
115 usbdiag_dev_t *diag_dev = usb_device_data_alloc(dev, sizeof(usbdiag_dev_t));
116 if (!diag_dev)
117 return ENOMEM;
118
119 diag_dev->usb_dev = dev;
120
121 int err;
122 if ((err = device_init(diag_dev, endpoints)))
123 goto err_init;
124
125 *out_diag_dev = diag_dev;
126 return EOK;
127
128err_init:
129 /* There is no usb_device_data_free. */
130 return err;
131}
132
133void usbdiag_dev_destroy(usbdiag_dev_t *dev)
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.