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_name(struct trace_seq *p, struct nvmet_ctrl *ctrl);
36 #define __print_ctrl_name(ctrl) \
37 nvmet_trace_ctrl_name(p, ctrl)
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(struct nvmet_req * req)44 static inline struct nvmet_ctrl *nvmet_req_to_ctrl(struct nvmet_req *req)
45 {
46 return req->sq->ctrl;
47 }
48
__assign_req_name(char * name,struct nvmet_req * req)49 static inline void __assign_req_name(char *name, struct nvmet_req *req)
50 {
51 if (!req->ns) {
52 memset(name, 0, DISK_NAME_LEN);
53 return;
54 }
55
56 strscpy_pad(name, req->ns->device_path, DISK_NAME_LEN);
57 }
58 #endif
59
60 TRACE_EVENT(nvmet_req_init,
61 TP_PROTO(struct nvmet_req *req, struct nvme_command *cmd),
62 TP_ARGS(req, cmd),
63 TP_STRUCT__entry(
64 __field(struct nvme_command *, cmd)
65 __field(struct nvmet_ctrl *, ctrl)
66 __array(char, disk, DISK_NAME_LEN)
67 __field(int, qid)
68 __field(u16, cid)
69 __field(u8, opcode)
70 __field(u8, fctype)
71 __field(u8, flags)
72 __field(u32, nsid)
73 __field(u64, metadata)
74 __array(u8, cdw10, 24)
75 ),
76 TP_fast_assign(
77 __entry->cmd = cmd;
78 __entry->ctrl = nvmet_req_to_ctrl(req);
79 __assign_req_name(__entry->disk, req);
80 __entry->qid = req->sq->qid;
81 __entry->cid = cmd->common.command_id;
82 __entry->opcode = cmd->common.opcode;
83 __entry->fctype = cmd->fabrics.fctype;
84 __entry->flags = cmd->common.flags;
85 __entry->nsid = le32_to_cpu(cmd->common.nsid);
86 __entry->metadata = le64_to_cpu(cmd->common.metadata);
87 memcpy(__entry->cdw10, &cmd->common.cdws,
88 sizeof(__entry->cdw10));
89 ),
90 TP_printk("nvmet%s: %sqid=%d, cmdid=%u, nsid=%u, flags=%#x, "
91 "meta=%#llx, cmd=(%s, %s)",
92 __print_ctrl_name(__entry->ctrl),
93 __print_disk_name(__entry->disk),
94 __entry->qid, __entry->cid, __entry->nsid,
95 __entry->flags, __entry->metadata,
96 show_opcode_name(__entry->qid, __entry->opcode,
97 __entry->fctype),
98 parse_nvme_cmd(__entry->qid, __entry->opcode,
99 __entry->fctype, __entry->cdw10))
100 );
101
102 TRACE_EVENT(nvmet_req_complete,
103 TP_PROTO(struct nvmet_req *req),
104 TP_ARGS(req),
105 TP_STRUCT__entry(
106 __field(struct nvmet_ctrl *, ctrl)
107 __array(char, disk, DISK_NAME_LEN)
108 __field(int, qid)
109 __field(int, cid)
110 __field(u64, result)
111 __field(u16, status)
112 ),
113 TP_fast_assign(
114 __entry->ctrl = nvmet_req_to_ctrl(req);
115 __entry->qid = req->cq->qid;
116 __entry->cid = req->cqe->command_id;
117 __entry->result = le64_to_cpu(req->cqe->result.u64);
118 __entry->status = le16_to_cpu(req->cqe->status) >> 1;
119 __assign_req_name(__entry->disk, req);
120 ),
121 TP_printk("nvmet%s: %sqid=%d, cmdid=%u, res=%#llx, status=%#x",
122 __print_ctrl_name(__entry->ctrl),
123 __print_disk_name(__entry->disk),
124 __entry->qid, __entry->cid, __entry->result, __entry->status)
125
126 );
127
128 #define aer_name(aer) { aer, #aer }
129
130 TRACE_EVENT(nvmet_async_event,
131 TP_PROTO(struct nvmet_ctrl *ctrl, __le32 result),
132 TP_ARGS(ctrl, result),
133 TP_STRUCT__entry(
134 __field(int, ctrl_id)
135 __field(u32, result)
136 ),
137 TP_fast_assign(
138 __entry->ctrl_id = ctrl->cntlid;
139 __entry->result = (le32_to_cpu(result) & 0xff00) >> 8;
140 ),
141 TP_printk("nvmet%d: NVME_AEN=%#08x [%s]",
142 __entry->ctrl_id, __entry->result,
143 __print_symbolic(__entry->result,
144 aer_name(NVME_AER_NOTICE_NS_CHANGED),
145 aer_name(NVME_AER_NOTICE_ANA),
146 aer_name(NVME_AER_NOTICE_FW_ACT_STARTING),
147 aer_name(NVME_AER_NOTICE_DISC_CHANGED),
148 aer_name(NVME_AER_ERROR),
149 aer_name(NVME_AER_SMART),
150 aer_name(NVME_AER_CSS),
151 aer_name(NVME_AER_VS))
152 )
153 );
154 #undef aer_name
155
156 #endif /* _TRACE_NVMET_H */
157
158 #undef TRACE_INCLUDE_PATH
159 #define TRACE_INCLUDE_PATH .
160 #undef TRACE_INCLUDE_FILE
161 #define TRACE_INCLUDE_FILE trace
162
163 /* This part must be outside protection */
164 #include <trace/define_trace.h>
165