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_msgbyte_name(result) { result, #result } 128 #define show_msgbyte_name(val) \ 129 __print_symbolic(val, \ 130 scsi_msgbyte_name(COMMAND_COMPLETE), \ 131 scsi_msgbyte_name(EXTENDED_MESSAGE), \ 132 scsi_msgbyte_name(SAVE_POINTERS), \ 133 scsi_msgbyte_name(RESTORE_POINTERS), \ 134 scsi_msgbyte_name(DISCONNECT), \ 135 scsi_msgbyte_name(INITIATOR_ERROR), \ 136 scsi_msgbyte_name(ABORT_TASK_SET), \ 137 scsi_msgbyte_name(MESSAGE_REJECT), \ 138 scsi_msgbyte_name(NOP), \ 139 scsi_msgbyte_name(MSG_PARITY_ERROR), \ 140 scsi_msgbyte_name(LINKED_CMD_COMPLETE), \ 141 scsi_msgbyte_name(LINKED_FLG_CMD_COMPLETE), \ 142 scsi_msgbyte_name(TARGET_RESET), \ 143 scsi_msgbyte_name(ABORT_TASK), \ 144 scsi_msgbyte_name(CLEAR_TASK_SET), \ 145 scsi_msgbyte_name(INITIATE_RECOVERY), \ 146 scsi_msgbyte_name(RELEASE_RECOVERY), \ 147 scsi_msgbyte_name(CLEAR_ACA), \ 148 scsi_msgbyte_name(LOGICAL_UNIT_RESET), \ 149 scsi_msgbyte_name(SIMPLE_QUEUE_TAG), \ 150 scsi_msgbyte_name(HEAD_OF_QUEUE_TAG), \ 151 scsi_msgbyte_name(ORDERED_QUEUE_TAG), \ 152 scsi_msgbyte_name(IGNORE_WIDE_RESIDUE), \ 153 scsi_msgbyte_name(ACA), \ 154 scsi_msgbyte_name(QAS_REQUEST), \ 155 scsi_msgbyte_name(BUS_DEVICE_RESET), \ 156 scsi_msgbyte_name(ABORT)) 157 158 #define scsi_statusbyte_name(result) { result, #result } 159 #define show_statusbyte_name(val) \ 160 __print_symbolic(val, \ 161 scsi_statusbyte_name(SAM_STAT_GOOD), \ 162 scsi_statusbyte_name(SAM_STAT_CHECK_CONDITION), \ 163 scsi_statusbyte_name(SAM_STAT_CONDITION_MET), \ 164 scsi_statusbyte_name(SAM_STAT_BUSY), \ 165 scsi_statusbyte_name(SAM_STAT_INTERMEDIATE), \ 166 scsi_statusbyte_name(SAM_STAT_INTERMEDIATE_CONDITION_MET), \ 167 scsi_statusbyte_name(SAM_STAT_RESERVATION_CONFLICT), \ 168 scsi_statusbyte_name(SAM_STAT_COMMAND_TERMINATED), \ 169 scsi_statusbyte_name(SAM_STAT_TASK_SET_FULL), \ 170 scsi_statusbyte_name(SAM_STAT_ACA_ACTIVE), \ 171 scsi_statusbyte_name(SAM_STAT_TASK_ABORTED)) 172 173 #define scsi_prot_op_name(result) { result, #result } 174 #define show_prot_op_name(val) \ 175 __print_symbolic(val, \ 176 scsi_prot_op_name(SCSI_PROT_NORMAL), \ 177 scsi_prot_op_name(SCSI_PROT_READ_INSERT), \ 178 scsi_prot_op_name(SCSI_PROT_WRITE_STRIP), \ 179 scsi_prot_op_name(SCSI_PROT_READ_STRIP), \ 180 scsi_prot_op_name(SCSI_PROT_WRITE_INSERT), \ 181 scsi_prot_op_name(SCSI_PROT_READ_PASS), \ 182 scsi_prot_op_name(SCSI_PROT_WRITE_PASS)) 183 184 const char *scsi_trace_parse_cdb(struct trace_seq*, unsigned char*, int); 185 #define __parse_cdb(cdb, len) scsi_trace_parse_cdb(p, cdb, len) 186 187 TRACE_EVENT(scsi_dispatch_cmd_start, 188 189 TP_PROTO(struct scsi_cmnd *cmd), 190 191 TP_ARGS(cmd), 192 193 TP_STRUCT__entry( 194 __field( unsigned int, host_no ) 195 __field( unsigned int, channel ) 196 __field( unsigned int, id ) 197 __field( unsigned int, lun ) 198 __field( unsigned int, opcode ) 199 __field( unsigned int, cmd_len ) 200 __field( unsigned int, data_sglen ) 201 __field( unsigned int, prot_sglen ) 202 __field( unsigned char, prot_op ) 203 __dynamic_array(unsigned char, cmnd, cmd->cmd_len) 204 ), 205 206 TP_fast_assign( 207 __entry->host_no = cmd->device->host->host_no; 208 __entry->channel = cmd->device->channel; 209 __entry->id = cmd->device->id; 210 __entry->lun = cmd->device->lun; 211 __entry->opcode = cmd->cmnd[0]; 212 __entry->cmd_len = cmd->cmd_len; 213 __entry->data_sglen = scsi_sg_count(cmd); 214 __entry->prot_sglen = scsi_prot_sg_count(cmd); 215 __entry->prot_op = scsi_get_prot_op(cmd); 216 memcpy(__get_dynamic_array(cmnd), cmd->cmnd, cmd->cmd_len); 217 ), 218 219 TP_printk("host_no=%u channel=%u id=%u lun=%u data_sgl=%u prot_sgl=%u" \ 220 " prot_op=%s cmnd=(%s %s raw=%s)", 221 __entry->host_no, __entry->channel, __entry->id, 222 __entry->lun, __entry->data_sglen, __entry->prot_sglen, 223 show_prot_op_name(__entry->prot_op), 224 show_opcode_name(__entry->opcode), 225 __parse_cdb(__get_dynamic_array(cmnd), __entry->cmd_len), 226 __print_hex(__get_dynamic_array(cmnd), __entry->cmd_len)) 227 ); 228 229 TRACE_EVENT(scsi_dispatch_cmd_error, 230 231 TP_PROTO(struct scsi_cmnd *cmd, int rtn), 232 233 TP_ARGS(cmd, rtn), 234 235 TP_STRUCT__entry( 236 __field( unsigned int, host_no ) 237 __field( unsigned int, channel ) 238 __field( unsigned int, id ) 239 __field( unsigned int, lun ) 240 __field( int, rtn ) 241 __field( unsigned int, opcode ) 242 __field( unsigned int, cmd_len ) 243 __field( unsigned int, data_sglen ) 244 __field( unsigned int, prot_sglen ) 245 __field( unsigned char, prot_op ) 246 __dynamic_array(unsigned char, cmnd, cmd->cmd_len) 247 ), 248 249 TP_fast_assign( 250 __entry->host_no = cmd->device->host->host_no; 251 __entry->channel = cmd->device->channel; 252 __entry->id = cmd->device->id; 253 __entry->lun = cmd->device->lun; 254 __entry->rtn = rtn; 255 __entry->opcode = cmd->cmnd[0]; 256 __entry->cmd_len = cmd->cmd_len; 257 __entry->data_sglen = scsi_sg_count(cmd); 258 __entry->prot_sglen = scsi_prot_sg_count(cmd); 259 __entry->prot_op = scsi_get_prot_op(cmd); 260 memcpy(__get_dynamic_array(cmnd), cmd->cmnd, cmd->cmd_len); 261 ), 262 263 TP_printk("host_no=%u channel=%u id=%u lun=%u data_sgl=%u prot_sgl=%u" \ 264 " prot_op=%s cmnd=(%s %s raw=%s) rtn=%d", 265 __entry->host_no, __entry->channel, __entry->id, 266 __entry->lun, __entry->data_sglen, __entry->prot_sglen, 267 show_prot_op_name(__entry->prot_op), 268 show_opcode_name(__entry->opcode), 269 __parse_cdb(__get_dynamic_array(cmnd), __entry->cmd_len), 270 __print_hex(__get_dynamic_array(cmnd), __entry->cmd_len), 271 __entry->rtn) 272 ); 273 274 DECLARE_EVENT_CLASS(scsi_cmd_done_timeout_template, 275 276 TP_PROTO(struct scsi_cmnd *cmd), 277 278 TP_ARGS(cmd), 279 280 TP_STRUCT__entry( 281 __field( unsigned int, host_no ) 282 __field( unsigned int, channel ) 283 __field( unsigned int, id ) 284 __field( unsigned int, lun ) 285 __field( int, result ) 286 __field( unsigned int, opcode ) 287 __field( unsigned int, cmd_len ) 288 __field( unsigned int, data_sglen ) 289 __field( unsigned int, prot_sglen ) 290 __field( unsigned char, prot_op ) 291 __dynamic_array(unsigned char, cmnd, cmd->cmd_len) 292 ), 293 294 TP_fast_assign( 295 __entry->host_no = cmd->device->host->host_no; 296 __entry->channel = cmd->device->channel; 297 __entry->id = cmd->device->id; 298 __entry->lun = cmd->device->lun; 299 __entry->result = cmd->result; 300 __entry->opcode = cmd->cmnd[0]; 301 __entry->cmd_len = cmd->cmd_len; 302 __entry->data_sglen = scsi_sg_count(cmd); 303 __entry->prot_sglen = scsi_prot_sg_count(cmd); 304 __entry->prot_op = scsi_get_prot_op(cmd); 305 memcpy(__get_dynamic_array(cmnd), cmd->cmnd, cmd->cmd_len); 306 ), 307 308 TP_printk("host_no=%u channel=%u id=%u lun=%u data_sgl=%u " \ 309 "prot_sgl=%u prot_op=%s cmnd=(%s %s raw=%s) result=(driver=" \ 310 "%s host=%s message=%s status=%s)", 311 __entry->host_no, __entry->channel, __entry->id, 312 __entry->lun, __entry->data_sglen, __entry->prot_sglen, 313 show_prot_op_name(__entry->prot_op), 314 show_opcode_name(__entry->opcode), 315 __parse_cdb(__get_dynamic_array(cmnd), __entry->cmd_len), 316 __print_hex(__get_dynamic_array(cmnd), __entry->cmd_len), 317 "DRIVER_OK", 318 show_hostbyte_name(((__entry->result) >> 16) & 0xff), 319 show_msgbyte_name(((__entry->result) >> 8) & 0xff), 320 show_statusbyte_name(__entry->result & 0xff)) 321 ); 322 323 DEFINE_EVENT(scsi_cmd_done_timeout_template, scsi_dispatch_cmd_done, 324 TP_PROTO(struct scsi_cmnd *cmd), 325 TP_ARGS(cmd)); 326 327 DEFINE_EVENT(scsi_cmd_done_timeout_template, scsi_dispatch_cmd_timeout, 328 TP_PROTO(struct scsi_cmnd *cmd), 329 TP_ARGS(cmd)); 330 331 TRACE_EVENT(scsi_eh_wakeup, 332 333 TP_PROTO(struct Scsi_Host *shost), 334 335 TP_ARGS(shost), 336 337 TP_STRUCT__entry( 338 __field( unsigned int, host_no ) 339 ), 340 341 TP_fast_assign( 342 __entry->host_no = shost->host_no; 343 ), 344 345 TP_printk("host_no=%u", __entry->host_no) 346 ); 347 348 #endif /* _TRACE_SCSI_H */ 349 350 /* This part must be outside protection */ 351 #include <trace/define_trace.h> 352