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
36 * Version of this interface.
37 * The user mode application must first issue a hpt_get_version() call to
38 * check HPT_INTERFACE_VERSION. When an utility using newer version interface
39 * is used with old version drivers, it must call only the functions that
41 * A new version interface should only add ioctl functions; it should implement
42 * all old version functions without change their definition.
44 #define __this_HPT_INTERFACE_VERSION 0x01010000
46 #ifndef HPT_INTERFACE_VERSION
47 #error "You must define HPT_INTERFACE_VERSION you implemented"
50 #if HPT_INTERFACE_VERSION > __this_HPT_INTERFACE_VERSION
51 #error "HPT_INTERFACE_VERSION is invalid"
56 * Logical device --- a device that can be accessed by OS.
57 * Physical device --- device attached to the controller.
58 * A logical device can be simply a physical device.
60 * Each logical and physical device has a 32bit ID. GUI will use this ID
61 * to identify devices.
62 * 1. The ID must be unique.
63 * 2. The ID must be immutable. Once an ID is assigned to a device, it
64 * must not change when system is running and the device exists.
65 * 3. The ID of logical device must be NOT reusable. If a device is
66 * removed, other newly created logical device must not use the same ID.
67 * 4. The ID must not be zero or 0xFFFFFFFF.
69 typedef DWORD DEVICEID;
72 * logical device type.
73 * Identify array (logical device) and physical device.
80 * GUI will treat all array as 1-level RAID. No RAID0/1 or RAID1/0.
81 * A RAID0/1 device is type AT_RAID1. A RAID1/0 device is type AT_RAID0.
82 * Their members may be another array of type RAID0 or RAID1.
91 * physical device type
94 #define PDT_HARDDISK 1
101 #define MAX_NAME_LENGTH 36
102 #define MAX_ARRAYNAME_LEN 16
104 #define MAX_ARRAY_MEMBERS_V1 8
105 #define MAX_ARRAY_MEMBERS_V2 16
106 /* keep definition for source code compatibility */
107 #define MAX_ARRAY_MEMBERS MAX_ARRAY_MEMBERS_V1
111 * GUI use these commands to do IO on logical/physical devices.
113 #define IO_COMMAND_READ 1
114 #define IO_COMMAND_WRITE 2
119 #define ARRAY_FLAG_DISABLED 0x00000001 /* The array is disabled */
120 #define ARRAY_FLAG_NEEDBUILDING 0x00000002 /* array need synchronizing */
121 #define ARRAY_FLAG_REBUILDING 0x00000004 /* array is in rebuilding process */
122 #define ARRAY_FLAG_BROKEN 0x00000008 /* broken but may still working */
123 #define ARRAY_FLAG_BOOTDISK 0x00000010 /* array has a active partition */
124 #define ARRAY_FLAG_NEWLY_CREATED 0x00000020 /* a newly created array */
125 #define ARRAY_FLAG_BOOTMARK 0x00000040 /* array has boot mark set */
126 #define ARRAY_FLAG_NEED_AUTOREBUILD 0x00000080 /* auto-rebuild should start */
127 #define ARRAY_FLAG_VERIFYING 0x00000100 /* is being verified */
128 #define ARRAY_FLAG_INITIALIZING 0x00000200 /* is being initialized */
129 #define ARRAY_FLAG_RAID15PLUS 0x80000000 /* display this RAID 1 as RAID 1.5 */
134 #define DEVICE_FLAG_DISABLED 0x00000001 /* device is disabled */
135 #define DEVICE_FLAG_BOOTDISK 0x00000002 /* disk has a active partition */
136 #define DEVICE_FLAG_BOOTMARK 0x00000004 /* disk has boot mark set */
137 #define DEVICE_FLAG_WITH_601 0x00000008 /* has HPT601 connected */
138 #define DEVICE_FLAG_SATA 0x00000010 /* S-ATA device */
139 #define DEVICE_FLAG_IS_SPARE 0x80000000 /* is a spare disk */
142 * array states used by hpt_set_array_state()
145 #define MIRROR_REBUILD_START 1
146 #define MIRROR_REBUILD_ABORT 2
147 #define MIRROR_REBUILD_COMPLETE 3
149 #define AS_REBUILD_START 1
150 #define AS_REBUILD_ABORT 2
151 #define AS_REBUILD_PAUSE AS_REBUILD_ABORT
152 #define AS_REBUILD_COMPLETE 3
153 #define AS_VERIFY_START 4
154 #define AS_VERIFY_ABORT 5
155 #define AS_VERIFY_COMPLETE 6
156 #define AS_INITIALIZE_START 7
157 #define AS_INITIALIZE_ABORT 8
158 #define AS_INITIALIZE_COMPLETE 9
159 #define AS_VERIFY_FAILED 10
160 #define AS_REBUILD_STOP 11
161 #define AS_SAVE_STATE 12
162 /************************************************************************
164 * It would be better if ioctl code are the same on different platforms,
165 * but we must not conflict with system defined ioctl code.
166 ************************************************************************/
167 #if defined(LINUX) || defined(__FreeBSD_version)
168 #define HPT_CTL_CODE(x) (x+0xFF00)
169 #elif defined(_MS_WIN32_) || defined(WIN32)
172 #define CTL_CODE( DeviceType, Function, Method, Access ) \
173 (((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
175 #define HPT_CTL_CODE(x) CTL_CODE(0x370, 0x900+(x), 0, 0)
176 #define HPT_CTL_CODE_WIN32_TO_I960(x) ((((x) & 0xffff)>>2)-0x900)
179 #define HPT_CTL_CODE(x) (x)
182 #define HPT_IOCTL_GET_VERSION HPT_CTL_CODE(0)
183 #define HPT_IOCTL_GET_CONTROLLER_COUNT HPT_CTL_CODE(1)
184 #define HPT_IOCTL_GET_CONTROLLER_INFO HPT_CTL_CODE(2)
185 #define HPT_IOCTL_GET_CHANNEL_INFO HPT_CTL_CODE(3)
186 #define HPT_IOCTL_GET_LOGICAL_DEVICES HPT_CTL_CODE(4)
187 #define HPT_IOCTL_GET_DEVICE_INFO HPT_CTL_CODE(5)
188 #define HPT_IOCTL_CREATE_ARRAY HPT_CTL_CODE(6)
189 #define HPT_IOCTL_DELETE_ARRAY HPT_CTL_CODE(7)
190 #define HPT_IOCTL_ARRAY_IO HPT_CTL_CODE(8)
191 #define HPT_IOCTL_DEVICE_IO HPT_CTL_CODE(9)
192 #define HPT_IOCTL_GET_EVENT HPT_CTL_CODE(10)
193 #define HPT_IOCTL_REBUILD_MIRROR HPT_CTL_CODE(11)
194 /* use HPT_IOCTL_REBUILD_DATA_BLOCK from now on */
195 #define HPT_IOCTL_REBUILD_DATA_BLOCK HPT_IOCTL_REBUILD_MIRROR
196 #define HPT_IOCTL_ADD_SPARE_DISK HPT_CTL_CODE(12)
197 #define HPT_IOCTL_REMOVE_SPARE_DISK HPT_CTL_CODE(13)
198 #define HPT_IOCTL_ADD_DISK_TO_ARRAY HPT_CTL_CODE(14)
199 #define HPT_IOCTL_SET_ARRAY_STATE HPT_CTL_CODE(15)
200 #define HPT_IOCTL_SET_ARRAY_INFO HPT_CTL_CODE(16)
201 #define HPT_IOCTL_SET_DEVICE_INFO HPT_CTL_CODE(17)
202 #define HPT_IOCTL_RESCAN_DEVICES HPT_CTL_CODE(18)
203 #define HPT_IOCTL_GET_DRIVER_CAPABILITIES HPT_CTL_CODE(19)
204 #define HPT_IOCTL_GET_601_INFO HPT_CTL_CODE(20)
205 #define HPT_IOCTL_SET_601_INFO HPT_CTL_CODE(21)
206 #define HPT_IOCTL_LOCK_DEVICE HPT_CTL_CODE(22)
207 #define HPT_IOCTL_UNLOCK_DEVICE HPT_CTL_CODE(23)
208 #define HPT_IOCTL_IDE_PASS_THROUGH HPT_CTL_CODE(24)
209 #define HPT_IOCTL_VERIFY_DATA_BLOCK HPT_CTL_CODE(25)
210 #define HPT_IOCTL_INITIALIZE_DATA_BLOCK HPT_CTL_CODE(26)
211 #define HPT_IOCTL_ADD_DEDICATED_SPARE HPT_CTL_CODE(27)
212 #define HPT_IOCTL_DEVICE_IO_EX HPT_CTL_CODE(28)
213 #define HPT_IOCTL_SET_BOOT_MARK HPT_CTL_CODE(29)
214 #define HPT_IOCTL_QUERY_REMOVE HPT_CTL_CODE(30)
215 #define HPT_IOCTL_REMOVE_DEVICES HPT_CTL_CODE(31)
216 #define HPT_IOCTL_CREATE_ARRAY_V2 HPT_CTL_CODE(32)
217 #define HPT_IOCTL_GET_DEVICE_INFO_V2 HPT_CTL_CODE(33)
218 #define HPT_IOCTL_SET_DEVICE_INFO_V2 HPT_CTL_CODE(34)
219 #define HPT_IOCTL_REBUILD_DATA_BLOCK_V2 HPT_CTL_CODE(35)
220 #define HPT_IOCTL_VERIFY_DATA_BLOCK_V2 HPT_CTL_CODE(36)
221 #define HPT_IOCTL_INITIALIZE_DATA_BLOCK_V2 HPT_CTL_CODE(37)
222 #define HPT_IOCTL_LOCK_DEVICE_V2 HPT_CTL_CODE(38)
223 #define HPT_IOCTL_DEVICE_IO_V2 HPT_CTL_CODE(39)
224 #define HPT_IOCTL_DEVICE_IO_EX_V2 HPT_CTL_CODE(40)
226 #define HPT_IOCTL_I2C_TRANSACTION HPT_CTL_CODE(48)
227 #define HPT_IOCTL_GET_PARAMETER_LIST HPT_CTL_CODE(49)
228 #define HPT_IOCTL_GET_PARAMETER HPT_CTL_CODE(50)
229 #define HPT_IOCTL_SET_PARAMETER HPT_CTL_CODE(51)
232 #define HPT_IOCTL_GET_CONTROLLER_IDS HPT_CTL_CODE(100)
233 #define HPT_IOCTL_GET_DCB HPT_CTL_CODE(101)
234 #define HPT_IOCTL_EPROM_IO HPT_CTL_CODE(102)
235 #define HPT_IOCTL_GET_CONTROLLER_VENID HPT_CTL_CODE(103)
237 /************************************************************************
238 * shared data structures
239 ************************************************************************/
244 #define CHIP_TYPE_HPT366 1
245 #define CHIP_TYPE_HPT368 2
246 #define CHIP_TYPE_HPT370 3
247 #define CHIP_TYPE_HPT370A 4
248 #define CHIP_TYPE_HPT370B 5
249 #define CHIP_TYPE_HPT374 6
250 #define CHIP_TYPE_HPT372 7
251 #define CHIP_TYPE_HPT372A 8
252 #define CHIP_TYPE_HPT302 9
253 #define CHIP_TYPE_HPT371 10
254 #define CHIP_TYPE_HPT372N 11
255 #define CHIP_TYPE_HPT302N 12
256 #define CHIP_TYPE_HPT371N 13
257 #define CHIP_TYPE_SI3112A 14
258 #define CHIP_TYPE_ICH5 15
259 #define CHIP_TYPE_ICH5R 16
264 #define CHIP_SUPPORT_ULTRA_66 0x20
265 #define CHIP_SUPPORT_ULTRA_100 0x40
266 #define CHIP_HPT3XX_DPLL_MODE 0x80
267 #define CHIP_SUPPORT_ULTRA_133 0x01
268 #define CHIP_SUPPORT_ULTRA_150 0x02
270 typedef struct _DRIVER_CAPABILITIES {
273 UCHAR MaximumControllers; /* maximum controllers the driver can support */
274 UCHAR SupportCrossControllerRAID; /* 1-support, 0-not support */
275 UCHAR MinimumBlockSizeShift; /* minimum block size shift */
276 UCHAR MaximumBlockSizeShift; /* maximum block size shift */
278 UCHAR SupportDiskModeSetting;
279 UCHAR SupportSparePool;
280 UCHAR MaximumArrayNameLength;
281 /* only one byte left here! */
282 #ifdef __BIG_ENDIAN_BITFIELD
284 UCHAR SupportHotSwap: 1;
285 UCHAR HighPerformanceRAID1: 1;
286 UCHAR RebuildProcessInDriver: 1;
287 UCHAR SupportDedicatedSpare: 1;
289 UCHAR SupportDedicatedSpare: 1; /* call hpt_add_dedicated_spare() for dedicated spare. */
290 UCHAR RebuildProcessInDriver: 1; /* Windows only. used by mid layer for rebuild control. */
291 UCHAR HighPerformanceRAID1: 1; /* Support RAID1.5 */
292 UCHAR SupportHotSwap: 1;
296 /* SupportedRAIDTypes is an array of bytes, one of each is an array type.
297 * Only non-zero values is valid. Bit0-3 represents the lower(child) level RAID type;
298 * bit4-7 represents the top level. i.e.
299 * RAID 0/1 is (AT_RAID1<<4) | AT_RAID0
300 * RAID 5/0 is (AT_RAID0<<4) | AT_RAID5
302 UCHAR SupportedRAIDTypes[16];
303 /* maximum members in an array corresponding to SupportedRAIDTypes */
304 UCHAR MaximumArrayMembers[16];
306 DRIVER_CAPABILITIES, *PDRIVER_CAPABILITIES;
309 * Controller information.
311 typedef struct _CONTROLLER_INFO {
312 UCHAR ChipType; /* chip type */
313 UCHAR InterruptLevel; /* IRQ level */
314 UCHAR NumBuses; /* bus count */
317 UCHAR szProductID[MAX_NAME_LENGTH]; /* product name */
318 UCHAR szVendorID[MAX_NAME_LENGTH]; /* vender name */
320 } CONTROLLER_INFO, *PCONTROLLER_INFO;
323 * Channel information.
325 typedef struct _CHANNEL_INFO {
326 ULONG IoPort; /* IDE Base Port Address */
327 ULONG ControlPort; /* IDE Control Port Address */
329 DEVICEID Devices[2]; /* device connected to this channel */
331 } CHANNEL_INFO, *PCHANNEL_INFO;
334 * time represented in DWORD format
337 typedef struct _TIME_RECORD {
338 UINT seconds:6; /* 0 - 59 */
339 UINT minutes:6; /* 0 - 59 */
340 UINT month:4; /* 1 - 12 */
341 UINT hours:6; /* 0 - 59 */
342 UINT day:5; /* 1 - 31 */
343 UINT year:5; /* 0=2000, 31=2031 */
350 typedef struct _HPT_ARRAY_INFO {
351 UCHAR Name[MAX_ARRAYNAME_LEN];/* array name */
352 UCHAR Description[64]; /* array description */
353 UCHAR CreateManager[16]; /* who created it */
354 TIME_RECORD CreateTime; /* when created it */
356 UCHAR ArrayType; /* array type */
357 UCHAR BlockSizeShift; /* stripe size */
358 UCHAR nDisk; /* member count: Number of ID in Members[] */
361 DWORD Flags; /* working flags, see ARRAY_FLAG_XXX */
362 DWORD Members[MAX_ARRAY_MEMBERS_V1]; /* member array/disks */
365 * rebuilding progress, xx.xx% = sprintf(s, "%.2f%%", RebuildingProgress/100.0);
366 * only valid if rebuilding is done by driver code.
367 * Member Flags will have ARRAY_FLAG_REBUILDING set at this case.
368 * Verify operation use same fields below, the only difference is
369 * ARRAY_FLAG_VERIFYING is set.
371 DWORD RebuildingProgress;
372 DWORD RebuiltSectors; /* rebuilding point (LBA) for single member */
374 } HPT_ARRAY_INFO, *PHPT_ARRAY_INFO; /*LDX modify ARRAY_INFO TO HPT_ARRAY_INFO to avoid compiling error in Windows*/
376 #if HPT_INTERFACE_VERSION>=0x01010000
377 typedef struct _LBA64 {
378 #ifdef __BIG_ENDIAN_BITFIELD
387 typedef struct _HPT_ARRAY_INFO_V2 {
388 UCHAR Name[MAX_ARRAYNAME_LEN];/* array name */
389 UCHAR Description[64]; /* array description */
390 UCHAR CreateManager[16]; /* who created it */
391 TIME_RECORD CreateTime; /* when created it */
393 UCHAR ArrayType; /* array type */
394 UCHAR BlockSizeShift; /* stripe size */
395 UCHAR nDisk; /* member count: Number of ID in Members[] */
398 DWORD Flags; /* working flags, see ARRAY_FLAG_XXX */
399 DWORD Members[MAX_ARRAY_MEMBERS_V2]; /* member array/disks */
401 DWORD RebuildingProgress;
402 LBA64 RebuiltSectors; /* rebuilding point (LBA) for single member */
406 } HPT_ARRAY_INFO_V2, *PHPT_ARRAY_INFO_V2;
410 * ATA/ATAPI Device identify data without the Reserved4.
413 typedef struct _IDENTIFY_DATA2 {
414 USHORT GeneralConfiguration; /* 00 00 */
415 USHORT NumberOfCylinders; /* 02 1 */
416 USHORT Reserved1; /* 04 2 */
417 USHORT NumberOfHeads; /* 06 3 */
418 USHORT UnformattedBytesPerTrack; /* 08 4 */
419 USHORT UnformattedBytesPerSector; /* 0A 5 */
420 USHORT SectorsPerTrack; /* 0C 6 */
421 USHORT VendorUnique1[3]; /* 0E 7-9 */
422 USHORT SerialNumber[10]; /* 14 10-19 */
423 USHORT BufferType; /* 28 20 */
424 USHORT BufferSectorSize; /* 2A 21 */
425 USHORT NumberOfEccBytes; /* 2C 22 */
426 USHORT FirmwareRevision[4]; /* 2E 23-26 */
427 USHORT ModelNumber[20]; /* 36 27-46 */
428 UCHAR MaximumBlockTransfer; /* 5E 47 */
429 UCHAR VendorUnique2; /* 5F */
430 USHORT DoubleWordIo; /* 60 48 */
431 USHORT Capabilities; /* 62 49 */
432 USHORT Reserved2; /* 64 50 */
433 UCHAR VendorUnique3; /* 66 51 */
434 UCHAR PioCycleTimingMode; /* 67 */
435 UCHAR VendorUnique4; /* 68 52 */
436 UCHAR DmaCycleTimingMode; /* 69 */
437 USHORT TranslationFieldsValid:1; /* 6A 53 */
439 USHORT NumberOfCurrentCylinders; /* 6C 54 */
440 USHORT NumberOfCurrentHeads; /* 6E 55 */
441 USHORT CurrentSectorsPerTrack; /* 70 56 */
442 ULONG CurrentSectorCapacity; /* 72 57-58 */
443 USHORT CurrentMultiSectorSetting; /* 59 */
444 ULONG UserAddressableSectors; /* 60-61 */
445 USHORT SingleWordDMASupport : 8; /* 62 */
446 USHORT SingleWordDMAActive : 8;
447 USHORT MultiWordDMASupport : 8; /* 63 */
448 USHORT MultiWordDMAActive : 8;
449 USHORT AdvancedPIOModes : 8; /* 64 */
450 USHORT Reserved4 : 8;
451 USHORT MinimumMWXferCycleTime; /* 65 */
452 USHORT RecommendedMWXferCycleTime; /* 66 */
453 USHORT MinimumPIOCycleTime; /* 67 */
454 USHORT MinimumPIOCycleTimeIORDY; /* 68 */
455 USHORT Reserved5[2]; /* 69-70 */
456 USHORT ReleaseTimeOverlapped; /* 71 */
457 USHORT ReleaseTimeServiceCommand; /* 72 */
458 USHORT MajorRevision; /* 73 */
459 USHORT MinorRevision; /* 74 */
460 /* USHORT Reserved6[14]; // 75-88 */
461 } IDENTIFY_DATA2, *PIDENTIFY_DATA2;
465 * physical device information.
466 * IdentifyData.ModelNumber[] is byte-swapped from the original identify data.
468 typedef struct _DEVICE_INFO {
469 UCHAR ControllerId; /* controller id */
470 UCHAR PathId; /* bus */
471 UCHAR TargetId; /* id */
472 UCHAR DeviceModeSetting; /* Current Data Transfer mode: 0-4 PIO 0-4 */
473 /* 5-7 MW DMA0-2, 8-13 UDMA0-5 */
474 UCHAR DeviceType; /* device type */
475 UCHAR UsableMode; /* highest usable mode */
477 UCHAR ReadAheadSupported: 1;
478 UCHAR ReadAheadEnabled: 1;
479 UCHAR WriteCacheSupported: 1;
480 UCHAR WriteCacheEnabled: 1;
481 UCHAR TCQSupported: 1;
483 UCHAR NCQSupported: 1;
487 DWORD Flags; /* working flags, see DEVICE_FLAG_XXX */
489 IDENTIFY_DATA2 IdentifyData; /* Identify Data of this device */
491 } DEVICE_INFO, *PDEVICE_INFO;
496 #define HPT601_INFO_DEVICEID 1
497 #define HPT601_INFO_TEMPERATURE 2
498 #define HPT601_INFO_FANSTATUS 4
499 #define HPT601_INFO_BEEPERCONTROL 8
500 #define HPT601_INFO_LED1CONTROL 0x10
501 #define HPT601_INFO_LED2CONTROL 0x20
502 #define HPT601_INFO_POWERSTATUS 0x40
504 typedef struct _HPT601_INFO {
505 WORD ValidFields; /* mark valid fields below */
506 WORD DeviceId; /* 0x5A3E */
507 WORD Temperature; /* Read: temperature sensor value. Write: temperature limit */
508 WORD FanStatus; /* Fan status */
509 WORD BeeperControl; /* bit4: beeper control bit. bit0-3: frequency bits */
510 WORD LED1Control; /* bit4: twinkling control bit. bit0-3: frequency bits */
511 WORD LED2Control; /* bit4: twinkling control bit. bit0-3: frequency bits */
512 WORD PowerStatus; /* 1: has power 2: no power */
513 } HPT601_INFO, *PHPT601_INFO;
516 * Logical device information.
517 * Union of ArrayInfo and DeviceInfo.
518 * Common properties will be put in logical device information.
520 typedef struct _LOGICAL_DEVICE_INFO {
521 UCHAR Type; /* LDT_ARRAY or LDT_DEVICE */
524 DWORD Capacity; /* array capacity */
525 DEVICEID ParentArray;
528 HPT_ARRAY_INFO array;
532 } LOGICAL_DEVICE_INFO, *PLOGICAL_DEVICE_INFO;
534 #if HPT_INTERFACE_VERSION>=0x01010000
535 typedef struct _LOGICAL_DEVICE_INFO_V2 {
536 UCHAR Type; /* LDT_ARRAY or LDT_DEVICE */
539 LBA64 Capacity; /* array capacity */
540 DEVICEID ParentArray;
543 HPT_ARRAY_INFO_V2 array;
547 } LOGICAL_DEVICE_INFO_V2, *PLOGICAL_DEVICE_INFO_V2;
551 * ALTERABLE_ARRAY_INFO and ALTERABLE_DEVICE_INFO, used in set_array_info()
552 * and set_device_info().
553 * When set_xxx_info() is called, the ValidFields member indicates which
554 * fields in the structure are valid.
558 #define AAIF_DESCRIPTION 2
562 #define ADIF_WRITE_CACHE 8
563 #define ADIF_READ_AHEAD 0x10
565 typedef struct _ALTERABLE_ARRAY_INFO {
566 DWORD ValidFields; /* mark valid fields below */
567 UCHAR Name[MAX_ARRAYNAME_LEN]; /* array name */
568 UCHAR Description[64]; /* array description */
570 ALTERABLE_ARRAY_INFO, *PALTERABLE_ARRAY_INFO;
572 typedef struct _ALTERABLE_DEVICE_INFO {
573 DWORD ValidFields; /* mark valid fields below */
574 UCHAR DeviceModeSetting; /* 0-4 PIO 0-4, 5-7 MW DMA0-2, 8-13 UDMA0-5 */
576 ALTERABLE_DEVICE_INFO, *PALTERABLE_DEVICE_INFO;
578 typedef struct _ALTERABLE_DEVICE_INFO_V2 {
579 DWORD ValidFields; /* mark valid fields below */
580 UCHAR DeviceModeSetting; /* 0-4 PIO 0-4, 5-7 MW DMA0-2, 8-13 UDMA0-5 */
583 UCHAR WriteCacheEnabled;
584 UCHAR ReadAheadEnabled;
586 ULONG reserve2[13]; /* pad to 64 bytes */
588 ALTERABLE_DEVICE_INFO_V2, *PALTERABLE_DEVICE_INFO_V2;
591 * CREATE_ARRAY_PARAMS
592 * Param structure used to create an array.
594 typedef struct _CREATE_ARRAY_PARAMS {
595 UCHAR ArrayType; /* 1-level array type */
596 UCHAR nDisk; /* number of elements in Members[] array */
597 UCHAR BlockSizeShift; /* Stripe size if ArrayType==AT_RAID0 / AT_RAID5 */
598 UCHAR CreateFlags; /* See CAF_xxx */
600 UCHAR ArrayName[MAX_ARRAYNAME_LEN]; /* Array name */
601 UCHAR Description[64]; /* array description */
602 UCHAR CreateManager[16]; /* who created it */
603 TIME_RECORD CreateTime; /* when created it */
605 DWORD Members[MAX_ARRAY_MEMBERS_V1];/* ID of array members, a member can be an array */
607 } CREATE_ARRAY_PARAMS, *PCREATE_ARRAY_PARAMS;
609 #if HPT_INTERFACE_VERSION>=0x01010000
610 typedef struct _CREATE_ARRAY_PARAMS_V2 {
611 UCHAR ArrayType; /* 1-level array type */
612 UCHAR nDisk; /* number of elements in Members[] array */
613 UCHAR BlockSizeShift; /* Stripe size if ArrayType==AT_RAID0 / AT_RAID5 */
614 UCHAR CreateFlags; /* See CAF_xxx */
616 UCHAR ArrayName[MAX_ARRAYNAME_LEN]; /* Array name */
617 UCHAR Description[64]; /* array description */
618 UCHAR CreateManager[16]; /* who created it */
619 TIME_RECORD CreateTime; /* when created it */
620 LBA64 Capacity; /* specify array capacity (0 for default) */
622 DWORD Members[MAX_ARRAY_MEMBERS_V2];/* ID of array members, a member can be an array */
624 } CREATE_ARRAY_PARAMS_V2, *PCREATE_ARRAY_PARAMS_V2;
628 * Flags used for creating an RAID 1 array
630 * CAF_CREATE_AND_DUPLICATE
631 * Copy source disk contents to target for RAID 1. If user choose "create and duplicate"
632 * to create an array, GUI will call CreateArray() with this flag set. Then GUI should
633 * call hpt_get_device_info() with the returned array ID and check returned flags to
634 * see if ARRAY_FLAG_REBUILDING is set. If not set, driver does not support rebuilding
635 * and GUI must do duplication itself.
636 * CAF_DUPLICATE_MUST_DONE
637 * If the duplication is aborted or fails, do not create the array.
639 #define CAF_CREATE_AND_DUPLICATE 1
640 #define CAF_DUPLICATE_MUST_DONE 2
641 #define CAF_CREATE_AS_RAID15 4
643 * Flags used for creating an RAID 5 array
645 #define CAF_CREATE_R5_NO_BUILD 1
646 #define CAF_CREATE_R5_ZERO_INIT 2
647 #define CAF_CREATE_R5_BUILD_PARITY 4
650 * Flags used for deleting an array
652 * DAF_KEEP_DATA_IF_POSSIBLE
653 * If this flag is set, deleting a RAID 1 array will not destroy the data on both disks.
654 * Deleting a JBOD should keep partitions on first disk ( not implement now ).
655 * Deleting a RAID 0/1 should result as two RAID 0 array ( not implement now ).
657 #define DAF_KEEP_DATA_IF_POSSIBLE 1
662 #define ET_DEVICE_REMOVED 1 /* device removed */
663 #define ET_DEVICE_PLUGGED 2 /* device plugged */
664 #define ET_DEVICE_ERROR 3 /* device I/O error */
665 #define ET_REBUILD_STARTED 4
666 #define ET_REBUILD_ABORTED 5
667 #define ET_REBUILD_FINISHED 6
668 #define ET_SPARE_TOOK_OVER 7
669 #define ET_REBUILD_FAILED 8
670 #define ET_VERIFY_STARTED 9
671 #define ET_VERIFY_ABORTED 10
672 #define ET_VERIFY_FAILED 11
673 #define ET_VERIFY_FINISHED 12
674 #define ET_INITIALIZE_STARTED 13
675 #define ET_INITIALIZE_ABORTED 14
676 #define ET_INITIALIZE_FAILED 15
677 #define ET_INITIALIZE_FINISHED 16
678 #define ET_VERIFY_DATA_ERROR 17
683 typedef struct _HPT_EVENT {
689 UCHAR Data[32]; /* various data depend on EventType */
690 } HPT_EVENT, *PHPT_EVENT;
693 * IDE pass-through command. Use it at your own risk!
696 #pragma warning(disable:4200)
698 typedef struct _IDE_PASS_THROUGH_HEADER {
699 DEVICEID idDisk; /* disk ID */
700 BYTE bFeaturesReg; /* feature register */
701 BYTE bSectorCountReg; /* IDE sector count register. */
702 BYTE bLbaLowReg; /* IDE sector number register. */
703 BYTE bLbaMidReg; /* IDE low order cylinder value. */
704 BYTE bLbaHighReg; /* IDE high order cylinder value. */
705 BYTE bDriveHeadReg; /* IDE drive/head register. */
706 BYTE bCommandReg; /* Actual IDE command. Checked for validity by driver. */
707 BYTE nSectors; /* data sze in sectors, if the command has data transfer */
708 BYTE protocol; /* IO_COMMAND_(READ,WRITE) or zero for non-DATA */
710 #define IDE_PASS_THROUGH_buffer(p) ((unsigned char *)(p) + sizeof(IDE_PASS_THROUGH_HEADER))
712 IDE_PASS_THROUGH_HEADER, *PIDE_PASS_THROUGH_HEADER;
715 * device io packet format
717 typedef struct _DEVICE_IO_EX_PARAMS {
721 UCHAR Command; /* IO_COMMAD_xxx */
722 UCHAR BufferType; /* BUFFER_TYPE_xxx, see below */
725 DEVICE_IO_EX_PARAMS, *PDEVICE_IO_EX_PARAMS;
727 #define BUFFER_TYPE_LOGICAL 1 /* logical pointer to buffer */
728 #define BUFFER_TYPE_PHYSICAL 2 /* physical address of buffer */
729 #define BUFFER_TYPE_LOGICAL_LOGICAL_SG 3 /* logical pointer to logical S/G table */
730 #define BUFFER_TYPE_LOGICAL_PHYSICAL_SG 4 /* logical pointer to physical S/G table */
731 #define BUFFER_TYPE_PHYSICAL_LOGICAL_SG 5 /* physical address to logical S/G table */
732 #define BUFFER_TYPE_PHYSICAL_PHYSICAL_SG 6 /* physical address of physical S/G table */
733 #define BUFFER_TYPE_PHYSICAL_PHYSICAL_SG_PIO 7 /* non DMA capable physical address of physical S/G table */
736 * all ioctl functions should use far pointers. It's not a problem on
737 * 32bit platforms, however, BIOS needs care.
743 #define HPT_IOCTL_MAGIC32 0x1A2B3C4D
744 #define HPT_IOCTL_MAGIC 0xA1B2C3D4
746 typedef struct _HPT_IOCTL_PARAM {
747 DWORD Magic; /* used to check if it's a valid ioctl packet */
748 DWORD dwIoControlCode; /* operation control code */
749 LPVOID lpInBuffer; /* input data buffer */
750 DWORD nInBufferSize; /* size of input data buffer */
751 LPVOID lpOutBuffer; /* output data buffer */
752 DWORD nOutBufferSize; /* size of output data buffer */
753 LPDWORD lpBytesReturned; /* count of bytes returned */
755 HPT_IOCTL_PARAM, *PHPT_IOCTL_PARAM;
757 /* for 32-bit app running on 64-bit system */
758 typedef struct _HPT_IOCTL_PARAM32 {
760 DWORD dwIoControlCode;
764 DWORD nOutBufferSize;
765 DWORD lpBytesReturned;
767 HPT_IOCTL_PARAM32, *PHPT_IOCTL_PARAM32;
770 * User-mode ioctl parameter passing conventions:
771 * The ioctl function implementation is platform specific, so we don't
772 * have forced rules for it. However, it's suggested to use a parameter
773 * passing method as below
774 * 1) Put all input data continuously in an input buffer.
775 * 2) Prepare an output buffer with enough size if needed.
776 * 3) Fill a HPT_IOCTL_PARAM structure.
777 * 4) Pass the structure to driver through a platform-specific method.
778 * This is implemented in the mid-layer user-mode library. The UI
779 * programmer needn't care about it.
782 /************************************************************************
783 * User mode functions
784 ************************************************************************/
788 * Version compatibility: all versions
792 * interface version. 0 when fail.
794 DWORD hpt_get_version();
796 /*-------------------------------------------------------------------------- */
799 * hpt_get_driver_capabilities
800 * Version compatibility: v1.0.0.2 or later
802 * Pointer to receive a DRIVE_CAPABILITIES structure. The caller must set
803 * dwSize member to sizeof(DRIVER_CAPABILITIES). The callee must check this
804 * member to see if it's correct.
808 int hpt_get_driver_capabilities(PDRIVER_CAPABILITIES cap);
810 /*-------------------------------------------------------------------------- */
813 * hpt_get_controller_count
814 * Version compatibility: v1.0.0.1 or later
818 * number of controllers
820 int hpt_get_controller_count();
822 /*-------------------------------------------------------------------------- */
824 /* hpt_get_controller_info
825 * Version compatibility: v1.0.0.1 or later
828 * pInfo pointer to CONTROLLER_INFO buffer
830 * 0 Success, controller info is put into (*pInfo ).
832 int hpt_get_controller_info(int id, PCONTROLLER_INFO pInfo);
834 /*-------------------------------------------------------------------------- */
836 /* hpt_get_channel_info
837 * Version compatibility: v1.0.0.1 or later
841 * pInfo pointer to CHANNEL_INFO buffer
843 * 0 Success, channel info is put into (*pInfo ).
845 int hpt_get_channel_info(int id, int bus, PCHANNEL_INFO pInfo);
847 /*-------------------------------------------------------------------------- */
849 /* hpt_get_logical_devices
850 * Version compatibility: v1.0.0.1 or later
852 * pIds pointer to a DEVICEID array
853 * nMaxCount array size
855 * Number of ID returned. All logical device IDs are put into pIds array.
856 * Note: A spare disk is not a logical device.
858 int hpt_get_logical_devices(DEVICEID * pIds, int nMaxCount);
860 /*-------------------------------------------------------------------------- */
862 /* hpt_get_device_info
863 * Version compatibility: v1.0.0.1 or later
865 * id logical device id
866 * pInfo pointer to HPT_ARRAY_INFO structure
870 int hpt_get_device_info(DEVICEID id, PLOGICAL_DEVICE_INFO pInfo);
872 #if HPT_INTERFACE_VERSION>=0x01010000
873 int hpt_get_device_info_v2(DEVICEID id, PLOGICAL_DEVICE_INFO_V2 pInfo);
876 /*-------------------------------------------------------------------------- */
879 * Version compatibility: v1.0.0.1 or later
881 * pParam pointer to CREATE_ARRAY_PARAMS structure
884 * else return array id
886 DEVICEID hpt_create_array(PCREATE_ARRAY_PARAMS pParam);
888 #if HPT_INTERFACE_VERSION>=0x01010000
889 DEVICEID hpt_create_array_v2(PCREATE_ARRAY_PARAMS_V2 pParam);
892 /*-------------------------------------------------------------------------- */
895 * Version compatibility: v1.0.0.1 or later
901 int hpt_delete_array(DEVICEID id, DWORD options);
903 /*-------------------------------------------------------------------------- */
906 * Read/write data on array and physcal device.
907 * Version compatibility: v1.0.0.1 or later
909 * id device id. If it's an array ID, IO will be performed on the array.
910 * If it's a physical device ID, IO will be performed on the device.
911 * cmd IO_COMMAND_READ or IO_COMMAND_WRITE
917 int hpt_device_io(DEVICEID id, int cmd, ULONG lba, DWORD nSector, LPVOID buffer);
919 #if HPT_INTERFACE_VERSION >= 0x01010000
920 int hpt_device_io_v2(DEVICEID id, int cmd, LBA64 lba, DWORD nSector, LPVOID buffer);
923 /* hpt_add_disk_to_array
924 * Used to dynamicly add a disk to an RAID1, RAID0/1, RAID1/0 or RAID5 array.
925 * Auto-rebuild will start.
926 * Version compatibility: v1.0.0.1 or later
933 int hpt_add_disk_to_array(DEVICEID idArray, DEVICEID idDisk);
934 /*-------------------------------------------------------------------------- */
936 /* hpt_add_spare_disk
937 * Version compatibility: v1.0.0.1 or later
938 * Add a disk to spare pool.
944 int hpt_add_spare_disk(DEVICEID idDisk);
945 /*-------------------------------------------------------------------------- */
947 /* hpt_add_dedicated_spare
948 * Version compatibility: v1.0.0.3 or later
949 * Add a spare disk to an array
956 int hpt_add_dedicated_spare(DEVICEID idDisk, DEVICEID idArray);
957 /*-------------------------------------------------------------------------- */
959 /* hpt_remove_spare_disk
960 * remove a disk from spare pool.
961 * Version compatibility: v1.0.0.1 or later
967 int hpt_remove_spare_disk(DEVICEID idDisk);
968 /*-------------------------------------------------------------------------- */
971 * Used to poll events from driver.
972 * Version compatibility: v1.0.0.1 or later
974 * pEvent pointer to HPT_EVENT structure
976 * 0 Success, event info is filled in *pEvent
978 int hpt_get_event(PHPT_EVENT pEvent);
979 /*-------------------------------------------------------------------------- */
981 /* hpt_rebuild_data_block
982 * Used to copy data from source disk and mirror disk.
983 * Version compatibility: v1.0.0.1 or later
985 * idArray Array ID (RAID1, 0/1 or RAID5)
986 * Lba Start LBA for each array member
987 * nSector Number of sectors for each array member (RAID 5 will ignore this parameter)
990 * 0 Success, event info is filled in *pEvent
992 int hpt_rebuild_data_block(DEVICEID idMirror, DWORD Lba, UCHAR nSector);
993 #define hpt_rebuild_mirror(p1, p2, p3) hpt_rebuild_data_block(p1, p2, p3)
995 #if HPT_INTERFACE_VERSION >= 0x01010000
996 int hpt_rebuild_data_block_v2(DEVICEID idArray, LBA64 Lba, USHORT nSector);
998 /*-------------------------------------------------------------------------- */
1000 /* hpt_set_array_state
1002 * Version compatibility: v1.0.0.1 or later
1005 * state See above 'array states' constants, possible values are:
1006 * MIRROR_REBUILD_START
1007 * Indicate that GUI wants to rebuild a mirror array
1008 * MIRROR_REBUILD_ABORT
1009 * GUI wants to abort rebuilding an array
1010 * MIRROR_REBUILD_COMPLETE
1011 * GUI finished to rebuild an array. If rebuild is done by driver this
1017 int hpt_set_array_state(DEVICEID idArray, DWORD state);
1018 /*-------------------------------------------------------------------------- */
1020 /* hpt_set_array_info
1022 * Version compatibility: v1.0.0.1 or later
1025 * pInfo pointer to new info
1030 int hpt_set_array_info(DEVICEID idArray, PALTERABLE_ARRAY_INFO pInfo);
1031 /*-------------------------------------------------------------------------- */
1033 /* hpt_set_device_info
1035 * Version compatibility: v1.0.0.1 or later
1038 * pInfo pointer to new info
1043 * If idDisk==0, call to this function will stop buzzer on the adapter
1044 * (if supported by driver).
1046 int hpt_set_device_info(DEVICEID idDisk, PALTERABLE_DEVICE_INFO pInfo);
1048 #if HPT_INTERFACE_VERSION >= 0x01000004
1049 int hpt_set_device_info_v2(DEVICEID idDisk, PALTERABLE_DEVICE_INFO_V2 pInfo);
1052 /*-------------------------------------------------------------------------- */
1054 /* hpt_rescan_devices
1056 * Version compatibility: v1.0.0.1 or later
1062 int hpt_rescan_devices();
1063 /*-------------------------------------------------------------------------- */
1067 * Version compatibiilty: v1.0.0.3 or later
1069 * idDisk - Disk handle
1070 * PHPT601_INFO - pointer to HPT601 info buffer
1074 int hpt_get_601_info(DEVICEID idDisk, PHPT601_INFO pInfo);
1075 /*-------------------------------------------------------------------------- */
1078 * HPT601 function control
1079 * Version compatibiilty: v1.0.0.3 or later
1081 * idDisk - Disk handle
1082 * PHPT601_INFO - pointer to HPT601 info buffer
1086 int hpt_set_601_info(DEVICEID idDisk, PHPT601_INFO pInfo);
1087 /*-------------------------------------------------------------------------- */
1090 * Lock a block on a device (prevent OS accessing it)
1091 * Version compatibiilty: v1.0.0.3 or later
1093 * idDisk - Disk handle
1095 * nSectors - number of sectors
1099 int hpt_lock_device(DEVICEID idDisk, ULONG Lba, UCHAR nSectors);
1101 #if HPT_INTERFACE_VERSION >= 0x01010000
1102 int hpt_lock_device_v2(DEVICEID idDisk, LBA64 Lba, USHORT nSectors);
1104 /*-------------------------------------------------------------------------- */
1108 * Version compatibiilty: v1.0.0.3 or later
1110 * idDisk - Disk handle
1114 int hpt_unlock_device(DEVICEID idDisk);
1115 /*-------------------------------------------------------------------------- */
1117 /* hpt_ide_pass_through
1118 * directly access controller's command and control registers.
1119 * Can only call it on physical devices.
1120 * Version compatibility: v1.0.0.3 or later
1122 * p - IDE_PASS_THROUGH header pointer
1126 int hpt_ide_pass_through(PIDE_PASS_THROUGH_HEADER p);
1127 /*-------------------------------------------------------------------------- */
1129 /* hpt_verify_data_block
1130 * verify data block on RAID1 or RAID5.
1131 * Version compatibility: v1.0.0.3 or later
1133 * idArray - Array ID
1134 * Lba - block number (on each array member, not logical block!)
1135 * nSectors - Sectors for each member (RAID 5 will ignore this parameter)
1138 * 1 Data compare error
1141 int hpt_verify_data_block(DEVICEID idArray, ULONG Lba, UCHAR nSectors);
1143 #if HPT_INTERFACE_VERSION >= 0x01010000
1144 int hpt_verify_data_block_v2(DEVICEID idArray, LBA64 Lba, USHORT nSectors);
1146 /*-------------------------------------------------------------------------- */
1148 /* hpt_initialize_data_block
1149 * initialize data block (fill with zero) on RAID5
1150 * Version compatibility: v1.0.0.3 or later
1152 * idArray - Array ID
1153 * Lba - block number (on each array member, not logical block!)
1154 * nSectors - Sectors for each member (RAID 5 will ignore this parameter)
1158 int hpt_initialize_data_block(DEVICEID idArray, ULONG Lba, UCHAR nSectors);
1160 #if HPT_INTERFACE_VERSION >= 0x01010000
1161 int hpt_initialize_data_block_v2(DEVICEID idArray, LBA64 Lba, USHORT nSectors);
1163 /*-------------------------------------------------------------------------- */
1166 * extended device I/O function
1167 * Version compatibility: v1.0.0.3 or later
1169 * idArray - Array ID
1170 * Lba - block number (on each array member, not logical block!)
1171 * nSectors - Sectors for each member
1172 * buffer - I/O buffer or s/g address
1176 int hpt_device_io_ex(PDEVICE_IO_EX_PARAMS param);
1177 #if HPT_INTERFACE_VERSION >= 0x01010000
1178 int hpt_device_io_ex_v2(void * param); /* NOT IMPLEMENTED */
1180 /*-------------------------------------------------------------------------- */
1182 /* hpt_set_boot_mark
1183 * select boot device
1184 * Version compatibility: v1.0.0.3 or later
1186 * id - logical device ID. If id is 0 the boot mark will be removed.
1190 int hpt_set_boot_mark(DEVICEID id);
1191 /*-------------------------------------------------------------------------- */
1194 * check if device can be removed safely
1195 * Version compatibility: v1.0.0.4 or later
1197 * ndev - number of devices
1198 * pIds - device ID list
1201 * -1 - unknown error
1202 * n - the n-th device that can't be removed
1204 int hpt_query_remove(DWORD ndev, DEVICEID *pIds);
1205 /*-------------------------------------------------------------------------- */
1207 /* hpt_remove_devices
1208 * remove a list of devices
1209 * Version compatibility: v1.0.0.4 or later
1211 * ndev - number of devices
1212 * pIds - device ID list
1215 * -1 - unknown error
1216 * n - the n-th device that can't be removed
1218 int hpt_remove_devices(DWORD ndev, DEVICEID *pIds);
1219 /*-------------------------------------------------------------------------- */
1221 /* hpt_ide_pass_through
1222 * directly access controller's command and control registers.
1223 * Can only call it on physical devices.
1224 * Version compatibility: v1.0.0.3 or later
1226 * p - IDE_PASS_THROUGH header pointer
1230 int hpt_ide_pass_through(PIDE_PASS_THROUGH_HEADER p);
1231 /*-------------------------------------------------------------------------- */