2 * Copyright (c) 2000 - 2008 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.
33 #define AR_PROXIMITY 2048 /* how many sectors is "close" */
35 #define ATA_MAGIC "FreeBSD ATA driver RAID "
37 struct ata_raid_subdisk {
38 struct ar_softc *raid[MAX_VOLUMES];
39 int disk_number[MAX_VOLUMES];
42 /* ATA PseudoRAID Metadata */
50 #define AR_T_JBOD 0x0001
51 #define AR_T_SPAN 0x0002
52 #define AR_T_RAID0 0x0004
53 #define AR_T_RAID1 0x0008
54 #define AR_T_RAID01 0x0010
55 #define AR_T_RAID3 0x0020
56 #define AR_T_RAID4 0x0040
57 #define AR_T_RAID5 0x0080
60 #define AR_S_READY 0x0001
61 #define AR_S_DEGRADED 0x0002
62 #define AR_S_REBUILDING 0x0004
65 #define AR_F_FREEBSD_RAID 0x0001
66 #define AR_F_ADAPTEC_RAID 0x0002
67 #define AR_F_HPTV2_RAID 0x0004
68 #define AR_F_HPTV3_RAID 0x0008
69 #define AR_F_INTEL_RAID 0x0010
70 #define AR_F_ITE_RAID 0x0020
71 #define AR_F_JMICRON_RAID 0x0040
72 #define AR_F_LSIV2_RAID 0x0080
73 #define AR_F_LSIV3_RAID 0x0100
74 #define AR_F_NVIDIA_RAID 0x0200
75 #define AR_F_PROMISE_RAID 0x0400
76 #define AR_F_SII_RAID 0x0800
77 #define AR_F_SIS_RAID 0x1000
78 #define AR_F_VIA_RAID 0x2000
79 #define AR_F_DDF_RAID 0x4000
80 #define AR_F_FORMAT_MASK 0x7fff
83 u_int64_t total_sectors;
84 u_int64_t offset_sectors; /* offset from start of disk */
88 u_int width; /* array width in disks */
89 u_int interleave; /* interleave in sectors */
90 u_int total_disks; /* number of disks in this array */
93 u_int8_t serial[16]; /* serial # of physical disk */
94 u_int64_t sectors; /* useable sectors on this disk */
95 off_t last_lba; /* last lba used (for performance) */
97 #define AR_DF_PRESENT 0x0001 /* this HW pos has a disk present */
98 #define AR_DF_ASSIGNED 0x0002 /* this HW pos assigned to an array */
99 #define AR_DF_SPARE 0x0004 /* this HW pos is a spare */
100 #define AR_DF_ONLINE 0x0008 /* this HW pos is online and in use */
103 int toggle; /* performance hack for RAID1's */
104 u_int64_t rebuild_lba; /* rebuild progress indicator */
105 struct mtx lock; /* metadata lock */
106 struct disk *disk; /* disklabel/slice stuff */
107 struct proc *pid; /* rebuilder process id */
110 /* Adaptec HostRAID Metadata */
111 #define ADP_LBA(dev) \
112 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 17)
114 /* note all entries are big endian */
115 struct adaptec_raid_conf {
117 #define ADP_MAGIC_0 0xc4650790
119 u_int32_t generation;
121 u_int16_t total_configs;
128 u_int32_t dummy_4[4];
129 u_int32_t dummy_5[4];
131 u_int16_t total_disks;
132 u_int16_t generation;
136 #define ADP_T_RAID0 0x00
137 #define ADP_T_RAID1 0x01
146 u_int32_t disk_number;
149 u_int16_t stripe_shift;
152 u_int32_t dummy_8[4];
155 u_int32_t dummy_6[13];
157 #define ADP_MAGIC_1 0x9ff85009
158 u_int32_t dummy_7[3];
160 u_int32_t dummy_8[46];
162 #define ADP_MAGIC_3 0x4d545044
164 #define ADP_MAGIC_4 0x9ff85009
165 u_int32_t dummy_9[62];
168 /* DDF Information. Metadata definitions are in another file */
169 #define DDF_LBA(dev) \
170 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
172 /* Highpoint V2 RocketRAID Metadata */
173 #define HPTV2_LBA(dev) 9
175 struct hptv2_raid_conf {
178 #define HPTV2_MAGIC_OK 0x5a7816f0
179 #define HPTV2_MAGIC_BAD 0x5a7816fd
184 #define HPTV2_O_RAID0 0x01
185 #define HPTV2_O_RAID1 0x02
186 #define HPTV2_O_OK 0x04
188 u_int8_t array_width;
189 u_int8_t stripe_shift;
191 #define HPTV2_T_RAID0 0x00
192 #define HPTV2_T_RAID1 0x01
193 #define HPTV2_T_RAID01_RAID0 0x02
194 #define HPTV2_T_SPAN 0x03
195 #define HPTV2_T_RAID_3 0x04
196 #define HPTV2_T_RAID_5 0x05
197 #define HPTV2_T_JBOD 0x06
198 #define HPTV2_T_RAID01_RAID1 0x07
200 u_int8_t disk_number;
201 u_int32_t total_sectors;
205 u_int8_t boot_protect;
206 u_int8_t error_log_entries;
207 u_int8_t error_log_index;
211 #define HPTV2_R_REMOVED 0xfe
212 #define HPTV2_R_BROKEN 0xff
220 u_int32_t rebuild_lba;
229 /* Highpoint V3 RocketRAID Metadata */
230 #define HPTV3_LBA(dev) \
231 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 11)
233 struct hptv3_raid_conf {
235 #define HPTV3_MAGIC 0x5a7816f3
240 #define HPTV3_BOOT_MARK 0x01
241 #define HPTV3_USER_MODE 0x02
244 u_int8_t config_entries;
246 u_int32_t total_sectors;
248 #define HPTV3_T_SPARE 0x00
249 #define HPTV3_T_JBOD 0x03
250 #define HPTV3_T_SPAN 0x04
251 #define HPTV3_T_RAID0 0x05
252 #define HPTV3_T_RAID1 0x06
253 #define HPTV3_T_RAID3 0x07
254 #define HPTV3_T_RAID5 0x08
256 u_int8_t total_disks;
257 u_int8_t disk_number;
258 u_int8_t stripe_shift;
260 #define HPTV3_T_NEED_REBUILD 0x01
261 #define HPTV3_T_RAID5_FLAG 0x02
263 u_int16_t critical_disks;
264 u_int32_t rebuild_lba;
265 } __packed configs[2];
268 u_int8_t description[64];
269 u_int8_t creator[16];
274 #define HPTV3_T_ENABLE_TCQ 0x01
275 #define HPTV3_T_ENABLE_NCQ 0x02
276 #define HPTV3_T_ENABLE_WCACHE 0x04
277 #define HPTV3_T_ENABLE_RCACHE 0x08
280 u_int32_t total_sectors;
281 u_int32_t rebuild_lba;
282 } __packed configs_high[2];
283 u_int32_t filler[87];
287 /* Intel MatrixRAID Metadata */
288 #define INTEL_LBA(dev) \
289 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 3)
291 struct intel_raid_conf {
292 u_int8_t intel_id[24];
293 #define INTEL_MAGIC "Intel Raid ISM Cfg Sig. "
296 #define INTEL_VERSION_1100 "1.1.00"
297 #define INTEL_VERSION_1201 "1.2.01"
298 #define INTEL_VERSION_1202 "1.2.02"
302 u_int32_t config_size;
304 u_int32_t generation;
305 u_int32_t dummy_1[2];
306 u_int8_t total_disks;
307 u_int8_t total_volumes;
309 u_int32_t filler_0[39];
315 #define INTEL_F_SPARE 0x01
316 #define INTEL_F_ASSIGNED 0x02
317 #define INTEL_F_DOWN 0x04
318 #define INTEL_F_ONLINE 0x08
322 u_int32_t filler_1[62];
325 struct intel_raid_mapping {
327 u_int64_t total_sectors __packed;
330 u_int32_t filler_0[20];
332 u_int32_t disk_sectors;
333 u_int32_t stripe_count;
334 u_int16_t stripe_sectors;
336 #define INTEL_S_READY 0x00
337 #define INTEL_S_DISABLED 0x01
338 #define INTEL_S_DEGRADED 0x02
339 #define INTEL_S_FAILURE 0x03
342 #define INTEL_T_RAID0 0x00
343 #define INTEL_T_RAID1 0x01
344 #define INTEL_T_RAID5 0x05
346 u_int8_t total_disks;
348 u_int32_t filler_1[7];
349 u_int32_t disk_idx[1];
353 /* Integrated Technology Express Metadata */
354 #define ITE_LBA(dev) \
355 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
357 struct ite_raid_conf {
358 u_int32_t filler_1[5];
359 u_int8_t timestamp_0[8];
361 u_int32_t filler_2[5];
364 #define ITE_MAGIC "Integrated Technology Express Inc "
367 u_int32_t filler_5[6];
370 u_int32_t filler_6[12];
372 u_int32_t filler_7[5];
373 u_int64_t total_sectors __packed;
374 u_int32_t filler_8[12];
378 #define ITE_T_RAID0 0x00
379 #define ITE_T_RAID1 0x01
380 #define ITE_T_RAID01 0x02
381 #define ITE_T_SPAN 0x03
384 u_int32_t dummy_5[8];
385 u_int8_t stripe_1kblocks;
386 u_int8_t filler_11[3];
387 u_int32_t filler_12[54];
389 u_int32_t dummy_6[4];
390 u_int8_t timestamp_1[8];
391 u_int32_t filler_13[9];
392 u_int8_t stripe_sectors;
393 u_int8_t filler_14[3];
394 u_int8_t array_width;
395 u_int8_t filler_15[3];
398 u_int8_t disk_number;
399 u_int32_t disk_sectors;
401 u_int32_t dummy_7[4];
402 u_int32_t filler_20[104];
406 /* JMicron Technology Corp Metadata */
407 #define JMICRON_LBA(dev) \
408 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
409 #define JM_MAX_DISKS 8
411 struct jmicron_raid_conf {
412 u_int8_t signature[2];
413 #define JMICRON_MAGIC "JM"
416 #define JMICRON_VERSION 0x0001
419 u_int8_t filler_1[10];
422 u_int32_t disk_sectors_high;
423 u_int16_t disk_sectors_low;
424 u_int8_t filler_2[2];
429 #define JM_T_RAID01 2
433 u_int8_t stripe_shift;
435 #define JM_F_READY 0x0001
436 #define JM_F_BOOTABLE 0x0002
437 #define JM_F_BAD 0x0004
438 #define JM_F_ACTIVE 0c0010
439 #define JM_F_UNSYNC 0c0020
440 #define JM_F_NEWEST 0c0040
442 u_int8_t filler_3[4];
444 u_int32_t disks[JM_MAX_DISKS];
445 u_int8_t filler_4[32];
446 u_int8_t filler_5[384];
450 /* LSILogic V2 MegaRAID Metadata */
451 #define LSIV2_LBA(dev) \
452 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
454 struct lsiv2_raid_conf {
456 #define LSIV2_MAGIC "$XIDE$"
461 u_int8_t config_entries;
463 u_int8_t total_disks;
470 #define LSIV2_T_RAID0 0x01
471 #define LSIV2_T_RAID1 0x02
472 #define LSIV2_T_SPARE 0x08
475 u_int16_t stripe_sectors;
476 u_int8_t array_width;
478 u_int8_t config_offset;
481 #define LSIV2_R_DEGRADED 0x02
483 u_int32_t total_sectors;
488 #define LSIV2_D_MASTER 0x00
489 #define LSIV2_D_SLAVE 0x01
490 #define LSIV2_D_CHANNEL0 0x00
491 #define LSIV2_D_CHANNEL1 0x10
492 #define LSIV2_D_NONE 0xff
495 u_int32_t disk_sectors;
496 u_int8_t disk_number;
497 u_int8_t raid_number;
499 #define LSIV2_D_GONE 0x02
504 u_int8_t disk_number;
505 u_int8_t raid_number;
511 /* LSILogic V3 MegaRAID Metadata */
512 #define LSIV3_LBA(dev) \
513 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 4)
515 struct lsiv3_raid_conf {
516 u_int32_t magic_0; /* 0xa0203200 */
517 u_int32_t filler_0[3];
518 u_int8_t magic_1[4]; /* "SATA" */
519 u_int32_t filler_1[40];
520 u_int32_t dummy_0; /* 0x0d000003 */
521 u_int32_t filler_2[7];
522 u_int32_t dummy_1; /* 0x0d000003 */
523 u_int32_t filler_3[70];
524 u_int8_t magic_2[8]; /* "$_ENQ$31" */
525 u_int8_t filler_4[7];
527 u_int8_t filler_5[512*2];
529 #define LSIV3_MAGIC "$_IDE$"
531 u_int16_t dummy_2; /* 0x33de for OK disk */
532 u_int16_t version; /* 0x0131 for this version */
533 u_int16_t dummy_3; /* 0x0440 always */
537 u_int16_t stripe_pages;
539 #define LSIV3_T_RAID0 0x00
540 #define LSIV3_T_RAID1 0x01
543 u_int8_t total_disks;
544 u_int8_t array_width;
545 u_int8_t filler_0[10];
552 #define LSIV3_D_DEVICE 0x01
553 #define LSIV3_D_CHANNEL 0x10
558 u_int8_t filler_1[16];
561 u_int32_t disk_sectors;
567 #define LSIV3_D_MIRROR 0x00
568 #define LSIV3_D_STRIPE 0xff
571 u_int8_t filler_7[7];
574 u_int8_t filler_8[3];
579 /* nVidia MediaShield Metadata */
580 #define NVIDIA_LBA(dev) \
581 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
583 struct nvidia_raid_conf {
584 u_int8_t nvidia_id[8];
585 #define NV_MAGIC "NVIDIA "
587 u_int32_t config_size;
590 u_int8_t disk_number;
592 u_int32_t total_sectors;
593 u_int32_t sector_size;
595 u_int8_t revision[4];
599 #define NV_MAGIC0 0x00640044
604 u_int8_t array_width;
605 u_int8_t total_disks;
608 #define NV_T_RAID0 0x00000080
609 #define NV_T_RAID1 0x00000081
610 #define NV_T_RAID3 0x00000083
611 #define NV_T_RAID5 0x00000085
612 #define NV_T_RAID01 0x00008180
613 #define NV_T_SPAN 0x000000ff
616 u_int32_t stripe_sectors;
617 u_int32_t stripe_bytes;
618 u_int32_t stripe_shift;
619 u_int32_t stripe_mask;
620 u_int32_t stripe_sizesectors;
621 u_int32_t stripe_sizebytes;
622 u_int32_t rebuild_lba;
626 #define NV_S_BOOTABLE 0x00000001
627 #define NV_S_DEGRADED 0x00000002
629 u_int32_t filler[98];
633 /* Promise FastTrak Metadata */
634 #define PROMISE_LBA(dev) \
635 (((((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)
637 struct promise_raid_conf {
639 #define PR_MAGIC "Promise Technology, Inc."
643 #define PR_MAGIC0(x) (((u_int64_t)(x.channel) << 48) | \
644 ((u_int64_t)(x.device != 0) << 56))
647 u_int8_t filler1[470];
650 #define PR_I_VALID 0x00000080
653 #define PR_F_VALID 0x00000001
654 #define PR_F_ONLINE 0x00000002
655 #define PR_F_ASSIGNED 0x00000004
656 #define PR_F_SPARE 0x00000008
657 #define PR_F_DUPLICATE 0x00000010
658 #define PR_F_REDIR 0x00000020
659 #define PR_F_DOWN 0x00000040
660 #define PR_F_READY 0x00000080
662 u_int8_t disk_number;
665 u_int64_t magic_0 __packed;
666 u_int32_t disk_offset;
667 u_int32_t disk_sectors;
668 u_int32_t rebuild_lba;
669 u_int16_t generation;
671 #define PR_S_VALID 0x01
672 #define PR_S_ONLINE 0x02
673 #define PR_S_INITED 0x04
674 #define PR_S_READY 0x08
675 #define PR_S_DEGRADED 0x10
676 #define PR_S_MARKED 0x20
677 #define PR_S_FUNCTIONAL 0x80
680 #define PR_T_RAID0 0x00
681 #define PR_T_RAID1 0x01
682 #define PR_T_RAID3 0x02
683 #define PR_T_RAID5 0x04
684 #define PR_T_SPAN 0x08
685 #define PR_T_JBOD 0x10
687 u_int8_t total_disks;
688 u_int8_t stripe_shift;
689 u_int8_t array_width;
690 u_int8_t array_number;
691 u_int32_t total_sectors;
695 u_int64_t magic_1 __packed;
701 u_int64_t magic_0 __packed;
704 int32_t filler2[346];
709 /* Silicon Image Medley Metadata */
710 #define SII_LBA(dev) \
711 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
713 struct sii_raid_conf {
714 u_int16_t ata_params_00_53[54];
715 u_int64_t total_sectors;
716 u_int16_t ata_params_58_79[70];
719 u_int32_t controller_pci_id;
720 u_int16_t version_minor;
721 u_int16_t version_major;
722 u_int8_t timestamp[6];
723 u_int16_t stripe_sectors;
725 u_int8_t disk_number;
727 #define SII_T_RAID0 0x00
728 #define SII_T_RAID1 0x01
729 #define SII_T_RAID01 0x02
730 #define SII_T_SPARE 0x03
732 u_int8_t raid0_disks;
733 u_int8_t raid0_ident;
734 u_int8_t raid1_disks;
735 u_int8_t raid1_ident;
736 u_int64_t rebuild_lba;
737 u_int32_t generation;
739 #define SII_S_READY 0x01
741 u_int8_t base_raid1_position;
742 u_int8_t base_raid0_position;
746 u_int16_t checksum_0;
748 u_int16_t checksum_1;
752 /* Silicon Integrated Systems RAID Metadata */
753 #define SIS_LBA(dev) \
754 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 16)
756 struct sis_raid_conf {
758 #define SIS_MAGIC 0x0010
761 #define SIS_D_MASTER 0xf0
762 #define SIS_D_MIRROR 0x0f
764 u_int8_t type_total_disks;
765 #define SIS_D_MASK 0x0f
766 #define SIS_T_MASK 0xf0
767 #define SIS_T_JBOD 0x10
768 #define SIS_T_RAID0 0x20
769 #define SIS_T_RAID1 0x30
772 u_int32_t controller_pci_id;
773 u_int16_t stripe_sectors;
777 u_int8_t disk_number;
783 /* VIA Tech V-RAID Metadata */
784 #define VIA_LBA(dev) \
785 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
787 struct via_raid_conf {
789 #define VIA_MAGIC 0xaa55
793 #define VIA_T_MASK 0x7e
794 #define VIA_T_BOOTABLE 0x01
795 #define VIA_T_RAID0 0x04
796 #define VIA_T_RAID1 0x0c
797 #define VIA_T_RAID01 0x4c
798 #define VIA_T_RAID5 0x2c
799 #define VIA_T_SPAN 0x44
800 #define VIA_T_UNKNOWN 0x80
803 #define VIA_D_MASK 0x0f
804 #define VIA_D_DEGRADED 0x10
805 #define VIA_D_HIGH_IDX 0x20
807 u_int8_t stripe_layout;
808 #define VIA_L_DISKS 0x07
809 #define VIA_L_MASK 0xf0
810 #define VIA_L_SHIFT 4
812 u_int64_t disk_sectors;
816 u_int8_t filler_1[461];