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