xref: /linux/drivers/nvme/target/trace.h (revision 4fd18fc38757217c746aa063ba9e4729814dc737)
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
44 static inline struct nvmet_ctrl *nvmet_req_to_ctrl(struct nvmet_req *req)
45 {
46 	return req->sq->ctrl;
47 }
48 
49 static inline void __assign_req_name(char *name, struct nvmet_req *req)
50 {
51 	if (req->ns)
52 		strncpy(name, req->ns->device_path, DISK_NAME_LEN);
53 	else
54 		memset(name, 0, DISK_NAME_LEN);
55 }
56 #endif
57 
58 TRACE_EVENT(nvmet_req_init,
59 	TP_PROTO(struct nvmet_req *req, struct nvme_command *cmd),
60 	TP_ARGS(req, cmd),
61 	TP_STRUCT__entry(
62 		__field(struct nvme_command *, cmd)
63 		__field(struct nvmet_ctrl *, ctrl)
64 		__array(char, disk, DISK_NAME_LEN)
65 		__field(int, qid)
66 		__field(u16, cid)
67 		__field(u8, opcode)
68 		__field(u8, fctype)
69 		__field(u8, flags)
70 		__field(u32, nsid)
71 		__field(u64, metadata)
72 		__array(u8, cdw10, 24)
73 	),
74 	TP_fast_assign(
75 		__entry->cmd = cmd;
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));
87 	),
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,
95 				__entry->fctype),
96 		parse_nvme_cmd(__entry->qid, __entry->opcode,
97 				__entry->fctype, __entry->cdw10))
98 );
99 
100 TRACE_EVENT(nvmet_req_complete,
101 	TP_PROTO(struct nvmet_req *req),
102 	TP_ARGS(req),
103 	TP_STRUCT__entry(
104 		__field(struct nvmet_ctrl *, ctrl)
105 		__array(char, disk, DISK_NAME_LEN)
106 		__field(int, qid)
107 		__field(int, cid)
108 		__field(u64, result)
109 		__field(u16, status)
110 	),
111 	TP_fast_assign(
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);
118 	),
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)
123 
124 );
125 
126 #define aer_name(aer) { aer, #aer }
127 
128 TRACE_EVENT(nvmet_async_event,
129 	TP_PROTO(struct nvmet_ctrl *ctrl, __le32 result),
130 	TP_ARGS(ctrl, result),
131 	TP_STRUCT__entry(
132 		__field(int, ctrl_id)
133 		__field(u32, result)
134 	),
135 	TP_fast_assign(
136 		__entry->ctrl_id = ctrl->cntlid;
137 		__entry->result = (le32_to_cpu(result) & 0xff00) >> 8;
138 	),
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))
150 	)
151 );
152 #undef aer_name
153 
154 #endif /* _TRACE_NVMET_H */
155 
156 #undef TRACE_INCLUDE_PATH
157 #define TRACE_INCLUDE_PATH .
158 #undef TRACE_INCLUDE_FILE
159 #define TRACE_INCLUDE_FILE trace
160 
161 /* This part must be outside protection */
162 #include <trace/define_trace.h>
163