Merge branch 'master' of file:///repository/git/dragonfly
[dragonfly.git] / sys / dev / disk / ata / ata-raid.h
1 /*-
2  * Copyright (c) 2000,2001,2002 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.2.2.8 2002/04/11 09:31:57 sos Exp $
29  * $DragonFly: src/sys/dev/disk/ata/ata-raid.h,v 1.6 2006/09/10 01:26:33 dillon Exp $
30  */
31
32 /* misc defines */
33 #define MAX_ARRAYS      16
34 #define MAX_DISKS       16
35 #define AR_PROXIMITY    2048
36 #define AR_READ         0x01
37 #define AR_WRITE        0x02
38 #define AR_WAIT         0x04
39 #define AD_SOFTC(x)     ((struct ad_softc *)(x.device->driver))
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_RAID0              0x0001  /* STRIPE */
59 #define AR_F_RAID1              0x0002  /* MIRROR */
60 #define AR_F_SPAN               0x0004  /* SPAN */
61 #define AR_F_READY              0x0100
62 #define AR_F_DEGRADED           0x0200
63 #define AR_F_REBUILDING         0x0400
64 #define AR_F_PROMISE_RAID       0x1000
65 #define AR_F_HIGHPOINT_RAID     0x2000
66 #define AR_F_FREEBSD_RAID       0x4000
67     
68     int                 total_disks;    /* number of disks in this array */
69     int                 generation;     /* generation of this array */
70     struct ar_disk      disks[MAX_DISKS+1]; /* ptr to each disk in array */
71     int                 width;          /* array width in disks */
72     u_int16_t           heads;
73     u_int16_t           sectors;
74     u_int32_t           cylinders;
75     u_int64_t           total_sectors;
76     int                 interleave;     /* interleave in blocks */
77     int                 reserved;       /* sectors that are NOT to be used */
78     int                 offset;         /* offset from start of disk */
79     u_int64_t           lock_start;     /* start of locked area for rebuild */
80     u_int64_t           lock_end;       /* end of locked area for rebuild */
81     struct disk         disk;           /* disklabel/slice stuff */
82     struct proc         *pid;
83     cdev_t              dev;            /* device place holder */
84 };
85
86 struct ar_buf {
87     struct buf          bp;             /* must be first element! */
88     struct bio          *org;
89     struct ar_buf       *mirror;
90     int                 drive;
91     int                 flags;
92 #define AB_F_DONE               0x01
93 };
94
95 #define HPT_LBA                 9
96
97 struct highpoint_raid_conf {
98     int8_t              filler1[32];
99     u_int32_t           magic;                  /* 0x20 */
100 #define HPT_MAGIC_OK            0x5a7816f0
101 #define HPT_MAGIC_BAD           0x5a7816fd
102
103     u_int32_t           magic_0;
104     u_int32_t           magic_1;
105     u_int32_t           order;
106 #define HPT_O_RAID0             0x01
107 #define HPT_O_RAID1             0x02
108 #define HPT_O_OK                0x04
109
110     u_int8_t            array_width;
111     u_int8_t            stripe_shift;
112     u_int8_t            type;
113 #define HPT_T_RAID0             0x00
114 #define HPT_T_RAID1             0x01
115 #define HPT_T_RAID01_RAID0      0x02
116 #define HPT_T_SPAN              0x03
117 #define HPT_T_RAID_3            0x04
118 #define HPT_T_RAID_5            0x05
119 #define HPT_T_SINGLEDISK        0x06
120 #define HPT_T_RAID01_RAID1      0x07
121
122     u_int8_t            disk_number;
123     u_int32_t           total_sectors;
124     u_int32_t           disk_mode;
125     u_int32_t           boot_mode;
126     u_int8_t            boot_disk;
127     u_int8_t            boot_protect;
128     u_int8_t            error_log_entries;
129     u_int8_t            error_log_index;
130     struct {
131         u_int32_t       timestamp;
132         u_int8_t        reason;
133 #define HPT_R_REMOVED           0xfe
134 #define HPT_R_BROKEN            0xff
135         
136         u_int8_t        disk;
137         u_int8_t        status;
138         u_int8_t        sectors;
139         u_int32_t       lba;
140     } errorlog[32];
141     int8_t              filler2[16];
142     u_int32_t           rebuild_lba;
143     u_int8_t            dummy_1;
144     u_int8_t            name_1[15];
145     u_int8_t            dummy_2;
146     u_int8_t            name_2[15];
147     int8_t              filler3[8];
148 } __attribute__((packed));
149
150
151 #define PR_LBA(adp) \
152         (((adp->total_secs / (adp->heads * adp->sectors)) * \
153           adp->heads * adp->sectors) - adp->sectors)
154
155 struct promise_raid_conf {
156     char                promise_id[24];
157 #define PR_MAGIC        "Promise Technology, Inc."
158
159     u_int32_t           dummy_0;
160     u_int64_t           magic_0;
161 #define PR_MAGIC0(x)    (x.device ? ((u_int64_t)x.device->channel->unit<<48) | \
162                         ((u_int64_t)(x.device->unit != 0) << 56) : 0)
163     u_int16_t           magic_1;
164     u_int32_t           magic_2;
165     u_int8_t            filler1[470];
166     struct {
167         u_int32_t       integrity;              /* 0x200 */
168 #define PR_I_VALID              0x00000080
169
170         u_int8_t        flags;
171 #define PR_F_VALID              0x00000001
172 #define PR_F_ONLINE             0x00000002
173 #define PR_F_ASSIGNED           0x00000004
174 #define PR_F_SPARE              0x00000008
175 #define PR_F_DUPLICATE          0x00000010
176 #define PR_F_REDIR              0x00000020
177 #define PR_F_DOWN               0x00000040
178 #define PR_F_READY              0x00000080
179
180         u_int8_t        disk_number;
181         u_int8_t        channel;
182         u_int8_t        device;
183         u_int64_t       magic_0 __attribute__((packed));
184         u_int32_t       disk_offset;            /* 0x210 */
185         u_int32_t       disk_sectors;
186         u_int32_t       rebuild_lba;
187         u_int16_t       generation;
188         u_int8_t        status;
189 #define PR_S_VALID              0x01
190 #define PR_S_ONLINE             0x02
191 #define PR_S_INITED             0x04
192 #define PR_S_READY              0x08
193 #define PR_S_DEGRADED           0x10
194 #define PR_S_MARKED             0x20
195 #define PR_S_FUNCTIONAL         0x80
196
197         u_int8_t        type;
198 #define PR_T_RAID0              0x00
199 #define PR_T_RAID1              0x01
200 #define PR_T_RAID3              0x02
201 #define PR_T_RAID5              0x04
202 #define PR_T_SPAN               0x08
203
204         u_int8_t        total_disks;            /* 0x220 */
205         u_int8_t        stripe_shift;
206         u_int8_t        array_width;
207         u_int8_t        array_number;
208         u_int32_t       total_sectors;
209         u_int16_t       cylinders;
210         u_int8_t        heads;
211         u_int8_t        sectors;
212         int64_t         magic_1 __attribute__((packed));
213         struct {                                /* 0x240 */
214             u_int8_t    flags;
215             u_int8_t    dummy_0;
216             u_int8_t    channel;
217             u_int8_t    device;
218             u_int64_t   magic_0 __attribute__((packed));
219         } disk[8];
220     } raid;
221     int32_t             filler2[346];
222     u_int32_t           checksum;
223 } __attribute__((packed));
224
225 int ata_raiddisk_probe(struct ad_softc *);
226 int ata_raiddisk_attach(struct ad_softc *);
227 int ata_raiddisk_detach(struct ad_softc *);
228 void ata_raid_attach(void);
229 int ata_raid_create(struct raid_setup *);
230 int ata_raid_delete(int);
231 int ata_raid_status(int array, struct raid_status *);
232 int ata_raid_rebuild(int);
233