1147997Srwatson/*- 2155552Srwatson * Copyright (c) 2012 Alexander Motin <mav@FreeBSD.org> 3147997Srwatson * Copyright (c) 2008 Scott Long 4147997Srwatson * All rights reserved. 5147997Srwatson * 6147997Srwatson * Redistribution and use in source and binary forms, with or without 7147997Srwatson * modification, are permitted provided that the following conditions 8147997Srwatson * are met: 9147997Srwatson * 1. Redistributions of source code must retain the above copyright 10147997Srwatson * notice, this list of conditions and the following disclaimer, 11147997Srwatson * without modification, immediately at the beginning of the file. 12147997Srwatson * 2. Redistributions in binary form must reproduce the above copyright 13147997Srwatson * notice, this list of conditions and the following disclaimer in the 14147997Srwatson * documentation and/or other materials provided with the distribution. 15147997Srwatson * 16147997Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17147997Srwatson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18147997Srwatson * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19147997Srwatson * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20147997Srwatson * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21147997Srwatson * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22147997Srwatson * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23147997Srwatson * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24147997Srwatson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25147997Srwatson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26147997Srwatson * 27147997Srwatson * $FreeBSD: releng/10.2/sys/geom/raid/md_ddf.h 234848 2012-04-30 17:53:02Z mav $ 28147997Srwatson */ 29147997Srwatson 30222813Sattilio#ifndef MD_DDF_H 31147997Srwatson#define MD_DDF_H 32147997Srwatson 33148627Srwatson/* Definitions from the SNIA DDF spec, rev 1.2/2.0 */ 34148627Srwatson 35148627Srwatson#define DDF_HEADER_LENGTH 512 36147997Srwatsonstruct ddf_header { 37148627Srwatson uint32_t Signature; 38147997Srwatson#define DDF_HEADER_SIGNATURE 0xde11de11 39147997Srwatson uint32_t CRC; 40147997Srwatson uint8_t DDF_Header_GUID[24]; 41148627Srwatson uint8_t DDF_rev[8]; 42148627Srwatson uint32_t Sequence_Number; 43155550Srwatson uint32_t TimeStamp; 44147997Srwatson uint8_t Open_Flag; 45147997Srwatson#define DDF_HEADER_CLOSED 0x00 46147997Srwatson#define DDF_HEADER_OPENED_MASK 0x0f 47222813Sattilio#define DDF_HEADER_OPEN_ANCHOR 0xff 48147997Srwatson uint8_t Foreign_Flag; 49147997Srwatson uint8_t Diskgrouping; 50147997Srwatson uint8_t pad1[13]; 51147997Srwatson uint8_t Header_ext[32]; 52148627Srwatson uint64_t Primary_Header_LBA; 53148627Srwatson uint64_t Secondary_Header_LBA; 54148627Srwatson uint8_t Header_Type; 55148627Srwatson#define DDF_HEADER_ANCHOR 0x00 56148627Srwatson#define DDF_HEADER_PRIMARY 0x01 57155547Srwatson#define DDF_HEADER_SECONDARY 0x02 58155547Srwatson uint8_t pad2[3]; 59148627Srwatson uint32_t WorkSpace_Length; 60148627Srwatson uint64_t WorkSpace_LBA; 61148627Srwatson uint16_t Max_PD_Entries; 62147997Srwatson uint16_t Max_VD_Entries; 63147997Srwatson uint16_t Max_Partitions; 64147997Srwatson uint16_t Configuration_Record_Length; 65147997Srwatson uint16_t Max_Primary_Element_Entries; 66147997Srwatson uint32_t Max_Mapped_Block_Entries; /* DDF 2.0 */ 67147997Srwatson uint8_t pad3[50]; 68147997Srwatson uint32_t cd_section; /* Controller_Data_Section */ 69147997Srwatson uint32_t cd_length; /* Controller_Data_Section_Length */ 70147997Srwatson uint32_t pdr_section; /* Physical_Drive_Records_Section */ 71147997Srwatson uint32_t pdr_length; /* Physical_Drive_Records_Length */ 72147997Srwatson uint32_t vdr_section; /* Virtual_Drive_Records_Section */ 73147997Srwatson uint32_t vdr_length; /* Virtual_Drive_Records_Length */ 74147997Srwatson uint32_t cr_section; /* Configuration_Records_Section */ 75147997Srwatson uint32_t cr_length; /* Configuration_Records_Length */ 76147997Srwatson uint32_t pdd_section; /* Physical_Drive_Data_Section */ 77147997Srwatson uint32_t pdd_length; /* Physical_Drive_Data_Length */ 78147997Srwatson uint32_t bbmlog_section; /* BBM_Log_Section */ 79147997Srwatson uint32_t bbmlog_length; /* BBM_Log_Section_Length */ 80147997Srwatson uint32_t Diagnostic_Space; 81224569Spluknet uint32_t Diagnostic_Space_Length; 82147997Srwatson uint32_t Vendor_Specific_Logs; 83147997Srwatson uint32_t Vendor_Specific_Logs_Length; 84147997Srwatson uint8_t pad4[256]; 85148357Srwatson} __packed; 86147997Srwatson 87147997Srwatsonstruct ddf_cd_record { 88147997Srwatson uint32_t Signature; 89147997Srwatson#define DDF_CONTROLLER_DATA_SIGNATURE 0xad111111 90147997Srwatson uint32_t CRC; 91147997Srwatson uint8_t Controller_GUID[24]; 92147997Srwatson struct { 93147997Srwatson uint16_t Vendor_ID; 94147997Srwatson uint16_t Device_ID; 95224569Spluknet uint16_t SubVendor_ID; 96224569Spluknet uint16_t SubDevice_ID; 97148357Srwatson } Controller_Type __packed; 98148357Srwatson uint8_t Product_ID[16]; 99148357Srwatson uint8_t pad1[8]; 100148357Srwatson uint8_t Controller_Data[448]; 101147997Srwatson} __packed; 102147997Srwatson 103224569Spluknetstruct ddf_device_scsi { 104148357Srwatson uint8_t Lun; 105147997Srwatson uint8_t Id; 106147997Srwatson uint8_t Channel; 107147997Srwatson uint8_t Path_Flags; 108147997Srwatson#define DDF_DEVICE_SCSI_FLAG_BROKEN (1 << 7) 109147997Srwatson} __packed; 110148357Srwatson 111148357Srwatsonstruct ddf_device_sas { 112148357Srwatson uint64_t Initiator_Path; 113148357Srwatson} __packed; 114147997Srwatson 115147997Srwatsonunion ddf_pathinfo { 116147997Srwatson struct { 117148357Srwatson struct ddf_device_scsi Path0; 118147997Srwatson struct ddf_device_scsi Path1; 119147997Srwatson uint8_t pad[10]; 120147997Srwatson } __packed scsi; 121147997Srwatson struct { 122224569Spluknet struct ddf_device_sas Path0; 123147997Srwatson struct ddf_device_sas Path1; 124147997Srwatson uint8_t Path0_Flags; 125147997Srwatson uint8_t Path1_Flags; 126148357Srwatson#define DDF_DEVICE_SAS_PHY_ID 0x7f 127147997Srwatson#define DDF_DEVICE_SAS_FLAG_BROKEN (1 << 7) 128147997Srwatson } __packed sas; 129147997Srwatson} __packed; 130147997Srwatson 131147997Srwatsonstruct ddf_pd_entry { 132147997Srwatson uint8_t PD_GUID[24]; 133147997Srwatson uint32_t PD_Reference; 134147997Srwatson uint16_t PD_Type; 135147997Srwatson#define DDF_PDE_GUID_FORCE (1 << 0) 136147997Srwatson#define DDF_PDE_PARTICIPATING (1 << 1) 137147997Srwatson#define DDF_PDE_GLOBAL_SPARE (1 << 2) 138147997Srwatson#define DDF_PDE_CONFIG_SPARE (1 << 3) 139148357Srwatson#define DDF_PDE_FOREIGN (1 << 4) 140148357Srwatson#define DDF_PDE_LEGACY (1 << 5) 141148357Srwatson#define DDF_PDE_TYPE_MASK (0x0f << 12) 142148357Srwatson#define DDF_PDE_UNKNOWN (0x00 << 12) 143147997Srwatson#define DDF_PDE_SCSI (0x01 << 12) 144147997Srwatson#define DDF_PDE_SAS (0x02 << 12) 145147997Srwatson#define DDF_PDE_SATA (0x03 << 12) 146147997Srwatson#define DDF_PDE_FC (0x04 << 12) 147147997Srwatson uint16_t PD_State; 148147997Srwatson#define DDF_PDE_ONLINE (1 << 0) 149147997Srwatson#define DDF_PDE_FAILED (1 << 1) 150147997Srwatson#define DDF_PDE_REBUILD (1 << 2) 151147997Srwatson#define DDF_PDE_TRANSITION (1 << 3) 152147997Srwatson#define DDF_PDE_PFA (1 << 4) 153148357Srwatson#define DDF_PDE_UNRECOVERED (1 << 5) 154147997Srwatson#define DDF_PDE_MISSING (1 << 6) 155147997Srwatson uint64_t Configured_Size; 156147997Srwatson union ddf_pathinfo Path_Information; 157147997Srwatson uint16_t Block_Size; /* DDF 2.0 */ 158147997Srwatson uint8_t pad1[4]; 159147997Srwatson} __packed; 160147997Srwatson 161147997Srwatsonstruct ddf_pd_record { 162148357Srwatson uint32_t Signature; 163147997Srwatson#define DDF_PDR_SIGNATURE 0x22222222 164147997Srwatson uint32_t CRC; 165147997Srwatson uint16_t Populated_PDEs; 166147997Srwatson uint16_t Max_PDE_Supported; 167147997Srwatson uint8_t pad1[52]; 168147997Srwatson struct ddf_pd_entry entry[0]; 169147997Srwatson} __packed; 170147997Srwatson 171147997Srwatsonstruct ddf_vd_entry { 172147997Srwatson uint8_t VD_GUID[24]; 173147997Srwatson uint16_t VD_Number; 174147997Srwatson uint8_t pad1[2]; 175147997Srwatson uint16_t VD_Type; 176147997Srwatson#define DDF_VDE_SHARED (1 << 0) 177147997Srwatson#define DDF_VDE_ENFORCE_GROUP (1 << 1) 178147997Srwatson#define DDF_VDE_UNICODE_NAME (1 << 2) 179147997Srwatson#define DDF_VDE_OWNER_ID_VALID (1 << 3) 180147997Srwatson uint16_t Controller_GUID_CRC; 181147997Srwatson uint8_t VD_State; 182147997Srwatson#define DDF_VDE_OPTIMAL 0x00 183147997Srwatson#define DDF_VDE_DEGRADED 0x01 184148354Srwatson#define DDF_VDE_DELETED 0x02 185224569Spluknet#define DDF_VDE_MISSING 0x03 186147997Srwatson#define DDF_VDE_FAILED 0x04 187148619Srwatson#define DDF_VDE_PARTIAL 0x05 188147997Srwatson#define DDF_VDE_OFFLINE 0x06 189148357Srwatson#define DDF_VDE_STATE_MASK 0x07 190147997Srwatson#define DDF_VDE_MORPH (1 << 3) 191147997Srwatson#define DDF_VDE_DIRTY (1 << 4) 192147997Srwatson uint8_t Init_State; 193147997Srwatson#define DDF_VDE_UNINTIALIZED 0x00 194147997Srwatson#define DDF_VDE_INIT_QUICK 0x01 195147997Srwatson#define DDF_VDE_INIT_FULL 0x02 196224569Spluknet#define DDF_VDE_INIT_MASK 0x03 197147997Srwatson#define DDF_VDE_UACCESS_RW 0x00 198148007Srwatson#define DDF_VDE_UACCESS_RO 0x80 199148007Srwatson#define DDF_VDE_UACCESS_BLOCKED 0xc0 200148071Srwatson#define DDF_VDE_UACCESS_MASK 0xc0 201209215Ssbruno uint8_t Drive_Failures_Remaining; /* DDF 2.0 */ 202148007Srwatson uint8_t pad2[13]; 203147997Srwatson uint8_t VD_Name[16]; 204147997Srwatson} __packed; 205147997Srwatson 206147997Srwatsonstruct ddf_vd_record { 207147997Srwatson uint32_t Signature; 208147997Srwatson#define DDF_VD_RECORD_SIGNATURE 0xdddddddd 209147997Srwatson uint32_t CRC; 210147997Srwatson uint16_t Populated_VDEs; 211147997Srwatson uint16_t Max_VDE_Supported; 212147997Srwatson uint8_t pad1[52]; 213147997Srwatson struct ddf_vd_entry entry[0]; 214147997Srwatson} __packed; 215148007Srwatson 216148007Srwatson#define DDF_CR_INVALID 0xffffffff 217147997Srwatson 218147997Srwatsonstruct ddf_vdc_record { 219147997Srwatson uint32_t Signature; 220147997Srwatson#define DDF_VDCR_SIGNATURE 0xeeeeeeee 221147997Srwatson uint32_t CRC; 222148170Srwatson uint8_t VD_GUID[24]; 223148381Srwatson uint32_t Timestamp; 224148381Srwatson uint32_t Sequence_Number; 225148381Srwatson uint8_t pad1[24]; 226148381Srwatson uint16_t Primary_Element_Count; 227148381Srwatson uint8_t Stripe_Size; 228148381Srwatson uint8_t Primary_RAID_Level; 229148381Srwatson#define DDF_VDCR_RAID0 0x00 230148619Srwatson#define DDF_VDCR_RAID1 0x01 231148381Srwatson#define DDF_VDCR_RAID3 0x03 232148381Srwatson#define DDF_VDCR_RAID4 0x04 233147997Srwatson#define DDF_VDCR_RAID5 0x05 234147997Srwatson#define DDF_VDCR_RAID6 0x06 235147997Srwatson#define DDF_VDCR_RAID1E 0x11 236147997Srwatson#define DDF_VDCR_SINGLE 0x0f 237147997Srwatson#define DDF_VDCR_CONCAT 0x1f 238147997Srwatson#define DDF_VDCR_RAID5E 0x15 239147997Srwatson#define DDF_VDCR_RAID5EE 0x25 240148627Srwatson uint8_t RLQ; 241148627Srwatson uint8_t Secondary_Element_Count; 242148627Srwatson uint8_t Secondary_Element_Seq; 243148627Srwatson uint8_t Secondary_RAID_Level; 244148627Srwatson uint64_t Block_Count; 245148627Srwatson uint64_t VD_Size; 246148627Srwatson uint16_t Block_Size; /* DDF 2.0 */ 247148627Srwatson uint8_t Rotate_Parity_count; /* DDF 2.0 */ 248148627Srwatson uint8_t pad2[5]; 249148627Srwatson uint32_t Associated_Spares[8]; 250148627Srwatson uint64_t Cache_Flags; 251148627Srwatson#define DDF_VDCR_CACHE_WB (1 << 0) 252148627Srwatson#define DDF_VDCR_CACHE_WB_ADAPTIVE (1 << 1) 253148627Srwatson#define DDF_VDCR_CACHE_RA (1 << 2) 254148627Srwatson#define DDF_VDCR_CACHE_RA_ADAPTIVE (1 << 3) 255148627Srwatson#define DDF_VDCR_CACHE_WCACHE_NOBATTERY (1 << 4) 256148627Srwatson#define DDF_VDCR_CACHE_WCACHE_ALLOW (1 << 5) 257242152Smdf#define DDF_VDCR_CACHE_RCACHE_ALLOW (1 << 6) 258148627Srwatson#define DDF_VDCR_CACHE_VENDOR (1 << 7) 259148627Srwatson uint8_t BG_Rate; 260148627Srwatson uint8_t pad3[3]; 261148627Srwatson uint8_t MDF_Parity_Disks; /* DDF 2.0 */ 262148627Srwatson uint16_t MDF_Parity_Generator_Polynomial; /* DDF 2.0 */ 263148627Srwatson uint8_t pad4; 264148627Srwatson uint8_t MDF_Constant_Generation_Method; /* DDF 2.0 */ 265148627Srwatson uint8_t pad5[47]; 266148627Srwatson uint8_t pad6[192]; 267148627Srwatson uint8_t V0[32]; 268148627Srwatson uint8_t V1[32]; 269148627Srwatson uint8_t V2[16]; 270148627Srwatson uint8_t V3[16]; 271148627Srwatson uint8_t Vendor_Scratch[32]; 272148627Srwatson uint32_t Physical_Disk_Sequence[0]; 273148627Srwatson} __packed; 274148627Srwatson 275148627Srwatsonstruct ddf_vuc_record { 276148627Srwatson uint32_t Signature; 277148627Srwatson#define DDF_VUCR_SIGNATURE 0x88888888 278148627Srwatson uint32_t CRC; 279148627Srwatson uint8_t VD_GUID[24]; 280148627Srwatson} __packed; 281148627Srwatson 282148627Srwatsonstruct ddf_sa_entry { 283148627Srwatson uint8_t VD_GUID[24]; 284148627Srwatson uint16_t Secondary_Element; 285148627Srwatson uint8_t rsrvd2[6]; 286148627Srwatson} __packed; 287148627Srwatson 288148627Srwatsonstruct ddf_sa_record { 289148627Srwatson uint32_t Signature; 290148627Srwatson#define DDF_SA_SIGNATURE 0x55555555 291148627Srwatson uint32_t CRC; 292148627Srwatson uint32_t Timestamp; 293148627Srwatson uint8_t pad1[7]; 294148627Srwatson uint8_t Spare_Type; 295148627Srwatson#define DDF_SAR_TYPE_DEDICATED (1 << 0) 296148627Srwatson#define DDF_SAR_TYPE_REVERTIBLE (1 << 1) 297148627Srwatson#define DDF_SAR_TYPE_ACTIVE (1 << 2) 298154416Srwatson#define DDF_SAR_TYPE_ENCL_AFFINITY (1 << 3) 299148627Srwatson uint16_t Populated_SAEs; 300148627Srwatson uint16_t MAX_SAE_Supported; 301155550Srwatson uint8_t pad2[8]; 302148627Srwatson struct ddf_sa_entry entry[0]; 303148627Srwatson} __packed; 304148627Srwatson 305148627Srwatsonstruct ddf_pdd_record { 306222813Sattilio uint32_t Signature; 307222813Sattilio#define DDF_PDD_SIGNATURE 0x33333333 308148627Srwatson uint32_t CRC; 309148627Srwatson uint8_t PD_GUID[24]; 310148627Srwatson uint32_t PD_Reference; 311148627Srwatson uint8_t Forced_Ref_Flag; 312148627Srwatson#define DDF_PDD_FORCED_REF 0x01 313148627Srwatson uint8_t Forced_PD_GUID_Flag; 314148627Srwatson#define DDF_PDD_FORCED_GUID 0x01 315148627Srwatson uint8_t Vendor_Scratch[32]; 316148627Srwatson uint8_t pad2[442]; 317148627Srwatson} __packed; 318148627Srwatson 319148627Srwatsonstruct ddf_bbm_entry { 320148627Srwatson uint64_t Defective_Block_Start; 321148627Srwatson uint32_t Spare_Block_Offset; 322148627Srwatson uint16_t Remapped_Count; 323148627Srwatson uint8_t pad[2]; 324148627Srwatson}; 325148627Srwatson 326148627Srwatsonstruct ddf_bbm_log { 327148627Srwatson uint32_t Signature; 328148627Srwatson#define DDF_BBML_SIGNATURE 0xabadb10c 329148627Srwatson uint32_t CRC; 330148627Srwatson uint32_t Entry_Count; 331222813Sattilio uint32_t Spare_Block_Count; 332222813Sattilio uint8_t pad1[8]; 333222813Sattilio uint64_t First_Spare_LBA; 334222813Sattilio uint64_t Mapped_Block_Entry[0]; 335222813Sattilio} __packed; 336222813Sattilio 337222813Sattiliostruct ddf_vendor_log { 338155547Srwatson uint32_t Signature; 339155547Srwatson#define DDF_VENDOR_LOG_SIGNATURE 0x01dbeef0 340155547Srwatson uint32_t CRC; 341155547Srwatson uint64_t Log_Owner; 342155550Srwatson uint8_t pad1[16]; 343155550Srwatson} __packed; 344155550Srwatson 345155550Srwatson#endif 346155550Srwatson