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_maintenance_in(struct trace_seq
*p
, unsigned char *cdb
, int len
)
193 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
196 switch (SERVICE_ACTION16(cdb
)) {
197 case MI_REPORT_IDENTIFYING_INFORMATION
:
198 cmd
= "REPORT_IDENTIFYING_INFORMATION";
200 case MI_REPORT_TARGET_PGS
:
201 cmd
= "REPORT_TARGET_PORT_GROUPS";
203 case MI_REPORT_ALIASES
:
204 cmd
= "REPORT_ALIASES";
206 case MI_REPORT_SUPPORTED_OPERATION_CODES
:
207 cmd
= "REPORT_SUPPORTED_OPERATION_CODES";
209 case MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS
:
210 cmd
= "REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS";
212 case MI_REPORT_PRIORITY
:
213 cmd
= "REPORT_PRIORITY";
215 case MI_REPORT_TIMESTAMP
:
216 cmd
= "REPORT_TIMESTAMP";
218 case MI_MANAGEMENT_PROTOCOL_IN
:
219 cmd
= "MANAGEMENT_PROTOCOL_IN";
222 trace_seq_puts(p
, "UNKNOWN");
226 alloc_len
= get_unaligned_be32(&cdb
[6]);
228 trace_seq_printf(p
, "%s alloc_len=%u", cmd
, alloc_len
);
231 trace_seq_putc(p
, 0);
237 scsi_trace_maintenance_out(struct trace_seq
*p
, unsigned char *cdb
, int len
)
239 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
242 switch (SERVICE_ACTION16(cdb
)) {
243 case MO_SET_IDENTIFYING_INFORMATION
:
244 cmd
= "SET_IDENTIFYING_INFORMATION";
246 case MO_SET_TARGET_PGS
:
247 cmd
= "SET_TARGET_PORT_GROUPS";
249 case MO_CHANGE_ALIASES
:
250 cmd
= "CHANGE_ALIASES";
252 case MO_SET_PRIORITY
:
253 cmd
= "SET_PRIORITY";
255 case MO_SET_TIMESTAMP
:
256 cmd
= "SET_TIMESTAMP";
258 case MO_MANAGEMENT_PROTOCOL_OUT
:
259 cmd
= "MANAGEMENT_PROTOCOL_OUT";
262 trace_seq_puts(p
, "UNKNOWN");
266 alloc_len
= get_unaligned_be32(&cdb
[6]);
268 trace_seq_printf(p
, "%s alloc_len=%u", cmd
, alloc_len
);
271 trace_seq_putc(p
, 0);
277 scsi_trace_zbc_in(struct trace_seq
*p
, unsigned char *cdb
, int len
)
279 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
284 switch (SERVICE_ACTION16(cdb
)) {
285 case ZI_REPORT_ZONES
:
286 cmd
= "REPORT_ZONES";
289 trace_seq_puts(p
, "UNKNOWN");
293 zone_id
= get_unaligned_be64(&cdb
[2]);
294 alloc_len
= get_unaligned_be32(&cdb
[10]);
295 options
= cdb
[14] & 0x3f;
297 trace_seq_printf(p
, "%s zone=%llu alloc_len=%u options=%u partial=%u",
298 cmd
, (unsigned long long)zone_id
, alloc_len
,
299 options
, (cdb
[14] >> 7) & 1);
302 trace_seq_putc(p
, 0);
308 scsi_trace_zbc_out(struct trace_seq
*p
, unsigned char *cdb
, int len
)
310 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
313 switch (SERVICE_ACTION16(cdb
)) {
323 case ZO_RESET_WRITE_POINTER
:
324 cmd
= "RESET_WRITE_POINTER";
327 trace_seq_puts(p
, "UNKNOWN");
331 zone_id
= get_unaligned_be64(&cdb
[2]);
333 trace_seq_printf(p
, "%s zone=%llu all=%u", cmd
,
334 (unsigned long long)zone_id
, cdb
[14] & 1);
337 trace_seq_putc(p
, 0);
343 scsi_trace_varlen(struct trace_seq
*p
, unsigned char *cdb
, int len
)
345 switch (SERVICE_ACTION32(cdb
)) {
350 return scsi_trace_rw32(p
, cdb
, len
);
352 return scsi_trace_misc(p
, cdb
, len
);
357 scsi_trace_misc(struct trace_seq
*p
, unsigned char *cdb
, int len
)
359 const char *ret
= trace_seq_buffer_ptr(p
);
361 trace_seq_putc(p
, '-');
362 trace_seq_putc(p
, 0);
368 scsi_trace_parse_cdb(struct trace_seq
*p
, unsigned char *cdb
, int len
)
373 return scsi_trace_rw6(p
, cdb
, len
);
378 return scsi_trace_rw10(p
, cdb
, len
);
382 return scsi_trace_rw12(p
, cdb
, len
);
387 return scsi_trace_rw16(p
, cdb
, len
);
389 return scsi_trace_unmap(p
, cdb
, len
);
390 case SERVICE_ACTION_IN_16
:
391 return scsi_trace_service_action_in(p
, cdb
, len
);
392 case VARIABLE_LENGTH_CMD
:
393 return scsi_trace_varlen(p
, cdb
, len
);
395 return scsi_trace_maintenance_in(p
, cdb
, len
);
396 case MAINTENANCE_OUT
:
397 return scsi_trace_maintenance_out(p
, cdb
, len
);
399 return scsi_trace_zbc_in(p
, cdb
, len
);
401 return scsi_trace_zbc_out(p
, cdb
, len
);
403 return scsi_trace_misc(p
, cdb
, len
);