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"
38 print_sg_io_buffer(struct tcb *const tcp, const kernel_ulong_t addr,
39 const unsigned int len)
41 printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
45 decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
47 struct sg_io_v4 sg_io;
48 static const size_t skip_iid = offsetof(struct sg_io_v4, protocol);
50 tprints("{guard='Q', ");
51 if (umoven_or_printaddr(tcp, arg + skip_iid, sizeof(sg_io) - skip_iid,
54 return RVAL_DECODED | 1;
58 printxval(bsg_protocol, sg_io.protocol, "BSG_PROTOCOL_???");
59 tprints(", subprotocol=");
60 printxval(bsg_subprotocol, sg_io.subprotocol, "BSG_SUB_PROTOCOL_???");
61 tprintf(", request[%u]=", sg_io.request_len);
62 print_sg_io_buffer(tcp, sg_io.request, sg_io.request_len);
63 tprintf(", request_tag=%" PRI__u64, sg_io.request_tag);
64 tprintf(", request_attr=%u", sg_io.request_attr);
65 tprintf(", request_priority=%u", sg_io.request_priority);
66 tprintf(", request_extra=%u", sg_io.request_extra);
67 tprintf(", max_response_len=%u", sg_io.max_response_len);
69 tprintf(", dout_iovec_count=%u", sg_io.dout_iovec_count);
70 tprintf(", dout_xfer_len=%u", sg_io.dout_xfer_len);
71 tprintf(", din_iovec_count=%u", sg_io.din_iovec_count);
72 tprintf(", din_xfer_len=%u", sg_io.din_xfer_len);
73 tprintf(", timeout=%u", sg_io.timeout);
74 tprintf(", flags=%u", sg_io.flags);
75 tprintf(", usr_ptr=%" PRI__u64, sg_io.usr_ptr);
76 tprintf(", spare_in=%u", sg_io.spare_in);
77 tprintf(", dout[%u]=", sg_io.dout_xfer_len);
78 if (sg_io.dout_iovec_count)
79 tprint_iov_upto(tcp, sg_io.dout_iovec_count, sg_io.dout_xferp,
80 IOV_DECODE_STR, sg_io.dout_xfer_len);
82 print_sg_io_buffer(tcp, sg_io.dout_xferp, sg_io.dout_xfer_len);
87 decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
89 struct sg_io_v4 sg_io;
92 if (umove(tcp, arg, &sg_io) < 0) {
94 return RVAL_DECODED | 1;
97 if (sg_io.guard != (unsigned char) 'Q') {
98 tprintf(" => guard=%u", sg_io.guard);
99 return RVAL_DECODED | 1;
102 tprintf(", response[%u]=", sg_io.response_len);
103 print_sg_io_buffer(tcp, sg_io.response, sg_io.response_len);
104 din_len = sg_io.din_xfer_len;
105 if (sg_io.din_resid > 0)
106 din_len -= sg_io.din_resid;
107 tprintf(", din[%u]=", din_len);
108 if (sg_io.din_iovec_count)
109 tprint_iov_upto(tcp, sg_io.din_iovec_count, sg_io.din_xferp,
110 syserror(tcp) ? IOV_DECODE_ADDR :
111 IOV_DECODE_STR, din_len);
113 print_sg_io_buffer(tcp, sg_io.din_xferp, din_len);
114 tprintf(", driver_status=%u", sg_io.driver_status);
115 tprintf(", transport_status=%u", sg_io.transport_status);
116 tprintf(", device_status=%u", sg_io.device_status);
117 tprintf(", retry_delay=%u", sg_io.retry_delay);
118 tprintf(", info=%u", sg_io.info);
119 tprintf(", duration=%u", sg_io.duration);
120 tprintf(", response_len=%u", sg_io.response_len);
121 tprintf(", din_resid=%u", sg_io.din_resid);
122 tprintf(", dout_resid=%u", sg_io.dout_resid);
123 tprintf(", generated_tag=%" PRI__u64, sg_io.generated_tag);
124 tprintf(", spare_out=%u", sg_io.spare_out);
126 return RVAL_DECODED | 1;
129 #else /* !HAVE_LINUX_BSG_H */
132 decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
134 tprints("{guard='Q', ...}");
135 return RVAL_DECODED | 1;
139 decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
147 decode_sg_io_v4(struct tcb *const tcp, const kernel_ulong_t arg)
149 return entering(tcp) ? decode_request(tcp, arg)
150 : decode_response(tcp, arg);