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