2 * Copyright (c) 2004-2005 HighPoint Technologies, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * Version of this interface.
35 * The user mode application must first issue a hpt_get_version() call to
36 * check HPT_INTERFACE_VERSION. When an utility using newer version interface
37 * is used with old version drivers, it must call only the functions that
39 * A new version interface should only add ioctl functions; it should implement
40 * all old version functions without change their definition.
42 #define __this_HPT_INTERFACE_VERSION 0x01010000
44 #ifndef HPT_INTERFACE_VERSION
45 #error "You must define HPT_INTERFACE_VERSION you implemented"
48 #if HPT_INTERFACE_VERSION > __this_HPT_INTERFACE_VERSION
49 #error "HPT_INTERFACE_VERSION is invalid"
54 * Logical device --- a device that can be accessed by OS.
55 * Physical device --- device attached to the controller.
56 * A logical device can be simply a physical device.
58 * Each logical and physical device has a 32bit ID. GUI will use this ID
59 * to identify devices.
60 * 1. The ID must be unique.
61 * 2. The ID must be immutable. Once an ID is assigned to a device, it
62 * must not change when system is running and the device exists.
63 * 3. The ID of logical device must be NOT reusable. If a device is
64 * removed, other newly created logical device must not use the same ID.
65 * 4. The ID must not be zero or 0xFFFFFFFF.
67 typedef DWORD DEVICEID;
70 * logical device type.
71 * Identify array (logical device) and physical device.
78 * GUI will treat all array as 1-level RAID. No RAID0/1 or RAID1/0.
79 * A RAID0/1 device is type AT_RAID1. A RAID1/0 device is type AT_RAID0.
80 * Their members may be another array of type RAID0 or RAID1.
89 * physical device type
92 #define PDT_HARDDISK 1
99 #define MAX_NAME_LENGTH 36
100 #define MAX_ARRAYNAME_LEN 16
102 #define MAX_ARRAY_MEMBERS_V1 8
103 #define MAX_ARRAY_MEMBERS_V2 16
104 /* keep definition for source code compatiblity */
105 #define MAX_ARRAY_MEMBERS MAX_ARRAY_MEMBERS_V1
109 * GUI use these commands to do IO on logical/physical devices.
111 #define IO_COMMAND_READ 1
112 #define IO_COMMAND_WRITE 2
117 #define ARRAY_FLAG_DISABLED 0x00000001 /* The array is disabled */
118 #define ARRAY_FLAG_NEEDBUILDING 0x00000002 /* array need synchronizing */
119 #define ARRAY_FLAG_REBUILDING 0x00000004 /* array is in rebuilding process */
120 #define ARRAY_FLAG_BROKEN 0x00000008 /* broken but may still working */
121 #define ARRAY_FLAG_BOOTDISK 0x00000010 /* array has a active partition */
122 #define ARRAY_FLAG_NEWLY_CREATED 0x00000020 /* a newly created array */
123 #define ARRAY_FLAG_BOOTMARK 0x00000040 /* array has boot mark set */
124 #define ARRAY_FLAG_NEED_AUTOREBUILD 0x00000080 /* auto-rebuild should start */
125 #define ARRAY_FLAG_VERIFYING 0x00000100 /* is being verified */
126 #define ARRAY_FLAG_INITIALIZING 0x00000200 /* is being initialized */
127 #define ARRAY_FLAG_RAID15PLUS 0x80000000 /* display this RAID 1 as RAID 1.5 */
132 #define DEVICE_FLAG_DISABLED 0x00000001 /* device is disabled */
133 #define DEVICE_FLAG_BOOTDISK 0x00000002 /* disk has a active partition */
134 #define DEVICE_FLAG_BOOTMARK 0x00000004 /* disk has boot mark set */
135 #define DEVICE_FLAG_WITH_601 0x00000008 /* has HPT601 connected */
136 #define DEVICE_FLAG_SATA 0x00000010 /* S-ATA device */
137 #define DEVICE_FLAG_IS_SPARE 0x80000000 /* is a spare disk */
140 * array states used by hpt_set_array_state()
143 #define MIRROR_REBUILD_START 1
144 #define MIRROR_REBUILD_ABORT 2
145 #define MIRROR_REBUILD_COMPLETE 3
147 #define AS_REBUILD_START 1
148 #define AS_REBUILD_ABORT 2
149 #define AS_REBUILD_PAUSE AS_REBUILD_ABORT
150 #define AS_REBUILD_COMPLETE 3
151 #define AS_VERIFY_START 4
152 #define AS_VERIFY_ABORT 5
153 #define AS_VERIFY_COMPLETE 6
154 #define AS_INITIALIZE_START 7
155 #define AS_INITIALIZE_ABORT 8
156 #define AS_INITIALIZE_COMPLETE 9
157 #define AS_VERIFY_FAILED 10
158 #define AS_REBUILD_STOP 11
159 #define AS_SAVE_STATE 12
160 /************************************************************************
162 * It would be better if ioctl code are the same on different platforms,
163 * but we must not conflict with system defined ioctl code.
164 ************************************************************************/
165 #if defined(LINUX) || defined(__FreeBSD_version) || defined(_MACOSX_)
166 #define HPT_CTL_CODE(x) (x+0xFF00)
167 #elif defined(_MS_WIN32_) || defined(WIN32)
170 #define CTL_CODE( DeviceType, Function, Method, Access ) \
171 (((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
173 #define HPT_CTL_CODE(x) CTL_CODE(0x370, 0x900+(x), 0, 0)
174 #define HPT_CTL_CODE_WIN32_TO_I960(x) ((((x) & 0xffff)>>2)-0x900)
177 #define HPT_CTL_CODE(x) (x)
180 #define HPT_IOCTL_GET_VERSION HPT_CTL_CODE(0)
181 #define HPT_IOCTL_GET_CONTROLLER_COUNT HPT_CTL_CODE(1)
182 #define HPT_IOCTL_GET_CONTROLLER_INFO HPT_CTL_CODE(2)
183 #define HPT_IOCTL_GET_CHANNEL_INFO HPT_CTL_CODE(3)
184 #define HPT_IOCTL_GET_LOGICAL_DEVICES HPT_CTL_CODE(4)
185 #define HPT_IOCTL_GET_DEVICE_INFO HPT_CTL_CODE(5)
186 #define HPT_IOCTL_CREATE_ARRAY HPT_CTL_CODE(6)
187 #define HPT_IOCTL_DELETE_ARRAY HPT_CTL_CODE(7)
188 #define HPT_IOCTL_ARRAY_IO HPT_CTL_CODE(8)
189 #define HPT_IOCTL_DEVICE_IO HPT_CTL_CODE(9)
190 #define HPT_IOCTL_GET_EVENT HPT_CTL_CODE(10)
191 #define HPT_IOCTL_REBUILD_MIRROR HPT_CTL_CODE(11)
192 /* use HPT_IOCTL_REBUILD_DATA_BLOCK from now on */
193 #define HPT_IOCTL_REBUILD_DATA_BLOCK HPT_IOCTL_REBUILD_MIRROR
194 #define HPT_IOCTL_ADD_SPARE_DISK HPT_CTL_CODE(12)
195 #define HPT_IOCTL_REMOVE_SPARE_DISK HPT_CTL_CODE(13)
196 #define HPT_IOCTL_ADD_DISK_TO_ARRAY HPT_CTL_CODE(14)
197 #define HPT_IOCTL_SET_ARRAY_STATE HPT_CTL_CODE(15)
198 #define HPT_IOCTL_SET_ARRAY_INFO HPT_CTL_CODE(16)
199 #define HPT_IOCTL_SET_DEVICE_INFO HPT_CTL_CODE(17)
200 #define HPT_IOCTL_RESCAN_DEVICES HPT_CTL_CODE(18)
201 #define HPT_IOCTL_GET_DRIVER_CAPABILITIES HPT_CTL_CODE(19)
202 #define HPT_IOCTL_GET_601_INFO HPT_CTL_CODE(20)
203 #define HPT_IOCTL_SET_601_INFO HPT_CTL_CODE(21)
204 #define HPT_IOCTL_LOCK_DEVICE HPT_CTL_CODE(22)
205 #define HPT_IOCTL_UNLOCK_DEVICE HPT_CTL_CODE(23)
206 #define HPT_IOCTL_IDE_PASS_THROUGH HPT_CTL_CODE(24)
207 #define HPT_IOCTL_VERIFY_DATA_BLOCK HPT_CTL_CODE(25)
208 #define HPT_IOCTL_INITIALIZE_DATA_BLOCK HPT_CTL_CODE(26)
209 #define HPT_IOCTL_ADD_DEDICATED_SPARE HPT_CTL_CODE(27)
210 #define HPT_IOCTL_DEVICE_IO_EX HPT_CTL_CODE(28)
211 #define HPT_IOCTL_SET_BOOT_MARK HPT_CTL_CODE(29)
212 #define HPT_IOCTL_QUERY_REMOVE HPT_CTL_CODE(30)
213 #define HPT_IOCTL_REMOVE_DEVICES HPT_CTL_CODE(31)
214 #define HPT_IOCTL_CREATE_ARRAY_V2 HPT_CTL_CODE(32)
215 #define HPT_IOCTL_GET_DEVICE_INFO_V2 HPT_CTL_CODE(33)
216 #define HPT_IOCTL_SET_DEVICE_INFO_V2 HPT_CTL_CODE(34)
217 #define HPT_IOCTL_REBUILD_DATA_BLOCK_V2 HPT_CTL_CODE(35)
218 #define HPT_IOCTL_VERIFY_DATA_BLOCK_V2 HPT_CTL_CODE(36)
219 #define HPT_IOCTL_INITIALIZE_DATA_BLOCK_V2 HPT_CTL_CODE(37)
220 #define HPT_IOCTL_LOCK_DEVICE_V2 HPT_CTL_CODE(38)
221 #define HPT_IOCTL_DEVICE_IO_V2 HPT_CTL_CODE(39)
222 #define HPT_IOCTL_DEVICE_IO_EX_V2 HPT_CTL_CODE(40)
225 #define HPT_IOCTL_GET_CONTROLLER_IDS HPT_CTL_CODE(100)
226 #define HPT_IOCTL_GET_DCB HPT_CTL_CODE(101)
227 #define HPT_IOCTL_EPROM_IO HPT_CTL_CODE(102)
228 #define HPT_IOCTL_GET_CONTROLLER_VENID HPT_CTL_CODE(103)
230 /************************************************************************
231 * shared data structures
232 ************************************************************************/
237 #define CHIP_TYPE_HPT366 1
238 #define CHIP_TYPE_HPT368 2
239 #define CHIP_TYPE_HPT370 3
240 #define CHIP_TYPE_HPT370A 4
241 #define CHIP_TYPE_HPT370B 5
242 #define CHIP_TYPE_HPT374 6
243 #define CHIP_TYPE_HPT372 7
244 #define CHIP_TYPE_HPT372A 8
245 #define CHIP_TYPE_HPT302 9
246 #define CHIP_TYPE_HPT371 10
247 #define CHIP_TYPE_HPT372N 11
248 #define CHIP_TYPE_HPT302N 12
249 #define CHIP_TYPE_HPT371N 13
250 #define CHIP_TYPE_SI3112A 14
251 #define CHIP_TYPE_ICH5 15
252 #define CHIP_TYPE_ICH5R 16
257 #define CHIP_SUPPORT_ULTRA_66 0x20
258 #define CHIP_SUPPORT_ULTRA_100 0x40
259 #define CHIP_HPT3XX_DPLL_MODE 0x80
260 #define CHIP_SUPPORT_ULTRA_133 0x01
261 #define CHIP_SUPPORT_ULTRA_150 0x02
263 typedef struct _DRIVER_CAPABILITIES {
266 UCHAR MaximumControllers; /* maximum controllers the driver can support */
267 UCHAR SupportCrossControllerRAID; /* 1-support, 0-not support */
268 UCHAR MinimumBlockSizeShift; /* minimum block size shift */
269 UCHAR MaximumBlockSizeShift; /* maximum block size shift */
271 UCHAR SupportDiskModeSetting;
272 UCHAR SupportSparePool;
273 UCHAR MaximumArrayNameLength;
274 /* only one byte left here! */
275 #ifdef __BIG_ENDIAN_BITFIELD
277 UCHAR SupportHotSwap: 1;
278 UCHAR HighPerformanceRAID1: 1;
279 UCHAR RebuildProcessInDriver: 1;
280 UCHAR SupportDedicatedSpare: 1;
282 UCHAR SupportDedicatedSpare: 1; /* call hpt_add_dedicated_spare() for dedicated spare. */
283 UCHAR RebuildProcessInDriver: 1; /* Windows only. used by mid layer for rebuild control. */
284 UCHAR HighPerformanceRAID1: 1; /* Support RAID1.5 */
285 UCHAR SupportHotSwap: 1;
289 /* SupportedRAIDTypes is an array of bytes, one of each is an array type.
290 * Only non-zero values is valid. Bit0-3 represents the lower(child) level RAID type;
291 * bit4-7 represents the top level. i.e.
292 * RAID 0/1 is (AT_RAID1<<4) | AT_RAID0
293 * RAID 5/0 is (AT_RAID0<<4) | AT_RAID5
295 UCHAR SupportedRAIDTypes[16];
296 /* maximum members in an array corresponding to SupportedRAIDTypes */
297 UCHAR MaximumArrayMembers[16];
299 DRIVER_CAPABILITIES, *PDRIVER_CAPABILITIES;
302 * Controller information.
304 typedef struct _CONTROLLER_INFO {
305 UCHAR ChipType; /* chip type */
306 UCHAR InterruptLevel; /* IRQ level */
307 UCHAR NumBuses; /* bus count */
310 UCHAR szProductID[MAX_NAME_LENGTH]; /* product name */
311 UCHAR szVendorID[MAX_NAME_LENGTH]; /* vender name */
313 } CONTROLLER_INFO, *PCONTROLLER_INFO;
316 * Channel information.
318 typedef struct _CHANNEL_INFO {
319 ULONG IoPort; /* IDE Base Port Address */
320 ULONG ControlPort; /* IDE Control Port Address */
322 DEVICEID Devices[2]; /* device connected to this channel */
324 } CHANNEL_INFO, *PCHANNEL_INFO;
327 * time represented in DWORD format
330 typedef struct _TIME_RECORD {
331 UINT seconds:6; /* 0 - 59 */
332 UINT minutes:6; /* 0 - 59 */
333 UINT month:4; /* 1 - 12 */
334 UINT hours:6; /* 0 - 59 */
335 UINT day:5; /* 1 - 31 */
336 UINT year:5; /* 0=2000, 31=2031 */
343 typedef struct _HPT_ARRAY_INFO {
344 UCHAR Name[MAX_ARRAYNAME_LEN];/* array name */
345 UCHAR Description[64]; /* array description */
346 UCHAR CreateManager[16]; /* who created it */
347 TIME_RECORD CreateTime; /* when created it */
349 UCHAR ArrayType; /* array type */
350 UCHAR BlockSizeShift; /* stripe size */
351 UCHAR nDisk; /* member count: Number of ID in Members[] */
354 DWORD Flags; /* working flags, see ARRAY_FLAG_XXX */
355 DWORD Members[MAX_ARRAY_MEMBERS_V1]; /* member array/disks */
358 * rebuilding progress, xx.xx% = sprintf(s, "%.2f%%", RebuildingProgress/100.0);
359 * only valid if rebuilding is done by driver code.
360 * Member Flags will have ARRAY_FLAG_REBUILDING set at this case.
361 * Verify operation use same fields below, the only difference is
362 * ARRAY_FLAG_VERIFYING is set.
364 DWORD RebuildingProgress;
365 DWORD RebuiltSectors; /* rebuilding point (LBA) for single member */
367 } HPT_ARRAY_INFO, *PHPT_ARRAY_INFO; /*LDX modify ARRAY_INFO TO HPT_ARRAY_INFO to avoid compiling error in Windows*/
369 #if HPT_INTERFACE_VERSION>=0x01010000
370 typedef struct _LBA64 {
375 typedef struct _HPT_ARRAY_INFO_V2 {
376 UCHAR Name[MAX_ARRAYNAME_LEN];/* array name */
377 UCHAR Description[64]; /* array description */
378 UCHAR CreateManager[16]; /* who created it */
379 TIME_RECORD CreateTime; /* when created it */
381 UCHAR ArrayType; /* array type */
382 UCHAR BlockSizeShift; /* stripe size */
383 UCHAR nDisk; /* member count: Number of ID in Members[] */
386 DWORD Flags; /* working flags, see ARRAY_FLAG_XXX */
387 DWORD Members[MAX_ARRAY_MEMBERS_V2]; /* member array/disks */
389 DWORD RebuildingProgress;
390 LBA64 RebuiltSectors; /* rebuilding point (LBA) for single member */
394 } HPT_ARRAY_INFO_V2, *PHPT_ARRAY_INFO_V2;
398 * ATA/ATAPI Device identify data without the Reserved4.
401 typedef struct _IDENTIFY_DATA2 {
402 USHORT GeneralConfiguration; /* 00 00 */
403 USHORT NumberOfCylinders; /* 02 1 */
404 USHORT Reserved1; /* 04 2 */
405 USHORT NumberOfHeads; /* 06 3 */
406 USHORT UnformattedBytesPerTrack; /* 08 4 */
407 USHORT UnformattedBytesPerSector; /* 0A 5 */
408 USHORT SectorsPerTrack; /* 0C 6 */
409 USHORT VendorUnique1[3]; /* 0E 7-9 */
410 USHORT SerialNumber[10]; /* 14 10-19 */
411 USHORT BufferType; /* 28 20 */
412 USHORT BufferSectorSize; /* 2A 21 */
413 USHORT NumberOfEccBytes; /* 2C 22 */
414 USHORT FirmwareRevision[4]; /* 2E 23-26 */
415 USHORT ModelNumber[20]; /* 36 27-46 */
416 UCHAR MaximumBlockTransfer; /* 5E 47 */
417 UCHAR VendorUnique2; /* 5F */
418 USHORT DoubleWordIo; /* 60 48 */
419 USHORT Capabilities; /* 62 49 */
420 USHORT Reserved2; /* 64 50 */
421 UCHAR VendorUnique3; /* 66 51 */
422 UCHAR PioCycleTimingMode; /* 67 */
423 UCHAR VendorUnique4; /* 68 52 */
424 UCHAR DmaCycleTimingMode; /* 69 */
425 USHORT TranslationFieldsValid:1; /* 6A 53 */
427 USHORT NumberOfCurrentCylinders; /* 6C 54 */
428 USHORT NumberOfCurrentHeads; /* 6E 55 */
429 USHORT CurrentSectorsPerTrack; /* 70 56 */
430 ULONG CurrentSectorCapacity; /* 72 57-58 */
431 USHORT CurrentMultiSectorSetting; /* 59 */
432 ULONG UserAddressableSectors; /* 60-61 */
433 USHORT SingleWordDMASupport : 8; /* 62 */
434 USHORT SingleWordDMAActive : 8;
435 USHORT MultiWordDMASupport : 8; /* 63 */
436 USHORT MultiWordDMAActive : 8;
437 USHORT AdvancedPIOModes : 8; /* 64 */
438 USHORT Reserved4 : 8;
439 USHORT MinimumMWXferCycleTime; /* 65 */
440 USHORT RecommendedMWXferCycleTime; /* 66 */
441 USHORT MinimumPIOCycleTime; /* 67 */
442 USHORT MinimumPIOCycleTimeIORDY; /* 68 */
443 USHORT Reserved5[2]; /* 69-70 */
444 USHORT ReleaseTimeOverlapped; /* 71 */
445 USHORT ReleaseTimeServiceCommand; /* 72 */
446 USHORT MajorRevision; /* 73 */
447 USHORT MinorRevision; /* 74 */
448 /* USHORT Reserved6[14]; // 75-88 */
449 } IDENTIFY_DATA2, *PIDENTIFY_DATA2;
453 * physical device information.
454 * IdentifyData.ModelNumber[] is byte-swapped from the original identify data.
456 typedef struct _DEVICE_INFO {
457 UCHAR ControllerId; /* controller id */
458 UCHAR PathId; /* bus */
459 UCHAR TargetId; /* id */
460 UCHAR DeviceModeSetting; /* Current Data Transfer mode: 0-4 PIO 0-4 */
461 /* 5-7 MW DMA0-2, 8-13 UDMA0-5 */
462 UCHAR DeviceType; /* device type */
463 UCHAR UsableMode; /* highest usable mode */
465 UCHAR ReadAheadSupported: 1;
466 UCHAR ReadAheadEnabled: 1;
467 UCHAR WriteCacheSupported: 1;
468 UCHAR WriteCacheEnabled: 1;
469 UCHAR TCQSupported: 1;
471 UCHAR NCQSupported: 1;
475 DWORD Flags; /* working flags, see DEVICE_FLAG_XXX */
477 IDENTIFY_DATA2 IdentifyData; /* Identify Data of this device */
479 } DEVICE_INFO, *PDEVICE_INFO;
484 #define HPT601_INFO_DEVICEID 1
485 #define HPT601_INFO_TEMPERATURE 2
486 #define HPT601_INFO_FANSTATUS 4
487 #define HPT601_INFO_BEEPERCONTROL 8
488 #define HPT601_INFO_LED1CONTROL 0x10
489 #define HPT601_INFO_LED2CONTROL 0x20
490 #define HPT601_INFO_POWERSTATUS 0x40
492 typedef struct _HPT601_INFO {
493 WORD ValidFields; /* mark valid fields below */
494 WORD DeviceId; /* 0x5A3E */
495 WORD Temperature; /* Read: temperature sensor value. Write: temperature limit */
496 WORD FanStatus; /* Fan status */
497 WORD BeeperControl; /* bit4: beeper control bit. bit0-3: frequency bits */
498 WORD LED1Control; /* bit4: twinkling control bit. bit0-3: frequency bits */
499 WORD LED2Control; /* bit4: twinkling control bit. bit0-3: frequency bits */
500 WORD PowerStatus; /* 1: has power 2: no power */
501 } HPT601_INFO, *PHPT601_INFO;
504 * Logical device information.
505 * Union of ArrayInfo and DeviceInfo.
506 * Common properties will be put in logical device information.
508 typedef struct _LOGICAL_DEVICE_INFO {
509 UCHAR Type; /* LDT_ARRAY or LDT_DEVICE */
512 DWORD Capacity; /* array capacity */
513 DEVICEID ParentArray;
516 HPT_ARRAY_INFO array;
520 } LOGICAL_DEVICE_INFO, *PLOGICAL_DEVICE_INFO;
522 #if HPT_INTERFACE_VERSION>=0x01010000
523 typedef struct _LOGICAL_DEVICE_INFO_V2 {
524 UCHAR Type; /* LDT_ARRAY or LDT_DEVICE */
527 LBA64 Capacity; /* array capacity */
528 DEVICEID ParentArray;
531 HPT_ARRAY_INFO_V2 array;
535 } LOGICAL_DEVICE_INFO_V2, *PLOGICAL_DEVICE_INFO_V2;
539 * ALTERABLE_ARRAY_INFO and ALTERABLE_DEVICE_INFO, used in set_array_info()
540 * and set_device_info().
541 * When set_xxx_info() is called, the ValidFields member indicates which
542 * fields in the structure are valid.
546 #define AAIF_DESCRIPTION 2
550 #define ADIF_WRITE_CACHE 8
551 #define ADIF_READ_AHEAD 0x10
553 typedef struct _ALTERABLE_ARRAY_INFO {
554 DWORD ValidFields; /* mark valid fields below */
555 UCHAR Name[MAX_ARRAYNAME_LEN]; /* array name */
556 UCHAR Description[64]; /* array description */
558 ALTERABLE_ARRAY_INFO, *PALTERABLE_ARRAY_INFO;
560 typedef struct _ALTERABLE_DEVICE_INFO {
561 DWORD ValidFields; /* mark valid fields below */
562 UCHAR DeviceModeSetting; /* 0-4 PIO 0-4, 5-7 MW DMA0-2, 8-13 UDMA0-5 */
564 ALTERABLE_DEVICE_INFO, *PALTERABLE_DEVICE_INFO;
566 typedef struct _ALTERABLE_DEVICE_INFO_V2 {
567 DWORD ValidFields; /* mark valid fields below */
568 UCHAR DeviceModeSetting; /* 0-4 PIO 0-4, 5-7 MW DMA0-2, 8-13 UDMA0-5 */
571 UCHAR WriteCacheEnabled;
572 UCHAR ReadAheadEnabled;
574 ULONG reserve2[13]; /* pad to 64 bytes */
576 ALTERABLE_DEVICE_INFO_V2, *PALTERABLE_DEVICE_INFO_V2;
579 * CREATE_ARRAY_PARAMS
580 * Param structure used to create an array.
582 typedef struct _CREATE_ARRAY_PARAMS {
583 UCHAR ArrayType; /* 1-level array type */
584 UCHAR nDisk; /* number of elements in Members[] array */
585 UCHAR BlockSizeShift; /* Stripe size if ArrayType==AT_RAID0 / AT_RAID5 */
586 UCHAR CreateFlags; /* See CAF_xxx */
588 UCHAR ArrayName[MAX_ARRAYNAME_LEN]; /* Array name */
589 UCHAR Description[64]; /* array description */
590 UCHAR CreateManager[16]; /* who created it */
591 TIME_RECORD CreateTime; /* when created it */
593 DWORD Members[MAX_ARRAY_MEMBERS_V1];/* ID of array members, a member can be an array */
595 } CREATE_ARRAY_PARAMS, *PCREATE_ARRAY_PARAMS;
597 #if HPT_INTERFACE_VERSION>=0x01010000
598 typedef struct _CREATE_ARRAY_PARAMS_V2 {
599 UCHAR ArrayType; /* 1-level array type */
600 UCHAR nDisk; /* number of elements in Members[] array */
601 UCHAR BlockSizeShift; /* Stripe size if ArrayType==AT_RAID0 / AT_RAID5 */
602 UCHAR CreateFlags; /* See CAF_xxx */
604 UCHAR ArrayName[MAX_ARRAYNAME_LEN]; /* Array name */
605 UCHAR Description[64]; /* array description */
606 UCHAR CreateManager[16]; /* who created it */
607 TIME_RECORD CreateTime; /* when created it */
608 LBA64 Capacity; /* specify array capacity (0 for default) */
610 DWORD Members[MAX_ARRAY_MEMBERS_V2];/* ID of array members, a member can be an array */
612 } CREATE_ARRAY_PARAMS_V2, *PCREATE_ARRAY_PARAMS_V2;
616 * Flags used for creating an RAID 1 array
618 * CAF_CREATE_AND_DUPLICATE
619 * Copy source disk contents to target for RAID 1. If user choose "create and duplicate"
620 * to create an array, GUI will call CreateArray() with this flag set. Then GUI should
621 * call hpt_get_device_info() with the returned array ID and check returned flags to
622 * see if ARRAY_FLAG_REBUILDING is set. If not set, driver does not support rebuilding
623 * and GUI must do duplication itself.
624 * CAF_DUPLICATE_MUST_DONE
625 * If the duplication is aborted or fails, do not create the array.
627 #define CAF_CREATE_AND_DUPLICATE 1
628 #define CAF_DUPLICATE_MUST_DONE 2
629 #define CAF_CREATE_AS_RAID15 4
631 * Flags used for creating an RAID 5 array
633 #define CAF_CREATE_R5_NO_BUILD 1
634 #define CAF_CREATE_R5_ZERO_INIT 2
635 #define CAF_CREATE_R5_BUILD_PARITY 4
638 * Flags used for deleting an array
640 * DAF_KEEP_DATA_IF_POSSIBLE
641 * If this flag is set, deleting a RAID 1 array will not destroy the data on both disks.
642 * Deleting a JBOD should keep partitions on first disk ( not implement now ).
643 * Deleting a RAID 0/1 should result as two RAID 0 array ( not implement now ).
645 #define DAF_KEEP_DATA_IF_POSSIBLE 1
650 #define ET_DEVICE_REMOVED 1 /* device removed */
651 #define ET_DEVICE_PLUGGED 2 /* device plugged */
652 #define ET_DEVICE_ERROR 3 /* device I/O error */
653 #define ET_REBUILD_STARTED 4
654 #define ET_REBUILD_ABORTED 5
655 #define ET_REBUILD_FINISHED 6
656 #define ET_SPARE_TOOK_OVER 7
657 #define ET_REBUILD_FAILED 8
658 #define ET_VERIFY_STARTED 9
659 #define ET_VERIFY_ABORTED 10
660 #define ET_VERIFY_FAILED 11
661 #define ET_VERIFY_FINISHED 12
662 #define ET_INITIALIZE_STARTED 13
663 #define ET_INITIALIZE_ABORTED 14
664 #define ET_INITIALIZE_FAILED 15
665 #define ET_INITIALIZE_FINISHED 16
666 #define ET_VERIFY_DATA_ERROR 17
671 typedef struct _HPT_EVENT {
677 UCHAR Data[32]; /* various data depend on EventType */
678 } HPT_EVENT, *PHPT_EVENT;
681 * IDE pass-through command. Use it at your own risk!
684 #pragma warning(disable:4200)
686 typedef struct _IDE_PASS_THROUGH_HEADER {
687 DEVICEID idDisk; /* disk ID */
688 BYTE bFeaturesReg; /* feature register */
689 BYTE bSectorCountReg; /* IDE sector count register. */
690 BYTE bSectorNumberReg; /* IDE sector number register. */
691 BYTE bCylLowReg; /* IDE low order cylinder value. */
692 BYTE bCylHighReg; /* IDE high order cylinder value. */
693 BYTE bDriveHeadReg; /* IDE drive/head register. */
694 BYTE bCommandReg; /* Actual IDE command. Checked for validity by driver. */
696 DWORD DataSize; /* data size in bytes, if the command has data transfer */
698 BYTE DataBuffer[0]; /* data buffer */
701 IDE_PASS_THROUGH_HEADER, *PIDE_PASS_THROUGH_HEADER;
704 * device io packet format
706 typedef struct _DEVICE_IO_EX_PARAMS {
710 UCHAR Command; /* IO_COMMAD_xxx */
711 UCHAR BufferType; /* BUFFER_TYPE_xxx, see below */
714 DEVICE_IO_EX_PARAMS, *PDEVICE_IO_EX_PARAMS;
716 #define BUFFER_TYPE_LOGICAL 1 /* logical pointer to buffer */
717 #define BUFFER_TYPE_PHYSICAL 2 /* physical address of buffer */
718 #define BUFFER_TYPE_LOGICAL_LOGICAL_SG 3 /* logical pointer to logical S/G table */
719 #define BUFFER_TYPE_LOGICAL_PHYSICAL_SG 4 /* logical pointer to physical S/G table */
720 #define BUFFER_TYPE_PHYSICAL_LOGICAL_SG 5 /* physical address to logical S/G table */
721 #define BUFFER_TYPE_PHYSICAL_PHYSICAL_SG 6 /* physical address of physical S/G table */
722 #define BUFFER_TYPE_PHYSICAL_PHYSICAL_SG_PIO 7 /* non DMA capable physical address of physical S/G table */
725 * all ioctl functions should use far pointers. It's not a problem on
726 * 32bit platforms, however, BIOS needs care.
732 #define HPT_IOCTL_MAGIC 0x1A2B3C4D
734 typedef struct _HPT_IOCTL_PARAM {
735 DWORD Magic; /* used to check if it's a valid ioctl packet */
736 DWORD dwIoControlCode; /* operation control code */
737 LPVOID lpInBuffer; /* input data buffer */
738 DWORD nInBufferSize; /* size of input data buffer */
739 LPVOID lpOutBuffer; /* output data buffer */
740 DWORD nOutBufferSize; /* size of output data buffer */
741 LPDWORD lpBytesReturned; /* count of bytes returned */
743 HPT_IOCTL_PARAM, *PHPT_IOCTL_PARAM;
745 /* for 64-bit system */
746 typedef struct _HPT_IOCTL_PARAM32 {
748 DWORD dwIoControlCode;
752 DWORD nOutBufferSize;
753 DWORD lpBytesReturned;
755 HPT_IOCTL_PARAM32, *PHPT_IOCTL_PARAM32;
758 * User-mode ioctl parameter passing conventions:
759 * The ioctl function implementation is platform specific, so we don't
760 * have forced rules for it. However, it's suggested to use a parameter
761 * passing method as below
762 * 1) Put all input data continuously in an input buffer.
763 * 2) Prepare an output buffer with enough size if needed.
764 * 3) Fill a HPT_IOCTL_PARAM structure.
765 * 4) Pass the structure to driver through a platform-specific method.
766 * This is implemented in the mid-layer user-mode library. The UI
767 * programmer needn't care about it.
770 /************************************************************************
771 * User mode functions
772 ************************************************************************/
776 * Version compatibility: all versions
780 * interface version. 0 when fail.
782 DWORD hpt_get_version();
784 /*-------------------------------------------------------------------------- */
787 * hpt_get_driver_capabilities
788 * Version compatibility: v1.0.0.2 or later
790 * Pointer to receive a DRIVE_CAPABILITIES structure. The caller must set
791 * dwSize member to sizeof(DRIVER_CAPABILITIES). The callee must check this
792 * member to see if it's correct.
796 int hpt_get_driver_capabilities(PDRIVER_CAPABILITIES cap);
798 /*-------------------------------------------------------------------------- */
801 * hpt_get_controller_count
802 * Version compatibility: v1.0.0.1 or later
806 * number of controllers
808 int hpt_get_controller_count();
810 /*-------------------------------------------------------------------------- */
812 /* hpt_get_controller_info
813 * Version compatibility: v1.0.0.1 or later
816 * pInfo pointer to CONTROLLER_INFO buffer
818 * 0 Success, controller info is put into (*pInfo ).
820 int hpt_get_controller_info(int id, PCONTROLLER_INFO pInfo);
822 /*-------------------------------------------------------------------------- */
824 /* hpt_get_channel_info
825 * Version compatibility: v1.0.0.1 or later
829 * pInfo pointer to CHANNEL_INFO buffer
831 * 0 Success, channel info is put into (*pInfo ).
833 int hpt_get_channel_info(int id, int bus, PCHANNEL_INFO pInfo);
835 /*-------------------------------------------------------------------------- */
837 /* hpt_get_logical_devices
838 * Version compatibility: v1.0.0.1 or later
840 * pIds pointer to a DEVICEID array
841 * nMaxCount array size
843 * Number of ID returned. All logical device IDs are put into pIds array.
844 * Note: A spare disk is not a logical device.
846 int hpt_get_logical_devices(DEVICEID * pIds, int nMaxCount);
848 /*-------------------------------------------------------------------------- */
850 /* hpt_get_device_info
851 * Version compatibility: v1.0.0.1 or later
853 * id logical device id
854 * pInfo pointer to HPT_ARRAY_INFO structure
858 int hpt_get_device_info(DEVICEID id, PLOGICAL_DEVICE_INFO pInfo);
860 #if HPT_INTERFACE_VERSION>=0x01010000
861 int hpt_get_device_info_v2(DEVICEID id, PLOGICAL_DEVICE_INFO_V2 pInfo);
864 /*-------------------------------------------------------------------------- */
867 * Version compatibility: v1.0.0.1 or later
869 * pParam pointer to CREATE_ARRAY_PARAMS structure
872 * else return array id
874 DEVICEID hpt_create_array(PCREATE_ARRAY_PARAMS pParam);
876 #if HPT_INTERFACE_VERSION>=0x01010000
877 DEVICEID hpt_create_array_v2(PCREATE_ARRAY_PARAMS_V2 pParam);
880 /*-------------------------------------------------------------------------- */
883 * Version compatibility: v1.0.0.1 or later
889 int hpt_delete_array(DEVICEID id, DWORD options);
891 /*-------------------------------------------------------------------------- */
894 * Read/write data on array and physcal device.
895 * Version compatibility: v1.0.0.1 or later
897 * id device id. If it's an array ID, IO will be performed on the array.
898 * If it's a physical device ID, IO will be performed on the device.
899 * cmd IO_COMMAND_READ or IO_COMMAND_WRITE
905 int hpt_device_io(DEVICEID id, int cmd, ULONG lba, DWORD nSector, LPVOID buffer);
907 #if HPT_INTERFACE_VERSION >= 0x01010000
908 int hpt_device_io_v2(DEVICEID id, int cmd, LBA64 lba, DWORD nSector, LPVOID buffer);
911 /* hpt_add_disk_to_array
912 * Used to dynamicly add a disk to an RAID1, RAID0/1, RAID1/0 or RAID5 array.
913 * Auto-rebuild will start.
914 * Version compatibility: v1.0.0.1 or later
921 int hpt_add_disk_to_array(DEVICEID idArray, DEVICEID idDisk);
922 /*-------------------------------------------------------------------------- */
924 /* hpt_add_spare_disk
925 * Version compatibility: v1.0.0.1 or later
926 * Add a disk to spare pool.
932 int hpt_add_spare_disk(DEVICEID idDisk);
933 /*-------------------------------------------------------------------------- */
935 /* hpt_add_dedicated_spare
936 * Version compatibility: v1.0.0.3 or later
937 * Add a spare disk to an array
944 int hpt_add_dedicated_spare(DEVICEID idDisk, DEVICEID idArray);
945 /*-------------------------------------------------------------------------- */
947 /* hpt_remove_spare_disk
948 * remove a disk from spare pool.
949 * Version compatibility: v1.0.0.1 or later
955 int hpt_remove_spare_disk(DEVICEID idDisk);
956 /*-------------------------------------------------------------------------- */
959 * Used to poll events from driver.
960 * Version compatibility: v1.0.0.1 or later
962 * pEvent pointer to HPT_EVENT structure
964 * 0 Success, event info is filled in *pEvent
966 int hpt_get_event(PHPT_EVENT pEvent);
967 /*-------------------------------------------------------------------------- */
969 /* hpt_rebuild_data_block
970 * Used to copy data from source disk and mirror disk.
971 * Version compatibility: v1.0.0.1 or later
973 * idArray Array ID (RAID1, 0/1 or RAID5)
974 * Lba Start LBA for each array member
975 * nSector Number of sectors for each array member (RAID 5 will ignore this parameter)
978 * 0 Success, event info is filled in *pEvent
980 int hpt_rebuild_data_block(DEVICEID idMirror, DWORD Lba, UCHAR nSector);
981 #define hpt_rebuild_mirror(p1, p2, p3) hpt_rebuild_data_block(p1, p2, p3)
983 #if HPT_INTERFACE_VERSION >= 0x01010000
984 int hpt_rebuild_data_block_v2(DEVICEID idArray, LBA64 Lba, USHORT nSector);
986 /*-------------------------------------------------------------------------- */
988 /* hpt_set_array_state
990 * Version compatibility: v1.0.0.1 or later
993 * state See above 'array states' constants, possible values are:
994 * MIRROR_REBUILD_START
995 * Indicate that GUI wants to rebuild a mirror array
996 * MIRROR_REBUILD_ABORT
997 * GUI wants to abort rebuilding an array
998 * MIRROR_REBUILD_COMPLETE
999 * GUI finished to rebuild an array. If rebuild is done by driver this
1005 int hpt_set_array_state(DEVICEID idArray, DWORD state);
1006 /*-------------------------------------------------------------------------- */
1008 /* hpt_set_array_info
1010 * Version compatibility: v1.0.0.1 or later
1013 * pInfo pointer to new info
1018 int hpt_set_array_info(DEVICEID idArray, PALTERABLE_ARRAY_INFO pInfo);
1019 /*-------------------------------------------------------------------------- */
1021 /* hpt_set_device_info
1023 * Version compatibility: v1.0.0.1 or later
1026 * pInfo pointer to new info
1031 * If idDisk==0, call to this function will stop buzzer on the adapter
1032 * (if supported by driver).
1034 int hpt_set_device_info(DEVICEID idDisk, PALTERABLE_DEVICE_INFO pInfo);
1036 #if HPT_INTERFACE_VERSION >= 0x01000004
1037 int hpt_set_device_info_v2(DEVICEID idDisk, PALTERABLE_DEVICE_INFO_V2 pInfo);
1040 /*-------------------------------------------------------------------------- */
1042 /* hpt_rescan_devices
1044 * Version compatibility: v1.0.0.1 or later
1050 int hpt_rescan_devices();
1051 /*-------------------------------------------------------------------------- */
1055 * Version compatibiilty: v1.0.0.3 or later
1057 * idDisk - Disk handle
1058 * PHPT601_INFO - pointer to HPT601 info buffer
1062 int hpt_get_601_info(DEVICEID idDisk, PHPT601_INFO pInfo);
1063 /*-------------------------------------------------------------------------- */
1066 * HPT601 function control
1067 * Version compatibiilty: v1.0.0.3 or later
1069 * idDisk - Disk handle
1070 * PHPT601_INFO - pointer to HPT601 info buffer
1074 int hpt_set_601_info(DEVICEID idDisk, PHPT601_INFO pInfo);
1075 /*-------------------------------------------------------------------------- */
1078 * Lock a block on a device (prevent OS accessing it)
1079 * Version compatibiilty: v1.0.0.3 or later
1081 * idDisk - Disk handle
1083 * nSectors - number of sectors
1087 int hpt_lock_device(DEVICEID idDisk, ULONG Lba, UCHAR nSectors);
1089 #if HPT_INTERFACE_VERSION >= 0x01010000
1090 int hpt_lock_device_v2(DEVICEID idDisk, LBA64 Lba, USHORT nSectors);
1092 /*-------------------------------------------------------------------------- */
1096 * Version compatibiilty: v1.0.0.3 or later
1098 * idDisk - Disk handle
1102 int hpt_unlock_device(DEVICEID idDisk);
1103 /*-------------------------------------------------------------------------- */
1105 /* hpt_ide_pass_through
1106 * directly access controller's command and control registers.
1107 * Can only call it on physical devices.
1108 * Version compatibility: v1.0.0.3 or later
1110 * p - IDE_PASS_THROUGH header pointer
1114 int hpt_ide_pass_through(PIDE_PASS_THROUGH_HEADER p);
1115 /*-------------------------------------------------------------------------- */
1117 /* hpt_verify_data_block
1118 * verify data block on RAID1 or RAID5.
1119 * Version compatibility: v1.0.0.3 or later
1121 * idArray - Array ID
1122 * Lba - block number (on each array member, not logical block!)
1123 * nSectors - Sectors for each member (RAID 5 will ignore this parameter)
1126 * 1 Data compare error
1129 int hpt_verify_data_block(DEVICEID idArray, ULONG Lba, UCHAR nSectors);
1131 #if HPT_INTERFACE_VERSION >= 0x01010000
1132 int hpt_verify_data_block_v2(DEVICEID idArray, LBA64 Lba, USHORT nSectors);
1134 /*-------------------------------------------------------------------------- */
1136 /* hpt_initialize_data_block
1137 * initialize data block (fill with zero) on RAID5
1138 * Version compatibility: v1.0.0.3 or later
1140 * idArray - Array ID
1141 * Lba - block number (on each array member, not logical block!)
1142 * nSectors - Sectors for each member (RAID 5 will ignore this parameter)
1146 int hpt_initialize_data_block(DEVICEID idArray, ULONG Lba, UCHAR nSectors);
1148 #if HPT_INTERFACE_VERSION >= 0x01010000
1149 int hpt_initialize_data_block_v2(DEVICEID idArray, LBA64 Lba, USHORT nSectors);
1151 /*-------------------------------------------------------------------------- */
1154 * extended device I/O function
1155 * Version compatibility: v1.0.0.3 or later
1157 * idArray - Array ID
1158 * Lba - block number (on each array member, not logical block!)
1159 * nSectors - Sectors for each member
1160 * buffer - I/O buffer or s/g address
1164 int hpt_device_io_ex(PDEVICE_IO_EX_PARAMS param);
1165 #if HPT_INTERFACE_VERSION >= 0x01010000
1166 int hpt_device_io_ex_v2(void * param); /* NOT IMPLEMENTED */
1168 /*-------------------------------------------------------------------------- */
1170 /* hpt_set_boot_mark
1171 * select boot device
1172 * Version compatibility: v1.0.0.3 or later
1174 * id - logical device ID. If id is 0 the boot mark will be removed.
1178 int hpt_set_boot_mark(DEVICEID id);
1179 /*-------------------------------------------------------------------------- */
1182 * check if device can be removed safely
1183 * Version compatibility: v1.0.0.4 or later
1185 * ndev - number of devices
1186 * pIds - device ID list
1189 * -1 - unknown error
1190 * n - the n-th device that can't be removed
1192 int hpt_query_remove(DWORD ndev, DEVICEID *pIds);
1193 /*-------------------------------------------------------------------------- */
1195 /* hpt_remove_devices
1196 * remove a list of devices
1197 * Version compatibility: v1.0.0.4 or later
1199 * ndev - number of devices
1200 * pIds - device ID list
1203 * -1 - unknown error
1204 * n - the n-th device that can't be removed
1206 int hpt_remove_devices(DWORD ndev, DEVICEID *pIds);
1207 /*-------------------------------------------------------------------------- */