1 /* SPDX-License-Identifier: GPL-2.0 */
3 * NVM Express target device driver tracepoints
4 * Copyright (c) 2018 Johannes Thumshirn, SUSE Linux GmbH
6 * This is entirely based on drivers/nvme/host/trace.h
10 #define TRACE_SYSTEM nvmet
12 #if !defined(_TRACE_NVMET_H) || defined(TRACE_HEADER_MULTI_READ)
13 #define _TRACE_NVMET_H
15 #include <linux/nvme.h>
16 #include <linux/tracepoint.h>
17 #include <linux/trace_seq.h>
21 const char *nvmet_trace_parse_admin_cmd(struct trace_seq
*p
, u8 opcode
,
23 const char *nvmet_trace_parse_nvm_cmd(struct trace_seq
*p
, u8 opcode
,
25 const char *nvmet_trace_parse_fabrics_cmd(struct trace_seq
*p
, u8 fctype
,
28 #define parse_nvme_cmd(qid, opcode, fctype, cdw10) \
29 ((opcode) == nvme_fabrics_command ? \
30 nvmet_trace_parse_fabrics_cmd(p, fctype, cdw10) : \
32 nvmet_trace_parse_nvm_cmd(p, opcode, cdw10) : \
33 nvmet_trace_parse_admin_cmd(p, opcode, cdw10)))
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)
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)
43 #ifndef TRACE_HEADER_MULTI_READ
44 static inline struct nvmet_ctrl
*nvmet_req_to_ctrl(struct nvmet_req
*req
)
49 static inline void __assign_disk_name(char *name
, struct nvmet_req
*req
,
52 struct nvmet_ctrl
*ctrl
= nvmet_req_to_ctrl(req
);
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
);
61 memset(name
, 0, DISK_NAME_LEN
);
65 TRACE_EVENT(nvmet_req_init
,
66 TP_PROTO(struct nvmet_req
*req
, struct nvme_command
*cmd
),
69 __field(struct nvme_command
*, cmd
)
70 __field(struct nvmet_ctrl
*, ctrl
)
71 __array(char, disk
, DISK_NAME_LEN
)
78 __field(u64
, metadata
)
79 __array(u8
, cdw10
, 24)
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
));
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
,
103 parse_nvme_cmd(__entry
->qid
, __entry
->opcode
,
104 __entry
->fctype
, __entry
->cdw10
))
107 TRACE_EVENT(nvmet_req_complete
,
108 TP_PROTO(struct nvmet_req
*req
),
111 __field(struct nvmet_ctrl
*, ctrl
)
112 __array(char, disk
, DISK_NAME_LEN
)
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);
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
)
133 #endif /* _TRACE_NVMET_H */
135 #undef TRACE_INCLUDE_PATH
136 #define TRACE_INCLUDE_PATH .
137 #undef TRACE_INCLUDE_FILE
138 #define TRACE_INCLUDE_FILE trace
140 /* This part must be outside protection */
141 #include <trace/define_trace.h>