Skip to content

Commit 900adf5

Browse files
committed
logging: add nvme_mi_submit entry and exit functions
Only supported for the NVMe-MI message type NVMe admin command. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent b686e0e commit 900adf5

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

util/logging.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@
1111
#include <linux/types.h>
1212

1313
#include <libnvme.h>
14+
#include <libnvme-mi.h>
15+
16+
#include <ccan/endian/endian.h>
1417

1518
#include "logging.h"
1619
#include "sighdl.h"
1720

21+
struct submit_data {
22+
struct timeval start;
23+
struct timeval end;
24+
};
25+
1826
int log_level;
1927
static bool dry_run;
28+
static struct submit_data sb;
2029

2130
int map_log_level(int verbose, bool quiet)
2231
{
@@ -167,3 +176,105 @@ int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd,
167176

168177
return err;
169178
}
179+
180+
static void nvme_show_req_admin(const struct nvme_mi_admin_req_hdr *hdr, size_t hdr_len,
181+
const void *data, size_t data_len)
182+
{
183+
struct nvme_passthru_cmd cmd = {
184+
.opcode = hdr->opcode,
185+
.flags = hdr->flags,
186+
.nsid = le32_to_cpu(hdr->cdw1),
187+
.cdw2 = le32_to_cpu(hdr->cdw2),
188+
.cdw3 = le32_to_cpu(hdr->cdw3),
189+
.addr = (uint64_t)(uintptr_t)data,
190+
.data_len = data_len,
191+
.cdw10 = le32_to_cpu(hdr->cdw10),
192+
.cdw11 = le32_to_cpu(hdr->cdw11),
193+
.cdw12 = le32_to_cpu(hdr->cdw12),
194+
.cdw13 = le32_to_cpu(hdr->cdw13),
195+
.cdw14 = le32_to_cpu(hdr->cdw14),
196+
.cdw15 = le32_to_cpu(hdr->cdw15),
197+
};
198+
199+
nvme_show_common(&cmd);
200+
printf("doff : %08x\n", le32_to_cpu(hdr->doff));
201+
printf("dlen : %08x\n", le32_to_cpu(hdr->dlen));
202+
}
203+
204+
static void nvme_show_req(__u8 type, const struct nvme_mi_msg_hdr *hdr, size_t hdr_len,
205+
const void *data, size_t data_len)
206+
{
207+
if (type != NVME_MI_MSGTYPE_NVME)
208+
return;
209+
210+
switch (hdr->nmp >> 3 & 0xf) {
211+
case NVME_MI_MT_CONTROL:
212+
break;
213+
case NVME_MI_MT_MI:
214+
break;
215+
case NVME_MI_MT_ADMIN:
216+
nvme_show_req_admin((struct nvme_mi_admin_req_hdr *)hdr, hdr_len, data, data_len);
217+
break;
218+
case NVME_MI_MT_PCIE:
219+
break;
220+
case NVME_MI_MT_AE:
221+
break;
222+
default:
223+
break;
224+
}
225+
}
226+
227+
void *nvme_mi_submit_entry(__u8 type, const struct nvme_mi_msg_hdr *hdr, size_t hdr_len,
228+
const void *data, size_t data_len)
229+
{
230+
memset(&sb, 0, sizeof(sb));
231+
232+
if (log_level >= LOG_DEBUG) {
233+
nvme_show_req(type, hdr, hdr_len, data, data_len);
234+
gettimeofday(&sb.start, NULL);
235+
}
236+
237+
return &sb;
238+
}
239+
240+
static void nvme_show_resp_admin(const struct nvme_mi_admin_resp_hdr *hdr, size_t hdr_len,
241+
const void *data, size_t data_len)
242+
{
243+
printf("result : %08x\n", le32_to_cpu(hdr->cdw0));
244+
printf("err : %d\n", hdr->status);
245+
}
246+
247+
static void nvme_show_resp(__u8 type, const struct nvme_mi_msg_hdr *hdr, size_t hdr_len,
248+
const void *data, size_t data_len)
249+
{
250+
if (type != NVME_MI_MSGTYPE_NVME)
251+
return;
252+
253+
switch (hdr->nmp >> 3 & 0xf) {
254+
case NVME_MI_MT_CONTROL:
255+
break;
256+
case NVME_MI_MT_MI:
257+
break;
258+
case NVME_MI_MT_ADMIN:
259+
nvme_show_resp_admin((struct nvme_mi_admin_resp_hdr *)hdr, hdr_len, data, data_len);
260+
break;
261+
case NVME_MI_MT_PCIE:
262+
break;
263+
case NVME_MI_MT_AE:
264+
break;
265+
default:
266+
break;
267+
}
268+
}
269+
270+
void nvme_mi_submit_exit(__u8 type, const struct nvme_mi_msg_hdr *hdr, size_t hdr_len,
271+
const void *data, size_t data_len, void *user_data)
272+
{
273+
struct submit_data *sb = user_data;
274+
275+
if (log_level >= LOG_DEBUG) {
276+
gettimeofday(&sb->end, NULL);
277+
nvme_show_resp(type, hdr, hdr_len, data, data_len);
278+
nvme_show_latency(sb->start, sb->end);
279+
}
280+
}

0 commit comments

Comments
 (0)