1136849Sscottl/* 2149871Sscottl * Copyright (c) 2004-2005 HighPoint Technologies, Inc. 3136849Sscottl * All rights reserved. 4136849Sscottl * 5136849Sscottl * Redistribution and use in source and binary forms, with or without 6136849Sscottl * modification, are permitted provided that the following conditions 7136849Sscottl * are met: 8136849Sscottl * 1. Redistributions of source code must retain the above copyright 9136849Sscottl * notice, this list of conditions and the following disclaimer. 10136849Sscottl * 2. Redistributions in binary form must reproduce the above copyright 11136849Sscottl * notice, this list of conditions and the following disclaimer in the 12136849Sscottl * documentation and/or other materials provided with the distribution. 13136849Sscottl * 14136849Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15136849Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16136849Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17136849Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18136849Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19136849Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20136849Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21136849Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22136849Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23136849Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24136849Sscottl * SUCH DAMAGE. 25142988Sscottl * 26142988Sscottl * $FreeBSD$ 27136849Sscottl */ 28136849Sscottl 29136849Sscottl#ifndef _ARRAY_H_ 30136849Sscottl#define _ARRAY_H_ 31136849Sscottl 32136849Sscottl/* 33136849Sscottl * time represented in DWORD format 34136849Sscottl */ 35136849Sscottl#pragma pack(1) 36136849Sscottl#ifdef __BIG_ENDIAN_BITFIELD 37136849Sscottltypedef DWORD TIME_RECORD; 38136849Sscottl#else 39136849Sscottltypedef struct _TIME_RECORD { 40136849Sscottl UINT seconds:6; /* 0 - 59 */ 41136849Sscottl UINT minutes:6; /* 0 - 59 */ 42136849Sscottl UINT month:4; /* 1 - 12 */ 43136849Sscottl UINT hours:6; /* 0 - 59 */ 44136849Sscottl UINT day:5; /* 1 - 31 */ 45136849Sscottl UINT year:5; /* 0=2000, 31=2031 */ 46136849Sscottl} TIME_RECORD; 47136849Sscottl#endif 48136849Sscottl#pragma pack() 49136849Sscottl 50136849Sscottl/*************************************************************************** 51136849Sscottl * Description: Virtual Device Table 52136849Sscottl ***************************************************************************/ 53136849Sscottl 54136849Sscottltypedef struct _RaidArray 55136849Sscottl{ 56136849Sscottl /* 57136849Sscottl * basic information 58136849Sscottl */ 59136849Sscottl UCHAR bArnMember; /* the number of members in array */ 60136849Sscottl UCHAR bArRealnMember; /* real member count */ 61136849Sscottl UCHAR bArBlockSizeShift; /* the number of shift bit for a block */ 62136849Sscottl UCHAR reserve1; 63136849Sscottl 64136849Sscottl ULONG dArStamp; /* array ID. all disks in a array has same ID */ 65190809Sdelphij ULONG failedStamps[4]; /* stamp for failed members */ 66136849Sscottl USHORT bStripeWitch; /* = (1 << BlockSizeShift) */ 67136849Sscottl 68136849Sscottl USHORT rf_broken: 1; 69136849Sscottl USHORT rf_need_rebuild: 1; /* one member's data are incorrect. 70136849Sscottl for R5, if CriticalMembers==0, it means 71136849Sscottl parity needs to be constructed */ 72136849Sscottl USHORT rf_need_sync: 1; /* need write array info to disk */ 73136849Sscottl /* ioctl flags */ 74136849Sscottl USHORT rf_auto_rebuild: 1; 75136849Sscottl USHORT rf_newly_created: 1; 76136849Sscottl USHORT rf_rebuilding: 1; 77136849Sscottl USHORT rf_verifying: 1; 78136849Sscottl USHORT rf_initializing: 1; 79136849Sscottl USHORT rf_abort_rebuild: 1; 80136849Sscottl USHORT rf_duplicate_and_create: 1; 81136849Sscottl USHORT rf_duplicate_and_created: 1; 82136849Sscottl USHORT rf_duplicate_must_done: 1; 83136849Sscottl USHORT rf_raid15: 1; 84136849Sscottl 85136849Sscottl USHORT CriticalMembers; /* tell which member is critial */ 86136849Sscottl UCHAR last_read; /* for RAID 1 load banlancing */ 87190809Sdelphij UCHAR alreadyBroken; 88136849Sscottl 89136849Sscottl LBA_T RebuildSectors; /* how many sectors is OK (LBA on member disk) */ 90136849Sscottl 91136849Sscottl PVDevice pMember[MAX_MEMBERS]; 92136849Sscottl /* 93136849Sscottl * utility working data 94136849Sscottl */ 95136849Sscottl UCHAR ArrayName[MAX_ARRAY_NAME]; /* The Name of the array */ 96136849Sscottl TIME_RECORD CreateTime; /* when created it */ 97136849Sscottl UCHAR Description[64]; /* array description */ 98136849Sscottl UCHAR CreateManager[16]; /* who created it */ 99136849Sscottl} RaidArray; 100136849Sscottl 101136849Sscottl/*************************************************************************** 102136849Sscottl * Array Descripton on disk 103136849Sscottl ***************************************************************************/ 104136849Sscottl#pragma pack(1) 105136849Sscottltypedef struct _ArrayDescript 106136849Sscottl{ 107136849Sscottl ULONG Signature; /* This block is vaild array info block */ 108136849Sscottl ULONG dArStamp; /* array ID. all disks in a array has same ID */ 109136849Sscottl 110136849Sscottl UCHAR bCheckSum; /* check sum of ArrayDescript_3_0_size bytes */ 111136849Sscottl 112136849Sscottl#ifdef __BIG_ENDIAN_BITFIELD 113136849Sscottl UCHAR df_reservedbits: 6; /* put more flags here */ 114136849Sscottl UCHAR df_user_mode_set: 1;/* user select device mode */ 115136849Sscottl UCHAR df_bootmark:1; /* user set boot mark on the disk */ 116136849Sscottl#else 117136849Sscottl UCHAR df_bootmark:1; /* user set boot mark on the disk */ 118136849Sscottl UCHAR df_user_mode_set: 1;/* user select device mode */ 119136849Sscottl UCHAR df_reservedbits: 6; /* put more flags here */ 120136849Sscottl#endif 121136849Sscottl 122136849Sscottl UCHAR bUserDeviceMode; /* see device.h */ 123136849Sscottl UCHAR ArrayLevel; /* how many level[] is valid */ 124136849Sscottl 125136849Sscottl struct { 126136849Sscottl ULONG Capacity; /* capacity for the array */ 127136849Sscottl 128136849Sscottl UCHAR VDeviceType; /* see above & arrayType in array.h */ 129136849Sscottl UCHAR bMemberCount; /* all disk in the array */ 130136849Sscottl UCHAR bSerialNumber; /* Serial Number */ 131136849Sscottl UCHAR bArBlockSizeShift; /* the number of shift bit for a block */ 132136849Sscottl 133136849Sscottl#ifdef __BIG_ENDIAN_BITFIELD 134136849Sscottl USHORT rf_reserved: 14; 135136849Sscottl USHORT rf_raid15: 1; /* don't remove even you don't use it */ 136136849Sscottl USHORT rf_need_rebuild:1; /* array is critical */ 137136849Sscottl#else 138136849Sscottl USHORT rf_need_rebuild:1; /* array is critical */ 139136849Sscottl USHORT rf_raid15: 1; /* don't remove even you don't use it */ 140136849Sscottl USHORT rf_reserved: 14; 141136849Sscottl#endif 142136849Sscottl USHORT CriticalMembers; /* record critical members */ 143136849Sscottl ULONG RebuildSectors; /* how many sectors is OK (LBA on member disk) */ 144136849Sscottl } level[2]; 145136849Sscottl 146136849Sscottl UCHAR ArrayName[MAX_ARRAY_NAME]; /* The Name of the array */ 147136849Sscottl TIME_RECORD CreateTime; /* when created it */ 148136849Sscottl UCHAR Description[64]; /* array description */ 149136849Sscottl UCHAR CreateManager[16]; /* who created it */ 150136849Sscottl 151136849Sscottl#define ArrayDescript_3_0_size ((unsigned)(ULONG_PTR)&((struct _ArrayDescript *)0)->bCheckSum31) 152136849Sscottl#define ArrayDescript_3_1_size 512 153136849Sscottl 154136849Sscottl UCHAR bCheckSum31; /* new check sum */ 155190809Sdelphij UCHAR PrivateFlag1; /* private */ 156190809Sdelphij UCHAR alreadyBroken; /* last stamp has been saved to failedStamps */ 157149871Sscottl 158136849Sscottl#ifdef __BIG_ENDIAN_BITFIELD 159136849Sscottl UCHAR df_read_ahead: 1; /* enable read ahead */ 160136849Sscottl UCHAR df_read_ahead_set: 1; 161136849Sscottl UCHAR df_write_cache: 1; /* enable write cache */ 162136849Sscottl UCHAR df_write_cache_set: 1; 163136849Sscottl UCHAR df_ncq: 1; /* enable NCQ */ 164136849Sscottl UCHAR df_ncq_set: 1; 165136849Sscottl UCHAR df_tcq: 1; /* enable TCQ */ 166136849Sscottl UCHAR df_tcq_set: 1; 167136849Sscottl#else 168136849Sscottl UCHAR df_tcq_set: 1; 169136849Sscottl UCHAR df_tcq: 1; /* enable TCQ */ 170136849Sscottl UCHAR df_ncq_set: 1; 171136849Sscottl UCHAR df_ncq: 1; /* enable NCQ */ 172136849Sscottl UCHAR df_write_cache_set: 1; 173136849Sscottl UCHAR df_write_cache: 1; /* enable write cache */ 174136849Sscottl UCHAR df_read_ahead_set: 1; 175136849Sscottl UCHAR df_read_ahead: 1; /* enable read ahead */ 176136849Sscottl#endif 177136849Sscottl 178136849Sscottl struct { 179136849Sscottl ULONG CapacityHi32; 180136849Sscottl ULONG RebuildSectorsHi32; 181136849Sscottl } 182136849Sscottl levelex[2]; 183136849Sscottl 184190809Sdelphij ULONG failedStamps[4]; /* failed memebrs's stamps */ 185149871Sscottl 186136849Sscottl} ArrayDescript; 187136849Sscottl 188149871Sscottl/* report an error if ArrayDescript size exceed 512 */ 189149871Sscottltypedef char ArrayDescript_size_should_not_exceed_512[512-sizeof(ArrayDescript)]; 190149871Sscottl 191136849Sscottl#pragma pack() 192136849Sscottl 193136849Sscottl/* Signature */ 194136849Sscottl#define HPT_ARRAY_V3 0x5a7816f3 195136849Sscottl#ifdef ARRAY_V2_ONLY 196136849Sscottl#define SAVE_FOR_RAID_INFO 0 197136849Sscottl#else 198136849Sscottl#define SAVE_FOR_RAID_INFO 10 199136849Sscottl#endif 200136849Sscottl 201136849Sscottl/*************************************************************************** 202136849Sscottl * Function protocol for array layer 203136849Sscottl ***************************************************************************/ 204136849Sscottl 205136849Sscottl/* 206136849Sscottl * array.c 207136849Sscottl */ 208136849SscottlULONG FASTCALL GetStamp(void); 209136849Sscottlvoid HPTLIBAPI SyncArrayInfo(PVDevice pVDev); 210136849Sscottlvoid HPTLIBAPI fDeleteArray(_VBUS_ARG PVDevice pVArray, BOOLEAN del_block0); 211136849Sscottl 212136849Sscottl/* 213136849Sscottl * iArray.c 214136849Sscottl */ 215136849Sscottlvoid HPTLIBAPI fCheckArray(PDevice pDevice); 216136849Sscottlvoid HPTLIBAPI CheckArrayCritical(_VBUS_ARG0); 217136849SscottlPVDevice HPTLIBAPI GetSpareDisk(_VBUS_ARG PVDevice pArray); 218136849Sscottl#ifdef SUPPORT_OLD_ARRAY 219136849Sscottlvoid HPTLIBAPI fFixRAID01Stripe(_VBUS_ARG PVDevice pStripe); 220136849Sscottl#endif 221136849Sscottl 222136849Sscottl/*************************************************************************** 223136849Sscottl * Macro defination 224136849Sscottl ***************************************************************************/ 225136849Sscottl#ifndef MAX_ARRAY_PER_VBUS 226136849Sscottl#define MAX_ARRAY_PER_VBUS (MAX_VDEVICE_PER_VBUS*2) /* worst case */ 227136849Sscottl#endif 228136849Sscottl 229136849Sscottl 230136849Sscottl#if defined(MAX_ARRAY_DEVICE) 231136849Sscottl#if MAX_ARRAY_DEVICE!=MAX_ARRAY_PER_VBUS 232136849Sscottl#error "remove MAX_ARRAY_DEVICE and use MAX_ARRAY_PER_VBUS instead" 233136849Sscottl#endif 234136849Sscottl#endif 235136849Sscottl 236136849Sscottl#define _SET_ARRAY_BUS_(pArray) pArray->pVBus = _vbus_p; 237136849Sscottl 238136849Sscottl#ifdef ARRAY_V2_ONLY 239136849Sscottl#define _SET_ARRAY_VER_(pArray) pArray->vf_format_v2 = 1; 240136849Sscottl#else 241136849Sscottl#define _SET_ARRAY_VER_(pArray) 242136849Sscottl#endif 243136849Sscottl 244136849Sscottl#define mArGetArrayTable(pVArray) \ 245136849Sscottl if((pVArray = _vbus_(pFreeArrayLink)) != 0) { \ 246136849Sscottl _vbus_(pFreeArrayLink) = (PVDevice)_vbus_(pFreeArrayLink)->pVBus; \ 247136849Sscottl ZeroMemory(pVArray, ARRAY_VDEV_SIZE); \ 248136849Sscottl _SET_ARRAY_BUS_(pVArray) \ 249136849Sscottl _SET_ARRAY_VER_(pVArray) \ 250136849Sscottl } else 251136849Sscottl 252136849Sscottl#define mArFreeArrayTable(pVArray) \ 253136849Sscottl do { \ 254136849Sscottl pVArray->pVBus = (PVBus)_vbus_(pFreeArrayLink);\ 255136849Sscottl _vbus_(pFreeArrayLink) = pVArray; \ 256136849Sscottl pVArray->u.array.dArStamp = 0; \ 257136849Sscottl } while(0) 258136849Sscottl 259136849SscottlUCHAR CheckSum(UCHAR *p, int size); 260136849Sscottl 261136849Sscottlvoid HPTLIBAPI fRAID0SendCommand(_VBUS_ARG PCommand pCmd); 262136849Sscottlvoid HPTLIBAPI fRAID1SendCommand(_VBUS_ARG PCommand pCmd); 263136849Sscottlvoid HPTLIBAPI fJBODSendCommand(_VBUS_ARG PCommand pCmd); 264136849Sscottlvoid HPTLIBAPI fRAID0MemberFailed(_VBUS_ARG PVDevice pVDev); 265136849Sscottlvoid HPTLIBAPI fRAID1MemberFailed(_VBUS_ARG PVDevice pVDev); 266136849Sscottlvoid HPTLIBAPI fJBODMemberFailed(_VBUS_ARG PVDevice pVDev); 267136849Sscottl#if SUPPORT_RAID5 268136849Sscottlvoid HPTLIBAPI fRAID5SendCommand(_VBUS_ARG PCommand pCmd); 269136849Sscottlvoid HPTLIBAPI fRAID5MemberFailed(_VBUS_ARG PVDevice pVDev); 270136849Sscottl#else 271136849Sscottl#define fRAID5SendCommand 0 272136849Sscottl#define fRAID5MemberFailed 0 273136849Sscottl#endif 274136849Sscottl 275136849Sscottl#endif 276