1/*-
2 * Copyright (c) 2008 Scott Long
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer,
10 *    without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29#ifndef ATA_RAID_DDF_H
30#define ATA_RAID_DDF_H
31
32/* Definitions from the SNIA DDF spec, rev 1.2 */
33
34#define	DDF_HEADER_LENGTH		512
35struct ddf_header {
36	uint32_t	Signature;
37#define	DDF_HEADER_SIGNATURE	0xde11de11
38	uint32_t	CRC;
39	uint8_t		DDF_Header_GUID[24];
40	uint8_t		DDF_rev[8];
41	uint32_t	Sequence_Number;
42	uint32_t	TimeStamp;
43	uint8_t		Open_Flag;
44#define	DDF_HEADER_CLOSED	0x00
45#define	DDF_HEADER_OPENED_MASK	0x0f
46#define	DDF_HEADER_OPEN_ANCHOR	0xff
47	uint8_t		Foreign_Flag;
48	uint8_t		Diskgrouping;
49	uint8_t		pad1[13];
50	uint8_t		Header_ext[32];
51	uint64_t	Primary_Header_LBA;
52	uint64_t	Secondary_Header_LBA;
53	uint8_t		Header_Type;
54#define	DDF_HEADER_ANCHOR	0x00
55#define	DDF_HEADER_PRIMARY	0x01
56#define	DDF_HEADER_SECONDARY	0x02
57	uint8_t		pad2[3];
58	uint32_t	WorkSpace_Length;
59	uint64_t	WorkSpace_LBA;
60	uint16_t	Max_PD_Entries;
61	uint16_t	Max_VD_Entries;
62	uint16_t	Max_Partitions;
63	uint16_t	Configuration_Record_Length;
64	uint16_t	Max_Primary_Element_Entries;
65	uint8_t		pad3[54];
66	uint32_t	cd_section;	/* Controller_Data_Section */
67	uint32_t	cd_length;	/* Controller_Data_Section_Length */
68	uint32_t	pdr_section;	/* Physical_Drive_Records_Section */
69	uint32_t	pdr_length;	/* Physical_Drive_Records_Length */
70	uint32_t	vdr_section;	/* Virtual_Drive_Records_Section */
71	uint32_t	vdr_length;	/* Virtual_Drive_Records_Length */
72	uint32_t	cr_section;	/* Configuration_Records_Section */
73	uint32_t	cr_length;	/* Configuration_Records_Length */
74	uint32_t	pdd_section;	/* Physical_Drive_Data_Section */
75	uint32_t	pdd_length;	/* Physical_Drive_Data_Length */
76	uint32_t	bbmlog_section;	/* BBM_Log_Section */
77	uint32_t	bbmlog_length;	/* BBM_Log_Section_Length */
78	uint32_t	Diagnostic_Space;
79	uint32_t	Diagnostic_Space_Length;
80	uint32_t	Vendor_Specific_Logs;
81	uint32_t	Vendor_Specific_Logs_Length;
82	uint8_t		pad4[256];
83} __packed;
84
85struct ddf_cd_record {
86	uint32_t	Signature;
87#define	DDF_CONTROLLER_DATA_SIGNATURE	0xad111111
88	uint32_t	CRC;
89	uint8_t		Controller_GUID[24];
90	struct {
91		uint16_t	Vendor_ID;
92		uint16_t	Device_ID;
93		uint16_t	SubVendor_ID;
94		uint16_t	SubDevice_ID;
95	} Controller_Type __packed;
96	uint8_t		Product_ID[16];
97	uint8_t		pad1[8];
98	uint8_t		Controller_Data[448];
99} __packed;
100
101struct ddf_device_scsi {
102	uint8_t		Lun;
103	uint8_t		Id;
104	uint8_t		Channel;
105	uint8_t		Path_Flags;
106#define DDF_DEVICE_SCSI_FLAG_BROKEN	(1 << 7)
107} __packed;
108
109struct ddf_device_sas {
110	uint64_t	Initiator_Path;
111} __packed;
112
113union ddf_pathinfo {
114	struct {
115		struct ddf_device_scsi	Path0;
116		struct ddf_device_scsi	Path1;
117		uint8_t			pad[10];
118	} __packed scsi;
119	struct {
120		struct ddf_device_sas	Path0;
121		struct ddf_device_sas	Path1;
122		uint8_t			Path0_Flags;
123		uint8_t			Path1_Flags;
124#define DDF_DEVICE_SAS_FLAG_BROKEN	(1 << 7)
125	} __packed sas;
126} __packed;
127
128struct ddf_pd_entry {
129	uint8_t			PD_GUID[24];
130	uint32_t		PD_Reference;
131	uint16_t		PD_Type;
132#define	DDF_PDE_GUID_FORCE	(1 << 0)
133#define	DDF_PDE_PARTICIPATING	(1 << 1)
134#define	DDF_PDE_GLOBAL_SPARE	(1 << 2)
135#define	DDF_PDE_CONFIG_SPARE	(1 << 3)
136#define	DDF_PDE_FOREIGN		(1 << 4)
137#define	DDF_PDE_LEGACY		(1 << 5)
138#define DDF_PDE_TYPE_MASK	(0x0f << 12)
139#define DDF_PDE_UNKNOWN		(0x00 << 12)
140#define DDF_PDE_SCSI		(0x01 << 12)
141#define DDF_PDE_SAS		(0x02 << 12)
142#define DDF_PDE_SATA		(0x03 << 12)
143#define DDF_PDE_FC		(0x04 << 12)
144	uint16_t		PD_State;
145#define	DDF_PDE_ONLINE		(1 << 0)
146#define	DDF_PDE_FAILED		(1 << 1)
147#define	DDF_PDE_REBUILD		(1 << 2)
148#define	DDF_PDE_TRANSITION	(1 << 3)
149#define	DDF_PDE_PFA		(1 << 4)
150#define	DDF_PDE_UNRECOVERED	(1 << 5)
151#define	DDF_PDE_MISSING		(1 << 6)
152	uint64_t		Configured_Size;
153	union ddf_pathinfo	Path_Information;
154	uint8_t			pad1[6];
155} __packed;
156
157struct ddf_pd_record {
158	uint32_t		Signature;
159#define	DDF_PDR_SIGNATURE	0x22222222
160	uint32_t		CRC;
161	uint16_t		Populated_PDEs;
162	uint16_t		Max_PDE_Supported;
163	uint8_t			pad1[52];
164	struct ddf_pd_entry	entry[0];
165} __packed;
166
167struct ddf_vd_entry {
168	uint8_t			VD_GUID[24];
169	uint16_t		VD_Number;
170	uint8_t			pad1[2];
171	uint16_t		VD_Type;
172#define DDF_VDE_SHARED		(1 << 0)
173#define	DDF_VDE_ENFORCE_GROUP	(1 << 1)
174#define	DDF_VDE_UNICODE_NAME	(1 << 2)
175#define	DDF_VDE_OWNER_ID_VALID	(1 << 3)
176	uint16_t		Controller_GUID_CRC;
177	uint8_t			VD_State;
178#define	DDF_VDE_OPTIMAL		0x00
179#define	DDF_VDE_DEGRADED	0x01
180#define	DDF_VDE_DELETED		0x02
181#define	DDF_VDE_MISSING		0x03
182#define	DDF_VDE_FAILED		0x04
183#define DDF_VDE_PARTIAL		0x05
184#define	DDF_VDE_STATE_MASK	0x07
185#define	DDF_VDE_MORPH		(1 << 3)
186#define	DDF_VDE_DIRTY		(1 << 4)
187	uint8_t			Init_State;
188#define	DDF_VDE_UNINTIALIZED	0x00
189#define	DDF_VDE_INIT_QUICK	0x01
190#define	DDF_VDE_INIT_FULL	0x02
191#define	DDF_VDE_INIT_MASK	0x03
192#define	DDF_VDE_UACCESS_RW	0x00
193#define	DDF_VDE_UACCESS_RO	0x80
194#define	DDF_VDE_UACCESS_BLOCKED	0xc0
195#define	DDF_VDE_UACCESS_MASK	0xc0
196	uint8_t			pad2[14];
197	uint8_t			VD_Name[16];
198} __packed;
199
200struct ddf_vd_record {
201	uint32_t		Signature;
202#define	DDF_VD_RECORD_SIGNATURE	0xdddddddd
203	uint32_t		CRC;
204	uint16_t		Populated_VDEs;
205	uint16_t		Max_VDE_Supported;
206	uint8_t			pad1[52];
207	struct ddf_vd_entry	entry[0];
208} __packed;
209
210#define DDF_CR_INVALID		0xffffffff
211
212struct ddf_vdc_record {
213	uint32_t	Signature;
214#define	DDF_VDCR_SIGNATURE	0xeeeeeeee
215	uint32_t	CRC;
216	uint8_t		VD_GUID[24];
217	uint32_t	Timestamp;
218	uint32_t	Sequence_Number;
219	uint8_t		pad1[24];
220	uint16_t	Primary_Element_Count;
221	uint8_t		Stripe_Size;
222	uint8_t		Primary_RAID_Level;
223#define DDF_VDCR_RAID0		0x00
224#define DDF_VDCR_RAID1		0x01
225#define DDF_VDCR_RAID3		0x03
226#define DDF_VDCR_RAID4		0x04
227#define DDF_VDCR_RAID5		0x05
228#define DDF_VDCR_RAID6		0x06
229#define DDF_VDCR_RAID1E		0x11
230#define DDF_VDCR_SINGLE		0x0f
231#define DDF_VDCR_CONCAT		0x1f
232#define DDF_VDCR_RAID5E		0x15
233#define DDF_VDCR_RAID5EE	0x25
234	uint8_t		RLQ;
235	uint8_t		Secondary_Element_Count;
236	uint8_t		Secondary_Element_Seq;
237	uint8_t		Secondary_RAID_Level;
238	uint64_t	Block_Count;
239	uint64_t	VD_Size;
240	uint8_t		pad2[8];
241	uint32_t	Associated_Spares[8];
242	uint64_t	Cache_Flags;
243#define DDF_VDCR_CACHE_WB		(1 << 0)
244#define	DDF_VDCR_CACHE_WB_ADAPTIVE	(1 << 1)
245#define	DDF_VDCR_CACHE_RA		(1 << 2)
246#define	DDF_VDCR_CACHE_RA_ADAPTIVE	(1 << 3)
247#define	DDF_VDCR_CACHE_WCACHE_NOBATTERY	(1 << 4)
248#define	DDF_VDCR_CACHE_WCACHE_ALLOW	(1 << 5)
249#define	DDF_VDCR_CACHE_RCACHE_ALLOW	(1 << 6)
250#define	DDF_VDCR_CACHE_VENDOR		(1 << 7)
251	uint8_t		BG_Rate;
252	uint8_t		pad3[3];
253	uint8_t		pad4[52];
254	uint8_t		pad5[192];
255	uint8_t		V0[32];
256	uint8_t		V1[32];
257	uint8_t		V2[16];
258	uint8_t		V3[16];
259	uint8_t		Vendor_Scratch[32];
260	uint32_t	Physical_Disk_Sequence[0];
261} __packed;
262
263struct ddf_vuc_record {
264	uint32_t	Signature;
265#define	DDF_VUCR_SIGNATURE	0x88888888
266	uint32_t	CRC;
267	uint8_t		VD_GUID[24];
268} __packed;
269
270struct ddf_sa_entry {
271	uint8_t		VD_GUID[24];
272	uint16_t	Secondary_Element;
273	uint8_t		rsrvd2[6];
274} __packed;
275
276struct ddf_sa_record {
277	uint32_t	Signature;
278#define	DDF_SA_SIGNATURE	0x55555555
279	uint32_t	CRC;
280	uint32_t	Timestamp;
281	uint8_t		pad1[7];
282	uint8_t		Spare_Type;
283#define	DDF_SAR_TYPE_DEDICATED		(1 << 0)
284#define	DDF_SAR_TYPE_REVERTIBLE		(1 << 1)
285#define	DDF_SAR_TYPE_ACTIVE		(1 << 2)
286#define	DDF_SAR_TYPE_ENCL_AFFINITY	(1 << 3)
287	uint16_t	Populated_SAEs;
288	uint16_t	MAX_SAE_Supported;
289	uint8_t		pad2[8];
290	struct ddf_sa_entry	entry[0];
291} __packed;
292
293struct ddf_pdd_record {
294	uint32_t	Signature;
295#define	DDF_PDD_SIGNATURE	0x33333333
296	uint32_t	CRC;
297	uint8_t		PD_GUID[24];
298	uint32_t	PD_Reference;
299	uint8_t		Forced_Ref_Flag;
300#define	DDF_PDD_FORCED_REF	0x01
301	uint8_t		Forced_PD_GUID_Flag;
302#define	DDF_PDD_FORCED_GUID	0x01
303	uint8_t		Vendor_Scratch[32];
304	uint8_t		pad2[442];
305} __packed;
306
307struct ddf_bbm_entry {
308	uint64_t	Defective_Block_Start;
309	uint32_t	Spare_Block_Offset;
310	uint16_t	Remapped_Count;
311	uint8_t	pad[2];
312};
313
314struct ddf_bbm_log {
315	uint32_t	Signature;
316#define	DDF_BBML_SIGNATURE	0xabadb10c
317	uint32_t	CRC;
318	uint16_t	Entry_Count;
319	uint32_t	Spare_Block_Count;
320	uint8_t		pad1[10];
321	uint64_t	First_Spare_LBA;
322	uint64_t	Mapped_Block_Entry[0];
323} __packed;
324
325struct ddf_vendor_log {
326	uint32_t	Signature;
327#define	DDF_VENDOR_LOG_SIGNATURE	0x01dbeef0
328	uint32_t	CRC;
329	uint64_t	Log_Owner;
330	uint8_t		pad1[16];
331} __packed;
332
333#endif
334