blob: ac35c301c792103ed8f527d438e9434ea25664c0 [file] [log] [blame]
Thomas Gleixner2b27bdc2019-05-29 16:57:50 -07001// SPDX-License-Identifier: GPL-2.0-only
Kei Tokunagabf816232010-04-01 20:41:40 +09002/*
3 * Copyright (C) 2010 FUJITSU LIMITED
4 * Copyright (C) 2010 Tomohiro Kusumi <kusumi.tomohiro@jp.fujitsu.com>
Kei Tokunagabf816232010-04-01 20:41:40 +09005 */
6#include <linux/kernel.h>
7#include <linux/trace_seq.h>
Hannes Reinecke5141f162016-03-24 15:21:19 +01008#include <asm/unaligned.h>
Kei Tokunagabf816232010-04-01 20:41:40 +09009#include <trace/events/scsi.h>
10
Martin K. Petersenc446c1f2010-03-23 01:16:57 -040011#define SERVICE_ACTION16(cdb) (cdb[1] & 0x1f)
Bart Van Asscheb1335f52019-11-01 14:14:47 -070012#define SERVICE_ACTION32(cdb) (get_unaligned_be16(&cdb[8]))
Kei Tokunagabf816232010-04-01 20:41:40 +090013
14static const char *
15scsi_trace_misc(struct trace_seq *, unsigned char *, int);
16
17static const char *
18scsi_trace_rw6(struct trace_seq *p, unsigned char *cdb, int len)
19{
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -040020 const char *ret = trace_seq_buffer_ptr(p);
Bart Van Asschef6b85402019-11-05 13:55:53 -080021 u32 lba = 0, txlen;
Kei Tokunagabf816232010-04-01 20:41:40 +090022
23 lba |= ((cdb[1] & 0x1F) << 16);
24 lba |= (cdb[2] << 8);
25 lba |= cdb[3];
Bart Van Asschef6b85402019-11-05 13:55:53 -080026 /*
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)).
29 */
30 txlen = cdb[4] ? cdb[4] : 256;
Kei Tokunagabf816232010-04-01 20:41:40 +090031
Bart Van Asschef6b85402019-11-05 13:55:53 -080032 trace_seq_printf(p, "lba=%u txlen=%u", lba, txlen);
Kei Tokunagabf816232010-04-01 20:41:40 +090033 trace_seq_putc(p, 0);
34
35 return ret;
36}
37
38static const char *
39scsi_trace_rw10(struct trace_seq *p, unsigned char *cdb, int len)
40{
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -040041 const char *ret = trace_seq_buffer_ptr(p);
Bart Van Asscheb1335f52019-11-01 14:14:47 -070042 u32 lba, txlen;
Kei Tokunagabf816232010-04-01 20:41:40 +090043
Bart Van Asscheb1335f52019-11-01 14:14:47 -070044 lba = get_unaligned_be32(&cdb[2]);
45 txlen = get_unaligned_be16(&cdb[7]);
Kei Tokunagabf816232010-04-01 20:41:40 +090046
Bart Van Asscheb1335f52019-11-01 14:14:47 -070047 trace_seq_printf(p, "lba=%u txlen=%u protect=%u", lba, txlen,
Martin K. Petersenc446c1f2010-03-23 01:16:57 -040048 cdb[1] >> 5);
Martin K. Petersenc498bf12011-05-18 00:46:34 -040049
50 if (cdb[0] == WRITE_SAME)
51 trace_seq_printf(p, " unmap=%u", cdb[1] >> 3 & 1);
52
Kei Tokunagabf816232010-04-01 20:41:40 +090053 trace_seq_putc(p, 0);
54
55 return ret;
56}
57
58static const char *
59scsi_trace_rw12(struct trace_seq *p, unsigned char *cdb, int len)
60{
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -040061 const char *ret = trace_seq_buffer_ptr(p);
Bart Van Asscheb1335f52019-11-01 14:14:47 -070062 u32 lba, txlen;
Kei Tokunagabf816232010-04-01 20:41:40 +090063
Bart Van Asscheb1335f52019-11-01 14:14:47 -070064 lba = get_unaligned_be32(&cdb[2]);
65 txlen = get_unaligned_be32(&cdb[6]);
Kei Tokunagabf816232010-04-01 20:41:40 +090066
Bart Van Asscheb1335f52019-11-01 14:14:47 -070067 trace_seq_printf(p, "lba=%u txlen=%u protect=%u", lba, txlen,
Martin K. Petersenc446c1f2010-03-23 01:16:57 -040068 cdb[1] >> 5);
Kei Tokunagabf816232010-04-01 20:41:40 +090069 trace_seq_putc(p, 0);
70
71 return ret;
72}
73
74static const char *
75scsi_trace_rw16(struct trace_seq *p, unsigned char *cdb, int len)
76{
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -040077 const char *ret = trace_seq_buffer_ptr(p);
Bart Van Asscheb1335f52019-11-01 14:14:47 -070078 u64 lba;
79 u32 txlen;
Kei Tokunagabf816232010-04-01 20:41:40 +090080
Bart Van Asscheb1335f52019-11-01 14:14:47 -070081 lba = get_unaligned_be64(&cdb[2]);
82 txlen = get_unaligned_be32(&cdb[10]);
Kei Tokunagabf816232010-04-01 20:41:40 +090083
Bart Van Asscheb1335f52019-11-01 14:14:47 -070084 trace_seq_printf(p, "lba=%llu txlen=%u protect=%u", lba, txlen,
Martin K. Petersenc446c1f2010-03-23 01:16:57 -040085 cdb[1] >> 5);
86
87 if (cdb[0] == WRITE_SAME_16)
88 trace_seq_printf(p, " unmap=%u", cdb[1] >> 3 & 1);
89
Kei Tokunagabf816232010-04-01 20:41:40 +090090 trace_seq_putc(p, 0);
91
92 return ret;
93}
94
95static const char *
96scsi_trace_rw32(struct trace_seq *p, unsigned char *cdb, int len)
97{
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -040098 const char *ret = trace_seq_buffer_ptr(p), *cmd;
Bart Van Asscheb1335f52019-11-01 14:14:47 -070099 u64 lba;
100 u32 ei_lbrt, txlen;
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400101
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:
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100116 trace_seq_puts(p, "UNKNOWN");
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400117 goto out;
118 }
Kei Tokunagabf816232010-04-01 20:41:40 +0900119
Bart Van Asscheb1335f52019-11-01 14:14:47 -0700120 lba = get_unaligned_be64(&cdb[12]);
121 ei_lbrt = get_unaligned_be32(&cdb[20]);
122 txlen = get_unaligned_be32(&cdb[28]);
Kei Tokunagabf816232010-04-01 20:41:40 +0900123
Bart Van Asscheb1335f52019-11-01 14:14:47 -0700124 trace_seq_printf(p, "%s_32 lba=%llu txlen=%u protect=%u ei_lbrt=%u",
125 cmd, lba, txlen, cdb[10] >> 5, ei_lbrt);
Kei Tokunagabf816232010-04-01 20:41:40 +0900126
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400127 if (SERVICE_ACTION32(cdb) == WRITE_SAME_32)
128 trace_seq_printf(p, " unmap=%u", cdb[10] >> 3 & 1);
129
130out:
131 trace_seq_putc(p, 0);
132
133 return ret;
134}
135
136static const char *
137scsi_trace_unmap(struct trace_seq *p, unsigned char *cdb, int len)
138{
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -0400139 const char *ret = trace_seq_buffer_ptr(p);
Bart Van Asscheb1335f52019-11-01 14:14:47 -0700140 unsigned int regions = get_unaligned_be16(&cdb[7]);
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400141
142 trace_seq_printf(p, "regions=%u", (regions - 8) / 16);
143 trace_seq_putc(p, 0);
144
145 return ret;
146}
147
148static const char *
149scsi_trace_service_action_in(struct trace_seq *p, unsigned char *cdb, int len)
150{
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -0400151 const char *ret = trace_seq_buffer_ptr(p), *cmd;
Bart Van Asscheb1335f52019-11-01 14:14:47 -0700152 u64 lba;
153 u32 alloc_len;
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400154
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:
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100163 trace_seq_puts(p, "UNKNOWN");
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400164 goto out;
165 }
166
Bart Van Asscheb1335f52019-11-01 14:14:47 -0700167 lba = get_unaligned_be64(&cdb[2]);
168 alloc_len = get_unaligned_be32(&cdb[10]);
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400169
Bart Van Asscheb1335f52019-11-01 14:14:47 -0700170 trace_seq_printf(p, "%s lba=%llu alloc_len=%u", cmd, lba, alloc_len);
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400171
172out:
Kei Tokunagabf816232010-04-01 20:41:40 +0900173 trace_seq_putc(p, 0);
174
175 return ret;
176}
177
178static const char *
Hannes Reinecke5141f162016-03-24 15:21:19 +0100179scsi_trace_maintenance_in(struct trace_seq *p, unsigned char *cdb, int len)
180{
181 const char *ret = trace_seq_buffer_ptr(p), *cmd;
182 u32 alloc_len;
183
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;
212 }
213
214 alloc_len = get_unaligned_be32(&cdb[6]);
215
216 trace_seq_printf(p, "%s alloc_len=%u", cmd, alloc_len);
217
218out:
219 trace_seq_putc(p, 0);
220
221 return ret;
222}
223
224static const char *
225scsi_trace_maintenance_out(struct trace_seq *p, unsigned char *cdb, int len)
226{
227 const char *ret = trace_seq_buffer_ptr(p), *cmd;
228 u32 alloc_len;
229
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;
252 }
253
254 alloc_len = get_unaligned_be32(&cdb[6]);
255
256 trace_seq_printf(p, "%s alloc_len=%u", cmd, alloc_len);
257
258out:
259 trace_seq_putc(p, 0);
260
261 return ret;
262}
263
264static const char *
Hannes Reinecke0008f1e2016-03-24 17:23:56 +0100265scsi_trace_zbc_in(struct trace_seq *p, unsigned char *cdb, int len)
266{
267 const char *ret = trace_seq_buffer_ptr(p), *cmd;
268 u64 zone_id;
269 u32 alloc_len;
270 u8 options;
271
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;
279 }
280
281 zone_id = get_unaligned_be64(&cdb[2]);
282 alloc_len = get_unaligned_be32(&cdb[10]);
283 options = cdb[14] & 0x3f;
284
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);
288
289out:
290 trace_seq_putc(p, 0);
291
292 return ret;
293}
294
295static const char *
296scsi_trace_zbc_out(struct trace_seq *p, unsigned char *cdb, int len)
297{
298 const char *ret = trace_seq_buffer_ptr(p), *cmd;
299 u64 zone_id;
300
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;
317 }
318
319 zone_id = get_unaligned_be64(&cdb[2]);
320
321 trace_seq_printf(p, "%s zone=%llu all=%u", cmd,
322 (unsigned long long)zone_id, cdb[14] & 1);
323
324out:
325 trace_seq_putc(p, 0);
326
327 return ret;
328}
329
330static const char *
Kei Tokunagabf816232010-04-01 20:41:40 +0900331scsi_trace_varlen(struct trace_seq *p, unsigned char *cdb, int len)
332{
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400333 switch (SERVICE_ACTION32(cdb)) {
Kei Tokunagabf816232010-04-01 20:41:40 +0900334 case READ_32:
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400335 case VERIFY_32:
Kei Tokunagabf816232010-04-01 20:41:40 +0900336 case WRITE_32:
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400337 case WRITE_SAME_32:
Kei Tokunagabf816232010-04-01 20:41:40 +0900338 return scsi_trace_rw32(p, cdb, len);
339 default:
340 return scsi_trace_misc(p, cdb, len);
341 }
342}
343
344static const char *
345scsi_trace_misc(struct trace_seq *p, unsigned char *cdb, int len)
346{
Steven Rostedt (Red Hat)7b039cb2014-06-26 09:42:41 -0400347 const char *ret = trace_seq_buffer_ptr(p);
Kei Tokunagabf816232010-04-01 20:41:40 +0900348
Rasmus Villemoesf50332f2014-12-03 00:10:54 +0100349 trace_seq_putc(p, '-');
Kei Tokunagabf816232010-04-01 20:41:40 +0900350 trace_seq_putc(p, 0);
351
352 return ret;
353}
354
355const char *
356scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len)
357{
358 switch (cdb[0]) {
359 case READ_6:
360 case WRITE_6:
361 return scsi_trace_rw6(p, cdb, len);
362 case READ_10:
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400363 case VERIFY:
Kei Tokunagabf816232010-04-01 20:41:40 +0900364 case WRITE_10:
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400365 case WRITE_SAME:
Kei Tokunagabf816232010-04-01 20:41:40 +0900366 return scsi_trace_rw10(p, cdb, len);
367 case READ_12:
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400368 case VERIFY_12:
Kei Tokunagabf816232010-04-01 20:41:40 +0900369 case WRITE_12:
370 return scsi_trace_rw12(p, cdb, len);
371 case READ_16:
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400372 case VERIFY_16:
Kei Tokunagabf816232010-04-01 20:41:40 +0900373 case WRITE_16:
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400374 case WRITE_SAME_16:
Kei Tokunagabf816232010-04-01 20:41:40 +0900375 return scsi_trace_rw16(p, cdb, len);
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400376 case UNMAP:
377 return scsi_trace_unmap(p, cdb, len);
Hannes Reineckeeb846d92014-11-17 14:25:19 +0100378 case SERVICE_ACTION_IN_16:
Martin K. Petersenc446c1f2010-03-23 01:16:57 -0400379 return scsi_trace_service_action_in(p, cdb, len);
Kei Tokunagabf816232010-04-01 20:41:40 +0900380 case VARIABLE_LENGTH_CMD:
381 return scsi_trace_varlen(p, cdb, len);
Hannes Reinecke5141f162016-03-24 15:21:19 +0100382 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);
Hannes Reinecke0008f1e2016-03-24 17:23:56 +0100386 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);
Kei Tokunagabf816232010-04-01 20:41:40 +0900390 default:
391 return scsi_trace_misc(p, cdb, len);
392 }
393}