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