source: mainline/uspace/lib/drv/generic/remote_usbdiag.c@ b7b7898

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b7b7898 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: 7.1 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 libdrv
30 * @{
31 */
32/** @file
33 * USB diagnostic device remote interface.
34 */
35
36#include <async.h>
37#include <assert.h>
38#include <macros.h>
39#include <errno.h>
40#include <devman.h>
41
42#include "usbdiag_iface.h"
43
44typedef enum {
45 IPC_M_USBDIAG_BURST_INTR_IN,
46 IPC_M_USBDIAG_BURST_INTR_OUT,
47 IPC_M_USBDIAG_BURST_BULK_IN,
48 IPC_M_USBDIAG_BURST_BULK_OUT,
49 IPC_M_USBDIAG_BURST_ISOCH_IN,
50 IPC_M_USBDIAG_BURST_ISOCH_OUT
51} usb_iface_funcs_t;
52
53async_sess_t *usbdiag_connect(devman_handle_t handle)
54{
55 return devman_device_connect(handle, IPC_FLAG_BLOCKING);
56}
57
58void usbdiag_disconnect(async_sess_t *sess)
59{
60 if (sess)
61 async_hangup(sess);
62}
63
64int usbdiag_burst_intr_in(async_exch_t *exch, int cycles, size_t size)
65{
66 if (!exch)
67 return EBADMEM;
68
69 return async_req_3_0(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_BURST_INTR_IN, cycles, size);
70}
71
72int usbdiag_burst_intr_out(async_exch_t *exch, int cycles, size_t size)
73{
74 if (!exch)
75 return EBADMEM;
76
77 return async_req_3_0(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_BURST_INTR_OUT, cycles, size);
78}
79
80int usbdiag_burst_bulk_in(async_exch_t *exch, int cycles, size_t size)
81{
82 if (!exch)
83 return EBADMEM;
84
85 return async_req_3_0(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_BURST_BULK_IN, cycles, size);
86}
87
88int usbdiag_burst_bulk_out(async_exch_t *exch, int cycles, size_t size)
89{
90 if (!exch)
91 return EBADMEM;
92
93 return async_req_3_0(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_BURST_BULK_OUT, cycles, size);
94}
95
96int usbdiag_burst_isoch_in(async_exch_t *exch, int cycles, size_t size)
97{
98 if (!exch)
99 return EBADMEM;
100
101 return async_req_3_0(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_BURST_ISOCH_IN, cycles, size);
102}
103
104int usbdiag_burst_isoch_out(async_exch_t *exch, int cycles, size_t size)
105{
106 if (!exch)
107 return EBADMEM;
108
109 return async_req_3_0(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_BURST_ISOCH_OUT, cycles, size);
110}
111
112static void remote_usbdiag_burst_intr_in(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
113static void remote_usbdiag_burst_intr_out(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
114static void remote_usbdiag_burst_bulk_in(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
115static void remote_usbdiag_burst_bulk_out(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
116static void remote_usbdiag_burst_isoch_in(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
117static void remote_usbdiag_burst_isoch_out(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
118
119/** Remote USB diagnostic interface operations. */
120static const remote_iface_func_ptr_t remote_usbdiag_iface_ops [] = {
121 [IPC_M_USBDIAG_BURST_INTR_IN] = remote_usbdiag_burst_intr_in,
122 [IPC_M_USBDIAG_BURST_INTR_OUT] = remote_usbdiag_burst_intr_out,
123 [IPC_M_USBDIAG_BURST_BULK_IN] = remote_usbdiag_burst_bulk_in,
124 [IPC_M_USBDIAG_BURST_BULK_OUT] = remote_usbdiag_burst_bulk_out,
125 [IPC_M_USBDIAG_BURST_ISOCH_IN] = remote_usbdiag_burst_isoch_in,
126 [IPC_M_USBDIAG_BURST_ISOCH_OUT] = remote_usbdiag_burst_isoch_out
127};
128
129/** Remote USB diagnostic interface structure. */
130const remote_iface_t remote_usbdiag_iface = {
131 .method_count = ARRAY_SIZE(remote_usbdiag_iface_ops),
132 .methods = remote_usbdiag_iface_ops,
133};
134
135void remote_usbdiag_burst_intr_in(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
136{
137 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
138
139 if (diag_iface->burst_bulk_in == NULL) {
140 async_answer_0(callid, ENOTSUP);
141 return;
142 }
143
144 int cycles = DEV_IPC_GET_ARG1(*call);
145 size_t size = DEV_IPC_GET_ARG2(*call);
146 const int ret = diag_iface->burst_intr_in(fun, cycles, size);
147 async_answer_0(callid, ret);
148}
149
150void remote_usbdiag_burst_intr_out(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
151{
152 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
153
154 if (diag_iface->burst_bulk_out == NULL) {
155 async_answer_0(callid, ENOTSUP);
156 return;
157 }
158
159 int cycles = DEV_IPC_GET_ARG1(*call);
160 size_t size = DEV_IPC_GET_ARG2(*call);
161 const int ret = diag_iface->burst_intr_out(fun, cycles, size);
162 async_answer_0(callid, ret);
163}
164
165void remote_usbdiag_burst_bulk_in(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
166{
167 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
168
169 if (diag_iface->burst_bulk_in == NULL) {
170 async_answer_0(callid, ENOTSUP);
171 return;
172 }
173
174 int cycles = DEV_IPC_GET_ARG1(*call);
175 size_t size = DEV_IPC_GET_ARG2(*call);
176 const int ret = diag_iface->burst_bulk_in(fun, cycles, size);
177 async_answer_0(callid, ret);
178}
179
180void remote_usbdiag_burst_bulk_out(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
181{
182 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
183
184 if (diag_iface->burst_bulk_out == NULL) {
185 async_answer_0(callid, ENOTSUP);
186 return;
187 }
188
189 int cycles = DEV_IPC_GET_ARG1(*call);
190 size_t size = DEV_IPC_GET_ARG2(*call);
191 const int ret = diag_iface->burst_bulk_out(fun, cycles, size);
192 async_answer_0(callid, ret);
193}
194
195void remote_usbdiag_burst_isoch_in(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
196{
197 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
198
199 if (diag_iface->burst_isoch_in == NULL) {
200 async_answer_0(callid, ENOTSUP);
201 return;
202 }
203
204 int cycles = DEV_IPC_GET_ARG1(*call);
205 size_t size = DEV_IPC_GET_ARG2(*call);
206 const int ret = diag_iface->burst_isoch_in(fun, cycles, size);
207 async_answer_0(callid, ret);
208}
209
210void remote_usbdiag_burst_isoch_out(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
211{
212 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
213
214 if (diag_iface->burst_isoch_out == NULL) {
215 async_answer_0(callid, ENOTSUP);
216 return;
217 }
218
219 int cycles = DEV_IPC_GET_ARG1(*call);
220 size_t size = DEV_IPC_GET_ARG2(*call);
221 const int ret = diag_iface->burst_isoch_out(fun, cycles, size);
222 async_answer_0(callid, ret);
223}
224
225/**
226 * @}
227 */
Note: See TracBrowser for help on using the repository browser.