[7faf0f0] | 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 |
|
---|
| 44 | typedef enum {
|
---|
[e9d600c2] | 45 | IPC_M_USBDIAG_STRESS_INTR_IN,
|
---|
| 46 | IPC_M_USBDIAG_STRESS_INTR_OUT,
|
---|
| 47 | IPC_M_USBDIAG_STRESS_BULK_IN,
|
---|
| 48 | IPC_M_USBDIAG_STRESS_BULK_OUT
|
---|
[7faf0f0] | 49 | } usb_iface_funcs_t;
|
---|
| 50 |
|
---|
| 51 | async_sess_t *usbdiag_connect(devman_handle_t handle)
|
---|
| 52 | {
|
---|
| 53 | return devman_device_connect(handle, IPC_FLAG_BLOCKING);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | void usbdiag_disconnect(async_sess_t *sess)
|
---|
| 57 | {
|
---|
| 58 | if (sess)
|
---|
| 59 | async_hangup(sess);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[e9d600c2] | 62 | int usbdiag_stress_intr_in(async_exch_t *exch, int cycles, size_t size)
|
---|
[7faf0f0] | 63 | {
|
---|
| 64 | if (!exch)
|
---|
| 65 | return EBADMEM;
|
---|
| 66 |
|
---|
[e9d600c2] | 67 | return async_req_3_0(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_STRESS_INTR_IN, cycles, size);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | int usbdiag_stress_intr_out(async_exch_t *exch, int cycles, size_t size)
|
---|
| 71 | {
|
---|
| 72 | if (!exch)
|
---|
| 73 | return EBADMEM;
|
---|
| 74 |
|
---|
| 75 | return async_req_3_0(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_STRESS_INTR_OUT, cycles, size);
|
---|
[fd312d5] | 76 | }
|
---|
[7faf0f0] | 77 |
|
---|
[fd312d5] | 78 | int usbdiag_stress_bulk_in(async_exch_t *exch, int cycles, size_t size)
|
---|
| 79 | {
|
---|
| 80 | if (!exch)
|
---|
| 81 | return EBADMEM;
|
---|
[7faf0f0] | 82 |
|
---|
[fd312d5] | 83 | return async_req_3_0(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_STRESS_BULK_IN, cycles, size);
|
---|
[7faf0f0] | 84 | }
|
---|
| 85 |
|
---|
[e9d600c2] | 86 | int usbdiag_stress_bulk_out(async_exch_t *exch, int cycles, size_t size)
|
---|
| 87 | {
|
---|
| 88 | if (!exch)
|
---|
| 89 | return EBADMEM;
|
---|
| 90 |
|
---|
| 91 | return async_req_3_0(exch, DEV_IFACE_ID(USBDIAG_DEV_IFACE), IPC_M_USBDIAG_STRESS_BULK_OUT, cycles, size);
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | static void remote_usbdiag_stress_intr_in(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 95 | static void remote_usbdiag_stress_intr_out(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[fd312d5] | 96 | static void remote_usbdiag_stress_bulk_in(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[e9d600c2] | 97 | static void remote_usbdiag_stress_bulk_out(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[7faf0f0] | 98 |
|
---|
| 99 | /** Remote USB diagnostic interface operations. */
|
---|
| 100 | static const remote_iface_func_ptr_t remote_usbdiag_iface_ops [] = {
|
---|
[e9d600c2] | 101 | [ IPC_M_USBDIAG_STRESS_INTR_IN] = remote_usbdiag_stress_intr_in,
|
---|
| 102 | [IPC_M_USBDIAG_STRESS_INTR_OUT] = remote_usbdiag_stress_intr_out,
|
---|
| 103 | [ IPC_M_USBDIAG_STRESS_BULK_IN] = remote_usbdiag_stress_bulk_in,
|
---|
| 104 | [IPC_M_USBDIAG_STRESS_BULK_OUT] = remote_usbdiag_stress_bulk_out
|
---|
[7faf0f0] | 105 | };
|
---|
| 106 |
|
---|
| 107 | /** Remote USB diagnostic interface structure. */
|
---|
| 108 | const remote_iface_t remote_usbdiag_iface = {
|
---|
| 109 | .method_count = ARRAY_SIZE(remote_usbdiag_iface_ops),
|
---|
| 110 | .methods = remote_usbdiag_iface_ops,
|
---|
| 111 | };
|
---|
| 112 |
|
---|
[e9d600c2] | 113 | void remote_usbdiag_stress_intr_in(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
| 114 | {
|
---|
| 115 | const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
|
---|
| 116 |
|
---|
| 117 | if (diag_iface->stress_bulk_in == NULL) {
|
---|
| 118 | async_answer_0(callid, ENOTSUP);
|
---|
| 119 | return;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | int cycles = DEV_IPC_GET_ARG1(*call);
|
---|
| 123 | size_t size = DEV_IPC_GET_ARG2(*call);
|
---|
| 124 | const int ret = diag_iface->stress_intr_in(fun, cycles, size);
|
---|
| 125 | async_answer_0(callid, ret);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | void remote_usbdiag_stress_intr_out(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
[7faf0f0] | 129 | {
|
---|
| 130 | const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
|
---|
| 131 |
|
---|
[fd312d5] | 132 | if (diag_iface->stress_bulk_out == NULL) {
|
---|
[7faf0f0] | 133 | async_answer_0(callid, ENOTSUP);
|
---|
| 134 | return;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
[fd312d5] | 137 | int cycles = DEV_IPC_GET_ARG1(*call);
|
---|
| 138 | size_t size = DEV_IPC_GET_ARG2(*call);
|
---|
[e9d600c2] | 139 | const int ret = diag_iface->stress_intr_out(fun, cycles, size);
|
---|
[fd312d5] | 140 | async_answer_0(callid, ret);
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | void remote_usbdiag_stress_bulk_in(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
| 144 | {
|
---|
| 145 | const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
|
---|
| 146 |
|
---|
| 147 | if (diag_iface->stress_bulk_in == NULL) {
|
---|
| 148 | async_answer_0(callid, ENOTSUP);
|
---|
| 149 | return;
|
---|
[7faf0f0] | 150 | }
|
---|
[fd312d5] | 151 |
|
---|
| 152 | int cycles = DEV_IPC_GET_ARG1(*call);
|
---|
| 153 | size_t size = DEV_IPC_GET_ARG2(*call);
|
---|
| 154 | const int ret = diag_iface->stress_bulk_in(fun, cycles, size);
|
---|
| 155 | async_answer_0(callid, ret);
|
---|
[7faf0f0] | 156 | }
|
---|
| 157 |
|
---|
[e9d600c2] | 158 | void remote_usbdiag_stress_bulk_out(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
| 159 | {
|
---|
| 160 | const usbdiag_iface_t *diag_iface = (usbdiag_iface_t *) iface;
|
---|
| 161 |
|
---|
| 162 | if (diag_iface->stress_bulk_out == NULL) {
|
---|
| 163 | async_answer_0(callid, ENOTSUP);
|
---|
| 164 | return;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | int cycles = DEV_IPC_GET_ARG1(*call);
|
---|
| 168 | size_t size = DEV_IPC_GET_ARG2(*call);
|
---|
| 169 | const int ret = diag_iface->stress_bulk_out(fun, cycles, size);
|
---|
| 170 | async_answer_0(callid, ret);
|
---|
| 171 | }
|
---|
| 172 |
|
---|
[7faf0f0] | 173 | /**
|
---|
| 174 | * @}
|
---|
| 175 | */
|
---|