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
89 #define READ_MEDIA_SERIAL_NUMBER 0xab
90 #define WRITE_VERIFY_12 0xae
91 #define VERIFY_12 0xaf
92 #define SEARCH_HIGH_12 0xb0
93 #define SEARCH_EQUAL_12 0xb1
94 #define SEARCH_LOW_12 0xb2
95 #define SECURITY_PROTOCOL_OUT 0xb5
96 #define READ_ELEMENT_STATUS 0xb8
97 #define SEND_VOLUME_TAG 0xb6
98 #define WRITE_LONG_2 0xea
99 #define EXTENDED_COPY 0x83
100 #define RECEIVE_COPY_RESULTS 0x84
101 #define ACCESS_CONTROL_IN 0x86
102 #define ACCESS_CONTROL_OUT 0x87
104 #define WRITE_16 0x8a
105 #define READ_ATTRIBUTE 0x8c
106 #define WRITE_ATTRIBUTE 0x8d
107 #define VERIFY_16 0x8f
108 #define SYNCHRONIZE_CACHE_16 0x91
109 #define WRITE_SAME_16 0x93
110 #define SERVICE_ACTION_IN 0x9e
111 /* values for service action in */
112 #define SAI_READ_CAPACITY_16 0x10
113 #define SAI_GET_LBA_STATUS 0x12
114 /* values for VARIABLE_LENGTH_CMD service action codes
115 * see spc4r17 Section D.3.5, table D.7 and D.8 */
116 #define VLC_SA_RECEIVE_CREDENTIAL 0x1800
117 /* values for maintenance in */
118 #define MI_REPORT_IDENTIFYING_INFORMATION 0x05
119 #define MI_REPORT_TARGET_PGS 0x0a
120 #define MI_REPORT_ALIASES 0x0b
121 #define MI_REPORT_SUPPORTED_OPERATION_CODES 0x0c
122 #define MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0d
123 #define MI_REPORT_PRIORITY 0x0e
124 #define MI_REPORT_TIMESTAMP 0x0f
125 #define MI_MANAGEMENT_PROTOCOL_IN 0x10
126 /* value for MI_REPORT_TARGET_PGS ext header */
127 #define MI_EXT_HDR_PARAM_FMT 0x20
128 /* values for maintenance out */
129 #define MO_SET_IDENTIFYING_INFORMATION 0x06
130 #define MO_SET_TARGET_PGS 0x0a
131 #define MO_CHANGE_ALIASES 0x0b
132 #define MO_SET_PRIORITY 0x0e
133 #define MO_SET_TIMESTAMP 0x0f
134 #define MO_MANAGEMENT_PROTOCOL_OUT 0x10
135 /* values for variable length command */
136 #define XDREAD_32 0x03
137 #define XDWRITE_32 0x04
138 #define XPWRITE_32 0x06
139 #define XDWRITEREAD_32 0x07
141 #define VERIFY_32 0x0a
142 #define WRITE_32 0x0b
143 #define WRITE_SAME_32 0x0d
145 #define SERVICE_ACTION16(cdb) (cdb[1] & 0x1f)
146 #define SERVICE_ACTION32(cdb) ((cdb[8] << 8) | cdb[9])
149 scsi_trace_misc(struct trace_seq
*, unsigned char *, int);
152 scsi_trace_rw6(struct trace_seq
*p
, unsigned char *cdb
, int len
)
154 const char *ret
= p
->buffer
+ p
->len
;
155 sector_t lba
= 0, txlen
= 0;
157 lba
|= ((cdb
[1] & 0x1F) << 16);
158 lba
|= (cdb
[2] << 8);
162 trace_seq_printf(p
, "lba=%llu txlen=%llu",
163 (unsigned long long)lba
, (unsigned long long)txlen
);
164 trace_seq_putc(p
, 0);
169 scsi_trace_rw10(struct trace_seq
*p
, unsigned char *cdb
, int len
)
171 const char *ret
= p
->buffer
+ p
->len
;
172 sector_t lba
= 0, txlen
= 0;
174 lba
|= (cdb
[2] << 24);
175 lba
|= (cdb
[3] << 16);
176 lba
|= (cdb
[4] << 8);
178 txlen
|= (cdb
[7] << 8);
181 trace_seq_printf(p
, "lba=%llu txlen=%llu protect=%u",
182 (unsigned long long)lba
, (unsigned long long)txlen
,
185 if (cdb
[0] == WRITE_SAME
)
186 trace_seq_printf(p
, " unmap=%u", cdb
[1] >> 3 & 1);
188 trace_seq_putc(p
, 0);
193 scsi_trace_rw12(struct trace_seq
*p
, unsigned char *cdb
, int len
)
195 const char *ret
= p
->buffer
+ p
->len
;
196 sector_t lba
= 0, txlen
= 0;
198 lba
|= (cdb
[2] << 24);
199 lba
|= (cdb
[3] << 16);
200 lba
|= (cdb
[4] << 8);
202 txlen
|= (cdb
[6] << 24);
203 txlen
|= (cdb
[7] << 16);
204 txlen
|= (cdb
[8] << 8);
207 trace_seq_printf(p
, "lba=%llu txlen=%llu protect=%u",
208 (unsigned long long)lba
, (unsigned long long)txlen
,
210 trace_seq_putc(p
, 0);
215 scsi_trace_rw16(struct trace_seq
*p
, unsigned char *cdb
, int len
)
217 const char *ret
= p
->buffer
+ p
->len
;
218 sector_t lba
= 0, txlen
= 0;
220 lba
|= ((u64
)cdb
[2] << 56);
221 lba
|= ((u64
)cdb
[3] << 48);
222 lba
|= ((u64
)cdb
[4] << 40);
223 lba
|= ((u64
)cdb
[5] << 32);
224 lba
|= (cdb
[6] << 24);
225 lba
|= (cdb
[7] << 16);
226 lba
|= (cdb
[8] << 8);
228 txlen
|= (cdb
[10] << 24);
229 txlen
|= (cdb
[11] << 16);
230 txlen
|= (cdb
[12] << 8);
233 trace_seq_printf(p
, "lba=%llu txlen=%llu protect=%u",
234 (unsigned long long)lba
, (unsigned long long)txlen
,
237 if (cdb
[0] == WRITE_SAME_16
)
238 trace_seq_printf(p
, " unmap=%u", cdb
[1] >> 3 & 1);
240 trace_seq_putc(p
, 0);
245 scsi_trace_rw32(struct trace_seq
*p
, unsigned char *cdb
, int len
)
247 const char *ret
= p
->buffer
+ p
->len
, *cmd
;
248 sector_t lba
= 0, txlen
= 0;
251 switch (SERVICE_ACTION32(cdb
)) {
265 trace_seq_printf(p
, "UNKNOWN");
269 lba
|= ((u64
)cdb
[12] << 56);
270 lba
|= ((u64
)cdb
[13] << 48);
271 lba
|= ((u64
)cdb
[14] << 40);
272 lba
|= ((u64
)cdb
[15] << 32);
273 lba
|= (cdb
[16] << 24);
274 lba
|= (cdb
[17] << 16);
275 lba
|= (cdb
[18] << 8);
277 ei_lbrt
|= (cdb
[20] << 24);
278 ei_lbrt
|= (cdb
[21] << 16);
279 ei_lbrt
|= (cdb
[22] << 8);
281 txlen
|= (cdb
[28] << 24);
282 txlen
|= (cdb
[29] << 16);
283 txlen
|= (cdb
[30] << 8);
286 trace_seq_printf(p
, "%s_32 lba=%llu txlen=%llu protect=%u ei_lbrt=%u",
287 cmd
, (unsigned long long)lba
,
288 (unsigned long long)txlen
, cdb
[10] >> 5, ei_lbrt
);
290 if (SERVICE_ACTION32(cdb
) == WRITE_SAME_32
)
291 trace_seq_printf(p
, " unmap=%u", cdb
[10] >> 3 & 1);
294 trace_seq_putc(p
, 0);
299 scsi_trace_unmap(struct trace_seq
*p
, unsigned char *cdb
, int len
)
301 const char *ret
= p
->buffer
+ p
->len
;
302 unsigned int regions
= cdb
[7] << 8 | cdb
[8];
304 trace_seq_printf(p
, "regions=%u", (regions
- 8) / 16);
305 trace_seq_putc(p
, 0);
310 scsi_trace_service_action_in(struct trace_seq
*p
, unsigned char *cdb
, int len
)
312 const char *ret
= p
->buffer
+ p
->len
, *cmd
;
316 switch (SERVICE_ACTION16(cdb
)) {
317 case SAI_READ_CAPACITY_16
:
318 cmd
= "READ_CAPACITY_16";
320 case SAI_GET_LBA_STATUS
:
321 cmd
= "GET_LBA_STATUS";
324 trace_seq_printf(p
, "UNKNOWN");
328 lba
|= ((u64
)cdb
[2] << 56);
329 lba
|= ((u64
)cdb
[3] << 48);
330 lba
|= ((u64
)cdb
[4] << 40);
331 lba
|= ((u64
)cdb
[5] << 32);
332 lba
|= (cdb
[6] << 24);
333 lba
|= (cdb
[7] << 16);
334 lba
|= (cdb
[8] << 8);
336 alloc_len
|= (cdb
[10] << 24);
337 alloc_len
|= (cdb
[11] << 16);
338 alloc_len
|= (cdb
[12] << 8);
339 alloc_len
|= cdb
[13];
341 trace_seq_printf(p
, "%s lba=%llu alloc_len=%u", cmd
,
342 (unsigned long long)lba
, alloc_len
);
345 trace_seq_putc(p
, 0);
350 scsi_trace_varlen(struct trace_seq
*p
, unsigned char *cdb
, int len
)
352 switch (SERVICE_ACTION32(cdb
)) {
357 return scsi_trace_rw32(p
, cdb
, len
);
359 return scsi_trace_misc(p
, cdb
, len
);
364 scsi_trace_misc(struct trace_seq
*p
, unsigned char *cdb
, int len
)
366 const char *ret
= p
->buffer
+ p
->len
;
368 trace_seq_printf(p
, "-");
369 trace_seq_putc(p
, 0);
374 scsi_trace_parse_cdb(struct trace_seq
*p
, unsigned char *cdb
, int len
)
379 return scsi_trace_rw6(p
, cdb
, len
);
384 return scsi_trace_rw10(p
, cdb
, len
);
388 return scsi_trace_rw12(p
, cdb
, len
);
393 return scsi_trace_rw16(p
, cdb
, len
);
395 return scsi_trace_unmap(p
, cdb
, len
);
396 case SERVICE_ACTION_IN
:
397 return scsi_trace_service_action_in(p
, cdb
, len
);
398 case VARIABLE_LENGTH_CMD
:
399 return scsi_trace_varlen(p
, cdb
, len
);
401 return scsi_trace_misc(p
, cdb
, len
);
405 unsigned long long process_scsi_trace_parse_cdb(struct trace_seq
*s
,
406 unsigned long long *args
)
408 scsi_trace_parse_cdb(s
, (unsigned char *) (unsigned long) args
[1], args
[2]);
412 int PEVENT_PLUGIN_LOADER(struct pevent
*pevent
)
414 pevent_register_print_function(pevent
,
415 process_scsi_trace_parse_cdb
,
416 PEVENT_FUNC_ARG_STRING
,
417 "scsi_trace_parse_cdb",
421 PEVENT_FUNC_ARG_VOID
);
425 void PEVENT_PLUGIN_UNLOADER(struct pevent
*pevent
)
427 pevent_unregister_print_function(pevent
, process_scsi_trace_parse_cdb
,
428 "scsi_trace_parse_cdb");