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

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

usbdiag: refactoring

Remote usbdiag interface has been modified to allow reporting test duration back to the caller. The usbdiag driver has been modified to pass such information to the remote interface. The tmon utility has been modified to display some basic statistical information derived from the received value.

  • Property mode set to 100644
File size: 8.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 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, usbdiag_dur_t *duration)
65{
66 if (!exch)
67 return EBADMEM;
68
69 sysarg_t duration_;
70 const int rc = async_req_3_1(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_BURST_INTR_IN, cycles, size, &duration_);
71
72 if (rc == EOK && duration)
73 *duration = duration_;
74
75 return rc;
76}
77
78int usbdiag_burst_intr_out(async_exch_t *exch, int cycles, size_t size, usbdiag_dur_t *duration)
79{
80 if (!exch)
81 return EBADMEM;
82
83 sysarg_t duration_;
84 const int rc = async_req_3_1(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_BURST_INTR_OUT, cycles, size, &duration_);
85
86 if (rc == EOK && duration)
87 *duration = duration_;
88
89 return rc;
90}
91
92int usbdiag_burst_bulk_in(async_exch_t *exch, int cycles, size_t size, usbdiag_dur_t *duration)
93{
94 if (!exch)
95 return EBADMEM;
96
97 sysarg_t duration_;
98 const int rc = async_req_3_1(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_BURST_BULK_IN, cycles, size, &duration_);
99
100 if (rc == EOK && duration)
101 *duration = duration_;
102
103 return rc;
104}
105
106int usbdiag_burst_bulk_out(async_exch_t *exch, int cycles, size_t size, usbdiag_dur_t *duration)
107{
108 if (!exch)
109 return EBADMEM;
110
111 sysarg_t duration_;
112 const int rc = async_req_3_1(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_BURST_BULK_OUT, cycles, size, &duration_);
113
114 if (rc == EOK && duration)
115 *duration = duration_;
116
117 return rc;
118}
119
120int usbdiag_burst_isoch_in(async_exch_t *exch, int cycles, size_t size, usbdiag_dur_t *duration)
121{
122 if (!exch)
123 return EBADMEM;
124
125 sysarg_t duration_;
126 const int rc = async_req_3_1(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_BURST_ISOCH_IN, cycles, size, &duration_);
127
128 if (rc == EOK && duration)
129 *duration = duration_;
130
131 return rc;
132}
133
134int usbdiag_burst_isoch_out(async_exch_t *exch, int cycles, size_t size, usbdiag_dur_t *duration)
135{
136 if (!exch)
137 return EBADMEM;
138
139 sysarg_t duration_;
140 const int rc = async_req_3_1(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_BURST_ISOCH_OUT, cycles, size, &duration_);
141
142 if (rc == EOK && duration)
143 *duration = duration_;
144
145 return rc;
146}
147
148static void remote_usbdiag_burst_intr_in(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
149static void remote_usbdiag_burst_intr_out(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
150static void remote_usbdiag_burst_bulk_in(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
151static void remote_usbdiag_burst_bulk_out(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
152static void remote_usbdiag_burst_isoch_in(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
153static void remote_usbdiag_burst_isoch_out(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
154
155/** Remote USB diagnostic interface operations. */
156static const remote_iface_func_ptr_t remote_usbdiag_iface_ops [] = {
157 [IPC_M_USBDIAG_BURST_INTR_IN] = remote_usbdiag_burst_intr_in,
158 [IPC_M_USBDIAG_BURST_INTR_OUT] = remote_usbdiag_burst_intr_out,
159 [IPC_M_USBDIAG_BURST_BULK_IN] = remote_usbdiag_burst_bulk_in,
160 [IPC_M_USBDIAG_BURST_BULK_OUT] = remote_usbdiag_burst_bulk_out,
161 [IPC_M_USBDIAG_BURST_ISOCH_IN] = remote_usbdiag_burst_isoch_in,
162 [IPC_M_USBDIAG_BURST_ISOCH_OUT] = remote_usbdiag_burst_isoch_out
163};
164
165/** Remote USB diagnostic interface structure. */
166const remote_iface_t remote_usbdiag_iface = {
167 .method_count = ARRAY_SIZE(remote_usbdiag_iface_ops),
168 .methods = remote_usbdiag_iface_ops,
169};
170
171void remote_usbdiag_burst_intr_in(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
172{
173 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
174
175 if (diag_iface->burst_bulk_in == NULL) {
176 async_answer_0(callid, ENOTSUP);
177 return;
178 }
179
180 int cycles = DEV_IPC_GET_ARG1(*call);
181 size_t size = DEV_IPC_GET_ARG2(*call);
182 usbdiag_dur_t duration;
183 const int ret = diag_iface->burst_intr_in(fun, cycles, size, &duration);
184
185 if (ret != EOK) {
186 async_answer_0(callid, ret);
187 } else {
188 async_answer_1(callid, EOK, duration);
189 }
190}
191
192void remote_usbdiag_burst_intr_out(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
193{
194 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
195
196 if (diag_iface->burst_bulk_out == NULL) {
197 async_answer_0(callid, ENOTSUP);
198 return;
199 }
200
201 int cycles = DEV_IPC_GET_ARG1(*call);
202 size_t size = DEV_IPC_GET_ARG2(*call);
203 usbdiag_dur_t duration;
204 const int ret = diag_iface->burst_intr_out(fun, cycles, size, &duration);
205
206 if (ret != EOK) {
207 async_answer_0(callid, ret);
208 } else {
209 async_answer_1(callid, EOK, duration);
210 }
211}
212
213void remote_usbdiag_burst_bulk_in(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
214{
215 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
216
217 if (diag_iface->burst_bulk_in == NULL) {
218 async_answer_0(callid, ENOTSUP);
219 return;
220 }
221
222 int cycles = DEV_IPC_GET_ARG1(*call);
223 size_t size = DEV_IPC_GET_ARG2(*call);
224 usbdiag_dur_t duration;
225 const int ret = diag_iface->burst_bulk_in(fun, cycles, size, &duration);
226
227 if (ret != EOK) {
228 async_answer_0(callid, ret);
229 } else {
230 async_answer_1(callid, EOK, duration);
231 }
232}
233
234void remote_usbdiag_burst_bulk_out(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
235{
236 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
237
238 if (diag_iface->burst_bulk_out == NULL) {
239 async_answer_0(callid, ENOTSUP);
240 return;
241 }
242
243 int cycles = DEV_IPC_GET_ARG1(*call);
244 size_t size = DEV_IPC_GET_ARG2(*call);
245 usbdiag_dur_t duration;
246 const int ret = diag_iface->burst_bulk_out(fun, cycles, size, &duration);
247
248 if (ret != EOK) {
249 async_answer_0(callid, ret);
250 } else {
251 async_answer_1(callid, EOK, duration);
252 }
253}
254
255void remote_usbdiag_burst_isoch_in(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
256{
257 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
258
259 if (diag_iface->burst_isoch_in == NULL) {
260 async_answer_0(callid, ENOTSUP);
261 return;
262 }
263
264 int cycles = DEV_IPC_GET_ARG1(*call);
265 size_t size = DEV_IPC_GET_ARG2(*call);
266 usbdiag_dur_t duration;
267 const int ret = diag_iface->burst_isoch_in(fun, cycles, size, &duration);
268
269 if (ret != EOK) {
270 async_answer_0(callid, ret);
271 } else {
272 async_answer_1(callid, EOK, duration);
273 }
274}
275
276void remote_usbdiag_burst_isoch_out(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
277{
278 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
279
280 if (diag_iface->burst_isoch_out == NULL) {
281 async_answer_0(callid, ENOTSUP);
282 return;
283 }
284
285 int cycles = DEV_IPC_GET_ARG1(*call);
286 size_t size = DEV_IPC_GET_ARG2(*call);
287 usbdiag_dur_t duration;
288 const int ret = diag_iface->burst_isoch_out(fun, cycles, size, &duration);
289
290 if (ret != EOK) {
291 async_answer_0(callid, ret);
292 } else {
293 async_answer_1(callid, EOK, duration);
294 }
295}
296
297/**
298 * @}
299 */
Note: See TracBrowser for help on using the repository browser.