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__u64, 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__u64, sg_io.usr_ptr);
78 tprintf(", spare_in=%u", sg_io.spare_in);
79 tprintf(", dout[%u]=", sg_io.dout_xfer_len);
80 if (sg_io.dout_iovec_count)
81 tprint_iov_upto(tcp, sg_io.dout_iovec_count, sg_io.dout_xferp,
82 IOV_DECODE_STR, sg_io.dout_xfer_len);
84 print_sg_io_buffer(tcp, sg_io.dout_xferp, sg_io.dout_xfer_len);
89 decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
91 struct sg_io_v4 sg_io;
94 if (umove(tcp, arg, &sg_io) < 0) {
96 return RVAL_DECODED | 1;
99 if (sg_io.guard != (unsigned char) 'Q') {
100 tprintf(" => guard=%u", sg_io.guard);
101 return RVAL_DECODED | 1;
104 tprintf(", response[%u]=", sg_io.response_len);
105 print_sg_io_buffer(tcp, sg_io.response, sg_io.response_len);
106 din_len = sg_io.din_xfer_len;
107 if (sg_io.din_resid > 0)
108 din_len -= sg_io.din_resid;
109 tprintf(", din[%u]=", din_len);
110 if (sg_io.din_iovec_count)
111 tprint_iov_upto(tcp, sg_io.din_iovec_count, sg_io.din_xferp,
112 syserror(tcp) ? IOV_DECODE_ADDR :
113 IOV_DECODE_STR, din_len);
115 print_sg_io_buffer(tcp, sg_io.din_xferp, din_len);
116 tprintf(", driver_status=%u", sg_io.driver_status);
117 tprintf(", transport_status=%u", sg_io.transport_status);
118 tprintf(", device_status=%u", sg_io.device_status);
119 tprintf(", retry_delay=%u", sg_io.retry_delay);
121 printflags(sg_io_info, sg_io.info, "SG_INFO_???");
122 tprintf(", duration=%u", sg_io.duration);
123 tprintf(", response_len=%u", sg_io.response_len);
124 tprintf(", din_resid=%u", sg_io.din_resid);
125 tprintf(", dout_resid=%u", sg_io.dout_resid);
126 tprintf(", generated_tag=%" PRI__u64, sg_io.generated_tag);
127 tprintf(", spare_out=%u", sg_io.spare_out);
129 return RVAL_DECODED | 1;
132 #else /* !HAVE_LINUX_BSG_H */
135 decode_request(struct tcb *const tcp, const kernel_ulong_t arg)
137 tprints("{guard='Q', ...}");
138 return RVAL_DECODED | 1;
142 decode_response(struct tcb *const tcp, const kernel_ulong_t arg)
150 decode_sg_io_v4(struct tcb *const tcp, const kernel_ulong_t arg)
152 return entering(tcp) ? decode_request(tcp, arg)
153 : decode_response(tcp, arg);