1 /* 2 * Copyright (c) 2004-2005 HighPoint Technologies, Inc. 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 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29 #ifndef _ARRAY_H_ 30 #define _ARRAY_H_ 31 32 /* 33 * time represented in DWORD format 34 */ 35 #pragma pack(1) 36 #ifdef __BIG_ENDIAN_BITFIELD 37 typedef DWORD TIME_RECORD; 38 #else 39 typedef struct _TIME_RECORD { 40 UINT seconds:6; /* 0 - 59 */ 41 UINT minutes:6; /* 0 - 59 */ 42 UINT month:4; /* 1 - 12 */ 43 UINT hours:6; /* 0 - 59 */ 44 UINT day:5; /* 1 - 31 */ 45 UINT year:5; /* 0=2000, 31=2031 */ 46 } TIME_RECORD; 47 #endif 48 #pragma pack() 49 50 /*************************************************************************** 51 * Description: Virtual Device Table 52 ***************************************************************************/ 53 54 typedef struct _RaidArray 55 { 56 /* 57 * basic information 58 */ 59 UCHAR bArnMember; /* the number of members in array */ 60 UCHAR bArRealnMember; /* real member count */ 61 UCHAR bArBlockSizeShift; /* the number of shift bit for a block */ 62 UCHAR reserve1; 63 64 ULONG dArStamp; /* array ID. all disks in a array has same ID */ 65 ULONG failedStamps[4]; /* stamp for failed members */ 66 USHORT bStripeWitch; /* = (1 << BlockSizeShift) */ 67 68 USHORT rf_broken: 1; 69 USHORT rf_need_rebuild: 1; /* one member's data are incorrect. 70 for R5, if CriticalMembers==0, it means 71 parity needs to be constructed */ 72 USHORT rf_need_sync: 1; /* need write array info to disk */ 73 /* ioctl flags */ 74 USHORT rf_auto_rebuild: 1; 75 USHORT rf_newly_created: 1; 76 USHORT rf_rebuilding: 1; 77 USHORT rf_verifying: 1; 78 USHORT rf_initializing: 1; 79 USHORT rf_abort_rebuild: 1; 80 USHORT rf_duplicate_and_create: 1; 81 USHORT rf_duplicate_and_created: 1; 82 USHORT rf_duplicate_must_done: 1; 83 USHORT rf_raid15: 1; 84 85 USHORT CriticalMembers; /* tell which member is critial */ 86 UCHAR last_read; /* for RAID 1 load banlancing */ 87 UCHAR alreadyBroken; 88 89 LBA_T RebuildSectors; /* how many sectors is OK (LBA on member disk) */ 90 91 PVDevice pMember[MAX_MEMBERS]; 92 /* 93 * utility working data 94 */ 95 UCHAR ArrayName[MAX_ARRAY_NAME]; /* The Name of the array */ 96 TIME_RECORD CreateTime; /* when created it */ 97 UCHAR Description[64]; /* array description */ 98 UCHAR CreateManager[16]; /* who created it */ 99 } RaidArray; 100 101 /*************************************************************************** 102 * Array Description on disk 103 ***************************************************************************/ 104 #pragma pack(1) 105 typedef struct _ArrayDescript 106 { 107 ULONG Signature; /* This block is vaild array info block */ 108 ULONG dArStamp; /* array ID. all disks in a array has same ID */ 109 110 UCHAR bCheckSum; /* check sum of ArrayDescript_3_0_size bytes */ 111 112 #ifdef __BIG_ENDIAN_BITFIELD 113 UCHAR df_reservedbits: 6; /* put more flags here */ 114 UCHAR df_user_mode_set: 1;/* user select device mode */ 115 UCHAR df_bootmark:1; /* user set boot mark on the disk */ 116 #else 117 UCHAR df_bootmark:1; /* user set boot mark on the disk */ 118 UCHAR df_user_mode_set: 1;/* user select device mode */ 119 UCHAR df_reservedbits: 6; /* put more flags here */ 120 #endif 121 122 UCHAR bUserDeviceMode; /* see device.h */ 123 UCHAR ArrayLevel; /* how many level[] is valid */ 124 125 struct { 126 ULONG Capacity; /* capacity for the array */ 127 128 UCHAR VDeviceType; /* see above & arrayType in array.h */ 129 UCHAR bMemberCount; /* all disk in the array */ 130 UCHAR bSerialNumber; /* Serial Number */ 131 UCHAR bArBlockSizeShift; /* the number of shift bit for a block */ 132 133 #ifdef __BIG_ENDIAN_BITFIELD 134 USHORT rf_reserved: 14; 135 USHORT rf_raid15: 1; /* don't remove even you don't use it */ 136 USHORT rf_need_rebuild:1; /* array is critical */ 137 #else 138 USHORT rf_need_rebuild:1; /* array is critical */ 139 USHORT rf_raid15: 1; /* don't remove even you don't use it */ 140 USHORT rf_reserved: 14; 141 #endif 142 USHORT CriticalMembers; /* record critical members */ 143 ULONG RebuildSectors; /* how many sectors is OK (LBA on member disk) */ 144 } level[2]; 145 146 UCHAR ArrayName[MAX_ARRAY_NAME]; /* The Name of the array */ 147 TIME_RECORD CreateTime; /* when created it */ 148 UCHAR Description[64]; /* array description */ 149 UCHAR CreateManager[16]; /* who created it */ 150 151 #define ArrayDescript_3_0_size ((unsigned)(ULONG_PTR)&((struct _ArrayDescript *)0)->bCheckSum31) 152 #define ArrayDescript_3_1_size 512 153 154 UCHAR bCheckSum31; /* new check sum */ 155 UCHAR PrivateFlag1; /* private */ 156 UCHAR alreadyBroken; /* last stamp has been saved to failedStamps */ 157 158 #ifdef __BIG_ENDIAN_BITFIELD 159 UCHAR df_read_ahead: 1; /* enable read ahead */ 160 UCHAR df_read_ahead_set: 1; 161 UCHAR df_write_cache: 1; /* enable write cache */ 162 UCHAR df_write_cache_set: 1; 163 UCHAR df_ncq: 1; /* enable NCQ */ 164 UCHAR df_ncq_set: 1; 165 UCHAR df_tcq: 1; /* enable TCQ */ 166 UCHAR df_tcq_set: 1; 167 #else 168 UCHAR df_tcq_set: 1; 169 UCHAR df_tcq: 1; /* enable TCQ */ 170 UCHAR df_ncq_set: 1; 171 UCHAR df_ncq: 1; /* enable NCQ */ 172 UCHAR df_write_cache_set: 1; 173 UCHAR df_write_cache: 1; /* enable write cache */ 174 UCHAR df_read_ahead_set: 1; 175 UCHAR df_read_ahead: 1; /* enable read ahead */ 176 #endif 177 178 struct { 179 ULONG CapacityHi32; 180 ULONG RebuildSectorsHi32; 181 } 182 levelex[2]; 183 184 ULONG failedStamps[4]; /* failed memebrs's stamps */ 185 186 } ArrayDescript; 187 188 /* report an error if ArrayDescript size exceed 512 */ 189 typedef char ArrayDescript_size_should_not_exceed_512[512-sizeof(ArrayDescript)]; 190 191 #pragma pack() 192 193 /* Signature */ 194 #define HPT_ARRAY_V3 0x5a7816f3 195 #ifdef ARRAY_V2_ONLY 196 #define SAVE_FOR_RAID_INFO 0 197 #else 198 #define SAVE_FOR_RAID_INFO 10 199 #endif 200 201 /*************************************************************************** 202 * Function protocol for array layer 203 ***************************************************************************/ 204 205 /* 206 * array.c 207 */ 208 ULONG FASTCALL GetStamp(void); 209 void HPTLIBAPI SyncArrayInfo(PVDevice pVDev); 210 void HPTLIBAPI fDeleteArray(_VBUS_ARG PVDevice pVArray, BOOLEAN del_block0); 211 212 /* 213 * iArray.c 214 */ 215 void HPTLIBAPI fCheckArray(PDevice pDevice); 216 void HPTLIBAPI CheckArrayCritical(_VBUS_ARG0); 217 PVDevice HPTLIBAPI GetSpareDisk(_VBUS_ARG PVDevice pArray); 218 #ifdef SUPPORT_OLD_ARRAY 219 void HPTLIBAPI fFixRAID01Stripe(_VBUS_ARG PVDevice pStripe); 220 #endif 221 222 /*************************************************************************** 223 * Macro defination 224 ***************************************************************************/ 225 #ifndef MAX_ARRAY_PER_VBUS 226 #define MAX_ARRAY_PER_VBUS (MAX_VDEVICE_PER_VBUS*2) /* worst case */ 227 #endif 228 229 230 #if defined(MAX_ARRAY_DEVICE) 231 #if MAX_ARRAY_DEVICE!=MAX_ARRAY_PER_VBUS 232 #error "remove MAX_ARRAY_DEVICE and use MAX_ARRAY_PER_VBUS instead" 233 #endif 234 #endif 235 236 #define _SET_ARRAY_BUS_(pArray) pArray->pVBus = _vbus_p; 237 238 #ifdef ARRAY_V2_ONLY 239 #define _SET_ARRAY_VER_(pArray) pArray->vf_format_v2 = 1; 240 #else 241 #define _SET_ARRAY_VER_(pArray) 242 #endif 243 244 #define mArGetArrayTable(pVArray) \ 245 if((pVArray = _vbus_(pFreeArrayLink)) != 0) { \ 246 _vbus_(pFreeArrayLink) = (PVDevice)_vbus_(pFreeArrayLink)->pVBus; \ 247 ZeroMemory(pVArray, ARRAY_VDEV_SIZE); \ 248 _SET_ARRAY_BUS_(pVArray) \ 249 _SET_ARRAY_VER_(pVArray) \ 250 } else 251 252 #define mArFreeArrayTable(pVArray) \ 253 do { \ 254 pVArray->pVBus = (PVBus)_vbus_(pFreeArrayLink);\ 255 _vbus_(pFreeArrayLink) = pVArray; \ 256 pVArray->u.array.dArStamp = 0; \ 257 } while(0) 258 259 UCHAR CheckSum(UCHAR *p, int size); 260 261 void HPTLIBAPI fRAID0SendCommand(_VBUS_ARG PCommand pCmd); 262 void HPTLIBAPI fRAID1SendCommand(_VBUS_ARG PCommand pCmd); 263 void HPTLIBAPI fJBODSendCommand(_VBUS_ARG PCommand pCmd); 264 void HPTLIBAPI fRAID0MemberFailed(_VBUS_ARG PVDevice pVDev); 265 void HPTLIBAPI fRAID1MemberFailed(_VBUS_ARG PVDevice pVDev); 266 void HPTLIBAPI fJBODMemberFailed(_VBUS_ARG PVDevice pVDev); 267 #if SUPPORT_RAID5 268 void HPTLIBAPI fRAID5SendCommand(_VBUS_ARG PCommand pCmd); 269 void HPTLIBAPI fRAID5MemberFailed(_VBUS_ARG PVDevice pVDev); 270 #else 271 #define fRAID5SendCommand 0 272 #define fRAID5MemberFailed 0 273 #endif 274 275 #endif 276