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 struct devstat devstat; /* device statistics */
115 cdev_t cdev; /* device placeholder */
116 struct proc *pid; /* rebuilder process id */
119 /* Adaptec HostRAID Metadata */
120 #define ADP_LBA(dev) \
121 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 17)
123 /* note all entries are big endian */
124 struct adaptec_raid_conf {
126 #define ADP_MAGIC_0 0xc4650790
128 u_int32_t generation;
130 u_int16_t total_configs;
137 u_int32_t dummy_4[4];
138 u_int32_t dummy_5[4];
140 u_int16_t total_disks;
141 u_int16_t generation;
145 #define ADP_T_RAID0 0x00
146 #define ADP_T_RAID1 0x01
155 u_int32_t disk_number;
158 u_int16_t stripe_shift;
161 u_int32_t dummy_8[4];
164 u_int32_t dummy_6[13];
166 #define ADP_MAGIC_1 0x9ff85009
167 u_int32_t dummy_7[3];
169 u_int32_t dummy_8[46];
171 #define ADP_MAGIC_3 0x4d545044
173 #define ADP_MAGIC_4 0x9ff85009
174 u_int32_t dummy_9[62];
178 /* Highpoint V2 RocketRAID Metadata */
179 #define HPTV2_LBA(dev) 9
181 struct hptv2_raid_conf {
184 #define HPTV2_MAGIC_OK 0x5a7816f0
185 #define HPTV2_MAGIC_BAD 0x5a7816fd
190 #define HPTV2_O_RAID0 0x01
191 #define HPTV2_O_RAID1 0x02
192 #define HPTV2_O_OK 0x04
194 u_int8_t array_width;
195 u_int8_t stripe_shift;
197 #define HPTV2_T_RAID0 0x00
198 #define HPTV2_T_RAID1 0x01
199 #define HPTV2_T_RAID01_RAID0 0x02
200 #define HPTV2_T_SPAN 0x03
201 #define HPTV2_T_RAID_3 0x04
202 #define HPTV2_T_RAID_5 0x05
203 #define HPTV2_T_JBOD 0x06
204 #define HPTV2_T_RAID01_RAID1 0x07
206 u_int8_t disk_number;
207 u_int32_t total_sectors;
211 u_int8_t boot_protect;
212 u_int8_t error_log_entries;
213 u_int8_t error_log_index;
217 #define HPTV2_R_REMOVED 0xfe
218 #define HPTV2_R_BROKEN 0xff
226 u_int32_t rebuild_lba;
235 /* Highpoint V3 RocketRAID Metadata */
236 #define HPTV3_LBA(dev) \
237 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 11)
239 struct hptv3_raid_conf {
241 #define HPTV3_MAGIC 0x5a7816f3
246 #define HPTV3_BOOT_MARK 0x01
247 #define HPTV3_USER_MODE 0x02
250 u_int8_t config_entries;
252 u_int32_t total_sectors;
254 #define HPTV3_T_SPARE 0x00
255 #define HPTV3_T_JBOD 0x03
256 #define HPTV3_T_SPAN 0x04
257 #define HPTV3_T_RAID0 0x05
258 #define HPTV3_T_RAID1 0x06
259 #define HPTV3_T_RAID3 0x07
260 #define HPTV3_T_RAID5 0x08
262 u_int8_t total_disks;
263 u_int8_t disk_number;
264 u_int8_t stripe_shift;
266 #define HPTV3_T_NEED_REBUILD 0x01
267 #define HPTV3_T_RAID5_FLAG 0x02
269 u_int16_t critical_disks;
270 u_int32_t rebuild_lba;
271 } __packed configs[2];
274 u_int8_t description[64];
275 u_int8_t creator[16];
280 #define HPTV3_T_ENABLE_TCQ 0x01
281 #define HPTV3_T_ENABLE_NCQ 0x02
282 #define HPTV3_T_ENABLE_WCACHE 0x04
283 #define HPTV3_T_ENABLE_RCACHE 0x08
286 u_int32_t total_sectors;
287 u_int32_t rebuild_lba;
288 } __packed configs_high[2];
289 u_int32_t filler[87];
293 /* Intel MatrixRAID Metadata */
294 #define INTEL_LBA(dev) \
295 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 3)
297 struct intel_raid_conf {
298 u_int8_t intel_id[24];
299 #define INTEL_MAGIC "Intel Raid ISM Cfg Sig. "
302 #define INTEL_VERSION_1100 "1.1.00"
303 #define INTEL_VERSION_1201 "1.2.01"
304 #define INTEL_VERSION_1202 "1.2.02"
308 u_int32_t config_size;
310 u_int32_t generation;
311 u_int32_t dummy_1[2];
312 u_int8_t total_disks;
313 u_int8_t total_volumes;
315 u_int32_t filler_0[39];
321 #define INTEL_F_SPARE 0x01
322 #define INTEL_F_ASSIGNED 0x02
323 #define INTEL_F_DOWN 0x04
324 #define INTEL_F_ONLINE 0x08
328 u_int32_t filler_1[62];
331 struct intel_raid_mapping {
333 u_int64_t total_sectors __packed;
336 u_int32_t filler_0[20];
338 u_int32_t disk_sectors;
339 u_int32_t stripe_count;
340 u_int16_t stripe_sectors;
342 #define INTEL_S_READY 0x00
343 #define INTEL_S_DISABLED 0x01
344 #define INTEL_S_DEGRADED 0x02
345 #define INTEL_S_FAILURE 0x03
348 #define INTEL_T_RAID0 0x00
349 #define INTEL_T_RAID1 0x01
350 #define INTEL_T_RAID5 0x05
352 u_int8_t total_disks;
354 u_int32_t filler_1[7];
355 u_int32_t disk_idx[1];
359 /* Integrated Technology Express Metadata */
360 #define ITE_LBA(dev) \
361 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
363 struct ite_raid_conf {
364 u_int32_t filler_1[5];
365 u_int8_t timestamp_0[8];
367 u_int32_t filler_2[5];
370 #define ITE_MAGIC "Integrated Technology Express Inc "
373 u_int32_t filler_5[6];
376 u_int32_t filler_6[12];
378 u_int32_t filler_7[5];
379 u_int64_t total_sectors __packed;
380 u_int32_t filler_8[12];
384 #define ITE_T_RAID0 0x00
385 #define ITE_T_RAID1 0x01
386 #define ITE_T_RAID01 0x02
387 #define ITE_T_SPAN 0x03
390 u_int32_t dummy_5[8];
391 u_int8_t stripe_1kblocks;
392 u_int8_t filler_11[3];
393 u_int32_t filler_12[54];
395 u_int32_t dummy_6[4];
396 u_int8_t timestamp_1[8];
397 u_int32_t filler_13[9];
398 u_int8_t stripe_sectors;
399 u_int8_t filler_14[3];
400 u_int8_t array_width;
401 u_int8_t filler_15[3];
404 u_int8_t disk_number;
405 u_int32_t disk_sectors;
407 u_int32_t dummy_7[4];
408 u_int32_t filler_20[104];
412 /* JMicron Technology Corp Metadata */
413 #define JMICRON_LBA(dev) \
414 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
415 #define JM_MAX_DISKS 8
417 struct jmicron_raid_conf {
418 u_int8_t signature[2];
419 #define JMICRON_MAGIC "JM"
422 #define JMICRON_VERSION 0x0001
425 u_int8_t filler_1[10];
428 u_int32_t disk_sectors_high;
429 u_int16_t disk_sectors_low;
430 u_int8_t filler_2[2];
435 #define JM_T_RAID01 2
439 u_int8_t stripe_shift;
441 #define JM_F_READY 0x0001
442 #define JM_F_BOOTABLE 0x0002
443 #define JM_F_BAD 0x0004
444 #define JM_F_ACTIVE 0c0010
445 #define JM_F_UNSYNC 0c0020
446 #define JM_F_NEWEST 0c0040
448 u_int8_t filler_3[4];
450 u_int32_t disks[JM_MAX_DISKS];
451 u_int8_t filler_4[32];
452 u_int8_t filler_5[384];
456 /* LSILogic V2 MegaRAID Metadata */
457 #define LSIV2_LBA(dev) \
458 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
460 struct lsiv2_raid_conf {
462 #define LSIV2_MAGIC "$XIDE$"
467 u_int8_t config_entries;
469 u_int8_t total_disks;
476 #define LSIV2_T_RAID0 0x01
477 #define LSIV2_T_RAID1 0x02
478 #define LSIV2_T_SPARE 0x08
481 u_int16_t stripe_sectors;
482 u_int8_t array_width;
484 u_int8_t config_offset;
487 #define LSIV2_R_DEGRADED 0x02
489 u_int32_t total_sectors;
494 #define LSIV2_D_MASTER 0x00
495 #define LSIV2_D_SLAVE 0x01
496 #define LSIV2_D_CHANNEL0 0x00
497 #define LSIV2_D_CHANNEL1 0x10
498 #define LSIV2_D_NONE 0xff
501 u_int32_t disk_sectors;
502 u_int8_t disk_number;
503 u_int8_t raid_number;
505 #define LSIV2_D_GONE 0x02
510 u_int8_t disk_number;
511 u_int8_t raid_number;
517 /* LSILogic V3 MegaRAID Metadata */
518 #define LSIV3_LBA(dev) \
519 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 4)
521 struct lsiv3_raid_conf {
522 u_int32_t magic_0; /* 0xa0203200 */
523 u_int32_t filler_0[3];
524 u_int8_t magic_1[4]; /* "SATA" */
525 u_int32_t filler_1[40];
526 u_int32_t dummy_0; /* 0x0d000003 */
527 u_int32_t filler_2[7];
528 u_int32_t dummy_1; /* 0x0d000003 */
529 u_int32_t filler_3[70];
530 u_int8_t magic_2[8]; /* "$_ENQ$31" */
531 u_int8_t filler_4[7];
533 u_int8_t filler_5[512*2];
535 #define LSIV3_MAGIC "$_IDE$"
537 u_int16_t dummy_2; /* 0x33de for OK disk */
538 u_int16_t version; /* 0x0131 for this version */
539 u_int16_t dummy_3; /* 0x0440 always */
543 u_int16_t stripe_pages;
545 #define LSIV3_T_RAID0 0x00
546 #define LSIV3_T_RAID1 0x01
549 u_int8_t total_disks;
550 u_int8_t array_width;
551 u_int8_t filler_0[10];
558 #define LSIV3_D_DEVICE 0x01
559 #define LSIV3_D_CHANNEL 0x10
564 u_int8_t filler_1[16];
567 u_int32_t disk_sectors;
573 #define LSIV3_D_MIRROR 0x00
574 #define LSIV3_D_STRIPE 0xff
577 u_int8_t filler_7[7];
580 u_int8_t filler_8[3];
585 /* nVidia MediaShield Metadata */
586 #define NVIDIA_LBA(dev) \
587 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
589 struct nvidia_raid_conf {
590 u_int8_t nvidia_id[8];
591 #define NV_MAGIC "NVIDIA "
593 u_int32_t config_size;
596 u_int8_t disk_number;
598 u_int32_t total_sectors;
599 u_int32_t sector_size;
601 u_int8_t revision[4];
605 #define NV_MAGIC0 0x00640044
610 u_int8_t array_width;
611 u_int8_t total_disks;
614 #define NV_T_RAID0 0x00000080
615 #define NV_T_RAID1 0x00000081
616 #define NV_T_RAID3 0x00000083
617 #define NV_T_RAID5 0x00000085
618 #define NV_T_RAID01 0x00008180
619 #define NV_T_SPAN 0x000000ff
622 u_int32_t stripe_sectors;
623 u_int32_t stripe_bytes;
624 u_int32_t stripe_shift;
625 u_int32_t stripe_mask;
626 u_int32_t stripe_sizesectors;
627 u_int32_t stripe_sizebytes;
628 u_int32_t rebuild_lba;
632 #define NV_S_BOOTABLE 0x00000001
633 #define NV_S_DEGRADED 0x00000002
635 u_int32_t filler[98];
639 /* Promise FastTrak Metadata */
640 #define PROMISE_LBA(dev) \
641 (((((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)
643 struct promise_raid_conf {
645 #define PR_MAGIC "Promise Technology, Inc."
649 #define PR_MAGIC0(x) (((u_int64_t)(x.channel) << 48) | \
650 ((u_int64_t)(x.device != 0) << 56))
653 u_int8_t filler1[470];
656 #define PR_I_VALID 0x00000080
659 #define PR_F_VALID 0x00000001
660 #define PR_F_ONLINE 0x00000002
661 #define PR_F_ASSIGNED 0x00000004
662 #define PR_F_SPARE 0x00000008
663 #define PR_F_DUPLICATE 0x00000010
664 #define PR_F_REDIR 0x00000020
665 #define PR_F_DOWN 0x00000040
666 #define PR_F_READY 0x00000080
668 u_int8_t disk_number;
671 u_int64_t magic_0 __packed;
672 u_int32_t disk_offset;
673 u_int32_t disk_sectors;
674 u_int32_t rebuild_lba;
675 u_int16_t generation;
677 #define PR_S_VALID 0x01
678 #define PR_S_ONLINE 0x02
679 #define PR_S_INITED 0x04
680 #define PR_S_READY 0x08
681 #define PR_S_DEGRADED 0x10
682 #define PR_S_MARKED 0x20
683 #define PR_S_FUNCTIONAL 0x80
686 #define PR_T_RAID0 0x00
687 #define PR_T_RAID1 0x01
688 #define PR_T_RAID3 0x02
689 #define PR_T_RAID5 0x04
690 #define PR_T_SPAN 0x08
691 #define PR_T_JBOD 0x10
693 u_int8_t total_disks;
694 u_int8_t stripe_shift;
695 u_int8_t array_width;
696 u_int8_t array_number;
697 u_int32_t total_sectors;
701 u_int64_t magic_1 __packed;
707 u_int64_t magic_0 __packed;
710 int32_t filler2[346];
715 /* Silicon Image Medley Metadata */
716 #define SII_LBA(dev) \
717 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
719 struct sii_raid_conf {
720 u_int16_t ata_params_00_53[54];
721 u_int64_t total_sectors;
722 u_int16_t ata_params_58_79[70];
725 u_int32_t controller_pci_id;
726 u_int16_t version_minor;
727 u_int16_t version_major;
728 u_int8_t timestamp[6];
729 u_int16_t stripe_sectors;
731 u_int8_t disk_number;
733 #define SII_T_RAID0 0x00
734 #define SII_T_RAID1 0x01
735 #define SII_T_RAID01 0x02
736 #define SII_T_SPARE 0x03
738 u_int8_t raid0_disks;
739 u_int8_t raid0_ident;
740 u_int8_t raid1_disks;
741 u_int8_t raid1_ident;
742 u_int64_t rebuild_lba;
743 u_int32_t generation;
745 #define SII_S_READY 0x01
747 u_int8_t base_raid1_position;
748 u_int8_t base_raid0_position;
752 u_int16_t checksum_0;
754 u_int16_t checksum_1;
758 /* Silicon Integrated Systems RAID Metadata */
759 #define SIS_LBA(dev) \
760 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 16)
762 struct sis_raid_conf {
764 #define SIS_MAGIC 0x0010
767 #define SIS_D_MASTER 0xf0
768 #define SIS_D_MIRROR 0x0f
770 u_int8_t type_total_disks;
771 #define SIS_D_MASK 0x0f
772 #define SIS_T_MASK 0xf0
773 #define SIS_T_JBOD 0x10
774 #define SIS_T_RAID0 0x20
775 #define SIS_T_RAID1 0x30
778 u_int32_t controller_pci_id;
779 u_int16_t stripe_sectors;
783 u_int8_t disk_number;
789 /* VIA Tech V-RAID Metadata */
790 #define VIA_LBA(dev) \
791 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
793 struct via_raid_conf {
795 #define VIA_MAGIC 0xaa55
799 #define VIA_T_MASK 0x7e
800 #define VIA_T_BOOTABLE 0x01
801 #define VIA_T_RAID0 0x04
802 #define VIA_T_RAID1 0x0c
803 #define VIA_T_RAID01 0x4c
804 #define VIA_T_RAID5 0x2c
805 #define VIA_T_SPAN 0x44
806 #define VIA_T_UNKNOWN 0x80
809 #define VIA_D_MASK 0x0f
810 #define VIA_D_DEGRADED 0x10
811 #define VIA_D_HIGH_IDX 0x20
813 u_int8_t stripe_layout;
814 #define VIA_L_DISKS 0x07
815 #define VIA_L_MASK 0xf0
816 #define VIA_L_SHIFT 4
818 u_int64_t disk_sectors;
822 u_int8_t filler_1[461];