1 /* 2 * Copyright (c) 2003-2004 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 27 #ifndef _ARRAY_H_ 28 #define _ARRAY_H_ 29 30 /* 31 * time represented in DWORD format 32 */ 33 #pragma pack(1) 34 #ifdef __BIG_ENDIAN_BITFIELD 35 typedef DWORD TIME_RECORD; 36 #else 37 typedef struct _TIME_RECORD { 38 UINT seconds:6; /* 0 - 59 */ 39 UINT minutes:6; /* 0 - 59 */ 40 UINT month:4; /* 1 - 12 */ 41 UINT hours:6; /* 0 - 59 */ 42 UINT day:5; /* 1 - 31 */ 43 UINT year:5; /* 0=2000, 31=2031 */ 44 } TIME_RECORD; 45 #endif 46 #pragma pack() 47 48 /*************************************************************************** 49 * Description: Virtual Device Table 50 ***************************************************************************/ 51 52 typedef struct _RaidArray 53 { 54 /* 55 * basic information 56 */ 57 UCHAR bArnMember; /* the number of members in array */ 58 UCHAR bArRealnMember; /* real member count */ 59 UCHAR bArBlockSizeShift; /* the number of shift bit for a block */ 60 UCHAR reserve1; 61 62 ULONG dArStamp; /* array ID. all disks in a array has same ID */ 63 USHORT bStripeWitch; /* = (1 << BlockSizeShift) */ 64 65 USHORT rf_broken: 1; 66 USHORT rf_need_rebuild: 1; /* one member's data are incorrect. 67 for R5, if CriticalMembers==0, it means 68 parity needs to be constructed */ 69 USHORT rf_need_sync: 1; /* need write array info to disk */ 70 /* ioctl flags */ 71 USHORT rf_auto_rebuild: 1; 72 USHORT rf_newly_created: 1; 73 USHORT rf_rebuilding: 1; 74 USHORT rf_verifying: 1; 75 USHORT rf_initializing: 1; 76 USHORT rf_abort_rebuild: 1; 77 USHORT rf_duplicate_and_create: 1; 78 USHORT rf_duplicate_and_created: 1; 79 USHORT rf_duplicate_must_done: 1; 80 USHORT rf_raid15: 1; 81 82 USHORT CriticalMembers; /* tell which member is critial */ 83 UCHAR last_read; /* for RAID 1 load banlancing */ 84 UCHAR pad1; 85 86 LBA_T RebuildSectors; /* how many sectors is OK (LBA on member disk) */ 87 88 PVDevice pMember[MAX_MEMBERS]; 89 /* 90 * utility working data 91 */ 92 UCHAR ArrayName[MAX_ARRAY_NAME]; /* The Name of the array */ 93 TIME_RECORD CreateTime; /* when created it */ 94 UCHAR Description[64]; /* array description */ 95 UCHAR CreateManager[16]; /* who created it */ 96 } RaidArray; 97 98 /*************************************************************************** 99 * Array Descripton on disk 100 ***************************************************************************/ 101 #pragma pack(1) 102 typedef struct _ArrayDescript 103 { 104 ULONG Signature; /* This block is vaild array info block */ 105 ULONG dArStamp; /* array ID. all disks in a array has same ID */ 106 107 UCHAR bCheckSum; /* check sum of ArrayDescript_3_0_size bytes */ 108 109 #ifdef __BIG_ENDIAN_BITFIELD 110 UCHAR df_reservedbits: 6; /* put more flags here */ 111 UCHAR df_user_mode_set: 1;/* user select device mode */ 112 UCHAR df_bootmark:1; /* user set boot mark on the disk */ 113 #else 114 UCHAR df_bootmark:1; /* user set boot mark on the disk */ 115 UCHAR df_user_mode_set: 1;/* user select device mode */ 116 UCHAR df_reservedbits: 6; /* put more flags here */ 117 #endif 118 119 UCHAR bUserDeviceMode; /* see device.h */ 120 UCHAR ArrayLevel; /* how many level[] is valid */ 121 122 struct { 123 ULONG Capacity; /* capacity for the array */ 124 125 UCHAR VDeviceType; /* see above & arrayType in array.h */ 126 UCHAR bMemberCount; /* all disk in the array */ 127 UCHAR bSerialNumber; /* Serial Number */ 128 UCHAR bArBlockSizeShift; /* the number of shift bit for a block */ 129 130 #ifdef __BIG_ENDIAN_BITFIELD 131 USHORT rf_reserved: 14; 132 USHORT rf_raid15: 1; /* don't remove even you don't use it */ 133 USHORT rf_need_rebuild:1; /* array is critical */ 134 #else 135 USHORT rf_need_rebuild:1; /* array is critical */ 136 USHORT rf_raid15: 1; /* don't remove even you don't use it */ 137 USHORT rf_reserved: 14; 138 #endif 139 USHORT CriticalMembers; /* record critical members */ 140 ULONG RebuildSectors; /* how many sectors is OK (LBA on member disk) */ 141 } level[2]; 142 143 UCHAR ArrayName[MAX_ARRAY_NAME]; /* The Name of the array */ 144 TIME_RECORD CreateTime; /* when created it */ 145 UCHAR Description[64]; /* array description */ 146 UCHAR CreateManager[16]; /* who created it */ 147 148 #define ArrayDescript_3_0_size ((unsigned)(ULONG_PTR)&((struct _ArrayDescript *)0)->bCheckSum31) 149 #define ArrayDescript_3_1_size 512 150 151 UCHAR bCheckSum31; /* new check sum */ 152 UCHAR reserve2[2]; 153 #ifdef __BIG_ENDIAN_BITFIELD 154 UCHAR df_read_ahead: 1; /* enable read ahead */ 155 UCHAR df_read_ahead_set: 1; 156 UCHAR df_write_cache: 1; /* enable write cache */ 157 UCHAR df_write_cache_set: 1; 158 UCHAR df_ncq: 1; /* enable NCQ */ 159 UCHAR df_ncq_set: 1; 160 UCHAR df_tcq: 1; /* enable TCQ */ 161 UCHAR df_tcq_set: 1; 162 #else 163 UCHAR df_tcq_set: 1; 164 UCHAR df_tcq: 1; /* enable TCQ */ 165 UCHAR df_ncq_set: 1; 166 UCHAR df_ncq: 1; /* enable NCQ */ 167 UCHAR df_write_cache_set: 1; 168 UCHAR df_write_cache: 1; /* enable write cache */ 169 UCHAR df_read_ahead_set: 1; 170 UCHAR df_read_ahead: 1; /* enable read ahead */ 171 #endif 172 173 struct { 174 ULONG CapacityHi32; 175 ULONG RebuildSectorsHi32; 176 } 177 levelex[2]; 178 179 } ArrayDescript; 180 181 #pragma pack() 182 183 /* Signature */ 184 #define HPT_ARRAY_V3 0x5a7816f3 185 #ifdef ARRAY_V2_ONLY 186 #define SAVE_FOR_RAID_INFO 0 187 #else 188 #define SAVE_FOR_RAID_INFO 10 189 #endif 190 191 /*************************************************************************** 192 * Function protocol for array layer 193 ***************************************************************************/ 194 195 /* 196 * array.c 197 */ 198 ULONG FASTCALL GetStamp(void); 199 void HPTLIBAPI SyncArrayInfo(PVDevice pVDev); 200 void HPTLIBAPI fDeleteArray(_VBUS_ARG PVDevice pVArray, BOOLEAN del_block0); 201 202 /* 203 * iArray.c 204 */ 205 void HPTLIBAPI fCheckArray(PDevice pDevice); 206 void HPTLIBAPI CheckArrayCritical(_VBUS_ARG0); 207 PVDevice HPTLIBAPI GetSpareDisk(_VBUS_ARG PVDevice pArray); 208 #ifdef SUPPORT_OLD_ARRAY 209 void HPTLIBAPI fFixRAID01Stripe(_VBUS_ARG PVDevice pStripe); 210 #endif 211 212 /*************************************************************************** 213 * Macro defination 214 ***************************************************************************/ 215 #ifndef MAX_ARRAY_PER_VBUS 216 #define MAX_ARRAY_PER_VBUS (MAX_VDEVICE_PER_VBUS*2) /* worst case */ 217 #endif 218 219 220 #if defined(MAX_ARRAY_DEVICE) 221 #if MAX_ARRAY_DEVICE!=MAX_ARRAY_PER_VBUS 222 #error "remove MAX_ARRAY_DEVICE and use MAX_ARRAY_PER_VBUS instead" 223 #endif 224 #endif 225 226 #define _SET_ARRAY_BUS_(pArray) pArray->pVBus = _vbus_p; 227 228 #ifdef ARRAY_V2_ONLY 229 #define _SET_ARRAY_VER_(pArray) pArray->vf_format_v2 = 1; 230 #else 231 #define _SET_ARRAY_VER_(pArray) 232 #endif 233 234 #define mArGetArrayTable(pVArray) \ 235 if((pVArray = _vbus_(pFreeArrayLink)) != 0) { \ 236 _vbus_(pFreeArrayLink) = (PVDevice)_vbus_(pFreeArrayLink)->pVBus; \ 237 ZeroMemory(pVArray, ARRAY_VDEV_SIZE); \ 238 _SET_ARRAY_BUS_(pVArray) \ 239 _SET_ARRAY_VER_(pVArray) \ 240 } else 241 242 #define mArFreeArrayTable(pVArray) \ 243 do { \ 244 pVArray->pVBus = (PVBus)_vbus_(pFreeArrayLink);\ 245 _vbus_(pFreeArrayLink) = pVArray; \ 246 pVArray->u.array.dArStamp = 0; \ 247 } while(0) 248 249 UCHAR CheckSum(UCHAR *p, int size); 250 251 void HPTLIBAPI fRAID0SendCommand(_VBUS_ARG PCommand pCmd); 252 void HPTLIBAPI fRAID1SendCommand(_VBUS_ARG PCommand pCmd); 253 void HPTLIBAPI fJBODSendCommand(_VBUS_ARG PCommand pCmd); 254 void HPTLIBAPI fRAID0MemberFailed(_VBUS_ARG PVDevice pVDev); 255 void HPTLIBAPI fRAID1MemberFailed(_VBUS_ARG PVDevice pVDev); 256 void HPTLIBAPI fJBODMemberFailed(_VBUS_ARG PVDevice pVDev); 257 #if SUPPORT_RAID5 258 void HPTLIBAPI fRAID5SendCommand(_VBUS_ARG PCommand pCmd); 259 void HPTLIBAPI fRAID5MemberFailed(_VBUS_ARG PVDevice pVDev); 260 #else 261 #define fRAID5SendCommand 0 262 #define fRAID5MemberFailed 0 263 #endif 264 265 #endif 266