]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/ata/ata-raid.h
Fix problem with finding the still working disk in a broken mirror on VIA.
[FreeBSD/FreeBSD.git] / sys / dev / ata / ata-raid.h
1 /*-
2  * Copyright (c) 2000 - 2005 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  * 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.
16  *
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.
27  *
28  * $FreeBSD$
29  */
30
31 /* misc defines */
32 #define MAX_ARRAYS      16
33 #define MAX_DISKS       16
34 #define AR_PROXIMITY    2048    /* how many sectors is "close" */
35
36 #define ATA_MAGIC       "FreeBSD ATA driver RAID "
37
38 struct ata_raid_subdisk {
39     struct ar_softc     *raid;
40     int                 disk_number;
41 };
42
43 /*  ATA PseudoRAID Metadata */
44 struct ar_softc {
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 */
49     int                 type;
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
58
59     int                 status;
60 #define AR_S_READY              0x0001
61 #define AR_S_DEGRADED           0x0002
62 #define AR_S_REBUILDING         0x0004
63
64     int                 format;
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_VIA_RAID           0x0800
77 #define AR_F_FORMAT_MASK        0x0fff
78
79     u_int               generation;     /* generation of this array */
80     u_int64_t           total_sectors;
81     u_int64_t           offset_sectors; /* offset from start of disk */
82     u_int16_t           heads;
83     u_int16_t           sectors;
84     u_int32_t           cylinders;
85     u_int               width;          /* array width in disks */
86     u_int               interleave;     /* interleave in blocks */
87     u_int               total_disks;    /* number of disks in this array */
88     struct ar_disk {
89         device_t        dev;
90         u_int8_t        serial[16];     /* serial # of physical disk */
91         u_int64_t       sectors;        /* useable sectors on this disk */
92         off_t           last_lba;       /* last lba used (for performance) */
93         u_int           flags;
94 #define AR_DF_PRESENT           0x0001  /* this HW pos has a disk present */
95 #define AR_DF_ASSIGNED          0x0002  /* this HW pos assigned to an array */
96 #define AR_DF_SPARE             0x0004  /* this HW pos is a spare */
97 #define AR_DF_ONLINE            0x0008  /* this HW pos is online and in use */
98
99     } disks[MAX_DISKS];
100     int                 toggle;         /* performance hack for RAID1's */
101     u_int64_t           rebuild_lba;    /* rebuild progress indicator */
102     struct mtx          lock;           /* metadata lock */
103     struct disk         *disk;          /* disklabel/slice stuff */
104     struct proc         *pid;           /* rebuilder process id */
105 };
106
107 /* Adaptec HostRAID Metadata */
108 #define ADP_LBA(dev) \
109         (((struct ad_softc *)device_get_ivars(dev))->total_secs - 17)
110
111 /* note all entries are big endian */
112 struct adaptec_raid_conf {
113     u_int32_t           magic_0;
114 #define ADP_MAGIC_0             0xc4650790
115
116     u_int32_t           generation;
117     u_int16_t           dummy_0;
118     u_int16_t           total_configs;
119     u_int16_t           dummy_1;
120     u_int16_t           checksum;
121     u_int32_t           dummy_2;
122     u_int32_t           dummy_3;
123     u_int32_t           flags;
124     u_int32_t           timestamp;
125     u_int32_t           dummy_4[4];
126     u_int32_t           dummy_5[4];
127     struct {
128         u_int16_t       total_disks;
129         u_int16_t       generation;
130         u_int32_t       magic_0;
131         u_int8_t        dummy_0;
132         u_int8_t        type;
133 #define ADP_T_RAID0             0x00
134 #define ADP_T_RAID1             0x01
135         u_int8_t        dummy_1;
136         u_int8_t        flags;
137
138         u_int8_t        dummy_2;
139         u_int8_t        dummy_3;
140         u_int8_t        dummy_4;
141         u_int8_t        dummy_5;
142
143         u_int32_t       disk_number;
144         u_int32_t       dummy_6;
145         u_int32_t       sectors;
146         u_int16_t       stripe_shift;
147         u_int16_t       dummy_7;
148
149         u_int32_t       dummy_8[4];
150         u_int8_t        name[16];
151     } configs[127];
152     u_int32_t           dummy_6[13];
153     u_int32_t           magic_1;
154 #define ADP_MAGIC_1             0x9ff85009
155     u_int32_t           dummy_7[3];
156     u_int32_t           magic_2;
157     u_int32_t           dummy_8[46];
158     u_int32_t           magic_3;
159 #define ADP_MAGIC_3             0x4d545044
160     u_int32_t           magic_4;
161 #define ADP_MAGIC_4             0x9ff85009
162     u_int32_t           dummy_9[62];
163 } __packed;
164
165
166 /* Highpoint V2 RocketRAID Metadata */
167 #define HPTV2_LBA(dev)  9
168
169 struct hptv2_raid_conf {
170     int8_t              filler1[32];
171     u_int32_t           magic;
172 #define HPTV2_MAGIC_OK          0x5a7816f0
173 #define HPTV2_MAGIC_BAD         0x5a7816fd
174
175     u_int32_t           magic_0;
176     u_int32_t           magic_1;
177     u_int32_t           order;
178 #define HPTV2_O_RAID0           0x01
179 #define HPTV2_O_RAID1           0x02
180 #define HPTV2_O_OK              0x04
181
182     u_int8_t            array_width;
183     u_int8_t            stripe_shift;
184     u_int8_t            type;
185 #define HPTV2_T_RAID0           0x00
186 #define HPTV2_T_RAID1           0x01
187 #define HPTV2_T_RAID01_RAID0    0x02
188 #define HPTV2_T_SPAN            0x03
189 #define HPTV2_T_RAID_3          0x04
190 #define HPTV2_T_RAID_5          0x05
191 #define HPTV2_T_JBOD            0x06
192 #define HPTV2_T_RAID01_RAID1    0x07
193
194     u_int8_t            disk_number;
195     u_int32_t           total_sectors;
196     u_int32_t           disk_mode;
197     u_int32_t           boot_mode;
198     u_int8_t            boot_disk;
199     u_int8_t            boot_protect;
200     u_int8_t            error_log_entries;
201     u_int8_t            error_log_index;
202     struct {
203         u_int32_t       timestamp;
204         u_int8_t        reason;
205 #define HPTV2_R_REMOVED         0xfe
206 #define HPTV2_R_BROKEN          0xff
207         
208         u_int8_t        disk;
209         u_int8_t        status;
210         u_int8_t        sectors;
211         u_int32_t       lba;
212     } errorlog[32];
213     int8_t              filler2[16];
214     u_int32_t           rebuild_lba;
215     u_int8_t            dummy_1;
216     u_int8_t            name_1[15];
217     u_int8_t            dummy_2;
218     u_int8_t            name_2[15];
219     int8_t              filler3[8];
220 } __packed;
221
222
223 /* Highpoint V3 RocketRAID Metadata */
224 #define HPTV3_LBA(dev) \
225         (((struct ad_softc *)device_get_ivars(dev))->total_secs - 11)
226
227 struct hptv3_raid_conf {
228     u_int32_t           magic;
229 #define HPTV3_MAGIC             0x5a7816f3
230
231     u_int32_t           magic_0;
232     u_int8_t            checksum_0;
233     u_int8_t            mode;
234 #define HPTV3_BOOT_MARK         0x01
235 #define HPTV3_USER_MODE         0x02
236     
237     u_int8_t            user_mode;
238     u_int8_t            config_entries;
239     struct {
240         u_int32_t       total_sectors;
241         u_int8_t        type;
242 #define HPTV3_T_SPARE           0x00
243 #define HPTV3_T_JBOD            0x03
244 #define HPTV3_T_SPAN            0x04
245 #define HPTV3_T_RAID0           0x05
246 #define HPTV3_T_RAID1           0x06
247 #define HPTV3_T_RAID3           0x07
248 #define HPTV3_T_RAID5           0x08
249
250         u_int8_t        total_disks;
251         u_int8_t        disk_number;
252         u_int8_t        stripe_shift;
253         u_int16_t       status;
254 #define HPTV3_T_NEED_REBUILD    0x01
255 #define HPTV3_T_RAID5_FLAG      0x02
256
257         u_int16_t       critical_disks;
258         u_int32_t       rebuild_lba;
259     } __packed configs[2];
260     u_int8_t            name[16];
261     u_int32_t           timestamp;
262     u_int8_t            description[64];
263     u_int8_t            creator[16];
264     u_int8_t            checksum_1;
265     u_int8_t            dummy_0;
266     u_int8_t            dummy_1;
267     u_int8_t            flags;
268 #define HPTV3_T_ENABLE_TCQ      0x01
269 #define HPTV3_T_ENABLE_NCQ      0x02
270 #define HPTV3_T_ENABLE_WCACHE   0x04
271 #define HPTV3_T_ENABLE_RCACHE   0x08
272
273     struct {
274         u_int32_t       total_sectors;
275         u_int32_t       rebuild_lba;
276     } __packed configs_high[2];
277     u_int32_t           filler[87];
278 } __packed;
279
280
281 /* Intel MatrixRAID Metadata */
282 #define INTEL_LBA(dev) \
283         (((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
284
285 struct intel_raid_conf {
286     u_int8_t            intel_id[24];
287 #define INTEL_MAGIC             "Intel Raid ISM Cfg Sig. "
288
289     u_int8_t            version[6];
290     u_int8_t            dummy_0[2];
291     u_int32_t           checksum;
292     u_int32_t           config_size;
293     u_int32_t           config_id;
294     u_int32_t           generation;
295     u_int32_t           dummy_1[2];
296     u_int8_t            total_disks;
297     u_int8_t            total_volumes;
298     u_int8_t            dummy_2[2];
299     u_int32_t           filler_0[39];
300     struct {
301         u_int8_t        serial[16];
302         u_int32_t       sectors;
303         u_int32_t       id;
304         u_int32_t       flags;
305 #define INTEL_F_SPARE           0x01
306 #define INTEL_F_ASSIGNED        0x02
307 #define INTEL_F_DOWN            0x04
308 #define INTEL_F_ONLINE          0x08
309
310         u_int32_t       filler[5];
311     } __packed disk[1];
312     u_int32_t           filler_1[62];
313 } __packed;
314
315 struct intel_raid_mapping {
316     u_int8_t            name[16];
317     u_int64_t           total_sectors __packed;
318     u_int32_t           state;
319     u_int32_t           reserved;
320     u_int32_t           filler_1[20];
321     u_int32_t           offset;
322     u_int32_t           disk_sectors;
323     u_int32_t           stripe_count;
324     u_int16_t           stripe_sectors;
325     u_int8_t            status;
326 #define INTEL_S_READY           0x00
327 #define INTEL_S_DISABLED        0x01
328 #define INTEL_S_DEGRADED        0x02
329 #define INTEL_S_FAILURE         0x03
330
331     u_int8_t            type;
332 #define INTEL_T_RAID0           0x00
333 #define INTEL_T_RAID1           0x01
334
335     u_int8_t            total_disks;
336     u_int8_t            dummy_2[3];
337     u_int32_t           filler_2[7];
338     u_int32_t           disk_idx[1];
339 } __packed;
340
341
342 /* Integrated Technology Express Metadata */
343 #define ITE_LBA(dev) \
344         (((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
345
346 struct ite_raid_conf {
347     u_int32_t           filler_1[5];
348     u_int8_t            timestamp_0[8];
349     u_int32_t           dummy_1;
350     u_int32_t           filler_2[5];
351     u_int16_t           filler_3;
352     u_int8_t            ite_id[40];
353 #define ITE_MAGIC               "Integrated Technology Express Inc      "
354
355     u_int16_t           filler_4;
356     u_int32_t           filler_5[6];
357     u_int32_t           dummy_2;
358     u_int32_t           dummy_3;
359     u_int32_t           filler_6[12];
360     u_int32_t           dummy_4;
361     u_int32_t           filler_7[5];
362     u_int64_t           total_sectors __packed;
363     u_int32_t           filler_8[12];
364     
365     u_int16_t           filler_9;
366     u_int8_t            type;
367 #define ITE_T_RAID0             0x00
368 #define ITE_T_RAID1             0x01
369 #define ITE_T_RAID01            0x02
370 #define ITE_T_SPAN              0x03
371
372     u_int8_t            filler_10;
373     u_int32_t           dummy_5[8];
374     u_int8_t            stripe_1kblocks;
375     u_int8_t            filler_11[3];
376     u_int32_t           filler_12[54];
377
378     u_int32_t           dummy_6[4];
379     u_int8_t            timestamp_1[8];
380     u_int32_t           filler_13[9];
381     u_int8_t            stripe_sectors;
382     u_int8_t            filler_14[3];
383     u_int8_t            array_width;
384     u_int8_t            filler_15[3];
385     u_int32_t           filler_16;
386     u_int8_t            filler_17;
387     u_int8_t            disk_number;
388     u_int32_t           disk_sectors;
389     u_int16_t           filler_18;
390     u_int32_t           dummy_7[4];
391     u_int32_t           filler_20[104];
392 } __packed;
393
394
395 /* LSILogic V2 MegaRAID Metadata */
396 #define LSIV2_LBA(dev) \
397         (((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
398
399 struct lsiv2_raid_conf {
400     u_int8_t            lsi_id[6];
401 #define LSIV2_MAGIC             "$XIDE$"
402
403     u_int8_t            dummy_0;
404     u_int8_t            flags;
405     u_int16_t           version;
406     u_int8_t            config_entries;
407     u_int8_t            raid_count;
408     u_int8_t            total_disks;
409     u_int8_t            dummy_1;
410     u_int16_t           dummy_2;
411
412     union {
413         struct {
414             u_int8_t    type;
415 #define LSIV2_T_RAID0           0x01
416 #define LSIV2_T_RAID1           0x02
417 #define LSIV2_T_SPARE           0x08
418
419             u_int8_t    dummy_0;
420             u_int16_t   stripe_sectors;
421             u_int8_t    array_width;
422             u_int8_t    disk_count;
423             u_int8_t    config_offset;
424             u_int8_t    dummy_1;
425             u_int8_t    flags;
426 #define LSIV2_R_DEGRADED        0x02
427
428             u_int32_t   total_sectors;
429             u_int8_t    filler[3];
430         } __packed raid;
431         struct {
432             u_int8_t    device;
433 #define LSIV2_D_MASTER          0x00
434 #define LSIV2_D_SLAVE           0x01
435 #define LSIV2_D_CHANNEL0        0x00
436 #define LSIV2_D_CHANNEL1        0x10
437 #define LSIV2_D_NONE            0xff
438
439             u_int8_t    dummy_0;
440             u_int32_t   disk_sectors;
441             u_int8_t    disk_number;
442             u_int8_t    raid_number;
443             u_int8_t    flags;
444 #define LSIV2_D_GONE            0x02
445
446             u_int8_t    filler[7];
447         } __packed disk;
448     } configs[30];
449     u_int8_t            disk_number;
450     u_int8_t            raid_number;
451     u_int32_t           timestamp;
452     u_int8_t            filler[10];
453 } __packed;
454
455
456 /* LSILogic V3 MegaRAID Metadata */
457 #define LSIV3_LBA(dev) \
458         (((struct ad_softc *)device_get_ivars(dev))->total_secs - 4)
459
460 struct lsiv3_raid_conf {
461     u_int32_t           magic_0;        /* 0xa0203200 */
462     u_int32_t           filler_0[3];
463     u_int8_t            magic_1[4];     /* "SATA" */
464     u_int32_t           filler_1[40];
465     u_int32_t           dummy_0;        /* 0x0d000003 */
466     u_int32_t           filler_2[7];
467     u_int32_t           dummy_1;        /* 0x0d000003 */
468     u_int32_t           filler_3[70];
469     u_int8_t            magic_2[8];     /* "$_ENQ$31" */
470     u_int8_t            filler_4[7];
471     u_int8_t            checksum_0;
472     u_int8_t            filler_5[512*2];
473     u_int8_t            lsi_id[6];
474 #define LSIV3_MAGIC             "$_IDE$"
475
476     u_int16_t           dummy_2;        /* 0x33de for OK disk */
477     u_int16_t           version;        /* 0x0131 for this version */
478     u_int16_t           dummy_3;        /* 0x0440 always */
479     u_int32_t           filler_6;
480
481     struct {
482         u_int16_t       stripe_pages;
483         u_int8_t        type;
484 #define LSIV3_T_RAID0           0x00
485 #define LSIV3_T_RAID1           0x01
486
487         u_int8_t        dummy_0;
488         u_int8_t        total_disks;
489         u_int8_t        array_width;
490         u_int8_t        filler_0[10];
491
492         u_int32_t       sectors;
493         u_int16_t       dummy_1;
494         u_int32_t       offset;
495         u_int16_t       dummy_2;
496         u_int8_t        device;
497 #define LSIV3_D_DEVICE          0x01
498 #define LSIV3_D_CHANNEL         0x10
499
500         u_int8_t        dummy_3;
501         u_int8_t        dummy_4;
502         u_int8_t        dummy_5;
503         u_int8_t        filler_1[16];
504     } __packed raid[8];
505     struct {
506         u_int32_t       disk_sectors;
507         u_int32_t       dummy_0;
508         u_int32_t       dummy_1;
509         u_int8_t        dummy_2;
510         u_int8_t        dummy_3;
511         u_int8_t        flags;
512 #define LSIV3_D_MIRROR          0x00
513 #define LSIV3_D_STRIPE          0xff
514         u_int8_t        dummy_4;
515     } __packed disk[6];
516     u_int8_t            filler_7[7];
517     u_int8_t            device;
518     u_int32_t           timestamp;
519     u_int8_t            filler_8[3];
520     u_int8_t            checksum_1;
521 } __packed;
522
523
524 /* nVidia MediaShield Metadata */
525 #define NVIDIA_LBA(dev) \
526         (((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
527
528 struct nvidia_raid_conf {
529     u_int8_t            nvidia_id[8];
530 #define NV_MAGIC                "NVIDIA  "
531
532     u_int32_t           config_size;
533     u_int32_t           checksum;
534     u_int16_t           version;
535     u_int8_t            disk_number;
536     u_int8_t            dummy_0;
537     u_int32_t           total_sectors;
538     u_int32_t           sector_size;
539     u_int8_t            serial[16];
540     u_int8_t            revision[4];
541     u_int32_t           dummy_1;
542
543     u_int32_t           magic_0;
544 #define NV_MAGIC0               0x00640044
545
546     u_int64_t           magic_1;
547     u_int64_t           magic_2;
548     u_int8_t            flags;
549     u_int8_t            array_width;
550     u_int8_t            total_disks;
551     u_int8_t            dummy_2;
552     u_int16_t           type;
553 #define NV_T_RAID0              0x00000080
554 #define NV_T_RAID1              0x00000081
555 #define NV_T_RAID3              0x00000083
556 #define NV_T_RAID5              0x00000085
557 #define NV_T_RAID01             0x00008180
558 #define NV_T_SPAN               0x000000ff
559
560     u_int16_t           dummy_3;
561     u_int32_t           stripe_sectors;
562     u_int32_t           stripe_bytes;
563     u_int32_t           stripe_shift;
564     u_int32_t           stripe_mask;
565     u_int32_t           stripe_sizesectors;
566     u_int32_t           stripe_sizebytes;
567     u_int32_t           rebuild_lba;
568     u_int32_t           dummy_4;
569     u_int32_t           dummy_5;
570     u_int32_t           status;
571 #define NV_S_BOOTABLE           0x00000001
572 #define NV_S_DEGRADED           0x00000002
573
574     u_int32_t           filler[98];
575 } __packed;
576
577
578 /* Promise FastTrak Metadata */
579 #define PR_LBA(dev) \
580         (((((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)
581
582 struct promise_raid_conf {
583     char                promise_id[24];
584 #define PR_MAGIC                "Promise Technology, Inc."
585
586     u_int32_t           dummy_0;
587     u_int64_t           magic_0;
588 #define PR_MAGIC0(x)            (((u_int64_t)(x.channel) << 48) | \
589                                 ((u_int64_t)(x.device != 0) << 56))
590     u_int16_t           magic_1;
591     u_int32_t           magic_2;
592     u_int8_t            filler1[470];
593     struct {
594         u_int32_t       integrity;
595 #define PR_I_VALID              0x00000080
596
597         u_int8_t        flags;
598 #define PR_F_VALID              0x00000001
599 #define PR_F_ONLINE             0x00000002
600 #define PR_F_ASSIGNED           0x00000004
601 #define PR_F_SPARE              0x00000008
602 #define PR_F_DUPLICATE          0x00000010
603 #define PR_F_REDIR              0x00000020
604 #define PR_F_DOWN               0x00000040
605 #define PR_F_READY              0x00000080
606
607         u_int8_t        disk_number;
608         u_int8_t        channel;
609         u_int8_t        device;
610         u_int64_t       magic_0 __packed;
611         u_int32_t       disk_offset;
612         u_int32_t       disk_sectors;
613         u_int32_t       rebuild_lba;
614         u_int16_t       generation;
615         u_int8_t        status;
616 #define PR_S_VALID              0x01
617 #define PR_S_ONLINE             0x02
618 #define PR_S_INITED             0x04
619 #define PR_S_READY              0x08
620 #define PR_S_DEGRADED           0x10
621 #define PR_S_MARKED             0x20
622 #define PR_S_FUNCTIONAL         0x80
623
624         u_int8_t        type;
625 #define PR_T_RAID0              0x00
626 #define PR_T_RAID1              0x01
627 #define PR_T_RAID3              0x02
628 #define PR_T_RAID5              0x04
629 #define PR_T_SPAN               0x08
630 #define PR_T_JBOD               0x10
631
632         u_int8_t        total_disks;
633         u_int8_t        stripe_shift;
634         u_int8_t        array_width;
635         u_int8_t        array_number;
636         u_int32_t       total_sectors;
637         u_int16_t       cylinders;
638         u_int8_t        heads;
639         u_int8_t        sectors;
640         u_int64_t       magic_1 __packed;
641         struct {
642             u_int8_t    flags;
643             u_int8_t    dummy_0;
644             u_int8_t    channel;
645             u_int8_t    device;
646             u_int64_t   magic_0 __packed;
647         } disk[8];
648     } raid;
649     int32_t             filler2[346];
650     u_int32_t           checksum;
651 } __packed;
652
653
654 /* Silicon Image Medley Metadata */
655 #define SII_LBA(dev) \
656         ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
657
658 struct sii_raid_conf {
659     u_int16_t   ata_params_00_53[54];
660     u_int64_t   total_sectors;
661     u_int16_t   ata_params_58_79[70];
662     u_int16_t   dummy_0;
663     u_int16_t   dummy_1;
664     u_int32_t   controller_pci_id;
665     u_int16_t   version_minor;
666     u_int16_t   version_major;
667     u_int8_t    timestamp[6];
668     u_int16_t   stripe_sectors;
669     u_int16_t   dummy_2;
670     u_int8_t    disk_number;
671     u_int8_t    type;
672 #define SII_T_RAID0             0x00
673 #define SII_T_RAID1             0x01
674 #define SII_T_RAID01            0x02
675 #define SII_T_SPARE             0x03
676
677     u_int8_t    raid0_disks;
678     u_int8_t    raid0_ident;
679     u_int8_t    raid1_disks;
680     u_int8_t    raid1_ident;
681     u_int64_t   rebuild_lba;
682     u_int32_t   generation;
683     u_int8_t    status;
684 #define SII_S_READY             0x01
685     
686     u_int8_t    base_raid1_position;
687     u_int8_t    base_raid0_position;
688     u_int8_t    position;
689     u_int16_t   dummy_3;
690     u_int8_t    name[16];
691     u_int16_t   checksum_0;
692     int8_t      filler1[190];
693     u_int16_t   checksum_1;
694 } __packed;
695
696
697 /* VIA Tech V-RAID Metadata */
698 #define VIA_LBA(dev) \
699         ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
700
701 struct via_raid_conf {
702     u_int16_t   magic;
703 #define VIA_MAGIC               0xaa55
704
705     u_int8_t    dummy_0;
706     u_int8_t    type;
707 #define VIA_T_MASK              0xfe
708 #define VIA_T_BOOTABLE          0x01
709 #define VIA_T_RAID0             0x04
710 #define VIA_T_RAID1             0x0c
711 #define VIA_T_SPAN              0x44
712
713     u_int8_t    disk_index;
714 #define VIA_D_MASK              0x0f
715 #define VIA_D_DEGRADED          0x10
716
717     u_int8_t    stripe_layout;
718 #define VIA_L_MASK              0x07
719 #define VIA_L_SHIFT             4
720
721     u_int64_t   total_sectors;
722     u_int32_t   disk_id;
723     u_int32_t   disks[8];
724     u_int8_t    checksum;
725     u_int8_t    filler_1[461];
726 } __packed;