2 * Copyright (c) 2015 Bart Van Assche <bart.vanassche@sandisk.com>
3 * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. 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 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
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.
31 #ifdef HAVE_LINUX_BSG_H
33 # include <linux/bsg.h>
34 # include "xlat/bsg_protocol.h"
35 # include "xlat/bsg_subprotocol.h"
36 # include "xlat/bsg_flags.h"
39 print_sg_io_buffer(struct tcb *const tcp, const kernel_ulong_t addr,
40 const unsigned int len)
42 printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
46 decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
48 struct sg_io_v4 sg_io;
49 static const size_t skip_iid = offsetof(struct sg_io_v4, protocol);
51 tprints("{guard='Q', ");
52 if (umoven_or_printaddr(tcp, arg + skip_iid, sizeof(sg_io) - skip_iid,
55 return RVAL_DECODED | 1;
59 printxval(bsg_protocol, sg_io.protocol, "BSG_PROTOCOL_???");
60 tprints(", subprotocol=");
61 printxval(bsg_subprotocol, sg_io.subprotocol, "BSG_SUB_PROTOCOL_???");
62 tprintf(", request[%u]=", sg_io.request_len);
63 print_sg_io_buffer(tcp, sg_io.request, sg_io.request_len);
64 tprintf(", request_tag=%#" PRI__x64, sg_io.request_tag);
65 tprintf(", request_attr=%u", sg_io.request_attr);
66 tprintf(", request_priority=%u", sg_io.request_priority);
67 tprintf(", request_extra=%u", sg_io.request_extra);
68 tprintf(", max_response_len=%u", sg_io.max_response_len);
70 tprintf(", dout_iovec_count=%u", sg_io.dout_iovec_count);
71 tprintf(", dout_xfer_len=%u", sg_io.dout_xfer_len);
72 tprintf(", din_iovec_count=%u", sg_io.din_iovec_count);
73 tprintf(", din_xfer_len=%u", sg_io.din_xfer_len);
74 tprintf(", timeout=%u", sg_io.timeout);
76 printflags(bsg_flags, sg_io.flags, "BSG_FLAG_???");
77 tprintf(", usr_ptr=%#" PRI__x64, sg_io.usr_ptr);
78 tprintf(", dout[%u]=", sg_io.dout_xfer_len);
79 if (sg_io.dout_iovec_count)
80 tprint_iov_upto(tcp, sg_io.dout_iovec_count, sg_io.dout_xferp,
81 IOV_DECODE_STR, sg_io.dout_xfer_len);
83 print_sg_io_buffer(tcp, sg_io.dout_xferp, sg_io.dout_xfer_len);
88 decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
90 struct sg_io_v4 sg_io;
93 if (umove(tcp, arg, &sg_io) < 0) {
95 return RVAL_DECODED | 1;
98 if (sg_io.guard != (unsigned char) 'Q') {
99 tprintf(" => guard=%u", sg_io.guard);
100 return RVAL_DECODED | 1;
103 tprintf(", response[%u]=", sg_io.response_len);
104 print_sg_io_buffer(tcp, sg_io.response, sg_io.response_len);
105 din_len = sg_io.din_xfer_len;
106 if (sg_io.din_resid > 0)
107 din_len -= sg_io.din_resid;
108 tprintf(", din[%u]=", din_len);
109 if (sg_io.din_iovec_count)
110 tprint_iov_upto(tcp, sg_io.din_iovec_count, sg_io.din_xferp,
111 syserror(tcp) ? IOV_DECODE_ADDR :
112 IOV_DECODE_STR, din_len);
114 print_sg_io_buffer(tcp, sg_io.din_xferp, din_len);
115 tprintf(", driver_status=%#x", sg_io.driver_status);
116 tprintf(", transport_status=%#x", sg_io.transport_status);
117 tprintf(", device_status=%#x", sg_io.device_status);
118 tprintf(", retry_delay=%u", sg_io.retry_delay);
120 printflags(sg_io_info, sg_io.info, "SG_INFO_???");
121 tprintf(", duration=%u", sg_io.duration);
122 tprintf(", response_len=%u", sg_io.response_len);
123 tprintf(", din_resid=%u", sg_io.din_resid);
124 tprintf(", dout_resid=%u", sg_io.dout_resid);
125 tprintf(", generated_tag=%#" PRI__x64, sg_io.generated_tag);
127 return RVAL_DECODED | 1;
130 #else /* !HAVE_LINUX_BSG_H */
133 decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
135 tprints("{guard='Q', ...}");
136 return RVAL_DECODED | 1;
140 decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
148 decode_sg_io_v4(struct tcb *const tcp, const kernel_ulong_t arg)
150 return entering(tcp) ? decode_request(tcp, arg)
151 : decode_response(tcp, arg);