blob: d9a18124cfc9d4604930d431a9f2cca118f9ffc1 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001// SPDX-License-Identifier: GPL-2.0
David Brazdil0f672f62019-12-10 10:32:29 +00002#include <linux/bitops.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00003#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
9static const char *const scsi_cmd_flags[] = {
10 SCSI_CMD_FLAG_NAME(TAGGED),
11 SCSI_CMD_FLAG_NAME(UNCHECKED_ISA_DMA),
12 SCSI_CMD_FLAG_NAME(INITIALIZED),
Olivier Deprez157378f2022-04-04 15:47:50 +020013 SCSI_CMD_FLAG_NAME(LAST),
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000014};
15#undef SCSI_CMD_FLAG_NAME
16
17static int scsi_flags_show(struct seq_file *m, const unsigned long flags,
18 const char *const *flag_name, int flag_name_count)
19{
20 bool sep = false;
21 int i;
22
David Brazdil0f672f62019-12-10 10:32:29 +000023 for_each_set_bit(i, &flags, BITS_PER_LONG) {
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000024 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}