xref: /openbmc/linux/drivers/nvme/target/trace.c (revision 5b7766ab)
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 
7a5448fdcSMinwoo Im #include <asm/unaligned.h>
8a5448fdcSMinwoo Im #include "trace.h"
9a5448fdcSMinwoo Im 
nvmet_trace_admin_identify(struct trace_seq * p,u8 * cdw10)10a5448fdcSMinwoo Im static const char *nvmet_trace_admin_identify(struct trace_seq *p, u8 *cdw10)
11a5448fdcSMinwoo Im {
12a5448fdcSMinwoo Im 	const char *ret = trace_seq_buffer_ptr(p);
13a5448fdcSMinwoo Im 	u8 cns = cdw10[0];
14a5448fdcSMinwoo Im 	u16 ctrlid = get_unaligned_le16(cdw10 + 2);
15a5448fdcSMinwoo Im 
16a5448fdcSMinwoo Im 	trace_seq_printf(p, "cns=%u, ctrlid=%u", cns, ctrlid);
17a5448fdcSMinwoo Im 	trace_seq_putc(p, 0);
18a5448fdcSMinwoo Im 
19a5448fdcSMinwoo Im 	return ret;
20a5448fdcSMinwoo Im }
21a5448fdcSMinwoo Im 
nvmet_trace_admin_get_features(struct trace_seq * p,u8 * cdw10)22a5448fdcSMinwoo Im static const char *nvmet_trace_admin_get_features(struct trace_seq *p,
23a5448fdcSMinwoo Im 						 u8 *cdw10)
24a5448fdcSMinwoo Im {
25a5448fdcSMinwoo Im 	const char *ret = trace_seq_buffer_ptr(p);
26a5448fdcSMinwoo Im 	u8 fid = cdw10[0];
27a5448fdcSMinwoo Im 	u8 sel = cdw10[1] & 0x7;
28a5448fdcSMinwoo Im 	u32 cdw11 = get_unaligned_le32(cdw10 + 4);
29a5448fdcSMinwoo Im 
308d84f9deSHou Pu 	trace_seq_printf(p, "fid=0x%x, sel=0x%x, cdw11=0x%x", fid, sel, cdw11);
31a5448fdcSMinwoo Im 	trace_seq_putc(p, 0);
32a5448fdcSMinwoo Im 
33a5448fdcSMinwoo Im 	return ret;
34a5448fdcSMinwoo Im }
35a5448fdcSMinwoo Im 
nvmet_trace_get_lba_status(struct trace_seq * p,u8 * cdw10)3642df26d4SMinwoo Im static const char *nvmet_trace_get_lba_status(struct trace_seq *p,
3742df26d4SMinwoo Im 					     u8 *cdw10)
3842df26d4SMinwoo Im {
3942df26d4SMinwoo Im 	const char *ret = trace_seq_buffer_ptr(p);
4042df26d4SMinwoo Im 	u64 slba = get_unaligned_le64(cdw10);
4142df26d4SMinwoo Im 	u32 mndw = get_unaligned_le32(cdw10 + 8);
4242df26d4SMinwoo Im 	u16 rl = get_unaligned_le16(cdw10 + 12);
4342df26d4SMinwoo Im 	u8 atype = cdw10[15];
4442df26d4SMinwoo Im 
4542df26d4SMinwoo Im 	trace_seq_printf(p, "slba=0x%llx, mndw=0x%x, rl=0x%x, atype=%u",
4642df26d4SMinwoo Im 			slba, mndw, rl, atype);
4742df26d4SMinwoo Im 	trace_seq_putc(p, 0);
4842df26d4SMinwoo Im 
4942df26d4SMinwoo Im 	return ret;
5042df26d4SMinwoo Im }
5142df26d4SMinwoo Im 
nvmet_trace_admin_set_features(struct trace_seq * p,u8 * cdw10)528d84f9deSHou Pu static const char *nvmet_trace_admin_set_features(struct trace_seq *p,
538d84f9deSHou Pu 						 u8 *cdw10)
548d84f9deSHou Pu {
558d84f9deSHou Pu 	const char *ret = trace_seq_buffer_ptr(p);
568d84f9deSHou Pu 	u8 fid = cdw10[0];
578d84f9deSHou Pu 	u8 sv = cdw10[3] & 0x8;
588d84f9deSHou Pu 	u32 cdw11 = get_unaligned_le32(cdw10 + 4);
598d84f9deSHou Pu 
608d84f9deSHou Pu 	trace_seq_printf(p, "fid=0x%x, sv=0x%x, cdw11=0x%x", fid, sv, cdw11);
618d84f9deSHou Pu 	trace_seq_putc(p, 0);
628d84f9deSHou Pu 
638d84f9deSHou Pu 	return ret;
648d84f9deSHou Pu }
658d84f9deSHou Pu 
nvmet_trace_read_write(struct trace_seq * p,u8 * cdw10)66a5448fdcSMinwoo Im static const char *nvmet_trace_read_write(struct trace_seq *p, u8 *cdw10)
67a5448fdcSMinwoo Im {
68a5448fdcSMinwoo Im 	const char *ret = trace_seq_buffer_ptr(p);
69a5448fdcSMinwoo Im 	u64 slba = get_unaligned_le64(cdw10);
70a5448fdcSMinwoo Im 	u16 length = get_unaligned_le16(cdw10 + 8);
71a5448fdcSMinwoo Im 	u16 control = get_unaligned_le16(cdw10 + 10);
72a5448fdcSMinwoo Im 	u32 dsmgmt = get_unaligned_le32(cdw10 + 12);
73a5448fdcSMinwoo Im 	u32 reftag = get_unaligned_le32(cdw10 +  16);
74a5448fdcSMinwoo Im 
75a5448fdcSMinwoo Im 	trace_seq_printf(p,
76a5448fdcSMinwoo Im 			 "slba=%llu, len=%u, ctrl=0x%x, dsmgmt=%u, reftag=%u",
77a5448fdcSMinwoo Im 			 slba, length, control, dsmgmt, reftag);
78a5448fdcSMinwoo Im 	trace_seq_putc(p, 0);
79a5448fdcSMinwoo Im 
80a5448fdcSMinwoo Im 	return ret;
81a5448fdcSMinwoo Im }
82a5448fdcSMinwoo Im 
nvmet_trace_dsm(struct trace_seq * p,u8 * cdw10)83a5448fdcSMinwoo Im static const char *nvmet_trace_dsm(struct trace_seq *p, u8 *cdw10)
84a5448fdcSMinwoo Im {
85a5448fdcSMinwoo Im 	const char *ret = trace_seq_buffer_ptr(p);
86a5448fdcSMinwoo Im 
87a5448fdcSMinwoo Im 	trace_seq_printf(p, "nr=%u, attributes=%u",
88a5448fdcSMinwoo Im 			 get_unaligned_le32(cdw10),
89a5448fdcSMinwoo Im 			 get_unaligned_le32(cdw10 + 4));
90a5448fdcSMinwoo Im 	trace_seq_putc(p, 0);
91a5448fdcSMinwoo Im 
92a5448fdcSMinwoo Im 	return ret;
93a5448fdcSMinwoo Im }
94a5448fdcSMinwoo Im 
nvmet_trace_common(struct trace_seq * p,u8 * cdw10)95a5448fdcSMinwoo Im static const char *nvmet_trace_common(struct trace_seq *p, u8 *cdw10)
96a5448fdcSMinwoo Im {
97a5448fdcSMinwoo Im 	const char *ret = trace_seq_buffer_ptr(p);
98a5448fdcSMinwoo Im 
99a5448fdcSMinwoo Im 	trace_seq_printf(p, "cdw10=%*ph", 24, cdw10);
100a5448fdcSMinwoo Im 	trace_seq_putc(p, 0);
101a5448fdcSMinwoo Im 
102a5448fdcSMinwoo Im 	return ret;
103a5448fdcSMinwoo Im }
104a5448fdcSMinwoo Im 
nvmet_trace_parse_admin_cmd(struct trace_seq * p,u8 opcode,u8 * cdw10)105a5448fdcSMinwoo Im const char *nvmet_trace_parse_admin_cmd(struct trace_seq *p,
106a5448fdcSMinwoo Im 		u8 opcode, u8 *cdw10)
107a5448fdcSMinwoo Im {
108a5448fdcSMinwoo Im 	switch (opcode) {
109a5448fdcSMinwoo Im 	case nvme_admin_identify:
110a5448fdcSMinwoo Im 		return nvmet_trace_admin_identify(p, cdw10);
1118d84f9deSHou Pu 	case nvme_admin_set_features:
1128d84f9deSHou Pu 		return nvmet_trace_admin_set_features(p, cdw10);
113a5448fdcSMinwoo Im 	case nvme_admin_get_features:
114a5448fdcSMinwoo Im 		return nvmet_trace_admin_get_features(p, cdw10);
11542df26d4SMinwoo Im 	case nvme_admin_get_lba_status:
11642df26d4SMinwoo Im 		return nvmet_trace_get_lba_status(p, cdw10);
117a5448fdcSMinwoo Im 	default:
118a5448fdcSMinwoo Im 		return nvmet_trace_common(p, cdw10);
119a5448fdcSMinwoo Im 	}
120a5448fdcSMinwoo Im }
121a5448fdcSMinwoo Im 
nvmet_trace_parse_nvm_cmd(struct trace_seq * p,u8 opcode,u8 * cdw10)122a5448fdcSMinwoo Im const char *nvmet_trace_parse_nvm_cmd(struct trace_seq *p,
123a5448fdcSMinwoo Im 		u8 opcode, u8 *cdw10)
124a5448fdcSMinwoo Im {
125a5448fdcSMinwoo Im 	switch (opcode) {
126a5448fdcSMinwoo Im 	case nvme_cmd_read:
127a5448fdcSMinwoo Im 	case nvme_cmd_write:
128a5448fdcSMinwoo Im 	case nvme_cmd_write_zeroes:
129a5448fdcSMinwoo Im 		return nvmet_trace_read_write(p, cdw10);
130a5448fdcSMinwoo Im 	case nvme_cmd_dsm:
131a5448fdcSMinwoo Im 		return nvmet_trace_dsm(p, cdw10);
132a5448fdcSMinwoo Im 	default:
133a5448fdcSMinwoo Im 		return nvmet_trace_common(p, cdw10);
134a5448fdcSMinwoo Im 	}
135a5448fdcSMinwoo Im }
136a5448fdcSMinwoo Im 
nvmet_trace_fabrics_property_set(struct trace_seq * p,u8 * spc)137a5448fdcSMinwoo Im static const char *nvmet_trace_fabrics_property_set(struct trace_seq *p,
138a5448fdcSMinwoo Im 		u8 *spc)
139a5448fdcSMinwoo Im {
140a5448fdcSMinwoo Im 	const char *ret = trace_seq_buffer_ptr(p);
141a5448fdcSMinwoo Im 	u8 attrib = spc[0];
142a5448fdcSMinwoo Im 	u32 ofst = get_unaligned_le32(spc + 4);
143a5448fdcSMinwoo Im 	u64 value = get_unaligned_le64(spc + 8);
144a5448fdcSMinwoo Im 
145a5448fdcSMinwoo Im 	trace_seq_printf(p, "attrib=%u, ofst=0x%x, value=0x%llx",
146a5448fdcSMinwoo Im 			 attrib, ofst, value);
147a5448fdcSMinwoo Im 	trace_seq_putc(p, 0);
148a5448fdcSMinwoo Im 	return ret;
149a5448fdcSMinwoo Im }
150a5448fdcSMinwoo Im 
nvmet_trace_fabrics_connect(struct trace_seq * p,u8 * spc)151a5448fdcSMinwoo Im static const char *nvmet_trace_fabrics_connect(struct trace_seq *p,
152a5448fdcSMinwoo Im 		u8 *spc)
153a5448fdcSMinwoo Im {
154a5448fdcSMinwoo Im 	const char *ret = trace_seq_buffer_ptr(p);
155a5448fdcSMinwoo Im 	u16 recfmt = get_unaligned_le16(spc);
156a5448fdcSMinwoo Im 	u16 qid = get_unaligned_le16(spc + 2);
157a5448fdcSMinwoo Im 	u16 sqsize = get_unaligned_le16(spc + 4);
158a5448fdcSMinwoo Im 	u8 cattr = spc[6];
159a5448fdcSMinwoo Im 	u32 kato = get_unaligned_le32(spc + 8);
160a5448fdcSMinwoo Im 
161a5448fdcSMinwoo Im 	trace_seq_printf(p, "recfmt=%u, qid=%u, sqsize=%u, cattr=%u, kato=%u",
162a5448fdcSMinwoo Im 			 recfmt, qid, sqsize, cattr, kato);
163a5448fdcSMinwoo Im 	trace_seq_putc(p, 0);
164a5448fdcSMinwoo Im 	return ret;
165a5448fdcSMinwoo Im }
166a5448fdcSMinwoo Im 
nvmet_trace_fabrics_property_get(struct trace_seq * p,u8 * spc)167a5448fdcSMinwoo Im static const char *nvmet_trace_fabrics_property_get(struct trace_seq *p,
168a5448fdcSMinwoo Im 		u8 *spc)
169a5448fdcSMinwoo Im {
170a5448fdcSMinwoo Im 	const char *ret = trace_seq_buffer_ptr(p);
171a5448fdcSMinwoo Im 	u8 attrib = spc[0];
172a5448fdcSMinwoo Im 	u32 ofst = get_unaligned_le32(spc + 4);
173a5448fdcSMinwoo Im 
174a5448fdcSMinwoo Im 	trace_seq_printf(p, "attrib=%u, ofst=0x%x", attrib, ofst);
175a5448fdcSMinwoo Im 	trace_seq_putc(p, 0);
176a5448fdcSMinwoo Im 	return ret;
177a5448fdcSMinwoo Im }
178a5448fdcSMinwoo Im 
nvmet_trace_fabrics_common(struct trace_seq * p,u8 * spc)179a5448fdcSMinwoo Im static const char *nvmet_trace_fabrics_common(struct trace_seq *p, u8 *spc)
180a5448fdcSMinwoo Im {
181a5448fdcSMinwoo Im 	const char *ret = trace_seq_buffer_ptr(p);
182a5448fdcSMinwoo Im 
18391f6d798SColin Ian King 	trace_seq_printf(p, "specific=%*ph", 24, spc);
184a5448fdcSMinwoo Im 	trace_seq_putc(p, 0);
185a5448fdcSMinwoo Im 	return ret;
186a5448fdcSMinwoo Im }
187a5448fdcSMinwoo Im 
nvmet_trace_parse_fabrics_cmd(struct trace_seq * p,u8 fctype,u8 * spc)188a5448fdcSMinwoo Im const char *nvmet_trace_parse_fabrics_cmd(struct trace_seq *p,
189a5448fdcSMinwoo Im 		u8 fctype, u8 *spc)
190a5448fdcSMinwoo Im {
191a5448fdcSMinwoo Im 	switch (fctype) {
192a5448fdcSMinwoo Im 	case nvme_fabrics_type_property_set:
193a5448fdcSMinwoo Im 		return nvmet_trace_fabrics_property_set(p, spc);
194a5448fdcSMinwoo Im 	case nvme_fabrics_type_connect:
195a5448fdcSMinwoo Im 		return nvmet_trace_fabrics_connect(p, spc);
196a5448fdcSMinwoo Im 	case nvme_fabrics_type_property_get:
197a5448fdcSMinwoo Im 		return nvmet_trace_fabrics_property_get(p, spc);
198a5448fdcSMinwoo Im 	default:
199a5448fdcSMinwoo Im 		return nvmet_trace_fabrics_common(p, spc);
200a5448fdcSMinwoo Im 	}
201a5448fdcSMinwoo Im }
202a5448fdcSMinwoo Im 
nvmet_trace_disk_name(struct trace_seq * p,char * name)203a5448fdcSMinwoo Im const char *nvmet_trace_disk_name(struct trace_seq *p, char *name)
204a5448fdcSMinwoo Im {
205a5448fdcSMinwoo Im 	const char *ret = trace_seq_buffer_ptr(p);
206a5448fdcSMinwoo Im 
207a5448fdcSMinwoo Im 	if (*name)
208a5448fdcSMinwoo Im 		trace_seq_printf(p, "disk=%s, ", name);
209a5448fdcSMinwoo Im 	trace_seq_putc(p, 0);
210a5448fdcSMinwoo Im 
211a5448fdcSMinwoo Im 	return ret;
212a5448fdcSMinwoo Im }
213a5448fdcSMinwoo Im 
nvmet_trace_ctrl_id(struct trace_seq * p,u16 ctrl_id)214*5b7766abSDaniel Wagner const char *nvmet_trace_ctrl_id(struct trace_seq *p, u16 ctrl_id)
215a5448fdcSMinwoo Im {
216a5448fdcSMinwoo Im 	const char *ret = trace_seq_buffer_ptr(p);
217a5448fdcSMinwoo Im 
218a5448fdcSMinwoo Im 	/*
219a5448fdcSMinwoo Im 	 * XXX: We don't know the controller instance before executing the
220a5448fdcSMinwoo Im 	 * connect command itself because the connect command for the admin
221a5448fdcSMinwoo Im 	 * queue will not provide the cntlid which will be allocated in this
222a5448fdcSMinwoo Im 	 * command.  In case of io queues, the controller instance will be
223a5448fdcSMinwoo Im 	 * mapped by the extra data of the connect command.
224a5448fdcSMinwoo Im 	 * If we can know the extra data of the connect command in this stage,
225a5448fdcSMinwoo Im 	 * we can update this print statement later.
226a5448fdcSMinwoo Im 	 */
227*5b7766abSDaniel Wagner 	if (ctrl_id)
228*5b7766abSDaniel Wagner 		trace_seq_printf(p, "%d", ctrl_id);
229a5448fdcSMinwoo Im 	else
230a5448fdcSMinwoo Im 		trace_seq_printf(p, "_");
231a5448fdcSMinwoo Im 	trace_seq_putc(p, 0);
232a5448fdcSMinwoo Im 
233a5448fdcSMinwoo Im 	return ret;
234a5448fdcSMinwoo Im }
235a5448fdcSMinwoo Im 
236