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) ((cdb[8] << 8) | cdb[9])
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
);
33 sector_t lba
= 0, txlen
= 0;
35 lba
|= ((cdb
[1] & 0x1F) << 16);
40 trace_seq_printf(p
, "lba=%llu txlen=%llu",
41 (unsigned long long)lba
, (unsigned long long)txlen
);
48 scsi_trace_rw10(struct trace_seq
*p
, unsigned char *cdb
, int len
)
50 const char *ret
= trace_seq_buffer_ptr(p
);
51 sector_t lba
= 0, txlen
= 0;
53 lba
|= (cdb
[2] << 24);
54 lba
|= (cdb
[3] << 16);
57 txlen
|= (cdb
[7] << 8);
60 trace_seq_printf(p
, "lba=%llu txlen=%llu protect=%u",
61 (unsigned long long)lba
, (unsigned long long)txlen
,
64 if (cdb
[0] == WRITE_SAME
)
65 trace_seq_printf(p
, " unmap=%u", cdb
[1] >> 3 & 1);
73 scsi_trace_rw12(struct trace_seq
*p
, unsigned char *cdb
, int len
)
75 const char *ret
= trace_seq_buffer_ptr(p
);
76 sector_t lba
= 0, txlen
= 0;
78 lba
|= (cdb
[2] << 24);
79 lba
|= (cdb
[3] << 16);
82 txlen
|= (cdb
[6] << 24);
83 txlen
|= (cdb
[7] << 16);
84 txlen
|= (cdb
[8] << 8);
87 trace_seq_printf(p
, "lba=%llu txlen=%llu protect=%u",
88 (unsigned long long)lba
, (unsigned long long)txlen
,
96 scsi_trace_rw16(struct trace_seq
*p
, unsigned char *cdb
, int len
)
98 const char *ret
= trace_seq_buffer_ptr(p
);
99 sector_t lba
= 0, txlen
= 0;
101 lba
|= ((u64
)cdb
[2] << 56);
102 lba
|= ((u64
)cdb
[3] << 48);
103 lba
|= ((u64
)cdb
[4] << 40);
104 lba
|= ((u64
)cdb
[5] << 32);
105 lba
|= (cdb
[6] << 24);
106 lba
|= (cdb
[7] << 16);
107 lba
|= (cdb
[8] << 8);
109 txlen
|= (cdb
[10] << 24);
110 txlen
|= (cdb
[11] << 16);
111 txlen
|= (cdb
[12] << 8);
114 trace_seq_printf(p
, "lba=%llu txlen=%llu protect=%u",
115 (unsigned long long)lba
, (unsigned long long)txlen
,
118 if (cdb
[0] == WRITE_SAME_16
)
119 trace_seq_printf(p
, " unmap=%u", cdb
[1] >> 3 & 1);
121 trace_seq_putc(p
, 0);
127 scsi_trace_rw32(struct trace_seq
*p
, unsigned char *cdb
, int len
)
129 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
130 sector_t lba
= 0, txlen
= 0;
133 switch (SERVICE_ACTION32(cdb
)) {
147 trace_seq_puts(p
, "UNKNOWN");
151 lba
|= ((u64
)cdb
[12] << 56);
152 lba
|= ((u64
)cdb
[13] << 48);
153 lba
|= ((u64
)cdb
[14] << 40);
154 lba
|= ((u64
)cdb
[15] << 32);
155 lba
|= (cdb
[16] << 24);
156 lba
|= (cdb
[17] << 16);
157 lba
|= (cdb
[18] << 8);
159 ei_lbrt
|= (cdb
[20] << 24);
160 ei_lbrt
|= (cdb
[21] << 16);
161 ei_lbrt
|= (cdb
[22] << 8);
163 txlen
|= (cdb
[28] << 24);
164 txlen
|= (cdb
[29] << 16);
165 txlen
|= (cdb
[30] << 8);
168 trace_seq_printf(p
, "%s_32 lba=%llu txlen=%llu protect=%u ei_lbrt=%u",
169 cmd
, (unsigned long long)lba
,
170 (unsigned long long)txlen
, cdb
[10] >> 5, ei_lbrt
);
172 if (SERVICE_ACTION32(cdb
) == WRITE_SAME_32
)
173 trace_seq_printf(p
, " unmap=%u", cdb
[10] >> 3 & 1);
176 trace_seq_putc(p
, 0);
182 scsi_trace_unmap(struct trace_seq
*p
, unsigned char *cdb
, int len
)
184 const char *ret
= trace_seq_buffer_ptr(p
);
185 unsigned int regions
= cdb
[7] << 8 | cdb
[8];
187 trace_seq_printf(p
, "regions=%u", (regions
- 8) / 16);
188 trace_seq_putc(p
, 0);
194 scsi_trace_service_action_in(struct trace_seq
*p
, unsigned char *cdb
, int len
)
196 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
200 switch (SERVICE_ACTION16(cdb
)) {
201 case SAI_READ_CAPACITY_16
:
202 cmd
= "READ_CAPACITY_16";
204 case SAI_GET_LBA_STATUS
:
205 cmd
= "GET_LBA_STATUS";
208 trace_seq_puts(p
, "UNKNOWN");
212 lba
|= ((u64
)cdb
[2] << 56);
213 lba
|= ((u64
)cdb
[3] << 48);
214 lba
|= ((u64
)cdb
[4] << 40);
215 lba
|= ((u64
)cdb
[5] << 32);
216 lba
|= (cdb
[6] << 24);
217 lba
|= (cdb
[7] << 16);
218 lba
|= (cdb
[8] << 8);
220 alloc_len
|= (cdb
[10] << 24);
221 alloc_len
|= (cdb
[11] << 16);
222 alloc_len
|= (cdb
[12] << 8);
223 alloc_len
|= cdb
[13];
225 trace_seq_printf(p
, "%s lba=%llu alloc_len=%u", cmd
,
226 (unsigned long long)lba
, alloc_len
);
229 trace_seq_putc(p
, 0);
235 scsi_trace_maintenance_in(struct trace_seq
*p
, unsigned char *cdb
, int len
)
237 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
240 switch (SERVICE_ACTION16(cdb
)) {
241 case MI_REPORT_IDENTIFYING_INFORMATION
:
242 cmd
= "REPORT_IDENTIFYING_INFORMATION";
244 case MI_REPORT_TARGET_PGS
:
245 cmd
= "REPORT_TARGET_PORT_GROUPS";
247 case MI_REPORT_ALIASES
:
248 cmd
= "REPORT_ALIASES";
250 case MI_REPORT_SUPPORTED_OPERATION_CODES
:
251 cmd
= "REPORT_SUPPORTED_OPERATION_CODES";
253 case MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS
:
254 cmd
= "REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS";
256 case MI_REPORT_PRIORITY
:
257 cmd
= "REPORT_PRIORITY";
259 case MI_REPORT_TIMESTAMP
:
260 cmd
= "REPORT_TIMESTAMP";
262 case MI_MANAGEMENT_PROTOCOL_IN
:
263 cmd
= "MANAGEMENT_PROTOCOL_IN";
266 trace_seq_puts(p
, "UNKNOWN");
270 alloc_len
= get_unaligned_be32(&cdb
[6]);
272 trace_seq_printf(p
, "%s alloc_len=%u", cmd
, alloc_len
);
275 trace_seq_putc(p
, 0);
281 scsi_trace_maintenance_out(struct trace_seq
*p
, unsigned char *cdb
, int len
)
283 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
286 switch (SERVICE_ACTION16(cdb
)) {
287 case MO_SET_IDENTIFYING_INFORMATION
:
288 cmd
= "SET_IDENTIFYING_INFORMATION";
290 case MO_SET_TARGET_PGS
:
291 cmd
= "SET_TARGET_PORT_GROUPS";
293 case MO_CHANGE_ALIASES
:
294 cmd
= "CHANGE_ALIASES";
296 case MO_SET_PRIORITY
:
297 cmd
= "SET_PRIORITY";
299 case MO_SET_TIMESTAMP
:
300 cmd
= "SET_TIMESTAMP";
302 case MO_MANAGEMENT_PROTOCOL_OUT
:
303 cmd
= "MANAGEMENT_PROTOCOL_OUT";
306 trace_seq_puts(p
, "UNKNOWN");
310 alloc_len
= get_unaligned_be32(&cdb
[6]);
312 trace_seq_printf(p
, "%s alloc_len=%u", cmd
, alloc_len
);
315 trace_seq_putc(p
, 0);
321 scsi_trace_zbc_in(struct trace_seq
*p
, unsigned char *cdb
, int len
)
323 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
328 switch (SERVICE_ACTION16(cdb
)) {
329 case ZI_REPORT_ZONES
:
330 cmd
= "REPORT_ZONES";
333 trace_seq_puts(p
, "UNKNOWN");
337 zone_id
= get_unaligned_be64(&cdb
[2]);
338 alloc_len
= get_unaligned_be32(&cdb
[10]);
339 options
= cdb
[14] & 0x3f;
341 trace_seq_printf(p
, "%s zone=%llu alloc_len=%u options=%u partial=%u",
342 cmd
, (unsigned long long)zone_id
, alloc_len
,
343 options
, (cdb
[14] >> 7) & 1);
346 trace_seq_putc(p
, 0);
352 scsi_trace_zbc_out(struct trace_seq
*p
, unsigned char *cdb
, int len
)
354 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
357 switch (SERVICE_ACTION16(cdb
)) {
367 case ZO_RESET_WRITE_POINTER
:
368 cmd
= "RESET_WRITE_POINTER";
371 trace_seq_puts(p
, "UNKNOWN");
375 zone_id
= get_unaligned_be64(&cdb
[2]);
377 trace_seq_printf(p
, "%s zone=%llu all=%u", cmd
,
378 (unsigned long long)zone_id
, cdb
[14] & 1);
381 trace_seq_putc(p
, 0);
387 scsi_trace_varlen(struct trace_seq
*p
, unsigned char *cdb
, int len
)
389 switch (SERVICE_ACTION32(cdb
)) {
394 return scsi_trace_rw32(p
, cdb
, len
);
396 return scsi_trace_misc(p
, cdb
, len
);
401 scsi_trace_misc(struct trace_seq
*p
, unsigned char *cdb
, int len
)
403 const char *ret
= trace_seq_buffer_ptr(p
);
405 trace_seq_putc(p
, '-');
406 trace_seq_putc(p
, 0);
412 scsi_trace_parse_cdb(struct trace_seq
*p
, unsigned char *cdb
, int len
)
417 return scsi_trace_rw6(p
, cdb
, len
);
422 return scsi_trace_rw10(p
, cdb
, len
);
426 return scsi_trace_rw12(p
, cdb
, len
);
431 return scsi_trace_rw16(p
, cdb
, len
);
433 return scsi_trace_unmap(p
, cdb
, len
);
434 case SERVICE_ACTION_IN_16
:
435 return scsi_trace_service_action_in(p
, cdb
, len
);
436 case VARIABLE_LENGTH_CMD
:
437 return scsi_trace_varlen(p
, cdb
, len
);
439 return scsi_trace_maintenance_in(p
, cdb
, len
);
440 case MAINTENANCE_OUT
:
441 return scsi_trace_maintenance_out(p
, cdb
, len
);
443 return scsi_trace_zbc_in(p
, cdb
, len
);
445 return scsi_trace_zbc_out(p
, cdb
, len
);
447 return scsi_trace_misc(p
, cdb
, len
);