1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2010 FUJITSU LIMITED
4 * Copyright (C) 2010 Tomohiro Kusumi <kusumi.tomohiro@jp.fujitsu.com>
6 #include <linux/kernel.h>
7 #include <linux/trace_seq.h>
8 #include <asm/unaligned.h>
9 #include <trace/events/scsi.h>
11 #define SERVICE_ACTION16(cdb) (cdb[1] & 0x1f)
12 #define SERVICE_ACTION32(cdb) (get_unaligned_be16(&cdb[8]))
15 scsi_trace_misc(struct trace_seq
*, unsigned char *, int);
18 scsi_trace_rw6(struct trace_seq
*p
, unsigned char *cdb
, int len
)
20 const char *ret
= trace_seq_buffer_ptr(p
);
23 lba
|= ((cdb
[1] & 0x1F) << 16);
27 * From SBC-2: a TRANSFER LENGTH field set to zero specifies that 256
28 * logical blocks shall be read (READ(6)) or written (WRITE(6)).
30 txlen
= cdb
[4] ? cdb
[4] : 256;
32 trace_seq_printf(p
, "lba=%u txlen=%u", lba
, txlen
);
39 scsi_trace_rw10(struct trace_seq
*p
, unsigned char *cdb
, int len
)
41 const char *ret
= trace_seq_buffer_ptr(p
);
44 lba
= get_unaligned_be32(&cdb
[2]);
45 txlen
= get_unaligned_be16(&cdb
[7]);
47 trace_seq_printf(p
, "lba=%u txlen=%u protect=%u", lba
, txlen
,
50 if (cdb
[0] == WRITE_SAME
)
51 trace_seq_printf(p
, " unmap=%u", cdb
[1] >> 3 & 1);
59 scsi_trace_rw12(struct trace_seq
*p
, unsigned char *cdb
, int len
)
61 const char *ret
= trace_seq_buffer_ptr(p
);
64 lba
= get_unaligned_be32(&cdb
[2]);
65 txlen
= get_unaligned_be32(&cdb
[6]);
67 trace_seq_printf(p
, "lba=%u txlen=%u protect=%u", lba
, txlen
,
75 scsi_trace_rw16(struct trace_seq
*p
, unsigned char *cdb
, int len
)
77 const char *ret
= trace_seq_buffer_ptr(p
);
81 lba
= get_unaligned_be64(&cdb
[2]);
82 txlen
= get_unaligned_be32(&cdb
[10]);
84 trace_seq_printf(p
, "lba=%llu txlen=%u protect=%u", lba
, txlen
,
87 if (cdb
[0] == WRITE_SAME_16
)
88 trace_seq_printf(p
, " unmap=%u", cdb
[1] >> 3 & 1);
96 scsi_trace_rw32(struct trace_seq
*p
, unsigned char *cdb
, int len
)
98 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
102 switch (SERVICE_ACTION32(cdb
)) {
116 trace_seq_puts(p
, "UNKNOWN");
120 lba
= get_unaligned_be64(&cdb
[12]);
121 ei_lbrt
= get_unaligned_be32(&cdb
[20]);
122 txlen
= get_unaligned_be32(&cdb
[28]);
124 trace_seq_printf(p
, "%s_32 lba=%llu txlen=%u protect=%u ei_lbrt=%u",
125 cmd
, lba
, txlen
, cdb
[10] >> 5, ei_lbrt
);
127 if (SERVICE_ACTION32(cdb
) == WRITE_SAME_32
)
128 trace_seq_printf(p
, " unmap=%u", cdb
[10] >> 3 & 1);
131 trace_seq_putc(p
, 0);
137 scsi_trace_unmap(struct trace_seq
*p
, unsigned char *cdb
, int len
)
139 const char *ret
= trace_seq_buffer_ptr(p
);
140 unsigned int regions
= get_unaligned_be16(&cdb
[7]);
142 trace_seq_printf(p
, "regions=%u", (regions
- 8) / 16);
143 trace_seq_putc(p
, 0);
149 scsi_trace_service_action_in(struct trace_seq
*p
, unsigned char *cdb
, int len
)
151 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
155 switch (SERVICE_ACTION16(cdb
)) {
156 case SAI_READ_CAPACITY_16
:
157 cmd
= "READ_CAPACITY_16";
159 case SAI_GET_LBA_STATUS
:
160 cmd
= "GET_LBA_STATUS";
163 trace_seq_puts(p
, "UNKNOWN");
167 lba
= get_unaligned_be64(&cdb
[2]);
168 alloc_len
= get_unaligned_be32(&cdb
[10]);
170 trace_seq_printf(p
, "%s lba=%llu alloc_len=%u", cmd
, lba
, alloc_len
);
173 trace_seq_putc(p
, 0);
179 scsi_trace_maintenance_in(struct trace_seq
*p
, unsigned char *cdb
, int len
)
181 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
184 switch (SERVICE_ACTION16(cdb
)) {
185 case MI_REPORT_IDENTIFYING_INFORMATION
:
186 cmd
= "REPORT_IDENTIFYING_INFORMATION";
188 case MI_REPORT_TARGET_PGS
:
189 cmd
= "REPORT_TARGET_PORT_GROUPS";
191 case MI_REPORT_ALIASES
:
192 cmd
= "REPORT_ALIASES";
194 case MI_REPORT_SUPPORTED_OPERATION_CODES
:
195 cmd
= "REPORT_SUPPORTED_OPERATION_CODES";
197 case MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS
:
198 cmd
= "REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS";
200 case MI_REPORT_PRIORITY
:
201 cmd
= "REPORT_PRIORITY";
203 case MI_REPORT_TIMESTAMP
:
204 cmd
= "REPORT_TIMESTAMP";
206 case MI_MANAGEMENT_PROTOCOL_IN
:
207 cmd
= "MANAGEMENT_PROTOCOL_IN";
210 trace_seq_puts(p
, "UNKNOWN");
214 alloc_len
= get_unaligned_be32(&cdb
[6]);
216 trace_seq_printf(p
, "%s alloc_len=%u", cmd
, alloc_len
);
219 trace_seq_putc(p
, 0);
225 scsi_trace_maintenance_out(struct trace_seq
*p
, unsigned char *cdb
, int len
)
227 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
230 switch (SERVICE_ACTION16(cdb
)) {
231 case MO_SET_IDENTIFYING_INFORMATION
:
232 cmd
= "SET_IDENTIFYING_INFORMATION";
234 case MO_SET_TARGET_PGS
:
235 cmd
= "SET_TARGET_PORT_GROUPS";
237 case MO_CHANGE_ALIASES
:
238 cmd
= "CHANGE_ALIASES";
240 case MO_SET_PRIORITY
:
241 cmd
= "SET_PRIORITY";
243 case MO_SET_TIMESTAMP
:
244 cmd
= "SET_TIMESTAMP";
246 case MO_MANAGEMENT_PROTOCOL_OUT
:
247 cmd
= "MANAGEMENT_PROTOCOL_OUT";
250 trace_seq_puts(p
, "UNKNOWN");
254 alloc_len
= get_unaligned_be32(&cdb
[6]);
256 trace_seq_printf(p
, "%s alloc_len=%u", cmd
, alloc_len
);
259 trace_seq_putc(p
, 0);
265 scsi_trace_zbc_in(struct trace_seq
*p
, unsigned char *cdb
, int len
)
267 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
272 switch (SERVICE_ACTION16(cdb
)) {
273 case ZI_REPORT_ZONES
:
274 cmd
= "REPORT_ZONES";
277 trace_seq_puts(p
, "UNKNOWN");
281 zone_id
= get_unaligned_be64(&cdb
[2]);
282 alloc_len
= get_unaligned_be32(&cdb
[10]);
283 options
= cdb
[14] & 0x3f;
285 trace_seq_printf(p
, "%s zone=%llu alloc_len=%u options=%u partial=%u",
286 cmd
, (unsigned long long)zone_id
, alloc_len
,
287 options
, (cdb
[14] >> 7) & 1);
290 trace_seq_putc(p
, 0);
296 scsi_trace_zbc_out(struct trace_seq
*p
, unsigned char *cdb
, int len
)
298 const char *ret
= trace_seq_buffer_ptr(p
), *cmd
;
301 switch (SERVICE_ACTION16(cdb
)) {
311 case ZO_RESET_WRITE_POINTER
:
312 cmd
= "RESET_WRITE_POINTER";
315 trace_seq_puts(p
, "UNKNOWN");
319 zone_id
= get_unaligned_be64(&cdb
[2]);
321 trace_seq_printf(p
, "%s zone=%llu all=%u", cmd
,
322 (unsigned long long)zone_id
, cdb
[14] & 1);
325 trace_seq_putc(p
, 0);
331 scsi_trace_varlen(struct trace_seq
*p
, unsigned char *cdb
, int len
)
333 switch (SERVICE_ACTION32(cdb
)) {
338 return scsi_trace_rw32(p
, cdb
, len
);
340 return scsi_trace_misc(p
, cdb
, len
);
345 scsi_trace_misc(struct trace_seq
*p
, unsigned char *cdb
, int len
)
347 const char *ret
= trace_seq_buffer_ptr(p
);
349 trace_seq_putc(p
, '-');
350 trace_seq_putc(p
, 0);
356 scsi_trace_parse_cdb(struct trace_seq
*p
, unsigned char *cdb
, int len
)
361 return scsi_trace_rw6(p
, cdb
, len
);
366 return scsi_trace_rw10(p
, cdb
, len
);
370 return scsi_trace_rw12(p
, cdb
, len
);
375 return scsi_trace_rw16(p
, cdb
, len
);
377 return scsi_trace_unmap(p
, cdb
, len
);
378 case SERVICE_ACTION_IN_16
:
379 return scsi_trace_service_action_in(p
, cdb
, len
);
380 case VARIABLE_LENGTH_CMD
:
381 return scsi_trace_varlen(p
, cdb
, len
);
383 return scsi_trace_maintenance_in(p
, cdb
, len
);
384 case MAINTENANCE_OUT
:
385 return scsi_trace_maintenance_out(p
, cdb
, len
);
387 return scsi_trace_zbc_in(p
, cdb
, len
);
389 return scsi_trace_zbc_out(p
, cdb
, len
);
391 return scsi_trace_misc(p
, cdb
, len
);