2 * Copyright (C) 2010 FUJITSU LIMITED
3 * Copyright (C) 2010 Tomohiro Kusumi <kusumi.tomohiro@jp.fujitsu.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #include <linux/kernel.h>
19 #include <linux/trace_seq.h>
20 #include <asm/unaligned.h>
21 #include <trace/events/scsi.h>
23 #define SERVICE_ACTION16(cdb) (cdb[1] & 0x1f)
24 #define SERVICE_ACTION32(cdb) (get_unaligned_be16(&cdb[8]))
27 scsi_trace_misc(struct trace_seq
*, unsigned char *, int);
30 scsi_trace_rw6(struct trace_seq
*p
, unsigned char *cdb
, int len
)
32 const char *ret
= trace_seq_buffer_ptr(p
);
35 lba
|= ((cdb
[1] & 0x1F) << 16);
39 * From SBC-2: a TRANSFER LENGTH field set to zero specifies that 256
40 * logical blocks shall be read (READ(6)) or written (WRITE(6)).
42 txlen
= cdb
[4] ? cdb
[4] : 256;
44 trace_seq_printf(p
, "lba=%u txlen=%u", lba
, txlen
);
51 scsi_trace_rw10(struct trace_seq
*p
, unsigned char *cdb
, int len
)
53 const char *ret
= trace_seq_buffer_ptr(p
);
56 lba
= get_unaligned_be32(&cdb
[2]);
57 txlen
= get_unaligned_be16(&cdb
[7]);
59 trace_seq_printf(p
, "lba=%u txlen=%u protect=%u", lba
, txlen
,
62 if (cdb
[0] == WRITE_SAME
)
63 trace_seq_printf(p
, " unmap=%u", cdb
[1] >> 3 & 1);
71 scsi_trace_rw12(struct trace_seq
*p
, unsigned char *cdb
, int len
)
73 const char *ret
= trace_seq_buffer_ptr(p
);
76 lba
= get_unaligned_be32(&cdb
[2]);
77 txlen
= get_unaligned_be32(&cdb
[6]);
79 trace_seq_printf(p
, "lba=%u txlen=%u protect=%u", lba
, txlen
,
87 scsi_trace_rw16(struct trace_seq
*p
, unsigned char *cdb
, int len
)
89 const char *ret
= trace_seq_buffer_ptr(p
);
93 lba
= get_unaligned_be64(&cdb
[2]);
94 txlen
= get_unaligned_be32(&cdb
[10]);
96 trace_seq_printf(p
, "lba=%llu txlen=%u protect=%u", lba
, txlen
,
99 if (cdb
[0] == WRITE_SAME_16
)
100 trace_seq_printf(p
, " unmap=%u", cdb
[1] >> 3 & 1);
102 trace_seq_putc(p
, 0);
108 scsi_trace_rw32(struct trace_seq
*p
, unsigned char *cdb
, int len
)
110 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
114 switch (SERVICE_ACTION32(cdb
)) {
128 trace_seq_puts(p
, "UNKNOWN");
132 lba
= get_unaligned_be64(&cdb
[12]);
133 ei_lbrt
= get_unaligned_be32(&cdb
[20]);
134 txlen
= get_unaligned_be32(&cdb
[28]);
136 trace_seq_printf(p
, "%s_32 lba=%llu txlen=%u protect=%u ei_lbrt=%u",
137 cmd
, lba
, txlen
, cdb
[10] >> 5, ei_lbrt
);
139 if (SERVICE_ACTION32(cdb
) == WRITE_SAME_32
)
140 trace_seq_printf(p
, " unmap=%u", cdb
[10] >> 3 & 1);
143 trace_seq_putc(p
, 0);
149 scsi_trace_unmap(struct trace_seq
*p
, unsigned char *cdb
, int len
)
151 const char *ret
= trace_seq_buffer_ptr(p
);
152 unsigned int regions
= get_unaligned_be16(&cdb
[7]);
154 trace_seq_printf(p
, "regions=%u", (regions
- 8) / 16);
155 trace_seq_putc(p
, 0);
161 scsi_trace_service_action_in(struct trace_seq
*p
, unsigned char *cdb
, int len
)
163 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
167 switch (SERVICE_ACTION16(cdb
)) {
168 case SAI_READ_CAPACITY_16
:
169 cmd
= "READ_CAPACITY_16";
171 case SAI_GET_LBA_STATUS
:
172 cmd
= "GET_LBA_STATUS";
175 trace_seq_puts(p
, "UNKNOWN");
179 lba
= get_unaligned_be64(&cdb
[2]);
180 alloc_len
= get_unaligned_be32(&cdb
[10]);
182 trace_seq_printf(p
, "%s lba=%llu alloc_len=%u", cmd
, lba
, alloc_len
);
185 trace_seq_putc(p
, 0);
191 scsi_trace_varlen(struct trace_seq
*p
, unsigned char *cdb
, int len
)
193 switch (SERVICE_ACTION32(cdb
)) {
198 return scsi_trace_rw32(p
, cdb
, len
);
200 return scsi_trace_misc(p
, cdb
, len
);
205 scsi_trace_misc(struct trace_seq
*p
, unsigned char *cdb
, int len
)
207 const char *ret
= trace_seq_buffer_ptr(p
);
209 trace_seq_putc(p
, '-');
210 trace_seq_putc(p
, 0);
216 scsi_trace_parse_cdb(struct trace_seq
*p
, unsigned char *cdb
, int len
)
221 return scsi_trace_rw6(p
, cdb
, len
);
226 return scsi_trace_rw10(p
, cdb
, len
);
230 return scsi_trace_rw12(p
, cdb
, len
);
235 return scsi_trace_rw16(p
, cdb
, len
);
237 return scsi_trace_unmap(p
, cdb
, len
);
238 case SERVICE_ACTION_IN_16
:
239 return scsi_trace_service_action_in(p
, cdb
, len
);
240 case VARIABLE_LENGTH_CMD
:
241 return scsi_trace_varlen(p
, cdb
, len
);
243 return scsi_trace_misc(p
, cdb
, len
);