Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/nvmecontrol/nvmecontrol.h
Show All 29 Lines | |||||
#ifndef __NVMECONTROL_H__ | #ifndef __NVMECONTROL_H__ | ||||
#define __NVMECONTROL_H__ | #define __NVMECONTROL_H__ | ||||
#include <sys/linker_set.h> | #include <sys/linker_set.h> | ||||
#include <dev/nvme/nvme.h> | #include <dev/nvme/nvme.h> | ||||
struct nvme_function; | struct nvme_function; | ||||
typedef void (*nvme_fn_t)(struct nvme_function *nf, int argc, char *argv[]); | typedef void (*nvme_fn_t)(const struct nvme_function *nf, int argc, char *argv[]); | ||||
struct nvme_function { | struct nvme_function { | ||||
const char *name; | const char *name; | ||||
nvme_fn_t fn; | nvme_fn_t fn; | ||||
const char *usage; | const char *usage; | ||||
}; | }; | ||||
#define NVME_SETNAME(set) set | #define NVME_SETNAME(set) set | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
struct set_concat { | struct set_concat { | ||||
void **begin; | void **begin; | ||||
void **limit; | void **limit; | ||||
}; | }; | ||||
void set_concat_add(struct set_concat *m, void *begin, void *end); | void set_concat_add(struct set_concat *m, void *begin, void *end); | ||||
#define SET_CONCAT_DEF(set, t) \ | #define SET_CONCAT_DEF(set, t) \ | ||||
static struct set_concat set ## _concat; \ | static struct set_concat set ## _concat; \ | ||||
static inline t **set ## _begin() { return ((t **)set ## _concat.begin); } \ | static inline const t * const *set ## _begin() { return ((const t * const *)set ## _concat.begin); } \ | ||||
static inline t **set ## _limit() { return ((t **)set ## _concat.limit); } \ | static inline const t * const *set ## _limit() { return ((const t * const *)set ## _concat.limit); } \ | ||||
void add_to_ ## set(t **b, t **e) \ | void add_to_ ## set(t **b, t **e) \ | ||||
{ \ | { \ | ||||
set_concat_add(&set ## _concat, b, e); \ | set_concat_add(&set ## _concat, b, e); \ | ||||
} | } | ||||
#define SET_CONCAT_DECL(set, t) \ | #define SET_CONCAT_DECL(set, t) \ | ||||
void add_to_ ## set(t **b, t **e) | void add_to_ ## set(t **b, t **e) | ||||
SET_CONCAT_DECL(top, struct nvme_function); | SET_CONCAT_DECL(top, struct nvme_function); | ||||
SET_CONCAT_DECL(logpage, struct logpage_function); | SET_CONCAT_DECL(logpage, struct logpage_function); | ||||
#define NVME_CTRLR_PREFIX "nvme" | #define NVME_CTRLR_PREFIX "nvme" | ||||
#define NVME_NS_PREFIX "ns" | #define NVME_NS_PREFIX "ns" | ||||
int open_dev(const char *str, int *fd, int show_error, int exit_on_error); | int open_dev(const char *str, int *fd, int show_error, int exit_on_error); | ||||
void parse_ns_str(const char *ns_str, char *ctrlr_str, uint32_t *nsid); | void parse_ns_str(const char *ns_str, char *ctrlr_str, uint32_t *nsid); | ||||
void read_controller_data(int fd, struct nvme_controller_data *cdata); | void read_controller_data(int fd, struct nvme_controller_data *cdata); | ||||
void read_namespace_data(int fd, uint32_t nsid, struct nvme_namespace_data *nsdata); | void read_namespace_data(int fd, uint32_t nsid, struct nvme_namespace_data *nsdata); | ||||
void print_hex(void *data, uint32_t length); | void print_hex(void *data, uint32_t length); | ||||
void read_logpage(int fd, uint8_t log_page, uint32_t nsid, void *payload, | void read_logpage(int fd, uint8_t log_page, uint32_t nsid, void *payload, | ||||
uint32_t payload_size); | uint32_t payload_size); | ||||
void print_temp(uint16_t t); | void print_temp(uint16_t t); | ||||
void usage(const struct nvme_function *f); | void usage(const struct nvme_function *f); | ||||
void dispatch_set(int argc, char *argv[], struct nvme_function **tbl, | void dispatch_set(int argc, char *argv[], const struct nvme_function * const *tbl, | ||||
struct nvme_function **tbl_limit); | const struct nvme_function * const *tbl_limit); | ||||
#define DISPATCH(argc, argv, set) \ | #define DISPATCH(argc, argv, set) \ | ||||
dispatch_set(argc, argv, NVME_CMD_BEGIN(set), NVME_CMD_LIMIT(set)) | dispatch_set(argc, argv, \ | ||||
(const struct nvme_function * const *)NVME_CMD_BEGIN(set), \ | |||||
(const struct nvme_function * const *)NVME_CMD_LIMIT(set)) \ | |||||
/* Utility Routines */ | /* Utility Routines */ | ||||
/* | /* | ||||
* 128-bit integer augments to standard values. On i386 this | * 128-bit integer augments to standard values. On i386 this | ||||
* doesn't exist, so we use 64-bit values. So, on 32-bit i386, | * doesn't exist, so we use 64-bit values. So, on 32-bit i386, | ||||
* you'll get truncated values until someone implement 128bit | * you'll get truncated values until someone implement 128bit | ||||
* ints in sofware. | * ints in sofware. | ||||
*/ | */ | ||||
Show All 17 Lines |