167071Ssos/*-
2178067Ssos * Copyright (c) 2000 - 2008 S�ren Schmidt <sos@FreeBSD.org>
367071Ssos * All rights reserved.
467071Ssos *
567071Ssos * Redistribution and use in source and binary forms, with or without
667071Ssos * modification, are permitted provided that the following conditions
767071Ssos * are met:
867071Ssos * 1. Redistributions of source code must retain the above copyright
967071Ssos *    notice, this list of conditions and the following disclaimer,
1067071Ssos *    without modification, immediately at the beginning of the file.
1167071Ssos * 2. Redistributions in binary form must reproduce the above copyright
1267071Ssos *    notice, this list of conditions and the following disclaimer in the
1367071Ssos *    documentation and/or other materials provided with the distribution.
1467071Ssos *
1567071Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1667071Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1767071Ssos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1867071Ssos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1967071Ssos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2067071Ssos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2167071Ssos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2267071Ssos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2367071Ssos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2467071Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2567071Ssos *
2667071Ssos * $FreeBSD$
2767071Ssos */
2867071Ssos
2991816Ssos/* misc defines */
30144330Ssos#define MAX_ARRAYS      16
31153117Ssos#define MAX_VOLUMES     4
32144330Ssos#define MAX_DISKS       16
33144330Ssos#define AR_PROXIMITY    2048    /* how many sectors is "close" */
3491816Ssos
35144330Ssos#define ATA_MAGIC       "FreeBSD ATA driver RAID "
36144330Ssos
37144330Ssosstruct ata_raid_subdisk {
38153117Ssos    struct ar_softc     *raid[MAX_VOLUMES];
39153117Ssos    int                 disk_number[MAX_VOLUMES];
4090215Ssos};
4190215Ssos
42144330Ssos/*  ATA PseudoRAID Metadata */
4367071Ssosstruct ar_softc {
44153117Ssos    int                 lun;
45153117Ssos    u_int8_t            name[32];
46154515Ssos    int                 volume;
47153117Ssos    u_int64_t           magic_0;
48153117Ssos    u_int64_t           magic_1;
49144330Ssos    int                 type;
50144330Ssos#define AR_T_JBOD               0x0001
51144330Ssos#define AR_T_SPAN               0x0002
52144330Ssos#define AR_T_RAID0              0x0004
53144330Ssos#define AR_T_RAID1              0x0008
54144330Ssos#define AR_T_RAID01             0x0010
55144330Ssos#define AR_T_RAID3              0x0020
56144330Ssos#define AR_T_RAID4              0x0040
57144330Ssos#define AR_T_RAID5              0x0080
58131113Ssos
59144330Ssos    int                 status;
60144330Ssos#define AR_S_READY              0x0001
61144330Ssos#define AR_S_DEGRADED           0x0002
62144330Ssos#define AR_S_REBUILDING         0x0004
63131113Ssos
64144330Ssos    int                 format;
65144330Ssos#define AR_F_FREEBSD_RAID       0x0001
66144330Ssos#define AR_F_ADAPTEC_RAID       0x0002
67144330Ssos#define AR_F_HPTV2_RAID         0x0004
68144330Ssos#define AR_F_HPTV3_RAID         0x0008
69144330Ssos#define AR_F_INTEL_RAID         0x0010
70144330Ssos#define AR_F_ITE_RAID           0x0020
71155779Ssos#define AR_F_JMICRON_RAID       0x0040
72155779Ssos#define AR_F_LSIV2_RAID         0x0080
73155779Ssos#define AR_F_LSIV3_RAID         0x0100
74155779Ssos#define AR_F_NVIDIA_RAID        0x0200
75155779Ssos#define AR_F_PROMISE_RAID       0x0400
76155779Ssos#define AR_F_SII_RAID           0x0800
77155779Ssos#define AR_F_SIS_RAID           0x1000
78155779Ssos#define AR_F_VIA_RAID           0x2000
79188840Sscottl#define AR_F_DDF_RAID		0x4000
80188840Sscottl#define AR_F_FORMAT_MASK        0x7fff
81131113Ssos
82153117Ssos    u_int               generation;
83144330Ssos    u_int64_t           total_sectors;
84144330Ssos    u_int64_t           offset_sectors; /* offset from start of disk */
85144330Ssos    u_int16_t           heads;
86144330Ssos    u_int16_t           sectors;
87144330Ssos    u_int32_t           cylinders;
88144330Ssos    u_int               width;          /* array width in disks */
89153117Ssos    u_int               interleave;     /* interleave in sectors */
90144330Ssos    u_int               total_disks;    /* number of disks in this array */
91144330Ssos    struct ar_disk {
92144330Ssos	device_t        dev;
93144330Ssos	u_int8_t        serial[16];     /* serial # of physical disk */
94144330Ssos	u_int64_t       sectors;        /* useable sectors on this disk */
95144330Ssos	off_t           last_lba;       /* last lba used (for performance) */
96144330Ssos	u_int           flags;
97144330Ssos#define AR_DF_PRESENT           0x0001  /* this HW pos has a disk present */
98144330Ssos#define AR_DF_ASSIGNED          0x0002  /* this HW pos assigned to an array */
99144330Ssos#define AR_DF_SPARE             0x0004  /* this HW pos is a spare */
100144330Ssos#define AR_DF_ONLINE            0x0008  /* this HW pos is online and in use */
10167071Ssos
102144330Ssos    } disks[MAX_DISKS];
103144330Ssos    int                 toggle;         /* performance hack for RAID1's */
104144330Ssos    u_int64_t           rebuild_lba;    /* rebuild progress indicator */
105144330Ssos    struct mtx          lock;           /* metadata lock */
106144330Ssos    struct disk         *disk;          /* disklabel/slice stuff */
107144330Ssos    struct proc         *pid;           /* rebuilder process id */
10867071Ssos};
10967071Ssos
110144330Ssos/* Adaptec HostRAID Metadata */
111144330Ssos#define ADP_LBA(dev) \
112144330Ssos	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 17)
113131113Ssos
114144330Ssos/* note all entries are big endian */
115144330Ssosstruct adaptec_raid_conf {
116144936Ssos    u_int32_t           magic_0;
117144330Ssos#define ADP_MAGIC_0             0xc4650790
11890215Ssos
119144330Ssos    u_int32_t           generation;
120144330Ssos    u_int16_t           dummy_0;
121144330Ssos    u_int16_t           total_configs;
122144330Ssos    u_int16_t           dummy_1;
123144330Ssos    u_int16_t           checksum;
124144936Ssos    u_int32_t           dummy_2;
125144330Ssos    u_int32_t           dummy_3;
126144330Ssos    u_int32_t           flags;
127144330Ssos    u_int32_t           timestamp;
128144936Ssos    u_int32_t           dummy_4[4];
129144936Ssos    u_int32_t           dummy_5[4];
130144936Ssos    struct {
131144330Ssos	u_int16_t       total_disks;
132144330Ssos	u_int16_t       generation;
133144330Ssos	u_int32_t       magic_0;
134144330Ssos	u_int8_t        dummy_0;
135144330Ssos	u_int8_t        type;
136144330Ssos#define ADP_T_RAID0             0x00
137144330Ssos#define ADP_T_RAID1             0x01
138144330Ssos	u_int8_t        dummy_1;
139144330Ssos	u_int8_t        flags;
14067071Ssos
141144330Ssos	u_int8_t        dummy_2;
142144330Ssos	u_int8_t        dummy_3;
143144330Ssos	u_int8_t        dummy_4;
144144330Ssos	u_int8_t        dummy_5;
14567071Ssos
146144330Ssos	u_int32_t       disk_number;
147144330Ssos	u_int32_t       dummy_6;
148144330Ssos	u_int32_t       sectors;
149144330Ssos	u_int16_t       stripe_shift;
150144330Ssos	u_int16_t       dummy_7;
15167071Ssos
152144330Ssos	u_int32_t       dummy_8[4];
153144330Ssos	u_int8_t        name[16];
154144936Ssos    } configs[127];
155144936Ssos    u_int32_t           dummy_6[13];
156144330Ssos    u_int32_t           magic_1;
157144330Ssos#define ADP_MAGIC_1             0x9ff85009
158144330Ssos    u_int32_t           dummy_7[3];
159144330Ssos    u_int32_t           magic_2;
160144330Ssos    u_int32_t           dummy_8[46];
161144330Ssos    u_int32_t           magic_3;
162144330Ssos#define ADP_MAGIC_3             0x4d545044
163144330Ssos    u_int32_t           magic_4;
164144330Ssos#define ADP_MAGIC_4             0x9ff85009
165144330Ssos    u_int32_t           dummy_9[62];
166144330Ssos} __packed;
167144330Ssos
168188840Sscottl/* DDF Information.  Metadata definitions are in another file */
169188840Sscottl#define DDF_LBA(dev) \
170188840Sscottl	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
171144330Ssos
172144330Ssos/* Highpoint V2 RocketRAID Metadata */
173144330Ssos#define HPTV2_LBA(dev)  9
174144330Ssos
175144330Ssosstruct hptv2_raid_conf {
176144330Ssos    int8_t              filler1[32];
177144330Ssos    u_int32_t           magic;
178144330Ssos#define HPTV2_MAGIC_OK          0x5a7816f0
179144330Ssos#define HPTV2_MAGIC_BAD         0x5a7816fd
180144330Ssos
181144330Ssos    u_int32_t           magic_0;
182144330Ssos    u_int32_t           magic_1;
183144330Ssos    u_int32_t           order;
184144330Ssos#define HPTV2_O_RAID0           0x01
185144330Ssos#define HPTV2_O_RAID1           0x02
186144330Ssos#define HPTV2_O_OK              0x04
187144330Ssos
188144330Ssos    u_int8_t            array_width;
189144330Ssos    u_int8_t            stripe_shift;
190144330Ssos    u_int8_t            type;
191144330Ssos#define HPTV2_T_RAID0           0x00
192144330Ssos#define HPTV2_T_RAID1           0x01
193144330Ssos#define HPTV2_T_RAID01_RAID0    0x02
194144330Ssos#define HPTV2_T_SPAN            0x03
195144330Ssos#define HPTV2_T_RAID_3          0x04
196144330Ssos#define HPTV2_T_RAID_5          0x05
197144330Ssos#define HPTV2_T_JBOD            0x06
198144330Ssos#define HPTV2_T_RAID01_RAID1    0x07
199144330Ssos
200144330Ssos    u_int8_t            disk_number;
201144330Ssos    u_int32_t           total_sectors;
202144330Ssos    u_int32_t           disk_mode;
203144330Ssos    u_int32_t           boot_mode;
204144330Ssos    u_int8_t            boot_disk;
205144330Ssos    u_int8_t            boot_protect;
206144330Ssos    u_int8_t            error_log_entries;
207144330Ssos    u_int8_t            error_log_index;
20867071Ssos    struct {
209144330Ssos	u_int32_t       timestamp;
210144330Ssos	u_int8_t        reason;
211144330Ssos#define HPTV2_R_REMOVED         0xfe
212144330Ssos#define HPTV2_R_BROKEN          0xff
21367071Ssos
214144330Ssos	u_int8_t        disk;
215144330Ssos	u_int8_t        status;
216144330Ssos	u_int8_t        sectors;
217144330Ssos	u_int32_t       lba;
21867071Ssos    } errorlog[32];
219144330Ssos    int8_t              filler2[16];
220144330Ssos    u_int32_t           rebuild_lba;
221144330Ssos    u_int8_t            dummy_1;
222144330Ssos    u_int8_t            name_1[15];
223144330Ssos    u_int8_t            dummy_2;
224144330Ssos    u_int8_t            name_2[15];
225144330Ssos    int8_t              filler3[8];
226103870Salfred} __packed;
22767071Ssos
22890566Ssos
229144330Ssos/* Highpoint V3 RocketRAID Metadata */
230144330Ssos#define HPTV3_LBA(dev) \
231144330Ssos	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 11)
232131113Ssos
233144330Ssosstruct hptv3_raid_conf {
234144330Ssos    u_int32_t           magic;
235144330Ssos#define HPTV3_MAGIC             0x5a7816f3
236131113Ssos
237144330Ssos    u_int32_t           magic_0;
238144330Ssos    u_int8_t            checksum_0;
239144330Ssos    u_int8_t            mode;
240144330Ssos#define HPTV3_BOOT_MARK         0x01
241144330Ssos#define HPTV3_USER_MODE         0x02
242144330Ssos
243144330Ssos    u_int8_t            user_mode;
244144330Ssos    u_int8_t            config_entries;
245144330Ssos    struct {
246144330Ssos	u_int32_t       total_sectors;
247144330Ssos	u_int8_t        type;
248144330Ssos#define HPTV3_T_SPARE           0x00
249144330Ssos#define HPTV3_T_JBOD            0x03
250144330Ssos#define HPTV3_T_SPAN            0x04
251144330Ssos#define HPTV3_T_RAID0           0x05
252144330Ssos#define HPTV3_T_RAID1           0x06
253144330Ssos#define HPTV3_T_RAID3           0x07
254144330Ssos#define HPTV3_T_RAID5           0x08
255131113Ssos
256144330Ssos	u_int8_t        total_disks;
257144330Ssos	u_int8_t        disk_number;
258144330Ssos	u_int8_t        stripe_shift;
259144330Ssos	u_int16_t       status;
260144330Ssos#define HPTV3_T_NEED_REBUILD    0x01
261144330Ssos#define HPTV3_T_RAID5_FLAG      0x02
262144330Ssos
263144330Ssos	u_int16_t       critical_disks;
264144330Ssos	u_int32_t       rebuild_lba;
265144330Ssos    } __packed configs[2];
266144330Ssos    u_int8_t            name[16];
267144330Ssos    u_int32_t           timestamp;
268144330Ssos    u_int8_t            description[64];
269144330Ssos    u_int8_t            creator[16];
270144330Ssos    u_int8_t            checksum_1;
271144330Ssos    u_int8_t            dummy_0;
272144330Ssos    u_int8_t            dummy_1;
273144330Ssos    u_int8_t            flags;
274144330Ssos#define HPTV3_T_ENABLE_TCQ      0x01
275144330Ssos#define HPTV3_T_ENABLE_NCQ      0x02
276144330Ssos#define HPTV3_T_ENABLE_WCACHE   0x04
277144330Ssos#define HPTV3_T_ENABLE_RCACHE   0x08
278144330Ssos
279144330Ssos    struct {
280144330Ssos	u_int32_t       total_sectors;
281144330Ssos	u_int32_t       rebuild_lba;
282144330Ssos    } __packed configs_high[2];
283144330Ssos    u_int32_t           filler[87];
284144330Ssos} __packed;
285144330Ssos
286144330Ssos
287144330Ssos/* Intel MatrixRAID Metadata */
288144330Ssos#define INTEL_LBA(dev) \
289153015Ssos	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 3)
290144330Ssos
291144330Ssosstruct intel_raid_conf {
292144330Ssos    u_int8_t            intel_id[24];
293145713Ssos#define INTEL_MAGIC             "Intel Raid ISM Cfg Sig. "
294144330Ssos
295144330Ssos    u_int8_t            version[6];
296153117Ssos#define INTEL_VERSION_1100      "1.1.00"
297153117Ssos#define INTEL_VERSION_1201      "1.2.01"
298153117Ssos#define INTEL_VERSION_1202      "1.2.02"
299153117Ssos
300144330Ssos    u_int8_t            dummy_0[2];
301144330Ssos    u_int32_t           checksum;
302144330Ssos    u_int32_t           config_size;
303144330Ssos    u_int32_t           config_id;
304144330Ssos    u_int32_t           generation;
305144330Ssos    u_int32_t           dummy_1[2];
306144330Ssos    u_int8_t            total_disks;
307144330Ssos    u_int8_t            total_volumes;
308144330Ssos    u_int8_t            dummy_2[2];
309144330Ssos    u_int32_t           filler_0[39];
310144330Ssos    struct {
311144330Ssos	u_int8_t        serial[16];
312144330Ssos	u_int32_t       sectors;
313144330Ssos	u_int32_t       id;
314144330Ssos	u_int32_t       flags;
315144330Ssos#define INTEL_F_SPARE           0x01
316144330Ssos#define INTEL_F_ASSIGNED        0x02
317144330Ssos#define INTEL_F_DOWN            0x04
318144330Ssos#define INTEL_F_ONLINE          0x08
319144330Ssos
320144330Ssos	u_int32_t       filler[5];
321144330Ssos    } __packed disk[1];
322144330Ssos    u_int32_t           filler_1[62];
323144330Ssos} __packed;
324144330Ssos
325144330Ssosstruct intel_raid_mapping {
326144330Ssos    u_int8_t            name[16];
327144330Ssos    u_int64_t           total_sectors __packed;
328144330Ssos    u_int32_t           state;
329144330Ssos    u_int32_t           reserved;
330153117Ssos    u_int32_t           filler_0[20];
331144330Ssos    u_int32_t           offset;
332144330Ssos    u_int32_t           disk_sectors;
333144330Ssos    u_int32_t           stripe_count;
334144330Ssos    u_int16_t           stripe_sectors;
335144330Ssos    u_int8_t            status;
336144330Ssos#define INTEL_S_READY           0x00
337144330Ssos#define INTEL_S_DISABLED        0x01
338144330Ssos#define INTEL_S_DEGRADED        0x02
339144330Ssos#define INTEL_S_FAILURE         0x03
340144330Ssos
341144330Ssos    u_int8_t            type;
342144330Ssos#define INTEL_T_RAID0           0x00
343144330Ssos#define INTEL_T_RAID1           0x01
344153015Ssos#define INTEL_T_RAID5           0x05
345144330Ssos
346144330Ssos    u_int8_t            total_disks;
347153117Ssos    u_int8_t            magic[3];
348153117Ssos    u_int32_t           filler_1[7];
349144330Ssos    u_int32_t           disk_idx[1];
350144330Ssos} __packed;
351144330Ssos
352144330Ssos
353144330Ssos/* Integrated Technology Express Metadata */
354144330Ssos#define ITE_LBA(dev) \
355144330Ssos	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
356144330Ssos
357144330Ssosstruct ite_raid_conf {
358144330Ssos    u_int32_t           filler_1[5];
359144936Ssos    u_int8_t            timestamp_0[8];
360144330Ssos    u_int32_t           dummy_1;
361144330Ssos    u_int32_t           filler_2[5];
362144330Ssos    u_int16_t           filler_3;
363144936Ssos    u_int8_t            ite_id[40];
364145713Ssos#define ITE_MAGIC               "Integrated Technology Express Inc      "
365144330Ssos
366144330Ssos    u_int16_t           filler_4;
367144330Ssos    u_int32_t           filler_5[6];
368144330Ssos    u_int32_t           dummy_2;
369144330Ssos    u_int32_t           dummy_3;
370144330Ssos    u_int32_t           filler_6[12];
371144330Ssos    u_int32_t           dummy_4;
372144330Ssos    u_int32_t           filler_7[5];
373144330Ssos    u_int64_t           total_sectors __packed;
374144330Ssos    u_int32_t           filler_8[12];
375144330Ssos
376144936Ssos    u_int16_t           filler_9;
377144330Ssos    u_int8_t            type;
378144330Ssos#define ITE_T_RAID0             0x00
379144330Ssos#define ITE_T_RAID1             0x01
380144330Ssos#define ITE_T_RAID01            0x02
381144330Ssos#define ITE_T_SPAN              0x03
382144330Ssos
383144330Ssos    u_int8_t            filler_10;
384144330Ssos    u_int32_t           dummy_5[8];
385144330Ssos    u_int8_t            stripe_1kblocks;
386144330Ssos    u_int8_t            filler_11[3];
387144330Ssos    u_int32_t           filler_12[54];
388144330Ssos
389144936Ssos    u_int32_t           dummy_6[4];
390144936Ssos    u_int8_t            timestamp_1[8];
391144330Ssos    u_int32_t           filler_13[9];
392144330Ssos    u_int8_t            stripe_sectors;
393144330Ssos    u_int8_t            filler_14[3];
394144330Ssos    u_int8_t            array_width;
395144330Ssos    u_int8_t            filler_15[3];
396144330Ssos    u_int32_t           filler_16;
397144330Ssos    u_int8_t            filler_17;
398144330Ssos    u_int8_t            disk_number;
399144330Ssos    u_int32_t           disk_sectors;
400144330Ssos    u_int16_t           filler_18;
401144330Ssos    u_int32_t           dummy_7[4];
402144330Ssos    u_int32_t           filler_20[104];
403144330Ssos} __packed;
404144330Ssos
405144330Ssos
406155779Ssos/* JMicron Technology Corp Metadata */
407155779Ssos#define JMICRON_LBA(dev) \
408155779Ssos	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
409155779Ssos#define	JM_MAX_DISKS		8
410155779Ssos
411155779Ssosstruct jmicron_raid_conf {
412155779Ssos    u_int8_t            signature[2];
413155779Ssos#define JMICRON_MAGIC		"JM"
414155779Ssos
415155779Ssos    u_int16_t           version;
416155779Ssos#define JMICRON_VERSION		0x0001
417155779Ssos
418155779Ssos    u_int16_t           checksum;
419155779Ssos    u_int8_t		filler_1[10];
420155779Ssos    u_int32_t           disk_id;
421155779Ssos    u_int32_t           offset;
422155779Ssos    u_int32_t           disk_sectors_high;
423155779Ssos    u_int16_t           disk_sectors_low;
424155779Ssos    u_int8_t		filler_2[2];
425155779Ssos    u_int8_t            name[16];
426155779Ssos    u_int8_t            type;
427155779Ssos#define	JM_T_RAID0		0
428155779Ssos#define	JM_T_RAID1		1
429155779Ssos#define	JM_T_RAID01		2
430155779Ssos#define	JM_T_JBOD		3
431155779Ssos#define	JM_T_RAID5		5
432155779Ssos
433155779Ssos    u_int8_t            stripe_shift;
434155779Ssos    u_int16_t           flags;
435155779Ssos#define	JM_F_READY		0x0001
436155779Ssos#define JM_F_BOOTABLE		0x0002
437155779Ssos#define JM_F_BAD		0x0004
438155779Ssos#define JM_F_ACTIVE		0c0010
439155779Ssos#define JM_F_UNSYNC		0c0020
440155779Ssos#define JM_F_NEWEST		0c0040
441155779Ssos
442155779Ssos    u_int8_t		filler_3[4];
443155779Ssos    u_int32_t           spare[2];
444155779Ssos    u_int32_t           disks[JM_MAX_DISKS];
445155779Ssos    u_int8_t		filler_4[32];
446155779Ssos    u_int8_t		filler_5[384];
447155779Ssos};
448155779Ssos
449155779Ssos
450144330Ssos/* LSILogic V2 MegaRAID Metadata */
451144330Ssos#define LSIV2_LBA(dev) \
452144330Ssos	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
453144330Ssos
454144330Ssosstruct lsiv2_raid_conf {
455144330Ssos    u_int8_t            lsi_id[6];
456145713Ssos#define LSIV2_MAGIC             "$XIDE$"
457144330Ssos
458144330Ssos    u_int8_t            dummy_0;
459144330Ssos    u_int8_t            flags;
460144330Ssos    u_int16_t           version;
461144330Ssos    u_int8_t            config_entries;
462144330Ssos    u_int8_t            raid_count;
463144330Ssos    u_int8_t            total_disks;
464144330Ssos    u_int8_t            dummy_1;
465144330Ssos    u_int16_t           dummy_2;
466144330Ssos
467131113Ssos    union {
468131113Ssos	struct {
469144330Ssos	    u_int8_t    type;
470144330Ssos#define LSIV2_T_RAID0           0x01
471144330Ssos#define LSIV2_T_RAID1           0x02
472144330Ssos#define LSIV2_T_SPARE           0x08
473131113Ssos
474144330Ssos	    u_int8_t    dummy_0;
475144330Ssos	    u_int16_t   stripe_sectors;
476144330Ssos	    u_int8_t    array_width;
477144330Ssos	    u_int8_t    disk_count;
478144330Ssos	    u_int8_t    config_offset;
479144330Ssos	    u_int8_t    dummy_1;
480144330Ssos	    u_int8_t    flags;
481144330Ssos#define LSIV2_R_DEGRADED        0x02
482131113Ssos
483144330Ssos	    u_int32_t   total_sectors;
484144330Ssos	    u_int8_t    filler[3];
485131113Ssos	} __packed raid;
486131113Ssos	struct {
487144330Ssos	    u_int8_t    device;
488144330Ssos#define LSIV2_D_MASTER          0x00
489144330Ssos#define LSIV2_D_SLAVE           0x01
490144330Ssos#define LSIV2_D_CHANNEL0        0x00
491144330Ssos#define LSIV2_D_CHANNEL1        0x10
492144330Ssos#define LSIV2_D_NONE            0xff
493131113Ssos
494144330Ssos	    u_int8_t    dummy_0;
495144330Ssos	    u_int32_t   disk_sectors;
496144330Ssos	    u_int8_t    disk_number;
497144330Ssos	    u_int8_t    raid_number;
498144330Ssos	    u_int8_t    flags;
499144330Ssos#define LSIV2_D_GONE            0x02
500131113Ssos
501144330Ssos	    u_int8_t    filler[7];
502131113Ssos	} __packed disk;
503131113Ssos    } configs[30];
504144330Ssos    u_int8_t            disk_number;
505144330Ssos    u_int8_t            raid_number;
506144330Ssos    u_int32_t           timestamp;
507144330Ssos    u_int8_t            filler[10];
508131113Ssos} __packed;
509131113Ssos
510131113Ssos
511144330Ssos/* LSILogic V3 MegaRAID Metadata */
512144330Ssos#define LSIV3_LBA(dev) \
513144330Ssos	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 4)
51490215Ssos
515144330Ssosstruct lsiv3_raid_conf {
516144330Ssos    u_int32_t           magic_0;        /* 0xa0203200 */
517144330Ssos    u_int32_t           filler_0[3];
518144330Ssos    u_int8_t            magic_1[4];     /* "SATA" */
519144330Ssos    u_int32_t           filler_1[40];
520144330Ssos    u_int32_t           dummy_0;        /* 0x0d000003 */
521144330Ssos    u_int32_t           filler_2[7];
522144330Ssos    u_int32_t           dummy_1;        /* 0x0d000003 */
523144330Ssos    u_int32_t           filler_3[70];
524144330Ssos    u_int8_t            magic_2[8];     /* "$_ENQ$31" */
525144330Ssos    u_int8_t            filler_4[7];
526144330Ssos    u_int8_t            checksum_0;
527144330Ssos    u_int8_t            filler_5[512*2];
528144330Ssos    u_int8_t            lsi_id[6];
529145713Ssos#define LSIV3_MAGIC             "$_IDE$"
530144330Ssos
531144330Ssos    u_int16_t           dummy_2;        /* 0x33de for OK disk */
532144330Ssos    u_int16_t           version;        /* 0x0131 for this version */
533144330Ssos    u_int16_t           dummy_3;        /* 0x0440 always */
534144330Ssos    u_int32_t           filler_6;
535144330Ssos
536144330Ssos    struct {
537144330Ssos	u_int16_t       stripe_pages;
538144330Ssos	u_int8_t        type;
539144330Ssos#define LSIV3_T_RAID0           0x00
540144330Ssos#define LSIV3_T_RAID1           0x01
541144330Ssos
542144330Ssos	u_int8_t        dummy_0;
543144330Ssos	u_int8_t        total_disks;
544144330Ssos	u_int8_t        array_width;
545144330Ssos	u_int8_t        filler_0[10];
546144330Ssos
547144330Ssos	u_int32_t       sectors;
548144330Ssos	u_int16_t       dummy_1;
549144330Ssos	u_int32_t       offset;
550144330Ssos	u_int16_t       dummy_2;
551144330Ssos	u_int8_t        device;
552144330Ssos#define LSIV3_D_DEVICE          0x01
553144330Ssos#define LSIV3_D_CHANNEL         0x10
554144330Ssos
555144330Ssos	u_int8_t        dummy_3;
556144330Ssos	u_int8_t        dummy_4;
557144330Ssos	u_int8_t        dummy_5;
558144330Ssos	u_int8_t        filler_1[16];
559144330Ssos    } __packed raid[8];
560144330Ssos    struct {
561144330Ssos	u_int32_t       disk_sectors;
562144330Ssos	u_int32_t       dummy_0;
563144330Ssos	u_int32_t       dummy_1;
564144330Ssos	u_int8_t        dummy_2;
565144330Ssos	u_int8_t        dummy_3;
566144330Ssos	u_int8_t        flags;
567144330Ssos#define LSIV3_D_MIRROR          0x00
568144330Ssos#define LSIV3_D_STRIPE          0xff
569144330Ssos	u_int8_t        dummy_4;
570144330Ssos    } __packed disk[6];
571144330Ssos    u_int8_t            filler_7[7];
572144330Ssos    u_int8_t            device;
573144330Ssos    u_int32_t           timestamp;
574144330Ssos    u_int8_t            filler_8[3];
575144330Ssos    u_int8_t            checksum_1;
576144330Ssos} __packed;
577144330Ssos
578144330Ssos
579147052Ssos/* nVidia MediaShield Metadata */
580147052Ssos#define NVIDIA_LBA(dev) \
581147052Ssos	(((struct ad_softc *)device_get_ivars(dev))->total_secs - 2)
582147052Ssos
583147052Ssosstruct nvidia_raid_conf {
584147052Ssos    u_int8_t            nvidia_id[8];
585147052Ssos#define NV_MAGIC                "NVIDIA  "
586147052Ssos
587147052Ssos    u_int32_t           config_size;
588147052Ssos    u_int32_t           checksum;
589147052Ssos    u_int16_t           version;
590147052Ssos    u_int8_t            disk_number;
591147052Ssos    u_int8_t            dummy_0;
592147052Ssos    u_int32_t           total_sectors;
593147052Ssos    u_int32_t           sector_size;
594147052Ssos    u_int8_t            serial[16];
595147052Ssos    u_int8_t            revision[4];
596147052Ssos    u_int32_t           dummy_1;
597147052Ssos
598147052Ssos    u_int32_t           magic_0;
599147052Ssos#define NV_MAGIC0               0x00640044
600147052Ssos
601147052Ssos    u_int64_t           magic_1;
602147052Ssos    u_int64_t           magic_2;
603147052Ssos    u_int8_t            flags;
604147052Ssos    u_int8_t            array_width;
605147052Ssos    u_int8_t            total_disks;
606147052Ssos    u_int8_t            dummy_2;
607147052Ssos    u_int16_t           type;
608147052Ssos#define NV_T_RAID0              0x00000080
609147052Ssos#define NV_T_RAID1              0x00000081
610147052Ssos#define NV_T_RAID3              0x00000083
611147052Ssos#define NV_T_RAID5              0x00000085
612147052Ssos#define NV_T_RAID01             0x00008180
613147052Ssos#define NV_T_SPAN               0x000000ff
614147052Ssos
615147052Ssos    u_int16_t           dummy_3;
616147052Ssos    u_int32_t           stripe_sectors;
617147052Ssos    u_int32_t           stripe_bytes;
618147052Ssos    u_int32_t           stripe_shift;
619147052Ssos    u_int32_t           stripe_mask;
620147052Ssos    u_int32_t           stripe_sizesectors;
621147052Ssos    u_int32_t           stripe_sizebytes;
622147052Ssos    u_int32_t           rebuild_lba;
623147052Ssos    u_int32_t           dummy_4;
624147052Ssos    u_int32_t           dummy_5;
625147052Ssos    u_int32_t           status;
626147052Ssos#define NV_S_BOOTABLE           0x00000001
627147052Ssos#define NV_S_DEGRADED           0x00000002
628147052Ssos
629147052Ssos    u_int32_t           filler[98];
630147052Ssos} __packed;
631147052Ssos
632147052Ssos
633144330Ssos/* Promise FastTrak Metadata */
634153446Ssos#define PROMISE_LBA(dev) \
635145760Ssos	(((((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)
636144330Ssos
63767071Ssosstruct promise_raid_conf {
638144330Ssos    char                promise_id[24];
639145713Ssos#define PR_MAGIC                "Promise Technology, Inc."
64067071Ssos
641144330Ssos    u_int32_t           dummy_0;
642144330Ssos    u_int64_t           magic_0;
643145713Ssos#define PR_MAGIC0(x)            (((u_int64_t)(x.channel) << 48) | \
644144936Ssos				((u_int64_t)(x.device != 0) << 56))
645144330Ssos    u_int16_t           magic_1;
646144330Ssos    u_int32_t           magic_2;
647144330Ssos    u_int8_t            filler1[470];
64867071Ssos    struct {
649144330Ssos	u_int32_t       integrity;
650144330Ssos#define PR_I_VALID              0x00000080
65190215Ssos
652144330Ssos	u_int8_t        flags;
653144330Ssos#define PR_F_VALID              0x00000001
654144330Ssos#define PR_F_ONLINE             0x00000002
655144330Ssos#define PR_F_ASSIGNED           0x00000004
656144330Ssos#define PR_F_SPARE              0x00000008
657144330Ssos#define PR_F_DUPLICATE          0x00000010
658144330Ssos#define PR_F_REDIR              0x00000020
659144330Ssos#define PR_F_DOWN               0x00000040
660144330Ssos#define PR_F_READY              0x00000080
66167071Ssos
662144330Ssos	u_int8_t        disk_number;
663144330Ssos	u_int8_t        channel;
664144330Ssos	u_int8_t        device;
665144330Ssos	u_int64_t       magic_0 __packed;
666144330Ssos	u_int32_t       disk_offset;
667144330Ssos	u_int32_t       disk_sectors;
668144330Ssos	u_int32_t       rebuild_lba;
669144330Ssos	u_int16_t       generation;
670144330Ssos	u_int8_t        status;
671144330Ssos#define PR_S_VALID              0x01
672144330Ssos#define PR_S_ONLINE             0x02
673144330Ssos#define PR_S_INITED             0x04
674144330Ssos#define PR_S_READY              0x08
675144330Ssos#define PR_S_DEGRADED           0x10
676144330Ssos#define PR_S_MARKED             0x20
677144330Ssos#define PR_S_FUNCTIONAL         0x80
67867071Ssos
679144330Ssos	u_int8_t        type;
680144330Ssos#define PR_T_RAID0              0x00
681144330Ssos#define PR_T_RAID1              0x01
682144330Ssos#define PR_T_RAID3              0x02
683144330Ssos#define PR_T_RAID5              0x04
684144330Ssos#define PR_T_SPAN               0x08
685144330Ssos#define PR_T_JBOD               0x10
68667071Ssos
687144330Ssos	u_int8_t        total_disks;
688144330Ssos	u_int8_t        stripe_shift;
689144330Ssos	u_int8_t        array_width;
690144330Ssos	u_int8_t        array_number;
691144330Ssos	u_int32_t       total_sectors;
692144330Ssos	u_int16_t       cylinders;
693144330Ssos	u_int8_t        heads;
694144330Ssos	u_int8_t        sectors;
695144330Ssos	u_int64_t       magic_1 __packed;
696131113Ssos	struct {
697144330Ssos	    u_int8_t    flags;
698144330Ssos	    u_int8_t    dummy_0;
699144330Ssos	    u_int8_t    channel;
700144330Ssos	    u_int8_t    device;
701144330Ssos	    u_int64_t   magic_0 __packed;
70267071Ssos	} disk[8];
70368183Ssos    } raid;
704144330Ssos    int32_t             filler2[346];
705144330Ssos    u_int32_t           checksum;
706103870Salfred} __packed;
70767071Ssos
708144330Ssos
709144330Ssos/* Silicon Image Medley Metadata */
710144330Ssos#define SII_LBA(dev) \
711144330Ssos	( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
712144330Ssos
713144330Ssosstruct sii_raid_conf {
714154515Ssos    u_int16_t           ata_params_00_53[54];
715154515Ssos    u_int64_t           total_sectors;
716154515Ssos    u_int16_t           ata_params_58_79[70];
717154515Ssos    u_int16_t           dummy_0;
718154515Ssos    u_int16_t           dummy_1;
719154515Ssos    u_int32_t           controller_pci_id;
720154515Ssos    u_int16_t           version_minor;
721154515Ssos    u_int16_t           version_major;
722154515Ssos    u_int8_t            timestamp[6];
723154515Ssos    u_int16_t           stripe_sectors;
724154515Ssos    u_int16_t           dummy_2;
725154515Ssos    u_int8_t            disk_number;
726154515Ssos    u_int8_t            type;
727144330Ssos#define SII_T_RAID0             0x00
728144330Ssos#define SII_T_RAID1             0x01
729144330Ssos#define SII_T_RAID01            0x02
730144330Ssos#define SII_T_SPARE             0x03
731144330Ssos
732154515Ssos    u_int8_t            raid0_disks;
733154515Ssos    u_int8_t            raid0_ident;
734154515Ssos    u_int8_t            raid1_disks;
735154515Ssos    u_int8_t            raid1_ident;
736154515Ssos    u_int64_t           rebuild_lba;
737154515Ssos    u_int32_t           generation;
738154515Ssos    u_int8_t            status;
739144330Ssos#define SII_S_READY             0x01
740144330Ssos
741154515Ssos    u_int8_t            base_raid1_position;
742154515Ssos    u_int8_t            base_raid0_position;
743154515Ssos    u_int8_t            position;
744154515Ssos    u_int16_t           dummy_3;
745154515Ssos    u_int8_t            name[16];
746154515Ssos    u_int16_t           checksum_0;
747154515Ssos    int8_t              filler1[190];
748154515Ssos    u_int16_t           checksum_1;
749144330Ssos} __packed;
750144936Ssos
751144936Ssos
752152908Ssos/* Silicon Integrated Systems RAID Metadata */
753152908Ssos#define SIS_LBA(dev) \
754152908Ssos	( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 16)
755152908Ssos
756152908Ssosstruct sis_raid_conf {
757154515Ssos    u_int16_t           magic;
758152908Ssos#define SIS_MAGIC               0x0010
759152908Ssos
760154515Ssos    u_int8_t            disks;
761154515Ssos#define SIS_D_MASTER            0xf0
762154515Ssos#define SIS_D_MIRROR            0x0f
763152908Ssos
764154515Ssos    u_int8_t            type_total_disks;
765154515Ssos#define SIS_D_MASK              0x0f
766152908Ssos#define SIS_T_MASK              0xf0
767152908Ssos#define SIS_T_JBOD              0x10
768154515Ssos#define SIS_T_RAID0             0x20
769152908Ssos#define SIS_T_RAID1             0x30
770152908Ssos
771154515Ssos    u_int32_t           dummy_0;
772154515Ssos    u_int32_t           controller_pci_id;
773154515Ssos    u_int16_t           stripe_sectors;
774154515Ssos    u_int16_t           dummy_1;
775154515Ssos    u_int32_t           timestamp;
776154515Ssos    u_int8_t            model[40];
777154515Ssos    u_int8_t            disk_number;
778154515Ssos    u_int8_t            dummy_2[3];
779154515Ssos    int8_t              filler1[448];
780152908Ssos} __packed;
781152908Ssos
782152908Ssos
783144940Ssos/* VIA Tech V-RAID Metadata */
784144936Ssos#define VIA_LBA(dev) \
785144936Ssos	( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1)
786144936Ssos
787144936Ssosstruct via_raid_conf {
788154515Ssos    u_int16_t           magic;
789145713Ssos#define VIA_MAGIC               0xaa55
790144936Ssos
791154515Ssos    u_int8_t            dummy_0;
792154515Ssos    u_int8_t            type;
793153416Ssos#define VIA_T_MASK              0x7e
794145713Ssos#define VIA_T_BOOTABLE          0x01
795145713Ssos#define VIA_T_RAID0             0x04
796145713Ssos#define VIA_T_RAID1             0x0c
797153416Ssos#define VIA_T_RAID01            0x4c
798153416Ssos#define VIA_T_RAID5             0x2c
799145713Ssos#define VIA_T_SPAN              0x44
800153416Ssos#define VIA_T_UNKNOWN           0x80
801144936Ssos
802154515Ssos    u_int8_t            disk_index;
803154515Ssos#define VIA_D_MASK              0x0f
804154515Ssos#define VIA_D_DEGRADED          0x10
805154515Ssos#define VIA_D_HIGH_IDX          0x20
806149823Ssos
807154515Ssos    u_int8_t            stripe_layout;
808153446Ssos#define VIA_L_DISKS             0x07
809153446Ssos#define VIA_L_MASK              0xf0
810154515Ssos#define VIA_L_SHIFT             4
811144936Ssos
812154515Ssos    u_int64_t           disk_sectors;
813154515Ssos    u_int32_t           disk_id;
814154515Ssos    u_int32_t           disks[8];
815154515Ssos    u_int8_t            checksum;
816154515Ssos    u_int8_t            filler_1[461];
817144936Ssos} __packed;
818