target.h 7.5 KB

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