array.h revision 142988
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.
25142988Sscottl *
26142988Sscottl * $FreeBSD: head/sys/dev/hptmv/array.h 142988 2005-03-02 05:14:28Z scottl $
27136849Sscottl */
28136849Sscottl
29136849Sscottl#ifndef _ARRAY_H_
30136849Sscottl#define _ARRAY_H_
31136849Sscottl
32136849Sscottl/*
33136849Sscottl * time represented in DWORD format
34136849Sscottl */
35136849Sscottl#pragma pack(1)
36136849Sscottl#ifdef __BIG_ENDIAN_BITFIELD
37136849Sscottltypedef DWORD TIME_RECORD;
38136849Sscottl#else
39136849Sscottltypedef struct _TIME_RECORD {
40136849Sscottl   UINT        seconds:6;      /* 0 - 59 */
41136849Sscottl   UINT        minutes:6;      /* 0 - 59 */
42136849Sscottl   UINT        month:4;        /* 1 - 12 */
43136849Sscottl   UINT        hours:6;        /* 0 - 59 */
44136849Sscottl   UINT        day:5;          /* 1 - 31 */
45136849Sscottl   UINT        year:5;         /* 0=2000, 31=2031 */
46136849Sscottl} TIME_RECORD;
47136849Sscottl#endif
48136849Sscottl#pragma pack()
49136849Sscottl
50136849Sscottl/***************************************************************************
51136849Sscottl * Description: Virtual Device Table
52136849Sscottl ***************************************************************************/
53136849Sscottl
54136849Sscottltypedef struct _RaidArray
55136849Sscottl{
56136849Sscottl    /*
57136849Sscottl     * basic information
58136849Sscottl     */
59136849Sscottl    UCHAR   bArnMember;        /* the number of members in array */
60136849Sscottl    UCHAR   bArRealnMember;    /* real member count */
61136849Sscottl    UCHAR   bArBlockSizeShift; /* the number of shift bit for a block */
62136849Sscottl    UCHAR   reserve1;
63136849Sscottl
64136849Sscottl    ULONG   dArStamp;          /* array ID. all disks in a array has same ID */
65136849Sscottl    USHORT  bStripeWitch;      /* = (1 << BlockSizeShift) */
66136849Sscottl
67136849Sscottl	USHORT	rf_broken: 1;
68136849Sscottl	USHORT	rf_need_rebuild: 1;			/* one member's data are incorrect.
69136849Sscottl	                                       for R5, if CriticalMembers==0, it means
70136849Sscottl										   parity needs to be constructed */
71136849Sscottl	USHORT	rf_need_sync: 1;			/* need write array info to disk */
72136849Sscottl	/* ioctl flags */
73136849Sscottl	USHORT  rf_auto_rebuild: 1;
74136849Sscottl	USHORT  rf_newly_created: 1;
75136849Sscottl	USHORT  rf_rebuilding: 1;
76136849Sscottl	USHORT  rf_verifying: 1;
77136849Sscottl	USHORT  rf_initializing: 1;
78136849Sscottl	USHORT  rf_abort_rebuild: 1;
79136849Sscottl	USHORT  rf_duplicate_and_create: 1;
80136849Sscottl	USHORT  rf_duplicate_and_created: 1;
81136849Sscottl	USHORT  rf_duplicate_must_done: 1;
82136849Sscottl	USHORT  rf_raid15: 1;
83136849Sscottl
84136849Sscottl	USHORT  CriticalMembers;   /* tell which member is critial */
85136849Sscottl	UCHAR   last_read;       /* for RAID 1 load banlancing */
86136849Sscottl	UCHAR   pad1;
87136849Sscottl
88136849Sscottl	LBA_T   RebuildSectors;  /* how many sectors is OK (LBA on member disk) */
89136849Sscottl
90136849Sscottl    PVDevice pMember[MAX_MEMBERS];
91136849Sscottl    /*
92136849Sscottl     * utility working data
93136849Sscottl     */
94136849Sscottl    UCHAR   ArrayName[MAX_ARRAY_NAME];  /* The Name of the array */
95136849Sscottl	TIME_RECORD CreateTime;				/* when created it */
96136849Sscottl	UCHAR	Description[64];		/* array description */
97136849Sscottl	UCHAR	CreateManager[16];		/* who created it */
98136849Sscottl} RaidArray;
99136849Sscottl
100136849Sscottl/***************************************************************************
101136849Sscottl *            Array Descripton on disk
102136849Sscottl ***************************************************************************/
103136849Sscottl#pragma pack(1)
104136849Sscottltypedef struct _ArrayDescript
105136849Sscottl{
106136849Sscottl	ULONG   Signature;      	/* This block is vaild array info block */
107136849Sscottl    ULONG   dArStamp;          	/* array ID. all disks in a array has same ID */
108136849Sscottl
109136849Sscottl	UCHAR   bCheckSum;          /* check sum of ArrayDescript_3_0_size bytes */
110136849Sscottl
111136849Sscottl#ifdef __BIG_ENDIAN_BITFIELD
112136849Sscottl	UCHAR   df_reservedbits: 6; /* put more flags here */
113136849Sscottl    UCHAR   df_user_mode_set: 1;/* user select device mode */
114136849Sscottl    UCHAR   df_bootmark:1;      /* user set boot mark on the disk */
115136849Sscottl#else
116136849Sscottl    UCHAR   df_bootmark:1;      /* user set boot mark on the disk */
117136849Sscottl    UCHAR   df_user_mode_set: 1;/* user select device mode */
118136849Sscottl	UCHAR   df_reservedbits: 6; /* put more flags here */
119136849Sscottl#endif
120136849Sscottl
121136849Sscottl    UCHAR   bUserDeviceMode;	/* see device.h */
122136849Sscottl    UCHAR   ArrayLevel;			/* how many level[] is valid */
123136849Sscottl
124136849Sscottl	struct {
125136849Sscottl	    ULONG   Capacity;         	/* capacity for the array */
126136849Sscottl
127136849Sscottl		UCHAR   VDeviceType;  		/* see above & arrayType in array.h */
128136849Sscottl	    UCHAR   bMemberCount;		/* all disk in the array */
129136849Sscottl	    UCHAR   bSerialNumber;  	/* Serial Number	*/
130136849Sscottl	    UCHAR   bArBlockSizeShift; 	/* the number of shift bit for a block */
131136849Sscottl
132136849Sscottl#ifdef __BIG_ENDIAN_BITFIELD
133136849Sscottl		USHORT  rf_reserved: 14;
134136849Sscottl		USHORT  rf_raid15: 1;       /* don't remove even you don't use it */
135136849Sscottl		USHORT  rf_need_rebuild:1;  /* array is critical */
136136849Sscottl#else
137136849Sscottl		USHORT  rf_need_rebuild:1;  /* array is critical */
138136849Sscottl		USHORT  rf_raid15: 1;       /* don't remove even you don't use it */
139136849Sscottl		USHORT  rf_reserved: 14;
140136849Sscottl#endif
141136849Sscottl		USHORT  CriticalMembers;    /* record critical members */
142136849Sscottl		ULONG   RebuildSectors;  /* how many sectors is OK (LBA on member disk) */
143136849Sscottl	} level[2];
144136849Sscottl
145136849Sscottl    UCHAR   ArrayName[MAX_ARRAY_NAME];  /* The Name of the array */
146136849Sscottl	TIME_RECORD CreateTime;				/* when created it */
147136849Sscottl	UCHAR	Description[64];		/* array description */
148136849Sscottl	UCHAR	CreateManager[16];		/* who created it */
149136849Sscottl
150136849Sscottl#define ArrayDescript_3_0_size ((unsigned)(ULONG_PTR)&((struct _ArrayDescript *)0)->bCheckSum31)
151136849Sscottl#define ArrayDescript_3_1_size 512
152136849Sscottl
153136849Sscottl	UCHAR   bCheckSum31;        /* new check sum */
154136849Sscottl	UCHAR   reserve2[2];
155136849Sscottl#ifdef __BIG_ENDIAN_BITFIELD
156136849Sscottl    UCHAR   df_read_ahead: 1;   /* enable read ahead */
157136849Sscottl	UCHAR   df_read_ahead_set: 1;
158136849Sscottl    UCHAR   df_write_cache: 1;  /* enable write cache */
159136849Sscottl	UCHAR   df_write_cache_set: 1;
160136849Sscottl    UCHAR   df_ncq: 1;          /* enable NCQ */
161136849Sscottl	UCHAR   df_ncq_set: 1;
162136849Sscottl    UCHAR   df_tcq: 1;          /* enable TCQ */
163136849Sscottl	UCHAR   df_tcq_set: 1;
164136849Sscottl#else
165136849Sscottl	UCHAR   df_tcq_set: 1;
166136849Sscottl    UCHAR   df_tcq: 1;          /* enable TCQ */
167136849Sscottl	UCHAR   df_ncq_set: 1;
168136849Sscottl    UCHAR   df_ncq: 1;          /* enable NCQ */
169136849Sscottl	UCHAR   df_write_cache_set: 1;
170136849Sscottl    UCHAR   df_write_cache: 1;  /* enable write cache */
171136849Sscottl	UCHAR   df_read_ahead_set: 1;
172136849Sscottl    UCHAR   df_read_ahead: 1;   /* enable read ahead */
173136849Sscottl#endif
174136849Sscottl
175136849Sscottl    struct {
176136849Sscottl    	ULONG CapacityHi32;
177136849Sscottl    	ULONG RebuildSectorsHi32;
178136849Sscottl    }
179136849Sscottl    levelex[2];
180136849Sscottl
181136849Sscottl} ArrayDescript;
182136849Sscottl
183136849Sscottl#pragma pack()
184136849Sscottl
185136849Sscottl/* Signature */
186136849Sscottl#define HPT_ARRAY_V3          0x5a7816f3
187136849Sscottl#ifdef ARRAY_V2_ONLY
188136849Sscottl#define SAVE_FOR_RAID_INFO    0
189136849Sscottl#else
190136849Sscottl#define SAVE_FOR_RAID_INFO    10
191136849Sscottl#endif
192136849Sscottl
193136849Sscottl/***************************************************************************
194136849Sscottl *  Function protocol for array layer
195136849Sscottl ***************************************************************************/
196136849Sscottl
197136849Sscottl/*
198136849Sscottl * array.c
199136849Sscottl */
200136849SscottlULONG FASTCALL GetStamp(void);
201136849Sscottlvoid HPTLIBAPI SyncArrayInfo(PVDevice pVDev);
202136849Sscottlvoid HPTLIBAPI fDeleteArray(_VBUS_ARG PVDevice pVArray, BOOLEAN del_block0);
203136849Sscottl
204136849Sscottl/*
205136849Sscottl * iArray.c
206136849Sscottl */
207136849Sscottlvoid HPTLIBAPI fCheckArray(PDevice pDevice);
208136849Sscottlvoid HPTLIBAPI CheckArrayCritical(_VBUS_ARG0);
209136849SscottlPVDevice HPTLIBAPI GetSpareDisk(_VBUS_ARG PVDevice pArray);
210136849Sscottl#ifdef SUPPORT_OLD_ARRAY
211136849Sscottlvoid HPTLIBAPI fFixRAID01Stripe(_VBUS_ARG PVDevice pStripe);
212136849Sscottl#endif
213136849Sscottl
214136849Sscottl/***************************************************************************
215136849Sscottl *  Macro defination
216136849Sscottl ***************************************************************************/
217136849Sscottl#ifndef MAX_ARRAY_PER_VBUS
218136849Sscottl#define MAX_ARRAY_PER_VBUS (MAX_VDEVICE_PER_VBUS*2) /* worst case */
219136849Sscottl#endif
220136849Sscottl
221136849Sscottl
222136849Sscottl#if defined(MAX_ARRAY_DEVICE)
223136849Sscottl#if MAX_ARRAY_DEVICE!=MAX_ARRAY_PER_VBUS
224136849Sscottl#error "remove MAX_ARRAY_DEVICE and use MAX_ARRAY_PER_VBUS instead"
225136849Sscottl#endif
226136849Sscottl#endif
227136849Sscottl
228136849Sscottl#define _SET_ARRAY_BUS_(pArray) pArray->pVBus = _vbus_p;
229136849Sscottl
230136849Sscottl#ifdef ARRAY_V2_ONLY
231136849Sscottl#define _SET_ARRAY_VER_(pArray) pArray->vf_format_v2 = 1;
232136849Sscottl#else
233136849Sscottl#define _SET_ARRAY_VER_(pArray)
234136849Sscottl#endif
235136849Sscottl
236136849Sscottl#define mArGetArrayTable(pVArray) \
237136849Sscottl	if((pVArray = _vbus_(pFreeArrayLink)) != 0) { \
238136849Sscottl    	_vbus_(pFreeArrayLink) = (PVDevice)_vbus_(pFreeArrayLink)->pVBus; \
239136849Sscottl    	ZeroMemory(pVArray, ARRAY_VDEV_SIZE); \
240136849Sscottl		_SET_ARRAY_BUS_(pVArray) \
241136849Sscottl		_SET_ARRAY_VER_(pVArray) \
242136849Sscottl    } else
243136849Sscottl
244136849Sscottl#define mArFreeArrayTable(pVArray) \
245136849Sscottl	do { \
246136849Sscottl		pVArray->pVBus = (PVBus)_vbus_(pFreeArrayLink);\
247136849Sscottl    	_vbus_(pFreeArrayLink) = pVArray; \
248136849Sscottl    	pVArray->u.array.dArStamp = 0; \
249136849Sscottl    } while(0)
250136849Sscottl
251136849SscottlUCHAR CheckSum(UCHAR *p, int size);
252136849Sscottl
253136849Sscottlvoid HPTLIBAPI fRAID0SendCommand(_VBUS_ARG PCommand pCmd);
254136849Sscottlvoid HPTLIBAPI fRAID1SendCommand(_VBUS_ARG PCommand pCmd);
255136849Sscottlvoid HPTLIBAPI fJBODSendCommand(_VBUS_ARG PCommand pCmd);
256136849Sscottlvoid HPTLIBAPI fRAID0MemberFailed(_VBUS_ARG PVDevice pVDev);
257136849Sscottlvoid HPTLIBAPI fRAID1MemberFailed(_VBUS_ARG PVDevice pVDev);
258136849Sscottlvoid HPTLIBAPI fJBODMemberFailed(_VBUS_ARG PVDevice pVDev);
259136849Sscottl#if SUPPORT_RAID5
260136849Sscottlvoid HPTLIBAPI fRAID5SendCommand(_VBUS_ARG PCommand pCmd);
261136849Sscottlvoid HPTLIBAPI fRAID5MemberFailed(_VBUS_ARG PVDevice pVDev);
262136849Sscottl#else
263136849Sscottl#define fRAID5SendCommand 0
264136849Sscottl#define fRAID5MemberFailed 0
265136849Sscottl#endif
266136849Sscottl
267136849Sscottl#endif
268