xref: /linux/include/trace/events/target.h (revision b85d45947951d23cb22d90caecf4c1eb81342c96)
1 #undef TRACE_SYSTEM
2 #define TRACE_SYSTEM target
3 
4 #if !defined(_TRACE_TARGET_H) || defined(TRACE_HEADER_MULTI_READ)
5 #define _TRACE_TARGET_H
6 
7 #include <linux/tracepoint.h>
8 #include <linux/trace_seq.h>
9 #include <scsi/scsi_proto.h>
10 #include <scsi/scsi_tcq.h>
11 #include <target/target_core_base.h>
12 
13 /* cribbed verbatim from <trace/event/scsi.h> */
14 #define scsi_opcode_name(opcode)	{ opcode, #opcode }
15 #define show_opcode_name(val)					\
16 	__print_symbolic(val,					\
17 		scsi_opcode_name(TEST_UNIT_READY),		\
18 		scsi_opcode_name(REZERO_UNIT),			\
19 		scsi_opcode_name(REQUEST_SENSE),		\
20 		scsi_opcode_name(FORMAT_UNIT),			\
21 		scsi_opcode_name(READ_BLOCK_LIMITS),		\
22 		scsi_opcode_name(REASSIGN_BLOCKS),		\
23 		scsi_opcode_name(INITIALIZE_ELEMENT_STATUS),	\
24 		scsi_opcode_name(READ_6),			\
25 		scsi_opcode_name(WRITE_6),			\
26 		scsi_opcode_name(SEEK_6),			\
27 		scsi_opcode_name(READ_REVERSE),			\
28 		scsi_opcode_name(WRITE_FILEMARKS),		\
29 		scsi_opcode_name(SPACE),			\
30 		scsi_opcode_name(INQUIRY),			\
31 		scsi_opcode_name(RECOVER_BUFFERED_DATA),	\
32 		scsi_opcode_name(MODE_SELECT),			\
33 		scsi_opcode_name(RESERVE),			\
34 		scsi_opcode_name(RELEASE),			\
35 		scsi_opcode_name(COPY),				\
36 		scsi_opcode_name(ERASE),			\
37 		scsi_opcode_name(MODE_SENSE),			\
38 		scsi_opcode_name(START_STOP),			\
39 		scsi_opcode_name(RECEIVE_DIAGNOSTIC),		\
40 		scsi_opcode_name(SEND_DIAGNOSTIC),		\
41 		scsi_opcode_name(ALLOW_MEDIUM_REMOVAL),		\
42 		scsi_opcode_name(SET_WINDOW),			\
43 		scsi_opcode_name(READ_CAPACITY),		\
44 		scsi_opcode_name(READ_10),			\
45 		scsi_opcode_name(WRITE_10),			\
46 		scsi_opcode_name(SEEK_10),			\
47 		scsi_opcode_name(POSITION_TO_ELEMENT),		\
48 		scsi_opcode_name(WRITE_VERIFY),			\
49 		scsi_opcode_name(VERIFY),			\
50 		scsi_opcode_name(SEARCH_HIGH),			\
51 		scsi_opcode_name(SEARCH_EQUAL),			\
52 		scsi_opcode_name(SEARCH_LOW),			\
53 		scsi_opcode_name(SET_LIMITS),			\
54 		scsi_opcode_name(PRE_FETCH),			\
55 		scsi_opcode_name(READ_POSITION),		\
56 		scsi_opcode_name(SYNCHRONIZE_CACHE),		\
57 		scsi_opcode_name(LOCK_UNLOCK_CACHE),		\
58 		scsi_opcode_name(READ_DEFECT_DATA),		\
59 		scsi_opcode_name(MEDIUM_SCAN),			\
60 		scsi_opcode_name(COMPARE),			\
61 		scsi_opcode_name(COPY_VERIFY),			\
62 		scsi_opcode_name(WRITE_BUFFER),			\
63 		scsi_opcode_name(READ_BUFFER),			\
64 		scsi_opcode_name(UPDATE_BLOCK),			\
65 		scsi_opcode_name(READ_LONG),			\
66 		scsi_opcode_name(WRITE_LONG),			\
67 		scsi_opcode_name(CHANGE_DEFINITION),		\
68 		scsi_opcode_name(WRITE_SAME),			\
69 		scsi_opcode_name(UNMAP),			\
70 		scsi_opcode_name(READ_TOC),			\
71 		scsi_opcode_name(LOG_SELECT),			\
72 		scsi_opcode_name(LOG_SENSE),			\
73 		scsi_opcode_name(XDWRITEREAD_10),		\
74 		scsi_opcode_name(MODE_SELECT_10),		\
75 		scsi_opcode_name(RESERVE_10),			\
76 		scsi_opcode_name(RELEASE_10),			\
77 		scsi_opcode_name(MODE_SENSE_10),		\
78 		scsi_opcode_name(PERSISTENT_RESERVE_IN),	\
79 		scsi_opcode_name(PERSISTENT_RESERVE_OUT),	\
80 		scsi_opcode_name(VARIABLE_LENGTH_CMD),		\
81 		scsi_opcode_name(REPORT_LUNS),			\
82 		scsi_opcode_name(MAINTENANCE_IN),		\
83 		scsi_opcode_name(MAINTENANCE_OUT),		\
84 		scsi_opcode_name(MOVE_MEDIUM),			\
85 		scsi_opcode_name(EXCHANGE_MEDIUM),		\
86 		scsi_opcode_name(READ_12),			\
87 		scsi_opcode_name(WRITE_12),			\
88 		scsi_opcode_name(WRITE_VERIFY_12),		\
89 		scsi_opcode_name(SEARCH_HIGH_12),		\
90 		scsi_opcode_name(SEARCH_EQUAL_12),		\
91 		scsi_opcode_name(SEARCH_LOW_12),		\
92 		scsi_opcode_name(READ_ELEMENT_STATUS),		\
93 		scsi_opcode_name(SEND_VOLUME_TAG),		\
94 		scsi_opcode_name(WRITE_LONG_2),			\
95 		scsi_opcode_name(READ_16),			\
96 		scsi_opcode_name(WRITE_16),			\
97 		scsi_opcode_name(VERIFY_16),			\
98 		scsi_opcode_name(WRITE_SAME_16),		\
99 		scsi_opcode_name(SERVICE_ACTION_IN_16),		\
100 		scsi_opcode_name(SAI_READ_CAPACITY_16),		\
101 		scsi_opcode_name(SAI_GET_LBA_STATUS),		\
102 		scsi_opcode_name(MI_REPORT_TARGET_PGS),		\
103 		scsi_opcode_name(MO_SET_TARGET_PGS),		\
104 		scsi_opcode_name(READ_32),			\
105 		scsi_opcode_name(WRITE_32),			\
106 		scsi_opcode_name(WRITE_SAME_32),		\
107 		scsi_opcode_name(ATA_16),			\
108 		scsi_opcode_name(ATA_12))
109 
110 #define show_task_attribute_name(val)				\
111 	__print_symbolic(val,					\
112 		{ TCM_SIMPLE_TAG,	"SIMPLE"	},	\
113 		{ TCM_HEAD_TAG,		"HEAD"		},	\
114 		{ TCM_ORDERED_TAG,	"ORDERED"	},	\
115 		{ TCM_ACA_TAG,		"ACA"		} )
116 
117 #define show_scsi_status_name(val)				\
118 	__print_symbolic(val,					\
119 		{ SAM_STAT_GOOD,	"GOOD" },		\
120 		{ SAM_STAT_CHECK_CONDITION, "CHECK CONDITION" }, \
121 		{ SAM_STAT_CONDITION_MET, "CONDITION MET" },	\
122 		{ SAM_STAT_BUSY,	"BUSY" },		\
123 		{ SAM_STAT_INTERMEDIATE, "INTERMEDIATE" },	\
124 		{ SAM_STAT_INTERMEDIATE_CONDITION_MET, "INTERMEDIATE CONDITION MET" }, \
125 		{ SAM_STAT_RESERVATION_CONFLICT, "RESERVATION CONFLICT" }, \
126 		{ SAM_STAT_COMMAND_TERMINATED, "COMMAND TERMINATED" }, \
127 		{ SAM_STAT_TASK_SET_FULL, "TASK SET FULL" },	\
128 		{ SAM_STAT_ACA_ACTIVE, "ACA ACTIVE" },		\
129 		{ SAM_STAT_TASK_ABORTED, "TASK ABORTED" } )
130 
131 TRACE_EVENT(target_sequencer_start,
132 
133 	TP_PROTO(struct se_cmd *cmd),
134 
135 	TP_ARGS(cmd),
136 
137 	TP_STRUCT__entry(
138 		__field( unsigned int,	unpacked_lun	)
139 		__field( unsigned int,	opcode		)
140 		__field( unsigned int,	data_length	)
141 		__field( unsigned int,	task_attribute  )
142 		__array( unsigned char,	cdb, TCM_MAX_COMMAND_SIZE	)
143 		__string( initiator,	cmd->se_sess->se_node_acl->initiatorname	)
144 	),
145 
146 	TP_fast_assign(
147 		__entry->unpacked_lun	= cmd->orig_fe_lun;
148 		__entry->opcode		= cmd->t_task_cdb[0];
149 		__entry->data_length	= cmd->data_length;
150 		__entry->task_attribute	= cmd->sam_task_attr;
151 		memcpy(__entry->cdb, cmd->t_task_cdb, TCM_MAX_COMMAND_SIZE);
152 		__assign_str(initiator, cmd->se_sess->se_node_acl->initiatorname);
153 	),
154 
155 	TP_printk("%s -> LUN %03u %s data_length %6u  CDB %s  (TA:%s C:%02x)",
156 		  __get_str(initiator), __entry->unpacked_lun,
157 		  show_opcode_name(__entry->opcode),
158 		  __entry->data_length, __print_hex(__entry->cdb, 16),
159 		  show_task_attribute_name(__entry->task_attribute),
160 		  scsi_command_size(__entry->cdb) <= 16 ?
161 			__entry->cdb[scsi_command_size(__entry->cdb) - 1] :
162 			__entry->cdb[1]
163 	)
164 );
165 
166 TRACE_EVENT(target_cmd_complete,
167 
168 	TP_PROTO(struct se_cmd *cmd),
169 
170 	TP_ARGS(cmd),
171 
172 	TP_STRUCT__entry(
173 		__field( unsigned int,	unpacked_lun	)
174 		__field( unsigned int,	opcode		)
175 		__field( unsigned int,	data_length	)
176 		__field( unsigned int,	task_attribute  )
177 		__field( unsigned char,	scsi_status	)
178 		__field( unsigned char,	sense_length	)
179 		__array( unsigned char,	cdb, TCM_MAX_COMMAND_SIZE	)
180 		__array( unsigned char,	sense_data, 18	)
181 		__string(initiator,	cmd->se_sess->se_node_acl->initiatorname)
182 	),
183 
184 	TP_fast_assign(
185 		__entry->unpacked_lun	= cmd->orig_fe_lun;
186 		__entry->opcode		= cmd->t_task_cdb[0];
187 		__entry->data_length	= cmd->data_length;
188 		__entry->task_attribute	= cmd->sam_task_attr;
189 		__entry->scsi_status	= cmd->scsi_status;
190 		__entry->sense_length	= cmd->scsi_status == SAM_STAT_CHECK_CONDITION ?
191 			min(18, ((u8 *) cmd->sense_buffer)[SPC_ADD_SENSE_LEN_OFFSET] + 8) : 0;
192 		memcpy(__entry->cdb, cmd->t_task_cdb, TCM_MAX_COMMAND_SIZE);
193 		memcpy(__entry->sense_data, cmd->sense_buffer, __entry->sense_length);
194 		__assign_str(initiator, cmd->se_sess->se_node_acl->initiatorname);
195 	),
196 
197 	TP_printk("%s <- LUN %03u status %s (sense len %d%s%s)  %s data_length %6u  CDB %s  (TA:%s C:%02x)",
198 		  __get_str(initiator), __entry->unpacked_lun,
199 		  show_scsi_status_name(__entry->scsi_status),
200 		  __entry->sense_length, __entry->sense_length ? " / " : "",
201 		  __print_hex(__entry->sense_data, __entry->sense_length),
202 		  show_opcode_name(__entry->opcode),
203 		  __entry->data_length, __print_hex(__entry->cdb, 16),
204 		  show_task_attribute_name(__entry->task_attribute),
205 		  scsi_command_size(__entry->cdb) <= 16 ?
206 			__entry->cdb[scsi_command_size(__entry->cdb) - 1] :
207 			__entry->cdb[1]
208 	)
209 );
210 
211 #endif /*  _TRACE_TARGET_H */
212 
213 /* This part must be outside protection */
214 #include <trace/define_trace.h>
215