ld_cac.c revision 1.3.8.3 1 /* $NetBSD: ld_cac.c,v 1.3.8.3 2002/01/29 23:31:32 he Exp $ */
2
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Compaq array controller front-end for ld(4) driver.
41 */
42
43 #include "rnd.h"
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
48 #include <sys/device.h>
49 #include <sys/buf.h>
50 #include <sys/endian.h>
51 #include <sys/dkio.h>
52 #include <sys/disk.h>
53 #if NRND > 0
54 #include <sys/rnd.h>
55 #endif
56
57 #include <machine/bus.h>
58
59 #include <dev/ldvar.h>
60
61 #include <dev/ic/cacreg.h>
62 #include <dev/ic/cacvar.h>
63
64 struct ld_cac_softc {
65 struct ld_softc sc_ld;
66 int sc_hwunit;
67 struct timeval sc_serrtm;
68 int sc_serrcnt;
69 };
70
71 void ld_cac_attach(struct device *, struct device *, void *);
72 void ld_cac_done(struct device *, void *, int);
73 int ld_cac_dump(struct ld_softc *, void *, int, int);
74 int ld_cac_match(struct device *, struct cfdata *, void *);
75 int ld_cac_start(struct ld_softc *, struct buf *);
76
77 static const struct timeval ld_cac_serrintvl = { 60, 0 };
78
79 struct cfattach ld_cac_ca = {
80 sizeof(struct ld_cac_softc), ld_cac_match, ld_cac_attach
81 };
82
83 int
84 ld_cac_match(struct device *parent, struct cfdata *match, void *aux)
85 {
86
87 return (1);
88 }
89
90 void
91 ld_cac_attach(struct device *parent, struct device *self, void *aux)
92 {
93 struct cac_drive_info dinfo;
94 struct cac_attach_args *caca;
95 struct ld_softc *ld;
96 struct ld_cac_softc *sc;
97 struct cac_softc *cac;
98 const char *type;
99
100 sc = (struct ld_cac_softc *)self;
101 ld = &sc->sc_ld;
102 caca = (struct cac_attach_args *)aux;
103 sc->sc_hwunit = caca->caca_unit;
104 cac = (struct cac_softc *)parent;
105
106 if (cac_cmd(cac, CAC_CMD_GET_LOG_DRV_INFO, &dinfo, sizeof(dinfo),
107 sc->sc_hwunit, 0, CAC_CCB_DATA_IN, NULL)) {
108 printf("%s: CMD_GET_LOG_DRV_INFO failed\n", self->dv_xname);
109 return;
110 }
111
112 ld->sc_secsize = CAC_GET2(dinfo.secsize);
113 ld->sc_maxxfer = CAC_MAX_XFER;
114 ld->sc_maxqueuecnt = CAC_MAX_CCBS / cac->sc_nunits; /* XXX */
115 ld->sc_secperunit = CAC_GET2(dinfo.ncylinders) *
116 CAC_GET1(dinfo.nheads) * CAC_GET1(dinfo.nsectors);
117 ld->sc_start = ld_cac_start;
118 ld->sc_dump = ld_cac_dump;
119
120 switch (CAC_GET1(dinfo.mirror)) {
121 case 0:
122 type = "standalone disk or RAID0";
123 break;
124 case 1:
125 type = "RAID4";
126 break;
127 case 2:
128 type = "RAID1";
129 break;
130 case 3:
131 type = "RAID5";
132 break;
133 default:
134 type = "unknown type of";
135 break;
136 }
137
138 printf(": %s array\n", type);
139
140 /* XXX We should verify this... */
141 ld->sc_flags = LDF_ENABLED;
142 ldattach(ld);
143 }
144
145 int
146 ld_cac_start(struct ld_softc *ld, struct buf *bp)
147 {
148 int flags, cmd;
149 struct cac_softc *cac;
150 struct ld_cac_softc *sc;
151 struct cac_context cc;
152
153 sc = (struct ld_cac_softc *)ld;
154 cac = (struct cac_softc *)ld->sc_dv.dv_parent;
155
156 cc.cc_handler = ld_cac_done;
157 cc.cc_context = bp;
158 cc.cc_dv = &ld->sc_dv;
159
160 if ((bp->b_flags & B_READ) == 0) {
161 cmd = CAC_CMD_WRITE;
162 flags = CAC_CCB_DATA_OUT;
163 } else {
164 cmd = CAC_CMD_READ;
165 flags = CAC_CCB_DATA_IN;
166 }
167
168 return (cac_cmd(cac, cmd, bp->b_data, bp->b_bcount, sc->sc_hwunit,
169 bp->b_rawblkno, flags, &cc));
170 }
171
172 int
173 ld_cac_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
174 {
175 struct ld_cac_softc *sc;
176
177 sc = (struct ld_cac_softc *)ld;
178
179 return (cac_cmd((struct cac_softc *)ld->sc_dv.dv_parent,
180 CAC_CMD_WRITE_MEDIA, data, blkcnt * ld->sc_secsize,
181 sc->sc_hwunit, blkno, CAC_CCB_DATA_OUT, NULL));
182 }
183
184 void
185 ld_cac_done(struct device *dv, void *context, int error)
186 {
187 struct buf *bp;
188 struct ld_cac_softc *sc;
189
190 bp = context;
191
192 if ((error & CAC_RET_HARD_ERROR) != 0) {
193 printf("%s: hard error\n", dv->dv_xname);
194 error = EIO;
195 }
196 if ((error & CAC_RET_CMD_REJECTED) != 0) {
197 printf("%s: invalid request\n", dv->dv_xname);
198 error = EIO;
199 }
200 if ((error & CAC_RET_SOFT_ERROR) != 0) {
201 sc = (struct ld_cac_softc *)dv;
202 sc->sc_serrcnt++;
203 if (ratecheck(&sc->sc_serrtm, &ld_cac_serrintvl)) {
204 printf("%s: %d soft errors; array may be degraded\n",
205 dv->dv_xname, sc->sc_serrcnt);
206 sc->sc_serrcnt = 0;
207 }
208 error = 0;
209 }
210
211 if (error) {
212 bp->b_flags |= B_ERROR;
213 bp->b_error = error;
214 bp->b_resid = bp->b_bcount;
215 } else
216 bp->b_resid = 0;
217
218 lddone((struct ld_softc *)dv, bp);
219 }
220