summaryrefslogtreecommitdiffstats
path: root/sys/dev/hptmv/array.h
blob: 14d627af5832428d1dcfaf651435eb2ee4aabdd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
 * Copyright (c) 2004-2005 HighPoint Technologies, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#ifndef _ARRAY_H_
#define _ARRAY_H_

/*
 * time represented in DWORD format
 */
#pragma pack(1)	
#ifdef __BIG_ENDIAN_BITFIELD
typedef DWORD TIME_RECORD;
#else 
typedef struct _TIME_RECORD {
   UINT        seconds:6;      /* 0 - 59 */
   UINT        minutes:6;      /* 0 - 59 */
   UINT        month:4;        /* 1 - 12 */
   UINT        hours:6;        /* 0 - 59 */
   UINT        day:5;          /* 1 - 31 */
   UINT        year:5;         /* 0=2000, 31=2031 */
} TIME_RECORD;
#endif
#pragma pack()

/***************************************************************************
 * Description: Virtual Device Table
 ***************************************************************************/

typedef struct _RaidArray 
{
    /*
     * basic information
     */
    UCHAR   bArnMember;        /* the number of members in array */
    UCHAR   bArRealnMember;    /* real member count */
    UCHAR   bArBlockSizeShift; /* the number of shift bit for a block */
    UCHAR   reserve1;

    ULONG   dArStamp;          /* array ID. all disks in a array has same ID */
	ULONG   failedStamp;       /* stamp for failed member */
    USHORT  bStripeWitch;      /* = (1 << BlockSizeShift) */

	USHORT	rf_broken: 1;
	USHORT	rf_need_rebuild: 1;			/* one member's data are incorrect.
	                                       for R5, if CriticalMembers==0, it means 
										   parity needs to be constructed */
	USHORT	rf_need_sync: 1;			/* need write array info to disk */
	/* ioctl flags */
	USHORT  rf_auto_rebuild: 1;
	USHORT  rf_newly_created: 1;
	USHORT  rf_rebuilding: 1;
	USHORT  rf_verifying: 1;
	USHORT  rf_initializing: 1;
	USHORT  rf_abort_rebuild: 1;
	USHORT  rf_duplicate_and_create: 1;
	USHORT  rf_duplicate_and_created: 1;
	USHORT  rf_duplicate_must_done: 1;
	USHORT  rf_raid15: 1;

	USHORT  CriticalMembers;   /* tell which member is critial */
	UCHAR   last_read;       /* for RAID 1 load banlancing */
	UCHAR   PrivateFlag1;

	LBA_T   RebuildSectors;  /* how many sectors is OK (LBA on member disk) */

    PVDevice pMember[MAX_MEMBERS];
    /*
     * utility working data
     */
    UCHAR   ArrayName[MAX_ARRAY_NAME];  /* The Name of the array */
	TIME_RECORD CreateTime;				/* when created it */
	UCHAR	Description[64];		/* array description */
	UCHAR	CreateManager[16];		/* who created it */
} RaidArray;

/***************************************************************************
 *            Array Descripton on disk
 ***************************************************************************/
#pragma pack(1)	
typedef struct _ArrayDescript
{
	ULONG   Signature;      	/* This block is vaild array info block */
    ULONG   dArStamp;          	/* array ID. all disks in a array has same ID */

	UCHAR   bCheckSum;          /* check sum of ArrayDescript_3_0_size bytes */

#ifdef __BIG_ENDIAN_BITFIELD
	UCHAR   df_reservedbits: 6; /* put more flags here */
    UCHAR   df_user_mode_set: 1;/* user select device mode */
    UCHAR   df_bootmark:1;      /* user set boot mark on the disk */
#else 
    UCHAR   df_bootmark:1;      /* user set boot mark on the disk */
    UCHAR   df_user_mode_set: 1;/* user select device mode */
	UCHAR   df_reservedbits: 6; /* put more flags here */
#endif

    UCHAR   bUserDeviceMode;	/* see device.h */
    UCHAR   ArrayLevel;			/* how many level[] is valid */

	struct {
	    ULONG   Capacity;         	/* capacity for the array */

		UCHAR   VDeviceType;  		/* see above & arrayType in array.h */
	    UCHAR   bMemberCount;		/* all disk in the array */
	    UCHAR   bSerialNumber;  	/* Serial Number	*/	
	    UCHAR   bArBlockSizeShift; 	/* the number of shift bit for a block */

#ifdef __BIG_ENDIAN_BITFIELD
		USHORT  rf_reserved: 14;
		USHORT  rf_raid15: 1;       /* don't remove even you don't use it */
		USHORT  rf_need_rebuild:1;  /* array is critical */
#else 
		USHORT  rf_need_rebuild:1;  /* array is critical */
		USHORT  rf_raid15: 1;       /* don't remove even you don't use it */
		USHORT  rf_reserved: 14;
#endif
		USHORT  CriticalMembers;    /* record critical members */
		ULONG   RebuildSectors;  /* how many sectors is OK (LBA on member disk) */
	} level[2];

    UCHAR   ArrayName[MAX_ARRAY_NAME];  /* The Name of the array */
	TIME_RECORD CreateTime;				/* when created it */
	UCHAR	Description[64];		/* array description */
	UCHAR	CreateManager[16];		/* who created it */

#define ArrayDescript_3_0_size ((unsigned)(ULONG_PTR)&((struct _ArrayDescript *)0)->bCheckSum31)
#define ArrayDescript_3_1_size 512

	UCHAR   bCheckSum31;        /* new check sum */
	UCHAR   PrivateFlag1;       /* private */
	UCHAR   reserve1;
	
#ifdef __BIG_ENDIAN_BITFIELD
    UCHAR   df_read_ahead: 1;   /* enable read ahead */
	UCHAR   df_read_ahead_set: 1;
    UCHAR   df_write_cache: 1;  /* enable write cache */
	UCHAR   df_write_cache_set: 1;
    UCHAR   df_ncq: 1;          /* enable NCQ */
	UCHAR   df_ncq_set: 1;
    UCHAR   df_tcq: 1;          /* enable TCQ */
	UCHAR   df_tcq_set: 1;
#else 
	UCHAR   df_tcq_set: 1;
    UCHAR   df_tcq: 1;          /* enable TCQ */
	UCHAR   df_ncq_set: 1;
    UCHAR   df_ncq: 1;          /* enable NCQ */
	UCHAR   df_write_cache_set: 1;
    UCHAR   df_write_cache: 1;  /* enable write cache */
	UCHAR   df_read_ahead_set: 1;
    UCHAR   df_read_ahead: 1;   /* enable read ahead */
#endif
    
    struct {
    	ULONG CapacityHi32;
    	ULONG RebuildSectorsHi32;
    }
    levelex[2];

	ULONG failedStamp; /* array stamp for failed memebr */

} ArrayDescript;

