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.
34 #define AR_PROXIMITY 2048 /* how many sectors is "close" */
36 #define ATA_MAGIC "FreeBSD ATA driver RAID "
38 struct ata_raid_subdisk {
39 struct ar_softc *raid;
43 /* ATA PseudoRAID Metadata */
45 int lun; /* logical unit number of this RAID */
46 u_int8_t name[32]; /* name of array if any */
47 u_int64_t magic_0; /* magic for this array */
48 u_int64_t magic_1; /* magic for this array */
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_PROMISE_RAID 0x0100
74 #define AR_F_SII_RAID 0x0200
75 #define AR_F_VIA_RAID 0x0400
76 #define AR_F_FORMAT_MASK 0x07ff
78 u_int generation; /* generation of this array */
79 u_int64_t total_sectors;
80 u_int64_t offset_sectors; /* offset from start of disk */
84 u_int width; /* array width in disks */
85 u_int interleave; /* interleave in blocks */
86 u_int total_disks; /* number of disks in this array */
89 u_int8_t serial[16]; /* serial # of physical disk */
90 u_int64_t sectors; /* useable sectors on this disk */
91 off_t last_lba; /* last lba used (for performance) */
93 #define AR_DF_PRESENT 0x0001 /* this HW pos has a disk present */
94 #define AR_DF_ASSIGNED 0x0002 /* this HW pos assigned to an array */
95 #define AR_DF_SPARE 0x0004 /* this HW pos is a spare */
96 #define AR_DF_ONLINE 0x0008 /* this HW pos is online and in use */
99 int toggle; /* performance hack for RAID1's */
100 u_int64_t rebuild_lba; /* rebuild progress indicator */
101 struct mtx lock; /* metadata lock */
102 struct disk *disk; /* disklabel/slice stuff */
103 struct proc *pid; /* rebuilder process id */
106 /* Adaptec HostRAID Metadata */
107 #define ADP_LBA(dev) \
108 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 17)
110 /* note all entries are big endian */
111 struct adaptec_raid_conf {
113 #define ADP_MAGIC_0 0xc4650790
115 u_int32_t generation;
117 u_int16_t total_configs;
124 u_int32_t dummy_4[4];
125 u_int32_t dummy_5[4];
127 u_int16_t total_disks;
128 u_int16_t generation;
132 #define ADP_T_RAID0 0x00
133 #define ADP_T_RAID1 0x01
142 u_int32_t disk_number;
145 u_int16_t stripe_shift;
148 u_int32_t dummy_8[4];
151 u_int32_t dummy_6[13];
153 #define ADP_MAGIC_1 0x9ff85009
154 u_int32_t dummy_7[3];
156 u_int32_t dummy_8[46];
158 #define ADP_MAGIC_3 0x4d545044
160 #define ADP_MAGIC_4 0x9ff85009
161 u_int32_t dummy_9[62];
165 /* Highpoint V2 RocketRAID Metadata */
166 #define HPTV2_LBA(dev) 9
168 struct hptv2_raid_conf {
171 #define HPTV2_MAGIC_OK 0x5a7816f0
172 #define HPTV2_MAGIC_BAD 0x5a7816fd
177 #define HPTV2_O_RAID0 0x01
178 #define HPTV2_O_RAID1 0x02
179 #define HPTV2_O_OK 0x04
181 u_int8_t array_width;
182 u_int8_t stripe_shift;
184 #define HPTV2_T_RAID0 0x00
185 #define HPTV2_T_RAID1 0x01
186 #define HPTV2_T_RAID01_RAID0 0x02
187 #define HPTV2_T_SPAN 0x03
188 #define HPTV2_T_RAID_3 0x04
189 #define HPTV2_T_RAID_5 0x05
190 #define HPTV2_T_JBOD 0x06
191 #define HPTV2_T_RAID01_RAID1 0x07
193 u_int8_t disk_number;
194 u_int32_t total_sectors;
198 u_int8_t boot_protect;
199 u_int8_t error_log_entries;
200 u_int8_t error_log_index;
204 #define HPTV2_R_REMOVED 0xfe
205 #define HPTV2_R_BROKEN 0xff
213 u_int32_t rebuild_lba;
222 /* Highpoint V3 RocketRAID Metadata */
223 #define HPTV3_LBA(dev) \
224 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 11)
226 struct hptv3_raid_conf {
228 #define HPTV3_MAGIC 0x5a7816f3
233 #define HPTV3_BOOT_MARK 0x01
234 #define HPTV3_USER_MODE 0x02
237 u_int8_t config_entries;
239 u_int32_t total_sectors;
241 #define HPTV3_T_SPARE 0x00
242 #define HPTV3_T_JBOD 0x03
243 #define HPTV3_T_SPAN 0x04
244 #define HPTV3_T_RAID0 0x05
245 #define HPTV3_T_RAID1 0x06
246 #define HPTV3_T_RAID3 0x07
247 #define HPTV3_T_RAID5 0x08
249 u_int8_t total_disks;
250 u_int8_t disk_number;
251 u_int8_t stripe_shift;
253 #define HPTV3_T_NEED_REBUILD 0x01
254 #define HPTV3_T_RAID5_FLAG 0x02
256 u_int16_t critical_disks;
257 u_int32_t rebuild_lba;
258 } __packed configs[2];
261 u_int8_t description[64];
262 u_int8_t creator[16];
267 #define HPTV3_T_ENABLE_TCQ 0x01
268 #define HPTV3_T_ENABLE_NCQ 0x02
269 #define HPTV3_T_ENABLE_WCACHE 0x04
270 #define HPTV3_T_ENABLE_RCACHE 0x08
273 u_int32_t total_sectors;
274 u_int32_t rebuild_lba;
275 } __packed configs_high[2];
276 u_int32_t filler[87];
280 /* Intel MatrixRAID Metadata */
281 #define INTEL_LBA(dev) \
282 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
284 struct intel_raid_conf {
285 u_int8_t intel_id[24];
286 #define INTEL_MAGIC "Intel Raid ISM Cfg Sig. "
291 u_int32_t config_size;
293 u_int32_t generation;
294 u_int32_t dummy_1[2];
295 u_int8_t total_disks;
296 u_int8_t total_volumes;
298 u_int32_t filler_0[39];
304 #define INTEL_F_SPARE 0x01
305 #define INTEL_F_ASSIGNED 0x02
306 #define INTEL_F_DOWN 0x04
307 #define INTEL_F_ONLINE 0x08
311 u_int32_t filler_1[62];
314 struct intel_raid_mapping {
316 u_int64_t total_sectors __packed;
319 u_int32_t filler_1[20];
321 u_int32_t disk_sectors;
322 u_int32_t stripe_count;
323 u_int16_t stripe_sectors;
325 #define INTEL_S_READY 0x00
326 #define INTEL_S_DISABLED 0x01
327 #define INTEL_S_DEGRADED 0x02
328 #define INTEL_S_FAILURE 0x03
331 #define INTEL_T_RAID0 0x00
332 #define INTEL_T_RAID1 0x01
334 u_int8_t total_disks;
336 u_int32_t filler_2[7];
337 u_int32_t disk_idx[1];
341 /* Integrated Technology Express Metadata */
342 #define ITE_LBA(dev) \
343 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
345 struct ite_raid_conf {
346 u_int32_t filler_1[5];
347 u_int8_t timestamp_0[8];
349 u_int32_t filler_2[5];
352 #define ITE_MAGIC "Integrated Technology Express Inc "
355 u_int32_t filler_5[6];
358 u_int32_t filler_6[12];
360 u_int32_t filler_7[5];
361 u_int64_t total_sectors __packed;
362 u_int32_t filler_8[12];
366 #define ITE_T_RAID0 0x00
367 #define ITE_T_RAID1 0x01
368 #define ITE_T_RAID01 0x02
369 #define ITE_T_SPAN 0x03
372 u_int32_t dummy_5[8];
373 u_int8_t stripe_1kblocks;
374 u_int8_t filler_11[3];
375 u_int32_t filler_12[54];
377 u_int32_t dummy_6[4];
378 u_int8_t timestamp_1[8];
379 u_int32_t filler_13[9];
380 u_int8_t stripe_sectors;
381 u_int8_t filler_14[3];
382 u_int8_t array_width;
383 u_int8_t filler_15[3];
386 u_int8_t disk_number;
387 u_int32_t disk_sectors;
389 u_int32_t dummy_7[4];
390 u_int32_t filler_20[104];
394 /* LSILogic V2 MegaRAID Metadata */
395 #define LSIV2_LBA(dev) \
396 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
398 struct lsiv2_raid_conf {
400 #define LSIV2_MAGIC "$XIDE$"
405 u_int8_t config_entries;
407 u_int8_t total_disks;
414 #define LSIV2_T_RAID0 0x01
415 #define LSIV2_T_RAID1 0x02
416 #define LSIV2_T_SPARE 0x08
419 u_int16_t stripe_sectors;
420 u_int8_t array_width;
422 u_int8_t config_offset;
425 #define LSIV2_R_DEGRADED 0x02
427 u_int32_t total_sectors;
432 #define LSIV2_D_MASTER 0x00
433 #define LSIV2_D_SLAVE 0x01
434 #define LSIV2_D_CHANNEL0 0x00
435 #define LSIV2_D_CHANNEL1 0x10
436 #define LSIV2_D_NONE 0xff
439 u_int32_t disk_sectors;
440 u_int8_t disk_number;
441 u_int8_t raid_number;
443 #define LSIV2_D_GONE 0x02
448 u_int8_t disk_number;
449 u_int8_t raid_number;
455 /* LSILogic V3 MegaRAID Metadata */
456 #define LSIV3_LBA(dev) \
457 (((struct ad_softc *)device_get_ivars(dev))->total_secs - 4)
459 struct lsiv3_raid_conf {
460 u_int32_t magic_0; /* 0xa0203200 */
461 u_int32_t filler_0[3];
462 u_int8_t magic_1[4]; /* "SATA" */
463 u_int32_t filler_1[40];
464 u_int32_t dummy_0; /* 0x0d000003 */
465 u_int32_t filler_2[7];
466 u_int32_t dummy_1; /* 0x0d000003 */
467 u_int32_t filler_3[70];
468 u_int8_t magic_2[8]; /* "$_ENQ$31" */
469 u_int8_t filler_4[7];
471 u_int8_t filler_5[512*2];
473 #define LSIV3_MAGIC "$_IDE$"
475 u_int16_t dummy_2; /* 0x33de for OK disk */
476 u_int16_t version; /* 0x0131 for this version */
477 u_int16_t dummy_3; /* 0x0440 always */
481 u_int16_t stripe_pages;
483 #define LSIV3_T_RAID0 0x00
484 #define LSIV3_T_RAID1 0x01
487 u_int8_t total_disks;
488 u_int8_t array_width;
489 u_int8_t filler_0[10];
496 #define LSIV3_D_DEVICE 0x01
497 #define LSIV3_D_CHANNEL 0x10
502 u_int8_t filler_1[16];
505 u_int32_t disk_sectors;
511 #define LSIV3_D_MIRROR 0x00
512 #define LSIV3_D_STRIPE 0xff
515 u_int8_t filler_7[7];
518 u_int8_t filler_8[3];
523 /* Promise FastTrak Metadata */
524 #define PR_LBA(dev) \
525 (((((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)
527 struct promise_raid_conf {
529 #define PR_MAGIC "Promise Technology, Inc."
533 #define PR_MAGIC0(x) (((u_int64_t)(x.channel) << 48) | \
534 ((u_int64_t)(x.device != 0) << 56))
537 u_int8_t filler1[470];
540 #define PR_I_VALID 0x00000080
543 #define PR_F_VALID 0x00000001
544 #define PR_F_ONLINE 0x00000002
545 #define PR_F_ASSIGNED 0x00000004
546 #define PR_F_SPARE 0x00000008
547 #define PR_F_DUPLICATE 0x00000010
548 #define PR_F_REDIR 0x00000020
549 #define PR_F_DOWN 0x00000040
550 #define PR_F_READY 0x00000080
552 u_int8_t disk_number;
555 u_int64_t magic_0 __packed;
556 u_int32_t disk_offset;
557 u_int32_t disk_sectors;
558 u_int32_t rebuild_lba;
559 u_int16_t generation;
561 #define PR_S_VALID 0x01
562 #define PR_S_ONLINE 0x02
563 #define PR_S_INITED 0x04
564 #define PR_S_READY 0x08
565 #define PR_S_DEGRADED 0x10
566 #define PR_S_MARKED 0x20
567 #define PR_S_FUNCTIONAL 0x80
570 #define PR_T_RAID0 0x00
571 #define PR_T_RAID1 0x01
572 #define PR_T_RAID3 0x02
573 #define PR_T_RAID5 0x04
574 #define PR_T_SPAN 0x08
575 #define PR_T_JBOD 0x10
577 u_int8_t total_disks;
578 u_int8_t stripe_shift;
579 u_int8_t array_width;
580 u_int8_t array_number;
581 u_int32_t total_sectors;
585 u_int64_t magic_1 __packed;
591 u_int64_t magic_0 __packed;
594 int32_t filler2[346];
599 /* Silicon Image Medley Metadata */
600 #define SII_LBA(dev) \
601 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
603 struct sii_raid_conf {
604 u_int16_t ata_params_00_53[54];
605 u_int64_t total_sectors;
606 u_int16_t ata_params_58_79[70];
609 u_int32_t controller_pci_id;
610 u_int16_t version_minor;
611 u_int16_t version_major;
612 u_int8_t timestamp[6];
613 u_int16_t stripe_sectors;
615 u_int8_t disk_number;
617 #define SII_T_RAID0 0x00
618 #define SII_T_RAID1 0x01
619 #define SII_T_RAID01 0x02
620 #define SII_T_SPARE 0x03
622 u_int8_t raid0_disks;
623 u_int8_t raid0_ident;
624 u_int8_t raid1_disks;
625 u_int8_t raid1_ident;
626 u_int64_t rebuild_lba;
627 u_int32_t generation;
629 #define SII_S_READY 0x01
631 u_int8_t base_raid1_position;
632 u_int8_t base_raid0_position;
636 u_int16_t checksum_0;
638 u_int16_t checksum_1;
642 /* VIA Tech V-RAID Metadata */
643 #define VIA_LBA(dev) \
644 ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
646 struct via_raid_conf {
648 #define VIA_MAGIC 0xaa55
652 #define VIA_T_MASK 0xfe
653 #define VIA_T_BOOTABLE 0x01
654 #define VIA_T_RAID0 0x04
655 #define VIA_T_RAID1 0x0c
656 #define VIA_T_SPAN 0x44
659 u_int8_t stripe_layout;
660 #define VIA_L_MASK 0x07
661 #define VIA_L_SHIFT 4
663 u_int64_t total_sectors;
667 u_int8_t filler_1[461];