ld_iop.c revision 1.2 1 1.1 ad /* $NetBSD: ld_iop.c,v 1.2 2000/12/03 13:17:03 ad Exp $ */
2 1.1 ad
3 1.1 ad /*-
4 1.1 ad * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.1 ad * All rights reserved.
6 1.1 ad *
7 1.1 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.1 ad * by Andrew Doran.
9 1.1 ad *
10 1.1 ad * Redistribution and use in source and binary forms, with or without
11 1.1 ad * modification, are permitted provided that the following conditions
12 1.1 ad * are met:
13 1.1 ad * 1. Redistributions of source code must retain the above copyright
14 1.1 ad * notice, this list of conditions and the following disclaimer.
15 1.1 ad * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 ad * notice, this list of conditions and the following disclaimer in the
17 1.1 ad * documentation and/or other materials provided with the distribution.
18 1.1 ad * 3. All advertising materials mentioning features or use of this software
19 1.1 ad * must display the following acknowledgement:
20 1.1 ad * This product includes software developed by the NetBSD
21 1.1 ad * Foundation, Inc. and its contributors.
22 1.1 ad * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 ad * contributors may be used to endorse or promote products derived
24 1.1 ad * from this software without specific prior written permission.
25 1.1 ad *
26 1.1 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 ad * POSSIBILITY OF SUCH DAMAGE.
37 1.1 ad */
38 1.1 ad
39 1.1 ad /*
40 1.1 ad * I2O front-end for ld(4) driver, supporting random block storage class
41 1.2 ad * devices. Currently, this doesn't handle anything more complex than
42 1.2 ad * fixed direct-access devices.
43 1.1 ad */
44 1.1 ad
45 1.1 ad #include "opt_i2o.h"
46 1.1 ad #include "rnd.h"
47 1.1 ad
48 1.1 ad #include <sys/param.h>
49 1.1 ad #include <sys/systm.h>
50 1.1 ad #include <sys/kernel.h>
51 1.1 ad #include <sys/device.h>
52 1.1 ad #include <sys/buf.h>
53 1.1 ad #include <sys/endian.h>
54 1.1 ad #include <sys/dkio.h>
55 1.1 ad #include <sys/disk.h>
56 1.1 ad #include <sys/proc.h>
57 1.1 ad #if NRND > 0
58 1.1 ad #include <sys/rnd.h>
59 1.1 ad #endif
60 1.1 ad
61 1.1 ad #include <machine/bus.h>
62 1.1 ad
63 1.1 ad #include <dev/ldvar.h>
64 1.1 ad
65 1.1 ad #include <dev/i2o/i2o.h>
66 1.1 ad #include <dev/i2o/iopvar.h>
67 1.1 ad
68 1.1 ad #define LD_IOP_MAXQUEUECNT 64 /* XXX */
69 1.2 ad #define LD_IOP_TIMEOUT 10*1000*1000
70 1.1 ad
71 1.1 ad struct ld_iop_softc {
72 1.1 ad struct ld_softc sc_ld;
73 1.1 ad struct iop_initiator sc_ii;
74 1.2 ad struct iop_initiator sc_eventii;
75 1.2 ad int sc_claimed;
76 1.1 ad u_int sc_tid;
77 1.1 ad };
78 1.1 ad
79 1.1 ad static void ld_iop_attach(struct device *, struct device *, void *);
80 1.2 ad static int ld_iop_detach(struct device *, int);
81 1.1 ad static int ld_iop_dump(struct ld_softc *, void *, int, int);
82 1.1 ad static int ld_iop_flush(struct ld_softc *);
83 1.1 ad static void ld_iop_intr(struct device *, struct iop_msg *, void *);
84 1.2 ad static void ld_iop_intr_event(struct device *, struct iop_msg *, void *);
85 1.1 ad static int ld_iop_start(struct ld_softc *, struct buf *);
86 1.1 ad static int ld_iop_match(struct device *, struct cfdata *, void *);
87 1.1 ad
88 1.1 ad struct cfattach ld_iop_ca = {
89 1.2 ad sizeof(struct ld_iop_softc),
90 1.2 ad ld_iop_match,
91 1.2 ad ld_iop_attach,
92 1.2 ad ld_iop_detach
93 1.1 ad };
94 1.1 ad
95 1.1 ad #ifdef I2OVERBOSE
96 1.1 ad static const char *ld_iop_errors[] = {
97 1.1 ad "success",
98 1.1 ad "media error",
99 1.1 ad "failure communicating with device",
100 1.1 ad "device failure",
101 1.1 ad "device is not ready",
102 1.1 ad "media not present",
103 1.1 ad "media locked by another user",
104 1.1 ad "media failure",
105 1.1 ad "failure communicating to device",
106 1.1 ad "device bus failure",
107 1.1 ad "device locked by another user",
108 1.1 ad "device write protected",
109 1.1 ad "device reset",
110 1.1 ad "volume has changed, waiting for acknowledgement",
111 1.1 ad };
112 1.1 ad #endif
113 1.1 ad
114 1.1 ad static int
115 1.1 ad ld_iop_match(struct device *parent, struct cfdata *match, void *aux)
116 1.1 ad {
117 1.1 ad struct iop_attach_args *ia;
118 1.1 ad
119 1.1 ad ia = aux;
120 1.1 ad
121 1.2 ad return (ia->ia_class != I2O_CLASS_RANDOM_BLOCK_STORAGE);
122 1.1 ad }
123 1.1 ad
124 1.1 ad static void
125 1.1 ad ld_iop_attach(struct device *parent, struct device *self, void *aux)
126 1.1 ad {
127 1.1 ad struct iop_attach_args *ia;
128 1.1 ad struct ld_softc *ld;
129 1.1 ad struct ld_iop_softc *sc;
130 1.1 ad struct iop_softc *iop;
131 1.2 ad int rv, evreg, enable;
132 1.2 ad char ident[64 + 1], *typestr, *fixedstr;
133 1.1 ad u_int cachesz;
134 1.1 ad struct {
135 1.1 ad struct i2o_param_op_results pr;
136 1.1 ad struct i2o_param_read_results prr;
137 1.1 ad union {
138 1.1 ad struct i2o_param_rbs_cache_control cc;
139 1.1 ad struct i2o_param_rbs_device_info bdi;
140 1.1 ad struct i2o_param_device_identity di;
141 1.2 ad struct i2o_param_rbs_operation op;
142 1.1 ad } p;
143 1.1 ad } param;
144 1.1 ad
145 1.1 ad sc = (struct ld_iop_softc *)self;
146 1.1 ad ld = &sc->sc_ld;
147 1.1 ad iop = (struct iop_softc *)parent;
148 1.1 ad ia = (struct iop_attach_args *)aux;
149 1.1 ad sc->sc_tid = ia->ia_tid;
150 1.2 ad evreg = 0;
151 1.1 ad
152 1.1 ad /* Register us as an initiator. */
153 1.1 ad sc->sc_ii.ii_dv = self;
154 1.1 ad sc->sc_ii.ii_intr = ld_iop_intr;
155 1.1 ad sc->sc_ii.ii_flags = 0;
156 1.2 ad sc->sc_ii.ii_tid = ia->ia_tid;
157 1.1 ad if (iop_initiator_register(iop, &sc->sc_ii) != 0) {
158 1.2 ad printf("%s: unable to register initiator\n", self->dv_xname);
159 1.1 ad return;
160 1.1 ad }
161 1.1 ad
162 1.2 ad /* Register another initiator to handle events from the device. */
163 1.2 ad sc->sc_eventii.ii_dv = self;
164 1.2 ad sc->sc_eventii.ii_intr = ld_iop_intr_event;
165 1.2 ad sc->sc_eventii.ii_flags = II_DISCARD | II_UTILITY;
166 1.2 ad sc->sc_eventii.ii_tid = ia->ia_tid;
167 1.2 ad if (iop_initiator_register(iop, &sc->sc_eventii) != 0) {
168 1.2 ad printf("%s: unable to register initiator", self->dv_xname);
169 1.2 ad goto bad;
170 1.2 ad }
171 1.2 ad if (iop_util_eventreg(iop, &sc->sc_eventii, 0xffffffff)) {
172 1.2 ad printf("%s: unable to register for events", self->dv_xname);
173 1.2 ad goto bad;
174 1.2 ad }
175 1.2 ad evreg = 1;
176 1.2 ad
177 1.1 ad ld->sc_maxxfer = IOP_MAX_XFER;
178 1.1 ad ld->sc_maxqueuecnt = LD_IOP_MAXQUEUECNT;
179 1.1 ad ld->sc_dump = ld_iop_dump;
180 1.1 ad ld->sc_flush = ld_iop_flush;
181 1.1 ad ld->sc_start = ld_iop_start;
182 1.1 ad
183 1.1 ad /* Say what the device is. */
184 1.1 ad printf(": ");
185 1.2 ad if (iop_param_op(iop, ia->ia_tid, 0, I2O_PARAM_DEVICE_IDENTITY, ¶m,
186 1.1 ad sizeof(param)) == 0) {
187 1.2 ad iop_strvis(iop, param.p.di.vendorinfo,
188 1.1 ad sizeof(param.p.di.vendorinfo), ident, sizeof(ident));
189 1.1 ad printf("<%s, ", ident);
190 1.2 ad iop_strvis(iop, param.p.di.productinfo,
191 1.1 ad sizeof(param.p.di.productinfo), ident, sizeof(ident));
192 1.1 ad printf("%s, ", ident);
193 1.2 ad iop_strvis(iop, param.p.di.revlevel,
194 1.1 ad sizeof(param.p.di.revlevel), ident, sizeof(ident));
195 1.1 ad printf("%s> ", ident);
196 1.1 ad }
197 1.1 ad
198 1.2 ad /*
199 1.2 ad * Claim the device so that we don't get any nasty surprises. Allow
200 1.2 ad * failure.
201 1.2 ad */
202 1.2 ad sc->sc_claimed = !iop_util_claim(iop, &sc->sc_ii, 0,
203 1.1 ad I2O_UTIL_CLAIM_CAPACITY_SENSITIVE |
204 1.1 ad I2O_UTIL_CLAIM_NO_PEER_SERVICE |
205 1.1 ad I2O_UTIL_CLAIM_NO_MANAGEMENT_SERVICE |
206 1.1 ad I2O_UTIL_CLAIM_PRIMARY_USER);
207 1.1 ad
208 1.2 ad rv = iop_param_op(iop, ia->ia_tid, 0, I2O_PARAM_RBS_DEVICE_INFO,
209 1.2 ad ¶m, sizeof(param));
210 1.1 ad if (rv != 0) {
211 1.2 ad printf("%s: unable to get parameters (0x%04x; %d)\n",
212 1.2 ad ld->sc_dv.dv_xname, I2O_PARAM_RBS_DEVICE_INFO, rv);
213 1.1 ad goto bad;
214 1.1 ad }
215 1.1 ad
216 1.1 ad ld->sc_secsize = le32toh(param.p.bdi.blocksize);
217 1.1 ad ld->sc_secperunit = (int)
218 1.1 ad (le64toh(param.p.bdi.capacity) / ld->sc_secsize);
219 1.1 ad
220 1.1 ad /* Build synthetic geometry. */
221 1.1 ad if (ld->sc_secperunit <= 528 * 2048) /* 528MB */
222 1.1 ad ld->sc_nheads = 16;
223 1.1 ad else if (ld->sc_secperunit <= 1024 * 2048) /* 1GB */
224 1.1 ad ld->sc_nheads = 32;
225 1.1 ad else if (ld->sc_secperunit <= 21504 * 2048) /* 21GB */
226 1.1 ad ld->sc_nheads = 64;
227 1.1 ad else if (ld->sc_secperunit <= 43008 * 2048) /* 42GB */
228 1.1 ad ld->sc_nheads = 128;
229 1.1 ad else
230 1.1 ad ld->sc_nheads = 255;
231 1.2 ad
232 1.1 ad ld->sc_nsectors = 63;
233 1.1 ad ld->sc_ncylinders = ld->sc_secperunit /
234 1.1 ad (ld->sc_nheads * ld->sc_nsectors);
235 1.1 ad
236 1.1 ad switch (param.p.bdi.type) {
237 1.1 ad case I2O_RBS_TYPE_DIRECT:
238 1.1 ad typestr = "direct access";
239 1.2 ad enable = 1;
240 1.1 ad break;
241 1.1 ad case I2O_RBS_TYPE_WORM:
242 1.1 ad typestr = "WORM";
243 1.2 ad enable = 0;
244 1.1 ad break;
245 1.1 ad case I2O_RBS_TYPE_CDROM:
246 1.1 ad typestr = "cdrom";
247 1.2 ad enable = 0;
248 1.1 ad break;
249 1.1 ad case I2O_RBS_TYPE_OPTICAL:
250 1.1 ad typestr = "optical";
251 1.2 ad enable = 0;
252 1.1 ad break;
253 1.1 ad default:
254 1.1 ad typestr = "unknown";
255 1.2 ad enable = 0;
256 1.1 ad break;
257 1.1 ad }
258 1.1 ad
259 1.1 ad if ((le32toh(param.p.bdi.capabilities) & I2O_RBS_CAP_REMOVEABLE_MEDIA)
260 1.1 ad != 0) {
261 1.2 ad /* ld->sc_flags = LDF_REMOVEABLE; */
262 1.1 ad fixedstr = "removeable";
263 1.2 ad enable = 0;
264 1.2 ad } else
265 1.1 ad fixedstr = "fixed";
266 1.2 ad
267 1.2 ad printf("%s, %s", typestr, fixedstr);
268 1.1 ad
269 1.1 ad /*
270 1.1 ad * Determine if the device has an private cache. If so, print the
271 1.1 ad * cache size. Even if the device doesn't appear to have a cache,
272 1.1 ad * we perform a flush at shutdown, as it is still valid to do so.
273 1.1 ad */
274 1.2 ad rv = iop_param_op(iop, ia->ia_tid, 0, I2O_PARAM_RBS_CACHE_CONTROL,
275 1.1 ad ¶m, sizeof(param));
276 1.1 ad if (rv != 0) {
277 1.2 ad printf("%s: unable to get parameters (0x%04x; %d)\n",
278 1.2 ad ld->sc_dv.dv_xname, I2O_PARAM_RBS_CACHE_CONTROL, rv);
279 1.1 ad goto bad;
280 1.1 ad }
281 1.1 ad
282 1.1 ad if ((cachesz = le32toh(param.p.cc.totalcachesize)) != 0)
283 1.1 ad printf(", %dkB cache", cachesz >> 10);
284 1.1 ad
285 1.2 ad printf("\n");
286 1.2 ad
287 1.2 ad /*
288 1.2 ad * Configure the DDM's timeout functions to time out all commands
289 1.2 ad * after 10 seconds.
290 1.2 ad */
291 1.2 ad rv = iop_param_op(iop, ia->ia_tid, 0, I2O_PARAM_RBS_OPERATION,
292 1.2 ad ¶m, sizeof(param));
293 1.2 ad if (rv != 0) {
294 1.2 ad printf("%s: unable to get parameters (0x%04x; %d)\n",
295 1.2 ad ld->sc_dv.dv_xname, I2O_PARAM_RBS_OPERATION, rv);
296 1.2 ad goto bad;
297 1.2 ad }
298 1.2 ad
299 1.2 ad param.p.op.timeoutbase = htole32(LD_IOP_TIMEOUT);
300 1.2 ad param.p.op.rwvtimeoutbase = htole32(LD_IOP_TIMEOUT);
301 1.2 ad param.p.op.rwvtimeout = 0;
302 1.2 ad
303 1.2 ad rv = iop_param_op(iop, ia->ia_tid, 1, I2O_PARAM_RBS_OPERATION,
304 1.2 ad ¶m, sizeof(param));
305 1.2 ad if (rv != 0) {
306 1.2 ad printf("%s: unable to set parameters (0x%04x; %d)\n",
307 1.2 ad ld->sc_dv.dv_xname, I2O_PARAM_RBS_OPERATION, rv);
308 1.2 ad goto bad;
309 1.2 ad }
310 1.2 ad
311 1.2 ad if (enable)
312 1.2 ad ld->sc_flags |= LDF_ENABLED;
313 1.2 ad else
314 1.2 ad printf("%s: device not yet supported\n", self->dv_xname);
315 1.2 ad
316 1.1 ad ldattach(ld);
317 1.1 ad return;
318 1.1 ad
319 1.1 ad bad:
320 1.2 ad if (sc->sc_claimed)
321 1.2 ad iop_util_claim(iop, &sc->sc_ii, 1,
322 1.2 ad I2O_UTIL_CLAIM_PRIMARY_USER);
323 1.2 ad if (evreg)
324 1.2 ad iop_util_eventreg(iop, &sc->sc_eventii, 0);
325 1.2 ad if (sc->sc_eventii.ii_intr != NULL)
326 1.2 ad iop_initiator_unregister(iop, &sc->sc_eventii);
327 1.1 ad iop_initiator_unregister(iop, &sc->sc_ii);
328 1.1 ad }
329 1.1 ad
330 1.1 ad static int
331 1.2 ad ld_iop_detach(struct device *self, int flags)
332 1.2 ad {
333 1.2 ad struct ld_iop_softc *sc;
334 1.2 ad struct iop_softc *iop;
335 1.2 ad int s, rv;
336 1.2 ad
337 1.2 ad sc = (struct ld_iop_softc *)self;
338 1.2 ad
339 1.2 ad /* XXX */
340 1.2 ad if ((flags & DETACH_FORCE) == 0 && sc->sc_ld.sc_dk.dk_openmask != 0)
341 1.2 ad return (EBUSY);
342 1.2 ad s = splbio();
343 1.2 ad sc->sc_ld.sc_flags |= LDF_DRAIN;
344 1.2 ad splx(s);
345 1.2 ad
346 1.2 ad iop = (struct iop_softc *)self->dv_parent;
347 1.2 ad
348 1.2 ad /*
349 1.2 ad * Abort any requests queued with the IOP, but allow requests that
350 1.2 ad * are already in progress to complete.
351 1.2 ad */
352 1.2 ad if ((sc->sc_ld.sc_flags & LDF_ENABLED) != 0)
353 1.2 ad iop_util_abort(iop, &sc->sc_ii, 0, 0,
354 1.2 ad I2O_UTIL_ABORT_WILD | I2O_UTIL_ABORT_CLEAN);
355 1.2 ad
356 1.2 ad lddetach(&sc->sc_ld);
357 1.2 ad
358 1.2 ad /* Un-claim the target, and un-register us as an initiator. */
359 1.2 ad if ((sc->sc_ld.sc_flags & LDF_ENABLED) != 0) {
360 1.2 ad if (sc->sc_claimed) {
361 1.2 ad rv = iop_util_claim(iop, &sc->sc_ii, 1,
362 1.2 ad I2O_UTIL_CLAIM_PRIMARY_USER);
363 1.2 ad if (rv != 0)
364 1.2 ad return (rv);
365 1.2 ad }
366 1.2 ad iop_util_eventreg(iop, &sc->sc_eventii, 0);
367 1.2 ad iop_initiator_unregister(iop, &sc->sc_eventii);
368 1.2 ad iop_initiator_unregister(iop, &sc->sc_ii);
369 1.2 ad }
370 1.2 ad
371 1.2 ad return (0);
372 1.2 ad }
373 1.2 ad
374 1.2 ad static int
375 1.1 ad ld_iop_start(struct ld_softc *ld, struct buf *bp)
376 1.1 ad {
377 1.1 ad struct iop_msg *im;
378 1.1 ad struct iop_softc *iop;
379 1.1 ad struct ld_iop_softc *sc;
380 1.1 ad struct i2o_rbs_block_read *mb;
381 1.1 ad int rv, flags, write;
382 1.1 ad u_int64_t ba;
383 1.1 ad
384 1.1 ad sc = (struct ld_iop_softc *)ld;
385 1.1 ad iop = (struct iop_softc *)ld->sc_dv.dv_parent;
386 1.1 ad
387 1.1 ad im = NULL;
388 1.1 ad if ((rv = iop_msg_alloc(iop, &sc->sc_ii, &im, IM_NOWAIT)) != 0)
389 1.1 ad goto bad;
390 1.1 ad im->im_dvcontext = bp;
391 1.1 ad
392 1.1 ad write = ((bp->b_flags & B_READ) == 0);
393 1.1 ad ba = (u_int64_t)bp->b_rawblkno * ld->sc_secsize;
394 1.1 ad
395 1.2 ad /*
396 1.2 ad * Write through the cache when performing synchronous writes. When
397 1.2 ad * performing a read, we don't request that the DDM cache the data,
398 1.2 ad * as there's little advantage to it.
399 1.2 ad */
400 1.1 ad if (write) {
401 1.2 ad if ((bp->b_flags & B_ASYNC) == 0)
402 1.1 ad flags = I2O_RBS_BLOCK_WRITE_CACHE_WT;
403 1.1 ad else
404 1.1 ad flags = I2O_RBS_BLOCK_WRITE_CACHE_WB;
405 1.2 ad } else
406 1.2 ad flags = 0;
407 1.1 ad
408 1.1 ad /*
409 1.1 ad * Fill the message frame. We can use the block_read structure for
410 1.1 ad * both reads and writes, as it's almost identical to the
411 1.1 ad * block_write structure.
412 1.1 ad */
413 1.1 ad mb = (struct i2o_rbs_block_read *)im->im_msg;
414 1.1 ad mb->msgflags = I2O_MSGFLAGS(i2o_rbs_block_read);
415 1.1 ad mb->msgfunc = I2O_MSGFUNC(sc->sc_tid,
416 1.1 ad write ? I2O_RBS_BLOCK_WRITE : I2O_RBS_BLOCK_READ);
417 1.1 ad mb->msgictx = sc->sc_ii.ii_ictx;
418 1.1 ad mb->msgtctx = im->im_tctx;
419 1.2 ad mb->flags = flags | (1 << 16); /* flags & time multiplier */
420 1.1 ad mb->datasize = bp->b_bcount;
421 1.1 ad mb->lowoffset = (u_int32_t)ba;
422 1.1 ad mb->highoffset = (u_int32_t)(ba >> 32);
423 1.1 ad
424 1.1 ad /* Map the data transfer. */
425 1.1 ad if ((rv = iop_msg_map(iop, im, bp->b_data, bp->b_bcount, write)) != 0)
426 1.1 ad goto bad;
427 1.1 ad
428 1.1 ad /* Enqueue the command. */
429 1.2 ad iop_msg_enqueue(iop, im, 0);
430 1.1 ad return (0);
431 1.1 ad
432 1.1 ad bad:
433 1.1 ad if (im != NULL)
434 1.1 ad iop_msg_free(iop, &sc->sc_ii, im);
435 1.1 ad return (rv);
436 1.1 ad }
437 1.1 ad
438 1.1 ad static int
439 1.1 ad ld_iop_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
440 1.1 ad {
441 1.1 ad struct iop_msg *im;
442 1.1 ad struct iop_softc *iop;
443 1.1 ad struct ld_iop_softc *sc;
444 1.1 ad struct i2o_rbs_block_write *mb;
445 1.1 ad int rv, bcount;
446 1.1 ad u_int64_t ba;
447 1.1 ad
448 1.1 ad sc = (struct ld_iop_softc *)ld;
449 1.1 ad iop = (struct iop_softc *)ld->sc_dv.dv_parent;
450 1.1 ad bcount = blkcnt * ld->sc_secsize;
451 1.1 ad ba = (u_int64_t)blkno * ld->sc_secsize;
452 1.1 ad
453 1.1 ad rv = iop_msg_alloc(iop, &sc->sc_ii, &im, IM_NOWAIT | IM_NOINTR);
454 1.1 ad if (rv != 0)
455 1.1 ad return (rv);
456 1.1 ad
457 1.1 ad mb = (struct i2o_rbs_block_write *)im->im_msg;
458 1.1 ad mb->msgflags = I2O_MSGFLAGS(i2o_rbs_block_write);
459 1.1 ad mb->msgfunc = I2O_MSGFUNC(sc->sc_tid, I2O_RBS_BLOCK_WRITE);
460 1.1 ad mb->msgictx = sc->sc_ii.ii_ictx;
461 1.1 ad mb->msgtctx = im->im_tctx;
462 1.2 ad mb->flags = I2O_RBS_BLOCK_WRITE_CACHE_WT | (1 << 16);
463 1.1 ad mb->datasize = bcount;
464 1.1 ad mb->lowoffset = (u_int32_t)ba;
465 1.1 ad mb->highoffset = (u_int32_t)(ba >> 32);
466 1.1 ad
467 1.1 ad if ((rv = iop_msg_map(iop, im, data, bcount, 1)) != 0) {
468 1.1 ad iop_msg_free(iop, &sc->sc_ii, im);
469 1.1 ad return (rv);
470 1.1 ad }
471 1.1 ad
472 1.2 ad rv = (iop_msg_send(iop, im, 5000) != 0 ? EIO : 0);
473 1.1 ad iop_msg_unmap(iop, im);
474 1.1 ad iop_msg_free(iop, &sc->sc_ii, im);
475 1.1 ad return (rv);
476 1.1 ad }
477 1.1 ad
478 1.1 ad static int
479 1.1 ad ld_iop_flush(struct ld_softc *ld)
480 1.1 ad {
481 1.1 ad struct iop_msg *im;
482 1.1 ad struct iop_softc *iop;
483 1.1 ad struct ld_iop_softc *sc;
484 1.1 ad struct i2o_rbs_cache_flush *mb;
485 1.1 ad int rv;
486 1.1 ad
487 1.1 ad sc = (struct ld_iop_softc *)ld;
488 1.1 ad iop = (struct iop_softc *)ld->sc_dv.dv_parent;
489 1.1 ad
490 1.1 ad rv = iop_msg_alloc(iop, &sc->sc_ii, &im, IM_NOWAIT | IM_NOINTR);
491 1.1 ad if (rv != 0)
492 1.1 ad return (rv);
493 1.1 ad
494 1.1 ad mb = (struct i2o_rbs_cache_flush *)im->im_msg;
495 1.1 ad mb->msgflags = I2O_MSGFLAGS(i2o_rbs_cache_flush);
496 1.1 ad mb->msgfunc = I2O_MSGFUNC(sc->sc_tid, I2O_RBS_CACHE_FLUSH);
497 1.1 ad mb->msgictx = sc->sc_ii.ii_ictx;
498 1.1 ad mb->msgtctx = im->im_tctx;
499 1.2 ad mb->flags = 1 << 16; /* time multiplier */
500 1.1 ad
501 1.1 ad rv = iop_msg_send(iop, im, 10000);
502 1.1 ad iop_msg_free(iop, &sc->sc_ii, im);
503 1.1 ad return (rv);
504 1.1 ad }
505 1.1 ad
506 1.1 ad void
507 1.1 ad ld_iop_intr(struct device *dv, struct iop_msg *im, void *reply)
508 1.1 ad {
509 1.1 ad struct i2o_rbs_reply *rb;
510 1.1 ad struct buf *bp;
511 1.1 ad struct ld_iop_softc *sc;
512 1.1 ad struct iop_softc *iop;
513 1.1 ad #ifdef I2OVERBOSE
514 1.1 ad int detail;
515 1.1 ad const char *errstr;
516 1.1 ad #endif
517 1.1 ad
518 1.1 ad rb = reply;
519 1.1 ad bp = im->im_dvcontext;
520 1.1 ad sc = (struct ld_iop_softc *)dv;
521 1.1 ad iop = (struct iop_softc *)dv->dv_parent;
522 1.1 ad
523 1.1 ad #ifdef I2OVERBOSE
524 1.1 ad if (rb->reqstatus != I2O_STATUS_SUCCESS) {
525 1.1 ad detail = le16toh(rb->detail);
526 1.1 ad if (detail > sizeof(ld_iop_errors) / sizeof(ld_iop_errors[0]))
527 1.1 ad errstr = "unknown error";
528 1.1 ad else
529 1.1 ad errstr = ld_iop_errors[detail];
530 1.1 ad printf("%s: %s\n", dv->dv_xname, errstr);
531 1.1 ad #else
532 1.1 ad if (rb->reqstatus != I2O_STATUS_SUCCESS) {
533 1.1 ad #endif
534 1.1 ad bp->b_flags |= B_ERROR;
535 1.1 ad bp->b_error = EIO;
536 1.1 ad #ifndef notyet
537 1.1 ad bp->b_resid = bp->b_bcount;
538 1.1 ad } else
539 1.1 ad bp->b_resid = 0;
540 1.1 ad #else
541 1.1 ad }
542 1.1 ad bp->b_resid = bp->b_bcount - le32toh(rb->transfercount);
543 1.1 ad #endif
544 1.1 ad
545 1.1 ad iop_msg_unmap(iop, im);
546 1.1 ad iop_msg_free(iop, &sc->sc_ii, im);
547 1.1 ad lddone(&sc->sc_ld, bp);
548 1.2 ad }
549 1.2 ad
550 1.2 ad static void
551 1.2 ad ld_iop_intr_event(struct device *dv, struct iop_msg *im, void *reply)
552 1.2 ad {
553 1.2 ad struct i2o_util_event_register_reply *rb;
554 1.2 ad struct iop_softc *sc;
555 1.2 ad u_int event;
556 1.2 ad
557 1.2 ad sc = (struct iop_softc *)dv;
558 1.2 ad rb = reply;
559 1.2 ad event = le32toh(rb->event);
560 1.2 ad
561 1.2 ad #ifndef I2ODEBUG
562 1.2 ad if (event == I2O_EVENT_GEN_EVENT_MASK_MODIFIED)
563 1.2 ad return;
564 1.2 ad #endif
565 1.2 ad
566 1.2 ad printf("%s: event 0x%08x received\n", dv->dv_xname, event);
567 1.1 ad }
568