2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2004-2005 HighPoint Technologies, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 /***************************************************************************
35 * Description: virtual device header
36 ***************************************************************************/
38 typedef struct _VDevice
41 UCHAR vf_bootmark: 1; /* is boot device? */
42 UCHAR vf_bootable: 1; /* has active partition */
43 UCHAR vf_online: 1; /* is usable? */
44 UCHAR vf_cache_disk: 1; /* Cache enabled */
45 UCHAR vf_format_v2: 1; /* old array block */
46 UCHAR vf_freed: 1; /* memory free */
48 UCHAR bSerialNumber; /* valid if pParent!=0 */
50 PVDevice pParent; /* parent array */
51 PVBus pVBus; /* vbus this device located. Must not be NULL. */
53 LBA_T VDeviceCapacity; /* number of blocks */
57 USHORT ActiveRequests;
58 PCommand LockWaitList;
59 void (* HPTLIBAPI QuiesceAction)(_VBUS_ARG void *arg);
61 void (* HPTLIBAPI flush_callback)(_VBUS_ARG void *arg);
62 void *flush_callback_arg;
66 struct stripe **CacheEntry;
67 struct range_lock *range_lock;
70 void (* HPTLIBAPI pfnSendCommand)(_VBUS_ARG PCommand pCmd); /* call this to send a command to a VDevice */
71 void (* HPTLIBAPI pfnDeviceFailed)(_VBUS_ARG PVDevice pVDev); /* call this when a VDevice failed */
82 #define ARRAY_VDEV_SIZE (offsetof(VDevice, u) + sizeof(RaidArray))
83 #define DISK_VDEV_SIZE (offsetof(VDevice, u) + sizeof(Device))
85 #define Map2pVDevice(pDev) ((PVDevice)((UINT_PTR)pDev - (UINT)(UINT_PTR)&((PVDevice)0)->u.disk))
90 #define MEMBER_NOT_SET_MODE 0x5F
96 #define VD_REMOVABLE 1
98 #define VD_SINGLE_DISK 3
100 #define VD_JBOD 4 /* JBOD */
101 #define VD_RAID_0 5 /* RAID 0 stripe */
102 #define VD_RAID_1 6 /* RAID 1 mirror */
103 #define VD_RAID_3 7 /* RAID 3 */
104 #define VD_RAID_5 8 /* RAID 5 */
105 #define VD_MAX_TYPE 8
108 #define mIsArray(pVDev) (pVDev->VDeviceType>VD_SINGLE_DISK)
110 #define mIsArray(pVDev) 0
113 extern void (* HPTLIBAPI pfnSendCommand[])(_VBUS_ARG PCommand pCmd);
114 extern void (* HPTLIBAPI pfnDeviceFailed[])(_VBUS_ARG PVDevice pVDev);
115 void HPTLIBAPI fOsDiskFailed(_VBUS_ARG PVDevice pVDev);
116 void HPTLIBAPI fDeviceSendCommand(_VBUS_ARG PCommand pCmd);
117 void HPTLIBAPI fSingleDiskFailed(_VBUS_ARG PVDevice pVDev);
119 /***************************************************************************
120 * Description: RAID Adapter
121 ***************************************************************************/
123 typedef struct _VBus {
124 /* pVDevice[] may be non-continuous */
125 PVDevice pVDevice[MAX_VDEVICE_PER_VBUS];
128 PChipInstance pChipInstance[MAX_CHIP_IN_VBUS];
130 void * OsExt; /* for OS private use */
139 PCommand pFreeCommands;
140 DPC_ROUTINE PendingRoutines[MAX_PENDING_ROUTINES];
141 int PendingRoutinesFirst, PendingRoutinesLast;
142 DPC_ROUTINE IdleRoutines[MAX_IDLE_ROUTINES];
143 int IdleRoutinesFirst, IdleRoutinesLast;
146 PVDevice pFreeArrayLink;
147 BYTE _ArrayTables[MAX_ARRAY_PER_VBUS * ARRAY_VDEV_SIZE];
152 struct r5_global_data r5;
158 * Array members must be on same VBus.
159 * The platform dependent part shall select one of the following strategy.
161 #ifdef SET_VBUS_FOR_EACH_IRQ
162 #define CHIP_ON_SAME_VBUS(pChip1, pChip2) ((pChip1)->bChipIntrNum==(pChip2)->bChipIntrNum)
163 #elif defined(SET_VBUS_FOR_EACH_CONTROLLER)
164 #define CHIP_ON_SAME_VBUS(pChip1, pChip2) \
165 ((pChip1)->pci_bus==(pChip2)->pci_bus && (pChip1)->pci_dev==(pChip2)->pci_dev)
166 #elif defined(SET_VBUS_FOR_EACH_FUNCTION)
167 #define CHIP_ON_SAME_VBUS(pChip1, pChip2) \
168 ((pChip1)->pci_bus==(pChip2)->pci_bus && (pChip1)->pci_dev==(pChip2)->pci_dev && (pChip1)->pci_func==(pChip2)->pci_func)
170 #error You must set one vbus setting
173 #define FOR_EACH_CHANNEL_ON_VBUS(_pVBus, _pChan) \
174 for (_pChan=pChanStart; _pChan<pChanEnd; _pChan++) \
175 if (_pChan->pChipInstance->pVBus!=_pVBus) ; else
177 #define FOR_EACH_DEV_ON_VBUS(pVBus, pVDev, i) \
178 for(i = 0; i < MAX_VDEVICE_PER_VBUS; i++) \
179 if ((pVDev=pVBus->pVDevice[i])==0) continue; else
182 #define FOR_EACH_VBUS(pVBus) \
183 for(pVBus = gVBus; pVBus < &gVBus[MAX_VBUS]; pVBus++) \
185 #define FOR_EACH_ARRAY_ON_ALL_VBUS(pVBus, pArray, i) \
186 for(pVBus = gVBus; pVBus < &gVBus[MAX_VBUS]; pVBus++) \
187 for(i = 0; i < MAX_ARRAY_PER_VBUS; i++) \
188 if ((pArray=((PVDevice)&pVBus->_ArrayTables[i*ARRAY_VDEV_SIZE]))->u.array.dArStamp==0) continue; else
190 #define FOR_EACH_DEV_ON_ALL_VBUS(pVBus, pVDev, i) \
191 FOR_EACH_VBUS(pVBus) \
192 for(i = 0; i < MAX_VDEVICE_PER_VBUS; i++) \
193 if ((pVDev=pVBus->pVDevice[i])==0) continue; else
195 /***************************************************************************
196 * Description: the functions called by IDE layer
197 ***************************************************************************/
199 #define IdeRegisterDevice fCheckArray
201 void HPTLIBAPI IdeRegisterDevice(PDevice pDev);
204 /***************************************************************************
205 * Description: the functions OS must provided
206 ***************************************************************************/
208 void HPTLIBAPI OsSetDeviceTable(PDevice pDevice, PIDENTIFY_DATA pIdentify);
211 * allocate and free data structure
213 PChannel fGetChannelTable(void);
214 PDevice fGetDeviceTable(void);
215 #define OsGetChannelTable(x, y) fGetChannelTable()
216 #define OsGetDeviceTable(x, y) fGetDeviceTable()
217 void OsReturnTable(PDevice pDevice);
218 /***************************************************************************
219 * Description: the functions Prototype
220 ***************************************************************************/
224 int Initialize(void);
225 int InitializeAllChips(void);
226 void InitializeVBus(PVBus pVBus);
227 void fRegisterChip(PChipInstance pChip);
228 void __fRegisterVDevices(PVBus pVBus);
229 void fRegisterVDevices(void);
230 void HPTLIBAPI UnregisterVDevice(PVDevice);
231 void HPTLIBAPI fCheckBootable(PVDevice pVDev);
232 void HPTLIBAPI fFlushVDev(PVDevice pVDev);
233 void HPTLIBAPI fFlushVDevAsync(PVDevice pVDev, DPC_PROC done, void *arg);
234 void HPTLIBAPI fShutdownVDev(PVDevice pVDev);
235 void HPTLIBAPI fResetVBus(_VBUS_ARG0);
236 void HPTLIBAPI fCompleteAllCommandsSynchronously(PVBus _vbus_p);
238 #define RegisterVDevice(pVDev)
239 #define OsRegisterDevice(pVDev)
240 #define OsUnregisterDevice(pVDev)
242 #ifdef SUPPORT_VBUS_CONFIG
243 void VBus_Config(PVBus pVBus, char *str);
245 #define VBus_Config(pVBus, str)
249 struct fdisk_partition_table
251 UCHAR bootid; /* bootable? 0=no, 128=yes */
252 UCHAR beghead; /* beginning head number */
253 UCHAR begsect; /* beginning sector number */
254 UCHAR begcyl; /* 10 bit nmbr, with high 2 bits put in begsect */
255 UCHAR systid; /* Operating System type indicator code */
256 UCHAR endhead; /* ending head number */
257 UCHAR endsect; /* ending sector number */
258 UCHAR endcyl; /* also a 10 bit nmbr, with same high 2 bit trick */
259 ULONG relsect; /* first sector relative to start of disk */
260 ULONG numsect; /* number of sectors in partition */
263 typedef struct _Master_Boot_Record
265 UCHAR bootinst[446]; /* space to hold actual boot code */
266 struct fdisk_partition_table parts[4];
267 USHORT signature; /* set to 0xAA55 to indicate PC MBR format */
269 Master_Boot_Record, *PMaster_Boot_Record;
271 #ifndef SUPPORT_ARRAY
272 /* TODO: move it later */
273 #ifdef __BIG_ENDIAN_BITFIELD
274 typedef DWORD TIME_RECORD;
276 typedef struct _TIME_RECORD {
277 UINT seconds:6; /* 0 - 59 */
278 UINT minutes:6; /* 0 - 59 */
279 UINT month:4; /* 1 - 12 */
280 UINT hours:6; /* 0 - 59 */
281 UINT day:5; /* 1 - 31 */
282 UINT year:5; /* 0=2000, 31=2031 */