2 * Copyright (C) 2010 FUJITSU LIMITED
3 * Copyright (C) 2010 Tomohiro Kusumi <kusumi.tomohiro@jp.fujitsu.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #include <linux/kernel.h>
19 #include <linux/trace_seq.h>
20 #include <trace/events/scsi.h>
22 #define SERVICE_ACTION16(cdb) (cdb[1] & 0x1f)
23 #define SERVICE_ACTION32(cdb) ((cdb[8] << 8) | cdb[9])
26 scsi_trace_misc(struct trace_seq
*, unsigned char *, int);
29 scsi_trace_rw6(struct trace_seq
*p
, unsigned char *cdb
, int len
)
31 const char *ret
= p
->buffer
+ p
->len
;
32 sector_t lba
= 0, txlen
= 0;
34 lba
|= ((cdb
[1] & 0x1F) << 16);
39 trace_seq_printf(p
, "lba=%llu txlen=%llu",
40 (unsigned long long)lba
, (unsigned long long)txlen
);
47 scsi_trace_rw10(struct trace_seq
*p
, unsigned char *cdb
, int len
)
49 const char *ret
= p
->buffer
+ p
->len
;
50 sector_t lba
= 0, txlen
= 0;
52 lba
|= (cdb
[2] << 24);
53 lba
|= (cdb
[3] << 16);
56 txlen
|= (cdb
[7] << 8);
59 trace_seq_printf(p
, "lba=%llu txlen=%llu protect=%u",
60 (unsigned long long)lba
, (unsigned long long)txlen
,
68 scsi_trace_rw12(struct trace_seq
*p
, unsigned char *cdb
, int len
)
70 const char *ret
= p
->buffer
+ p
->len
;
71 sector_t lba
= 0, txlen
= 0;
73 lba
|= (cdb
[2] << 24);
74 lba
|= (cdb
[3] << 16);
77 txlen
|= (cdb
[6] << 24);
78 txlen
|= (cdb
[7] << 16);
79 txlen
|= (cdb
[8] << 8);
82 trace_seq_printf(p
, "lba=%llu txlen=%llu protect=%u",
83 (unsigned long long)lba
, (unsigned long long)txlen
,
91 scsi_trace_rw16(struct trace_seq
*p
, unsigned char *cdb
, int len
)
93 const char *ret
= p
->buffer
+ p
->len
;
94 sector_t lba
= 0, txlen
= 0;
96 lba
|= ((u64
)cdb
[2] << 56);
97 lba
|= ((u64
)cdb
[3] << 48);
98 lba
|= ((u64
)cdb
[4] << 40);
99 lba
|= ((u64
)cdb
[5] << 32);
100 lba
|= (cdb
[6] << 24);
101 lba
|= (cdb
[7] << 16);
102 lba
|= (cdb
[8] << 8);
104 txlen
|= (cdb
[10] << 24);
105 txlen
|= (cdb
[11] << 16);
106 txlen
|= (cdb
[12] << 8);
109 trace_seq_printf(p
, "lba=%llu txlen=%llu protect=%u",
110 (unsigned long long)lba
, (unsigned long long)txlen
,
113 if (cdb
[0] == WRITE_SAME_16
)
114 trace_seq_printf(p
, " unmap=%u", cdb
[1] >> 3 & 1);
116 trace_seq_putc(p
, 0);
122 scsi_trace_rw32(struct trace_seq
*p
, unsigned char *cdb
, int len
)
124 const char *ret
= p
->buffer
+ p
->len
, *cmd
;
125 sector_t lba
= 0, txlen
= 0;
128 switch (SERVICE_ACTION32(cdb
)) {
142 trace_seq_printf(p
, "UNKNOWN");
146 lba
|= ((u64
)cdb
[12] << 56);
147 lba
|= ((u64
)cdb
[13] << 48);
148 lba
|= ((u64
)cdb
[14] << 40);
149 lba
|= ((u64
)cdb
[15] << 32);
150 lba
|= (cdb
[16] << 24);
151 lba
|= (cdb
[17] << 16);
152 lba
|= (cdb
[18] << 8);
154 ei_lbrt
|= (cdb
[20] << 24);
155 ei_lbrt
|= (cdb
[21] << 16);
156 ei_lbrt
|= (cdb
[22] << 8);
158 txlen
|= (cdb
[28] << 24);
159 txlen
|= (cdb
[29] << 16);
160 txlen
|= (cdb
[30] << 8);
163 trace_seq_printf(p
, "%s_32 lba=%llu txlen=%llu protect=%u ei_lbrt=%u",
164 cmd
, (unsigned long long)lba
,
165 (unsigned long long)txlen
, cdb
[10] >> 5, ei_lbrt
);
167 if (SERVICE_ACTION32(cdb
) == WRITE_SAME_32
)
168 trace_seq_printf(p
, " unmap=%u", cdb
[10] >> 3 & 1);
171 trace_seq_putc(p
, 0);
177 scsi_trace_unmap(struct trace_seq
*p
, unsigned char *cdb
, int len
)
179 const char *ret
= p
->buffer
+ p
->len
;
180 unsigned int regions
= cdb
[7] << 8 | cdb
[8];
182 trace_seq_printf(p
, "regions=%u", (regions
- 8) / 16);
183 trace_seq_putc(p
, 0);
189 scsi_trace_service_action_in(struct trace_seq
*p
, unsigned char *cdb
, int len
)
191 const char *ret
= p
->buffer
+ p
->len
, *cmd
;
195 switch (SERVICE_ACTION16(cdb
)) {
196 case SAI_READ_CAPACITY_16
:
197 cmd
= "READ_CAPACITY_16";
199 case SAI_GET_LBA_STATUS
:
200 cmd
= "GET_LBA_STATUS";
203 trace_seq_printf(p
, "UNKNOWN");
207 lba
|= ((u64
)cdb
[2] << 56);
208 lba
|= ((u64
)cdb
[3] << 48);
209 lba
|= ((u64
)cdb
[4] << 40);
210 lba
|= ((u64
)cdb
[5] << 32);
211 lba
|= (cdb
[6] << 24);
212 lba
|= (cdb
[7] << 16);
213 lba
|= (cdb
[8] << 8);
215 alloc_len
|= (cdb
[10] << 24);
216 alloc_len
|= (cdb
[11] << 16);
217 alloc_len
|= (cdb
[12] << 8);
218 alloc_len
|= cdb
[13];
220 trace_seq_printf(p
, "%s lba=%llu alloc_len=%u", cmd
,
221 (unsigned long long)lba
, alloc_len
);
224 trace_seq_putc(p
, 0);
230 scsi_trace_varlen(struct trace_seq
*p
, unsigned char *cdb
, int len
)
232 switch (SERVICE_ACTION32(cdb
)) {
237 return scsi_trace_rw32(p
, cdb
, len
);
239 return scsi_trace_misc(p
, cdb
, len
);
244 scsi_trace_misc(struct trace_seq
*p
, unsigned char *cdb
, int len
)
246 const char *ret
= p
->buffer
+ p
->len
;
248 trace_seq_printf(p
, "-");
249 trace_seq_putc(p
, 0);
255 scsi_trace_parse_cdb(struct trace_seq
*p
, unsigned char *cdb
, int len
)
260 return scsi_trace_rw6(p
, cdb
, len
);
265 return scsi_trace_rw10(p
, cdb
, len
);
269 return scsi_trace_rw12(p
, cdb
, len
);
274 return scsi_trace_rw16(p
, cdb
, len
);
276 return scsi_trace_unmap(p
, cdb
, len
);
277 case SERVICE_ACTION_IN
:
278 return scsi_trace_service_action_in(p
, cdb
, len
);
279 case VARIABLE_LENGTH_CMD
:
280 return scsi_trace_varlen(p
, cdb
, len
);
282 return scsi_trace_misc(p
, cdb
, len
);