nvme.h revision 1.2 1 /* $NetBSD: nvme.h,v 1.2 2017/04/29 00:06:40 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/Set Features */
38 #define NVME_FEAT_ARBITRATION 0x01
39 #define NVME_FEAT_POWER_MANAGEMENT 0x02
40 #define NVME_FEAT_LBA_RANGE_TYPE 0x03
41 #define NVME_FEAT_TEMPERATURE_THRESHOLD 0x04
42 #define NVME_FEAT_ERROR_RECOVERY 0x05
43 #define NVME_FEAT_VOLATILE_WRITE_CACHE 0x06
44 #define NVME_FEAT_NUMBER_OF_QUEUES 0x07
45 #define NVME_FEAT_INTERRUPT_COALESCING 0x08
46 #define NVME_FEAT_INTERRUPT_VECTOR_CONFIGURATION 0x09
47 #define NVME_FEAT_WRITE_ATOMICITY_NORMAL 0x0a
48 #define NVME_FEAT_ASYNC_EVENT_CONFIGURATION 0x0b
49 #define NVME_FEAT_AUTONOMOUS_POWER_STATE_TRANSITION 0x0c
50 #define NVME_FEAT_HOST_MEMORY_BUFFER 0x0d
51 /* NVM Command Set specific */
52 #define NVME_FEAT_SOFTWARE_PROGRESS_MARKER 0x80
53 #define NVME_FEAT_HOST_IDENTIFIER 0x81
54 #define NVME_FEAT_RESERVATION_NOTIFICATION_MASK 0x82
55 #define NVME_FEAT_RESERVATION_PERSISTANCE 0x83
56
57 /* Get Log Page */
58 #define NVME_LOG_ERROR 0x01
59 #define NVME_LOG_HEALTH_INFORMATION 0x02
60 #define NVME_LOG_FIRMWARE_SLOT 0x03
61 #define NVME_LOG_CHANGED_NAMESPACE_LIST 0x04
62 #define NVME_LOG_COMMAND_EFFECTS_LOG 0x05
63 #define NVME_LOG_RESERVATION_NOTIFICATION 0x80
64 /*
65 * The following are Intel Specific log pages, but they seem
66 * to be widely implemented.
67 */
68 #define INTEL_LOG_READ_LAT_LOG 0xc1
69 #define INTEL_LOG_WRITE_LAT_LOG 0xc2
70 #define INTEL_LOG_TEMP_STATS 0xc5
71 #define INTEL_LOG_ADD_SMART 0xca
72 #define INTEL_LOG_DRIVE_MKT_NAME 0xdd
73 /*
74 * HGST log page, with lots ofs sub pages.
75 */
76 #define HGST_INFO_LOG 0xc1
77
78 /* Error Information Log (Log Identifier 01h) */
79 struct nvme_error_information_entry {
80 uint64_t error_count;
81 uint16_t sqid;
82 uint16_t cid;
83 uint16_t status;
84 uint16_t error_location;
85 uint64_t lba;
86 uint32_t nsid;
87 uint8_t vendor_specific;
88 uint8_t _reserved1[3];
89 uint64_t command_specific;
90 uint8_t reserved[24];
91 } __packed __aligned(4);
92
93 /* SMART / Health Information Log (Log Identifier 02h) */
94 struct nvme_health_information_page {
95 uint8_t critical_warning;
96 #define NVME_HEALTH_PAGE_CW_VOLATILE_MEMORY_BACKUP __BIT(4)
97 #define NVME_HEALTH_PAGE_CW_READ_ONLY __BIT(3)
98 #define NVME_HEALTH_PAGE_CW_DEVICE_RELIABLITY __BIT(2)
99 #define NVME_HEALTH_PAGE_CW_TEMPERTURE __BIT(1)
100 #define NVME_HEALTH_PAGE_CW_AVAIL_SPARE __BIT(0)
101 uint16_t composite_temperature;
102 uint8_t available_spare;
103 uint8_t available_spare_threshold;
104 uint8_t percentage_used;
105
106 uint8_t _reserved1[26];
107
108 uint64_t data_units_read[2];
109 uint64_t data_units_written[2];
110 uint64_t host_read_commands[2];
111 uint64_t host_write_commands[2];
112 uint64_t controller_busy_time[2];
113 uint64_t power_cycles[2];
114 uint64_t power_on_hours[2];
115 uint64_t unsafe_shutdowns[2];
116 uint64_t media_errors[2];
117 uint64_t num_error_info_log_entries[2];
118 uint32_t warning_temp_time;
119 uint32_t error_temp_time;
120 uint16_t temp_sensor[8];
121
122 uint8_t reserved[296];
123 } __packed __aligned(4);
124
125 /* Firmware Commit */
126 #define NVME_COMMIT_ACTION_REPLACE_NO_ACTIVATE 0
127 #define NVME_COMMIT_ACTION_REPLACE_ACTIVATE 1
128 #define NVME_COMMIT_ACTION_ACTIVATE_RESET 2
129 #define NVME_COMMIT_ACTION_ACTIVATE_NO_RESET 3
130
131 /* Firmware Slot Information (Log Identifier 03h) */
132 struct nvme_firmware_page {
133 uint8_t afi;
134 #define NVME_FW_PAGE_AFI_SLOT_RST __BITS(4, 6)
135 #define NVME_FW_PAGE_AFI_SLOT __BITS(0, 2)
136 uint8_t _reserved1[7];
137
138 uint64_t revision[7]; /* revisions for 7 slots */
139
140 uint8_t reserved[448];
141 } __packed __aligned(4);
142
143 struct intel_log_temp_stats {
144 uint64_t current;
145 uint64_t overtemp_flag_last;
146 uint64_t overtemp_flag_life;
147 uint64_t max_temp;
148 uint64_t min_temp;
149 uint64_t _rsvd[5];
150 uint64_t max_oper_temp;
151 uint64_t min_oper_temp;
152 uint64_t est_offset;
153 } __packed __aligned(4);
154
155 /* Commands Supported and Effects (Log Identifier 05h) */
156 struct nvme_command_effeects_page {
157 uint32_t acs[256];
158 #define NVME_CE_PAGE_CS_CSE __BITS(16, 18)
159 #define NVME_CE_PAGE_CS_CCC __BIT(4)
160 #define NVME_CE_PAGE_CS_NIC __BIT(3)
161 #define NVME_CE_PAGE_CS_NCC __BIT(2)
162 #define NVME_CE_PAGE_CS_LBCC __BIT(1)
163 #define NVME_CE_PAGE_CS_CSUPP __BIT(0)
164 uint32_t iocs[256];
165
166 uint8_t reserved[2048];
167 } __packed __aligned(4);
168
169 #endif /* __NVME_H__ */
170