xref: /freebsd/sys/dev/hptmv/vdevice.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 _VDEVICE_H_
301713e81bSScott Long #define _VDEVICE_H_
311713e81bSScott Long 
321713e81bSScott Long /***************************************************************************
331713e81bSScott Long  * Description:  virtual device header
341713e81bSScott Long  ***************************************************************************/
351713e81bSScott Long 
361713e81bSScott Long typedef  struct _VDevice
371713e81bSScott Long {
381713e81bSScott Long 	UCHAR        VDeviceType;
391713e81bSScott Long 	UCHAR        vf_bootmark: 1; 	/* is boot device? */
401713e81bSScott Long 	UCHAR		 vf_bootable: 1;    /* has active partition */
411713e81bSScott Long 	UCHAR        vf_online: 1; 		/* is usable? */
421713e81bSScott Long 	UCHAR        vf_cache_disk: 1;  /* Cache enabled */
431713e81bSScott Long 	UCHAR        vf_format_v2: 1;   /* old array block */
441713e81bSScott Long 	UCHAR        vf_freed: 1;       /* memory free */
451713e81bSScott Long 	UCHAR        reserve1;
461713e81bSScott Long 	UCHAR        bSerialNumber; 	/* valid if pParent!=0 */
471713e81bSScott Long 
481713e81bSScott Long 	PVDevice	 pParent;			/* parent array */
491713e81bSScott Long 	PVBus        pVBus;				/* vbus this device located. Must not be NULL. */
501713e81bSScott Long 
511713e81bSScott Long 	LBA_T        VDeviceCapacity;   /* number of blocks */
521713e81bSScott Long 
531713e81bSScott Long 	LBA_T        LockedLba;
541713e81bSScott Long 	USHORT       LockedSectors;
551713e81bSScott Long 	USHORT       ActiveRequests;
561713e81bSScott Long 	PCommand     LockWaitList;
571713e81bSScott Long 	void (* HPTLIBAPI QuiesceAction)(_VBUS_ARG void *arg);
581713e81bSScott Long 	void  *QuiesceArg;
591713e81bSScott Long 	void (* HPTLIBAPI flush_callback)(_VBUS_ARG void *arg);
601713e81bSScott Long 	void *flush_callback_arg;
611713e81bSScott Long 
621713e81bSScott Long 
631713e81bSScott Long #if defined(_RAID5N_)
641713e81bSScott Long 	struct stripe **CacheEntry;
651713e81bSScott Long 	struct range_lock *range_lock;
661713e81bSScott Long #endif
671713e81bSScott Long 
681713e81bSScott Long 	void (* HPTLIBAPI pfnSendCommand)(_VBUS_ARG PCommand pCmd);   /* call this to send a command to a VDevice */
691713e81bSScott Long 	void (* HPTLIBAPI pfnDeviceFailed)(_VBUS_ARG PVDevice pVDev); /* call this when a VDevice failed */
701713e81bSScott Long 
711713e81bSScott Long 	union {
721713e81bSScott Long #ifdef SUPPORT_ARRAY
731713e81bSScott Long 		RaidArray array;
741713e81bSScott Long #endif
751713e81bSScott Long 		Device disk;
761713e81bSScott Long 	} u;
771713e81bSScott Long 
781713e81bSScott Long } VDevice;
791713e81bSScott Long 
8032981ab8SRyan Libby #define ARRAY_VDEV_SIZE (offsetof(VDevice, u) + sizeof(RaidArray))
8132981ab8SRyan Libby #define DISK_VDEV_SIZE  (offsetof(VDevice, u) + sizeof(Device))
821713e81bSScott Long 
831713e81bSScott Long #define Map2pVDevice(pDev) ((PVDevice)((UINT_PTR)pDev - (UINT)(UINT_PTR)&((PVDevice)0)->u.disk))
841713e81bSScott Long 
851713e81bSScott Long /*
861713e81bSScott Long  * bUserDeviceMode
871713e81bSScott Long  */
881713e81bSScott Long #define MEMBER_NOT_SET_MODE  0x5F
891713e81bSScott Long 
901713e81bSScott Long /*
911713e81bSScott Long  * arrayType
921713e81bSScott Long  */
931713e81bSScott Long #define VD_SPARE             0
941713e81bSScott Long #define VD_REMOVABLE         1
951713e81bSScott Long #define VD_ATAPI             2
961713e81bSScott Long #define VD_SINGLE_DISK       3
971713e81bSScott Long 
981713e81bSScott Long #define VD_JBOD              4 /* JBOD */
991713e81bSScott Long #define VD_RAID_0            5 /* RAID 0 stripe */
1001713e81bSScott Long #define VD_RAID_1            6 /* RAID 1 mirror */
1011713e81bSScott Long #define VD_RAID_3            7 /* RAID 3 */
1021713e81bSScott Long #define VD_RAID_5            8 /* RAID 5 */
1031713e81bSScott Long #define VD_MAX_TYPE 8
1041713e81bSScott Long 
1051713e81bSScott Long #ifdef SUPPORT_ARRAY
1061713e81bSScott Long #define mIsArray(pVDev) (pVDev->VDeviceType>VD_SINGLE_DISK)
1071713e81bSScott Long #else
1081713e81bSScott Long #define mIsArray(pVDev) 0
1091713e81bSScott Long #endif
1101713e81bSScott Long 
1111713e81bSScott Long extern void (* HPTLIBAPI pfnSendCommand[])(_VBUS_ARG PCommand pCmd);
1121713e81bSScott Long extern void (* HPTLIBAPI pfnDeviceFailed[])(_VBUS_ARG PVDevice pVDev);
1131713e81bSScott Long void HPTLIBAPI fOsDiskFailed(_VBUS_ARG PVDevice pVDev);
1141713e81bSScott Long void HPTLIBAPI fDeviceSendCommand(_VBUS_ARG PCommand pCmd);
1151713e81bSScott Long void HPTLIBAPI fSingleDiskFailed(_VBUS_ARG PVDevice pVDev);
1161713e81bSScott Long 
1171713e81bSScott Long /***************************************************************************
1181713e81bSScott Long  * Description:  RAID Adapter
1191713e81bSScott Long  ***************************************************************************/
1201713e81bSScott Long 
1211713e81bSScott Long typedef struct _VBus  {
1221713e81bSScott Long 	/* pVDevice[] may be non-continuous */
1231713e81bSScott Long 	PVDevice      pVDevice[MAX_VDEVICE_PER_VBUS];
1241713e81bSScott Long 
1251713e81bSScott Long 	UINT          nInstances;
1261713e81bSScott Long 	PChipInstance pChipInstance[MAX_CHIP_IN_VBUS];
1271713e81bSScott Long 
1281713e81bSScott Long 	void *        OsExt; /* for OS private use */
1291713e81bSScott Long 
1301713e81bSScott Long 
1311713e81bSScott Long 	int serial_mode;
1321713e81bSScott Long 	int next_active;
1331713e81bSScott Long 	int working_devs;
1341713e81bSScott Long 
1351713e81bSScott Long 
1361713e81bSScott Long 
1371713e81bSScott Long 	PCommand pFreeCommands;
1381713e81bSScott Long 	DPC_ROUTINE PendingRoutines[MAX_PENDING_ROUTINES];
1391713e81bSScott Long 	int PendingRoutinesFirst, PendingRoutinesLast;
1401713e81bSScott Long 	DPC_ROUTINE IdleRoutines[MAX_IDLE_ROUTINES];
1411713e81bSScott Long 	int IdleRoutinesFirst, IdleRoutinesLast;
1421713e81bSScott Long 
1431713e81bSScott Long #ifdef SUPPORT_ARRAY
1441713e81bSScott Long 	PVDevice pFreeArrayLink;
1451713e81bSScott Long 	BYTE    _ArrayTables[MAX_ARRAY_PER_VBUS * ARRAY_VDEV_SIZE];
1461713e81bSScott Long #endif
1471713e81bSScott Long 
1481713e81bSScott Long 
1491713e81bSScott Long #ifdef _RAID5N_
1501713e81bSScott Long 	struct r5_global_data r5;
1511713e81bSScott Long #endif
1521713e81bSScott Long 
1531713e81bSScott Long } VBus;
1541713e81bSScott Long 
1551713e81bSScott Long /*
1561713e81bSScott Long  * Array members must be on same VBus.
1571713e81bSScott Long  * The platform dependent part shall select one of the following strategy.
1581713e81bSScott Long  */
1591713e81bSScott Long #ifdef SET_VBUS_FOR_EACH_IRQ
1601713e81bSScott Long #define CHIP_ON_SAME_VBUS(pChip1, pChip2) ((pChip1)->bChipIntrNum==(pChip2)->bChipIntrNum)
1611713e81bSScott Long #elif defined(SET_VBUS_FOR_EACH_CONTROLLER)
1621713e81bSScott Long #define CHIP_ON_SAME_VBUS(pChip1, pChip2) \
1631713e81bSScott Long 	((pChip1)->pci_bus==(pChip2)->pci_bus && (pChip1)->pci_dev==(pChip2)->pci_dev)
1641713e81bSScott Long #elif defined(SET_VBUS_FOR_EACH_FUNCTION)
1651713e81bSScott Long #define CHIP_ON_SAME_VBUS(pChip1, pChip2) \
1661713e81bSScott Long 	((pChip1)->pci_bus==(pChip2)->pci_bus && (pChip1)->pci_dev==(pChip2)->pci_dev && (pChip1)->pci_func==(pChip2)->pci_func)
1671713e81bSScott Long #else
1681713e81bSScott Long #error You must set one vbus setting
1691713e81bSScott Long #endif
1701713e81bSScott Long 
1711713e81bSScott Long #define FOR_EACH_CHANNEL_ON_VBUS(_pVBus, _pChan) \
1721713e81bSScott Long 		for (_pChan=pChanStart; _pChan<pChanEnd; _pChan++) \
1731713e81bSScott Long 			if (_pChan->pChipInstance->pVBus!=_pVBus) ; else
1741713e81bSScott Long 
1751713e81bSScott Long #define FOR_EACH_DEV_ON_VBUS(pVBus, pVDev, i) \
1761713e81bSScott Long 		for(i = 0; i < MAX_VDEVICE_PER_VBUS; i++) \
1771713e81bSScott Long 			if ((pVDev=pVBus->pVDevice[i])==0) continue; else
1781713e81bSScott Long 
17964470755SXin LI 
18064470755SXin LI #define FOR_EACH_VBUS(pVBus) \
1811713e81bSScott Long 	for(pVBus = gVBus; pVBus < &gVBus[MAX_VBUS]; pVBus++) \
1821713e81bSScott Long 
1831713e81bSScott Long #define FOR_EACH_ARRAY_ON_ALL_VBUS(pVBus, pArray, i) \
1841713e81bSScott Long 	for(pVBus = gVBus; pVBus < &gVBus[MAX_VBUS]; pVBus++) \
1851713e81bSScott Long 		for(i = 0; i < MAX_ARRAY_PER_VBUS; i++) \
1861713e81bSScott Long 			if ((pArray=((PVDevice)&pVBus->_ArrayTables[i*ARRAY_VDEV_SIZE]))->u.array.dArStamp==0) continue; else
1871713e81bSScott Long 
18864470755SXin LI #define FOR_EACH_DEV_ON_ALL_VBUS(pVBus, pVDev, i) \
18964470755SXin LI 	FOR_EACH_VBUS(pVBus) \
19064470755SXin LI 		for(i = 0; i < MAX_VDEVICE_PER_VBUS; i++) \
19164470755SXin LI 			if ((pVDev=pVBus->pVDevice[i])==0) continue; else
19264470755SXin LI 
1931713e81bSScott Long /***************************************************************************
1941713e81bSScott Long  * Description:  the functions called by IDE layer
1951713e81bSScott Long  ***************************************************************************/
1961713e81bSScott Long #ifdef SUPPORT_ARRAY
1971713e81bSScott Long #define IdeRegisterDevice               fCheckArray
1981713e81bSScott Long #else
1991713e81bSScott Long void HPTLIBAPI IdeRegisterDevice(PDevice pDev);
2001713e81bSScott Long #endif
2011713e81bSScott Long 
2021713e81bSScott Long /***************************************************************************
2031713e81bSScott Long  * Description:  the functions OS must provided
2041713e81bSScott Long  ***************************************************************************/
2051713e81bSScott Long 
20664470755SXin LI void HPTLIBAPI OsSetDeviceTable(PDevice pDevice, PIDENTIFY_DATA pIdentify);
2071713e81bSScott Long 
2081713e81bSScott Long /*
2091713e81bSScott Long  * allocate and free data structure
2101713e81bSScott Long  */
2111713e81bSScott Long PChannel fGetChannelTable(void);
2121713e81bSScott Long PDevice  fGetDeviceTable(void);
2131713e81bSScott Long #define  OsGetChannelTable(x, y)  fGetChannelTable()
2141713e81bSScott Long #define  OsGetDeviceTable(x, y)   fGetDeviceTable()
2151713e81bSScott Long void 	OsReturnTable(PDevice pDevice);
2161713e81bSScott Long /***************************************************************************
2171713e81bSScott Long  * Description:  the functions Prototype
2181713e81bSScott Long  ***************************************************************************/
2191713e81bSScott Long /*
2201713e81bSScott Long  * vdevice.c
2211713e81bSScott Long  */
2221713e81bSScott Long int Initialize(void);
2231713e81bSScott Long int InitializeAllChips(void);
2241713e81bSScott Long void InitializeVBus(PVBus pVBus);
2251713e81bSScott Long void fRegisterChip(PChipInstance pChip);
2261713e81bSScott Long void __fRegisterVDevices(PVBus pVBus);
2271713e81bSScott Long void fRegisterVDevices(void);
2281713e81bSScott Long void HPTLIBAPI UnregisterVDevice(PVDevice);
2291713e81bSScott Long void HPTLIBAPI fCheckBootable(PVDevice pVDev);
2301713e81bSScott Long void HPTLIBAPI fFlushVDev(PVDevice pVDev);
2311713e81bSScott Long void HPTLIBAPI fFlushVDevAsync(PVDevice pVDev, DPC_PROC done, void *arg);
2321713e81bSScott Long void HPTLIBAPI fShutdownVDev(PVDevice pVDev);
2331713e81bSScott Long void HPTLIBAPI fResetVBus(_VBUS_ARG0);
2341713e81bSScott Long void HPTLIBAPI fCompleteAllCommandsSynchronously(PVBus _vbus_p);
2351713e81bSScott Long 
2361713e81bSScott Long #define RegisterVDevice(pVDev)
2371713e81bSScott Long #define OsRegisterDevice(pVDev)
2381713e81bSScott Long #define OsUnregisterDevice(pVDev)
2391713e81bSScott Long 
2401713e81bSScott Long #ifdef SUPPORT_VBUS_CONFIG
2411713e81bSScott Long void VBus_Config(PVBus pVBus, char *str);
2421713e81bSScott Long #else
2431713e81bSScott Long #define VBus_Config(pVBus, str)
2441713e81bSScott Long #endif
2451713e81bSScott Long 
2461713e81bSScott Long #pragma pack(1)
2471713e81bSScott Long struct fdisk_partition_table
2481713e81bSScott Long {
2491713e81bSScott Long 	UCHAR 		bootid;   			/* bootable?  0=no, 128=yes  */
2501713e81bSScott Long 	UCHAR 		beghead;  			/* beginning head number */
2511713e81bSScott Long 	UCHAR 		begsect;  			/* beginning sector number */
2521713e81bSScott Long 	UCHAR		begcyl;   			/* 10 bit nmbr, with high 2 bits put in begsect */
2531713e81bSScott Long 	UCHAR		systid;   			/* Operating System type indicator code */
2541713e81bSScott Long 	UCHAR 		endhead;  			/* ending head number */
2551713e81bSScott Long 	UCHAR 		endsect;  			/* ending sector number */
2561713e81bSScott Long 	UCHAR 		endcyl;   			/* also a 10 bit nmbr, with same high 2 bit trick */
257d2bd3ab9SScott Long 	ULONG   	relsect;            /* first sector relative to start of disk */
258d2bd3ab9SScott Long 	ULONG 		numsect;            /* number of sectors in partition */
2591713e81bSScott Long };
2601713e81bSScott Long 
2615b990a94SBaptiste Daroussin typedef struct _Master_Boot_Record
2621713e81bSScott Long {
2631713e81bSScott Long 	UCHAR   bootinst[446];   		/* space to hold actual boot code */
2641713e81bSScott Long 	struct 	fdisk_partition_table parts[4];
2651713e81bSScott Long 	USHORT  signature;       		/* set to 0xAA55 to indicate PC MBR format */
2661713e81bSScott Long }
2675b990a94SBaptiste Daroussin Master_Boot_Record, *PMaster_Boot_Record;
2681713e81bSScott Long 
2691713e81bSScott Long #ifndef SUPPORT_ARRAY
2701713e81bSScott Long /* TODO: move it later */
2711713e81bSScott Long #ifdef __BIG_ENDIAN_BITFIELD
2721713e81bSScott Long typedef DWORD TIME_RECORD;
2731713e81bSScott Long #else
2741713e81bSScott Long typedef struct _TIME_RECORD {
2751713e81bSScott Long    UINT        seconds:6;      /* 0 - 59 */
2761713e81bSScott Long    UINT        minutes:6;      /* 0 - 59 */
2771713e81bSScott Long    UINT        month:4;        /* 1 - 12 */
2781713e81bSScott Long    UINT        hours:6;        /* 0 - 59 */
2791713e81bSScott Long    UINT        day:5;          /* 1 - 31 */
2801713e81bSScott Long    UINT        year:5;         /* 0=2000, 31=2031 */
2811713e81bSScott Long } TIME_RECORD;
2821713e81bSScott Long #endif
2831713e81bSScott Long #endif
2841713e81bSScott Long 
2851713e81bSScott Long #pragma pack()
2861713e81bSScott Long #endif
287