1 /* SPDX-License-Identifier: GPL-2.0 */
3 * NVM Express target device driver tracepoints
4 * Copyright (c) 2018 Johannes Thumshirn, SUSE Linux GmbH
6 * This is entirely based on drivers/nvme/host/trace.h
10 #define TRACE_SYSTEM nvmet
12 #if !defined(_TRACE_NVMET_H) || defined(TRACE_HEADER_MULTI_READ)
13 #define _TRACE_NVMET_H
15 #include <linux/nvme.h>
16 #include <linux/tracepoint.h>
17 #include <linux/trace_seq.h>
21 const char *nvmet_trace_parse_admin_cmd(struct trace_seq *p, u8 opcode,
23 const char *nvmet_trace_parse_nvm_cmd(struct trace_seq *p, u8 opcode,
25 const char *nvmet_trace_parse_fabrics_cmd(struct trace_seq *p, u8 fctype,
28 #define parse_nvme_cmd(qid, opcode, fctype, cdw10) \
29 ((opcode) == nvme_fabrics_command ? \
30 nvmet_trace_parse_fabrics_cmd(p, fctype, cdw10) : \
32 nvmet_trace_parse_nvm_cmd(p, opcode, cdw10) : \
33 nvmet_trace_parse_admin_cmd(p, opcode, cdw10)))
35 const char *nvmet_trace_ctrl_name(struct trace_seq *p, struct nvmet_ctrl *ctrl);
36 #define __print_ctrl_name(ctrl) \
37 nvmet_trace_ctrl_name(p, ctrl)
39 const char *nvmet_trace_disk_name(struct trace_seq *p, char *name);
40 #define __print_disk_name(name) \
41 nvmet_trace_disk_name(p, name)
43 #ifndef TRACE_HEADER_MULTI_READ
44 static inline struct nvmet_ctrl *nvmet_req_to_ctrl(struct nvmet_req *req)
49 static inline void __assign_req_name(char *name, struct nvmet_req *req)
52 strncpy(name, req->ns->device_path, DISK_NAME_LEN);
54 memset(name, 0, DISK_NAME_LEN);
58 TRACE_EVENT(nvmet_req_init,
59 TP_PROTO(struct nvmet_req *req, struct nvme_command *cmd),
62 __field(struct nvme_command *, cmd)
63 __field(struct nvmet_ctrl *, ctrl)
64 __array(char, disk, DISK_NAME_LEN)
71 __field(u64, metadata)
72 __array(u8, cdw10, 24)
76 __entry->ctrl = nvmet_req_to_ctrl(req);
77 __assign_req_name(__entry->disk, req);
78 __entry->qid = req->sq->qid;
79 __entry->cid = cmd->common.command_id;
80 __entry->opcode = cmd->common.opcode;
81 __entry->fctype = cmd->fabrics.fctype;
82 __entry->flags = cmd->common.flags;
83 __entry->nsid = le32_to_cpu(cmd->common.nsid);
84 __entry->metadata = le64_to_cpu(cmd->common.metadata);
85 memcpy(__entry->cdw10, &cmd->common.cdw10,
86 sizeof(__entry->cdw10));
88 TP_printk("nvmet%s: %sqid=%d, cmdid=%u, nsid=%u, flags=%#x, "
89 "meta=%#llx, cmd=(%s, %s)",
90 __print_ctrl_name(__entry->ctrl),
91 __print_disk_name(__entry->disk),
92 __entry->qid, __entry->cid, __entry->nsid,
93 __entry->flags, __entry->metadata,
94 show_opcode_name(__entry->qid, __entry->opcode,
96 parse_nvme_cmd(__entry->qid, __entry->opcode,
97 __entry->fctype, __entry->cdw10))
100 TRACE_EVENT(nvmet_req_complete,
101 TP_PROTO(struct nvmet_req *req),
104 __field(struct nvmet_ctrl *, ctrl)
105 __array(char, disk, DISK_NAME_LEN)
112 __entry->ctrl = nvmet_req_to_ctrl(req);
113 __entry->qid = req->cq->qid;
114 __entry->cid = req->cqe->command_id;
115 __entry->result = le64_to_cpu(req->cqe->result.u64);
116 __entry->status = le16_to_cpu(req->cqe->status) >> 1;
117 __assign_req_name(__entry->disk, req);
119 TP_printk("nvmet%s: %sqid=%d, cmdid=%u, res=%#llx, status=%#x",
120 __print_ctrl_name(__entry->ctrl),
121 __print_disk_name(__entry->disk),
122 __entry->qid, __entry->cid, __entry->result, __entry->status)
126 #define aer_name(aer) { aer, #aer }
128 TRACE_EVENT(nvmet_async_event,
129 TP_PROTO(struct nvmet_ctrl *ctrl, __le32 result),
130 TP_ARGS(ctrl, result),
132 __field(int, ctrl_id)
136 __entry->ctrl_id = ctrl->cntlid;
137 __entry->result = (le32_to_cpu(result) & 0xff00) >> 8;
139 TP_printk("nvmet%d: NVME_AEN=%#08x [%s]",
140 __entry->ctrl_id, __entry->result,
141 __print_symbolic(__entry->result,
142 aer_name(NVME_AER_NOTICE_NS_CHANGED),
143 aer_name(NVME_AER_NOTICE_ANA),
144 aer_name(NVME_AER_NOTICE_FW_ACT_STARTING),
145 aer_name(NVME_AER_NOTICE_DISC_CHANGED),
146 aer_name(NVME_AER_ERROR),
147 aer_name(NVME_AER_SMART),
148 aer_name(NVME_AER_CSS),
149 aer_name(NVME_AER_VS))
154 #endif /* _TRACE_NVMET_H */
156 #undef TRACE_INCLUDE_PATH
157 #define TRACE_INCLUDE_PATH .
158 #undef TRACE_INCLUDE_FILE
159 #define TRACE_INCLUDE_FILE trace
161 /* This part must be outside protection */
162 #include <trace/define_trace.h>