xref: /dflybsd-src/sys/dev/disk/nata/ata-raid.h (revision 744c01d0dc2aa1481a40e5b0988d15691602f5c9)
1 /*-
2  * Copyright (c) 2000 - 2006 S�ren Schmidt <sos@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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  *
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.
25  *
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.1 2006/12/04 14:40:37 tgen Exp $
28  */
29 
30 #include <sys/param.h>
31 
32 #include <sys/bus.h>
33 #include <sys/disk.h>
34 #include <sys/proc.h>
35 #include <sys/spinlock.h>
36 
37 /* misc defines */
38 #define MAX_ARRAYS      16
39 #define MAX_VOLUMES     4
40 #define MAX_DISKS       16
41 #define AR_PROXIMITY    2048    /* how many sectors is "close" */
42 
43 #define ATA_MAGIC       "FreeBSD ATA driver RAID "
44 
45 struct ata_raid_subdisk {
46     struct ar_softc     *raid[MAX_VOLUMES];
47     int                 disk_number[MAX_VOLUMES];
48 };
49 
50 /*  ATA PseudoRAID Metadata */
51 struct ar_softc {
52     int                 lun;
53     u_int8_t            name[32];
54     int                 volume;
55     u_int64_t           magic_0;
56     u_int64_t           magic_1;
57     int                 type;
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
66 
67     int                 status;
68 #define AR_S_READY              0x0001
69 #define AR_S_DEGRADED           0x0002
70 #define AR_S_REBUILDING         0x0004
71 
72     int                 format;
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
88 
89     u_int               generation;
90     u_int64_t           total_sectors;
91     u_int64_t           offset_sectors; /* offset from start of disk */
92     u_int16_t           heads;
93     u_int16_t           sectors;
94     u_int32_t           cylinders;
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 */
98     struct ar_disk {
99 	device_t        dev;
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) */
103 	u_int           flags;
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 */
108 
109     } disks[MAX_DISKS];
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 proc         *pid;           /* rebuilder process id */
115 };
116 
117 /* Adaptec HostRAID Metadata */
118 #define ADP_LBA(dev) \
119 	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 17)
120 
121 /* note all entries are big endian */
122 struct adaptec_raid_conf {
123     u_int32_t           magic_0;
124 #define ADP_MAGIC_0             0xc4650790
125 
126     u_int32_t           generation;
127     u_int16_t           dummy_0;
128     u_int16_t           total_configs;
129     u_int16_t           dummy_1;
130     u_int16_t           checksum;
131     u_int32_t           dummy_2;
132     u_int32_t           dummy_3;
133     u_int32_t           flags;
134     u_int32_t           timestamp;
135     u_int32_t           dummy_4[4];
136     u_int32_t           dummy_5[4];
137     struct {
138 	u_int16_t       total_disks;
139 	u_int16_t       generation;
140 	u_int32_t       magic_0;
141 	u_int8_t        dummy_0;
142 	u_int8_t        type;
143 #define ADP_T_RAID0             0x00
144 #define ADP_T_RAID1             0x01
145 	u_int8_t        dummy_1;
146 	u_int8_t        flags;
147 
148 	u_int8_t        dummy_2;
149 	u_int8_t        dummy_3;
150 	u_int8_t        dummy_4;
151 	u_int8_t        dummy_5;
152 
153 	u_int32_t       disk_number;
154 	u_int32_t       dummy_6;
155 	u_int32_t       sectors;
156 	u_int16_t       stripe_shift;
157 	u_int16_t       dummy_7;
158 
159 	u_int32_t       dummy_8[4];
160 	u_int8_t        name[16];
161     } configs[127];
162     u_int32_t           dummy_6[13];
163     u_int32_t           magic_1;
164 #define ADP_MAGIC_1             0x9ff85009
165     u_int32_t           dummy_7[3];
166     u_int32_t           magic_2;
167     u_int32_t           dummy_8[46];
168     u_int32_t           magic_3;
169 #define ADP_MAGIC_3             0x4d545044
170     u_int32_t           magic_4;
171 #define ADP_MAGIC_4             0x9ff85009
172     u_int32_t           dummy_9[62];
173 } __packed;
174 
175 
176 /* Highpoint V2 RocketRAID Metadata */
177 #define HPTV2_LBA(dev)  9
178 
179 struct hptv2_raid_conf {
180     int8_t              filler1[32];
181     u_int32_t           magic;
182 #define HPTV2_MAGIC_OK          0x5a7816f0
183 #define HPTV2_MAGIC_BAD         0x5a7816fd
184 
185     u_int32_t           magic_0;
186     u_int32_t           magic_1;
187     u_int32_t           order;
188 #define HPTV2_O_RAID0           0x01
189 #define HPTV2_O_RAID1           0x02
190 #define HPTV2_O_OK              0x04
191 
192     u_int8_t            array_width;
193     u_int8_t            stripe_shift;
194     u_int8_t            type;
195 #define HPTV2_T_RAID0           0x00
196 #define HPTV2_T_RAID1           0x01
197 #define HPTV2_T_RAID01_RAID0    0x02
198 #define HPTV2_T_SPAN            0x03
199 #define HPTV2_T_RAID_3          0x04
200 #define HPTV2_T_RAID_5          0x05
201 #define HPTV2_T_JBOD            0x06
202 #define HPTV2_T_RAID01_RAID1    0x07
203 
204     u_int8_t            disk_number;
205     u_int32_t           total_sectors;
206     u_int32_t           disk_mode;
207     u_int32_t           boot_mode;
208     u_int8_t            boot_disk;
209     u_int8_t            boot_protect;
210     u_int8_t            error_log_entries;
211     u_int8_t            error_log_index;
212     struct {
213 	u_int32_t       timestamp;
214 	u_int8_t        reason;
215 #define HPTV2_R_REMOVED         0xfe
216 #define HPTV2_R_BROKEN          0xff
217 
218 	u_int8_t        disk;
219 	u_int8_t        status;
220 	u_int8_t        sectors;
221 	u_int32_t       lba;
222     } errorlog[32];
223     int8_t              filler2[16];
224     u_int32_t           rebuild_lba;
225     u_int8_t            dummy_1;
226     u_int8_t            name_1[15];
227     u_int8_t            dummy_2;
228     u_int8_t            name_2[15];
229     int8_t              filler3[8];
230 } __packed;
231 
232 
233 /* Highpoint V3 RocketRAID Metadata */
234 #define HPTV3_LBA(dev) \
235 	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 11)
236 
237 struct hptv3_raid_conf {
238     u_int32_t           magic;
239 #define HPTV3_MAGIC             0x5a7816f3
240 
241     u_int32_t           magic_0;
242     u_int8_t            checksum_0;
243     u_int8_t            mode;
244 #define HPTV3_BOOT_MARK         0x01
245 #define HPTV3_USER_MODE         0x02
246 
247     u_int8_t            user_mode;
248     u_int8_t            config_entries;
249     struct {
250 	u_int32_t       total_sectors;
251 	u_int8_t        type;
252 #define HPTV3_T_SPARE           0x00
253 #define HPTV3_T_JBOD            0x03
254 #define HPTV3_T_SPAN            0x04
255 #define HPTV3_T_RAID0           0x05
256 #define HPTV3_T_RAID1           0x06
257 #define HPTV3_T_RAID3           0x07
258 #define HPTV3_T_RAID5           0x08
259 
260 	u_int8_t        total_disks;
261 	u_int8_t        disk_number;
262 	u_int8_t        stripe_shift;
263 	u_int16_t       status;
264 #define HPTV3_T_NEED_REBUILD    0x01
265 #define HPTV3_T_RAID5_FLAG      0x02
266 
267 	u_int16_t       critical_disks;
268 	u_int32_t       rebuild_lba;
269     } __packed configs[2];
270     u_int8_t            name[16];
271     u_int32_t           timestamp;
272     u_int8_t            description[64];
273     u_int8_t            creator[16];
274     u_int8_t            checksum_1;
275     u_int8_t            dummy_0;
276     u_int8_t            dummy_1;
277     u_int8_t            flags;
278 #define HPTV3_T_ENABLE_TCQ      0x01
279 #define HPTV3_T_ENABLE_NCQ      0x02
280 #define HPTV3_T_ENABLE_WCACHE   0x04
281 #define HPTV3_T_ENABLE_RCACHE   0x08
282 
283     struct {
284 	u_int32_t       total_sectors;
285 	u_int32_t       rebuild_lba;
286     } __packed configs_high[2];
287     u_int32_t           filler[87];
288 } __packed;
289 
290 
291 /* Intel MatrixRAID Metadata */
292 #define INTEL_LBA(dev) \
293 	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 3)
294 
295 struct intel_raid_conf {
296     u_int8_t            intel_id[24];
297 #define INTEL_MAGIC             "Intel Raid ISM Cfg Sig. "
298 
299     u_int8_t            version[6];
300 #define INTEL_VERSION_1100      "1.1.00"
301 #define INTEL_VERSION_1201      "1.2.01"
302 #define INTEL_VERSION_1202      "1.2.02"
303 
304     u_int8_t            dummy_0[2];
305     u_int32_t           checksum;
306     u_int32_t           config_size;
307     u_int32_t           config_id;
308     u_int32_t           generation;
309     u_int32_t           dummy_1[2];
310     u_int8_t            total_disks;
311     u_int8_t            total_volumes;
312     u_int8_t            dummy_2[2];
313     u_int32_t           filler_0[39];
314     struct {
315 	u_int8_t        serial[16];
316 	u_int32_t       sectors;
317 	u_int32_t       id;
318 	u_int32_t       flags;
319 #define INTEL_F_SPARE           0x01
320 #define INTEL_F_ASSIGNED        0x02
321 #define INTEL_F_DOWN            0x04
322 #define INTEL_F_ONLINE          0x08
323 
324 	u_int32_t       filler[5];
325     } __packed disk[1];
326     u_int32_t           filler_1[62];
327 } __packed;
328 
329 struct intel_raid_mapping {
330     u_int8_t            name[16];
331     u_int64_t           total_sectors __packed;
332     u_int32_t           state;
333     u_int32_t           reserved;
334     u_int32_t           filler_0[20];
335     u_int32_t           offset;
336     u_int32_t           disk_sectors;
337     u_int32_t           stripe_count;
338     u_int16_t           stripe_sectors;
339     u_int8_t            status;
340 #define INTEL_S_READY           0x00
341 #define INTEL_S_DISABLED        0x01
342 #define INTEL_S_DEGRADED        0x02
343 #define INTEL_S_FAILURE         0x03
344 
345     u_int8_t            type;
346 #define INTEL_T_RAID0           0x00
347 #define INTEL_T_RAID1           0x01
348 #define INTEL_T_RAID5           0x05
349 
350     u_int8_t            total_disks;
351     u_int8_t            magic[3];
352     u_int32_t           filler_1[7];
353     u_int32_t           disk_idx[1];
354 } __packed;
355 
356 
357 /* Integrated Technology Express Metadata */
358 #define ITE_LBA(dev) \
359 	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
360 
361 struct ite_raid_conf {
362     u_int32_t           filler_1[5];
363     u_int8_t            timestamp_0[8];
364     u_int32_t           dummy_1;
365     u_int32_t           filler_2[5];
366     u_int16_t           filler_3;
367     u_int8_t            ite_id[40];
368 #define ITE_MAGIC               "Integrated Technology Express Inc      "
369 
370     u_int16_t           filler_4;
371     u_int32_t           filler_5[6];
372     u_int32_t           dummy_2;
373     u_int32_t           dummy_3;
374     u_int32_t           filler_6[12];
375     u_int32_t           dummy_4;
376     u_int32_t           filler_7[5];
377     u_int64_t           total_sectors __packed;
378     u_int32_t           filler_8[12];
379 
380     u_int16_t           filler_9;
381     u_int8_t            type;
382 #define ITE_T_RAID0             0x00
383 #define ITE_T_RAID1             0x01
384 #define ITE_T_RAID01            0x02
385 #define ITE_T_SPAN              0x03
386 
387     u_int8_t            filler_10;
388     u_int32_t           dummy_5[8];
389     u_int8_t            stripe_1kblocks;
390     u_int8_t            filler_11[3];
391     u_int32_t           filler_12[54];
392 
393     u_int32_t           dummy_6[4];
394     u_int8_t            timestamp_1[8];
395     u_int32_t           filler_13[9];
396     u_int8_t            stripe_sectors;
397     u_int8_t            filler_14[3];
398     u_int8_t            array_width;
399     u_int8_t            filler_15[3];
400     u_int32_t           filler_16;
401     u_int8_t            filler_17;
402     u_int8_t            disk_number;
403     u_int32_t           disk_sectors;
404     u_int16_t           filler_18;
405     u_int32_t           dummy_7[4];
406     u_int32_t           filler_20[104];
407 } __packed;
408 
409 
410 /* JMicron Technology Corp Metadata */
411 #define JMICRON_LBA(dev) \
412 	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
413 #define	JM_MAX_DISKS		8
414 
415 struct jmicron_raid_conf {
416     u_int8_t            signature[2];
417 #define JMICRON_MAGIC		"JM"
418 
419     u_int16_t           version;
420 #define JMICRON_VERSION		0x0001
421 
422     u_int16_t           checksum;
423     u_int8_t		filler_1[10];
424     u_int32_t           disk_id;
425     u_int32_t           offset;
426     u_int32_t           disk_sectors_high;
427     u_int16_t           disk_sectors_low;
428     u_int8_t		filler_2[2];
429     u_int8_t            name[16];
430     u_int8_t            type;
431 #define	JM_T_RAID0		0
432 #define	JM_T_RAID1		1
433 #define	JM_T_RAID01		2
434 #define	JM_T_JBOD		3
435 #define	JM_T_RAID5		5
436 
437     u_int8_t            stripe_shift;
438     u_int16_t           flags;
439 #define	JM_F_READY		0x0001
440 #define JM_F_BOOTABLE		0x0002
441 #define JM_F_BAD		0x0004
442 #define JM_F_ACTIVE		0c0010
443 #define JM_F_UNSYNC		0c0020
444 #define JM_F_NEWEST		0c0040
445 
446     u_int8_t		filler_3[4];
447     u_int32_t           spare[2];
448     u_int32_t           disks[JM_MAX_DISKS];
449     u_int8_t		filler_4[32];
450     u_int8_t		filler_5[384];
451 };
452 
453 
454 /* LSILogic V2 MegaRAID Metadata */
455 #define LSIV2_LBA(dev) \
456 	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
457 
458 struct lsiv2_raid_conf {
459     u_int8_t            lsi_id[6];
460 #define LSIV2_MAGIC             "$XIDE$"
461 
462     u_int8_t            dummy_0;
463     u_int8_t            flags;
464     u_int16_t           version;
465     u_int8_t            config_entries;
466     u_int8_t            raid_count;
467     u_int8_t            total_disks;
468     u_int8_t            dummy_1;
469     u_int16_t           dummy_2;
470 
471     union {
472 	struct {
473 	    u_int8_t    type;
474 #define LSIV2_T_RAID0           0x01
475 #define LSIV2_T_RAID1           0x02
476 #define LSIV2_T_SPARE           0x08
477 
478 	    u_int8_t    dummy_0;
479 	    u_int16_t   stripe_sectors;
480 	    u_int8_t    array_width;
481 	    u_int8_t    disk_count;
482 	    u_int8_t    config_offset;
483 	    u_int8_t    dummy_1;
484 	    u_int8_t    flags;
485 #define LSIV2_R_DEGRADED        0x02
486 
487 	    u_int32_t   total_sectors;
488 	    u_int8_t    filler[3];
489 	} __packed raid;
490 	struct {
491 	    u_int8_t    device;
492 #define LSIV2_D_MASTER          0x00
493 #define LSIV2_D_SLAVE           0x01
494 #define LSIV2_D_CHANNEL0        0x00
495 #define LSIV2_D_CHANNEL1        0x10
496 #define LSIV2_D_NONE            0xff
497 
498 	    u_int8_t    dummy_0;
499 	    u_int32_t   disk_sectors;
500 	    u_int8_t    disk_number;
501 	    u_int8_t    raid_number;
502 	    u_int8_t    flags;
503 #define LSIV2_D_GONE            0x02
504 
505 	    u_int8_t    filler[7];
506 	} __packed disk;
507     } configs[30];
508     u_int8_t            disk_number;
509     u_int8_t            raid_number;
510     u_int32_t           timestamp;
511     u_int8_t            filler[10];
512 } __packed;
513 
514 
515 /* LSILogic V3 MegaRAID Metadata */
516 #define LSIV3_LBA(dev) \
517 	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 4)
518 
519 struct lsiv3_raid_conf {
520     u_int32_t           magic_0;        /* 0xa0203200 */
521     u_int32_t           filler_0[3];
522     u_int8_t            magic_1[4];     /* "SATA" */
523     u_int32_t           filler_1[40];
524     u_int32_t           dummy_0;        /* 0x0d000003 */
525     u_int32_t           filler_2[7];
526     u_int32_t           dummy_1;        /* 0x0d000003 */
527     u_int32_t           filler_3[70];
528     u_int8_t            magic_2[8];     /* "$_ENQ$31" */
529     u_int8_t            filler_4[7];
530     u_int8_t            checksum_0;
531     u_int8_t            filler_5[512*2];
532     u_int8_t            lsi_id[6];
533 #define LSIV3_MAGIC             "$_IDE$"
534 
535     u_int16_t           dummy_2;        /* 0x33de for OK disk */
536     u_int16_t           version;        /* 0x0131 for this version */
537     u_int16_t           dummy_3;        /* 0x0440 always */
538     u_int32_t           filler_6;
539 
540     struct {
541 	u_int16_t       stripe_pages;
542 	u_int8_t        type;
543 #define LSIV3_T_RAID0           0x00
544 #define LSIV3_T_RAID1           0x01
545 
546 	u_int8_t        dummy_0;
547 	u_int8_t        total_disks;
548 	u_int8_t        array_width;
549 	u_int8_t        filler_0[10];
550 
551 	u_int32_t       sectors;
552 	u_int16_t       dummy_1;
553 	u_int32_t       offset;
554 	u_int16_t       dummy_2;
555 	u_int8_t        device;
556 #define LSIV3_D_DEVICE          0x01
557 #define LSIV3_D_CHANNEL         0x10
558 
559 	u_int8_t        dummy_3;
560 	u_int8_t        dummy_4;
561 	u_int8_t        dummy_5;
562 	u_int8_t        filler_1[16];
563     } __packed raid[8];
564     struct {
565 	u_int32_t       disk_sectors;
566 	u_int32_t       dummy_0;
567 	u_int32_t       dummy_1;
568 	u_int8_t        dummy_2;
569 	u_int8_t        dummy_3;
570 	u_int8_t        flags;
571 #define LSIV3_D_MIRROR          0x00
572 #define LSIV3_D_STRIPE          0xff
573 	u_int8_t        dummy_4;
574     } __packed disk[6];
575     u_int8_t            filler_7[7];
576     u_int8_t            device;
577     u_int32_t           timestamp;
578     u_int8_t            filler_8[3];
579     u_int8_t            checksum_1;
580 } __packed;
581 
582 
583 /* nVidia MediaShield Metadata */
584 #define NVIDIA_LBA(dev) \
585 	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
586 
587 struct nvidia_raid_conf {
588     u_int8_t            nvidia_id[8];
589 #define NV_MAGIC                "NVIDIA  "
590 
591     u_int32_t           config_size;
592     u_int32_t           checksum;
593     u_int16_t           version;
594     u_int8_t            disk_number;
595     u_int8_t            dummy_0;
596     u_int32_t           total_sectors;
597     u_int32_t           sector_size;
598     u_int8_t            serial[16];
599     u_int8_t            revision[4];
600     u_int32_t           dummy_1;
601 
602     u_int32_t           magic_0;
603 #define NV_MAGIC0               0x00640044
604 
605     u_int64_t           magic_1;
606     u_int64_t           magic_2;
607     u_int8_t            flags;
608     u_int8_t            array_width;
609     u_int8_t            total_disks;
610     u_int8_t            dummy_2;
611     u_int16_t           type;
612 #define NV_T_RAID0              0x00000080
613 #define NV_T_RAID1              0x00000081
614 #define NV_T_RAID3              0x00000083
615 #define NV_T_RAID5              0x00000085
616 #define NV_T_RAID01             0x00008180
617 #define NV_T_SPAN               0x000000ff
618 
619     u_int16_t           dummy_3;
620     u_int32_t           stripe_sectors;
621     u_int32_t           stripe_bytes;
622     u_int32_t           stripe_shift;
623     u_int32_t           stripe_mask;
624     u_int32_t           stripe_sizesectors;
625     u_int32_t           stripe_sizebytes;
626     u_int32_t           rebuild_lba;
627     u_int32_t           dummy_4;
628     u_int32_t           dummy_5;
629     u_int32_t           status;
630 #define NV_S_BOOTABLE           0x00000001
631 #define NV_S_DEGRADED           0x00000002
632 
633     u_int32_t           filler[98];
634 } __packed;
635 
636 
637 /* Promise FastTrak Metadata */
638 #define PROMISE_LBA(dev) \
639 	(((((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)
640 
641 struct promise_raid_conf {
642     char                promise_id[24];
643 #define PR_MAGIC                "Promise Technology, Inc."
644 
645     u_int32_t           dummy_0;
646     u_int64_t           magic_0;
647 #define PR_MAGIC0(x)            (((u_int64_t)(x.channel) << 48) | \
648 				((u_int64_t)(x.device != 0) << 56))
649     u_int16_t           magic_1;
650     u_int32_t           magic_2;
651     u_int8_t            filler1[470];
652     struct {
653 	u_int32_t       integrity;
654 #define PR_I_VALID              0x00000080
655 
656 	u_int8_t        flags;
657 #define PR_F_VALID              0x00000001
658 #define PR_F_ONLINE             0x00000002
659 #define PR_F_ASSIGNED           0x00000004
660 #define PR_F_SPARE              0x00000008
661 #define PR_F_DUPLICATE          0x00000010
662 #define PR_F_REDIR              0x00000020
663 #define PR_F_DOWN               0x00000040
664 #define PR_F_READY              0x00000080
665 
666 	u_int8_t        disk_number;
667 	u_int8_t        channel;
668 	u_int8_t        device;
669 	u_int64_t       magic_0 __packed;
670 	u_int32_t       disk_offset;
671 	u_int32_t       disk_sectors;
672 	u_int32_t       rebuild_lba;
673 	u_int16_t       generation;
674 	u_int8_t        status;
675 #define PR_S_VALID              0x01
676 #define PR_S_ONLINE             0x02
677 #define PR_S_INITED             0x04
678 #define PR_S_READY              0x08
679 #define PR_S_DEGRADED           0x10
680 #define PR_S_MARKED             0x20
681 #define PR_S_FUNCTIONAL         0x80
682 
683 	u_int8_t        type;
684 #define PR_T_RAID0              0x00
685 #define PR_T_RAID1              0x01
686 #define PR_T_RAID3              0x02
687 #define PR_T_RAID5              0x04
688 #define PR_T_SPAN               0x08
689 #define PR_T_JBOD               0x10
690 
691 	u_int8_t        total_disks;
692 	u_int8_t        stripe_shift;
693 	u_int8_t        array_width;
694 	u_int8_t        array_number;
695 	u_int32_t       total_sectors;
696 	u_int16_t       cylinders;
697 	u_int8_t        heads;
698 	u_int8_t        sectors;
699 	u_int64_t       magic_1 __packed;
700 	struct {
701 	    u_int8_t    flags;
702 	    u_int8_t    dummy_0;
703 	    u_int8_t    channel;
704 	    u_int8_t    device;
705 	    u_int64_t   magic_0 __packed;
706 	} disk[8];
707     } raid;
708     int32_t             filler2[346];
709     u_int32_t           checksum;
710 } __packed;
711 
712 
713 /* Silicon Image Medley Metadata */
714 #define SII_LBA(dev) \
715 	( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
716 
717 struct sii_raid_conf {
718     u_int16_t           ata_params_00_53[54];
719     u_int64_t           total_sectors;
720     u_int16_t           ata_params_58_79[70];
721     u_int16_t           dummy_0;
722     u_int16_t           dummy_1;
723     u_int32_t           controller_pci_id;
724     u_int16_t           version_minor;
725     u_int16_t           version_major;
726     u_int8_t            timestamp[6];
727     u_int16_t           stripe_sectors;
728     u_int16_t           dummy_2;
729     u_int8_t            disk_number;
730     u_int8_t            type;
731 #define SII_T_RAID0             0x00
732 #define SII_T_RAID1             0x01
733 #define SII_T_RAID01            0x02
734 #define SII_T_SPARE             0x03
735 
736     u_int8_t            raid0_disks;
737     u_int8_t            raid0_ident;
738     u_int8_t            raid1_disks;
739     u_int8_t            raid1_ident;
740     u_int64_t           rebuild_lba;
741     u_int32_t           generation;
742     u_int8_t            status;
743 #define SII_S_READY             0x01
744 
745     u_int8_t            base_raid1_position;
746     u_int8_t            base_raid0_position;
747     u_int8_t            position;
748     u_int16_t           dummy_3;
749     u_int8_t            name[16];
750     u_int16_t           checksum_0;
751     int8_t              filler1[190];
752     u_int16_t           checksum_1;
753 } __packed;
754 
755 
756 /* Silicon Integrated Systems RAID Metadata */
757 #define SIS_LBA(dev) \
758 	( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 16)
759 
760 struct sis_raid_conf {
761     u_int16_t           magic;
762 #define SIS_MAGIC               0x0010
763 
764     u_int8_t            disks;
765 #define SIS_D_MASTER            0xf0
766 #define SIS_D_MIRROR            0x0f
767 
768     u_int8_t            type_total_disks;
769 #define SIS_D_MASK              0x0f
770 #define SIS_T_MASK              0xf0
771 #define SIS_T_JBOD              0x10
772 #define SIS_T_RAID0             0x20
773 #define SIS_T_RAID1             0x30
774 
775     u_int32_t           dummy_0;
776     u_int32_t           controller_pci_id;
777     u_int16_t           stripe_sectors;
778     u_int16_t           dummy_1;
779     u_int32_t           timestamp;
780     u_int8_t            model[40];
781     u_int8_t            disk_number;
782     u_int8_t            dummy_2[3];
783     int8_t              filler1[448];
784 } __packed;
785 
786 
787 /* VIA Tech V-RAID Metadata */
788 #define VIA_LBA(dev) \
789 	( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
790 
791 struct via_raid_conf {
792     u_int16_t           magic;
793 #define VIA_MAGIC               0xaa55
794 
795     u_int8_t            dummy_0;
796     u_int8_t            type;
797 #define VIA_T_MASK              0x7e
798 #define VIA_T_BOOTABLE          0x01
799 #define VIA_T_RAID0             0x04
800 #define VIA_T_RAID1             0x0c
801 #define VIA_T_RAID01            0x4c
802 #define VIA_T_RAID5             0x2c
803 #define VIA_T_SPAN              0x44
804 #define VIA_T_UNKNOWN           0x80
805 
806     u_int8_t            disk_index;
807 #define VIA_D_MASK              0x0f
808 #define VIA_D_DEGRADED          0x10
809 #define VIA_D_HIGH_IDX          0x20
810 
811     u_int8_t            stripe_layout;
812 #define VIA_L_DISKS             0x07
813 #define VIA_L_MASK              0xf0
814 #define VIA_L_SHIFT             4
815 
816     u_int64_t           disk_sectors;
817     u_int32_t           disk_id;
818     u_int32_t           disks[8];
819     u_int8_t            checksum;
820     u_int8_t            filler_1[461];
821 } __packed;
822