1 /* SPDX-License-Identifier: GPL-2.0 */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM scsi
4 
5 #if !defined(_TRACE_SCSI_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define _TRACE_SCSI_H
7 
8 #include <scsi/scsi_cmnd.h>
9 #include <scsi/scsi_host.h>
10 #include <linux/tracepoint.h>
11 #include <linux/trace_seq.h>
12 
13 #define scsi_opcode_name(opcode)	{ opcode, #opcode }
14 #define show_opcode_name(val)					\
15 	__print_symbolic(val,					\
16 		scsi_opcode_name(TEST_UNIT_READY),		\
17 		scsi_opcode_name(REZERO_UNIT),			\
18 		scsi_opcode_name(REQUEST_SENSE),		\
19 		scsi_opcode_name(FORMAT_UNIT),			\
20 		scsi_opcode_name(READ_BLOCK_LIMITS),		\
21 		scsi_opcode_name(REASSIGN_BLOCKS),		\
22 		scsi_opcode_name(INITIALIZE_ELEMENT_STATUS),	\
23 		scsi_opcode_name(READ_6),			\
24 		scsi_opcode_name(WRITE_6),			\
25 		scsi_opcode_name(SEEK_6),			\
26 		scsi_opcode_name(READ_REVERSE),			\
27 		scsi_opcode_name(WRITE_FILEMARKS),		\
28 		scsi_opcode_name(SPACE),			\
29 		scsi_opcode_name(INQUIRY),			\
30 		scsi_opcode_name(RECOVER_BUFFERED_DATA),	\
31 		scsi_opcode_name(MODE_SELECT),			\
32 		scsi_opcode_name(RESERVE),			\
33 		scsi_opcode_name(RELEASE),			\
34 		scsi_opcode_name(COPY),				\
35 		scsi_opcode_name(ERASE),			\
36 		scsi_opcode_name(MODE_SENSE),			\
37 		scsi_opcode_name(START_STOP),			\
38 		scsi_opcode_name(RECEIVE_DIAGNOSTIC),		\
39 		scsi_opcode_name(SEND_DIAGNOSTIC),		\
40 		scsi_opcode_name(ALLOW_MEDIUM_REMOVAL),		\
41 		scsi_opcode_name(SET_WINDOW),			\
42 		scsi_opcode_name(READ_CAPACITY),		\
43 		scsi_opcode_name(READ_10),			\
44 		scsi_opcode_name(WRITE_10),			\
45 		scsi_opcode_name(SEEK_10),			\
46 		scsi_opcode_name(POSITION_TO_ELEMENT),		\
47 		scsi_opcode_name(WRITE_VERIFY),			\
48 		scsi_opcode_name(VERIFY),			\
49 		scsi_opcode_name(SEARCH_HIGH),			\
50 		scsi_opcode_name(SEARCH_EQUAL),			\
51 		scsi_opcode_name(SEARCH_LOW),			\
52 		scsi_opcode_name(SET_LIMITS),			\
53 		scsi_opcode_name(PRE_FETCH),			\
54 		scsi_opcode_name(READ_POSITION),		\
55 		scsi_opcode_name(SYNCHRONIZE_CACHE),		\
56 		scsi_opcode_name(LOCK_UNLOCK_CACHE),		\
57 		scsi_opcode_name(READ_DEFECT_DATA),		\
58 		scsi_opcode_name(MEDIUM_SCAN),			\
59 		scsi_opcode_name(COMPARE),			\
60 		scsi_opcode_name(COPY_VERIFY),			\
61 		scsi_opcode_name(WRITE_BUFFER),			\
62 		scsi_opcode_name(READ_BUFFER),			\
63 		scsi_opcode_name(UPDATE_BLOCK),			\
64 		scsi_opcode_name(READ_LONG),			\
65 		scsi_opcode_name(WRITE_LONG),			\
66 		scsi_opcode_name(CHANGE_DEFINITION),		\
67 		scsi_opcode_name(WRITE_SAME),			\
68 		scsi_opcode_name(UNMAP),			\
69 		scsi_opcode_name(READ_TOC),			\
70 		scsi_opcode_name(LOG_SELECT),			\
71 		scsi_opcode_name(LOG_SENSE),			\
72 		scsi_opcode_name(XDWRITEREAD_10),		\
73 		scsi_opcode_name(MODE_SELECT_10),		\
74 		scsi_opcode_name(RESERVE_10),			\
75 		scsi_opcode_name(RELEASE_10),			\
76 		scsi_opcode_name(MODE_SENSE_10),		\
77 		scsi_opcode_name(PERSISTENT_RESERVE_IN),	\
78 		scsi_opcode_name(PERSISTENT_RESERVE_OUT),	\
79 		scsi_opcode_name(VARIABLE_LENGTH_CMD),		\
80 		scsi_opcode_name(REPORT_LUNS),			\
81 		scsi_opcode_name(MAINTENANCE_IN),		\
82 		scsi_opcode_name(MAINTENANCE_OUT),		\
83 		scsi_opcode_name(MOVE_MEDIUM),			\
84 		scsi_opcode_name(EXCHANGE_MEDIUM),		\
85 		scsi_opcode_name(READ_12),			\
86 		scsi_opcode_name(WRITE_12),			\
87 		scsi_opcode_name(WRITE_VERIFY_12),		\
88 		scsi_opcode_name(SEARCH_HIGH_12),		\
89 		scsi_opcode_name(SEARCH_EQUAL_12),		\
90 		scsi_opcode_name(SEARCH_LOW_12),		\
91 		scsi_opcode_name(READ_ELEMENT_STATUS),		\
92 		scsi_opcode_name(SEND_VOLUME_TAG),		\
93 		scsi_opcode_name(WRITE_LONG_2),			\
94 		scsi_opcode_name(READ_16),			\
95 		scsi_opcode_name(WRITE_16),			\
96 		scsi_opcode_name(VERIFY_16),			\
97 		scsi_opcode_name(WRITE_SAME_16),		\
98 		scsi_opcode_name(ZBC_OUT),			\
99 		scsi_opcode_name(ZBC_IN),			\
100 		scsi_opcode_name(SERVICE_ACTION_IN_16),		\
101 		scsi_opcode_name(READ_32),			\
102 		scsi_opcode_name(WRITE_32),			\
103 		scsi_opcode_name(WRITE_SAME_32),		\
104 		scsi_opcode_name(ATA_16),			\
105 		scsi_opcode_name(ATA_12))
106 
107 #define scsi_hostbyte_name(result)	{ result, #result }
108 #define show_hostbyte_name(val)					\
109 	__print_symbolic(val,					\
110 		scsi_hostbyte_name(DID_OK),			\
111 		scsi_hostbyte_name(DID_NO_CONNECT),		\
112 		scsi_hostbyte_name(DID_BUS_BUSY),		\
113 		scsi_hostbyte_name(DID_TIME_OUT),		\
114 		scsi_hostbyte_name(DID_BAD_TARGET),		\
115 		scsi_hostbyte_name(DID_ABORT),			\
116 		scsi_hostbyte_name(DID_PARITY),			\
117 		scsi_hostbyte_name(DID_ERROR),			\
118 		scsi_hostbyte_name(DID_RESET),			\
119 		scsi_hostbyte_name(DID_BAD_INTR),		\
120 		scsi_hostbyte_name(DID_PASSTHROUGH),		\
121 		scsi_hostbyte_name(DID_SOFT_ERROR),		\
122 		scsi_hostbyte_name(DID_IMM_RETRY),		\
123 		scsi_hostbyte_name(DID_REQUEUE),		\
124 		scsi_hostbyte_name(DID_TRANSPORT_DISRUPTED),	\
125 		scsi_hostbyte_name(DID_TRANSPORT_FAILFAST))
126 
127 #define scsi_statusbyte_name(result)	{ result, #result }
128 #define show_statusbyte_name(val)				\
129 	__print_symbolic(val,					\
130 		scsi_statusbyte_name(SAM_STAT_GOOD),		\
131 		scsi_statusbyte_name(SAM_STAT_CHECK_CONDITION),	\
132 		scsi_statusbyte_name(SAM_STAT_CONDITION_MET),	\
133 		scsi_statusbyte_name(SAM_STAT_BUSY),		\
134 		scsi_statusbyte_name(SAM_STAT_INTERMEDIATE),	\
135 		scsi_statusbyte_name(SAM_STAT_INTERMEDIATE_CONDITION_MET), \
136 		scsi_statusbyte_name(SAM_STAT_RESERVATION_CONFLICT),	\
137 		scsi_statusbyte_name(SAM_STAT_COMMAND_TERMINATED),	\
138 		scsi_statusbyte_name(SAM_STAT_TASK_SET_FULL),	\
139 		scsi_statusbyte_name(SAM_STAT_ACA_ACTIVE),	\
140 		scsi_statusbyte_name(SAM_STAT_TASK_ABORTED))
141 
142 #define scsi_prot_op_name(result)	{ result, #result }
143 #define show_prot_op_name(val)					\
144 	__print_symbolic(val,					\
145 		scsi_prot_op_name(SCSI_PROT_NORMAL),		\
146 		scsi_prot_op_name(SCSI_PROT_READ_INSERT),	\
147 		scsi_prot_op_name(SCSI_PROT_WRITE_STRIP),	\
148 		scsi_prot_op_name(SCSI_PROT_READ_STRIP),	\
149 		scsi_prot_op_name(SCSI_PROT_WRITE_INSERT),	\
150 		scsi_prot_op_name(SCSI_PROT_READ_PASS),		\
151 		scsi_prot_op_name(SCSI_PROT_WRITE_PASS))
152 
153 const char *scsi_trace_parse_cdb(struct trace_seq*, unsigned char*, int);
154 #define __parse_cdb(cdb, len) scsi_trace_parse_cdb(p, cdb, len)
155 
156 TRACE_EVENT(scsi_dispatch_cmd_start,
157 
158 	TP_PROTO(struct scsi_cmnd *cmd),
159 
160 	TP_ARGS(cmd),
161 
162 	TP_STRUCT__entry(
163 		__field( unsigned int,	host_no	)
164 		__field( unsigned int,	channel	)
165 		__field( unsigned int,	id	)
166 		__field( unsigned int,	lun	)
167 		__field( unsigned int,	opcode	)
168 		__field( unsigned int,	cmd_len )
169 		__field( int,	driver_tag)
170 		__field( int,	scheduler_tag)
171 		__field( unsigned int,	data_sglen )
172 		__field( unsigned int,	prot_sglen )
173 		__field( unsigned char,	prot_op )
174 		__dynamic_array(unsigned char,	cmnd, cmd->cmd_len)
175 	),
176 
177 	TP_fast_assign(
178 		__entry->host_no	= cmd->device->host->host_no;
179 		__entry->channel	= cmd->device->channel;
180 		__entry->id		= cmd->device->id;
181 		__entry->lun		= cmd->device->lun;
182 		__entry->opcode		= cmd->cmnd[0];
183 		__entry->cmd_len	= cmd->cmd_len;
184 		__entry->driver_tag	= scsi_cmd_to_rq(cmd)->tag;
185 		__entry->scheduler_tag	= scsi_cmd_to_rq(cmd)->internal_tag;
186 		__entry->data_sglen	= scsi_sg_count(cmd);
187 		__entry->prot_sglen	= scsi_prot_sg_count(cmd);
188 		__entry->prot_op	= scsi_get_prot_op(cmd);
189 		memcpy(__get_dynamic_array(cmnd), cmd->cmnd, cmd->cmd_len);
190 	),
191 
192 	TP_printk("host_no=%u channel=%u id=%u lun=%u data_sgl=%u prot_sgl=%u" \
193 		  " prot_op=%s driver_tag=%d scheduler_tag=%d cmnd=(%s %s raw=%s)",
194 		  __entry->host_no, __entry->channel, __entry->id,
195 		  __entry->lun, __entry->data_sglen, __entry->prot_sglen,
196 		  show_prot_op_name(__entry->prot_op), __entry->driver_tag,
197 		  __entry->scheduler_tag, show_opcode_name(__entry->opcode),
198 		  __parse_cdb(__get_dynamic_array(cmnd), __entry->cmd_len),
199 		  __print_hex(__get_dynamic_array(cmnd), __entry->cmd_len))
200 );
201 
202 TRACE_EVENT(scsi_dispatch_cmd_error,
203 
204 	TP_PROTO(struct scsi_cmnd *cmd, int rtn),
205 
206 	TP_ARGS(cmd, rtn),
207 
208 	TP_STRUCT__entry(
209 		__field( unsigned int,	host_no	)
210 		__field( unsigned int,	channel	)
211 		__field( unsigned int,	id	)
212 		__field( unsigned int,	lun	)
213 		__field( int,		rtn	)
214 		__field( unsigned int,	opcode	)
215 		__field( unsigned int,	cmd_len )
216 		__field( int,	driver_tag)
217 		__field( int,	scheduler_tag)
218 		__field( unsigned int,	data_sglen )
219 		__field( unsigned int,	prot_sglen )
220 		__field( unsigned char,	prot_op )
221 		__dynamic_array(unsigned char,	cmnd, cmd->cmd_len)
222 	),
223 
224 	TP_fast_assign(
225 		__entry->host_no	= cmd->device->host->host_no;
226 		__entry->channel	= cmd->device->channel;
227 		__entry->id		= cmd->device->id;
228 		__entry->lun		= cmd->device->lun;
229 		__entry->rtn		= rtn;
230 		__entry->opcode		= cmd->cmnd[0];
231 		__entry->cmd_len	= cmd->cmd_len;
232 		__entry->driver_tag	= scsi_cmd_to_rq(cmd)->tag;
233 		__entry->scheduler_tag	= scsi_cmd_to_rq(cmd)->internal_tag;
234 		__entry->data_sglen	= scsi_sg_count(cmd);
235 		__entry->prot_sglen	= scsi_prot_sg_count(cmd);
236 		__entry->prot_op	= scsi_get_prot_op(cmd);
237 		memcpy(__get_dynamic_array(cmnd), cmd->cmnd, cmd->cmd_len);
238 	),
239 
240 	TP_printk("host_no=%u channel=%u id=%u lun=%u data_sgl=%u prot_sgl=%u" \
241 		  " prot_op=%s driver_tag=%d scheduler_tag=%d cmnd=(%s %s raw=%s)" \
242 		  " rtn=%d",
243 		  __entry->host_no, __entry->channel, __entry->id,
244 		  __entry->lun, __entry->data_sglen, __entry->prot_sglen,
245 		  show_prot_op_name(__entry->prot_op), __entry->driver_tag,
246 		  __entry->scheduler_tag, show_opcode_name(__entry->opcode),
247 		  __parse_cdb(__get_dynamic_array(cmnd), __entry->cmd_len),
248 		  __print_hex(__get_dynamic_array(cmnd), __entry->cmd_len),
249 		  __entry->rtn)
250 );
251 
252 DECLARE_EVENT_CLASS(scsi_cmd_done_timeout_template,
253 
254 	TP_PROTO(struct scsi_cmnd *cmd),
255 
256 	TP_ARGS(cmd),
257 
258 	TP_STRUCT__entry(
259 		__field( unsigned int,	host_no	)
260 		__field( unsigned int,	channel	)
261 		__field( unsigned int,	id	)
262 		__field( unsigned int,	lun	)
263 		__field( int,		result	)
264 		__field( unsigned int,	opcode	)
265 		__field( unsigned int,	cmd_len )
266 		__field( int,	driver_tag)
267 		__field( int,	scheduler_tag)
268 		__field( unsigned int,	data_sglen )
269 		__field( unsigned int,	prot_sglen )
270 		__field( unsigned char,	prot_op )
271 		__dynamic_array(unsigned char,	cmnd, cmd->cmd_len)
272 	),
273 
274 	TP_fast_assign(
275 		__entry->host_no	= cmd->device->host->host_no;
276 		__entry->channel	= cmd->device->channel;
277 		__entry->id		= cmd->device->id;
278 		__entry->lun		= cmd->device->lun;
279 		__entry->result		= cmd->result;
280 		__entry->opcode		= cmd->cmnd[0];
281 		__entry->cmd_len	= cmd->cmd_len;
282 		__entry->driver_tag	= scsi_cmd_to_rq(cmd)->tag;
283 		__entry->scheduler_tag	= scsi_cmd_to_rq(cmd)->internal_tag;
284 		__entry->data_sglen	= scsi_sg_count(cmd);
285 		__entry->prot_sglen	= scsi_prot_sg_count(cmd);
286 		__entry->prot_op	= scsi_get_prot_op(cmd);
287 		memcpy(__get_dynamic_array(cmnd), cmd->cmnd, cmd->cmd_len);
288 	),
289 
290 	TP_printk("host_no=%u channel=%u id=%u lun=%u data_sgl=%u prot_sgl=%u " \
291 		  "prot_op=%s driver_tag=%d scheduler_tag=%d cmnd=(%s %s raw=%s) " \
292 		  "result=(driver=%s host=%s message=%s status=%s)",
293 		  __entry->host_no, __entry->channel, __entry->id,
294 		  __entry->lun, __entry->data_sglen, __entry->prot_sglen,
295 		  show_prot_op_name(__entry->prot_op), __entry->driver_tag,
296 		  __entry->scheduler_tag, show_opcode_name(__entry->opcode),
297 		  __parse_cdb(__get_dynamic_array(cmnd), __entry->cmd_len),
298 		  __print_hex(__get_dynamic_array(cmnd), __entry->cmd_len),
299 		  "DRIVER_OK",
300 		  show_hostbyte_name(((__entry->result) >> 16) & 0xff),
301 		  "COMMAND_COMPLETE",
302 		  show_statusbyte_name(__entry->result & 0xff))
303 );
304 
305 DEFINE_EVENT(scsi_cmd_done_timeout_template, scsi_dispatch_cmd_done,
306 	     TP_PROTO(struct scsi_cmnd *cmd),
307 	     TP_ARGS(cmd));
308 
309 DEFINE_EVENT(scsi_cmd_done_timeout_template, scsi_dispatch_cmd_timeout,
310 	     TP_PROTO(struct scsi_cmnd *cmd),
311 	     TP_ARGS(cmd));
312 
313 TRACE_EVENT(scsi_eh_wakeup,
314 
315 	TP_PROTO(struct Scsi_Host *shost),
316 
317 	TP_ARGS(shost),
318 
319 	TP_STRUCT__entry(
320 		__field( unsigned int,	host_no	)
321 	),
322 
323 	TP_fast_assign(
324 		__entry->host_no	= shost->host_no;
325 	),
326 
327 	TP_printk("host_no=%u", __entry->host_no)
328 );
329 
330 #endif /*  _TRACE_SCSI_H */
331 
332 /* This part must be outside protection */
333 #include <trace/define_trace.h>
334