1 // SPDX-License-Identifier: GPL-2.0 2 #include <linux/bitops.h> 3 #include <linux/seq_file.h> 4 #include <scsi/scsi_cmnd.h> 5 #include <scsi/scsi_dbg.h> 6 #include "scsi_debugfs.h" 7 8 #define SCSI_CMD_FLAG_NAME(name)[const_ilog2(SCMD_##name)] = #name 9 static const char *const scsi_cmd_flags[] = { 10 SCSI_CMD_FLAG_NAME(TAGGED), 11 SCSI_CMD_FLAG_NAME(INITIALIZED), 12 SCSI_CMD_FLAG_NAME(LAST), 13 }; 14 #undef SCSI_CMD_FLAG_NAME 15 16 static int scsi_flags_show(struct seq_file *m, const unsigned long flags, 17 const char *const *flag_name, int flag_name_count) 18 { 19 bool sep = false; 20 int i; 21 22 for_each_set_bit(i, &flags, BITS_PER_LONG) { 23 if (sep) 24 seq_puts(m, "|"); 25 sep = true; 26 if (i < flag_name_count && flag_name[i]) 27 seq_puts(m, flag_name[i]); 28 else 29 seq_printf(m, "%d", i); 30 } 31 return 0; 32 } 33 34 void scsi_show_rq(struct seq_file *m, struct request *rq) 35 { 36 struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); 37 int alloc_ms = jiffies_to_msecs(jiffies - cmd->jiffies_at_alloc); 38 int timeout_ms = jiffies_to_msecs(rq->timeout); 39 char buf[80] = "(?)"; 40 41 __scsi_format_command(buf, sizeof(buf), cmd->cmnd, cmd->cmd_len); 42 seq_printf(m, ", .cmd=%s, .retries=%d, .result = %#x, .flags=", buf, 43 cmd->retries, cmd->result); 44 scsi_flags_show(m, cmd->flags, scsi_cmd_flags, 45 ARRAY_SIZE(scsi_cmd_flags)); 46 seq_printf(m, ", .timeout=%d.%03d, allocated %d.%03d s ago", 47 timeout_ms / 1000, timeout_ms % 1000, 48 alloc_ms / 1000, alloc_ms % 1000); 49 } 50