2 * Copyright (c) 2004-2005 HighPoint Technologies, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
33 * time represented in DWORD format
36 #ifdef __BIG_ENDIAN_BITFIELD
37 typedef DWORD TIME_RECORD;
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 */
50 /***************************************************************************
51 * Description: Virtual Device Table
52 ***************************************************************************/
54 typedef struct _RaidArray
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 */
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) */
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 */
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;
85 USHORT CriticalMembers; /* tell which member is critial */
86 UCHAR last_read; /* for RAID 1 load banlancing */
89 LBA_T RebuildSectors; /* how many sectors is OK (LBA on member disk) */
91 PVDevice pMember[MAX_MEMBERS];
93 * utility working data
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 */
101 /***************************************************************************
102 * Array Descripton on disk
103 ***************************************************************************/
105 typedef struct _ArrayDescript
107 ULONG Signature; /* This block is vaild array info block */
108 ULONG dArStamp; /* array ID. all disks in a array has same ID */
110 UCHAR bCheckSum; /* check sum of ArrayDescript_3_0_size bytes */
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 */
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 */
122 UCHAR bUserDeviceMode; /* see device.h */
123 UCHAR ArrayLevel; /* how many level[] is valid */
126 ULONG Capacity; /* capacity for the array */
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 */
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 */
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;
142 USHORT CriticalMembers; /* record critical members */
143 ULONG RebuildSectors; /* how many sectors is OK (LBA on member disk) */
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 */
151 #define ArrayDescript_3_0_size ((unsigned)(ULONG_PTR)&((struct _ArrayDescript *)0)->bCheckSum31)
152 #define ArrayDescript_3_1_size 512
154 UCHAR bCheckSum31; /* new check sum */
155 UCHAR PrivateFlag1; /* private */
156 UCHAR alreadyBroken; /* last stamp has been saved to failedStamps */
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 */
165 UCHAR df_tcq: 1; /* enable TCQ */
169 UCHAR df_tcq: 1; /* enable TCQ */
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 */
180 ULONG RebuildSectorsHi32;
184 ULONG failedStamps[4]; /* failed memebrs's stamps */
188 /* report an error if ArrayDescript size exceed 512 */
189 typedef char ArrayDescript_size_should_not_exceed_512[512-sizeof(ArrayDescript)];
194 #define HPT_ARRAY_V3 0x5a7816f3
196 #define SAVE_FOR_RAID_INFO 0
198 #define SAVE_FOR_RAID_INFO 10
201 /***************************************************************************
202 * Function protocol for array layer
203 ***************************************************************************/
208 ULONG FASTCALL GetStamp(void);
209 void HPTLIBAPI SyncArrayInfo(PVDevice pVDev);
210 void HPTLIBAPI fDeleteArray(_VBUS_ARG PVDevice pVArray, BOOLEAN del_block0);
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);
222 /***************************************************************************
224 ***************************************************************************/
225 #ifndef MAX_ARRAY_PER_VBUS
226 #define MAX_ARRAY_PER_VBUS (MAX_VDEVICE_PER_VBUS*2) /* worst case */
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"
236 #define _SET_ARRAY_BUS_(pArray) pArray->pVBus = _vbus_p;
239 #define _SET_ARRAY_VER_(pArray) pArray->vf_format_v2 = 1;
241 #define _SET_ARRAY_VER_(pArray)
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) \
252 #define mArFreeArrayTable(pVArray) \
254 pVArray->pVBus = (PVBus)_vbus_(pFreeArrayLink);\
255 _vbus_(pFreeArrayLink) = pVArray; \
256 pVArray->u.array.dArStamp = 0; \
259 UCHAR CheckSum(UCHAR *p, int size);
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);
268 void HPTLIBAPI fRAID5SendCommand(_VBUS_ARG PCommand pCmd);
269 void HPTLIBAPI fRAID5MemberFailed(_VBUS_ARG PVDevice pVDev);
271 #define fRAID5SendCommand 0
272 #define fRAID5MemberFailed 0