4 #include "event-parse.h"
6 typedef unsigned long sector_t
;
8 typedef unsigned int u32
;
13 #define TEST_UNIT_READY 0x00
14 #define REZERO_UNIT 0x01
15 #define REQUEST_SENSE 0x03
16 #define FORMAT_UNIT 0x04
17 #define READ_BLOCK_LIMITS 0x05
18 #define REASSIGN_BLOCKS 0x07
19 #define INITIALIZE_ELEMENT_STATUS 0x07
23 #define READ_REVERSE 0x0f
24 #define WRITE_FILEMARKS 0x10
27 #define RECOVER_BUFFERED_DATA 0x14
28 #define MODE_SELECT 0x15
33 #define MODE_SENSE 0x1a
34 #define START_STOP 0x1b
35 #define RECEIVE_DIAGNOSTIC 0x1c
36 #define SEND_DIAGNOSTIC 0x1d
37 #define ALLOW_MEDIUM_REMOVAL 0x1e
39 #define READ_FORMAT_CAPACITIES 0x23
40 #define SET_WINDOW 0x24
41 #define READ_CAPACITY 0x25
45 #define POSITION_TO_ELEMENT 0x2b
46 #define WRITE_VERIFY 0x2e
48 #define SEARCH_HIGH 0x30
49 #define SEARCH_EQUAL 0x31
50 #define SEARCH_LOW 0x32
51 #define SET_LIMITS 0x33
52 #define PRE_FETCH 0x34
53 #define READ_POSITION 0x34
54 #define SYNCHRONIZE_CACHE 0x35
55 #define LOCK_UNLOCK_CACHE 0x36
56 #define READ_DEFECT_DATA 0x37
57 #define MEDIUM_SCAN 0x38
59 #define COPY_VERIFY 0x3a
60 #define WRITE_BUFFER 0x3b
61 #define READ_BUFFER 0x3c
62 #define UPDATE_BLOCK 0x3d
63 #define READ_LONG 0x3e
64 #define WRITE_LONG 0x3f
65 #define CHANGE_DEFINITION 0x40
66 #define WRITE_SAME 0x41
69 #define READ_HEADER 0x44
70 #define GET_EVENT_STATUS_NOTIFICATION 0x4a
71 #define LOG_SELECT 0x4c
72 #define LOG_SENSE 0x4d
73 #define XDWRITEREAD_10 0x53
74 #define MODE_SELECT_10 0x55
75 #define RESERVE_10 0x56
76 #define RELEASE_10 0x57
77 #define MODE_SENSE_10 0x5a
78 #define PERSISTENT_RESERVE_IN 0x5e
79 #define PERSISTENT_RESERVE_OUT 0x5f
80 #define VARIABLE_LENGTH_CMD 0x7f
81 #define REPORT_LUNS 0xa0
82 #define SECURITY_PROTOCOL_IN 0xa2
83 #define MAINTENANCE_IN 0xa3
84 #define MAINTENANCE_OUT 0xa4
85 #define MOVE_MEDIUM 0xa5
86 #define EXCHANGE_MEDIUM 0xa6
88 #define SERVICE_ACTION_OUT_12 0xa9
90 #define SERVICE_ACTION_IN_12 0xab
91 #define WRITE_VERIFY_12 0xae
92 #define VERIFY_12 0xaf
93 #define SEARCH_HIGH_12 0xb0
94 #define SEARCH_EQUAL_12 0xb1
95 #define SEARCH_LOW_12 0xb2
96 #define SECURITY_PROTOCOL_OUT 0xb5
97 #define READ_ELEMENT_STATUS 0xb8
98 #define SEND_VOLUME_TAG 0xb6
99 #define WRITE_LONG_2 0xea
100 #define EXTENDED_COPY 0x83
101 #define RECEIVE_COPY_RESULTS 0x84
102 #define ACCESS_CONTROL_IN 0x86
103 #define ACCESS_CONTROL_OUT 0x87
105 #define WRITE_16 0x8a
106 #define READ_ATTRIBUTE 0x8c
107 #define WRITE_ATTRIBUTE 0x8d
108 #define VERIFY_16 0x8f
109 #define SYNCHRONIZE_CACHE_16 0x91
110 #define WRITE_SAME_16 0x93
111 #define SERVICE_ACTION_BIDIRECTIONAL 0x9d
112 #define SERVICE_ACTION_IN_16 0x9e
113 #define SERVICE_ACTION_OUT_16 0x9f
114 /* values for service action in */
115 #define SAI_READ_CAPACITY_16 0x10
116 #define SAI_GET_LBA_STATUS 0x12
117 /* values for VARIABLE_LENGTH_CMD service action codes
118 * see spc4r17 Section D.3.5, table D.7 and D.8 */
119 #define VLC_SA_RECEIVE_CREDENTIAL 0x1800
120 /* values for maintenance in */
121 #define MI_REPORT_IDENTIFYING_INFORMATION 0x05
122 #define MI_REPORT_TARGET_PGS 0x0a
123 #define MI_REPORT_ALIASES 0x0b
124 #define MI_REPORT_SUPPORTED_OPERATION_CODES 0x0c
125 #define MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0d
126 #define MI_REPORT_PRIORITY 0x0e
127 #define MI_REPORT_TIMESTAMP 0x0f
128 #define MI_MANAGEMENT_PROTOCOL_IN 0x10
129 /* value for MI_REPORT_TARGET_PGS ext header */
130 #define MI_EXT_HDR_PARAM_FMT 0x20
131 /* values for maintenance out */
132 #define MO_SET_IDENTIFYING_INFORMATION 0x06
133 #define MO_SET_TARGET_PGS 0x0a
134 #define MO_CHANGE_ALIASES 0x0b
135 #define MO_SET_PRIORITY 0x0e
136 #define MO_SET_TIMESTAMP 0x0f
137 #define MO_MANAGEMENT_PROTOCOL_OUT 0x10
138 /* values for variable length command */
139 #define XDREAD_32 0x03
140 #define XDWRITE_32 0x04
141 #define XPWRITE_32 0x06
142 #define XDWRITEREAD_32 0x07
144 #define VERIFY_32 0x0a
145 #define WRITE_32 0x0b
146 #define WRITE_SAME_32 0x0d
148 #define SERVICE_ACTION16(cdb) (cdb[1] & 0x1f)
149 #define SERVICE_ACTION32(cdb) ((cdb[8] << 8) | cdb[9])
152 scsi_trace_misc(struct trace_seq
*, unsigned char *, int);
155 scsi_trace_rw6(struct trace_seq
*p
, unsigned char *cdb
, int len
)
157 const char *ret
= p
->buffer
+ p
->len
;
158 sector_t lba
= 0, txlen
= 0;
160 lba
|= ((cdb
[1] & 0x1F) << 16);
161 lba
|= (cdb
[2] << 8);
165 trace_seq_printf(p
, "lba=%llu txlen=%llu",
166 (unsigned long long)lba
, (unsigned long long)txlen
);
167 trace_seq_putc(p
, 0);
172 scsi_trace_rw10(struct trace_seq
*p
, unsigned char *cdb
, int len
)
174 const char *ret
= p
->buffer
+ p
->len
;
175 sector_t lba
= 0, txlen
= 0;
177 lba
|= (cdb
[2] << 24);
178 lba
|= (cdb
[3] << 16);
179 lba
|= (cdb
[4] << 8);
181 txlen
|= (cdb
[7] << 8);
184 trace_seq_printf(p
, "lba=%llu txlen=%llu protect=%u",
185 (unsigned long long)lba
, (unsigned long long)txlen
,
188 if (cdb
[0] == WRITE_SAME
)
189 trace_seq_printf(p
, " unmap=%u", cdb
[1] >> 3 & 1);
191 trace_seq_putc(p
, 0);
196 scsi_trace_rw12(struct trace_seq
*p
, unsigned char *cdb
, int len
)
198 const char *ret
= p
->buffer
+ p
->len
;
199 sector_t lba
= 0, txlen
= 0;
201 lba
|= (cdb
[2] << 24);
202 lba
|= (cdb
[3] << 16);
203 lba
|= (cdb
[4] << 8);
205 txlen
|= (cdb
[6] << 24);
206 txlen
|= (cdb
[7] << 16);
207 txlen
|= (cdb
[8] << 8);
210 trace_seq_printf(p
, "lba=%llu txlen=%llu protect=%u",
211 (unsigned long long)lba
, (unsigned long long)txlen
,
213 trace_seq_putc(p
, 0);
218 scsi_trace_rw16(struct trace_seq
*p
, unsigned char *cdb
, int len
)
220 const char *ret
= p
->buffer
+ p
->len
;
221 sector_t lba
= 0, txlen
= 0;
223 lba
|= ((u64
)cdb
[2] << 56);
224 lba
|= ((u64
)cdb
[3] << 48);
225 lba
|= ((u64
)cdb
[4] << 40);
226 lba
|= ((u64
)cdb
[5] << 32);
227 lba
|= (cdb
[6] << 24);
228 lba
|= (cdb
[7] << 16);
229 lba
|= (cdb
[8] << 8);
231 txlen
|= (cdb
[10] << 24);
232 txlen
|= (cdb
[11] << 16);
233 txlen
|= (cdb
[12] << 8);
236 trace_seq_printf(p
, "lba=%llu txlen=%llu protect=%u",
237 (unsigned long long)lba
, (unsigned long long)txlen
,
240 if (cdb
[0] == WRITE_SAME_16
)
241 trace_seq_printf(p
, " unmap=%u", cdb
[1] >> 3 & 1);
243 trace_seq_putc(p
, 0);
248 scsi_trace_rw32(struct trace_seq
*p
, unsigned char *cdb
, int len
)
250 const char *ret
= p
->buffer
+ p
->len
, *cmd
;
251 sector_t lba
= 0, txlen
= 0;
254 switch (SERVICE_ACTION32(cdb
)) {
268 trace_seq_printf(p
, "UNKNOWN");
272 lba
|= ((u64
)cdb
[12] << 56);
273 lba
|= ((u64
)cdb
[13] << 48);
274 lba
|= ((u64
)cdb
[14] << 40);
275 lba
|= ((u64
)cdb
[15] << 32);
276 lba
|= (cdb
[16] << 24);
277 lba
|= (cdb
[17] << 16);
278 lba
|= (cdb
[18] << 8);
280 ei_lbrt
|= (cdb
[20] << 24);
281 ei_lbrt
|= (cdb
[21] << 16);
282 ei_lbrt
|= (cdb
[22] << 8);
284 txlen
|= (cdb
[28] << 24);
285 txlen
|= (cdb
[29] << 16);
286 txlen
|= (cdb
[30] << 8);
289 trace_seq_printf(p
, "%s_32 lba=%llu txlen=%llu protect=%u ei_lbrt=%u",
290 cmd
, (unsigned long long)lba
,
291 (unsigned long long)txlen
, cdb
[10] >> 5, ei_lbrt
);
293 if (SERVICE_ACTION32(cdb
) == WRITE_SAME_32
)
294 trace_seq_printf(p
, " unmap=%u", cdb
[10] >> 3 & 1);
297 trace_seq_putc(p
, 0);
302 scsi_trace_unmap(struct trace_seq
*p
, unsigned char *cdb
, int len
)
304 const char *ret
= p
->buffer
+ p
->len
;
305 unsigned int regions
= cdb
[7] << 8 | cdb
[8];
307 trace_seq_printf(p
, "regions=%u", (regions
- 8) / 16);
308 trace_seq_putc(p
, 0);
313 scsi_trace_service_action_in(struct trace_seq
*p
, unsigned char *cdb
, int len
)
315 const char *ret
= p
->buffer
+ p
->len
, *cmd
;
319 switch (SERVICE_ACTION16(cdb
)) {
320 case SAI_READ_CAPACITY_16
:
321 cmd
= "READ_CAPACITY_16";
323 case SAI_GET_LBA_STATUS
:
324 cmd
= "GET_LBA_STATUS";
327 trace_seq_printf(p
, "UNKNOWN");
331 lba
|= ((u64
)cdb
[2] << 56);
332 lba
|= ((u64
)cdb
[3] << 48);
333 lba
|= ((u64
)cdb
[4] << 40);
334 lba
|= ((u64
)cdb
[5] << 32);
335 lba
|= (cdb
[6] << 24);
336 lba
|= (cdb
[7] << 16);
337 lba
|= (cdb
[8] << 8);
339 alloc_len
|= (cdb
[10] << 24);
340 alloc_len
|= (cdb
[11] << 16);
341 alloc_len
|= (cdb
[12] << 8);
342 alloc_len
|= cdb
[13];
344 trace_seq_printf(p
, "%s lba=%llu alloc_len=%u", cmd
,
345 (unsigned long long)lba
, alloc_len
);
348 trace_seq_putc(p
, 0);
353 scsi_trace_varlen(struct trace_seq
*p
, unsigned char *cdb
, int len
)
355 switch (SERVICE_ACTION32(cdb
)) {
360 return scsi_trace_rw32(p
, cdb
, len
);
362 return scsi_trace_misc(p
, cdb
, len
);
367 scsi_trace_misc(struct trace_seq
*p
, unsigned char *cdb
, int len
)
369 const char *ret
= p
->buffer
+ p
->len
;
371 trace_seq_printf(p
, "-");
372 trace_seq_putc(p
, 0);
377 scsi_trace_parse_cdb(struct trace_seq
*p
, unsigned char *cdb
, int len
)
382 return scsi_trace_rw6(p
, cdb
, len
);
387 return scsi_trace_rw10(p
, cdb
, len
);
391 return scsi_trace_rw12(p
, cdb
, len
);
396 return scsi_trace_rw16(p
, cdb
, len
);
398 return scsi_trace_unmap(p
, cdb
, len
);
399 case SERVICE_ACTION_IN_16
:
400 return scsi_trace_service_action_in(p
, cdb
, len
);
401 case VARIABLE_LENGTH_CMD
:
402 return scsi_trace_varlen(p
, cdb
, len
);
404 return scsi_trace_misc(p
, cdb
, len
);
408 unsigned long long process_scsi_trace_parse_cdb(struct trace_seq
*s
,
409 unsigned long long *args
)
411 scsi_trace_parse_cdb(s
, (unsigned char *) (unsigned long) args
[1], args
[2]);
415 int PEVENT_PLUGIN_LOADER(struct pevent
*pevent
)
417 pevent_register_print_function(pevent
,
418 process_scsi_trace_parse_cdb
,
419 PEVENT_FUNC_ARG_STRING
,
420 "scsi_trace_parse_cdb",
424 PEVENT_FUNC_ARG_VOID
);
428 void PEVENT_PLUGIN_UNLOADER(struct pevent
*pevent
)
430 pevent_unregister_print_function(pevent
, process_scsi_trace_parse_cdb
,
431 "scsi_trace_parse_cdb");