array.h revision 136849
1136849Sscottl/*
2136849Sscottl * Copyright (c) 2003-2004 HighPoint Technologies, Inc.
3136849Sscottl * All rights reserved.
4136849Sscottl *
5136849Sscottl * Redistribution and use in source and binary forms, with or without
6136849Sscottl * modification, are permitted provided that the following conditions
7136849Sscottl * are met:
8136849Sscottl * 1. Redistributions of source code must retain the above copyright
9136849Sscottl *    notice, this list of conditions and the following disclaimer.
10136849Sscottl * 2. Redistributions in binary form must reproduce the above copyright
11136849Sscottl *    notice, this list of conditions and the following disclaimer in the
12136849Sscottl *    documentation and/or other materials provided with the distribution.
13136849Sscottl *
14136849Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15136849Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16136849Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17136849Sscottl * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18136849Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19136849Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20136849Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21136849Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22136849Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23136849Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24136849Sscottl * SUCH DAMAGE.
25136849Sscottl */
26136849Sscottl
27136849Sscottl#ifndef _ARRAY_H_
28136849Sscottl#define _ARRAY_H_
29136849Sscottl
30136849Sscottl/*
31136849Sscottl * time represented in DWORD format
32136849Sscottl */
33136849Sscottl#pragma pack(1)
34136849Sscottl#ifdef __BIG_ENDIAN_BITFIELD
35136849Sscottltypedef DWORD TIME_RECORD;
36136849Sscottl#else
37136849Sscottltypedef struct _TIME_RECORD {
38136849Sscottl   UINT        seconds:6;      /* 0 - 59 */
39136849Sscottl   UINT        minutes:6;      /* 0 - 59 */
40136849Sscottl   UINT        month:4;        /* 1 - 12 */
41136849Sscottl   UINT        hours:6;        /* 0 - 59 */
42136849Sscottl   UINT        day:5;          /* 1 - 31 */
43136849Sscottl   UINT        year:5;         /* 0=2000, 31=2031 */
44136849Sscottl} TIME_RECORD;
45136849Sscottl#endif
46136849Sscottl#pragma pack()
47136849Sscottl
48136849Sscottl/***************************************************************************
49136849Sscottl * Description: Virtual Device Table
50136849Sscottl ***************************************************************************/
51136849Sscottl
52136849Sscottltypedef struct _RaidArray
53136849Sscottl{
54136849Sscottl    /*
55136849Sscottl     * basic information
56136849Sscottl     */
57136849Sscottl    UCHAR   bArnMember;        /* the number of members in array */
58136849Sscottl    UCHAR   bArRealnMember;    /* real member count */
59136849Sscottl    UCHAR   bArBlockSizeShift; /* the number of shift bit for a block */
60136849Sscottl    UCHAR   reserve1;
61136849Sscottl
62136849Sscottl    ULONG   dArStamp;          /* array ID. all disks in a array has same ID */
63136849Sscottl    USHORT  bStripeWitch;      /* = (1 << BlockSizeShift) */
64136849Sscottl
65136849Sscottl	USHORT	rf_broken: 1;
66136849Sscottl	USHORT	rf_need_rebuild: 1;			/* one member's data are incorrect.
67136849Sscottl	                                       for R5, if CriticalMembers==0, it means
68136849Sscottl										   parity needs to be constructed */
69136849Sscottl	USHORT	rf_need_sync: 1;			/* need write array info to disk */
70136849Sscottl	/* ioctl flags */
71136849Sscottl	USHORT  rf_auto_rebuild: 1;
72136849Sscottl	USHORT  rf_newly_created: 1;
73136849Sscottl	USHORT  rf_rebuilding: 1;
74136849Sscottl	USHORT  rf_verifying: 1;
75136849Sscottl	USHORT  rf_initializing: 1;
76136849Sscottl	USHORT  rf_abort_rebuild: 1;
77136849Sscottl	USHORT  rf_duplicate_and_create: 1;
78136849Sscottl	USHORT  rf_duplicate_and_created: 1;
79136849Sscottl	USHORT  rf_duplicate_must_done: 1;
80136849Sscottl	USHORT  rf_raid15: 1;
81136849Sscottl
82136849Sscottl	USHORT  CriticalMembers;   /* tell which member is critial */
83136849Sscottl	UCHAR   last_read;       /* for RAID 1 load banlancing */
84136849Sscottl	UCHAR   pad1;
85136849Sscottl
86136849Sscottl	LBA_T   RebuildSectors;  /* how many sectors is OK (LBA on member disk) */
87136849Sscottl
88136849Sscottl    PVDevice pMember[MAX_MEMBERS];
89136849Sscottl    /*
90136849Sscottl     * utility working data
91136849Sscottl     */
92136849Sscottl    UCHAR   ArrayName[MAX_ARRAY_NAME];  /* The Name of the array */
93136849Sscottl	TIME_RECORD CreateTime;				/* when created it */
94136849Sscottl	UCHAR	Description[64];		/* array description */
95136849Sscottl	UCHAR	CreateManager[16];		/* who created it */
96136849Sscottl} RaidArray;
97136849Sscottl
98136849Sscottl/***************************************************************************
99136849Sscottl *            Array Descripton on disk
100136849Sscottl ***************************************************************************/
101136849Sscottl#pragma pack(1)
102136849Sscottltypedef struct _ArrayDescript
103136849Sscottl{
104136849Sscottl	ULONG   Signature;      	/* This block is vaild array info block */
105136849Sscottl    ULONG   dArStamp;          	/* array ID. all disks in a array has same ID */
106136849Sscottl
107136849Sscottl	UCHAR   bCheckSum;          /* check sum of ArrayDescript_3_0_size bytes */
108136849Sscottl
109136849Sscottl#ifdef __BIG_ENDIAN_BITFIELD
110136849Sscottl	UCHAR   df_reservedbits: 6; /* put more flags here */
111136849Sscottl    UCHAR   df_user_mode_set: 1;/* user select device mode */
112136849Sscottl    UCHAR   df_bootmark:1;      /* user set boot mark on the disk */
113136849Sscottl#else
114136849Sscottl    UCHAR   df_bootmark:1;      /* user set boot mark on the disk */
115136849Sscottl    UCHAR   df_user_mode_set: 1;/* user select device mode */
116136849Sscottl	UCHAR   df_reservedbits: 6; /* put more flags here */
117136849Sscottl#endif
118136849Sscottl
119136849Sscottl    UCHAR   bUserDeviceMode;	/* see device.h */
120136849Sscottl    UCHAR   ArrayLevel;			/* how many level[] is valid */
121136849Sscottl
122136849Sscottl	struct {
123136849Sscottl	    ULONG   Capacity;         	/* capacity for the array */
124136849Sscottl
125136849Sscottl		UCHAR   VDeviceType;  		/* see above & arrayType in array.h */
126136849Sscottl	    UCHAR   bMemberCount;		/* all disk in the array */
127136849Sscottl	    UCHAR   bSerialNumber;  	/* Serial Number	*/
128136849Sscottl	    UCHAR   bArBlockSizeShift; 	/* the number of shift bit for a block */
129136849Sscottl
130136849Sscottl#ifdef __BIG_ENDIAN_BITFIELD
131136849Sscottl		USHORT  rf_reserved: 14;
132136849Sscottl		USHORT  rf_raid15: 1;       /* don't remove even you don't use it */
133136849Sscottl		USHORT  rf_need_rebuild:1;  /* array is critical */
134136849Sscottl#else
135136849Sscottl		USHORT  rf_need_rebuild:1;  /* array is critical */
136136849Sscottl		USHORT  rf_raid15: 1;       /* don't remove even you don't use it */
137136849Sscottl		USHORT  rf_reserved: 14;
138136849Sscottl#endif
139136849Sscottl		USHORT  CriticalMembers;    /* record critical members */
140136849Sscottl		ULONG   RebuildSectors;  /* how many sectors is OK (LBA on member disk) */
141136849Sscottl	} level[2];
142136849Sscottl
143136849Sscottl    UCHAR   ArrayName[MAX_ARRAY_NAME];  /* The Name of the array */
144136849Sscottl	TIME_RECORD CreateTime;				/* when created it */
145136849Sscottl	UCHAR	Description[64];		/* array description */
146136849Sscottl	UCHAR	CreateManager[16];		/* who created it */
147136849Sscottl
148136849Sscottl#define ArrayDescript_3_0_size ((unsigned)(ULONG_PTR)&((struct _ArrayDescript *)0)->bCheckSum31)
149136849Sscottl#define ArrayDescript_3_1_size 512
150136849Sscottl
151136849Sscottl	UCHAR   bCheckSum31;        /* new check sum */
152136849Sscottl	UCHAR   reserve2[2];
153136849Sscottl#ifdef __BIG_ENDIAN_BITFIELD
154136849Sscottl    UCHAR   df_read_ahead: 1;   /* enable read ahead */
155136849Sscottl	UCHAR   df_read_ahead_set: 1;
156136849Sscottl    UCHAR   df_write_cache: 1;  /* enable write cache */
157136849Sscottl	UCHAR   df_write_cache_set: 1;
158136849Sscottl    UCHAR   df_ncq: 1;          /* enable NCQ */
159136849Sscottl	UCHAR   df_ncq_set: 1;
160136849Sscottl    UCHAR   df_tcq: 1;          /* enable TCQ */
161136849Sscottl	UCHAR   df_tcq_set: 1;
162136849Sscottl#else
163136849Sscottl	UCHAR   df_tcq_set: 1;
164136849Sscottl    UCHAR   df_tcq: 1;          /* enable TCQ */
165136849Sscottl	UCHAR   df_ncq_set: 1;
166136849Sscottl    UCHAR   df_ncq: 1;          /* enable NCQ */
167136849Sscottl	UCHAR   df_write_cache_set: 1;
168136849Sscottl    UCHAR   df_write_cache: 1;  /* enable write cache */
169136849Sscottl	UCHAR   df_read_ahead_set: 1;
170136849Sscottl    UCHAR   df_read_ahead: 1;   /* enable read ahead */
171136849Sscottl#endif
172136849Sscottl
173136849Sscottl    struct {
174136849Sscottl    	ULONG CapacityHi32;
175136849Sscottl    	ULONG RebuildSectorsHi32;
176136849Sscottl    }
177136849Sscottl    levelex[2];
178136849Sscottl
179136849Sscottl} ArrayDescript;
180136849Sscottl
181136849Sscottl#pragma pack()
182136849Sscottl
183136849Sscottl/* Signature */
184136849Sscottl#define HPT_ARRAY_V3          0x5a7816f3
185136849Sscottl#ifdef ARRAY_V2_ONLY
186136849Sscottl#define SAVE_FOR_RAID_INFO    0
187136849Sscottl#else
188136849Sscottl#define SAVE_FOR_RAID_INFO    10
189136849Sscottl#endif
190136849Sscottl
191136849Sscottl/***************************************************************************
192136849Sscottl *  Function protocol for array layer
193136849Sscottl ***************************************************************************/
194136849Sscottl
195136849Sscottl/*
196136849Sscottl * array.c
197136849Sscottl */
198136849SscottlULONG FASTCALL GetStamp(void);
199136849Sscottlvoid HPTLIBAPI SyncArrayInfo(PVDevice pVDev);
200136849Sscottlvoid HPTLIBAPI fDeleteArray(_VBUS_ARG PVDevice pVArray, BOOLEAN del_block0);
201136849Sscottl
202136849Sscottl/*
203136849Sscottl * iArray.c
204136849Sscottl */
205136849Sscottlvoid HPTLIBAPI fCheckArray(PDevice pDevice);
206136849Sscottlvoid HPTLIBAPI CheckArrayCritical(_VBUS_ARG0);
207136849SscottlPVDevice HPTLIBAPI GetSpareDisk(_VBUS_ARG PVDevice pArray);
208136849Sscottl#ifdef SUPPORT_OLD_ARRAY
209136849Sscottlvoid HPTLIBAPI fFixRAID01Stripe(_VBUS_ARG PVDevice pStripe);
210136849Sscottl#endif
211136849Sscottl
212136849Sscottl/***************************************************************************
213136849Sscottl *  Macro defination
214136849Sscottl ***************************************************************************/
215136849Sscottl#ifndef MAX_ARRAY_PER_VBUS
216136849Sscottl#define MAX_ARRAY_PER_VBUS (MAX_VDEVICE_PER_VBUS*2) /* worst case */
217136849Sscottl#endif
218136849Sscottl
219136849Sscottl
220136849Sscottl#if defined(MAX_ARRAY_DEVICE)
221136849Sscottl#if MAX_ARRAY_DEVICE!=MAX_ARRAY_PER_VBUS
222136849Sscottl#error "remove MAX_ARRAY_DEVICE and use MAX_ARRAY_PER_VBUS instead"
223136849Sscottl#endif
224136849Sscottl#endif
225136849Sscottl
226136849Sscottl#define _SET_ARRAY_BUS_(pArray) pArray->pVBus = _vbus_p;
227136849Sscottl
228136849Sscottl#ifdef ARRAY_V2_ONLY
229136849Sscottl#define _SET_ARRAY_VER_(pArray) pArray->vf_format_v2 = 1;
230136849Sscottl#else
231136849Sscottl#define _SET_ARRAY_VER_(pArray)
232136849Sscottl#endif
233136849Sscottl
234136849Sscottl#define mArGetArrayTable(pVArray) \
235136849Sscottl	if((pVArray = _vbus_(pFreeArrayLink)) != 0) { \
236136849Sscottl    	_vbus_(pFreeArrayLink) = (PVDevice)_vbus_(pFreeArrayLink)->pVBus; \
237136849Sscottl    	ZeroMemory(pVArray, ARRAY_VDEV_SIZE); \
238136849Sscottl		_SET_ARRAY_BUS_(pVArray) \
239136849Sscottl		_SET_ARRAY_VER_(pVArray) \
240136849Sscottl    } else
241136849Sscottl
242136849Sscottl#define mArFreeArrayTable(pVArray) \
243136849Sscottl	do { \
244136849Sscottl		pVArray->pVBus = (PVBus)_vbus_(pFreeArrayLink);\
245136849Sscottl    	_vbus_(pFreeArrayLink) = pVArray; \
246136849Sscottl    	pVArray->u.array.dArStamp = 0; \
247136849Sscottl    } while(0)
248136849Sscottl
249136849SscottlUCHAR CheckSum(UCHAR *p, int size);
250136849Sscottl
251136849Sscottlvoid HPTLIBAPI fRAID0SendCommand(_VBUS_ARG PCommand pCmd);
252136849Sscottlvoid HPTLIBAPI fRAID1SendCommand(_VBUS_ARG PCommand pCmd);
253136849Sscottlvoid HPTLIBAPI fJBODSendCommand(_VBUS_ARG PCommand pCmd);
254136849Sscottlvoid HPTLIBAPI fRAID0MemberFailed(_VBUS_ARG PVDevice pVDev);
255136849Sscottlvoid HPTLIBAPI fRAID1MemberFailed(_VBUS_ARG PVDevice pVDev);
256136849Sscottlvoid HPTLIBAPI fJBODMemberFailed(_VBUS_ARG PVDevice pVDev);
257136849Sscottl#if SUPPORT_RAID5
258136849Sscottlvoid HPTLIBAPI fRAID5SendCommand(_VBUS_ARG PCommand pCmd);
259136849Sscottlvoid HPTLIBAPI fRAID5MemberFailed(_VBUS_ARG PVDevice pVDev);
260136849Sscottl#else
261136849Sscottl#define fRAID5SendCommand 0
262136849Sscottl#define fRAID5MemberFailed 0
263136849Sscottl#endif
264136849Sscottl
265136849Sscottl#endif
266