2 * Copyright (c) 2012 Alexander Motin <mav@FreeBSD.org>
3 * Copyright (c) 2008 Scott Long
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer,
11 * without modification, immediately at the beginning of the file.
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 /* Definitions from the SNIA DDF spec, rev 1.2/2.0 */
35 #define DDF_HEADER_LENGTH 512
38 #define DDF_HEADER_SIGNATURE 0xde11de11
40 uint8_t DDF_Header_GUID[24];
42 uint32_t Sequence_Number;
45 #define DDF_HEADER_CLOSED 0x00
46 #define DDF_HEADER_OPENED_MASK 0x0f
47 #define DDF_HEADER_OPEN_ANCHOR 0xff
51 uint8_t Header_ext[32];
52 uint64_t Primary_Header_LBA;
53 uint64_t Secondary_Header_LBA;
55 #define DDF_HEADER_ANCHOR 0x00
56 #define DDF_HEADER_PRIMARY 0x01
57 #define DDF_HEADER_SECONDARY 0x02
59 uint32_t WorkSpace_Length;
60 uint64_t WorkSpace_LBA;
61 uint16_t Max_PD_Entries;
62 uint16_t Max_VD_Entries;
63 uint16_t Max_Partitions;
64 uint16_t Configuration_Record_Length;
65 uint16_t Max_Primary_Element_Entries;
66 uint32_t Max_Mapped_Block_Entries; /* DDF 2.0 */
68 uint32_t cd_section; /* Controller_Data_Section */
69 uint32_t cd_length; /* Controller_Data_Section_Length */
70 uint32_t pdr_section; /* Physical_Drive_Records_Section */
71 uint32_t pdr_length; /* Physical_Drive_Records_Length */
72 uint32_t vdr_section; /* Virtual_Drive_Records_Section */
73 uint32_t vdr_length; /* Virtual_Drive_Records_Length */
74 uint32_t cr_section; /* Configuration_Records_Section */
75 uint32_t cr_length; /* Configuration_Records_Length */
76 uint32_t pdd_section; /* Physical_Drive_Data_Section */
77 uint32_t pdd_length; /* Physical_Drive_Data_Length */
78 uint32_t bbmlog_section; /* BBM_Log_Section */
79 uint32_t bbmlog_length; /* BBM_Log_Section_Length */
80 uint32_t Diagnostic_Space;
81 uint32_t Diagnostic_Space_Length;
82 uint32_t Vendor_Specific_Logs;
83 uint32_t Vendor_Specific_Logs_Length;
87 struct ddf_cd_record {
89 #define DDF_CONTROLLER_DATA_SIGNATURE 0xad111111
91 uint8_t Controller_GUID[24];
95 uint16_t SubVendor_ID;
96 uint16_t SubDevice_ID;
97 } Controller_Type __packed;
98 uint8_t Product_ID[16];
100 uint8_t Controller_Data[448];
103 struct ddf_device_scsi {
108 #define DDF_DEVICE_SCSI_FLAG_BROKEN (1 << 7)
111 struct ddf_device_sas {
112 uint64_t Initiator_Path;
117 struct ddf_device_scsi Path0;
118 struct ddf_device_scsi Path1;
122 struct ddf_device_sas Path0;
123 struct ddf_device_sas Path1;
126 #define DDF_DEVICE_SAS_PHY_ID 0x7f
127 #define DDF_DEVICE_SAS_FLAG_BROKEN (1 << 7)
131 struct ddf_pd_entry {
133 uint32_t PD_Reference;
135 #define DDF_PDE_GUID_FORCE (1 << 0)
136 #define DDF_PDE_PARTICIPATING (1 << 1)
137 #define DDF_PDE_GLOBAL_SPARE (1 << 2)
138 #define DDF_PDE_CONFIG_SPARE (1 << 3)
139 #define DDF_PDE_FOREIGN (1 << 4)
140 #define DDF_PDE_LEGACY (1 << 5)
141 #define DDF_PDE_TYPE_MASK (0x0f << 12)
142 #define DDF_PDE_UNKNOWN (0x00 << 12)
143 #define DDF_PDE_SCSI (0x01 << 12)
144 #define DDF_PDE_SAS (0x02 << 12)
145 #define DDF_PDE_SATA (0x03 << 12)
146 #define DDF_PDE_FC (0x04 << 12)
148 #define DDF_PDE_ONLINE (1 << 0)
149 #define DDF_PDE_FAILED (1 << 1)
150 #define DDF_PDE_REBUILD (1 << 2)
151 #define DDF_PDE_TRANSITION (1 << 3)
152 #define DDF_PDE_PFA (1 << 4)
153 #define DDF_PDE_UNRECOVERED (1 << 5)
154 #define DDF_PDE_MISSING (1 << 6)
155 uint64_t Configured_Size;
156 union ddf_pathinfo Path_Information;
157 uint16_t Block_Size; /* DDF 2.0 */
161 struct ddf_pd_record {
163 #define DDF_PDR_SIGNATURE 0x22222222
165 uint16_t Populated_PDEs;
166 uint16_t Max_PDE_Supported;
168 struct ddf_pd_entry entry[0];
171 struct ddf_vd_entry {
176 #define DDF_VDE_SHARED (1 << 0)
177 #define DDF_VDE_ENFORCE_GROUP (1 << 1)
178 #define DDF_VDE_UNICODE_NAME (1 << 2)
179 #define DDF_VDE_OWNER_ID_VALID (1 << 3)
180 uint16_t Controller_GUID_CRC;
182 #define DDF_VDE_OPTIMAL 0x00
183 #define DDF_VDE_DEGRADED 0x01
184 #define DDF_VDE_DELETED 0x02
185 #define DDF_VDE_MISSING 0x03
186 #define DDF_VDE_FAILED 0x04
187 #define DDF_VDE_PARTIAL 0x05
188 #define DDF_VDE_OFFLINE 0x06
189 #define DDF_VDE_STATE_MASK 0x07
190 #define DDF_VDE_MORPH (1 << 3)
191 #define DDF_VDE_DIRTY (1 << 4)
193 #define DDF_VDE_UNINTIALIZED 0x00
194 #define DDF_VDE_INIT_QUICK 0x01
195 #define DDF_VDE_INIT_FULL 0x02
196 #define DDF_VDE_INIT_MASK 0x03
197 #define DDF_VDE_UACCESS_RW 0x00
198 #define DDF_VDE_UACCESS_RO 0x80
199 #define DDF_VDE_UACCESS_BLOCKED 0xc0
200 #define DDF_VDE_UACCESS_MASK 0xc0
201 uint8_t Drive_Failures_Remaining; /* DDF 2.0 */
206 struct ddf_vd_record {
208 #define DDF_VD_RECORD_SIGNATURE 0xdddddddd
210 uint16_t Populated_VDEs;
211 uint16_t Max_VDE_Supported;
213 struct ddf_vd_entry entry[0];
216 #define DDF_CR_INVALID 0xffffffff
218 struct ddf_vdc_record {
220 #define DDF_VDCR_SIGNATURE 0xeeeeeeee
224 uint32_t Sequence_Number;
226 uint16_t Primary_Element_Count;
228 uint8_t Primary_RAID_Level;
229 #define DDF_VDCR_RAID0 0x00
230 #define DDF_VDCR_RAID1 0x01
231 #define DDF_VDCR_RAID3 0x03
232 #define DDF_VDCR_RAID4 0x04
233 #define DDF_VDCR_RAID5 0x05
234 #define DDF_VDCR_RAID6 0x06
235 #define DDF_VDCR_RAID1E 0x11
236 #define DDF_VDCR_SINGLE 0x0f
237 #define DDF_VDCR_CONCAT 0x1f
238 #define DDF_VDCR_RAID5E 0x15
239 #define DDF_VDCR_RAID5EE 0x25
241 uint8_t Secondary_Element_Count;
242 uint8_t Secondary_Element_Seq;
243 uint8_t Secondary_RAID_Level;
244 uint64_t Block_Count;
246 uint16_t Block_Size; /* DDF 2.0 */
247 uint8_t Rotate_Parity_count; /* DDF 2.0 */
249 uint32_t Associated_Spares[8];
250 uint64_t Cache_Flags;
251 #define DDF_VDCR_CACHE_WB (1 << 0)
252 #define DDF_VDCR_CACHE_WB_ADAPTIVE (1 << 1)
253 #define DDF_VDCR_CACHE_RA (1 << 2)
254 #define DDF_VDCR_CACHE_RA_ADAPTIVE (1 << 3)
255 #define DDF_VDCR_CACHE_WCACHE_NOBATTERY (1 << 4)
256 #define DDF_VDCR_CACHE_WCACHE_ALLOW (1 << 5)
257 #define DDF_VDCR_CACHE_RCACHE_ALLOW (1 << 6)
258 #define DDF_VDCR_CACHE_VENDOR (1 << 7)
261 uint8_t MDF_Parity_Disks; /* DDF 2.0 */
262 uint16_t MDF_Parity_Generator_Polynomial; /* DDF 2.0 */
264 uint8_t MDF_Constant_Generation_Method; /* DDF 2.0 */
271 uint8_t Vendor_Scratch[32];
272 uint32_t Physical_Disk_Sequence[0];
275 struct ddf_vuc_record {
277 #define DDF_VUCR_SIGNATURE 0x88888888
282 struct ddf_sa_entry {
284 uint16_t Secondary_Element;
288 struct ddf_sa_record {
290 #define DDF_SA_SIGNATURE 0x55555555
295 #define DDF_SAR_TYPE_DEDICATED (1 << 0)
296 #define DDF_SAR_TYPE_REVERTIBLE (1 << 1)
297 #define DDF_SAR_TYPE_ACTIVE (1 << 2)
298 #define DDF_SAR_TYPE_ENCL_AFFINITY (1 << 3)
299 uint16_t Populated_SAEs;
300 uint16_t MAX_SAE_Supported;
302 struct ddf_sa_entry entry[0];
305 struct ddf_pdd_record {
307 #define DDF_PDD_SIGNATURE 0x33333333
310 uint32_t PD_Reference;
311 uint8_t Forced_Ref_Flag;
312 #define DDF_PDD_FORCED_REF 0x01
313 uint8_t Forced_PD_GUID_Flag;
314 #define DDF_PDD_FORCED_GUID 0x01
315 uint8_t Vendor_Scratch[32];
319 struct ddf_bbm_entry {
320 uint64_t Defective_Block_Start;
321 uint32_t Spare_Block_Offset;
322 uint16_t Remapped_Count;
328 #define DDF_BBML_SIGNATURE 0xabadb10c
330 uint32_t Entry_Count;
331 uint32_t Spare_Block_Count;
333 uint64_t First_Spare_LBA;
334 uint64_t Mapped_Block_Entry[0];
337 struct ddf_vendor_log {
339 #define DDF_VENDOR_LOG_SIGNATURE 0x01dbeef0