xref: /openbmc/linux/drivers/nvme/host/trace.c (revision 6491d698)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * NVM Express device driver tracepoints
4  * Copyright (c) 2018 Johannes Thumshirn, SUSE Linux GmbH
5  */
6 
7 #include <asm/unaligned.h>
8 #include "trace.h"
9 
10 static const char *nvme_trace_create_sq(struct trace_seq *p, u8 *cdw10)
11 {
12 	const char *ret = trace_seq_buffer_ptr(p);
13 	u16 sqid = get_unaligned_le16(cdw10);
14 	u16 qsize = get_unaligned_le16(cdw10 + 2);
15 	u16 sq_flags = get_unaligned_le16(cdw10 + 4);
16 	u16 cqid = get_unaligned_le16(cdw10 + 6);
17 
18 
19 	trace_seq_printf(p, "sqid=%u, qsize=%u, sq_flags=0x%x, cqid=%u",
20 			 sqid, qsize, sq_flags, cqid);
21 	trace_seq_putc(p, 0);
22 
23 	return ret;
24 }
25 
26 static const char *nvme_trace_create_cq(struct trace_seq *p, u8 *cdw10)
27 {
28 	const char *ret = trace_seq_buffer_ptr(p);
29 	u16 cqid = get_unaligned_le16(cdw10);
30 	u16 qsize = get_unaligned_le16(cdw10 + 2);
31 	u16 cq_flags = get_unaligned_le16(cdw10 + 4);
32 	u16 irq_vector = get_unaligned_le16(cdw10 + 6);
33 
34 	trace_seq_printf(p, "cqid=%u, qsize=%u, cq_flags=0x%x, irq_vector=%u",
35 			 cqid, qsize, cq_flags, irq_vector);
36 	trace_seq_putc(p, 0);
37 
38 	return ret;
39 }
40 
41 static const char *nvme_trace_admin_identify(struct trace_seq *p, u8 *cdw10)
42 {
43 	const char *ret = trace_seq_buffer_ptr(p);
44 	u8 cns = cdw10[0];
45 	u16 ctrlid = get_unaligned_le16(cdw10 + 2);
46 
47 	trace_seq_printf(p, "cns=%u, ctrlid=%u", cns, ctrlid);
48 	trace_seq_putc(p, 0);
49 
50 	return ret;
51 }
52 
53 static const char *nvme_trace_admin_get_features(struct trace_seq *p,
54 						 u8 *cdw10)
55 {
56 	const char *ret = trace_seq_buffer_ptr(p);
57 	u8 fid = cdw10[0];
58 	u8 sel = cdw10[1] & 0x7;
59 	u32 cdw11 = get_unaligned_le32(cdw10 + 4);
60 
61 	trace_seq_printf(p, "fid=0x%x sel=0x%x cdw11=0x%x", fid, sel, cdw11);
62 	trace_seq_putc(p, 0);
63 
64 	return ret;
65 }
66 
67 static const char *nvme_trace_read_write(struct trace_seq *p, u8 *cdw10)
68 {
69 	const char *ret = trace_seq_buffer_ptr(p);
70 	u64 slba = get_unaligned_le64(cdw10);
71 	u16 length = get_unaligned_le16(cdw10 + 8);
72 	u16 control = get_unaligned_le16(cdw10 + 10);
73 	u32 dsmgmt = get_unaligned_le32(cdw10 + 12);
74 	u32 reftag = get_unaligned_le32(cdw10 +  16);
75 
76 	trace_seq_printf(p,
77 			 "slba=%llu, len=%u, ctrl=0x%x, dsmgmt=%u, reftag=%u",
78 			 slba, length, control, dsmgmt, reftag);
79 	trace_seq_putc(p, 0);
80 
81 	return ret;
82 }
83 
84 static const char *nvme_trace_dsm(struct trace_seq *p, u8 *cdw10)
85 {
86 	const char *ret = trace_seq_buffer_ptr(p);
87 
88 	trace_seq_printf(p, "nr=%u, attributes=%u",
89 			 get_unaligned_le32(cdw10),
90 			 get_unaligned_le32(cdw10 + 4));
91 	trace_seq_putc(p, 0);
92 
93 	return ret;
94 }
95 
96 static const char *nvme_trace_common(struct trace_seq *p, u8 *cdw10)
97 {
98 	const char *ret = trace_seq_buffer_ptr(p);
99 
100 	trace_seq_printf(p, "cdw10=%*ph", 24, cdw10);
101 	trace_seq_putc(p, 0);
102 
103 	return ret;
104 }
105 
106 const char *nvme_trace_parse_admin_cmd(struct trace_seq *p,
107 				       u8 opcode, u8 *cdw10)
108 {
109 	switch (opcode) {
110 	case nvme_admin_create_sq:
111 		return nvme_trace_create_sq(p, cdw10);
112 	case nvme_admin_create_cq:
113 		return nvme_trace_create_cq(p, cdw10);
114 	case nvme_admin_identify:
115 		return nvme_trace_admin_identify(p, cdw10);
116 	case nvme_admin_get_features:
117 		return nvme_trace_admin_get_features(p, cdw10);
118 	default:
119 		return nvme_trace_common(p, cdw10);
120 	}
121 }
122 
123 const char *nvme_trace_parse_nvm_cmd(struct trace_seq *p,
124 				     u8 opcode, u8 *cdw10)
125 {
126 	switch (opcode) {
127 	case nvme_cmd_read:
128 	case nvme_cmd_write:
129 	case nvme_cmd_write_zeroes:
130 		return nvme_trace_read_write(p, cdw10);
131 	case nvme_cmd_dsm:
132 		return nvme_trace_dsm(p, cdw10);
133 	default:
134 		return nvme_trace_common(p, cdw10);
135 	}
136 }
137 
138 const char *nvme_trace_disk_name(struct trace_seq *p, char *name)
139 {
140 	const char *ret = trace_seq_buffer_ptr(p);
141 
142 	if (*name)
143 		trace_seq_printf(p, "disk=%s, ", name);
144 	trace_seq_putc(p, 0);
145 
146 	return ret;
147 }
148 EXPORT_SYMBOL_GPL(nvme_trace_disk_name);
149 
150 EXPORT_TRACEPOINT_SYMBOL_GPL(nvme_sq);
151