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