blob: 244d7c177e5a7e32d42e262c8e559ef6a94b74d3 [file] [log] [blame]
Christoph Hellwigbc50ad72019-02-18 09:36:29 +01001/* SPDX-License-Identifier: GPL-2.0 */
Johannes Thumshirn3d030e42018-01-26 11:21:37 +01002/*
3 * NVM Express device driver tracepoints
4 * Copyright (c) 2018 Johannes Thumshirn, SUSE Linux GmbH
Johannes Thumshirn3d030e42018-01-26 11:21:37 +01005 */
6
7#undef TRACE_SYSTEM
8#define TRACE_SYSTEM nvme
9
10#if !defined(_TRACE_NVME_H) || defined(TRACE_HEADER_MULTI_READ)
11#define _TRACE_NVME_H
12
13#include <linux/nvme.h>
14#include <linux/tracepoint.h>
15#include <linux/trace_seq.h>
16
17#include "nvme.h"
18
19#define nvme_admin_opcode_name(opcode) { opcode, #opcode }
20#define show_admin_opcode_name(val) \
21 __print_symbolic(val, \
22 nvme_admin_opcode_name(nvme_admin_delete_sq), \
23 nvme_admin_opcode_name(nvme_admin_create_sq), \
24 nvme_admin_opcode_name(nvme_admin_get_log_page), \
25 nvme_admin_opcode_name(nvme_admin_delete_cq), \
26 nvme_admin_opcode_name(nvme_admin_create_cq), \
27 nvme_admin_opcode_name(nvme_admin_identify), \
28 nvme_admin_opcode_name(nvme_admin_abort_cmd), \
29 nvme_admin_opcode_name(nvme_admin_set_features), \
30 nvme_admin_opcode_name(nvme_admin_get_features), \
31 nvme_admin_opcode_name(nvme_admin_async_event), \
32 nvme_admin_opcode_name(nvme_admin_ns_mgmt), \
33 nvme_admin_opcode_name(nvme_admin_activate_fw), \
34 nvme_admin_opcode_name(nvme_admin_download_fw), \
35 nvme_admin_opcode_name(nvme_admin_ns_attach), \
36 nvme_admin_opcode_name(nvme_admin_keep_alive), \
37 nvme_admin_opcode_name(nvme_admin_directive_send), \
38 nvme_admin_opcode_name(nvme_admin_directive_recv), \
39 nvme_admin_opcode_name(nvme_admin_dbbuf), \
40 nvme_admin_opcode_name(nvme_admin_format_nvm), \
41 nvme_admin_opcode_name(nvme_admin_security_send), \
42 nvme_admin_opcode_name(nvme_admin_security_recv), \
43 nvme_admin_opcode_name(nvme_admin_sanitize_nvm))
44
Johannes Thumshirn3d030e42018-01-26 11:21:37 +010045#define nvme_opcode_name(opcode) { opcode, #opcode }
Keith Busch5d87eb92018-06-29 16:50:01 -060046#define show_nvm_opcode_name(val) \
Johannes Thumshirn3d030e42018-01-26 11:21:37 +010047 __print_symbolic(val, \
48 nvme_opcode_name(nvme_cmd_flush), \
49 nvme_opcode_name(nvme_cmd_write), \
50 nvme_opcode_name(nvme_cmd_read), \
51 nvme_opcode_name(nvme_cmd_write_uncor), \
52 nvme_opcode_name(nvme_cmd_compare), \
53 nvme_opcode_name(nvme_cmd_write_zeroes), \
54 nvme_opcode_name(nvme_cmd_dsm), \
55 nvme_opcode_name(nvme_cmd_resv_register), \
56 nvme_opcode_name(nvme_cmd_resv_report), \
57 nvme_opcode_name(nvme_cmd_resv_acquire), \
58 nvme_opcode_name(nvme_cmd_resv_release))
59
Keith Busch5d87eb92018-06-29 16:50:01 -060060#define show_opcode_name(qid, opcode) \
61 (qid ? show_nvm_opcode_name(opcode) : show_admin_opcode_name(opcode))
62
63const char *nvme_trace_parse_admin_cmd(struct trace_seq *p, u8 opcode,
64 u8 *cdw10);
Johannes Thumshirn3d030e42018-01-26 11:21:37 +010065const char *nvme_trace_parse_nvm_cmd(struct trace_seq *p, u8 opcode,
Keith Busch5d87eb92018-06-29 16:50:01 -060066 u8 *cdw10);
Johannes Thumshirn3d030e42018-01-26 11:21:37 +010067
Keith Busch5d87eb92018-06-29 16:50:01 -060068#define parse_nvme_cmd(qid, opcode, cdw10) \
69 (qid ? \
70 nvme_trace_parse_nvm_cmd(p, opcode, cdw10) : \
71 nvme_trace_parse_admin_cmd(p, opcode, cdw10))
72
Keith Busch62689532018-06-29 16:50:03 -060073const char *nvme_trace_disk_name(struct trace_seq *p, char *name);
74#define __print_disk_name(name) \
75 nvme_trace_disk_name(p, name)
76
77#ifndef TRACE_HEADER_MULTI_READ
78static inline void __assign_disk_name(char *name, struct gendisk *disk)
79{
80 if (disk)
81 memcpy(name, disk->disk_name, DISK_NAME_LEN);
82 else
83 memset(name, 0, DISK_NAME_LEN);
84}
85#endif
86
Keith Busch5d87eb92018-06-29 16:50:01 -060087TRACE_EVENT(nvme_setup_cmd,
88 TP_PROTO(struct request *req, struct nvme_command *cmd),
89 TP_ARGS(req, cmd),
Johannes Thumshirn3d030e42018-01-26 11:21:37 +010090 TP_STRUCT__entry(
Keith Busch62689532018-06-29 16:50:03 -060091 __array(char, disk, DISK_NAME_LEN)
Keith Buschb80a55e2018-07-02 09:15:03 -060092 __field(int, ctrl_id)
Keith Busch5d87eb92018-06-29 16:50:01 -060093 __field(int, qid)
94 __field(u8, opcode)
95 __field(u8, flags)
96 __field(u16, cid)
97 __field(u32, nsid)
98 __field(u64, metadata)
99 __array(u8, cdw10, 24)
Johannes Thumshirn3d030e42018-01-26 11:21:37 +0100100 ),
101 TP_fast_assign(
Keith Buschb80a55e2018-07-02 09:15:03 -0600102 __entry->ctrl_id = nvme_req(req)->ctrl->instance;
Keith Busch5d87eb92018-06-29 16:50:01 -0600103 __entry->qid = nvme_req_qid(req);
104 __entry->opcode = cmd->common.opcode;
105 __entry->flags = cmd->common.flags;
106 __entry->cid = cmd->common.command_id;
107 __entry->nsid = le32_to_cpu(cmd->common.nsid);
108 __entry->metadata = le64_to_cpu(cmd->common.metadata);
Keith Busch62689532018-06-29 16:50:03 -0600109 __assign_disk_name(__entry->disk, req->rq_disk);
Chaitanya Kulkarnib7c8f362018-12-12 15:11:37 -0800110 memcpy(__entry->cdw10, &cmd->common.cdw10,
111 6 * sizeof(__entry->cdw10));
Johannes Thumshirn3d030e42018-01-26 11:21:37 +0100112 ),
Keith Busch62689532018-06-29 16:50:03 -0600113 TP_printk("nvme%d: %sqid=%d, cmdid=%u, nsid=%u, flags=0x%x, meta=0x%llx, cmd=(%s %s)",
114 __entry->ctrl_id, __print_disk_name(__entry->disk),
115 __entry->qid, __entry->cid, __entry->nsid,
116 __entry->flags, __entry->metadata,
Keith Busch5d87eb92018-06-29 16:50:01 -0600117 show_opcode_name(__entry->qid, __entry->opcode),
118 parse_nvme_cmd(__entry->qid, __entry->opcode, __entry->cdw10))
Johannes Thumshirn3d030e42018-01-26 11:21:37 +0100119);
120
Johannes Thumshirnca5554a2018-01-26 11:21:38 +0100121TRACE_EVENT(nvme_complete_rq,
122 TP_PROTO(struct request *req),
123 TP_ARGS(req),
124 TP_STRUCT__entry(
Keith Busch62689532018-06-29 16:50:03 -0600125 __array(char, disk, DISK_NAME_LEN)
Keith Buschb80a55e2018-07-02 09:15:03 -0600126 __field(int, ctrl_id)
Keith Busch5d87eb92018-06-29 16:50:01 -0600127 __field(int, qid)
128 __field(int, cid)
129 __field(u64, result)
130 __field(u8, retries)
131 __field(u8, flags)
132 __field(u16, status)
Johannes Thumshirnca5554a2018-01-26 11:21:38 +0100133 ),
134 TP_fast_assign(
Keith Buschb80a55e2018-07-02 09:15:03 -0600135 __entry->ctrl_id = nvme_req(req)->ctrl->instance;
Keith Busch5d87eb92018-06-29 16:50:01 -0600136 __entry->qid = nvme_req_qid(req);
137 __entry->cid = req->tag;
138 __entry->result = le64_to_cpu(nvme_req(req)->result.u64);
139 __entry->retries = nvme_req(req)->retries;
140 __entry->flags = nvme_req(req)->flags;
141 __entry->status = nvme_req(req)->status;
Keith Busch62689532018-06-29 16:50:03 -0600142 __assign_disk_name(__entry->disk, req->rq_disk);
Johannes Thumshirnca5554a2018-01-26 11:21:38 +0100143 ),
Keith Busch62689532018-06-29 16:50:03 -0600144 TP_printk("nvme%d: %sqid=%d, cmdid=%u, res=%llu, retries=%u, flags=0x%x, status=%u",
145 __entry->ctrl_id, __print_disk_name(__entry->disk),
146 __entry->qid, __entry->cid, __entry->result,
147 __entry->retries, __entry->flags, __entry->status)
Johannes Thumshirnca5554a2018-01-26 11:21:38 +0100148
149);
150
Chaitanya Kulkarni09bd1ff2018-09-17 10:47:06 -0700151#define aer_name(aer) { aer, #aer }
152
153TRACE_EVENT(nvme_async_event,
154 TP_PROTO(struct nvme_ctrl *ctrl, u32 result),
155 TP_ARGS(ctrl, result),
156 TP_STRUCT__entry(
157 __field(int, ctrl_id)
158 __field(u32, result)
159 ),
160 TP_fast_assign(
161 __entry->ctrl_id = ctrl->instance;
162 __entry->result = result;
163 ),
164 TP_printk("nvme%d: NVME_AEN=%#08x [%s]",
165 __entry->ctrl_id, __entry->result,
166 __print_symbolic(__entry->result,
167 aer_name(NVME_AER_NOTICE_NS_CHANGED),
168 aer_name(NVME_AER_NOTICE_ANA),
169 aer_name(NVME_AER_NOTICE_FW_ACT_STARTING),
170 aer_name(NVME_AER_ERROR),
171 aer_name(NVME_AER_SMART),
172 aer_name(NVME_AER_CSS),
173 aer_name(NVME_AER_VS))
174 )
175);
176
177#undef aer_name
178
yupeng604c01d2018-12-18 17:59:53 +0100179TRACE_EVENT(nvme_sq,
180 TP_PROTO(struct request *req, __le16 sq_head, int sq_tail),
181 TP_ARGS(req, sq_head, sq_tail),
182 TP_STRUCT__entry(
183 __field(int, ctrl_id)
184 __array(char, disk, DISK_NAME_LEN)
185 __field(int, qid)
186 __field(u16, sq_head)
187 __field(u16, sq_tail)
188 ),
189 TP_fast_assign(
190 __entry->ctrl_id = nvme_req(req)->ctrl->instance;
191 __assign_disk_name(__entry->disk, req->rq_disk);
192 __entry->qid = nvme_req_qid(req);
193 __entry->sq_head = le16_to_cpu(sq_head);
194 __entry->sq_tail = sq_tail;
195 ),
196 TP_printk("nvme%d: %sqid=%d, head=%u, tail=%u",
197 __entry->ctrl_id, __print_disk_name(__entry->disk),
198 __entry->qid, __entry->sq_head, __entry->sq_tail
199 )
200);
201
Johannes Thumshirn3d030e42018-01-26 11:21:37 +0100202#endif /* _TRACE_NVME_H */
203
204#undef TRACE_INCLUDE_PATH
205#define TRACE_INCLUDE_PATH .
206#undef TRACE_INCLUDE_FILE
207#define TRACE_INCLUDE_FILE trace
208
209/* This part must be outside protection */
210#include <trace/define_trace.h>