Home | History | Annotate | Line # | Download | only in nvmectl
      1 /*	$NetBSD: nvmectl.h,v 1.10 2023/02/02 08:21:32 mlelstv Exp $	*/
      2 
      3 /*-
      4  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
      5  *
      6  * Copyright (C) 2012-2013 Intel Corporation
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  *
     30  * $FreeBSD: head/sbin/nvmecontrol/nvmecontrol.h 326276 2017-11-27 15:37:16Z pfg $
     31  */
     32 
     33 #ifndef __NVMECTL_H__
     34 #define __NVMECTL_H__
     35 
     36 #include <sys/ioctl.h>
     37 
     38 #include <dev/ic/nvmeio.h>
     39 #include "nvme.h"
     40 
     41 typedef void (*nvme_fn_t)(int argc, char *argv[]);
     42 
     43 struct nvme_function {
     44 	const char	*name;
     45 	nvme_fn_t	fn;
     46 	const char	*usage;
     47 };
     48 
     49 #define NVME_CTRLR_PREFIX	"nvme"
     50 #define NVME_NS_PREFIX		"ns"
     51 
     52 #define DEVLIST_USAGE							       \
     53 "devlist\n"
     54 
     55 #define IDENTIFY_USAGE							       \
     56 "identify [-x [-v]] <controller_id|namespace_id>\n"
     57 
     58 #ifdef ENABLE_PREFTEST
     59 #define PERFTEST_USAGE							       \
     60 "perftest <-n num_threads> <-o read|write>\n"				       \
     61 "                        <-s size_in_bytes> <-t time_in_seconds>\n"	       \
     62 "                        <-i intr|wait> [-f refthread] [-p]\n"		       \
     63 "                        <namespace_id>\n"
     64 #endif
     65 
     66 #ifdef ENABLE_RESET
     67 #define RESET_USAGE							       \
     68 "reset <controller id>\n"
     69 #endif
     70 
     71 #define LOGPAGE_USAGE							       \
     72 "logpage <-p page_id> [-b] [-v vendor] [-x] "				       \
     73     "<controller_id|namespace_id>\n"
     74 
     75 #ifdef ENABLE_FIRMWARE
     76 #define FIRMWARE_USAGE							       \
     77 "firmware [-s slot] [-f path_to_firmware] [-a] <controller_id>\n"
     78 #endif
     79 
     80 #define POWER_USAGE							       \
     81 "power [-l] [[-s] -p new-state [-w workload-hint]] <controller_id>\n"
     82 
     83 #define WDC_USAGE							       \
     84 "wdc cap-diag [-o path-templete]\n"
     85 
     86 void devlist(int, char *[]) __dead;
     87 void identify(int, char *[]) __dead;
     88 #ifdef PERFTEST_USAGE
     89 void perftest(int, char *[]) __dead;
     90 #endif
     91 #ifdef RESET_USAGE
     92 void reset(int, char *[]) __dead;
     93 #endif
     94 void logpage(int, char *[]) __dead;
     95 #ifdef FIRMWARE_USAGE
     96 void firmware(int, char *[]) __dead;
     97 #endif
     98 void power(int, char *[]) __dead;
     99 void wdc(int, char *[]) __dead;
    100 
    101 int open_dev(const char *, int *, int, int);
    102 void parse_ns_str(const char *, char *, int *);
    103 void read_controller_data(int, struct nvm_identify_controller *);
    104 void read_namespace_data(int, int, struct nvm_identify_namespace *);
    105 void print_hex(void *, uint32_t);
    106 void read_logpage(int, uint8_t, int, void *, uint32_t);
    107 __dead void dispatch(int argc, char *argv[], const struct nvme_function *f);
    108 
    109 /* Utility Routines */
    110 void nvme_strvis(uint8_t *, int, const uint8_t *, int);
    111 void print_bignum(const char *, uint64_t v[2], const char *);
    112 void print_bignum1(const char *, uint64_t v[2], const char *, const char *, long);
    113 uint64_t le48dec(const void *);
    114 
    115 #endif	/* __NVMECTL_H__ */
    116