xref: /freebsd/sys/dev/hptmv/array.h (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
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.
27d38d9c9eSScott Long  *
28d38d9c9eSScott Long  * $FreeBSD$
291713e81bSScott Long  */
301713e81bSScott Long 
311713e81bSScott Long #ifndef _ARRAY_H_
321713e81bSScott Long #define _ARRAY_H_
331713e81bSScott Long 
341713e81bSScott Long /*
351713e81bSScott Long  * time represented in DWORD format
361713e81bSScott Long  */
371713e81bSScott Long #pragma pack(1)
381713e81bSScott Long #ifdef __BIG_ENDIAN_BITFIELD
391713e81bSScott Long typedef DWORD TIME_RECORD;
401713e81bSScott Long #else
411713e81bSScott Long typedef struct _TIME_RECORD {
421713e81bSScott Long    UINT        seconds:6;      /* 0 - 59 */
431713e81bSScott Long    UINT        minutes:6;      /* 0 - 59 */
441713e81bSScott Long    UINT        month:4;        /* 1 - 12 */
451713e81bSScott Long    UINT        hours:6;        /* 0 - 59 */
461713e81bSScott Long    UINT        day:5;          /* 1 - 31 */
471713e81bSScott Long    UINT        year:5;         /* 0=2000, 31=2031 */
481713e81bSScott Long } TIME_RECORD;
491713e81bSScott Long #endif
501713e81bSScott Long #pragma pack()
511713e81bSScott Long 
521713e81bSScott Long /***************************************************************************
531713e81bSScott Long  * Description: Virtual Device Table
541713e81bSScott Long  ***************************************************************************/
551713e81bSScott Long 
561713e81bSScott Long typedef struct _RaidArray
571713e81bSScott Long {
581713e81bSScott Long     /*
591713e81bSScott Long      * basic information
601713e81bSScott Long      */
611713e81bSScott Long     UCHAR   bArnMember;        /* the number of members in array */
621713e81bSScott Long     UCHAR   bArRealnMember;    /* real member count */
631713e81bSScott Long     UCHAR   bArBlockSizeShift; /* the number of shift bit for a block */
641713e81bSScott Long     UCHAR   reserve1;
651713e81bSScott Long 
661713e81bSScott Long     ULONG   dArStamp;          /* array ID. all disks in a array has same ID */
6764470755SXin LI 	ULONG   failedStamps[4];   /* stamp for failed members */
681713e81bSScott Long     USHORT  bStripeWitch;      /* = (1 << BlockSizeShift) */
691713e81bSScott Long 
701713e81bSScott Long 	USHORT	rf_broken: 1;
711713e81bSScott Long 	USHORT	rf_need_rebuild: 1;			/* one member's data are incorrect.
721713e81bSScott Long 	                                       for R5, if CriticalMembers==0, it means
731713e81bSScott Long 										   parity needs to be constructed */
741713e81bSScott Long 	USHORT	rf_need_sync: 1;			/* need write array info to disk */
751713e81bSScott Long 	/* ioctl flags */
761713e81bSScott Long 	USHORT  rf_auto_rebuild: 1;
771713e81bSScott Long 	USHORT  rf_newly_created: 1;
781713e81bSScott Long 	USHORT  rf_rebuilding: 1;
791713e81bSScott Long 	USHORT  rf_verifying: 1;
801713e81bSScott Long 	USHORT  rf_initializing: 1;
811713e81bSScott Long 	USHORT  rf_abort_rebuild: 1;
821713e81bSScott Long 	USHORT  rf_duplicate_and_create: 1;
831713e81bSScott Long 	USHORT  rf_duplicate_and_created: 1;
841713e81bSScott Long 	USHORT  rf_duplicate_must_done: 1;
851713e81bSScott Long 	USHORT  rf_raid15: 1;
861713e81bSScott Long 
871713e81bSScott Long 	USHORT  CriticalMembers;   /* tell which member is critial */
881713e81bSScott Long 	UCHAR   last_read;       /* for RAID 1 load banlancing */
8964470755SXin LI 	UCHAR   alreadyBroken;
901713e81bSScott Long 
911713e81bSScott Long 	LBA_T   RebuildSectors;  /* how many sectors is OK (LBA on member disk) */
921713e81bSScott Long 
931713e81bSScott Long     PVDevice pMember[MAX_MEMBERS];
941713e81bSScott Long     /*
951713e81bSScott Long      * utility working data
961713e81bSScott Long      */
971713e81bSScott Long     UCHAR   ArrayName[MAX_ARRAY_NAME];  /* The Name of the array */
981713e81bSScott Long 	TIME_RECORD CreateTime;				/* when created it */
991713e81bSScott Long 	UCHAR	Description[64];		/* array description */
1001713e81bSScott Long 	UCHAR	CreateManager[16];		/* who created it */
1011713e81bSScott Long } RaidArray;
1021713e81bSScott Long 
1031713e81bSScott Long /***************************************************************************
104453130d9SPedro F. Giffuni  *            Array Description on disk
1051713e81bSScott Long  ***************************************************************************/
1061713e81bSScott Long #pragma pack(1)
1071713e81bSScott Long typedef struct _ArrayDescript
1081713e81bSScott Long {
1091713e81bSScott Long 	ULONG   Signature;      	/* This block is vaild array info block */
1101713e81bSScott Long     ULONG   dArStamp;          	/* array ID. all disks in a array has same ID */
1111713e81bSScott Long 
1121713e81bSScott Long 	UCHAR   bCheckSum;          /* check sum of ArrayDescript_3_0_size bytes */
1131713e81bSScott Long 
1141713e81bSScott Long #ifdef __BIG_ENDIAN_BITFIELD
1151713e81bSScott Long 	UCHAR   df_reservedbits: 6; /* put more flags here */
1161713e81bSScott Long     UCHAR   df_user_mode_set: 1;/* user select device mode */
1171713e81bSScott Long     UCHAR   df_bootmark:1;      /* user set boot mark on the disk */
1181713e81bSScott Long #else
1191713e81bSScott Long     UCHAR   df_bootmark:1;      /* user set boot mark on the disk */
1201713e81bSScott Long     UCHAR   df_user_mode_set: 1;/* user select device mode */
1211713e81bSScott Long 	UCHAR   df_reservedbits: 6; /* put more flags here */
1221713e81bSScott Long #endif
1231713e81bSScott Long 
1241713e81bSScott Long     UCHAR   bUserDeviceMode;	/* see device.h */
1251713e81bSScott Long     UCHAR   ArrayLevel;			/* how many level[] is valid */
1261713e81bSScott Long 
1271713e81bSScott Long 	struct {
1281713e81bSScott Long 	    ULONG   Capacity;         	/* capacity for the array */
1291713e81bSScott Long 
1301713e81bSScott Long 		UCHAR   VDeviceType;  		/* see above & arrayType in array.h */
1311713e81bSScott Long 	    UCHAR   bMemberCount;		/* all disk in the array */
1321713e81bSScott Long 	    UCHAR   bSerialNumber;  	/* Serial Number	*/
1331713e81bSScott Long 	    UCHAR   bArBlockSizeShift; 	/* the number of shift bit for a block */
1341713e81bSScott Long 
1351713e81bSScott Long #ifdef __BIG_ENDIAN_BITFIELD
1361713e81bSScott Long 		USHORT  rf_reserved: 14;
1371713e81bSScott Long 		USHORT  rf_raid15: 1;       /* don't remove even you don't use it */
1381713e81bSScott Long 		USHORT  rf_need_rebuild:1;  /* array is critical */
1391713e81bSScott Long #else
1401713e81bSScott Long 		USHORT  rf_need_rebuild:1;  /* array is critical */
1411713e81bSScott Long 		USHORT  rf_raid15: 1;       /* don't remove even you don't use it */
1421713e81bSScott Long 		USHORT  rf_reserved: 14;
1431713e81bSScott Long #endif
1441713e81bSScott Long 		USHORT  CriticalMembers;    /* record critical members */
1451713e81bSScott Long 		ULONG   RebuildSectors;  /* how many sectors is OK (LBA on member disk) */
1461713e81bSScott Long 	} level[2];
1471713e81bSScott Long 
1481713e81bSScott Long     UCHAR   ArrayName[MAX_ARRAY_NAME];  /* The Name of the array */
1491713e81bSScott Long 	TIME_RECORD CreateTime;				/* when created it */
1501713e81bSScott Long 	UCHAR	Description[64];		/* array description */
1511713e81bSScott Long 	UCHAR	CreateManager[16];		/* who created it */
1521713e81bSScott Long 
1531713e81bSScott Long #define ArrayDescript_3_0_size ((unsigned)(ULONG_PTR)&((struct _ArrayDescript *)0)->bCheckSum31)
1541713e81bSScott Long #define ArrayDescript_3_1_size 512
1551713e81bSScott Long 
1561713e81bSScott Long 	UCHAR   bCheckSum31;        /* new check sum */
157d2bd3ab9SScott Long 	UCHAR   PrivateFlag1;       /* private */
15864470755SXin LI 	UCHAR   alreadyBroken;      /* last stamp has been saved to failedStamps */
159d2bd3ab9SScott Long 
1601713e81bSScott Long #ifdef __BIG_ENDIAN_BITFIELD
1611713e81bSScott Long     UCHAR   df_read_ahead: 1;   /* enable read ahead */
1621713e81bSScott Long 	UCHAR   df_read_ahead_set: 1;
1631713e81bSScott Long     UCHAR   df_write_cache: 1;  /* enable write cache */
1641713e81bSScott Long 	UCHAR   df_write_cache_set: 1;
1651713e81bSScott Long     UCHAR   df_ncq: 1;          /* enable NCQ */
1661713e81bSScott Long 	UCHAR   df_ncq_set: 1;
1671713e81bSScott Long     UCHAR   df_tcq: 1;          /* enable TCQ */
1681713e81bSScott Long 	UCHAR   df_tcq_set: 1;
1691713e81bSScott Long #else
1701713e81bSScott Long 	UCHAR   df_tcq_set: 1;
1711713e81bSScott Long     UCHAR   df_tcq: 1;          /* enable TCQ */
1721713e81bSScott Long 	UCHAR   df_ncq_set: 1;
1731713e81bSScott Long     UCHAR   df_ncq: 1;          /* enable NCQ */
1741713e81bSScott Long 	UCHAR   df_write_cache_set: 1;
1751713e81bSScott Long     UCHAR   df_write_cache: 1;  /* enable write cache */
1761713e81bSScott Long 	UCHAR   df_read_ahead_set: 1;
1771713e81bSScott Long     UCHAR   df_read_ahead: 1;   /* enable read ahead */
1781713e81bSScott Long #endif
1791713e81bSScott Long 
1801713e81bSScott Long     struct {
1811713e81bSScott Long     	ULONG CapacityHi32;
1821713e81bSScott Long     	ULONG RebuildSectorsHi32;
1831713e81bSScott Long     }
1841713e81bSScott Long     levelex[2];
1851713e81bSScott Long 
18664470755SXin LI 	ULONG failedStamps[4]; /* failed memebrs's stamps */
187d2bd3ab9SScott Long 
1881713e81bSScott Long } ArrayDescript;
1891713e81bSScott Long 
190d2bd3ab9SScott Long /* report an error if ArrayDescript size exceed 512 */
191d2bd3ab9SScott Long typedef char ArrayDescript_size_should_not_exceed_512[512-sizeof(ArrayDescript)];
192d2bd3ab9SScott Long 
1931713e81bSScott Long #pragma pack()
1941713e81bSScott Long 
1951713e81bSScott Long /* Signature */
1961713e81bSScott Long #define HPT_ARRAY_V3          0x5a7816f3
1971713e81bSScott Long #ifdef ARRAY_V2_ONLY
1981713e81bSScott Long #define SAVE_FOR_RAID_INFO    0
1991713e81bSScott Long #else
2001713e81bSScott Long #define SAVE_FOR_RAID_INFO    10
2011713e81bSScott Long #endif
2021713e81bSScott Long 
2031713e81bSScott Long /***************************************************************************
2041713e81bSScott Long  *  Function protocol for array layer
2051713e81bSScott Long  ***************************************************************************/
2061713e81bSScott Long 
2071713e81bSScott Long /*
2081713e81bSScott Long  * array.c
2091713e81bSScott Long  */
2101713e81bSScott Long ULONG FASTCALL GetStamp(void);
2111713e81bSScott Long void HPTLIBAPI SyncArrayInfo(PVDevice pVDev);
2121713e81bSScott Long void HPTLIBAPI fDeleteArray(_VBUS_ARG PVDevice pVArray, BOOLEAN del_block0);
2131713e81bSScott Long 
2141713e81bSScott Long /*
2151713e81bSScott Long  * iArray.c
2161713e81bSScott Long  */
2171713e81bSScott Long void HPTLIBAPI fCheckArray(PDevice pDevice);
2181713e81bSScott Long void HPTLIBAPI CheckArrayCritical(_VBUS_ARG0);
2191713e81bSScott Long PVDevice HPTLIBAPI GetSpareDisk(_VBUS_ARG PVDevice pArray);
2201713e81bSScott Long #ifdef SUPPORT_OLD_ARRAY
2211713e81bSScott Long void HPTLIBAPI fFixRAID01Stripe(_VBUS_ARG PVDevice pStripe);
2221713e81bSScott Long #endif
2231713e81bSScott Long 
2241713e81bSScott Long /***************************************************************************
2251713e81bSScott Long  *  Macro defination
2261713e81bSScott Long  ***************************************************************************/
2271713e81bSScott Long #ifndef MAX_ARRAY_PER_VBUS
2281713e81bSScott Long #define MAX_ARRAY_PER_VBUS (MAX_VDEVICE_PER_VBUS*2) /* worst case */
2291713e81bSScott Long #endif
2301713e81bSScott Long 
2311713e81bSScott Long 
2321713e81bSScott Long #if defined(MAX_ARRAY_DEVICE)
2331713e81bSScott Long #if MAX_ARRAY_DEVICE!=MAX_ARRAY_PER_VBUS
2341713e81bSScott Long #error "remove MAX_ARRAY_DEVICE and use MAX_ARRAY_PER_VBUS instead"
2351713e81bSScott Long #endif
2361713e81bSScott Long #endif
2371713e81bSScott Long 
2381713e81bSScott Long #define _SET_ARRAY_BUS_(pArray) pArray->pVBus = _vbus_p;
2391713e81bSScott Long 
2401713e81bSScott Long #ifdef ARRAY_V2_ONLY
2411713e81bSScott Long #define _SET_ARRAY_VER_(pArray) pArray->vf_format_v2 = 1;
2421713e81bSScott Long #else
2431713e81bSScott Long #define _SET_ARRAY_VER_(pArray)
2441713e81bSScott Long #endif
2451713e81bSScott Long 
2461713e81bSScott Long #define mArGetArrayTable(pVArray) \
2471713e81bSScott Long 	if((pVArray = _vbus_(pFreeArrayLink)) != 0) { \
2481713e81bSScott Long     	_vbus_(pFreeArrayLink) = (PVDevice)_vbus_(pFreeArrayLink)->pVBus; \
2491713e81bSScott Long     	ZeroMemory(pVArray, ARRAY_VDEV_SIZE); \
2501713e81bSScott Long 		_SET_ARRAY_BUS_(pVArray) \
2511713e81bSScott Long 		_SET_ARRAY_VER_(pVArray) \
2521713e81bSScott Long     } else
2531713e81bSScott Long 
2541713e81bSScott Long #define mArFreeArrayTable(pVArray) \
2551713e81bSScott Long 	do { \
2561713e81bSScott Long 		pVArray->pVBus = (PVBus)_vbus_(pFreeArrayLink);\
2571713e81bSScott Long     	_vbus_(pFreeArrayLink) = pVArray; \
2581713e81bSScott Long     	pVArray->u.array.dArStamp = 0; \
2591713e81bSScott Long     } while(0)
2601713e81bSScott Long 
2611713e81bSScott Long UCHAR CheckSum(UCHAR *p, int size);
2621713e81bSScott Long 
2631713e81bSScott Long void HPTLIBAPI fRAID0SendCommand(_VBUS_ARG PCommand pCmd);
2641713e81bSScott Long void HPTLIBAPI fRAID1SendCommand(_VBUS_ARG PCommand pCmd);
2651713e81bSScott Long void HPTLIBAPI fJBODSendCommand(_VBUS_ARG PCommand pCmd);
2661713e81bSScott Long void HPTLIBAPI fRAID0MemberFailed(_VBUS_ARG PVDevice pVDev);
2671713e81bSScott Long void HPTLIBAPI fRAID1MemberFailed(_VBUS_ARG PVDevice pVDev);
2681713e81bSScott Long void HPTLIBAPI fJBODMemberFailed(_VBUS_ARG PVDevice pVDev);
2691713e81bSScott Long #if SUPPORT_RAID5
2701713e81bSScott Long void HPTLIBAPI fRAID5SendCommand(_VBUS_ARG PCommand pCmd);
2711713e81bSScott Long void HPTLIBAPI fRAID5MemberFailed(_VBUS_ARG PVDevice pVDev);
2721713e81bSScott Long #else
2731713e81bSScott Long #define fRAID5SendCommand 0
2741713e81bSScott Long #define fRAID5MemberFailed 0
2751713e81bSScott Long #endif
2761713e81bSScott Long 
2771713e81bSScott Long #endif
278