xref: /freebsd/sys/dev/hptmv/array.h (revision 8df8b2d3e51d1b816201d8a1fe8bc29fe192e562)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2004-2005 HighPoint Technologies, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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.
15  *
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
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 #ifndef _ARRAY_H_
32 #define _ARRAY_H_
33 
34 /*
35  * time represented in DWORD format
36  */
37 #pragma pack(1)
38 #ifdef __BIG_ENDIAN_BITFIELD
39 typedef DWORD TIME_RECORD;
40 #else
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 */
48 } TIME_RECORD;
49 #endif
50 #pragma pack()
51 
52 /***************************************************************************
53  * Description: Virtual Device Table
54  ***************************************************************************/
55 
56 typedef struct _RaidArray
57 {
58     /*
59      * basic information
60      */
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 */
64     UCHAR   reserve1;
65 
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) */
69 
70 	USHORT	rf_broken: 1;
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 */
75 	/* ioctl flags */
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;
85 	USHORT  rf_raid15: 1;
86 
87 	USHORT  CriticalMembers;   /* tell which member is critial */
88 	UCHAR   last_read;       /* for RAID 1 load banlancing */
89 	UCHAR   alreadyBroken;
90 
91 	LBA_T   RebuildSectors;  /* how many sectors is OK (LBA on member disk) */
92 
93     PVDevice pMember[MAX_MEMBERS];
94     /*
95      * utility working data
96      */
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 */
101 } RaidArray;
102 
103 /***************************************************************************
104  *            Array Description on disk
105  ***************************************************************************/
106 #pragma pack(1)
107 typedef struct _ArrayDescript
108 {
109 	ULONG   Signature;      	/* This block is vaild array info block */
110     ULONG   dArStamp;          	/* array ID. all disks in a array has same ID */
111 
112 	UCHAR   bCheckSum;          /* check sum of ArrayDescript_3_0_size bytes */
113 
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 */
118 #else
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 */
122 #endif
123 
124     UCHAR   bUserDeviceMode;	/* see device.h */
125     UCHAR   ArrayLevel;			/* how many level[] is valid */
126 
127 	struct {
128 	    ULONG   Capacity;         	/* capacity for the array */
129 
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 */
134 
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 */
139 #else
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;
143 #endif
144 		USHORT  CriticalMembers;    /* record critical members */
145 		ULONG   RebuildSectors;  /* how many sectors is OK (LBA on member disk) */
146 	} level[2];
147 
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 */
152 
153 #define ArrayDescript_3_0_size ((unsigned)(ULONG_PTR)&((struct _ArrayDescript *)0)->bCheckSum31)
154 #define ArrayDescript_3_1_size 512
155 
156 	UCHAR   bCheckSum31;        /* new check sum */
157 	UCHAR   PrivateFlag1;       /* private */
158 	UCHAR   alreadyBroken;      /* last stamp has been saved to failedStamps */
159 
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 */
166 	UCHAR   df_ncq_set: 1;
167     UCHAR   df_tcq: 1;          /* enable TCQ */
168 	UCHAR   df_tcq_set: 1;
169 #else
170 	UCHAR   df_tcq_set: 1;
171     UCHAR   df_tcq: 1;          /* enable TCQ */
172 	UCHAR   df_ncq_set: 1;
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 */
178 #endif
179 
180     struct {
181     	ULONG CapacityHi32;
182     	ULONG RebuildSectorsHi32;
183     }
184     levelex[2];
185 
186 	ULONG failedStamps[4]; /* failed memebrs's stamps */
187 
188 } ArrayDescript;
189 
190 /* report an error if ArrayDescript size exceed 512 */
191 typedef char ArrayDescript_size_should_not_exceed_512[512-sizeof(ArrayDescript)];
192 
193 #pragma pack()
194 
195 /* Signature */
196 #define HPT_ARRAY_V3          0x5a7816f3
197 #ifdef ARRAY_V2_ONLY
198 #define SAVE_FOR_RAID_INFO    0
199 #else
200 #define SAVE_FOR_RAID_INFO    10
201 #endif
202 
203 /***************************************************************************
204  *  Function protocol for array layer
205  ***************************************************************************/
206 
207 /*
208  * array.c
209  */
210 ULONG FASTCALL GetStamp(void);
211 void HPTLIBAPI SyncArrayInfo(PVDevice pVDev);
212 void HPTLIBAPI fDeleteArray(_VBUS_ARG PVDevice pVArray, BOOLEAN del_block0);
213 
214 /*
215  * iArray.c
216  */
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);
222 #endif
223 
224 /***************************************************************************
225  *  Macro defination
226  ***************************************************************************/
227 #ifndef MAX_ARRAY_PER_VBUS
228 #define MAX_ARRAY_PER_VBUS (MAX_VDEVICE_PER_VBUS*2) /* worst case */
229 #endif
230 
231 
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"
235 #endif
236 #endif
237 
238 #define _SET_ARRAY_BUS_(pArray) pArray->pVBus = _vbus_p;
239 
240 #ifdef ARRAY_V2_ONLY
241 #define _SET_ARRAY_VER_(pArray) pArray->vf_format_v2 = 1;
242 #else
243 #define _SET_ARRAY_VER_(pArray)
244 #endif
245 
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) \
252     } else
253 
254 #define mArFreeArrayTable(pVArray) \
255 	do { \
256 		pVArray->pVBus = (PVBus)_vbus_(pFreeArrayLink);\
257     	_vbus_(pFreeArrayLink) = pVArray; \
258     	pVArray->u.array.dArStamp = 0; \
259     } while(0)
260 
261 UCHAR CheckSum(UCHAR *p, int size);
262 
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);
269 #if SUPPORT_RAID5
270 void HPTLIBAPI fRAID5SendCommand(_VBUS_ARG PCommand pCmd);
271 void HPTLIBAPI fRAID5MemberFailed(_VBUS_ARG PVDevice pVDev);
272 #else
273 #define fRAID5SendCommand 0
274 #define fRAID5MemberFailed 0
275 #endif
276 
277 #endif
278