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