178064Sume/*-
257922Sshin * Copyright (c) 2008 Scott Long
357922Sshin * All rights reserved.
457922Sshin *
562589Sitojun * Redistribution and use in source and binary forms, with or without
657922Sshin * modification, are permitted provided that the following conditions
757922Sshin * are met:
857922Sshin * 1. Redistributions of source code must retain the above copyright
957922Sshin *    notice, this list of conditions and the following disclaimer,
1057922Sshin *    without modification, immediately at the beginning of the file.
1157922Sshin * 2. Redistributions in binary form must reproduce the above copyright
1257922Sshin *    notice, this list of conditions and the following disclaimer in the
1357922Sshin *    documentation and/or other materials provided with the distribution.
1457922Sshin *
1557922Sshin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1657922Sshin * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1762589Sitojun * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1857922Sshin * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1957922Sshin * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2057922Sshin * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2157922Sshin * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2257922Sshin * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2357922Sshin * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2457922Sshin * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2557922Sshin *
2657922Sshin * $FreeBSD$
2757922Sshin */
2857922Sshin
2957922Sshin#ifndef ATA_RAID_DDF_H
30141580Sru#define ATA_RAID_DDF_H
31141580Sru
32244750Sae/* Definitions from the SNIA DDF spec, rev 1.2 */
3357922Sshin
3462589Sitojun#define	DDF_HEADER_LENGTH		512
3557922Sshinstruct ddf_header {
3657922Sshin	uint32_t	Signature;
3757922Sshin#define	DDF_HEADER_SIGNATURE	0xde11de11
3875670Sru	uint32_t	CRC;
3975670Sru	uint8_t		DDF_Header_GUID[24];
4057922Sshin	uint8_t		DDF_rev[8];
4176175Sschweikh	uint32_t	Sequence_Number;
4257922Sshin	uint32_t	TimeStamp;
4357922Sshin	uint8_t		Open_Flag;
4457922Sshin#define	DDF_HEADER_CLOSED	0x00
4557922Sshin#define	DDF_HEADER_OPENED_MASK	0x0f
4657922Sshin#define	DDF_HEADER_OPEN_ANCHOR	0xff
4757922Sshin	uint8_t		Foreign_Flag;
4857922Sshin	uint8_t		Diskgrouping;
4978064Sume	uint8_t		pad1[13];
5057922Sshin	uint8_t		Header_ext[32];
5162589Sitojun	uint64_t	Primary_Header_LBA;
5262589Sitojun	uint64_t	Secondary_Header_LBA;
5362589Sitojun	uint8_t		Header_Type;
5462589Sitojun#define	DDF_HEADER_ANCHOR	0x00
5562589Sitojun#define	DDF_HEADER_PRIMARY	0x01
5662589Sitojun#define	DDF_HEADER_SECONDARY	0x02
5781251Sru	uint8_t		pad2[3];
5862589Sitojun	uint32_t	WorkSpace_Length;
5981251Sru	uint64_t	WorkSpace_LBA;
6062589Sitojun	uint16_t	Max_PD_Entries;
6197451Sbrooks	uint16_t	Max_VD_Entries;
6297451Sbrooks	uint16_t	Max_Partitions;
6397451Sbrooks	uint16_t	Configuration_Record_Length;
6497451Sbrooks	uint16_t	Max_Primary_Element_Entries;
6597451Sbrooks	uint8_t		pad3[54];
6697451Sbrooks	uint32_t	cd_section;	/* Controller_Data_Section */
6797451Sbrooks	uint32_t	cd_length;	/* Controller_Data_Section_Length */
6897451Sbrooks	uint32_t	pdr_section;	/* Physical_Drive_Records_Section */
6997451Sbrooks	uint32_t	pdr_length;	/* Physical_Drive_Records_Length */
7097451Sbrooks	uint32_t	vdr_section;	/* Virtual_Drive_Records_Section */
7197451Sbrooks	uint32_t	vdr_length;	/* Virtual_Drive_Records_Length */
7297451Sbrooks	uint32_t	cr_section;	/* Configuration_Records_Section */
7357922Sshin	uint32_t	cr_length;	/* Configuration_Records_Length */
7457922Sshin	uint32_t	pdd_section;	/* Physical_Drive_Data_Section */
7557922Sshin	uint32_t	pdd_length;	/* Physical_Drive_Data_Length */
7657922Sshin	uint32_t	bbmlog_section;	/* BBM_Log_Section */
7781251Sru	uint32_t	bbmlog_length;	/* BBM_Log_Section_Length */
7857922Sshin	uint32_t	Diagnostic_Space;
7957922Sshin	uint32_t	Diagnostic_Space_Length;
8057922Sshin	uint32_t	Vendor_Specific_Logs;
8157922Sshin	uint32_t	Vendor_Specific_Logs_Length;
8268962Sru	uint8_t		pad4[256];
8357922Sshin} __packed;
8457922Sshin
8557922Sshinstruct ddf_cd_record {
8657922Sshin	uint32_t	Signature;
8757922Sshin#define	DDF_CONTROLLER_DATA_SIGNATURE	0xad111111
8857922Sshin	uint32_t	CRC;
8957922Sshin	uint8_t		Controller_GUID[24];
9057922Sshin	struct {
9157922Sshin		uint16_t	Vendor_ID;
9262589Sitojun		uint16_t	Device_ID;
9362589Sitojun		uint16_t	SubVendor_ID;
9462589Sitojun		uint16_t	SubDevice_ID;
9557922Sshin	} Controller_Type __packed;
9662589Sitojun	uint8_t		Product_ID[16];
9781251Sru	uint8_t		pad1[8];
9862589Sitojun	uint8_t		Controller_Data[448];
9981251Sru} __packed;
10062589Sitojun
10157922Sshinstruct ddf_device_scsi {
10257922Sshin	uint8_t		Lun;
10357922Sshin	uint8_t		Id;
10457922Sshin	uint8_t		Channel;
10557922Sshin	uint8_t		Path_Flags;
10657922Sshin#define DDF_DEVICE_SCSI_FLAG_BROKEN	(1 << 7)
10757922Sshin} __packed;
10857922Sshin
10957922Sshinstruct ddf_device_sas {
11062589Sitojun	uint64_t	Initiator_Path;
11162589Sitojun} __packed;
11262589Sitojun
11357922Sshinunion ddf_pathinfo {
11457922Sshin	struct {
11557922Sshin		struct ddf_device_scsi	Path0;
11657922Sshin		struct ddf_device_scsi	Path1;
11757922Sshin		uint8_t			pad[10];
11857922Sshin	} __packed scsi;
11957922Sshin	struct {
12057922Sshin		struct ddf_device_sas	Path0;
12157922Sshin		struct ddf_device_sas	Path1;
12257922Sshin		uint8_t			Path0_Flags;
12357922Sshin		uint8_t			Path1_Flags;
12457922Sshin#define DDF_DEVICE_SAS_FLAG_BROKEN	(1 << 7)
12557922Sshin	} __packed sas;
12657922Sshin} __packed;
12757922Sshin
12857922Sshinstruct ddf_pd_entry {
12957922Sshin	uint8_t			PD_GUID[24];
13057922Sshin	uint32_t		PD_Reference;
13157922Sshin	uint16_t		PD_Type;
13262589Sitojun#define	DDF_PDE_GUID_FORCE	(1 << 0)
13362589Sitojun#define	DDF_PDE_PARTICIPATING	(1 << 1)
13462589Sitojun#define	DDF_PDE_GLOBAL_SPARE	(1 << 2)
13562589Sitojun#define	DDF_PDE_CONFIG_SPARE	(1 << 3)
13662589Sitojun#define	DDF_PDE_FOREIGN		(1 << 4)
13762589Sitojun#define	DDF_PDE_LEGACY		(1 << 5)
13889610Smpp#define DDF_PDE_TYPE_MASK	(0x0f << 12)
13962589Sitojun#define DDF_PDE_UNKNOWN		(0x00 << 12)
14062589Sitojun#define DDF_PDE_SCSI		(0x01 << 12)
14162589Sitojun#define DDF_PDE_SAS		(0x02 << 12)
14262589Sitojun#define DDF_PDE_SATA		(0x03 << 12)
14362589Sitojun#define DDF_PDE_FC		(0x04 << 12)
14462589Sitojun	uint16_t		PD_State;
14562589Sitojun#define	DDF_PDE_ONLINE		(1 << 0)
14662589Sitojun#define	DDF_PDE_FAILED		(1 << 1)
14762589Sitojun#define	DDF_PDE_REBUILD		(1 << 2)
14862589Sitojun#define	DDF_PDE_TRANSITION	(1 << 3)
14962589Sitojun#define	DDF_PDE_PFA		(1 << 4)
150103476Sume#define	DDF_PDE_UNRECOVERED	(1 << 5)
151107383Sru#define	DDF_PDE_MISSING		(1 << 6)
152103476Sume	uint64_t		Configured_Size;
15362589Sitojun	union ddf_pathinfo	Path_Information;
15462589Sitojun	uint8_t			pad1[6];
15562589Sitojun} __packed;
15662589Sitojun
15762589Sitojunstruct ddf_pd_record {
15862589Sitojun	uint32_t		Signature;
15978064Sume#define	DDF_PDR_SIGNATURE	0x22222222
16078064Sume	uint32_t		CRC;
16178064Sume	uint16_t		Populated_PDEs;
16262589Sitojun	uint16_t		Max_PDE_Supported;
16389610Smpp	uint8_t			pad1[52];
16462589Sitojun	struct ddf_pd_entry	entry[0];
16562589Sitojun} __packed;
16662589Sitojun
16757922Sshinstruct ddf_vd_entry {
16857922Sshin	uint8_t			VD_GUID[24];
16962589Sitojun	uint16_t		VD_Number;
17062589Sitojun	uint8_t			pad1[2];
17162589Sitojun	uint16_t		VD_Type;
17278064Sume#define DDF_VDE_SHARED		(1 << 0)
17378064Sume#define	DDF_VDE_ENFORCE_GROUP	(1 << 1)
17478064Sume#define	DDF_VDE_UNICODE_NAME	(1 << 2)
17578064Sume#define	DDF_VDE_OWNER_ID_VALID	(1 << 3)
17678064Sume	uint16_t		Controller_GUID_CRC;
17778064Sume	uint8_t			VD_State;
17878064Sume#define	DDF_VDE_OPTIMAL		0x00
17978064Sume#define	DDF_VDE_DEGRADED	0x01
18078064Sume#define	DDF_VDE_DELETED		0x02
18178064Sume#define	DDF_VDE_MISSING		0x03
18257922Sshin#define	DDF_VDE_FAILED		0x04
183244750Sae#define DDF_VDE_PARTIAL		0x05
184244750Sae#define	DDF_VDE_STATE_MASK	0x07
185244750Sae#define	DDF_VDE_MORPH		(1 << 3)
186244750Sae#define	DDF_VDE_DIRTY		(1 << 4)
187244750Sae	uint8_t			Init_State;
188244750Sae#define	DDF_VDE_UNINTIALIZED	0x00
189244750Sae#define	DDF_VDE_INIT_QUICK	0x01
190244750Sae#define	DDF_VDE_INIT_FULL	0x02
191244750Sae#define	DDF_VDE_INIT_MASK	0x03
192244750Sae#define	DDF_VDE_UACCESS_RW	0x00
193245323Sjoel#define	DDF_VDE_UACCESS_RO	0x80
194245323Sjoel#define	DDF_VDE_UACCESS_BLOCKED	0xc0
195244750Sae#define	DDF_VDE_UACCESS_MASK	0xc0
196244750Sae	uint8_t			pad2[14];
197244750Sae	uint8_t			VD_Name[16];
198244750Sae} __packed;
19957922Sshin
20057922Sshinstruct ddf_vd_record {
20157922Sshin	uint32_t		Signature;
20257922Sshin#define	DDF_VD_RECORD_SIGNATURE	0xdddddddd
20357922Sshin	uint32_t		CRC;
20457922Sshin	uint16_t		Populated_VDEs;
20557922Sshin	uint16_t		Max_VDE_Supported;
20657922Sshin	uint8_t			pad1[52];
20757922Sshin	struct ddf_vd_entry	entry[0];
20857922Sshin} __packed;
20957922Sshin
21057922Sshin#define DDF_CR_INVALID		0xffffffff
21162589Sitojun
21262589Sitojunstruct ddf_vdc_record {
21362589Sitojun	uint32_t	Signature;
21462589Sitojun#define	DDF_VDCR_SIGNATURE	0xeeeeeeee
21581251Sru	uint32_t	CRC;
21681251Sru	uint8_t		VD_GUID[24];
21757922Sshin	uint32_t	Timestamp;
21862589Sitojun	uint32_t	Sequence_Number;
21962589Sitojun	uint8_t		pad1[24];
22057922Sshin	uint16_t	Primary_Element_Count;
22157922Sshin	uint8_t		Stripe_Size;
22278064Sume	uint8_t		Primary_RAID_Level;
22378064Sume#define DDF_VDCR_RAID0		0x00
22478064Sume#define DDF_VDCR_RAID1		0x01
22578064Sume#define DDF_VDCR_RAID3		0x03
22678064Sume#define DDF_VDCR_RAID4		0x04
22781251Sru#define DDF_VDCR_RAID5		0x05
22878064Sume#define DDF_VDCR_RAID6		0x06
22978064Sume#define DDF_VDCR_RAID1E		0x11
23078064Sume#define DDF_VDCR_SINGLE		0x0f
23178064Sume#define DDF_VDCR_CONCAT		0x1f
23281251Sru#define DDF_VDCR_RAID5E		0x15
23378064Sume#define DDF_VDCR_RAID5EE	0x25
23478064Sume	uint8_t		RLQ;
23578064Sume	uint8_t		Secondary_Element_Count;
23678064Sume	uint8_t		Secondary_Element_Seq;
23778064Sume	uint8_t		Secondary_RAID_Level;
23878064Sume	uint64_t	Block_Count;
23978064Sume	uint64_t	VD_Size;
24078064Sume	uint8_t		pad2[8];
24178064Sume	uint32_t	Associated_Spares[8];
24278064Sume	uint64_t	Cache_Flags;
24357922Sshin#define DDF_VDCR_CACHE_WB		(1 << 0)
24457922Sshin#define	DDF_VDCR_CACHE_WB_ADAPTIVE	(1 << 1)
24557922Sshin#define	DDF_VDCR_CACHE_RA		(1 << 2)
24657922Sshin#define	DDF_VDCR_CACHE_RA_ADAPTIVE	(1 << 3)
24757922Sshin#define	DDF_VDCR_CACHE_WCACHE_NOBATTERY	(1 << 4)
24878064Sume#define	DDF_VDCR_CACHE_WCACHE_ALLOW	(1 << 5)
249224284Sgjb#define	DDF_VDCR_CACHE_RCACHE_ALLOW	(1 << 6)
25057922Sshin#define	DDF_VDCR_CACHE_VENDOR		(1 << 7)
25157922Sshin	uint8_t		BG_Rate;
25257922Sshin	uint8_t		pad3[3];
25378064Sume	uint8_t		pad4[52];
25478064Sume	uint8_t		pad5[192];
25578064Sume	uint8_t		V0[32];
25678064Sume	uint8_t		V1[32];
25757922Sshin	uint8_t		V2[16];
25857922Sshin	uint8_t		V3[16];
25957922Sshin	uint8_t		Vendor_Scratch[32];
26057922Sshin	uint32_t	Physical_Disk_Sequence[0];
26178064Sume} __packed;
26278064Sume
26378064Sumestruct ddf_vuc_record {
26457922Sshin	uint32_t	Signature;
26557922Sshin#define	DDF_VUCR_SIGNATURE	0x88888888
26657922Sshin	uint32_t	CRC;
26757922Sshin	uint8_t		VD_GUID[24];
26857922Sshin} __packed;
26957922Sshin
27078064Sumestruct ddf_sa_entry {
27178064Sume	uint8_t		VD_GUID[24];
27278064Sume	uint16_t	Secondary_Element;
27378064Sume	uint8_t		rsrvd2[6];
27478064Sume} __packed;
27578064Sume
27678064Sumestruct ddf_sa_record {
27778064Sume	uint32_t	Signature;
27878064Sume#define	DDF_SA_SIGNATURE	0x55555555
27978064Sume	uint32_t	CRC;
28078064Sume	uint32_t	Timestamp;
28178064Sume	uint8_t		pad1[7];
28278064Sume	uint8_t		Spare_Type;
28378064Sume#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