xref: /netbsd-src/sbin/nvmectl/nvme.h (revision 6ac76f5b922e80abcc1378f7855ab65c6b521b35)
1 /*	$NetBSD: nvme.h,v 1.3 2018/04/18 10:11:44 nonaka Exp $	*/
2 
3 /*-
4  * Copyright (C) 2012-2013 Intel Corporation
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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.
15  *
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
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD: head/sys/dev/nvme/nvme.h 314888 2017-03-07 23:02:59Z imp $
29  */
30 
31 #ifndef __NVME_H__
32 #define __NVME_H__
33 
34 /* Cap nvme to 1MB transfers driver explodes with larger sizes */
35 #define NVME_MAX_XFER_SIZE		(MAXPHYS < (1<<20) ? MAXPHYS : (1<<20))
36 
37 /* Get Log Page */
38 #define	NVME_LOG_ERROR					0x01
39 #define	NVME_LOG_HEALTH_INFORMATION			0x02
40 #define	NVME_LOG_FIRMWARE_SLOT				0x03
41 #define	NVME_LOG_CHANGED_NAMESPACE_LIST			0x04
42 #define	NVME_LOG_COMMAND_EFFECTS_LOG			0x05
43 #define	NVME_LOG_RESERVATION_NOTIFICATION		0x80
44 /*
45  * The following are Intel Specific log pages, but they seem
46  * to be widely implemented.
47  */
48 #define	INTEL_LOG_READ_LAT_LOG				0xc1
49 #define	INTEL_LOG_WRITE_LAT_LOG				0xc2
50 #define	INTEL_LOG_TEMP_STATS				0xc5
51 #define	INTEL_LOG_ADD_SMART				0xca
52 #define	INTEL_LOG_DRIVE_MKT_NAME			0xdd
53 /*
54  * HGST log page, with lots ofs sub pages.
55  */
56 #define	HGST_INFO_LOG					0xc1
57 
58 /* Error Information Log (Log Identifier 01h) */
59 struct nvme_error_information_entry {
60 	uint64_t		error_count;
61 	uint16_t		sqid;
62 	uint16_t		cid;
63 	uint16_t		status;
64 	uint16_t		error_location;
65 	uint64_t		lba;
66 	uint32_t		nsid;
67 	uint8_t			vendor_specific;
68 	uint8_t			_reserved1[3];
69 	uint64_t		command_specific;
70 	uint8_t			reserved[24];
71 } __packed __aligned(4);
72 
73 /* SMART / Health Information Log (Log Identifier 02h) */
74 struct nvme_health_information_page {
75 	uint8_t			critical_warning;
76 #define	NVME_HEALTH_PAGE_CW_VOLATILE_MEMORY_BACKUP	__BIT(4)
77 #define	NVME_HEALTH_PAGE_CW_READ_ONLY			__BIT(3)
78 #define	NVME_HEALTH_PAGE_CW_DEVICE_RELIABLITY		__BIT(2)
79 #define	NVME_HEALTH_PAGE_CW_TEMPERTURE			__BIT(1)
80 #define	NVME_HEALTH_PAGE_CW_AVAIL_SPARE			__BIT(0)
81 	uint16_t		composite_temperature;
82 	uint8_t			available_spare;
83 	uint8_t			available_spare_threshold;
84 	uint8_t			percentage_used;
85 
86 	uint8_t			_reserved1[26];
87 
88 	uint64_t		data_units_read[2];
89 	uint64_t		data_units_written[2];
90 	uint64_t		host_read_commands[2];
91 	uint64_t		host_write_commands[2];
92 	uint64_t		controller_busy_time[2];
93 	uint64_t		power_cycles[2];
94 	uint64_t		power_on_hours[2];
95 	uint64_t		unsafe_shutdowns[2];
96 	uint64_t		media_errors[2];
97 	uint64_t		num_error_info_log_entries[2];
98 	uint32_t		warning_temp_time;
99 	uint32_t		error_temp_time;
100 	uint16_t		temp_sensor[8];
101 
102 	uint8_t			reserved[296];
103 } __packed __aligned(4);
104 
105 /* Firmware Commit */
106 #define	NVME_COMMIT_ACTION_REPLACE_NO_ACTIVATE	0
107 #define	NVME_COMMIT_ACTION_REPLACE_ACTIVATE	1
108 #define	NVME_COMMIT_ACTION_ACTIVATE_RESET	2
109 #define	NVME_COMMIT_ACTION_ACTIVATE_NO_RESET	3
110 
111 /* Firmware Slot Information (Log Identifier 03h) */
112 struct nvme_firmware_page {
113 	uint8_t			afi;
114 #define	NVME_FW_PAGE_AFI_SLOT_RST	__BITS(4, 6)
115 #define	NVME_FW_PAGE_AFI_SLOT		__BITS(0, 2)
116 	uint8_t			_reserved1[7];
117 
118 	uint64_t		revision[7];	/* revisions for 7 slots */
119 
120 	uint8_t			reserved[448];
121 } __packed __aligned(4);
122 
123 struct intel_log_temp_stats {
124 	uint64_t	current;
125 	uint64_t	overtemp_flag_last;
126 	uint64_t	overtemp_flag_life;
127 	uint64_t	max_temp;
128 	uint64_t	min_temp;
129 	uint64_t	_rsvd[5];
130 	uint64_t	max_oper_temp;
131 	uint64_t	min_oper_temp;
132 	uint64_t	est_offset;
133 } __packed __aligned(4);
134 
135 /* Commands Supported and Effects (Log Identifier 05h) */
136 struct nvme_command_effeects_page {
137 	uint32_t		acs[256];
138 #define	NVME_CE_PAGE_CS_CSE		__BITS(16, 18)
139 #define	NVME_CE_PAGE_CS_CCC		__BIT(4)
140 #define	NVME_CE_PAGE_CS_NIC		__BIT(3)
141 #define	NVME_CE_PAGE_CS_NCC		__BIT(2)
142 #define	NVME_CE_PAGE_CS_LBCC		__BIT(1)
143 #define	NVME_CE_PAGE_CS_CSUPP		__BIT(0)
144 	uint32_t		iocs[256];
145 
146 	uint8_t			reserved[2048];
147 } __packed __aligned(4);
148 
149 #endif	/* __NVME_H__ */
150