2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (C) 2012-2013 Intel Corporation
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #ifndef __NVMECONTROL_H__
32 #define __NVMECONTROL_H__
34 #include <dev/nvme/nvme.h>
37 typedef void (*print_fn_t)(const struct nvme_controller_data *cdata, void *buf, uint32_t size);
39 struct logpage_function {
40 SLIST_ENTRY(logpage_function) link;
48 #define NVME_LOGPAGE(unique, lp, vend, nam, fn, sz) \
49 static struct logpage_function unique ## _lpf = { \
56 static void logpage_reg_##unique(void) __attribute__((constructor)); \
57 static void logpage_reg_##unique(void) { logpage_register(&unique##_lpf); }
59 #define DEFAULT_SIZE (4096)
65 const char *kv_lookup(const struct kv_name *kv, size_t kv_count, uint32_t key);
67 void logpage_register(struct logpage_function *p);
68 #define NVME_CTRLR_PREFIX "nvme"
69 #define NVME_NS_PREFIX "ns"
71 int open_dev(const char *str, int *fd, int write, int exit_on_error);
72 void get_nsid(int fd, char **ctrlr_str, uint32_t *nsid);
73 int read_controller_data(int fd, struct nvme_controller_data *cdata);
74 int read_namespace_data(int fd, uint32_t nsid, struct nvme_namespace_data *nsdata);
75 void print_hex(void *data, uint32_t length);
76 void print_namespace(struct nvme_namespace_data *nsdata);
77 void read_logpage(int fd, uint8_t log_page, uint32_t nsid, uint8_t lsp,
78 uint16_t lsi, uint8_t rae, void *payload, uint32_t payload_size);
79 void print_temp(uint16_t t);
80 void print_intel_add_smart(const struct nvme_controller_data *cdata __unused, void *buf, uint32_t size __unused);
82 /* Utility Routines */
84 * 128-bit integer augments to standard values. On i386 this
85 * doesn't exist, so we use 64-bit values. So, on 32-bit i386,
86 * you'll get truncated values until someone implement 128bit
89 #define UINT128_DIG 39
91 typedef uint64_t uint128_t;
93 typedef __uint128_t uint128_t;
96 static __inline uint128_t
99 return *(uint128_t *)p;
102 uint64_t le48dec(const void *pp);
103 char * uint128_to_str(uint128_t u, char *buf, size_t buflen);