2 * Copyright (c) 2000 - 2005 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.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #define AR_PROXIMITY 2048 /* how many sectors is "close" */
37 #define ATA_MAGIC "FreeBSD ATA driver RAID "
39 struct ata_raid_subdisk {
40 struct ar_softc *raid[MAX_VOLUMES];
41 int disk_number[MAX_VOLUMES];
44 /* ATA PseudoRAID Metadata */
52 #define AR_T_JBOD 0x0001
53 #define AR_T_SPAN 0x0002
54 #define AR_T_RAID0 0x0004
55 #define AR_T_RAID1 0x0008
56 #define AR_T_RAID01 0x0010
57 #define AR_T_RAID3 0x0020
58 #define AR_T_RAID4 0x0040
59 #define AR_T_RAID5 0x0080
62 #define AR_S_READY 0x0001
63 #define AR_S_DEGRADED 0x0002
64 #define AR_S_REBUILDING 0x0004
67 #define AR_F_FREEBSD_RAID 0x0001
68 #define AR_F_ADAPTEC_RAID 0x0002
69 #define AR_F_HPTV2_RAID 0x0004
70 #define AR_F_HPTV3_RAID 0x0008
71 #define AR_F_INTEL_RAID 0x0010
72 #define AR_F_ITE_RAID 0x0020
73 #define AR_F_LSIV2_RAID 0x0040
74 #define AR_F_LSIV3_RAID 0x0080
75 #define AR_F_NVIDIA_RAID 0x0100
76 #define AR_F_PROMISE_RAID 0x0200
77 #define AR_F_SII_RAID 0x0400
78 #define AR_F_SIS_RAID 0x0800
79 #define AR_F_VIA_RAID 0x1000
80 #define AR_F_FORMAT_MASK 0x1fff
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];
169 /* Highpoint V2 RocketRAID Metadata */
170 #define HPTV2_LBA(dev) 9
172 struct hptv2_raid_conf {
175 #define HPTV2_MAGIC_OK 0x5a7816f0
176 #define HPTV2_MAGIC_BAD 0x5a7816fd
181 #define HPTV2_O_RAID0 0x01
182 #define HPTV2_O_RAID1 0x02
183 #define HPTV2_O_OK 0x04
185 u_int8_t array_width;
186 u_int8_t stripe_shift;
188 #define HPTV2_T_RAID0 0x00
189 #define HPTV2_T_RAID1 0x01
190 #define HPTV2_T_RAID01_RAID0 0x02
191 #define HPTV2_T_SPAN 0x03
192 #define HPTV2_T_RAID_3 0x04
193 #define HPTV2_T_RAID_5 0x05
194 #define HPTV2_T_JBOD 0x06
195 #define HPTV2_T_RAID01_RAID1 0x07
197 u_int8_t disk_number;
198 u_int32_t total_sectors;
202 u_int8_t boot_protect;
203 u_int8_t error_log_entries;
204 u_int8_t error_log_index;
208 #define HPTV2_R_REMOVED 0xfe
209 #define HPTV2_R_BROKEN 0xff
217 u_int32_t rebuild_lba;
226 /* Highpoint V3 RocketRAID Metadata */
227 #define HPTV3_LBA(dev) \
228 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 11)
230 struct hptv3_raid_conf {
232 #define HPTV3_MAGIC 0x5a7816f3
237 #define HPTV3_BOOT_MARK 0x01
238 #define HPTV3_USER_MODE 0x02
241 u_int8_t config_entries;
243 u_int32_t total_sectors;
245 #define HPTV3_T_SPARE 0x00
246 #define HPTV3_T_JBOD 0x03
247 #define HPTV3_T_SPAN 0x04
248 #define HPTV3_T_RAID0 0x05
249 #define HPTV3_T_RAID1 0x06
250 #define HPTV3_T_RAID3 0x07
251 #define HPTV3_T_RAID5 0x08
253 u_int8_t total_disks;
254 u_int8_t disk_number;
255 u_int8_t stripe_shift;
257 #define HPTV3_T_NEED_REBUILD 0x01
258 #define HPTV3_T_RAID5_FLAG 0x02
260 u_int16_t critical_disks;
261 u_int32_t rebuild_lba;
262 } __packed configs[2];
265 u_int8_t description[64];
266 u_int8_t creator[16];
271 #define HPTV3_T_ENABLE_TCQ 0x01
272 #define HPTV3_T_ENABLE_NCQ 0x02
273 #define HPTV3_T_ENABLE_WCACHE 0x04
274 #define HPTV3_T_ENABLE_RCACHE 0x08
277 u_int32_t total_sectors;
278 u_int32_t rebuild_lba;
279 } __packed configs_high[2];
280 u_int32_t filler[87];
284 /* Intel MatrixRAID Metadata */
285 #define INTEL_LBA(dev) \
286 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 3)
288 struct intel_raid_conf {
289 u_int8_t intel_id[24];
290 #define INTEL_MAGIC "Intel Raid ISM Cfg Sig. "
293 #define INTEL_VERSION_1100 "1.1.00"
294 #define INTEL_VERSION_1201 "1.2.01"
295 #define INTEL_VERSION_1202 "1.2.02"
299 u_int32_t config_size;
301 u_int32_t generation;
302 u_int32_t dummy_1[2];
303 u_int8_t total_disks;
304 u_int8_t total_volumes;
306 u_int32_t filler_0[39];
312 #define INTEL_F_SPARE 0x01
313 #define INTEL_F_ASSIGNED 0x02
314 #define INTEL_F_DOWN 0x04
315 #define INTEL_F_ONLINE 0x08
319 u_int32_t filler_1[62];
322 struct intel_raid_mapping {
324 u_int64_t total_sectors __packed;
327 u_int32_t filler_0[20];
329 u_int32_t disk_sectors;
330 u_int32_t stripe_count;
331 u_int16_t stripe_sectors;
333 #define INTEL_S_READY 0x00
334 #define INTEL_S_DISABLED 0x01
335 #define INTEL_S_DEGRADED 0x02
336 #define INTEL_S_FAILURE 0x03
339 #define INTEL_T_RAID0 0x00
340 #define INTEL_T_RAID1 0x01
341 #define INTEL_T_RAID5 0x05
343 u_int8_t total_disks;
345 u_int32_t filler_1[7];
346 u_int32_t disk_idx[1];
350 /* Integrated Technology Express Metadata */
351 #define ITE_LBA(dev) \
352 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
354 struct ite_raid_conf {
355 u_int32_t filler_1[5];
356 u_int8_t timestamp_0[8];
358 u_int32_t filler_2[5];
361 #define ITE_MAGIC "Integrated Technology Express Inc "
364 u_int32_t filler_5[6];
367 u_int32_t filler_6[12];
369 u_int32_t filler_7[5];
370 u_int64_t total_sectors __packed;
371 u_int32_t filler_8[12];
375 #define ITE_T_RAID0 0x00
376 #define ITE_T_RAID1 0x01
377 #define ITE_T_RAID01 0x02
378 #define ITE_T_SPAN 0x03
381 u_int32_t dummy_5[8];
382 u_int8_t stripe_1kblocks;
383 u_int8_t filler_11[3];
384 u_int32_t filler_12[54];
386 u_int32_t dummy_6[4];
387 u_int8_t timestamp_1[8];
388 u_int32_t filler_13[9];
389 u_int8_t stripe_sectors;
390 u_int8_t filler_14[3];
391 u_int8_t array_width;
392 u_int8_t filler_15[3];
395 u_int8_t disk_number;
396 u_int32_t disk_sectors;
398 u_int32_t dummy_7[4];
399 u_int32_t filler_20[104];
403 /* LSILogic V2 MegaRAID Metadata */
404 #define LSIV2_LBA(dev) \
405 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
407 struct lsiv2_raid_conf {
409 #define LSIV2_MAGIC "$XIDE$"
414 u_int8_t config_entries;
416 u_int8_t total_disks;
423 #define LSIV2_T_RAID0 0x01
424 #define LSIV2_T_RAID1 0x02
425 #define LSIV2_T_SPARE 0x08
428 u_int16_t stripe_sectors;
429 u_int8_t array_width;
431 u_int8_t config_offset;
434 #define LSIV2_R_DEGRADED 0x02
436 u_int32_t total_sectors;
441 #define LSIV2_D_MASTER 0x00
442 #define LSIV2_D_SLAVE 0x01
443 #define LSIV2_D_CHANNEL0 0x00
444 #define LSIV2_D_CHANNEL1 0x10
445 #define LSIV2_D_NONE 0xff
448 u_int32_t disk_sectors;
449 u_int8_t disk_number;
450 u_int8_t raid_number;
452 #define LSIV2_D_GONE 0x02
457 u_int8_t disk_number;
458 u_int8_t raid_number;
464 /* LSILogic V3 MegaRAID Metadata */
465 #define LSIV3_LBA(dev) \
466 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 4)
468 struct lsiv3_raid_conf {
469 u_int32_t magic_0; /* 0xa0203200 */
470 u_int32_t filler_0[3];
471 u_int8_t magic_1[4]; /* "SATA" */
472 u_int32_t filler_1[40];
473 u_int32_t dummy_0; /* 0x0d000003 */
474 u_int32_t filler_2[7];
475 u_int32_t dummy_1; /* 0x0d000003 */
476 u_int32_t filler_3[70];
477 u_int8_t magic_2[8]; /* "$_ENQ$31" */
478 u_int8_t filler_4[7];
480 u_int8_t filler_5[512*2];
482 #define LSIV3_MAGIC "$_IDE$"
484 u_int16_t dummy_2; /* 0x33de for OK disk */
485 u_int16_t version; /* 0x0131 for this version */
486 u_int16_t dummy_3; /* 0x0440 always */
490 u_int16_t stripe_pages;
492 #define LSIV3_T_RAID0 0x00
493 #define LSIV3_T_RAID1 0x01
496 u_int8_t total_disks;
497 u_int8_t array_width;
498 u_int8_t filler_0[10];
505 #define LSIV3_D_DEVICE 0x01
506 #define LSIV3_D_CHANNEL 0x10
511 u_int8_t filler_1[16];
514 u_int32_t disk_sectors;
520 #define LSIV3_D_MIRROR 0x00
521 #define LSIV3_D_STRIPE 0xff
524 u_int8_t filler_7[7];
527 u_int8_t filler_8[3];
532 /* nVidia MediaShield Metadata */
533 #define NVIDIA_LBA(dev) \
534 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
536 struct nvidia_raid_conf {
537 u_int8_t nvidia_id[8];
538 #define NV_MAGIC "NVIDIA "
540 u_int32_t config_size;
543 u_int8_t disk_number;
545 u_int32_t total_sectors;
546 u_int32_t sector_size;
548 u_int8_t revision[4];
552 #define NV_MAGIC0 0x00640044
557 u_int8_t array_width;
558 u_int8_t total_disks;
561 #define NV_T_RAID0 0x00000080
562 #define NV_T_RAID1 0x00000081
563 #define NV_T_RAID3 0x00000083
564 #define NV_T_RAID5 0x00000085
565 #define NV_T_RAID01 0x00008180
566 #define NV_T_SPAN 0x000000ff
569 u_int32_t stripe_sectors;
570 u_int32_t stripe_bytes;
571 u_int32_t stripe_shift;
572 u_int32_t stripe_mask;
573 u_int32_t stripe_sizesectors;
574 u_int32_t stripe_sizebytes;
575 u_int32_t rebuild_lba;
579 #define NV_S_BOOTABLE 0x00000001
580 #define NV_S_DEGRADED 0x00000002
582 u_int32_t filler[98];
586 /* Promise FastTrak Metadata */
587 #define PR_LBA(dev) \
588 (((((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)
590 struct promise_raid_conf {
592 #define PR_MAGIC "Promise Technology, Inc."
596 #define PR_MAGIC0(x) (((u_int64_t)(x.channel) << 48) | \
597 ((u_int64_t)(x.device != 0) << 56))
600 u_int8_t filler1[470];
603 #define PR_I_VALID 0x00000080
606 #define PR_F_VALID 0x00000001
607 #define PR_F_ONLINE 0x00000002
608 #define PR_F_ASSIGNED 0x00000004
609 #define PR_F_SPARE 0x00000008
610 #define PR_F_DUPLICATE 0x00000010
611 #define PR_F_REDIR 0x00000020
612 #define PR_F_DOWN 0x00000040
613 #define PR_F_READY 0x00000080
615 u_int8_t disk_number;
618 u_int64_t magic_0 __packed;
619 u_int32_t disk_offset;
620 u_int32_t disk_sectors;
621 u_int32_t rebuild_lba;
622 u_int16_t generation;
624 #define PR_S_VALID 0x01
625 #define PR_S_ONLINE 0x02
626 #define PR_S_INITED 0x04
627 #define PR_S_READY 0x08
628 #define PR_S_DEGRADED 0x10
629 #define PR_S_MARKED 0x20
630 #define PR_S_FUNCTIONAL 0x80
633 #define PR_T_RAID0 0x00
634 #define PR_T_RAID1 0x01
635 #define PR_T_RAID3 0x02
636 #define PR_T_RAID5 0x04
637 #define PR_T_SPAN 0x08
638 #define PR_T_JBOD 0x10
640 u_int8_t total_disks;
641 u_int8_t stripe_shift;
642 u_int8_t array_width;
643 u_int8_t array_number;
644 u_int32_t total_sectors;
648 u_int64_t magic_1 __packed;
654 u_int64_t magic_0 __packed;
657 int32_t filler2[346];
662 /* Silicon Image Medley Metadata */
663 #define SII_LBA(dev) \
664 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
666 struct sii_raid_conf {
667 u_int16_t ata_params_00_53[54];
668 u_int64_t total_sectors;
669 u_int16_t ata_params_58_79[70];
672 u_int32_t controller_pci_id;
673 u_int16_t version_minor;
674 u_int16_t version_major;
675 u_int8_t timestamp[6];
676 u_int16_t stripe_sectors;
678 u_int8_t disk_number;
680 #define SII_T_RAID0 0x00
681 #define SII_T_RAID1 0x01
682 #define SII_T_RAID01 0x02
683 #define SII_T_SPARE 0x03
685 u_int8_t raid0_disks;
686 u_int8_t raid0_ident;
687 u_int8_t raid1_disks;
688 u_int8_t raid1_ident;
689 u_int64_t rebuild_lba;
690 u_int32_t generation;
692 #define SII_S_READY 0x01
694 u_int8_t base_raid1_position;
695 u_int8_t base_raid0_position;
699 u_int16_t checksum_0;
701 u_int16_t checksum_1;
705 /* Silicon Integrated Systems RAID Metadata */
706 #define SIS_LBA(dev) \
707 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 16)
709 struct sis_raid_conf {
711 #define SIS_MAGIC 0x0010
714 #define SIS_D_MASTER 0xf0
715 #define SIS_D_MIRROR 0x0f
717 u_int8_t type_total_disks;
718 #define SIS_D_MASK 0x0f
719 #define SIS_T_MASK 0xf0
720 #define SIS_T_JBOD 0x10
721 #define SIS_T_RAID0 0x20
722 #define SIS_T_RAID1 0x30
725 u_int32_t controller_pci_id;
726 u_int16_t stripe_sectors;
730 u_int8_t disk_number;
736 /* VIA Tech V-RAID Metadata */
737 #define VIA_LBA(dev) \
738 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
740 struct via_raid_conf {
742 #define VIA_MAGIC 0xaa55
746 #define VIA_T_MASK 0xfe
747 #define VIA_T_BOOTABLE 0x01
748 #define VIA_T_RAID0 0x04
749 #define VIA_T_RAID1 0x0c
750 #define VIA_T_SPAN 0x44
753 #define VIA_D_MASK 0x0f
754 #define VIA_D_DEGRADED 0x10
756 u_int8_t stripe_layout;
757 #define VIA_L_MASK 0x07
758 #define VIA_L_SHIFT 4
760 u_int64_t total_sectors;
764 u_int8_t filler_1[461];