2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2004-2005 HighPoint Technologies, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * time represented in DWORD format
38 #ifdef __BIG_ENDIAN_BITFIELD
39 typedef DWORD TIME_RECORD;
41 typedef struct _TIME_RECORD {
42 UINT seconds:6; /* 0 - 59 */
43 UINT minutes:6; /* 0 - 59 */
44 UINT month:4; /* 1 - 12 */
45 UINT hours:6; /* 0 - 59 */
46 UINT day:5; /* 1 - 31 */
47 UINT year:5; /* 0=2000, 31=2031 */
52 /***************************************************************************
53 * Description: Virtual Device Table
54 ***************************************************************************/
56 typedef struct _RaidArray
61 UCHAR bArnMember; /* the number of members in array */
62 UCHAR bArRealnMember; /* real member count */
63 UCHAR bArBlockSizeShift; /* the number of shift bit for a block */
66 ULONG dArStamp; /* array ID. all disks in a array has same ID */
67 ULONG failedStamps[4]; /* stamp for failed members */
68 USHORT bStripeWitch; /* = (1 << BlockSizeShift) */
71 USHORT rf_need_rebuild: 1; /* one member's data are incorrect.
72 for R5, if CriticalMembers==0, it means
73 parity needs to be constructed */
74 USHORT rf_need_sync: 1; /* need write array info to disk */
76 USHORT rf_auto_rebuild: 1;
77 USHORT rf_newly_created: 1;
78 USHORT rf_rebuilding: 1;
79 USHORT rf_verifying: 1;
80 USHORT rf_initializing: 1;
81 USHORT rf_abort_rebuild: 1;
82 USHORT rf_duplicate_and_create: 1;
83 USHORT rf_duplicate_and_created: 1;
84 USHORT rf_duplicate_must_done: 1;
87 USHORT CriticalMembers; /* tell which member is critial */
88 UCHAR last_read; /* for RAID 1 load banlancing */
91 LBA_T RebuildSectors; /* how many sectors is OK (LBA on member disk) */
93 PVDevice pMember[MAX_MEMBERS];
95 * utility working data
97 UCHAR ArrayName[MAX_ARRAY_NAME]; /* The Name of the array */
98 TIME_RECORD CreateTime; /* when created it */
99 UCHAR Description[64]; /* array description */
100 UCHAR CreateManager[16]; /* who created it */
103 /***************************************************************************
104 * Array Description on disk
105 ***************************************************************************/
107 typedef struct _ArrayDescript
109 ULONG Signature; /* This block is vaild array info block */
110 ULONG dArStamp; /* array ID. all disks in a array has same ID */
112 UCHAR bCheckSum; /* check sum of ArrayDescript_3_0_size bytes */
114 #ifdef __BIG_ENDIAN_BITFIELD
115 UCHAR df_reservedbits: 6; /* put more flags here */
116 UCHAR df_user_mode_set: 1;/* user select device mode */
117 UCHAR df_bootmark:1; /* user set boot mark on the disk */
119 UCHAR df_bootmark:1; /* user set boot mark on the disk */
120 UCHAR df_user_mode_set: 1;/* user select device mode */
121 UCHAR df_reservedbits: 6; /* put more flags here */
124 UCHAR bUserDeviceMode; /* see device.h */
125 UCHAR ArrayLevel; /* how many level[] is valid */
128 ULONG Capacity; /* capacity for the array */
130 UCHAR VDeviceType; /* see above & arrayType in array.h */
131 UCHAR bMemberCount; /* all disk in the array */
132 UCHAR bSerialNumber; /* Serial Number */
133 UCHAR bArBlockSizeShift; /* the number of shift bit for a block */
135 #ifdef __BIG_ENDIAN_BITFIELD
136 USHORT rf_reserved: 14;
137 USHORT rf_raid15: 1; /* don't remove even you don't use it */
138 USHORT rf_need_rebuild:1; /* array is critical */
140 USHORT rf_need_rebuild:1; /* array is critical */
141 USHORT rf_raid15: 1; /* don't remove even you don't use it */
142 USHORT rf_reserved: 14;
144 USHORT CriticalMembers; /* record critical members */
145 ULONG RebuildSectors; /* how many sectors is OK (LBA on member disk) */
148 UCHAR ArrayName[MAX_ARRAY_NAME]; /* The Name of the array */
149 TIME_RECORD CreateTime; /* when created it */
150 UCHAR Description[64]; /* array description */
151 UCHAR CreateManager[16]; /* who created it */
153 #define ArrayDescript_3_0_size ((unsigned)(ULONG_PTR)&((struct _ArrayDescript *)0)->bCheckSum31)
154 #define ArrayDescript_3_1_size 512
156 UCHAR bCheckSum31; /* new check sum */
157 UCHAR PrivateFlag1; /* private */
158 UCHAR alreadyBroken; /* last stamp has been saved to failedStamps */
160 #ifdef __BIG_ENDIAN_BITFIELD
161 UCHAR df_read_ahead: 1; /* enable read ahead */
162 UCHAR df_read_ahead_set: 1;
163 UCHAR df_write_cache: 1; /* enable write cache */
164 UCHAR df_write_cache_set: 1;
165 UCHAR df_ncq: 1; /* enable NCQ */
167 UCHAR df_tcq: 1; /* enable TCQ */
171 UCHAR df_tcq: 1; /* enable TCQ */
173 UCHAR df_ncq: 1; /* enable NCQ */
174 UCHAR df_write_cache_set: 1;
175 UCHAR df_write_cache: 1; /* enable write cache */
176 UCHAR df_read_ahead_set: 1;
177 UCHAR df_read_ahead: 1; /* enable read ahead */
182 ULONG RebuildSectorsHi32;
186 ULONG failedStamps[4]; /* failed memebrs's stamps */
190 /* report an error if ArrayDescript size exceed 512 */
191 typedef char ArrayDescript_size_should_not_exceed_512[512-sizeof(ArrayDescript)];
196 #define HPT_ARRAY_V3 0x5a7816f3
198 #define SAVE_FOR_RAID_INFO 0
200 #define SAVE_FOR_RAID_INFO 10
203 /***************************************************************************
204 * Function protocol for array layer
205 ***************************************************************************/
210 ULONG FASTCALL GetStamp(void);
211 void HPTLIBAPI SyncArrayInfo(PVDevice pVDev);
212 void HPTLIBAPI fDeleteArray(_VBUS_ARG PVDevice pVArray, BOOLEAN del_block0);
217 void HPTLIBAPI fCheckArray(PDevice pDevice);
218 void HPTLIBAPI CheckArrayCritical(_VBUS_ARG0);
219 PVDevice HPTLIBAPI GetSpareDisk(_VBUS_ARG PVDevice pArray);
220 #ifdef SUPPORT_OLD_ARRAY
221 void HPTLIBAPI fFixRAID01Stripe(_VBUS_ARG PVDevice pStripe);
224 /***************************************************************************
226 ***************************************************************************/
227 #ifndef MAX_ARRAY_PER_VBUS
228 #define MAX_ARRAY_PER_VBUS (MAX_VDEVICE_PER_VBUS*2) /* worst case */
232 #if defined(MAX_ARRAY_DEVICE)
233 #if MAX_ARRAY_DEVICE!=MAX_ARRAY_PER_VBUS
234 #error "remove MAX_ARRAY_DEVICE and use MAX_ARRAY_PER_VBUS instead"
238 #define _SET_ARRAY_BUS_(pArray) pArray->pVBus = _vbus_p;
241 #define _SET_ARRAY_VER_(pArray) pArray->vf_format_v2 = 1;
243 #define _SET_ARRAY_VER_(pArray)
246 #define mArGetArrayTable(pVArray) \
247 if((pVArray = _vbus_(pFreeArrayLink)) != 0) { \
248 _vbus_(pFreeArrayLink) = (PVDevice)_vbus_(pFreeArrayLink)->pVBus; \
249 ZeroMemory(pVArray, ARRAY_VDEV_SIZE); \
250 _SET_ARRAY_BUS_(pVArray) \
251 _SET_ARRAY_VER_(pVArray) \
254 #define mArFreeArrayTable(pVArray) \
256 pVArray->pVBus = (PVBus)_vbus_(pFreeArrayLink);\
257 _vbus_(pFreeArrayLink) = pVArray; \
258 pVArray->u.array.dArStamp = 0; \
261 UCHAR CheckSum(UCHAR *p, int size);
263 void HPTLIBAPI fRAID0SendCommand(_VBUS_ARG PCommand pCmd);
264 void HPTLIBAPI fRAID1SendCommand(_VBUS_ARG PCommand pCmd);
265 void HPTLIBAPI fJBODSendCommand(_VBUS_ARG PCommand pCmd);
266 void HPTLIBAPI fRAID0MemberFailed(_VBUS_ARG PVDevice pVDev);
267 void HPTLIBAPI fRAID1MemberFailed(_VBUS_ARG PVDevice pVDev);
268 void HPTLIBAPI fJBODMemberFailed(_VBUS_ARG PVDevice pVDev);
270 void HPTLIBAPI fRAID5SendCommand(_VBUS_ARG PCommand pCmd);
271 void HPTLIBAPI fRAID5MemberFailed(_VBUS_ARG PVDevice pVDev);
273 #define fRAID5SendCommand 0
274 #define fRAID5MemberFailed 0