treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / scsi / scsi_trace.c
blobac35c301c792103ed8f527d438e9434ea25664c0
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2010 FUJITSU LIMITED
4 * Copyright (C) 2010 Tomohiro Kusumi <kusumi.tomohiro@jp.fujitsu.com>
5 */
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]))
14 static const char *
15 scsi_trace_misc(struct trace_seq *, unsigned char *, int);
17 static const char *
18 scsi_trace_rw6(struct trace_seq *p, unsigned char *cdb, int len)
20 const char *ret = trace_seq_buffer_ptr(p);
21 u32 lba = 0, txlen;
23 lba |= ((cdb[1] & 0x1F) << 16);
24 lba |= (cdb[2] << 8);
25 lba |= cdb[3];
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);
33 trace_seq_putc(p, 0);
35 return ret;
38 static const char *
39 scsi_trace_rw10(struct trace_seq *p, unsigned char *cdb, int len)
41 const char *ret = trace_seq_buffer_ptr(p);
42 u32 lba, txlen;
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,
48 cdb[1] >> 5);
50 if (cdb[0] == WRITE_SAME)
51 trace_seq_printf(p, " unmap=%u", cdb[1] >> 3 & 1);
53 trace_seq_putc(p, 0);
55 return ret;
58 static const char *
59 scsi_trace_rw12(struct trace_seq *p, unsigned char *cdb, int len)
61 const char *ret = trace_seq_buffer_ptr(p);
62 u32 lba, txlen;
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,
68 cdb[1] >> 5);
69 trace_seq_putc(p, 0);
71 return ret;
74 static const char *
75 scsi_trace_rw16(struct trace_seq *p, unsigned char *cdb, int len)
77 const char *ret = trace_seq_buffer_ptr(p);
78 u64 lba;
79 u32 txlen;
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,
85 cdb[1] >> 5);
87 if (cdb[0] == WRITE_SAME_16)
88 trace_seq_printf(p, " unmap=%u", cdb[1] >> 3 & 1);
90 trace_seq_putc(p, 0);
92 return ret;
95 static const char *
96 scsi_trace_rw32(struct trace_seq *p, unsigned char *cdb, int len)
98 const char *ret = trace_seq_buffer_ptr(p), *cmd;
99 u64 lba;
100 u32 ei_lbrt, txlen;
102 switch (SERVICE_ACTION32(cdb)) {
103 case READ_32:
104 cmd = "READ";
105 break;
106 case VERIFY_32:
107 cmd = "VERIFY";
108 break;
109 case WRITE_32:
110 cmd = "WRITE";
111 break;
112 case WRITE_SAME_32:
113 cmd = "WRITE_SAME";
114 break;
115 default:
116 trace_seq_puts(p, "UNKNOWN");
117 goto out;
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);
130 out:
131 trace_seq_putc(p, 0);
133 return ret;
136 static const char *
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);
145 return ret;
148 static const char *
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;
152 u64 lba;
153 u32 alloc_len;
155 switch (SERVICE_ACTION16(cdb)) {
156 case SAI_READ_CAPACITY_16:
157 cmd = "READ_CAPACITY_16";
158 break;
159 case SAI_GET_LBA_STATUS:
160 cmd = "GET_LBA_STATUS";
161 break;
162 default:
163 trace_seq_puts(p, "UNKNOWN");
164 goto out;
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);
172 out:
173 trace_seq_putc(p, 0);
175 return ret;
178 static const char *
179 scsi_trace_maintenance_in(struct trace_seq *p, unsigned char *cdb, int len)
181 const char *ret = trace_seq_buffer_ptr(p), *cmd;
182 u32 alloc_len;
184 switch (SERVICE_ACTION16(cdb)) {
185 case MI_REPORT_IDENTIFYING_INFORMATION:
186 cmd = "REPORT_IDENTIFYING_INFORMATION";
187 break;
188 case MI_REPORT_TARGET_PGS:
189 cmd = "REPORT_TARGET_PORT_GROUPS";
190 break;
191 case MI_REPORT_ALIASES:
192 cmd = "REPORT_ALIASES";
193 break;
194 case MI_REPORT_SUPPORTED_OPERATION_CODES:
195 cmd = "REPORT_SUPPORTED_OPERATION_CODES";
196 break;
197 case MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS:
198 cmd = "REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS";
199 break;
200 case MI_REPORT_PRIORITY:
201 cmd = "REPORT_PRIORITY";
202 break;
203 case MI_REPORT_TIMESTAMP:
204 cmd = "REPORT_TIMESTAMP";
205 break;
206 case MI_MANAGEMENT_PROTOCOL_IN:
207 cmd = "MANAGEMENT_PROTOCOL_IN";
208 break;
209 default:
210 trace_seq_puts(p, "UNKNOWN");
211 goto out;
214 alloc_len = get_unaligned_be32(&cdb[6]);
216 trace_seq_printf(p, "%s alloc_len=%u", cmd, alloc_len);
218 out:
219 trace_seq_putc(p, 0);
221 return ret;
224 static const char *
225 scsi_trace_maintenance_out(struct trace_seq *p, unsigned char *cdb, int len)
227 const char *ret = trace_seq_buffer_ptr(p), *cmd;
228 u32 alloc_len;
230 switch (SERVICE_ACTION16(cdb)) {
231 case MO_SET_IDENTIFYING_INFORMATION:
232 cmd = "SET_IDENTIFYING_INFORMATION";
233 break;
234 case MO_SET_TARGET_PGS:
235 cmd = "SET_TARGET_PORT_GROUPS";
236 break;
237 case MO_CHANGE_ALIASES:
238 cmd = "CHANGE_ALIASES";
239 break;
240 case MO_SET_PRIORITY:
241 cmd = "SET_PRIORITY";
242 break;
243 case MO_SET_TIMESTAMP:
244 cmd = "SET_TIMESTAMP";
245 break;
246 case MO_MANAGEMENT_PROTOCOL_OUT:
247 cmd = "MANAGEMENT_PROTOCOL_OUT";
248 break;
249 default:
250 trace_seq_puts(p, "UNKNOWN");
251 goto out;
254 alloc_len = get_unaligned_be32(&cdb[6]);
256 trace_seq_printf(p, "%s alloc_len=%u", cmd, alloc_len);
258 out:
259 trace_seq_putc(p, 0);
261 return ret;
264 static const char *
265 scsi_trace_zbc_in(struct trace_seq *p, unsigned char *cdb, int len)
267 const char *ret = trace_seq_buffer_ptr(p), *cmd;
268 u64 zone_id;
269 u32 alloc_len;
270 u8 options;
272 switch (SERVICE_ACTION16(cdb)) {
273 case ZI_REPORT_ZONES:
274 cmd = "REPORT_ZONES";
275 break;
276 default:
277 trace_seq_puts(p, "UNKNOWN");
278 goto out;
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);
289 out:
290 trace_seq_putc(p, 0);
292 return ret;
295 static const char *
296 scsi_trace_zbc_out(struct trace_seq *p, unsigned char *cdb, int len)
298 const char *ret = trace_seq_buffer_ptr(p), *cmd;
299 u64 zone_id;
301 switch (SERVICE_ACTION16(cdb)) {
302 case ZO_CLOSE_ZONE:
303 cmd = "CLOSE_ZONE";
304 break;
305 case ZO_FINISH_ZONE:
306 cmd = "FINISH_ZONE";
307 break;
308 case ZO_OPEN_ZONE:
309 cmd = "OPEN_ZONE";
310 break;
311 case ZO_RESET_WRITE_POINTER:
312 cmd = "RESET_WRITE_POINTER";
313 break;
314 default:
315 trace_seq_puts(p, "UNKNOWN");
316 goto out;
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);
324 out:
325 trace_seq_putc(p, 0);
327 return ret;
330 static const char *
331 scsi_trace_varlen(struct trace_seq *p, unsigned char *cdb, int len)
333 switch (SERVICE_ACTION32(cdb)) {
334 case READ_32:
335 case VERIFY_32:
336 case WRITE_32:
337 case WRITE_SAME_32:
338 return scsi_trace_rw32(p, cdb, len);
339 default:
340 return scsi_trace_misc(p, cdb, len);
344 static const char *
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);
352 return ret;
355 const char *
356 scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len)
358 switch (cdb[0]) {
359 case READ_6:
360 case WRITE_6:
361 return scsi_trace_rw6(p, cdb, len);
362 case READ_10:
363 case VERIFY:
364 case WRITE_10:
365 case WRITE_SAME:
366 return scsi_trace_rw10(p, cdb, len);
367 case READ_12:
368 case VERIFY_12:
369 case WRITE_12:
370 return scsi_trace_rw12(p, cdb, len);
371 case READ_16:
372 case VERIFY_16:
373 case WRITE_16:
374 case WRITE_SAME_16:
375 return scsi_trace_rw16(p, cdb, len);
376 case UNMAP:
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);
382 case MAINTENANCE_IN:
383 return scsi_trace_maintenance_in(p, cdb, len);
384 case MAINTENANCE_OUT:
385 return scsi_trace_maintenance_out(p, cdb, len);
386 case ZBC_IN:
387 return scsi_trace_zbc_in(p, cdb, len);
388 case ZBC_OUT:
389 return scsi_trace_zbc_out(p, cdb, len);
390 default:
391 return scsi_trace_misc(p, cdb, len);