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

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

usbdiag: more robust testing framework, added bulk in stress test, refactored remote usbdiag interface, new command for tmon

  • Property mode set to 100644
File size: 3.8 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_STRESS_BULK_OUT,
46 IPC_M_USBDIAG_STRESS_BULK_IN
47} usb_iface_funcs_t;
48
49async_sess_t *usbdiag_connect(devman_handle_t handle)
50{
51 return devman_device_connect(handle, IPC_FLAG_BLOCKING);
52}
53
54void usbdiag_disconnect(async_sess_t *sess)
55{
56 if (sess)
57 async_hangup(sess);
58}
59
60int usbdiag_stress_bulk_out(async_exch_t *exch, int cycles, size_t size)
61{
62 if (!exch)
63 return EBADMEM;
64
65 return async_req_3_0(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_STRESS_BULK_OUT, cycles, size);
66}
67
68int usbdiag_stress_bulk_in(async_exch_t *exch, int cycles, size_t size)
69{
70 if (!exch)
71 return EBADMEM;
72
73 return async_req_3_0(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_STRESS_BULK_IN, cycles, size);
74}
75
76static void remote_usbdiag_stress_bulk_out(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
77static void remote_usbdiag_stress_bulk_in(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
78
79/** Remote USB diagnostic interface operations. */
80static const remote_iface_func_ptr_t remote_usbdiag_iface_ops [] = {
81 [IPC_M_USBDIAG_STRESS_BULK_OUT] = remote_usbdiag_stress_bulk_out,
82 [IPC_M_USBDIAG_STRESS_BULK_IN] = remote_usbdiag_stress_bulk_in,
83};
84
85/** Remote USB diagnostic interface structure. */
86const remote_iface_t remote_usbdiag_iface = {
87 .method_count = ARRAY_SIZE(remote_usbdiag_iface_ops),
88 .methods = remote_usbdiag_iface_ops,
89};
90
91void remote_usbdiag_stress_bulk_out(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
92{
93 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
94
95 if (diag_iface->stress_bulk_out == NULL) {
96 async_answer_0(callid, ENOTSUP);
97 return;
98 }
99
100 int cycles = DEV_IPC_GET_ARG1(*call);
101 size_t size = DEV_IPC_GET_ARG2(*call);
102 const int ret = diag_iface->stress_bulk_out(fun, cycles, size);
103 async_answer_0(callid, ret);
104}
105
106void remote_usbdiag_stress_bulk_in(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
107{
108 const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
109
110 if (diag_iface->stress_bulk_in == NULL) {
111 async_answer_0(callid, ENOTSUP);
112 return;
113 }
114
115 int cycles = DEV_IPC_GET_ARG1(*call);
116 size_t size = DEV_IPC_GET_ARG2(*call);
117 const int ret = diag_iface->stress_bulk_in(fun, cycles, size);
118 async_answer_0(callid, ret);
119}
120
121/**
122 * @}
123 */
Note: See TracBrowser for help on using the repository browser.