/* report an error if ArrayDescript size exceed 512 */
typedef char ArrayDescript_size_should_not_exceed_512[512-sizeof(ArrayDescript)];

#pragma pack()

/* Signature */
#define HPT_ARRAY_V3          0x5a7816f3
#ifdef ARRAY_V2_ONLY
#define SAVE_FOR_RAID_INFO    0
#else 
#define SAVE_FOR_RAID_INFO    10
#endif

/***************************************************************************
 *  Function protocol for array layer
 ***************************************************************************/

/*
 * array.c
 */
ULONG FASTCALL GetStamp(void);
void HPTLIBAPI SyncArrayInfo(PVDevice pVDev);
void HPTLIBAPI fDeleteArray(_VBUS_ARG PVDevice pVArray, BOOLEAN del_block0);

/*
 * iArray.c
 */
void HPTLIBAPI fCheckArray(PDevice pDevice);
void HPTLIBAPI CheckArrayCritical(_VBUS_ARG0);
PVDevice HPTLIBAPI GetSpareDisk(_VBUS_ARG PVDevice pArray);
#ifdef SUPPORT_OLD_ARRAY
void HPTLIBAPI fFixRAID01Stripe(_VBUS_ARG PVDevice pStripe);
#endif

/***************************************************************************
 *  Macro defination
 ***************************************************************************/
#ifndef MAX_ARRAY_PER_VBUS
#define MAX_ARRAY_PER_VBUS (MAX_VDEVICE_PER_VBUS*2) /* worst case */
#endif


#if defined(MAX_ARRAY_DEVICE)
#if MAX_ARRAY_DEVICE!=MAX_ARRAY_PER_VBUS
#error "remove MAX_ARRAY_DEVICE and use MAX_ARRAY_PER_VBUS instead"
#endif
#endif

#define _SET_ARRAY_BUS_(pArray) pArray->pVBus = _vbus_p;

#ifdef ARRAY_V2_ONLY
#define _SET_ARRAY_VER_(pArray) pArray->vf_format_v2 = 1;
#else 
#define _SET_ARRAY_VER_(pArray)
#endif

#define mArGetArrayTable(pVArray) \
	if((pVArray = _vbus_(pFreeArrayLink)) != 0) { \
    	_vbus_(pFreeArrayLink) = (PVDevice)_vbus_(pFreeArrayLink)->pVBus; \
    	ZeroMemory(pVArray, ARRAY_VDEV_SIZE); \
		_SET_ARRAY_BUS_(pVArray) \
		_SET_ARRAY_VER_(pVArray) \
    } else

#define mArFreeArrayTable(pVArray) \
	do { \
		pVArray->pVBus = (PVBus)_vbus_(pFreeArrayLink);\
    	_vbus_(pFreeArrayLink) = pVArray; \
    	pVArray->u.array.dArStamp = 0; \
    } while(0)

UCHAR CheckSum(UCHAR *p, int size);

void HPTLIBAPI fRAID0SendCommand(_VBUS_ARG PCommand pCmd);
void HPTLIBAPI fRAID1SendCommand(_VBUS_ARG PCommand pCmd);
void HPTLIBAPI fJBODSendCommand(_VBUS_ARG PCommand pCmd);
void HPTLIBAPI fRAID0MemberFailed(_VBUS_ARG PVDevice pVDev);
void HPTLIBAPI fRAID1MemberFailed(_VBUS_ARG PVDevice pVDev);
void HPTLIBAPI fJBODMemberFailed(_VBUS_ARG PVDevice pVDev);
#if SUPPORT_RAID5
void HPTLIBAPI fRAID5SendCommand(_VBUS_ARG PCommand pCmd);
void HPTLIBAPI fRAID5MemberFailed(_VBUS_ARG PVDevice pVDev);
#else 
#define fRAID5SendCommand 0
#define fRAID5MemberFailed 0
#endif

#endif
OpenPOWER on IntegriCloud