nvme.h revision 1.2 1 1.2 nonaka /* $NetBSD: nvme.h,v 1.2 2017/04/29 00:06:40 nonaka Exp $ */
2 1.1 nonaka
3 1.1 nonaka /*-
4 1.1 nonaka * Copyright (C) 2012-2013 Intel Corporation
5 1.1 nonaka * All rights reserved.
6 1.1 nonaka *
7 1.1 nonaka * Redistribution and use in source and binary forms, with or without
8 1.1 nonaka * modification, are permitted provided that the following conditions
9 1.1 nonaka * are met:
10 1.1 nonaka * 1. Redistributions of source code must retain the above copyright
11 1.1 nonaka * notice, this list of conditions and the following disclaimer.
12 1.1 nonaka * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 nonaka * notice, this list of conditions and the following disclaimer in the
14 1.1 nonaka * documentation and/or other materials provided with the distribution.
15 1.1 nonaka *
16 1.1 nonaka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.1 nonaka * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 nonaka * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 nonaka * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.1 nonaka * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1 nonaka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1 nonaka * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 nonaka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1 nonaka * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 nonaka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 nonaka * SUCH DAMAGE.
27 1.1 nonaka *
28 1.2 nonaka * $FreeBSD: head/sys/dev/nvme/nvme.h 314888 2017-03-07 23:02:59Z imp $
29 1.1 nonaka */
30 1.1 nonaka
31 1.1 nonaka #ifndef __NVME_H__
32 1.1 nonaka #define __NVME_H__
33 1.1 nonaka
34 1.2 nonaka /* Cap nvme to 1MB transfers driver explodes with larger sizes */
35 1.2 nonaka #define NVME_MAX_XFER_SIZE (MAXPHYS < (1<<20) ? MAXPHYS : (1<<20))
36 1.1 nonaka
37 1.1 nonaka /* Get/Set Features */
38 1.1 nonaka #define NVME_FEAT_ARBITRATION 0x01
39 1.1 nonaka #define NVME_FEAT_POWER_MANAGEMENT 0x02
40 1.1 nonaka #define NVME_FEAT_LBA_RANGE_TYPE 0x03
41 1.1 nonaka #define NVME_FEAT_TEMPERATURE_THRESHOLD 0x04
42 1.1 nonaka #define NVME_FEAT_ERROR_RECOVERY 0x05
43 1.1 nonaka #define NVME_FEAT_VOLATILE_WRITE_CACHE 0x06
44 1.1 nonaka #define NVME_FEAT_NUMBER_OF_QUEUES 0x07
45 1.1 nonaka #define NVME_FEAT_INTERRUPT_COALESCING 0x08
46 1.1 nonaka #define NVME_FEAT_INTERRUPT_VECTOR_CONFIGURATION 0x09
47 1.1 nonaka #define NVME_FEAT_WRITE_ATOMICITY_NORMAL 0x0a
48 1.1 nonaka #define NVME_FEAT_ASYNC_EVENT_CONFIGURATION 0x0b
49 1.1 nonaka #define NVME_FEAT_AUTONOMOUS_POWER_STATE_TRANSITION 0x0c
50 1.1 nonaka #define NVME_FEAT_HOST_MEMORY_BUFFER 0x0d
51 1.1 nonaka /* NVM Command Set specific */
52 1.1 nonaka #define NVME_FEAT_SOFTWARE_PROGRESS_MARKER 0x80
53 1.1 nonaka #define NVME_FEAT_HOST_IDENTIFIER 0x81
54 1.1 nonaka #define NVME_FEAT_RESERVATION_NOTIFICATION_MASK 0x82
55 1.1 nonaka #define NVME_FEAT_RESERVATION_PERSISTANCE 0x83
56 1.1 nonaka
57 1.1 nonaka /* Get Log Page */
58 1.1 nonaka #define NVME_LOG_ERROR 0x01
59 1.1 nonaka #define NVME_LOG_HEALTH_INFORMATION 0x02
60 1.1 nonaka #define NVME_LOG_FIRMWARE_SLOT 0x03
61 1.1 nonaka #define NVME_LOG_CHANGED_NAMESPACE_LIST 0x04
62 1.1 nonaka #define NVME_LOG_COMMAND_EFFECTS_LOG 0x05
63 1.1 nonaka #define NVME_LOG_RESERVATION_NOTIFICATION 0x80
64 1.2 nonaka /*
65 1.2 nonaka * The following are Intel Specific log pages, but they seem
66 1.2 nonaka * to be widely implemented.
67 1.2 nonaka */
68 1.2 nonaka #define INTEL_LOG_READ_LAT_LOG 0xc1
69 1.2 nonaka #define INTEL_LOG_WRITE_LAT_LOG 0xc2
70 1.2 nonaka #define INTEL_LOG_TEMP_STATS 0xc5
71 1.2 nonaka #define INTEL_LOG_ADD_SMART 0xca
72 1.2 nonaka #define INTEL_LOG_DRIVE_MKT_NAME 0xdd
73 1.2 nonaka /*
74 1.2 nonaka * HGST log page, with lots ofs sub pages.
75 1.2 nonaka */
76 1.2 nonaka #define HGST_INFO_LOG 0xc1
77 1.1 nonaka
78 1.1 nonaka /* Error Information Log (Log Identifier 01h) */
79 1.1 nonaka struct nvme_error_information_entry {
80 1.1 nonaka uint64_t error_count;
81 1.1 nonaka uint16_t sqid;
82 1.1 nonaka uint16_t cid;
83 1.1 nonaka uint16_t status;
84 1.1 nonaka uint16_t error_location;
85 1.1 nonaka uint64_t lba;
86 1.1 nonaka uint32_t nsid;
87 1.1 nonaka uint8_t vendor_specific;
88 1.1 nonaka uint8_t _reserved1[3];
89 1.1 nonaka uint64_t command_specific;
90 1.1 nonaka uint8_t reserved[24];
91 1.1 nonaka } __packed __aligned(4);
92 1.1 nonaka
93 1.1 nonaka /* SMART / Health Information Log (Log Identifier 02h) */
94 1.1 nonaka struct nvme_health_information_page {
95 1.1 nonaka uint8_t critical_warning;
96 1.1 nonaka #define NVME_HEALTH_PAGE_CW_VOLATILE_MEMORY_BACKUP __BIT(4)
97 1.1 nonaka #define NVME_HEALTH_PAGE_CW_READ_ONLY __BIT(3)
98 1.1 nonaka #define NVME_HEALTH_PAGE_CW_DEVICE_RELIABLITY __BIT(2)
99 1.1 nonaka #define NVME_HEALTH_PAGE_CW_TEMPERTURE __BIT(1)
100 1.1 nonaka #define NVME_HEALTH_PAGE_CW_AVAIL_SPARE __BIT(0)
101 1.1 nonaka uint16_t composite_temperature;
102 1.1 nonaka uint8_t available_spare;
103 1.1 nonaka uint8_t available_spare_threshold;
104 1.1 nonaka uint8_t percentage_used;
105 1.1 nonaka
106 1.1 nonaka uint8_t _reserved1[26];
107 1.1 nonaka
108 1.1 nonaka uint64_t data_units_read[2];
109 1.1 nonaka uint64_t data_units_written[2];
110 1.1 nonaka uint64_t host_read_commands[2];
111 1.1 nonaka uint64_t host_write_commands[2];
112 1.1 nonaka uint64_t controller_busy_time[2];
113 1.1 nonaka uint64_t power_cycles[2];
114 1.1 nonaka uint64_t power_on_hours[2];
115 1.1 nonaka uint64_t unsafe_shutdowns[2];
116 1.1 nonaka uint64_t media_errors[2];
117 1.1 nonaka uint64_t num_error_info_log_entries[2];
118 1.2 nonaka uint32_t warning_temp_time;
119 1.2 nonaka uint32_t error_temp_time;
120 1.2 nonaka uint16_t temp_sensor[8];
121 1.1 nonaka
122 1.1 nonaka uint8_t reserved[296];
123 1.1 nonaka } __packed __aligned(4);
124 1.1 nonaka
125 1.1 nonaka /* Firmware Commit */
126 1.1 nonaka #define NVME_COMMIT_ACTION_REPLACE_NO_ACTIVATE 0
127 1.1 nonaka #define NVME_COMMIT_ACTION_REPLACE_ACTIVATE 1
128 1.1 nonaka #define NVME_COMMIT_ACTION_ACTIVATE_RESET 2
129 1.1 nonaka #define NVME_COMMIT_ACTION_ACTIVATE_NO_RESET 3
130 1.1 nonaka
131 1.1 nonaka /* Firmware Slot Information (Log Identifier 03h) */
132 1.1 nonaka struct nvme_firmware_page {
133 1.1 nonaka uint8_t afi;
134 1.1 nonaka #define NVME_FW_PAGE_AFI_SLOT_RST __BITS(4, 6)
135 1.1 nonaka #define NVME_FW_PAGE_AFI_SLOT __BITS(0, 2)
136 1.1 nonaka uint8_t _reserved1[7];
137 1.1 nonaka
138 1.1 nonaka uint64_t revision[7]; /* revisions for 7 slots */
139 1.1 nonaka
140 1.1 nonaka uint8_t reserved[448];
141 1.1 nonaka } __packed __aligned(4);
142 1.1 nonaka
143 1.2 nonaka struct intel_log_temp_stats {
144 1.2 nonaka uint64_t current;
145 1.2 nonaka uint64_t overtemp_flag_last;
146 1.2 nonaka uint64_t overtemp_flag_life;
147 1.2 nonaka uint64_t max_temp;
148 1.2 nonaka uint64_t min_temp;
149 1.2 nonaka uint64_t _rsvd[5];
150 1.2 nonaka uint64_t max_oper_temp;
151 1.2 nonaka uint64_t min_oper_temp;
152 1.2 nonaka uint64_t est_offset;
153 1.2 nonaka } __packed __aligned(4);
154 1.2 nonaka
155 1.1 nonaka /* Commands Supported and Effects (Log Identifier 05h) */
156 1.1 nonaka struct nvme_command_effeects_page {
157 1.1 nonaka uint32_t acs[256];
158 1.1 nonaka #define NVME_CE_PAGE_CS_CSE __BITS(16, 18)
159 1.1 nonaka #define NVME_CE_PAGE_CS_CCC __BIT(4)
160 1.1 nonaka #define NVME_CE_PAGE_CS_NIC __BIT(3)
161 1.1 nonaka #define NVME_CE_PAGE_CS_NCC __BIT(2)
162 1.1 nonaka #define NVME_CE_PAGE_CS_LBCC __BIT(1)
163 1.1 nonaka #define NVME_CE_PAGE_CS_CSUPP __BIT(0)
164 1.1 nonaka uint32_t iocs[256];
165 1.1 nonaka
166 1.1 nonaka uint8_t reserved[2048];
167 1.1 nonaka } __packed __aligned(4);
168 1.1 nonaka
169 1.1 nonaka #endif /* __NVME_H__ */
170