xref: /freebsd/sys/dev/hptmv/array.h (revision 1713e81b9cdf06d2a9a365a7ded13a54fad84798)
11713e81bSScott Long /*
21713e81bSScott Long  * Copyright (c) 2003-2004 HighPoint Technologies, Inc.
31713e81bSScott Long  * All rights reserved.
41713e81bSScott Long  *
51713e81bSScott Long  * Redistribution and use in source and binary forms, with or without
61713e81bSScott Long  * modification, are permitted provided that the following conditions
71713e81bSScott Long  * are met:
81713e81bSScott Long  * 1. Redistributions of source code must retain the above copyright
91713e81bSScott Long  *    notice, this list of conditions and the following disclaimer.
101713e81bSScott Long  * 2. Redistributions in binary form must reproduce the above copyright
111713e81bSScott Long  *    notice, this list of conditions and the following disclaimer in the
121713e81bSScott Long  *    documentation and/or other materials provided with the distribution.
131713e81bSScott Long  *
141713e81bSScott Long  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
151713e81bSScott Long  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
161713e81bSScott Long  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
171713e81bSScott Long  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
181713e81bSScott Long  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
191713e81bSScott Long  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
201713e81bSScott Long  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211713e81bSScott Long  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
221713e81bSScott Long  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
231713e81bSScott Long  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
241713e81bSScott Long  * SUCH DAMAGE.
251713e81bSScott Long  */
261713e81bSScott Long 
271713e81bSScott Long #ifndef _ARRAY_H_
281713e81bSScott Long #define _ARRAY_H_
291713e81bSScott Long 
301713e81bSScott Long /*
311713e81bSScott Long  * time represented in DWORD format
321713e81bSScott Long  */
331713e81bSScott Long #pragma pack(1)
341713e81bSScott Long #ifdef __BIG_ENDIAN_BITFIELD
351713e81bSScott Long typedef DWORD TIME_RECORD;
361713e81bSScott Long #else
371713e81bSScott Long typedef struct _TIME_RECORD {
381713e81bSScott Long    UINT        seconds:6;      /* 0 - 59 */
391713e81bSScott Long    UINT        minutes:6;      /* 0 - 59 */
401713e81bSScott Long    UINT        month:4;        /* 1 - 12 */
411713e81bSScott Long    UINT        hours:6;        /* 0 - 59 */
421713e81bSScott Long    UINT        day:5;          /* 1 - 31 */
431713e81bSScott Long    UINT        year:5;         /* 0=2000, 31=2031 */
441713e81bSScott Long } TIME_RECORD;
451713e81bSScott Long #endif
461713e81bSScott Long #pragma pack()
471713e81bSScott Long 
481713e81bSScott Long /***************************************************************************
491713e81bSScott Long  * Description: Virtual Device Table
501713e81bSScott Long  ***************************************************************************/
511713e81bSScott Long 
521713e81bSScott Long typedef struct _RaidArray
531713e81bSScott Long {
541713e81bSScott Long     /*
551713e81bSScott Long      * basic information
561713e81bSScott Long      */
571713e81bSScott Long     UCHAR   bArnMember;        /* the number of members in array */
581713e81bSScott Long     UCHAR   bArRealnMember;    /* real member count */
591713e81bSScott Long     UCHAR   bArBlockSizeShift; /* the number of shift bit for a block */
601713e81bSScott Long     UCHAR   reserve1;
611713e81bSScott Long 
621713e81bSScott Long     ULONG   dArStamp;          /* array ID. all disks in a array has same ID */
631713e81bSScott Long     USHORT  bStripeWitch;      /* = (1 << BlockSizeShift) */
641713e81bSScott Long 
651713e81bSScott Long 	USHORT	rf_broken: 1;
661713e81bSScott Long 	USHORT	rf_need_rebuild: 1;			/* one member's data are incorrect.
671713e81bSScott Long 	                                       for R5, if CriticalMembers==0, it means
681713e81bSScott Long 										   parity needs to be constructed */
691713e81bSScott Long 	USHORT	rf_need_sync: 1;			/* need write array info to disk */
701713e81bSScott Long 	/* ioctl flags */
711713e81bSScott Long 	USHORT  rf_auto_rebuild: 1;
721713e81bSScott Long 	USHORT  rf_newly_created: 1;
731713e81bSScott Long 	USHORT  rf_rebuilding: 1;
741713e81bSScott Long 	USHORT  rf_verifying: 1;
751713e81bSScott Long 	USHORT  rf_initializing: 1;
761713e81bSScott Long 	USHORT  rf_abort_rebuild: 1;
771713e81bSScott Long 	USHORT  rf_duplicate_and_create: 1;
781713e81bSScott Long 	USHORT  rf_duplicate_and_created: 1;
791713e81bSScott Long 	USHORT  rf_duplicate_must_done: 1;
801713e81bSScott Long 	USHORT  rf_raid15: 1;
811713e81bSScott Long 
821713e81bSScott Long 	USHORT  CriticalMembers;   /* tell which member is critial */
831713e81bSScott Long 	UCHAR   last_read;       /* for RAID 1 load banlancing */
841713e81bSScott Long 	UCHAR   pad1;
851713e81bSScott Long 
861713e81bSScott Long 	LBA_T   RebuildSectors;  /* how many sectors is OK (LBA on member disk) */
871713e81bSScott Long 
881713e81bSScott Long     PVDevice pMember[MAX_MEMBERS];
891713e81bSScott Long     /*
901713e81bSScott Long      * utility working data
911713e81bSScott Long      */
921713e81bSScott Long     UCHAR   ArrayName[MAX_ARRAY_NAME];  /* The Name of the array */
931713e81bSScott Long 	TIME_RECORD CreateTime;				/* when created it */
941713e81bSScott Long 	UCHAR	Description[64];		/* array description */
951713e81bSScott Long 	UCHAR	CreateManager[16];		/* who created it */
961713e81bSScott Long } RaidArray;
971713e81bSScott Long 
981713e81bSScott Long /***************************************************************************
991713e81bSScott Long  *            Array Descripton on disk
1001713e81bSScott Long  ***************************************************************************/
1011713e81bSScott Long #pragma pack(1)
1021713e81bSScott Long typedef struct _ArrayDescript
1031713e81bSScott Long {
1041713e81bSScott Long 	ULONG   Signature;      	/* This block is vaild array info block */
1051713e81bSScott Long     ULONG   dArStamp;          	/* array ID. all disks in a array has same ID */
1061713e81bSScott Long 
1071713e81bSScott Long 	UCHAR   bCheckSum;          /* check sum of ArrayDescript_3_0_size bytes */
1081713e81bSScott Long 
1091713e81bSScott Long #ifdef __BIG_ENDIAN_BITFIELD
1101713e81bSScott Long 	UCHAR   df_reservedbits: 6; /* put more flags here */
1111713e81bSScott Long     UCHAR   df_user_mode_set: 1;/* user select device mode */
1121713e81bSScott Long     UCHAR   df_bootmark:1;      /* user set boot mark on the disk */
1131713e81bSScott Long #else
1141713e81bSScott Long     UCHAR   df_bootmark:1;      /* user set boot mark on the disk */
1151713e81bSScott Long     UCHAR   df_user_mode_set: 1;/* user select device mode */
1161713e81bSScott Long 	UCHAR   df_reservedbits: 6; /* put more flags here */
1171713e81bSScott Long #endif
1181713e81bSScott Long 
1191713e81bSScott Long     UCHAR   bUserDeviceMode;	/* see device.h */
1201713e81bSScott Long     UCHAR   ArrayLevel;			/* how many level[] is valid */
1211713e81bSScott Long 
1221713e81bSScott Long 	struct {
1231713e81bSScott Long 	    ULONG   Capacity;         	/* capacity for the array */
1241713e81bSScott Long 
1251713e81bSScott Long 		UCHAR   VDeviceType;  		/* see above & arrayType in array.h */
1261713e81bSScott Long 	    UCHAR   bMemberCount;		/* all disk in the array */
1271713e81bSScott Long 	    UCHAR   bSerialNumber;  	/* Serial Number	*/
1281713e81bSScott Long 	    UCHAR   bArBlockSizeShift; 	/* the number of shift bit for a block */
1291713e81bSScott Long 
1301713e81bSScott Long #ifdef __BIG_ENDIAN_BITFIELD
1311713e81bSScott Long 		USHORT  rf_reserved: 14;
1321713e81bSScott Long 		USHORT  rf_raid15: 1;       /* don't remove even you don't use it */
1331713e81bSScott Long 		USHORT  rf_need_rebuild:1;  /* array is critical */
1341713e81bSScott Long #else
1351713e81bSScott Long 		USHORT  rf_need_rebuild:1;  /* array is critical */
1361713e81bSScott Long 		USHORT  rf_raid15: 1;       /* don't remove even you don't use it */
1371713e81bSScott Long 		USHORT  rf_reserved: 14;
1381713e81bSScott Long #endif
1391713e81bSScott Long 		USHORT  CriticalMembers;    /* record critical members */
1401713e81bSScott Long 		ULONG   RebuildSectors;  /* how many sectors is OK (LBA on member disk) */
1411713e81bSScott Long 	} level[2];
1421713e81bSScott Long 
1431713e81bSScott Long     UCHAR   ArrayName[MAX_ARRAY_NAME];  /* The Name of the array */
1441713e81bSScott Long 	TIME_RECORD CreateTime;				/* when created it */
1451713e81bSScott Long 	UCHAR	Description[64];		/* array description */
1461713e81bSScott Long 	UCHAR	CreateManager[16];		/* who created it */
1471713e81bSScott Long 
1481713e81bSScott Long #define ArrayDescript_3_0_size ((unsigned)(ULONG_PTR)&((struct _ArrayDescript *)0)->bCheckSum31)
1491713e81bSScott Long #define ArrayDescript_3_1_size 512
1501713e81bSScott Long 
1511713e81bSScott Long 	UCHAR   bCheckSum31;        /* new check sum */
1521713e81bSScott Long 	UCHAR   reserve2[2];
1531713e81bSScott Long #ifdef __BIG_ENDIAN_BITFIELD
1541713e81bSScott Long     UCHAR   df_read_ahead: 1;   /* enable read ahead */
1551713e81bSScott Long 	UCHAR   df_read_ahead_set: 1;
1561713e81bSScott Long     UCHAR   df_write_cache: 1;  /* enable write cache */
1571713e81bSScott Long 	UCHAR   df_write_cache_set: 1;
1581713e81bSScott Long     UCHAR   df_ncq: 1;          /* enable NCQ */
1591713e81bSScott Long 	UCHAR   df_ncq_set: 1;
1601713e81bSScott Long     UCHAR   df_tcq: 1;          /* enable TCQ */
1611713e81bSScott Long 	UCHAR   df_tcq_set: 1;
1621713e81bSScott Long #else
1631713e81bSScott Long 	UCHAR   df_tcq_set: 1;
1641713e81bSScott Long     UCHAR   df_tcq: 1;          /* enable TCQ */
1651713e81bSScott Long 	UCHAR   df_ncq_set: 1;
1661713e81bSScott Long     UCHAR   df_ncq: 1;          /* enable NCQ */
1671713e81bSScott Long 	UCHAR   df_write_cache_set: 1;
1681713e81bSScott Long     UCHAR   df_write_cache: 1;  /* enable write cache */
1691713e81bSScott Long 	UCHAR   df_read_ahead_set: 1;
1701713e81bSScott Long     UCHAR   df_read_ahead: 1;   /* enable read ahead */
1711713e81bSScott Long #endif
1721713e81bSScott Long 
1731713e81bSScott Long     struct {
1741713e81bSScott Long     	ULONG CapacityHi32;
1751713e81bSScott Long     	ULONG RebuildSectorsHi32;
1761713e81bSScott Long     }
1771713e81bSScott Long     levelex[2];
1781713e81bSScott Long 
1791713e81bSScott Long } ArrayDescript;
1801713e81bSScott Long 
1811713e81bSScott Long #pragma pack()
1821713e81bSScott Long 
1831713e81bSScott Long /* Signature */
1841713e81bSScott Long #define HPT_ARRAY_V3          0x5a7816f3
1851713e81bSScott Long #ifdef ARRAY_V2_ONLY
1861713e81bSScott Long #define SAVE_FOR_RAID_INFO    0
1871713e81bSScott Long #else
1881713e81bSScott Long #define SAVE_FOR_RAID_INFO    10
1891713e81bSScott Long #endif
1901713e81bSScott Long 
1911713e81bSScott Long /***************************************************************************
1921713e81bSScott Long  *  Function protocol for array layer
1931713e81bSScott Long  ***************************************************************************/
1941713e81bSScott Long 
1951713e81bSScott Long /*
1961713e81bSScott Long  * array.c
1971713e81bSScott Long  */
1981713e81bSScott Long ULONG FASTCALL GetStamp(void);
1991713e81bSScott Long void HPTLIBAPI SyncArrayInfo(PVDevice pVDev);
2001713e81bSScott Long void HPTLIBAPI fDeleteArray(_VBUS_ARG PVDevice pVArray, BOOLEAN del_block0);
2011713e81bSScott Long 
2021713e81bSScott Long /*
2031713e81bSScott Long  * iArray.c
2041713e81bSScott Long  */
2051713e81bSScott Long void HPTLIBAPI fCheckArray(PDevice pDevice);
2061713e81bSScott Long void HPTLIBAPI CheckArrayCritical(_VBUS_ARG0);
2071713e81bSScott Long PVDevice HPTLIBAPI GetSpareDisk(_VBUS_ARG PVDevice pArray);
2081713e81bSScott Long #ifdef SUPPORT_OLD_ARRAY
2091713e81bSScott Long void HPTLIBAPI fFixRAID01Stripe(_VBUS_ARG PVDevice pStripe);
2101713e81bSScott Long #endif
2111713e81bSScott Long 
2121713e81bSScott Long /***************************************************************************
2131713e81bSScott Long  *  Macro defination
2141713e81bSScott Long  ***************************************************************************/
2151713e81bSScott Long #ifndef MAX_ARRAY_PER_VBUS
2161713e81bSScott Long #define MAX_ARRAY_PER_VBUS (MAX_VDEVICE_PER_VBUS*2) /* worst case */
2171713e81bSScott Long #endif
2181713e81bSScott Long 
2191713e81bSScott Long 
2201713e81bSScott Long #if defined(MAX_ARRAY_DEVICE)
2211713e81bSScott Long #if MAX_ARRAY_DEVICE!=MAX_ARRAY_PER_VBUS
2221713e81bSScott Long #error "remove MAX_ARRAY_DEVICE and use MAX_ARRAY_PER_VBUS instead"
2231713e81bSScott Long #endif
2241713e81bSScott Long #endif
2251713e81bSScott Long 
2261713e81bSScott Long #define _SET_ARRAY_BUS_(pArray) pArray->pVBus = _vbus_p;
2271713e81bSScott Long 
2281713e81bSScott Long #ifdef ARRAY_V2_ONLY
2291713e81bSScott Long #define _SET_ARRAY_VER_(pArray) pArray->vf_format_v2 = 1;
2301713e81bSScott Long #else
2311713e81bSScott Long #define _SET_ARRAY_VER_(pArray)
2321713e81bSScott Long #endif
2331713e81bSScott Long 
2341713e81bSScott Long #define mArGetArrayTable(pVArray) \
2351713e81bSScott Long 	if((pVArray = _vbus_(pFreeArrayLink)) != 0) { \
2361713e81bSScott Long     	_vbus_(pFreeArrayLink) = (PVDevice)_vbus_(pFreeArrayLink)->pVBus; \
2371713e81bSScott Long     	ZeroMemory(pVArray, ARRAY_VDEV_SIZE); \
2381713e81bSScott Long 		_SET_ARRAY_BUS_(pVArray) \
2391713e81bSScott Long 		_SET_ARRAY_VER_(pVArray) \
2401713e81bSScott Long     } else
2411713e81bSScott Long 
2421713e81bSScott Long #define mArFreeArrayTable(pVArray) \
2431713e81bSScott Long 	do { \
2441713e81bSScott Long 		pVArray->pVBus = (PVBus)_vbus_(pFreeArrayLink);\
2451713e81bSScott Long     	_vbus_(pFreeArrayLink) = pVArray; \
2461713e81bSScott Long     	pVArray->u.array.dArStamp = 0; \
2471713e81bSScott Long     } while(0)
2481713e81bSScott Long 
2491713e81bSScott Long UCHAR CheckSum(UCHAR *p, int size);
2501713e81bSScott Long 
2511713e81bSScott Long void HPTLIBAPI fRAID0SendCommand(_VBUS_ARG PCommand pCmd);
2521713e81bSScott Long void HPTLIBAPI fRAID1SendCommand(_VBUS_ARG PCommand pCmd);
2531713e81bSScott Long void HPTLIBAPI fJBODSendCommand(_VBUS_ARG PCommand pCmd);
2541713e81bSScott Long void HPTLIBAPI fRAID0MemberFailed(_VBUS_ARG PVDevice pVDev);
2551713e81bSScott Long void HPTLIBAPI fRAID1MemberFailed(_VBUS_ARG PVDevice pVDev);
2561713e81bSScott Long void HPTLIBAPI fJBODMemberFailed(_VBUS_ARG PVDevice pVDev);
2571713e81bSScott Long #if SUPPORT_RAID5
2581713e81bSScott Long void HPTLIBAPI fRAID5SendCommand(_VBUS_ARG PCommand pCmd);
2591713e81bSScott Long void HPTLIBAPI fRAID5MemberFailed(_VBUS_ARG PVDevice pVDev);
2601713e81bSScott Long #else
2611713e81bSScott Long #define fRAID5SendCommand 0
2621713e81bSScott Long #define fRAID5MemberFailed 0
2631713e81bSScott Long #endif
2641713e81bSScott Long 
2651713e81bSScott Long #endif
266