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.
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_LSIV2_RAID 0x0040
72 #define AR_F_LSIV3_RAID 0x0080
73 #define AR_F_NVIDIA_RAID 0x0100
74 #define AR_F_PROMISE_RAID 0x0200
75 #define AR_F_SII_RAID 0x0400
76 #define AR_F_SIS_RAID 0x0800
77 #define AR_F_VIA_RAID 0x1000
78 #define AR_F_FORMAT_MASK 0x1fff
81 u_int64_t total_sectors;
82 u_int64_t offset_sectors; /* offset from start of disk */
86 u_int width; /* array width in disks */
87 u_int interleave; /* interleave in sectors */
88 u_int total_disks; /* number of disks in this array */
91 u_int8_t serial[16]; /* serial # of physical disk */
92 u_int64_t sectors; /* useable sectors on this disk */
93 off_t last_lba; /* last lba used (for performance) */
95 #define AR_DF_PRESENT 0x0001 /* this HW pos has a disk present */
96 #define AR_DF_ASSIGNED 0x0002 /* this HW pos assigned to an array */
97 #define AR_DF_SPARE 0x0004 /* this HW pos is a spare */
98 #define AR_DF_ONLINE 0x0008 /* this HW pos is online and in use */
101 int toggle; /* performance hack for RAID1's */
102 u_int64_t rebuild_lba; /* rebuild progress indicator */
103 struct mtx lock; /* metadata lock */
104 struct disk *disk; /* disklabel/slice stuff */
105 struct proc *pid; /* rebuilder process id */
108 /* Adaptec HostRAID Metadata */
109 #define ADP_LBA(dev) \
110 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 17)
112 /* note all entries are big endian */
113 struct adaptec_raid_conf {
115 #define ADP_MAGIC_0 0xc4650790
117 u_int32_t generation;
119 u_int16_t total_configs;
126 u_int32_t dummy_4[4];
127 u_int32_t dummy_5[4];
129 u_int16_t total_disks;
130 u_int16_t generation;
134 #define ADP_T_RAID0 0x00
135 #define ADP_T_RAID1 0x01
144 u_int32_t disk_number;
147 u_int16_t stripe_shift;
150 u_int32_t dummy_8[4];
153 u_int32_t dummy_6[13];
155 #define ADP_MAGIC_1 0x9ff85009
156 u_int32_t dummy_7[3];
158 u_int32_t dummy_8[46];
160 #define ADP_MAGIC_3 0x4d545044
162 #define ADP_MAGIC_4 0x9ff85009
163 u_int32_t dummy_9[62];
167 /* Highpoint V2 RocketRAID Metadata */
168 #define HPTV2_LBA(dev) 9
170 struct hptv2_raid_conf {
173 #define HPTV2_MAGIC_OK 0x5a7816f0
174 #define HPTV2_MAGIC_BAD 0x5a7816fd
179 #define HPTV2_O_RAID0 0x01
180 #define HPTV2_O_RAID1 0x02
181 #define HPTV2_O_OK 0x04
183 u_int8_t array_width;
184 u_int8_t stripe_shift;
186 #define HPTV2_T_RAID0 0x00
187 #define HPTV2_T_RAID1 0x01
188 #define HPTV2_T_RAID01_RAID0 0x02
189 #define HPTV2_T_SPAN 0x03
190 #define HPTV2_T_RAID_3 0x04
191 #define HPTV2_T_RAID_5 0x05
192 #define HPTV2_T_JBOD 0x06
193 #define HPTV2_T_RAID01_RAID1 0x07
195 u_int8_t disk_number;
196 u_int32_t total_sectors;
200 u_int8_t boot_protect;
201 u_int8_t error_log_entries;
202 u_int8_t error_log_index;
206 #define HPTV2_R_REMOVED 0xfe
207 #define HPTV2_R_BROKEN 0xff
215 u_int32_t rebuild_lba;
224 /* Highpoint V3 RocketRAID Metadata */
225 #define HPTV3_LBA(dev) \
226 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 11)
228 struct hptv3_raid_conf {
230 #define HPTV3_MAGIC 0x5a7816f3
235 #define HPTV3_BOOT_MARK 0x01
236 #define HPTV3_USER_MODE 0x02
239 u_int8_t config_entries;
241 u_int32_t total_sectors;
243 #define HPTV3_T_SPARE 0x00
244 #define HPTV3_T_JBOD 0x03
245 #define HPTV3_T_SPAN 0x04
246 #define HPTV3_T_RAID0 0x05
247 #define HPTV3_T_RAID1 0x06
248 #define HPTV3_T_RAID3 0x07
249 #define HPTV3_T_RAID5 0x08
251 u_int8_t total_disks;
252 u_int8_t disk_number;
253 u_int8_t stripe_shift;
255 #define HPTV3_T_NEED_REBUILD 0x01
256 #define HPTV3_T_RAID5_FLAG 0x02
258 u_int16_t critical_disks;
259 u_int32_t rebuild_lba;
260 } __packed configs[2];
263 u_int8_t description[64];
264 u_int8_t creator[16];
269 #define HPTV3_T_ENABLE_TCQ 0x01
270 #define HPTV3_T_ENABLE_NCQ 0x02
271 #define HPTV3_T_ENABLE_WCACHE 0x04
272 #define HPTV3_T_ENABLE_RCACHE 0x08
275 u_int32_t total_sectors;
276 u_int32_t rebuild_lba;
277 } __packed configs_high[2];
278 u_int32_t filler[87];
282 /* Intel MatrixRAID Metadata */
283 #define INTEL_LBA(dev) \
284 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 3)
286 struct intel_raid_conf {
287 u_int8_t intel_id[24];
288 #define INTEL_MAGIC "Intel Raid ISM Cfg Sig. "
291 #define INTEL_VERSION_1100 "1.1.00"
292 #define INTEL_VERSION_1201 "1.2.01"
293 #define INTEL_VERSION_1202 "1.2.02"
297 u_int32_t config_size;
299 u_int32_t generation;
300 u_int32_t dummy_1[2];
301 u_int8_t total_disks;
302 u_int8_t total_volumes;
304 u_int32_t filler_0[39];
310 #define INTEL_F_SPARE 0x01
311 #define INTEL_F_ASSIGNED 0x02
312 #define INTEL_F_DOWN 0x04
313 #define INTEL_F_ONLINE 0x08
317 u_int32_t filler_1[62];
320 struct intel_raid_mapping {
322 u_int64_t total_sectors __packed;
325 u_int32_t filler_0[20];
327 u_int32_t disk_sectors;
328 u_int32_t stripe_count;
329 u_int16_t stripe_sectors;
331 #define INTEL_S_READY 0x00
332 #define INTEL_S_DISABLED 0x01
333 #define INTEL_S_DEGRADED 0x02
334 #define INTEL_S_FAILURE 0x03
337 #define INTEL_T_RAID0 0x00
338 #define INTEL_T_RAID1 0x01
339 #define INTEL_T_RAID5 0x05
341 u_int8_t total_disks;
343 u_int32_t filler_1[7];
344 u_int32_t disk_idx[1];
348 /* Integrated Technology Express Metadata */
349 #define ITE_LBA(dev) \
350 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
352 struct ite_raid_conf {
353 u_int32_t filler_1[5];
354 u_int8_t timestamp_0[8];
356 u_int32_t filler_2[5];
359 #define ITE_MAGIC "Integrated Technology Express Inc "
362 u_int32_t filler_5[6];
365 u_int32_t filler_6[12];
367 u_int32_t filler_7[5];
368 u_int64_t total_sectors __packed;
369 u_int32_t filler_8[12];
373 #define ITE_T_RAID0 0x00
374 #define ITE_T_RAID1 0x01
375 #define ITE_T_RAID01 0x02
376 #define ITE_T_SPAN 0x03
379 u_int32_t dummy_5[8];
380 u_int8_t stripe_1kblocks;
381 u_int8_t filler_11[3];
382 u_int32_t filler_12[54];
384 u_int32_t dummy_6[4];
385 u_int8_t timestamp_1[8];
386 u_int32_t filler_13[9];
387 u_int8_t stripe_sectors;
388 u_int8_t filler_14[3];
389 u_int8_t array_width;
390 u_int8_t filler_15[3];
393 u_int8_t disk_number;
394 u_int32_t disk_sectors;
396 u_int32_t dummy_7[4];
397 u_int32_t filler_20[104];
401 /* LSILogic V2 MegaRAID Metadata */
402 #define LSIV2_LBA(dev) \
403 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
405 struct lsiv2_raid_conf {
407 #define LSIV2_MAGIC "$XIDE$"
412 u_int8_t config_entries;
414 u_int8_t total_disks;
421 #define LSIV2_T_RAID0 0x01
422 #define LSIV2_T_RAID1 0x02
423 #define LSIV2_T_SPARE 0x08
426 u_int16_t stripe_sectors;
427 u_int8_t array_width;
429 u_int8_t config_offset;
432 #define LSIV2_R_DEGRADED 0x02
434 u_int32_t total_sectors;
439 #define LSIV2_D_MASTER 0x00
440 #define LSIV2_D_SLAVE 0x01
441 #define LSIV2_D_CHANNEL0 0x00
442 #define LSIV2_D_CHANNEL1 0x10
443 #define LSIV2_D_NONE 0xff
446 u_int32_t disk_sectors;
447 u_int8_t disk_number;
448 u_int8_t raid_number;
450 #define LSIV2_D_GONE 0x02
455 u_int8_t disk_number;
456 u_int8_t raid_number;
462 /* LSILogic V3 MegaRAID Metadata */
463 #define LSIV3_LBA(dev) \
464 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 4)
466 struct lsiv3_raid_conf {
467 u_int32_t magic_0; /* 0xa0203200 */
468 u_int32_t filler_0[3];
469 u_int8_t magic_1[4]; /* "SATA" */
470 u_int32_t filler_1[40];
471 u_int32_t dummy_0; /* 0x0d000003 */
472 u_int32_t filler_2[7];
473 u_int32_t dummy_1; /* 0x0d000003 */
474 u_int32_t filler_3[70];
475 u_int8_t magic_2[8]; /* "$_ENQ$31" */
476 u_int8_t filler_4[7];
478 u_int8_t filler_5[512*2];
480 #define LSIV3_MAGIC "$_IDE$"
482 u_int16_t dummy_2; /* 0x33de for OK disk */
483 u_int16_t version; /* 0x0131 for this version */
484 u_int16_t dummy_3; /* 0x0440 always */
488 u_int16_t stripe_pages;
490 #define LSIV3_T_RAID0 0x00
491 #define LSIV3_T_RAID1 0x01
494 u_int8_t total_disks;
495 u_int8_t array_width;
496 u_int8_t filler_0[10];
503 #define LSIV3_D_DEVICE 0x01
504 #define LSIV3_D_CHANNEL 0x10
509 u_int8_t filler_1[16];
512 u_int32_t disk_sectors;
518 #define LSIV3_D_MIRROR 0x00
519 #define LSIV3_D_STRIPE 0xff
522 u_int8_t filler_7[7];
525 u_int8_t filler_8[3];
530 /* nVidia MediaShield Metadata */
531 #define NVIDIA_LBA(dev) \
532 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
534 struct nvidia_raid_conf {
535 u_int8_t nvidia_id[8];
536 #define NV_MAGIC "NVIDIA "
538 u_int32_t config_size;
541 u_int8_t disk_number;
543 u_int32_t total_sectors;
544 u_int32_t sector_size;
546 u_int8_t revision[4];
550 #define NV_MAGIC0 0x00640044
555 u_int8_t array_width;
556 u_int8_t total_disks;
559 #define NV_T_RAID0 0x00000080
560 #define NV_T_RAID1 0x00000081
561 #define NV_T_RAID3 0x00000083
562 #define NV_T_RAID5 0x00000085
563 #define NV_T_RAID01 0x00008180
564 #define NV_T_SPAN 0x000000ff
567 u_int32_t stripe_sectors;
568 u_int32_t stripe_bytes;
569 u_int32_t stripe_shift;
570 u_int32_t stripe_mask;
571 u_int32_t stripe_sizesectors;
572 u_int32_t stripe_sizebytes;
573 u_int32_t rebuild_lba;
577 #define NV_S_BOOTABLE 0x00000001
578 #define NV_S_DEGRADED 0x00000002
580 u_int32_t filler[98];
584 /* Promise FastTrak Metadata */
585 #define PROMISE_LBA(dev) \
586 (((((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)
588 struct promise_raid_conf {
590 #define PR_MAGIC "Promise Technology, Inc."
594 #define PR_MAGIC0(x) (((u_int64_t)(x.channel) << 48) | \
595 ((u_int64_t)(x.device != 0) << 56))
598 u_int8_t filler1[470];
601 #define PR_I_VALID 0x00000080
604 #define PR_F_VALID 0x00000001
605 #define PR_F_ONLINE 0x00000002
606 #define PR_F_ASSIGNED 0x00000004
607 #define PR_F_SPARE 0x00000008
608 #define PR_F_DUPLICATE 0x00000010
609 #define PR_F_REDIR 0x00000020
610 #define PR_F_DOWN 0x00000040
611 #define PR_F_READY 0x00000080
613 u_int8_t disk_number;
616 u_int64_t magic_0 __packed;
617 u_int32_t disk_offset;
618 u_int32_t disk_sectors;
619 u_int32_t rebuild_lba;
620 u_int16_t generation;
622 #define PR_S_VALID 0x01
623 #define PR_S_ONLINE 0x02
624 #define PR_S_INITED 0x04
625 #define PR_S_READY 0x08
626 #define PR_S_DEGRADED 0x10
627 #define PR_S_MARKED 0x20
628 #define PR_S_FUNCTIONAL 0x80
631 #define PR_T_RAID0 0x00
632 #define PR_T_RAID1 0x01
633 #define PR_T_RAID3 0x02
634 #define PR_T_RAID5 0x04
635 #define PR_T_SPAN 0x08
636 #define PR_T_JBOD 0x10
638 u_int8_t total_disks;
639 u_int8_t stripe_shift;
640 u_int8_t array_width;
641 u_int8_t array_number;
642 u_int32_t total_sectors;
646 u_int64_t magic_1 __packed;
652 u_int64_t magic_0 __packed;
655 int32_t filler2[346];
660 /* Silicon Image Medley Metadata */
661 #define SII_LBA(dev) \
662 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
664 struct sii_raid_conf {
665 u_int16_t ata_params_00_53[54];
666 u_int64_t total_sectors;
667 u_int16_t ata_params_58_79[70];
670 u_int32_t controller_pci_id;
671 u_int16_t version_minor;
672 u_int16_t version_major;
673 u_int8_t timestamp[6];
674 u_int16_t stripe_sectors;
676 u_int8_t disk_number;
678 #define SII_T_RAID0 0x00
679 #define SII_T_RAID1 0x01
680 #define SII_T_RAID01 0x02
681 #define SII_T_SPARE 0x03
683 u_int8_t raid0_disks;
684 u_int8_t raid0_ident;
685 u_int8_t raid1_disks;
686 u_int8_t raid1_ident;
687 u_int64_t rebuild_lba;
688 u_int32_t generation;
690 #define SII_S_READY 0x01
692 u_int8_t base_raid1_position;
693 u_int8_t base_raid0_position;
697 u_int16_t checksum_0;
699 u_int16_t checksum_1;
703 /* Silicon Integrated Systems RAID Metadata */
704 #define SIS_LBA(dev) \
705 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 16)
707 struct sis_raid_conf {
709 #define SIS_MAGIC 0x0010
712 #define SIS_D_MASTER 0xf0
713 #define SIS_D_MIRROR 0x0f
715 u_int8_t type_total_disks;
716 #define SIS_D_MASK 0x0f
717 #define SIS_T_MASK 0xf0
718 #define SIS_T_JBOD 0x10
719 #define SIS_T_RAID0 0x20
720 #define SIS_T_RAID1 0x30
723 u_int32_t controller_pci_id;
724 u_int16_t stripe_sectors;
728 u_int8_t disk_number;
734 /* VIA Tech V-RAID Metadata */
735 #define VIA_LBA(dev) \
736 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
738 struct via_raid_conf {
740 #define VIA_MAGIC 0xaa55
744 #define VIA_T_MASK 0x7e
745 #define VIA_T_BOOTABLE 0x01
746 #define VIA_T_RAID0 0x04
747 #define VIA_T_RAID1 0x0c
748 #define VIA_T_RAID01 0x4c
749 #define VIA_T_RAID5 0x2c
750 #define VIA_T_SPAN 0x44
751 #define VIA_T_UNKNOWN 0x80
754 #define VIA_D_MASK 0x0f
755 #define VIA_D_DEGRADED 0x10
756 #define VIA_D_HIGH_IDX 0x20
758 u_int8_t stripe_layout;
759 #define VIA_L_DISKS 0x07
760 #define VIA_L_MASK 0xf0
761 #define VIA_L_SHIFT 4
763 u_int64_t disk_sectors;
767 u_int8_t filler_1[461];