1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * NVM Express target device driver tracepoints
4 * Copyright (c) 2018 Johannes Thumshirn, SUSE Linux GmbH
5 *
6 * This is entirely based on drivers/nvme/host/trace.h
7 */
8
9 #undef TRACE_SYSTEM
10 #define TRACE_SYSTEM nvmet
11
12 #if !defined(_TRACE_NVMET_H) || defined(TRACE_HEADER_MULTI_READ)
13 #define _TRACE_NVMET_H
14
15 #include <linux/nvme.h>
16 #include <linux/tracepoint.h>
17 #include <linux/trace_seq.h>
18
19 #include "nvmet.h"
20
21 const char *nvmet_trace_parse_admin_cmd(struct trace_seq *p, u8 opcode,
22 u8 *cdw10);
23 const char *nvmet_trace_parse_nvm_cmd(struct trace_seq *p, u8 opcode,
24 u8 *cdw10);
25 const char *nvmet_trace_parse_fabrics_cmd(struct trace_seq *p, u8 fctype,
26 u8 *spc);
27
28 #define parse_nvme_cmd(qid, opcode, fctype, cdw10) \
29 ((opcode) == nvme_fabrics_command ? \
30 nvmet_trace_parse_fabrics_cmd(p, fctype, cdw10) : \
31 (qid ? \
32 nvmet_trace_parse_nvm_cmd(p, opcode, cdw10) : \
33 nvmet_trace_parse_admin_cmd(p, opcode, cdw10)))
34
35 const char *nvmet_trace_ctrl_id(struct trace_seq *p, u16 ctrl_id);
36 #define __print_ctrl_id(ctrl_id) \
37 nvmet_trace_ctrl_id(p, ctrl_id)
38
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)
42
43 #ifndef TRACE_HEADER_MULTI_READ
nvmet_req_to_ctrl_id(struct nvmet_req * req)44 static inline u16 nvmet_req_to_ctrl_id(struct nvmet_req *req)
45 {
46 /*
47 * The queue and controller pointers are not valid until an association
48 * has been established.
49 */
50 if (!req->sq || !req->sq->ctrl)
51 return 0;
52 return req->sq->ctrl->cntlid;
53 }
54
__assign_req_name(char * name,struct nvmet_req * req)55 static inline void __assign_req_name(char *name, struct nvmet_req *req)
56 {
57 if (!req->ns) {
58 memset(name, 0, DISK_NAME_LEN);
59 return;
60 }
61
62 strscpy_pad(name, req->ns->device_path, DISK_NAME_LEN);
63 }
64 #endif
65
66 TRACE_EVENT(nvmet_req_init,
67 TP_PROTO(struct nvmet_req *req, struct nvme_command *cmd),
68 TP_ARGS(req, cmd),
69 TP_STRUCT__entry(
70 __field(struct nvme_command *, cmd)
71 __field(u16, ctrl_id)
72 __array(char, disk, DISK_NAME_LEN)
73 __field(int, qid)
74 __field(u16, cid)
75 __field(u8, opcode)
76 __field(u8, fctype)
77 __field(u8, flags)
78 __field(u32, nsid)
79 __field(u64, metadata)
80 __array(u8, cdw10, 24)
81 ),
82 TP_fast_assign(
83 __entry->cmd = cmd;
84 __entry->ctrl_id = nvmet_req_to_ctrl_id(req);
85 __assign_req_name(__entry->disk, req);
86 __entry->qid = req->sq->qid;
87 __entry->cid = cmd->common.command_id;
88 __entry->opcode = cmd->common.opcode;
89 __entry->fctype = cmd->fabrics.fctype;
90 __entry->flags = cmd->common.flags;
91 __entry->nsid = le32_to_cpu(cmd->common.nsid);
92 __entry->metadata = le64_to_cpu(cmd->common.metadata);
93 memcpy(__entry->cdw10, &cmd->common.cdws,
94 sizeof(__entry->cdw10));
95 ),
96 TP_printk("nvmet%s: %sqid=%d, cmdid=%u, nsid=%u, flags=%#x, "
97 "meta=%#llx, cmd=(%s, %s)",
98 __print_ctrl_id(__entry->ctrl_id),
99 __print_disk_name(__entry->disk),
100 __entry->qid, __entry->cid, __entry->nsid,
101 __entry->flags, __entry->metadata,
102 show_opcode_name(__entry->qid, __entry->opcode,
103 __entry->fctype),
104 parse_nvme_cmd(__entry->qid, __entry->opcode,
105 __entry->fctype, __entry->cdw10))
106 );
107
108 TRACE_EVENT(nvmet_req_complete,
109 TP_PROTO(struct nvmet_req *req),
110 TP_ARGS(req),
111 TP_STRUCT__entry(
112 __field(u16, ctrl_id)
113 __array(char, disk, DISK_NAME_LEN)
114 __field(int, qid)
115 __field(int, cid)
116 __field(u64, result)
117 __field(u16, status)
118 ),
119 TP_fast_assign(
120 __entry->ctrl_id = nvmet_req_to_ctrl_id(req);
121 __entry->qid = req->cq->qid;
122 __entry->cid = req->cqe->command_id;
123 __entry->result = le64_to_cpu(req->cqe->result.u64);
124 __entry->status = le16_to_cpu(req->cqe->status) >> 1;
125 __assign_req_name(__entry->disk, req);
126 ),
127 TP_printk("nvmet%s: %sqid=%d, cmdid=%u, res=%#llx, status=%#x",
128 __print_ctrl_id(__entry->ctrl_id),
129 __print_disk_name(__entry->disk),
130 __entry->qid, __entry->cid, __entry->result, __entry->status)
131
132 );
133
134 #define aer_name(aer) { aer, #aer }
135
136 TRACE_EVENT(nvmet_async_event,
137 TP_PROTO(struct nvmet_ctrl *ctrl, __le32 result),
138 TP_ARGS(ctrl, result),
139 TP_STRUCT__entry(
140 __field(int, ctrl_id)
141 __field(u32, result)
142 ),
143 TP_fast_assign(
144 __entry->ctrl_id = ctrl->cntlid;
145 __entry->result = (le32_to_cpu(result) & 0xff00) >> 8;
146 ),
147 TP_printk("nvmet%d: NVME_AEN=%#08x [%s]",
148 __entry->ctrl_id, __entry->result,
149 __print_symbolic(__entry->result,
150 aer_name(NVME_AER_NOTICE_NS_CHANGED),
151 aer_name(NVME_AER_NOTICE_ANA),
152 aer_name(NVME_AER_NOTICE_FW_ACT_STARTING),
153 aer_name(NVME_AER_NOTICE_DISC_CHANGED),
154 aer_name(NVME_AER_ERROR),
155 aer_name(NVME_AER_SMART),
156 aer_name(NVME_AER_CSS),
157 aer_name(NVME_AER_VS))
158 )
159 );
160 #undef aer_name
161
162 #endif /* _TRACE_NVMET_H */
163
164 #undef TRACE_INCLUDE_PATH
165 #define TRACE_INCLUDE_PATH .
166 #undef TRACE_INCLUDE_FILE
167 #define TRACE_INCLUDE_FILE trace
168
169 /* This part must be outside protection */
170 #include <trace/define_trace.h>
171