]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/dde/fbsd/lib/ata/contrib/dev/ata/ata-raid.h
Inital import
[l4.git] / l4 / pkg / dde / fbsd / lib / ata / contrib / dev / ata / ata-raid.h
1 /*-
2  * Copyright (c) 2000 - 2003 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: src/sys/dev/ata/ata-raid.h,v 1.27 2004/06/25 21:21:59 sos Exp $
29  */
30
31 /* misc defines */
32 #define MAX_ARRAYS      16
33 #define MAX_DISKS       16
34 #define AR_PROXIMITY    2048
35 #define AR_READ         0x01
36 #define AR_WRITE        0x02
37 #define AR_WAIT         0x04
38 #define AR_STRATEGY(x)  (x)->bio_disk->d_strategy((x))
39 #define AD_SOFTC(x)     ((struct ad_softc *)(x.device->softc))
40 #define ATA_MAGIC       "FreeBSD ATA driver RAID "
41
42 struct ar_disk {
43     struct ata_device   *device;
44     u_int64_t           disk_sectors;   /* sectors on this disk */
45     off_t               last_lba;       /* last lba used */
46     int                 flags;
47 #define AR_DF_PRESENT           0x00000001
48 #define AR_DF_ASSIGNED          0x00000002
49 #define AR_DF_SPARE             0x00000004
50 #define AR_DF_ONLINE            0x00000008
51 };
52
53 struct ar_softc {
54     int                 lun;
55     int32_t             magic_0;        /* ident for this array */
56     int32_t             magic_1;        /* ident for this array */
57     int                 flags;
58 #define AR_F_SPAN               0x00000001
59 #define AR_F_RAID0              0x00000002
60 #define AR_F_RAID1              0x00000004
61 #define AR_F_RAID3              0x00000008
62 #define AR_F_RAID5              0x00000010      
63
64 #define AR_F_READY              0x00000100
65 #define AR_F_DEGRADED           0x00000200
66 #define AR_F_REBUILDING         0x00000400
67 #define AR_F_TOGGLE             0x00000800
68
69 #define AR_F_FREEBSD_RAID       0x00010000
70 #define AR_F_PROMISE_RAID       0x00020000
71 #define AR_F_HIGHPOINT_RAID     0x00040000
72 #define AR_F_ADAPTEC_RAID       0x00080000
73 #define AR_F_LSI_RAID           0x00100000
74 #define AR_F_INTEL_RAID         0x00200000
75 #define AR_F_QTEC_RAID          0x00400000
76
77     int                 total_disks;    /* number of disks in this array */
78     int                 generation;     /* generation of this array */
79     struct ar_disk      disks[MAX_DISKS+1]; /* ptr to each disk in array */
80     int                 width;          /* array width in disks */
81     u_int16_t           heads;
82     u_int16_t           sectors;
83     u_int32_t           cylinders;
84     u_int64_t           total_sectors;
85     int                 interleave;     /* interleave in blocks */
86     int                 reserved;       /* sectors that are NOT to be used */
87     int                 offset;         /* offset from start of disk */
88     u_int64_t           lock_start;     /* start of locked area for rebuild */
89     u_int64_t           lock_end;       /* end of locked area for rebuild */
90     struct disk         *disk;          /* disklabel/slice stuff */
91     struct proc         *pid;           /* rebuilder process id */
92 };
93
94 struct ar_buf {
95     struct bio          bp;             /* must be first element! */
96     struct bio          *org;
97     struct ar_buf       *mirror;
98     int                 drive;
99     int                 flags;
100 #define AB_F_DONE               0x01
101 };
102
103
104 #define HPT_LBA                 9
105
106 struct highpoint_raid_conf {
107     int8_t              filler1[32];
108     u_int32_t           magic;
109 #define HPT_MAGIC_OK            0x5a7816f0
110 #define HPT_MAGIC_BAD           0x5a7816fd
111
112     u_int32_t           magic_0;
113     u_int32_t           magic_1;
114     u_int32_t           order;
115 #define HPT_O_RAID0             0x01
116 #define HPT_O_RAID1             0x02
117 #define HPT_O_OK                0x04
118
119     u_int8_t            array_width;
120     u_int8_t            stripe_shift;
121     u_int8_t            type;
122 #define HPT_T_RAID0             0x00
123 #define HPT_T_RAID1             0x01
124 #define HPT_T_RAID01_RAID0      0x02
125 #define HPT_T_SPAN              0x03
126 #define HPT_T_RAID_3            0x04
127 #define HPT_T_RAID_5            0x05
128 #define HPT_T_SINGLEDISK        0x06
129 #define HPT_T_RAID01_RAID1      0x07
130
131     u_int8_t            disk_number;
132     u_int32_t           total_sectors;
133     u_int32_t           disk_mode;
134     u_int32_t           boot_mode;
135     u_int8_t            boot_disk;
136     u_int8_t            boot_protect;
137     u_int8_t            error_log_entries;
138     u_int8_t            error_log_index;
139     struct {
140         u_int32_t       timestamp;
141         u_int8_t        reason;
142 #define HPT_R_REMOVED           0xfe
143 #define HPT_R_BROKEN            0xff
144         
145         u_int8_t        disk;
146         u_int8_t        status;
147         u_int8_t        sectors;
148         u_int32_t       lba;
149     } errorlog[32];
150     int8_t              filler2[16];
151     u_int32_t           rebuild_lba;
152     u_int8_t            dummy_1;
153     u_int8_t            name_1[15];
154     u_int8_t            dummy_2;
155     u_int8_t            name_2[15];
156     int8_t              filler3[8];
157 } __packed;
158
159
160 #define LSI_LBA(adp)    (adp->total_secs - 1)
161
162 struct lsi_raid_conf {
163     u_int8_t            lsi_id[6];
164 #define LSI_MAGIC       "$XIDE$"
165
166     u_int8_t            dummy_1;
167     u_int8_t            flags;
168     u_int8_t            version[2];
169     u_int8_t            config_entries;
170     u_int8_t            raid_count;
171     u_int8_t            total_disks;
172     u_int8_t            dummy_d;
173     u_int8_t            dummy_e;
174     u_int8_t            dummy_f;
175
176     union {
177         struct {
178             u_int8_t    type;
179 #define LSI_R_RAID0     0x01
180 #define LSI_R_RAID1     0x02
181 #define LSI_R_SPARE     0x08
182
183             u_int8_t    dummy_1;
184             u_int16_t   stripe_size;
185             u_int8_t    raid_width;
186             u_int8_t    disk_count;
187             u_int8_t    config_offset;
188             u_int8_t    dummy_7;
189             u_int8_t    flags;
190 #define LSI_R_DEGRADED  0x02
191
192             u_int32_t   total_sectors;
193             u_int8_t    filler[3];
194         } __packed raid;
195         struct {
196             u_int8_t    device;
197 #define LSI_D_MASTER    0x00
198 #define LSI_D_SLAVE     0x01
199 #define LSI_D_CHANNEL0  0x00
200 #define LSI_D_CHANNEL1  0x10
201 #define LSI_D_NONE      0xff
202
203             u_int8_t    dummy_1;
204             u_int32_t   disk_sectors;
205             u_int8_t    disk_number;
206             u_int8_t    raid_number;
207             u_int8_t    flags;
208 #define LSI_D_GONE      0x02
209
210             u_int8_t    filler[7];
211         } __packed disk;
212     } configs[30];
213     u_int8_t            disk_number;
214     u_int8_t            raid_number;
215     u_int32_t           timestamp;
216     u_int8_t            filler[10];
217 } __packed;
218
219
220 #define PR_LBA(adp) \
221         (((adp->total_secs / (adp->heads * adp->sectors)) * \
222           adp->heads * adp->sectors) - adp->sectors)
223
224 struct promise_raid_conf {
225     char                promise_id[24];
226 #define PR_MAGIC        "Promise Technology, Inc."
227
228     u_int32_t           dummy_0;
229     u_int64_t           magic_0;
230 #define PR_MAGIC0(x)    (x.device ? ((u_int64_t)x.device->channel->unit<<48) | \
231                         ((u_int64_t)(x.device->unit != 0) << 56) : 0)
232     u_int16_t           magic_1;
233     u_int32_t           magic_2;
234     u_int8_t            filler1[470];
235     struct {
236         u_int32_t       integrity;
237 #define PR_I_VALID              0x00000080
238
239         u_int8_t        flags;
240 #define PR_F_VALID              0x00000001
241 #define PR_F_ONLINE             0x00000002
242 #define PR_F_ASSIGNED           0x00000004
243 #define PR_F_SPARE              0x00000008
244 #define PR_F_DUPLICATE          0x00000010
245 #define PR_F_REDIR              0x00000020
246 #define PR_F_DOWN               0x00000040
247 #define PR_F_READY              0x00000080
248
249         u_int8_t        disk_number;
250         u_int8_t        channel;
251         u_int8_t        device;
252         u_int64_t       magic_0 __packed;
253         u_int32_t       disk_offset;
254         u_int32_t       disk_sectors;
255         u_int32_t       rebuild_lba;
256         u_int16_t       generation;
257         u_int8_t        status;
258 #define PR_S_VALID              0x01
259 #define PR_S_ONLINE             0x02
260 #define PR_S_INITED             0x04
261 #define PR_S_READY              0x08
262 #define PR_S_DEGRADED           0x10
263 #define PR_S_MARKED             0x20
264 #define PR_S_FUNCTIONAL         0x80
265
266         u_int8_t        type;
267 #define PR_T_RAID0              0x00
268 #define PR_T_RAID1              0x01
269 #define PR_T_RAID3              0x02
270 #define PR_T_RAID5              0x04
271 #define PR_T_SPAN               0x08
272
273         u_int8_t        total_disks;
274         u_int8_t        stripe_shift;
275         u_int8_t        array_width;
276         u_int8_t        array_number;
277         u_int32_t       total_sectors;
278         u_int16_t       cylinders;
279         u_int8_t        heads;
280         u_int8_t        sectors;
281         int64_t         magic_1 __packed;
282         struct {
283             u_int8_t    flags;
284             u_int8_t    dummy_0;
285             u_int8_t    channel;
286             u_int8_t    device;
287             u_int64_t   magic_0 __packed;
288         } disk[8];
289     } raid;
290     int32_t             filler2[346];
291     u_int32_t           checksum;
292 } __packed;
293
294 int ata_raiddisk_attach(struct ad_softc *);
295 int ata_raiddisk_detach(struct ad_softc *);
296 void ata_raid_attach(void);
297 int ata_raid_create(struct raid_setup *);
298 int ata_raid_delete(int);
299 int ata_raid_status(int, struct raid_status *);
300 int ata_raid_addspare(int, int);
301 int ata_raid_rebuild(int);