xref: /openbmc/linux/drivers/nvme/target/trace.h (revision b830f94f)
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_disk_name(char *name, struct nvmet_req *req,
50 		bool init)
51 {
52 	struct nvmet_ctrl *ctrl = nvmet_req_to_ctrl(req);
53 	struct nvmet_ns *ns;
54 
55 	if ((init && req->sq->qid) || (!init && req->cq->qid)) {
56 		ns = nvmet_find_namespace(ctrl, req->cmd->rw.nsid);
57 		strncpy(name, ns->device_path, DISK_NAME_LEN);
58 		return;
59 	}
60 
61 	memset(name, 0, DISK_NAME_LEN);
62 }
63 #endif
64 
65 TRACE_EVENT(nvmet_req_init,
66 	TP_PROTO(struct nvmet_req *req, struct nvme_command *cmd),
67 	TP_ARGS(req, cmd),
68 	TP_STRUCT__entry(
69 		__field(struct nvme_command *, cmd)
70 		__field(struct nvmet_ctrl *, ctrl)
71 		__array(char, disk, DISK_NAME_LEN)
72 		__field(int, qid)
73 		__field(u16, cid)
74 		__field(u8, opcode)
75 		__field(u8, fctype)
76 		__field(u8, flags)
77 		__field(u32, nsid)
78 		__field(u64, metadata)
79 		__array(u8, cdw10, 24)
80 	),
81 	TP_fast_assign(
82 		__entry->cmd = cmd;
83 		__entry->ctrl = nvmet_req_to_ctrl(req);
84 		__assign_disk_name(__entry->disk, req, true);
85 		__entry->qid = req->sq->qid;
86 		__entry->cid = cmd->common.command_id;
87 		__entry->opcode = cmd->common.opcode;
88 		__entry->fctype = cmd->fabrics.fctype;
89 		__entry->flags = cmd->common.flags;
90 		__entry->nsid = le32_to_cpu(cmd->common.nsid);
91 		__entry->metadata = le64_to_cpu(cmd->common.metadata);
92 		memcpy(__entry->cdw10, &cmd->common.cdw10,
93 			sizeof(__entry->cdw10));
94 	),
95 	TP_printk("nvmet%s: %sqid=%d, cmdid=%u, nsid=%u, flags=%#x, "
96 		  "meta=%#llx, cmd=(%s, %s)",
97 		__print_ctrl_name(__entry->ctrl),
98 		__print_disk_name(__entry->disk),
99 		__entry->qid, __entry->cid, __entry->nsid,
100 		__entry->flags, __entry->metadata,
101 		show_opcode_name(__entry->qid, __entry->opcode,
102 				__entry->fctype),
103 		parse_nvme_cmd(__entry->qid, __entry->opcode,
104 				__entry->fctype, __entry->cdw10))
105 );
106 
107 TRACE_EVENT(nvmet_req_complete,
108 	TP_PROTO(struct nvmet_req *req),
109 	TP_ARGS(req),
110 	TP_STRUCT__entry(
111 		__field(struct nvmet_ctrl *, ctrl)
112 		__array(char, disk, DISK_NAME_LEN)
113 		__field(int, qid)
114 		__field(int, cid)
115 		__field(u64, result)
116 		__field(u16, status)
117 	),
118 	TP_fast_assign(
119 		__entry->ctrl = nvmet_req_to_ctrl(req);
120 		__entry->qid = req->cq->qid;
121 		__entry->cid = req->cqe->command_id;
122 		__entry->result = le64_to_cpu(req->cqe->result.u64);
123 		__entry->status = le16_to_cpu(req->cqe->status) >> 1;
124 		__assign_disk_name(__entry->disk, req, false);
125 	),
126 	TP_printk("nvmet%s: %sqid=%d, cmdid=%u, res=%#llx, status=%#x",
127 		__print_ctrl_name(__entry->ctrl),
128 		__print_disk_name(__entry->disk),
129 		__entry->qid, __entry->cid, __entry->result, __entry->status)
130 
131 );
132 
133 #endif /* _TRACE_NVMET_H */
134 
135 #undef TRACE_INCLUDE_PATH
136 #define TRACE_INCLUDE_PATH .
137 #undef TRACE_INCLUDE_FILE
138 #define TRACE_INCLUDE_FILE trace
139 
140 /* This part must be outside protection */
141 #include <trace/define_trace.h>
142