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 memset(name, 0, DISK_NAME_LEN);
56 strncpy(name, req->ns->device_path,
57 min_t(size_t, DISK_NAME_LEN, strlen(req->ns->device_path)));
61 TRACE_EVENT(nvmet_req_init,
62 TP_PROTO(struct nvmet_req *req, struct nvme_command *cmd),
65 __field(struct nvme_command *, cmd)
66 __field(struct nvmet_ctrl *, ctrl)
67 __array(char, disk, DISK_NAME_LEN)
74 __field(u64, metadata)
75 __array(u8, cdw10, 24)
79 __entry->ctrl = nvmet_req_to_ctrl(req);
80 __assign_req_name(__entry->disk, req);
81 __entry->qid = req->sq->qid;
82 __entry->cid = cmd->common.command_id;
83 __entry->opcode = cmd->common.opcode;
84 __entry->fctype = cmd->fabrics.fctype;
85 __entry->flags = cmd->common.flags;
86 __entry->nsid = le32_to_cpu(cmd->common.nsid);
87 __entry->metadata = le64_to_cpu(cmd->common.metadata);
88 memcpy(__entry->cdw10, &cmd->common.cdw10,
89 sizeof(__entry->cdw10));
91 TP_printk("nvmet%s: %sqid=%d, cmdid=%u, nsid=%u, flags=%#x, "
92 "meta=%#llx, cmd=(%s, %s)",
93 __print_ctrl_name(__entry->ctrl),
94 __print_disk_name(__entry->disk),
95 __entry->qid, __entry->cid, __entry->nsid,
96 __entry->flags, __entry->metadata,
97 show_opcode_name(__entry->qid, __entry->opcode,
99 parse_nvme_cmd(__entry->qid, __entry->opcode,
100 __entry->fctype, __entry->cdw10))
103 TRACE_EVENT(nvmet_req_complete,
104 TP_PROTO(struct nvmet_req *req),
107 __field(struct nvmet_ctrl *, ctrl)
108 __array(char, disk, DISK_NAME_LEN)
115 __entry->ctrl = nvmet_req_to_ctrl(req);
116 __entry->qid = req->cq->qid;
117 __entry->cid = req->cqe->command_id;
118 __entry->result = le64_to_cpu(req->cqe->result.u64);
119 __entry->status = le16_to_cpu(req->cqe->status) >> 1;
120 __assign_req_name(__entry->disk, req);
122 TP_printk("nvmet%s: %sqid=%d, cmdid=%u, res=%#llx, status=%#x",
123 __print_ctrl_name(__entry->ctrl),
124 __print_disk_name(__entry->disk),
125 __entry->qid, __entry->cid, __entry->result, __entry->status)
129 #define aer_name(aer) { aer, #aer }
131 TRACE_EVENT(nvmet_async_event,
132 TP_PROTO(struct nvmet_ctrl *ctrl, __le32 result),
133 TP_ARGS(ctrl, result),
135 __field(int, ctrl_id)
139 __entry->ctrl_id = ctrl->cntlid;
140 __entry->result = (le32_to_cpu(result) & 0xff00) >> 8;
142 TP_printk("nvmet%d: NVME_AEN=%#08x [%s]",
143 __entry->ctrl_id, __entry->result,
144 __print_symbolic(__entry->result,
145 aer_name(NVME_AER_NOTICE_NS_CHANGED),
146 aer_name(NVME_AER_NOTICE_ANA),
147 aer_name(NVME_AER_NOTICE_FW_ACT_STARTING),
148 aer_name(NVME_AER_NOTICE_DISC_CHANGED),
149 aer_name(NVME_AER_ERROR),
150 aer_name(NVME_AER_SMART),
151 aer_name(NVME_AER_CSS),
152 aer_name(NVME_AER_VS))
157 #endif /* _TRACE_NVMET_H */
159 #undef TRACE_INCLUDE_PATH
160 #define TRACE_INCLUDE_PATH .
161 #undef TRACE_INCLUDE_FILE
162 #define TRACE_INCLUDE_FILE trace
164 /* This part must be outside protection */
165 #include <trace/define_trace.h>