1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/bitops.h>
3 #include <linux/cleanup.h>
4 #include <linux/seq_file.h>
5 #include <scsi/scsi_cmnd.h>
6 #include <scsi/scsi_dbg.h>
7 #include <scsi/scsi_host.h>
8 #include "scsi_debugfs.h"
10 #define SCSI_CMD_FLAG_NAME(name)[const_ilog2(SCMD_##name)] = #name
11 static const char *const scsi_cmd_flags
[] = {
12 SCSI_CMD_FLAG_NAME(TAGGED
),
13 SCSI_CMD_FLAG_NAME(INITIALIZED
),
14 SCSI_CMD_FLAG_NAME(LAST
),
16 #undef SCSI_CMD_FLAG_NAME
18 static int scsi_flags_show(struct seq_file
*m
, const unsigned long flags
,
19 const char *const *flag_name
, int flag_name_count
)
24 for_each_set_bit(i
, &flags
, BITS_PER_LONG
) {
28 if (i
< flag_name_count
&& flag_name
[i
])
29 seq_puts(m
, flag_name
[i
]);
31 seq_printf(m
, "%d", i
);
36 static const char *scsi_cmd_list_info(struct scsi_cmnd
*cmd
)
38 struct Scsi_Host
*shost
= cmd
->device
->host
;
39 struct scsi_cmnd
*cmd2
;
41 guard(spinlock_irq
)(shost
->host_lock
);
43 list_for_each_entry(cmd2
, &shost
->eh_abort_list
, eh_entry
)
45 return "on eh_abort_list";
47 list_for_each_entry(cmd2
, &shost
->eh_cmd_q
, eh_entry
)
54 void scsi_show_rq(struct seq_file
*m
, struct request
*rq
)
56 struct scsi_cmnd
*cmd
= blk_mq_rq_to_pdu(rq
);
57 int alloc_ms
= jiffies_to_msecs(jiffies
- cmd
->jiffies_at_alloc
);
58 int timeout_ms
= jiffies_to_msecs(rq
->timeout
);
61 if (cmd
->flags
& SCMD_INITIALIZED
) {
62 const char *list_info
= scsi_cmd_list_info(cmd
);
64 __scsi_format_command(buf
, sizeof(buf
), cmd
->cmnd
, cmd
->cmd_len
);
65 seq_printf(m
, ", .cmd=%s, .retries=%d, .allowed=%d, .result = %#x%s%s",
66 buf
, cmd
->retries
, cmd
->allowed
, cmd
->result
,
67 list_info
? ", " : "", list_info
? : "");
68 seq_printf(m
, ", .timeout=%d.%03d, allocated %d.%03d s ago",
69 timeout_ms
/ 1000, timeout_ms
% 1000,
70 alloc_ms
/ 1000, alloc_ms
% 1000);
72 seq_printf(m
, ", .flags=");
73 scsi_flags_show(m
, cmd
->flags
, scsi_cmd_flags
,
74 ARRAY_SIZE(scsi_cmd_flags
));