2 * Copyright (c) 2000 - 2006 Søren Schmidt <sos@FreeBSD.org>
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 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: src/sys/dev/ata/ata-raid.h,v 1.44 2006/02/17 13:02:10 sos Exp $
27 * $DragonFly: src/sys/dev/disk/nata/ata-raid.h,v 1.2 2007/02/06 15:17:44 tgen Exp $
30 #include <sys/param.h>
35 #include <sys/spinlock.h>
41 #define AR_PROXIMITY 2048 /* how many sectors is "close" */
43 #define ATA_MAGIC "FreeBSD ATA driver RAID "
45 struct ata_raid_subdisk {
46 struct ar_softc *raid[MAX_VOLUMES];
47 int disk_number[MAX_VOLUMES];
50 /* ATA PseudoRAID Metadata */
58 #define AR_T_JBOD 0x0001
59 #define AR_T_SPAN 0x0002
60 #define AR_T_RAID0 0x0004
61 #define AR_T_RAID1 0x0008
62 #define AR_T_RAID01 0x0010
63 #define AR_T_RAID3 0x0020
64 #define AR_T_RAID4 0x0040
65 #define AR_T_RAID5 0x0080
68 #define AR_S_READY 0x0001
69 #define AR_S_DEGRADED 0x0002
70 #define AR_S_REBUILDING 0x0004
73 #define AR_F_FREEBSD_RAID 0x0001
74 #define AR_F_ADAPTEC_RAID 0x0002
75 #define AR_F_HPTV2_RAID 0x0004
76 #define AR_F_HPTV3_RAID 0x0008
77 #define AR_F_INTEL_RAID 0x0010
78 #define AR_F_ITE_RAID 0x0020
79 #define AR_F_JMICRON_RAID 0x0040
80 #define AR_F_LSIV2_RAID 0x0080
81 #define AR_F_LSIV3_RAID 0x0100
82 #define AR_F_NVIDIA_RAID 0x0200
83 #define AR_F_PROMISE_RAID 0x0400
84 #define AR_F_SII_RAID 0x0800
85 #define AR_F_SIS_RAID 0x1000
86 #define AR_F_VIA_RAID 0x2000
87 #define AR_F_FORMAT_MASK 0x1fff
90 u_int64_t total_sectors;
91 u_int64_t offset_sectors; /* offset from start of disk */
95 u_int width; /* array width in disks */
96 u_int interleave; /* interleave in sectors */
97 u_int total_disks; /* number of disks in this array */
100 u_int8_t serial[16]; /* serial # of physical disk */
101 u_int64_t sectors; /* useable sectors on this disk */
102 off_t last_lba; /* last lba used (for performance) */
104 #define AR_DF_PRESENT 0x0001 /* this HW pos has a disk present */
105 #define AR_DF_ASSIGNED 0x0002 /* this HW pos assigned to an array */
106 #define AR_DF_SPARE 0x0004 /* this HW pos is a spare */
107 #define AR_DF_ONLINE 0x0008 /* this HW pos is online and in use */
110 int toggle; /* performance hack for RAID1's */
111 u_int64_t rebuild_lba; /* rebuild progress indicator */
112 struct spinlock lock; /* metadata lock */
113 struct disk disk; /* disklabel/slice stuff */
114 cdev_t cdev; /* device placeholder */
115 struct proc *pid; /* rebuilder process id */
118 /* Adaptec HostRAID Metadata */
119 #define ADP_LBA(dev) \
120 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 17)
122 /* note all entries are big endian */
123 struct adaptec_raid_conf {
125 #define ADP_MAGIC_0 0xc4650790
127 u_int32_t generation;
129 u_int16_t total_configs;
136 u_int32_t dummy_4[4];
137 u_int32_t dummy_5[4];
139 u_int16_t total_disks;
140 u_int16_t generation;
144 #define ADP_T_RAID0 0x00
145 #define ADP_T_RAID1 0x01
154 u_int32_t disk_number;
157 u_int16_t stripe_shift;
160 u_int32_t dummy_8[4];
163 u_int32_t dummy_6[13];
165 #define ADP_MAGIC_1 0x9ff85009
166 u_int32_t dummy_7[3];
168 u_int32_t dummy_8[46];
170 #define ADP_MAGIC_3 0x4d545044
172 #define ADP_MAGIC_4 0x9ff85009
173 u_int32_t dummy_9[62];
177 /* Highpoint V2 RocketRAID Metadata */
178 #define HPTV2_LBA(dev) 9
180 struct hptv2_raid_conf {
183 #define HPTV2_MAGIC_OK 0x5a7816f0
184 #define HPTV2_MAGIC_BAD 0x5a7816fd
189 #define HPTV2_O_RAID0 0x01
190 #define HPTV2_O_RAID1 0x02
191 #define HPTV2_O_OK 0x04
193 u_int8_t array_width;
194 u_int8_t stripe_shift;
196 #define HPTV2_T_RAID0 0x00
197 #define HPTV2_T_RAID1 0x01
198 #define HPTV2_T_RAID01_RAID0 0x02
199 #define HPTV2_T_SPAN 0x03
200 #define HPTV2_T_RAID_3 0x04
201 #define HPTV2_T_RAID_5 0x05
202 #define HPTV2_T_JBOD 0x06
203 #define HPTV2_T_RAID01_RAID1 0x07
205 u_int8_t disk_number;
206 u_int32_t total_sectors;
210 u_int8_t boot_protect;
211 u_int8_t error_log_entries;
212 u_int8_t error_log_index;
216 #define HPTV2_R_REMOVED 0xfe
217 #define HPTV2_R_BROKEN 0xff
225 u_int32_t rebuild_lba;
234 /* Highpoint V3 RocketRAID Metadata */
235 #define HPTV3_LBA(dev) \
236 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 11)
238 struct hptv3_raid_conf {
240 #define HPTV3_MAGIC 0x5a7816f3
245 #define HPTV3_BOOT_MARK 0x01
246 #define HPTV3_USER_MODE 0x02
249 u_int8_t config_entries;
251 u_int32_t total_sectors;
253 #define HPTV3_T_SPARE 0x00
254 #define HPTV3_T_JBOD 0x03
255 #define HPTV3_T_SPAN 0x04
256 #define HPTV3_T_RAID0 0x05
257 #define HPTV3_T_RAID1 0x06
258 #define HPTV3_T_RAID3 0x07
259 #define HPTV3_T_RAID5 0x08
261 u_int8_t total_disks;
262 u_int8_t disk_number;
263 u_int8_t stripe_shift;
265 #define HPTV3_T_NEED_REBUILD 0x01
266 #define HPTV3_T_RAID5_FLAG 0x02
268 u_int16_t critical_disks;
269 u_int32_t rebuild_lba;
270 } __packed configs[2];
273 u_int8_t description[64];
274 u_int8_t creator[16];
279 #define HPTV3_T_ENABLE_TCQ 0x01
280 #define HPTV3_T_ENABLE_NCQ 0x02
281 #define HPTV3_T_ENABLE_WCACHE 0x04
282 #define HPTV3_T_ENABLE_RCACHE 0x08
285 u_int32_t total_sectors;
286 u_int32_t rebuild_lba;
287 } __packed configs_high[2];
288 u_int32_t filler[87];
292 /* Intel MatrixRAID Metadata */
293 #define INTEL_LBA(dev) \
294 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 3)
296 struct intel_raid_conf {
297 u_int8_t intel_id[24];
298 #define INTEL_MAGIC "Intel Raid ISM Cfg Sig. "
301 #define INTEL_VERSION_1100 "1.1.00"
302 #define INTEL_VERSION_1201 "1.2.01"
303 #define INTEL_VERSION_1202 "1.2.02"
307 u_int32_t config_size;
309 u_int32_t generation;
310 u_int32_t dummy_1[2];
311 u_int8_t total_disks;
312 u_int8_t total_volumes;
314 u_int32_t filler_0[39];
320 #define INTEL_F_SPARE 0x01
321 #define INTEL_F_ASSIGNED 0x02
322 #define INTEL_F_DOWN 0x04
323 #define INTEL_F_ONLINE 0x08
327 u_int32_t filler_1[62];
330 struct intel_raid_mapping {
332 u_int64_t total_sectors __packed;
335 u_int32_t filler_0[20];
337 u_int32_t disk_sectors;
338 u_int32_t stripe_count;
339 u_int16_t stripe_sectors;
341 #define INTEL_S_READY 0x00
342 #define INTEL_S_DISABLED 0x01
343 #define INTEL_S_DEGRADED 0x02
344 #define INTEL_S_FAILURE 0x03
347 #define INTEL_T_RAID0 0x00
348 #define INTEL_T_RAID1 0x01
349 #define INTEL_T_RAID5 0x05
351 u_int8_t total_disks;
353 u_int32_t filler_1[7];
354 u_int32_t disk_idx[1];
358 /* Integrated Technology Express Metadata */
359 #define ITE_LBA(dev) \
360 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
362 struct ite_raid_conf {
363 u_int32_t filler_1[5];
364 u_int8_t timestamp_0[8];
366 u_int32_t filler_2[5];
369 #define ITE_MAGIC "Integrated Technology Express Inc "
372 u_int32_t filler_5[6];
375 u_int32_t filler_6[12];
377 u_int32_t filler_7[5];
378 u_int64_t total_sectors __packed;
379 u_int32_t filler_8[12];
383 #define ITE_T_RAID0 0x00
384 #define ITE_T_RAID1 0x01
385 #define ITE_T_RAID01 0x02
386 #define ITE_T_SPAN 0x03
389 u_int32_t dummy_5[8];
390 u_int8_t stripe_1kblocks;
391 u_int8_t filler_11[3];
392 u_int32_t filler_12[54];
394 u_int32_t dummy_6[4];
395 u_int8_t timestamp_1[8];
396 u_int32_t filler_13[9];
397 u_int8_t stripe_sectors;
398 u_int8_t filler_14[3];
399 u_int8_t array_width;
400 u_int8_t filler_15[3];
403 u_int8_t disk_number;
404 u_int32_t disk_sectors;
406 u_int32_t dummy_7[4];
407 u_int32_t filler_20[104];
411 /* JMicron Technology Corp Metadata */
412 #define JMICRON_LBA(dev) \
413 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
414 #define JM_MAX_DISKS 8
416 struct jmicron_raid_conf {
417 u_int8_t signature[2];
418 #define JMICRON_MAGIC "JM"
421 #define JMICRON_VERSION 0x0001
424 u_int8_t filler_1[10];
427 u_int32_t disk_sectors_high;
428 u_int16_t disk_sectors_low;
429 u_int8_t filler_2[2];
434 #define JM_T_RAID01 2
438 u_int8_t stripe_shift;
440 #define JM_F_READY 0x0001
441 #define JM_F_BOOTABLE 0x0002
442 #define JM_F_BAD 0x0004
443 #define JM_F_ACTIVE 0c0010
444 #define JM_F_UNSYNC 0c0020
445 #define JM_F_NEWEST 0c0040
447 u_int8_t filler_3[4];
449 u_int32_t disks[JM_MAX_DISKS];
450 u_int8_t filler_4[32];
451 u_int8_t filler_5[384];
455 /* LSILogic V2 MegaRAID Metadata */
456 #define LSIV2_LBA(dev) \
457 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
459 struct lsiv2_raid_conf {
461 #define LSIV2_MAGIC "$XIDE$"
466 u_int8_t config_entries;
468 u_int8_t total_disks;
475 #define LSIV2_T_RAID0 0x01
476 #define LSIV2_T_RAID1 0x02
477 #define LSIV2_T_SPARE 0x08
480 u_int16_t stripe_sectors;
481 u_int8_t array_width;
483 u_int8_t config_offset;
486 #define LSIV2_R_DEGRADED 0x02
488 u_int32_t total_sectors;
493 #define LSIV2_D_MASTER 0x00
494 #define LSIV2_D_SLAVE 0x01
495 #define LSIV2_D_CHANNEL0 0x00
496 #define LSIV2_D_CHANNEL1 0x10
497 #define LSIV2_D_NONE 0xff
500 u_int32_t disk_sectors;
501 u_int8_t disk_number;
502 u_int8_t raid_number;
504 #define LSIV2_D_GONE 0x02
509 u_int8_t disk_number;
510 u_int8_t raid_number;
516 /* LSILogic V3 MegaRAID Metadata */
517 #define LSIV3_LBA(dev) \
518 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 4)
520 struct lsiv3_raid_conf {
521 u_int32_t magic_0; /* 0xa0203200 */
522 u_int32_t filler_0[3];
523 u_int8_t magic_1[4]; /* "SATA" */
524 u_int32_t filler_1[40];
525 u_int32_t dummy_0; /* 0x0d000003 */
526 u_int32_t filler_2[7];
527 u_int32_t dummy_1; /* 0x0d000003 */
528 u_int32_t filler_3[70];
529 u_int8_t magic_2[8]; /* "$_ENQ$31" */
530 u_int8_t filler_4[7];
532 u_int8_t filler_5[512*2];
534 #define LSIV3_MAGIC "$_IDE$"
536 u_int16_t dummy_2; /* 0x33de for OK disk */
537 u_int16_t version; /* 0x0131 for this version */
538 u_int16_t dummy_3; /* 0x0440 always */
542 u_int16_t stripe_pages;
544 #define LSIV3_T_RAID0 0x00
545 #define LSIV3_T_RAID1 0x01
548 u_int8_t total_disks;
549 u_int8_t array_width;
550 u_int8_t filler_0[10];
557 #define LSIV3_D_DEVICE 0x01
558 #define LSIV3_D_CHANNEL 0x10
563 u_int8_t filler_1[16];
566 u_int32_t disk_sectors;
572 #define LSIV3_D_MIRROR 0x00
573 #define LSIV3_D_STRIPE 0xff
576 u_int8_t filler_7[7];
579 u_int8_t filler_8[3];
584 /* nVidia MediaShield Metadata */
585 #define NVIDIA_LBA(dev) \
586 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
588 struct nvidia_raid_conf {
589 u_int8_t nvidia_id[8];
590 #define NV_MAGIC "NVIDIA "
592 u_int32_t config_size;
595 u_int8_t disk_number;
597 u_int32_t total_sectors;
598 u_int32_t sector_size;
600 u_int8_t revision[4];
604 #define NV_MAGIC0 0x00640044
609 u_int8_t array_width;
610 u_int8_t total_disks;
613 #define NV_T_RAID0 0x00000080
614 #define NV_T_RAID1 0x00000081
615 #define NV_T_RAID3 0x00000083
616 #define NV_T_RAID5 0x00000085
617 #define NV_T_RAID01 0x00008180
618 #define NV_T_SPAN 0x000000ff
621 u_int32_t stripe_sectors;
622 u_int32_t stripe_bytes;
623 u_int32_t stripe_shift;
624 u_int32_t stripe_mask;
625 u_int32_t stripe_sizesectors;
626 u_int32_t stripe_sizebytes;
627 u_int32_t rebuild_lba;
631 #define NV_S_BOOTABLE 0x00000001
632 #define NV_S_DEGRADED 0x00000002
634 u_int32_t filler[98];
638 /* Promise FastTrak Metadata */
639 #define PROMISE_LBA(dev) \
640 (((((struct ad_softc *)device_get_ivars(dev))->total_secs / (((struct ad_softc *)device_get_ivars(dev))->heads * ((struct ad_softc *)device_get_ivars(dev))->sectors)) * ((struct ad_softc *)device_get_ivars(dev))->heads * ((struct ad_softc *)device_get_ivars(dev))->sectors) - ((struct ad_softc *)device_get_ivars(dev))->sectors)
642 struct promise_raid_conf {
644 #define PR_MAGIC "Promise Technology, Inc."
648 #define PR_MAGIC0(x) (((u_int64_t)(x.channel) << 48) | \
649 ((u_int64_t)(x.device != 0) << 56))
652 u_int8_t filler1[470];
655 #define PR_I_VALID 0x00000080
658 #define PR_F_VALID 0x00000001
659 #define PR_F_ONLINE 0x00000002
660 #define PR_F_ASSIGNED 0x00000004
661 #define PR_F_SPARE 0x00000008
662 #define PR_F_DUPLICATE 0x00000010
663 #define PR_F_REDIR 0x00000020
664 #define PR_F_DOWN 0x00000040
665 #define PR_F_READY 0x00000080
667 u_int8_t disk_number;
670 u_int64_t magic_0 __packed;
671 u_int32_t disk_offset;
672 u_int32_t disk_sectors;
673 u_int32_t rebuild_lba;
674 u_int16_t generation;
676 #define PR_S_VALID 0x01
677 #define PR_S_ONLINE 0x02
678 #define PR_S_INITED 0x04
679 #define PR_S_READY 0x08
680 #define PR_S_DEGRADED 0x10
681 #define PR_S_MARKED 0x20
682 #define PR_S_FUNCTIONAL 0x80
685 #define PR_T_RAID0 0x00
686 #define PR_T_RAID1 0x01
687 #define PR_T_RAID3 0x02
688 #define PR_T_RAID5 0x04
689 #define PR_T_SPAN 0x08
690 #define PR_T_JBOD 0x10
692 u_int8_t total_disks;
693 u_int8_t stripe_shift;
694 u_int8_t array_width;
695 u_int8_t array_number;
696 u_int32_t total_sectors;
700 u_int64_t magic_1 __packed;
706 u_int64_t magic_0 __packed;
709 int32_t filler2[346];
714 /* Silicon Image Medley Metadata */
715 #define SII_LBA(dev) \
716 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
718 struct sii_raid_conf {
719 u_int16_t ata_params_00_53[54];
720 u_int64_t total_sectors;
721 u_int16_t ata_params_58_79[70];
724 u_int32_t controller_pci_id;
725 u_int16_t version_minor;
726 u_int16_t version_major;
727 u_int8_t timestamp[6];
728 u_int16_t stripe_sectors;
730 u_int8_t disk_number;
732 #define SII_T_RAID0 0x00
733 #define SII_T_RAID1 0x01
734 #define SII_T_RAID01 0x02
735 #define SII_T_SPARE 0x03
737 u_int8_t raid0_disks;
738 u_int8_t raid0_ident;
739 u_int8_t raid1_disks;
740 u_int8_t raid1_ident;
741 u_int64_t rebuild_lba;
742 u_int32_t generation;
744 #define SII_S_READY 0x01
746 u_int8_t base_raid1_position;
747 u_int8_t base_raid0_position;
751 u_int16_t checksum_0;
753 u_int16_t checksum_1;
757 /* Silicon Integrated Systems RAID Metadata */
758 #define SIS_LBA(dev) \
759 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 16)
761 struct sis_raid_conf {
763 #define SIS_MAGIC 0x0010
766 #define SIS_D_MASTER 0xf0
767 #define SIS_D_MIRROR 0x0f
769 u_int8_t type_total_disks;
770 #define SIS_D_MASK 0x0f
771 #define SIS_T_MASK 0xf0
772 #define SIS_T_JBOD 0x10
773 #define SIS_T_RAID0 0x20
774 #define SIS_T_RAID1 0x30
777 u_int32_t controller_pci_id;
778 u_int16_t stripe_sectors;
782 u_int8_t disk_number;
788 /* VIA Tech V-RAID Metadata */
789 #define VIA_LBA(dev) \
790 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
792 struct via_raid_conf {
794 #define VIA_MAGIC 0xaa55
798 #define VIA_T_MASK 0x7e
799 #define VIA_T_BOOTABLE 0x01
800 #define VIA_T_RAID0 0x04
801 #define VIA_T_RAID1 0x0c
802 #define VIA_T_RAID01 0x4c
803 #define VIA_T_RAID5 0x2c
804 #define VIA_T_SPAN 0x44
805 #define VIA_T_UNKNOWN 0x80
808 #define VIA_D_MASK 0x0f
809 #define VIA_D_DEGRADED 0x10
810 #define VIA_D_HIGH_IDX 0x20
812 u_int8_t stripe_layout;
813 #define VIA_L_DISKS 0x07
814 #define VIA_L_MASK 0xf0
815 #define VIA_L_SHIFT 4
817 u_int64_t disk_sectors;
821 u_int8_t filler_1[461];