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 = get_unaligned_be24(&cdb[1]) & 0x1fffff;
25 * From SBC-2: a TRANSFER LENGTH field set to zero specifies that 256
26 * logical blocks shall be read (READ(6)) or written (WRITE(6)).
28 txlen = cdb[4] ? cdb[4] : 256;
30 trace_seq_printf(p, "lba=%u txlen=%u", lba, txlen);
37 scsi_trace_rw10(struct trace_seq *p, unsigned char *cdb, int len)
39 const char *ret = trace_seq_buffer_ptr(p);
42 lba = get_unaligned_be32(&cdb[2]);
43 txlen = get_unaligned_be16(&cdb[7]);
45 trace_seq_printf(p, "lba=%u txlen=%u protect=%u", lba, txlen,
48 if (cdb[0] == WRITE_SAME)
49 trace_seq_printf(p, " unmap=%u", cdb[1] >> 3 & 1);
57 scsi_trace_rw12(struct trace_seq *p, unsigned char *cdb, int len)
59 const char *ret = trace_seq_buffer_ptr(p);
62 lba = get_unaligned_be32(&cdb[2]);
63 txlen = get_unaligned_be32(&cdb[6]);
65 trace_seq_printf(p, "lba=%u txlen=%u protect=%u", lba, txlen,
73 scsi_trace_rw16(struct trace_seq *p, unsigned char *cdb, int len)
75 const char *ret = trace_seq_buffer_ptr(p);
79 lba = get_unaligned_be64(&cdb[2]);
80 txlen = get_unaligned_be32(&cdb[10]);
82 trace_seq_printf(p, "lba=%llu txlen=%u protect=%u", lba, txlen,
85 if (cdb[0] == WRITE_SAME_16)
86 trace_seq_printf(p, " unmap=%u", cdb[1] >> 3 & 1);
94 scsi_trace_rw32(struct trace_seq *p, unsigned char *cdb, int len)
96 const char *ret = trace_seq_buffer_ptr(p), *cmd;
100 switch (SERVICE_ACTION32(cdb)) {
114 trace_seq_puts(p, "UNKNOWN");
118 lba = get_unaligned_be64(&cdb[12]);
119 ei_lbrt = get_unaligned_be32(&cdb[20]);
120 txlen = get_unaligned_be32(&cdb[28]);
122 trace_seq_printf(p, "%s_32 lba=%llu txlen=%u protect=%u ei_lbrt=%u",
123 cmd, lba, txlen, cdb[10] >> 5, ei_lbrt);
125 if (SERVICE_ACTION32(cdb) == WRITE_SAME_32)
126 trace_seq_printf(p, " unmap=%u", cdb[10] >> 3 & 1);
129 trace_seq_putc(p, 0);
135 scsi_trace_unmap(struct trace_seq *p, unsigned char *cdb, int len)
137 const char *ret = trace_seq_buffer_ptr(p);
138 unsigned int regions = get_unaligned_be16(&cdb[7]);
140 trace_seq_printf(p, "regions=%u", (regions - 8) / 16);
141 trace_seq_putc(p, 0);
147 scsi_trace_service_action_in(struct trace_seq *p, unsigned char *cdb, int len)
149 const char *ret = trace_seq_buffer_ptr(p), *cmd;
153 switch (SERVICE_ACTION16(cdb)) {
154 case SAI_READ_CAPACITY_16:
155 cmd = "READ_CAPACITY_16";
157 case SAI_GET_LBA_STATUS:
158 cmd = "GET_LBA_STATUS";
161 trace_seq_puts(p, "UNKNOWN");
165 lba = get_unaligned_be64(&cdb[2]);
166 alloc_len = get_unaligned_be32(&cdb[10]);
168 trace_seq_printf(p, "%s lba=%llu alloc_len=%u", cmd, lba, alloc_len);
171 trace_seq_putc(p, 0);
177 scsi_trace_maintenance_in(struct trace_seq *p, unsigned char *cdb, int len)
179 const char *ret = trace_seq_buffer_ptr(p), *cmd;
182 switch (SERVICE_ACTION16(cdb)) {
183 case MI_REPORT_IDENTIFYING_INFORMATION:
184 cmd = "REPORT_IDENTIFYING_INFORMATION";
186 case MI_REPORT_TARGET_PGS:
187 cmd = "REPORT_TARGET_PORT_GROUPS";
189 case MI_REPORT_ALIASES:
190 cmd = "REPORT_ALIASES";
192 case MI_REPORT_SUPPORTED_OPERATION_CODES:
193 cmd = "REPORT_SUPPORTED_OPERATION_CODES";
195 case MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS:
196 cmd = "REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS";
198 case MI_REPORT_PRIORITY:
199 cmd = "REPORT_PRIORITY";
201 case MI_REPORT_TIMESTAMP:
202 cmd = "REPORT_TIMESTAMP";
204 case MI_MANAGEMENT_PROTOCOL_IN:
205 cmd = "MANAGEMENT_PROTOCOL_IN";
208 trace_seq_puts(p, "UNKNOWN");
212 alloc_len = get_unaligned_be32(&cdb[6]);
214 trace_seq_printf(p, "%s alloc_len=%u", cmd, alloc_len);
217 trace_seq_putc(p, 0);
223 scsi_trace_maintenance_out(struct trace_seq *p, unsigned char *cdb, int len)
225 const char *ret = trace_seq_buffer_ptr(p), *cmd;
228 switch (SERVICE_ACTION16(cdb)) {
229 case MO_SET_IDENTIFYING_INFORMATION:
230 cmd = "SET_IDENTIFYING_INFORMATION";
232 case MO_SET_TARGET_PGS:
233 cmd = "SET_TARGET_PORT_GROUPS";
235 case MO_CHANGE_ALIASES:
236 cmd = "CHANGE_ALIASES";
238 case MO_SET_PRIORITY:
239 cmd = "SET_PRIORITY";
241 case MO_SET_TIMESTAMP:
242 cmd = "SET_TIMESTAMP";
244 case MO_MANAGEMENT_PROTOCOL_OUT:
245 cmd = "MANAGEMENT_PROTOCOL_OUT";
248 trace_seq_puts(p, "UNKNOWN");
252 alloc_len = get_unaligned_be32(&cdb[6]);
254 trace_seq_printf(p, "%s alloc_len=%u", cmd, alloc_len);
257 trace_seq_putc(p, 0);
263 scsi_trace_zbc_in(struct trace_seq *p, unsigned char *cdb, int len)
265 const char *ret = trace_seq_buffer_ptr(p), *cmd;
270 switch (SERVICE_ACTION16(cdb)) {
271 case ZI_REPORT_ZONES:
272 cmd = "REPORT_ZONES";
275 trace_seq_puts(p, "UNKNOWN");
279 zone_id = get_unaligned_be64(&cdb[2]);
280 alloc_len = get_unaligned_be32(&cdb[10]);
281 options = cdb[14] & 0x3f;
283 trace_seq_printf(p, "%s zone=%llu alloc_len=%u options=%u partial=%u",
284 cmd, (unsigned long long)zone_id, alloc_len,
285 options, (cdb[14] >> 7) & 1);
288 trace_seq_putc(p, 0);
294 scsi_trace_zbc_out(struct trace_seq *p, unsigned char *cdb, int len)
296 const char *ret = trace_seq_buffer_ptr(p), *cmd;
299 switch (SERVICE_ACTION16(cdb)) {
309 case ZO_RESET_WRITE_POINTER:
310 cmd = "RESET_WRITE_POINTER";
313 trace_seq_puts(p, "UNKNOWN");
317 zone_id = get_unaligned_be64(&cdb[2]);
319 trace_seq_printf(p, "%s zone=%llu all=%u", cmd,
320 (unsigned long long)zone_id, cdb[14] & 1);
323 trace_seq_putc(p, 0);
329 scsi_trace_varlen(struct trace_seq *p, unsigned char *cdb, int len)
331 switch (SERVICE_ACTION32(cdb)) {
336 return scsi_trace_rw32(p, cdb, len);
338 return scsi_trace_misc(p, cdb, len);
343 scsi_trace_misc(struct trace_seq *p, unsigned char *cdb, int len)
345 const char *ret = trace_seq_buffer_ptr(p);
347 trace_seq_putc(p, '-');
348 trace_seq_putc(p, 0);
354 scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len)
359 return scsi_trace_rw6(p, cdb, len);
364 return scsi_trace_rw10(p, cdb, len);
368 return scsi_trace_rw12(p, cdb, len);
373 return scsi_trace_rw16(p, cdb, len);
375 return scsi_trace_unmap(p, cdb, len);
376 case SERVICE_ACTION_IN_16:
377 return scsi_trace_service_action_in(p, cdb, len);
378 case VARIABLE_LENGTH_CMD:
379 return scsi_trace_varlen(p, cdb, len);
381 return scsi_trace_maintenance_in(p, cdb, len);
382 case MAINTENANCE_OUT:
383 return scsi_trace_maintenance_out(p, cdb, len);
385 return scsi_trace_zbc_in(p, cdb, len);
387 return scsi_trace_zbc_out(p, cdb, len);
389 return scsi_trace_misc(p, cdb, len);