Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Andy Shevchenko | 1623835 | 2019-07-25 23:07:51 +0300 | [diff] [blame] | 2 | #include <linux/bitops.h> |
Bart Van Assche | 0eebd00 | 2017-04-26 13:47:57 -0700 | [diff] [blame] | 3 | #include <linux/seq_file.h> |
| 4 | #include <scsi/scsi_cmnd.h> |
| 5 | #include <scsi/scsi_dbg.h> |
| 6 | #include "scsi_debugfs.h" |
| 7 | |
Martin Wilck | 659c1c1 | 2018-04-18 01:35:07 +0200 | [diff] [blame] | 8 | #define SCSI_CMD_FLAG_NAME(name)[const_ilog2(SCMD_##name)] = #name |
Bart Van Assche | 2ee4e9c | 2017-12-05 16:57:53 -0800 | [diff] [blame] | 9 | static const char *const scsi_cmd_flags[] = { |
| 10 | SCSI_CMD_FLAG_NAME(TAGGED), |
Bart Van Assche | 2ee4e9c | 2017-12-05 16:57:53 -0800 | [diff] [blame] | 11 | SCSI_CMD_FLAG_NAME(INITIALIZED), |
Bart Van Assche | 3369046 | 2021-11-29 11:46:00 -0800 | [diff] [blame] | 12 | SCSI_CMD_FLAG_NAME(LAST), |
Bart Van Assche | 2ee4e9c | 2017-12-05 16:57:53 -0800 | [diff] [blame] | 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 | |
Andy Shevchenko | 1623835 | 2019-07-25 23:07:51 +0300 | [diff] [blame] | 22 | for_each_set_bit(i, &flags, BITS_PER_LONG) { |
Bart Van Assche | 2ee4e9c | 2017-12-05 16:57:53 -0800 | [diff] [blame] | 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 | |
Bart Van Assche | 0eebd00 | 2017-04-26 13:47:57 -0700 | [diff] [blame] | 34 | void scsi_show_rq(struct seq_file *m, struct request *rq) |
| 35 | { |
| 36 | struct scsi_cmnd *cmd = container_of(scsi_req(rq), typeof(*cmd), req); |
Bart Van Assche | 2ee4e9c | 2017-12-05 16:57:53 -0800 | [diff] [blame] | 37 | int alloc_ms = jiffies_to_msecs(jiffies - cmd->jiffies_at_alloc); |
| 38 | int timeout_ms = jiffies_to_msecs(rq->timeout); |
Bart Van Assche | 14e3062 | 2017-12-05 16:57:51 -0800 | [diff] [blame] | 39 | const u8 *const cdb = READ_ONCE(cmd->cmnd); |
| 40 | char buf[80] = "(?)"; |
Bart Van Assche | 0eebd00 | 2017-04-26 13:47:57 -0700 | [diff] [blame] | 41 | |
Bart Van Assche | 14e3062 | 2017-12-05 16:57:51 -0800 | [diff] [blame] | 42 | if (cdb) |
| 43 | __scsi_format_command(buf, sizeof(buf), cdb, cmd->cmd_len); |
Bart Van Assche | 2ee4e9c | 2017-12-05 16:57:53 -0800 | [diff] [blame] | 44 | seq_printf(m, ", .cmd=%s, .retries=%d, .result = %#x, .flags=", buf, |
| 45 | cmd->retries, cmd->result); |
| 46 | scsi_flags_show(m, cmd->flags, scsi_cmd_flags, |
| 47 | ARRAY_SIZE(scsi_cmd_flags)); |
| 48 | seq_printf(m, ", .timeout=%d.%03d, allocated %d.%03d s ago", |
| 49 | timeout_ms / 1000, timeout_ms % 1000, |
| 50 | alloc_ms / 1000, alloc_ms % 1000); |
Bart Van Assche | 0eebd00 | 2017-04-26 13:47:57 -0700 | [diff] [blame] | 51 | } |