1 // SPDX-License-Identifier: GPL-2.0
5 #include "event-parse.h"
8 typedef unsigned long sector_t
;
10 typedef unsigned int u32
;
15 #define TEST_UNIT_READY 0x00
16 #define REZERO_UNIT 0x01
17 #define REQUEST_SENSE 0x03
18 #define FORMAT_UNIT 0x04
19 #define READ_BLOCK_LIMITS 0x05
20 #define REASSIGN_BLOCKS 0x07
21 #define INITIALIZE_ELEMENT_STATUS 0x07
25 #define READ_REVERSE 0x0f
26 #define WRITE_FILEMARKS 0x10
29 #define RECOVER_BUFFERED_DATA 0x14
30 #define MODE_SELECT 0x15
35 #define MODE_SENSE 0x1a
36 #define START_STOP 0x1b
37 #define RECEIVE_DIAGNOSTIC 0x1c
38 #define SEND_DIAGNOSTIC 0x1d
39 #define ALLOW_MEDIUM_REMOVAL 0x1e
41 #define READ_FORMAT_CAPACITIES 0x23
42 #define SET_WINDOW 0x24
43 #define READ_CAPACITY 0x25
47 #define POSITION_TO_ELEMENT 0x2b
48 #define WRITE_VERIFY 0x2e
50 #define SEARCH_HIGH 0x30
51 #define SEARCH_EQUAL 0x31
52 #define SEARCH_LOW 0x32
53 #define SET_LIMITS 0x33
54 #define PRE_FETCH 0x34
55 #define READ_POSITION 0x34
56 #define SYNCHRONIZE_CACHE 0x35
57 #define LOCK_UNLOCK_CACHE 0x36
58 #define READ_DEFECT_DATA 0x37
59 #define MEDIUM_SCAN 0x38
61 #define COPY_VERIFY 0x3a
62 #define WRITE_BUFFER 0x3b
63 #define READ_BUFFER 0x3c
64 #define UPDATE_BLOCK 0x3d
65 #define READ_LONG 0x3e
66 #define WRITE_LONG 0x3f
67 #define CHANGE_DEFINITION 0x40
68 #define WRITE_SAME 0x41
71 #define READ_HEADER 0x44
72 #define GET_EVENT_STATUS_NOTIFICATION 0x4a
73 #define LOG_SELECT 0x4c
74 #define LOG_SENSE 0x4d
75 #define XDWRITEREAD_10 0x53
76 #define MODE_SELECT_10 0x55
77 #define RESERVE_10 0x56
78 #define RELEASE_10 0x57
79 #define MODE_SENSE_10 0x5a
80 #define PERSISTENT_RESERVE_IN 0x5e
81 #define PERSISTENT_RESERVE_OUT 0x5f
82 #define VARIABLE_LENGTH_CMD 0x7f
83 #define REPORT_LUNS 0xa0
84 #define SECURITY_PROTOCOL_IN 0xa2
85 #define MAINTENANCE_IN 0xa3
86 #define MAINTENANCE_OUT 0xa4
87 #define MOVE_MEDIUM 0xa5
88 #define EXCHANGE_MEDIUM 0xa6
90 #define SERVICE_ACTION_OUT_12 0xa9
92 #define SERVICE_ACTION_IN_12 0xab
93 #define WRITE_VERIFY_12 0xae
94 #define VERIFY_12 0xaf
95 #define SEARCH_HIGH_12 0xb0
96 #define SEARCH_EQUAL_12 0xb1
97 #define SEARCH_LOW_12 0xb2
98 #define SECURITY_PROTOCOL_OUT 0xb5
99 #define READ_ELEMENT_STATUS 0xb8
100 #define SEND_VOLUME_TAG 0xb6
101 #define WRITE_LONG_2 0xea
102 #define EXTENDED_COPY 0x83
103 #define RECEIVE_COPY_RESULTS 0x84
104 #define ACCESS_CONTROL_IN 0x86
105 #define ACCESS_CONTROL_OUT 0x87
107 #define WRITE_16 0x8a
108 #define READ_ATTRIBUTE 0x8c
109 #define WRITE_ATTRIBUTE 0x8d
110 #define VERIFY_16 0x8f
111 #define SYNCHRONIZE_CACHE_16 0x91
112 #define WRITE_SAME_16 0x93
113 #define SERVICE_ACTION_BIDIRECTIONAL 0x9d
114 #define SERVICE_ACTION_IN_16 0x9e
115 #define SERVICE_ACTION_OUT_16 0x9f
116 /* values for service action in */
117 #define SAI_READ_CAPACITY_16 0x10
118 #define SAI_GET_LBA_STATUS 0x12
119 /* values for VARIABLE_LENGTH_CMD service action codes
120 * see spc4r17 Section D.3.5, table D.7 and D.8 */
121 #define VLC_SA_RECEIVE_CREDENTIAL 0x1800
122 /* values for maintenance in */
123 #define MI_REPORT_IDENTIFYING_INFORMATION 0x05
124 #define MI_REPORT_TARGET_PGS 0x0a
125 #define MI_REPORT_ALIASES 0x0b
126 #define MI_REPORT_SUPPORTED_OPERATION_CODES 0x0c
127 #define MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0d
128 #define MI_REPORT_PRIORITY 0x0e
129 #define MI_REPORT_TIMESTAMP 0x0f
130 #define MI_MANAGEMENT_PROTOCOL_IN 0x10
131 /* value for MI_REPORT_TARGET_PGS ext header */
132 #define MI_EXT_HDR_PARAM_FMT 0x20
133 /* values for maintenance out */
134 #define MO_SET_IDENTIFYING_INFORMATION 0x06
135 #define MO_SET_TARGET_PGS 0x0a
136 #define MO_CHANGE_ALIASES 0x0b
137 #define MO_SET_PRIORITY 0x0e
138 #define MO_SET_TIMESTAMP 0x0f
139 #define MO_MANAGEMENT_PROTOCOL_OUT 0x10
140 /* values for variable length command */
141 #define XDREAD_32 0x03
142 #define XDWRITE_32 0x04
143 #define XPWRITE_32 0x06
144 #define XDWRITEREAD_32 0x07
146 #define VERIFY_32 0x0a
147 #define WRITE_32 0x0b
148 #define WRITE_SAME_32 0x0d
150 #define SERVICE_ACTION16(cdb) (cdb[1] & 0x1f)
151 #define SERVICE_ACTION32(cdb) ((cdb[8] << 8) | cdb[9])
154 scsi_trace_misc(struct trace_seq
*, unsigned char *, int);
157 scsi_trace_rw6(struct trace_seq
*p
, unsigned char *cdb
, int len
)
159 const char *ret
= p
->buffer
+ p
->len
;
160 sector_t lba
= 0, txlen
= 0;
162 lba
|= ((cdb
[1] & 0x1F) << 16);
163 lba
|= (cdb
[2] << 8);
167 trace_seq_printf(p
, "lba=%llu txlen=%llu",
168 (unsigned long long)lba
, (unsigned long long)txlen
);
169 trace_seq_putc(p
, 0);
174 scsi_trace_rw10(struct trace_seq
*p
, unsigned char *cdb
, int len
)
176 const char *ret
= p
->buffer
+ p
->len
;
177 sector_t lba
= 0, txlen
= 0;
179 lba
|= (cdb
[2] << 24);
180 lba
|= (cdb
[3] << 16);
181 lba
|= (cdb
[4] << 8);
183 txlen
|= (cdb
[7] << 8);
186 trace_seq_printf(p
, "lba=%llu txlen=%llu protect=%u",
187 (unsigned long long)lba
, (unsigned long long)txlen
,
190 if (cdb
[0] == WRITE_SAME
)
191 trace_seq_printf(p
, " unmap=%u", cdb
[1] >> 3 & 1);
193 trace_seq_putc(p
, 0);
198 scsi_trace_rw12(struct trace_seq
*p
, unsigned char *cdb
, int len
)
200 const char *ret
= p
->buffer
+ p
->len
;
201 sector_t lba
= 0, txlen
= 0;
203 lba
|= (cdb
[2] << 24);
204 lba
|= (cdb
[3] << 16);
205 lba
|= (cdb
[4] << 8);
207 txlen
|= (cdb
[6] << 24);
208 txlen
|= (cdb
[7] << 16);
209 txlen
|= (cdb
[8] << 8);
212 trace_seq_printf(p
, "lba=%llu txlen=%llu protect=%u",
213 (unsigned long long)lba
, (unsigned long long)txlen
,
215 trace_seq_putc(p
, 0);
220 scsi_trace_rw16(struct trace_seq
*p
, unsigned char *cdb
, int len
)
222 const char *ret
= p
->buffer
+ p
->len
;
223 sector_t lba
= 0, txlen
= 0;
225 lba
|= ((u64
)cdb
[2] << 56);
226 lba
|= ((u64
)cdb
[3] << 48);
227 lba
|= ((u64
)cdb
[4] << 40);
228 lba
|= ((u64
)cdb
[5] << 32);
229 lba
|= (cdb
[6] << 24);
230 lba
|= (cdb
[7] << 16);
231 lba
|= (cdb
[8] << 8);
233 txlen
|= (cdb
[10] << 24);
234 txlen
|= (cdb
[11] << 16);
235 txlen
|= (cdb
[12] << 8);
238 trace_seq_printf(p
, "lba=%llu txlen=%llu protect=%u",
239 (unsigned long long)lba
, (unsigned long long)txlen
,
242 if (cdb
[0] == WRITE_SAME_16
)
243 trace_seq_printf(p
, " unmap=%u", cdb
[1] >> 3 & 1);
245 trace_seq_putc(p
, 0);
250 scsi_trace_rw32(struct trace_seq
*p
, unsigned char *cdb
, int len
)
252 const char *ret
= p
->buffer
+ p
->len
, *cmd
;
253 sector_t lba
= 0, txlen
= 0;
256 switch (SERVICE_ACTION32(cdb
)) {
270 trace_seq_printf(p
, "UNKNOWN");
274 lba
|= ((u64
)cdb
[12] << 56);
275 lba
|= ((u64
)cdb
[13] << 48);
276 lba
|= ((u64
)cdb
[14] << 40);
277 lba
|= ((u64
)cdb
[15] << 32);
278 lba
|= (cdb
[16] << 24);
279 lba
|= (cdb
[17] << 16);
280 lba
|= (cdb
[18] << 8);
282 ei_lbrt
|= (cdb
[20] << 24);
283 ei_lbrt
|= (cdb
[21] << 16);
284 ei_lbrt
|= (cdb
[22] << 8);
286 txlen
|= (cdb
[28] << 24);
287 txlen
|= (cdb
[29] << 16);
288 txlen
|= (cdb
[30] << 8);
291 trace_seq_printf(p
, "%s_32 lba=%llu txlen=%llu protect=%u ei_lbrt=%u",
292 cmd
, (unsigned long long)lba
,
293 (unsigned long long)txlen
, cdb
[10] >> 5, ei_lbrt
);
295 if (SERVICE_ACTION32(cdb
) == WRITE_SAME_32
)
296 trace_seq_printf(p
, " unmap=%u", cdb
[10] >> 3 & 1);
299 trace_seq_putc(p
, 0);
304 scsi_trace_unmap(struct trace_seq
*p
, unsigned char *cdb
, int len
)
306 const char *ret
= p
->buffer
+ p
->len
;
307 unsigned int regions
= cdb
[7] << 8 | cdb
[8];
309 trace_seq_printf(p
, "regions=%u", (regions
- 8) / 16);
310 trace_seq_putc(p
, 0);
315 scsi_trace_service_action_in(struct trace_seq
*p
, unsigned char *cdb
, int len
)
317 const char *ret
= p
->buffer
+ p
->len
, *cmd
;
321 switch (SERVICE_ACTION16(cdb
)) {
322 case SAI_READ_CAPACITY_16
:
323 cmd
= "READ_CAPACITY_16";
325 case SAI_GET_LBA_STATUS
:
326 cmd
= "GET_LBA_STATUS";
329 trace_seq_printf(p
, "UNKNOWN");
333 lba
|= ((u64
)cdb
[2] << 56);
334 lba
|= ((u64
)cdb
[3] << 48);
335 lba
|= ((u64
)cdb
[4] << 40);
336 lba
|= ((u64
)cdb
[5] << 32);
337 lba
|= (cdb
[6] << 24);
338 lba
|= (cdb
[7] << 16);
339 lba
|= (cdb
[8] << 8);
341 alloc_len
|= (cdb
[10] << 24);
342 alloc_len
|= (cdb
[11] << 16);
343 alloc_len
|= (cdb
[12] << 8);
344 alloc_len
|= cdb
[13];
346 trace_seq_printf(p
, "%s lba=%llu alloc_len=%u", cmd
,
347 (unsigned long long)lba
, alloc_len
);
350 trace_seq_putc(p
, 0);
355 scsi_trace_varlen(struct trace_seq
*p
, unsigned char *cdb
, int len
)
357 switch (SERVICE_ACTION32(cdb
)) {
362 return scsi_trace_rw32(p
, cdb
, len
);
364 return scsi_trace_misc(p
, cdb
, len
);
369 scsi_trace_misc(struct trace_seq
*p
, unsigned char *cdb
, int len
)
371 const char *ret
= p
->buffer
+ p
->len
;
373 trace_seq_printf(p
, "-");
374 trace_seq_putc(p
, 0);
379 scsi_trace_parse_cdb(struct trace_seq
*p
, unsigned char *cdb
, int len
)
384 return scsi_trace_rw6(p
, cdb
, len
);
389 return scsi_trace_rw10(p
, cdb
, len
);
393 return scsi_trace_rw12(p
, cdb
, len
);
398 return scsi_trace_rw16(p
, cdb
, len
);
400 return scsi_trace_unmap(p
, cdb
, len
);
401 case SERVICE_ACTION_IN_16
:
402 return scsi_trace_service_action_in(p
, cdb
, len
);
403 case VARIABLE_LENGTH_CMD
:
404 return scsi_trace_varlen(p
, cdb
, len
);
406 return scsi_trace_misc(p
, cdb
, len
);
410 unsigned long long process_scsi_trace_parse_cdb(struct trace_seq
*s
,
411 unsigned long long *args
)
413 scsi_trace_parse_cdb(s
, (unsigned char *) (unsigned long) args
[1], args
[2]);
417 int TEP_PLUGIN_LOADER(struct tep_handle
*pevent
)
419 tep_register_print_function(pevent
,
420 process_scsi_trace_parse_cdb
,
422 "scsi_trace_parse_cdb",
430 void TEP_PLUGIN_UNLOADER(struct tep_handle
*pevent
)
432 tep_unregister_print_function(pevent
, process_scsi_trace_parse_cdb
,
433 "scsi_trace_parse_cdb");