xref: /linux/drivers/nvme/target/trace.h (revision d86481e924a7d6e8a40477ffa98077c6c0d77ed5)
1a5448fdcSMinwoo Im /* SPDX-License-Identifier: GPL-2.0 */
2a5448fdcSMinwoo Im /*
3a5448fdcSMinwoo Im  * NVM Express target device driver tracepoints
4a5448fdcSMinwoo Im  * Copyright (c) 2018 Johannes Thumshirn, SUSE Linux GmbH
5a5448fdcSMinwoo Im  *
6a5448fdcSMinwoo Im  * This is entirely based on drivers/nvme/host/trace.h
7a5448fdcSMinwoo Im  */
8a5448fdcSMinwoo Im 
9a5448fdcSMinwoo Im #undef TRACE_SYSTEM
10a5448fdcSMinwoo Im #define TRACE_SYSTEM nvmet
11a5448fdcSMinwoo Im 
12a5448fdcSMinwoo Im #if !defined(_TRACE_NVMET_H) || defined(TRACE_HEADER_MULTI_READ)
13a5448fdcSMinwoo Im #define _TRACE_NVMET_H
14a5448fdcSMinwoo Im 
15a5448fdcSMinwoo Im #include <linux/nvme.h>
16a5448fdcSMinwoo Im #include <linux/tracepoint.h>
17a5448fdcSMinwoo Im #include <linux/trace_seq.h>
18a5448fdcSMinwoo Im 
19a5448fdcSMinwoo Im #include "nvmet.h"
20a5448fdcSMinwoo Im 
21a5448fdcSMinwoo Im const char *nvmet_trace_parse_admin_cmd(struct trace_seq *p, u8 opcode,
22a5448fdcSMinwoo Im 		u8 *cdw10);
23a5448fdcSMinwoo Im const char *nvmet_trace_parse_nvm_cmd(struct trace_seq *p, u8 opcode,
24a5448fdcSMinwoo Im 		u8 *cdw10);
25a5448fdcSMinwoo Im const char *nvmet_trace_parse_fabrics_cmd(struct trace_seq *p, u8 fctype,
26a5448fdcSMinwoo Im 		u8 *spc);
27a5448fdcSMinwoo Im 
28a5448fdcSMinwoo Im #define parse_nvme_cmd(qid, opcode, fctype, cdw10)			\
29a5448fdcSMinwoo Im 	((opcode) == nvme_fabrics_command ?				\
30a5448fdcSMinwoo Im 	 nvmet_trace_parse_fabrics_cmd(p, fctype, cdw10) :		\
31a5448fdcSMinwoo Im 	(qid ?								\
32a5448fdcSMinwoo Im 	 nvmet_trace_parse_nvm_cmd(p, opcode, cdw10) :			\
33a5448fdcSMinwoo Im 	 nvmet_trace_parse_admin_cmd(p, opcode, cdw10)))
34a5448fdcSMinwoo Im 
35a5448fdcSMinwoo Im const char *nvmet_trace_ctrl_name(struct trace_seq *p, struct nvmet_ctrl *ctrl);
36a5448fdcSMinwoo Im #define __print_ctrl_name(ctrl)				\
37a5448fdcSMinwoo Im 	nvmet_trace_ctrl_name(p, ctrl)
38a5448fdcSMinwoo Im 
39a5448fdcSMinwoo Im const char *nvmet_trace_disk_name(struct trace_seq *p, char *name);
40a5448fdcSMinwoo Im #define __print_disk_name(name)				\
41a5448fdcSMinwoo Im 	nvmet_trace_disk_name(p, name)
42a5448fdcSMinwoo Im 
43a5448fdcSMinwoo Im #ifndef TRACE_HEADER_MULTI_READ
44a5448fdcSMinwoo Im static inline struct nvmet_ctrl *nvmet_req_to_ctrl(struct nvmet_req *req)
45a5448fdcSMinwoo Im {
46a5448fdcSMinwoo Im 	return req->sq->ctrl;
47a5448fdcSMinwoo Im }
48a5448fdcSMinwoo Im 
493c3751f2SChaitanya Kulkarni static inline void __assign_req_name(char *name, struct nvmet_req *req)
50a5448fdcSMinwoo Im {
51*d86481e9SChaitanya Kulkarni 	if (!req->ns) {
52a5448fdcSMinwoo Im 		memset(name, 0, DISK_NAME_LEN);
53*d86481e9SChaitanya Kulkarni 		return;
54*d86481e9SChaitanya Kulkarni 	}
55*d86481e9SChaitanya Kulkarni 
56*d86481e9SChaitanya Kulkarni 	strncpy(name, req->ns->device_path,
57*d86481e9SChaitanya Kulkarni 		min_t(size_t, DISK_NAME_LEN, strlen(req->ns->device_path)));
58a5448fdcSMinwoo Im }
59a5448fdcSMinwoo Im #endif
60a5448fdcSMinwoo Im 
61a5448fdcSMinwoo Im TRACE_EVENT(nvmet_req_init,
62a5448fdcSMinwoo Im 	TP_PROTO(struct nvmet_req *req, struct nvme_command *cmd),
63a5448fdcSMinwoo Im 	TP_ARGS(req, cmd),
64a5448fdcSMinwoo Im 	TP_STRUCT__entry(
65a5448fdcSMinwoo Im 		__field(struct nvme_command *, cmd)
66a5448fdcSMinwoo Im 		__field(struct nvmet_ctrl *, ctrl)
67a5448fdcSMinwoo Im 		__array(char, disk, DISK_NAME_LEN)
68a5448fdcSMinwoo Im 		__field(int, qid)
69a5448fdcSMinwoo Im 		__field(u16, cid)
70a5448fdcSMinwoo Im 		__field(u8, opcode)
71a5448fdcSMinwoo Im 		__field(u8, fctype)
72a5448fdcSMinwoo Im 		__field(u8, flags)
73a5448fdcSMinwoo Im 		__field(u32, nsid)
74a5448fdcSMinwoo Im 		__field(u64, metadata)
75a5448fdcSMinwoo Im 		__array(u8, cdw10, 24)
76a5448fdcSMinwoo Im 	),
77a5448fdcSMinwoo Im 	TP_fast_assign(
78a5448fdcSMinwoo Im 		__entry->cmd = cmd;
79a5448fdcSMinwoo Im 		__entry->ctrl = nvmet_req_to_ctrl(req);
803c3751f2SChaitanya Kulkarni 		__assign_req_name(__entry->disk, req);
81a5448fdcSMinwoo Im 		__entry->qid = req->sq->qid;
82a5448fdcSMinwoo Im 		__entry->cid = cmd->common.command_id;
83a5448fdcSMinwoo Im 		__entry->opcode = cmd->common.opcode;
84a5448fdcSMinwoo Im 		__entry->fctype = cmd->fabrics.fctype;
85a5448fdcSMinwoo Im 		__entry->flags = cmd->common.flags;
86a5448fdcSMinwoo Im 		__entry->nsid = le32_to_cpu(cmd->common.nsid);
87a5448fdcSMinwoo Im 		__entry->metadata = le64_to_cpu(cmd->common.metadata);
88a5448fdcSMinwoo Im 		memcpy(__entry->cdw10, &cmd->common.cdw10,
89a5448fdcSMinwoo Im 			sizeof(__entry->cdw10));
90a5448fdcSMinwoo Im 	),
91a5448fdcSMinwoo Im 	TP_printk("nvmet%s: %sqid=%d, cmdid=%u, nsid=%u, flags=%#x, "
92a5448fdcSMinwoo Im 		  "meta=%#llx, cmd=(%s, %s)",
93a5448fdcSMinwoo Im 		__print_ctrl_name(__entry->ctrl),
94a5448fdcSMinwoo Im 		__print_disk_name(__entry->disk),
95a5448fdcSMinwoo Im 		__entry->qid, __entry->cid, __entry->nsid,
96a5448fdcSMinwoo Im 		__entry->flags, __entry->metadata,
97a5448fdcSMinwoo Im 		show_opcode_name(__entry->qid, __entry->opcode,
98a5448fdcSMinwoo Im 				__entry->fctype),
99a5448fdcSMinwoo Im 		parse_nvme_cmd(__entry->qid, __entry->opcode,
100a5448fdcSMinwoo Im 				__entry->fctype, __entry->cdw10))
101a5448fdcSMinwoo Im );
102a5448fdcSMinwoo Im 
103a5448fdcSMinwoo Im TRACE_EVENT(nvmet_req_complete,
104a5448fdcSMinwoo Im 	TP_PROTO(struct nvmet_req *req),
105a5448fdcSMinwoo Im 	TP_ARGS(req),
106a5448fdcSMinwoo Im 	TP_STRUCT__entry(
107a5448fdcSMinwoo Im 		__field(struct nvmet_ctrl *, ctrl)
108a5448fdcSMinwoo Im 		__array(char, disk, DISK_NAME_LEN)
109a5448fdcSMinwoo Im 		__field(int, qid)
110a5448fdcSMinwoo Im 		__field(int, cid)
111a5448fdcSMinwoo Im 		__field(u64, result)
112a5448fdcSMinwoo Im 		__field(u16, status)
113a5448fdcSMinwoo Im 	),
114a5448fdcSMinwoo Im 	TP_fast_assign(
115a5448fdcSMinwoo Im 		__entry->ctrl = nvmet_req_to_ctrl(req);
116a5448fdcSMinwoo Im 		__entry->qid = req->cq->qid;
117a5448fdcSMinwoo Im 		__entry->cid = req->cqe->command_id;
118a5448fdcSMinwoo Im 		__entry->result = le64_to_cpu(req->cqe->result.u64);
119a5448fdcSMinwoo Im 		__entry->status = le16_to_cpu(req->cqe->status) >> 1;
1203c3751f2SChaitanya Kulkarni 		__assign_req_name(__entry->disk, req);
121a5448fdcSMinwoo Im 	),
122a5448fdcSMinwoo Im 	TP_printk("nvmet%s: %sqid=%d, cmdid=%u, res=%#llx, status=%#x",
123a5448fdcSMinwoo Im 		__print_ctrl_name(__entry->ctrl),
124a5448fdcSMinwoo Im 		__print_disk_name(__entry->disk),
125a5448fdcSMinwoo Im 		__entry->qid, __entry->cid, __entry->result, __entry->status)
126a5448fdcSMinwoo Im 
127a5448fdcSMinwoo Im );
128a5448fdcSMinwoo Im 
129696ece75SChaitanya Kulkarni #define aer_name(aer) { aer, #aer }
130696ece75SChaitanya Kulkarni 
131696ece75SChaitanya Kulkarni TRACE_EVENT(nvmet_async_event,
132696ece75SChaitanya Kulkarni 	TP_PROTO(struct nvmet_ctrl *ctrl, __le32 result),
133696ece75SChaitanya Kulkarni 	TP_ARGS(ctrl, result),
134696ece75SChaitanya Kulkarni 	TP_STRUCT__entry(
135696ece75SChaitanya Kulkarni 		__field(int, ctrl_id)
136696ece75SChaitanya Kulkarni 		__field(u32, result)
137696ece75SChaitanya Kulkarni 	),
138696ece75SChaitanya Kulkarni 	TP_fast_assign(
139696ece75SChaitanya Kulkarni 		__entry->ctrl_id = ctrl->cntlid;
140696ece75SChaitanya Kulkarni 		__entry->result = (le32_to_cpu(result) & 0xff00) >> 8;
141696ece75SChaitanya Kulkarni 	),
142696ece75SChaitanya Kulkarni 	TP_printk("nvmet%d: NVME_AEN=%#08x [%s]",
143696ece75SChaitanya Kulkarni 		__entry->ctrl_id, __entry->result,
144696ece75SChaitanya Kulkarni 		__print_symbolic(__entry->result,
145696ece75SChaitanya Kulkarni 		aer_name(NVME_AER_NOTICE_NS_CHANGED),
146696ece75SChaitanya Kulkarni 		aer_name(NVME_AER_NOTICE_ANA),
147696ece75SChaitanya Kulkarni 		aer_name(NVME_AER_NOTICE_FW_ACT_STARTING),
148696ece75SChaitanya Kulkarni 		aer_name(NVME_AER_NOTICE_DISC_CHANGED),
149696ece75SChaitanya Kulkarni 		aer_name(NVME_AER_ERROR),
150696ece75SChaitanya Kulkarni 		aer_name(NVME_AER_SMART),
151696ece75SChaitanya Kulkarni 		aer_name(NVME_AER_CSS),
152696ece75SChaitanya Kulkarni 		aer_name(NVME_AER_VS))
153696ece75SChaitanya Kulkarni 	)
154696ece75SChaitanya Kulkarni );
155696ece75SChaitanya Kulkarni #undef aer_name
156696ece75SChaitanya Kulkarni 
157a5448fdcSMinwoo Im #endif /* _TRACE_NVMET_H */
158a5448fdcSMinwoo Im 
159a5448fdcSMinwoo Im #undef TRACE_INCLUDE_PATH
160a5448fdcSMinwoo Im #define TRACE_INCLUDE_PATH .
161a5448fdcSMinwoo Im #undef TRACE_INCLUDE_FILE
162a5448fdcSMinwoo Im #define TRACE_INCLUDE_FILE trace
163a5448fdcSMinwoo Im 
164a5448fdcSMinwoo Im /* This part must be outside protection */
165a5448fdcSMinwoo Im #include <trace/define_trace.h>
166