ld_iop.c revision 1.29 1 1.29 simonb /* $NetBSD: ld_iop.c,v 1.29 2008/05/10 14:52:55 simonb Exp $ */
2 1.1 ad
3 1.1 ad /*-
4 1.6 ad * Copyright (c) 2000, 2001 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 *
19 1.1 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 ad * POSSIBILITY OF SUCH DAMAGE.
30 1.1 ad */
31 1.1 ad
32 1.1 ad /*
33 1.1 ad * I2O front-end for ld(4) driver, supporting random block storage class
34 1.2 ad * devices. Currently, this doesn't handle anything more complex than
35 1.2 ad * fixed direct-access devices.
36 1.1 ad */
37 1.10 lukem
38 1.10 lukem #include <sys/cdefs.h>
39 1.29 simonb __KERNEL_RCSID(0, "$NetBSD: ld_iop.c,v 1.29 2008/05/10 14:52:55 simonb Exp $");
40 1.1 ad
41 1.1 ad #include "rnd.h"
42 1.1 ad
43 1.1 ad #include <sys/param.h>
44 1.1 ad #include <sys/systm.h>
45 1.1 ad #include <sys/kernel.h>
46 1.1 ad #include <sys/device.h>
47 1.1 ad #include <sys/buf.h>
48 1.15 yamt #include <sys/bufq.h>
49 1.1 ad #include <sys/endian.h>
50 1.1 ad #include <sys/dkio.h>
51 1.1 ad #include <sys/disk.h>
52 1.1 ad #include <sys/proc.h>
53 1.1 ad #if NRND > 0
54 1.1 ad #include <sys/rnd.h>
55 1.1 ad #endif
56 1.1 ad
57 1.26 ad #include <sys/bus.h>
58 1.1 ad
59 1.1 ad #include <dev/ldvar.h>
60 1.1 ad
61 1.1 ad #include <dev/i2o/i2o.h>
62 1.6 ad #include <dev/i2o/iopio.h>
63 1.1 ad #include <dev/i2o/iopvar.h>
64 1.1 ad
65 1.6 ad #define LD_IOP_TIMEOUT 30*1000
66 1.6 ad
67 1.6 ad #define LD_IOP_CLAIMED 0x01
68 1.6 ad #define LD_IOP_NEW_EVTMASK 0x02
69 1.1 ad
70 1.1 ad struct ld_iop_softc {
71 1.1 ad struct ld_softc sc_ld;
72 1.1 ad struct iop_initiator sc_ii;
73 1.2 ad struct iop_initiator sc_eventii;
74 1.6 ad int sc_flags;
75 1.1 ad };
76 1.1 ad
77 1.6 ad static void ld_iop_adjqparam(struct device *, int);
78 1.1 ad static void ld_iop_attach(struct device *, struct device *, void *);
79 1.2 ad static int ld_iop_detach(struct device *, int);
80 1.1 ad static int ld_iop_dump(struct ld_softc *, void *, int, int);
81 1.1 ad static int ld_iop_flush(struct ld_softc *);
82 1.1 ad static void ld_iop_intr(struct device *, struct iop_msg *, void *);
83 1.2 ad static void ld_iop_intr_event(struct device *, struct iop_msg *, void *);
84 1.6 ad static int ld_iop_match(struct device *, struct cfdata *, void *);
85 1.1 ad static int ld_iop_start(struct ld_softc *, struct buf *);
86 1.6 ad static void ld_iop_unconfig(struct ld_iop_softc *, int);
87 1.1 ad
88 1.12 thorpej CFATTACH_DECL(ld_iop, sizeof(struct ld_iop_softc),
89 1.13 thorpej ld_iop_match, ld_iop_attach, ld_iop_detach, NULL);
90 1.1 ad
91 1.16 perry static const char * const ld_iop_errors[] = {
92 1.16 perry "success",
93 1.16 perry "media error",
94 1.6 ad "access error",
95 1.1 ad "device failure",
96 1.6 ad "device not ready",
97 1.1 ad "media not present",
98 1.6 ad "media locked",
99 1.1 ad "media failure",
100 1.6 ad "protocol failure",
101 1.6 ad "bus failure",
102 1.6 ad "access violation",
103 1.6 ad "media write protected",
104 1.1 ad "device reset",
105 1.6 ad "volume changed, waiting for acknowledgement",
106 1.6 ad "timeout",
107 1.1 ad };
108 1.1 ad
109 1.1 ad static int
110 1.23 christos ld_iop_match(struct device *parent, struct cfdata *match,
111 1.22 christos void *aux)
112 1.1 ad {
113 1.1 ad struct iop_attach_args *ia;
114 1.1 ad
115 1.1 ad ia = aux;
116 1.1 ad
117 1.3 ad return (ia->ia_class == I2O_CLASS_RANDOM_BLOCK_STORAGE);
118 1.1 ad }
119 1.1 ad
120 1.1 ad static void
121 1.1 ad ld_iop_attach(struct device *parent, struct device *self, void *aux)
122 1.1 ad {
123 1.1 ad struct iop_attach_args *ia;
124 1.1 ad struct ld_softc *ld;
125 1.1 ad struct ld_iop_softc *sc;
126 1.1 ad struct iop_softc *iop;
127 1.2 ad int rv, evreg, enable;
128 1.17 christos const char *typestr, *fixedstr;
129 1.1 ad u_int cachesz;
130 1.9 ad u_int32_t timeoutbase, rwvtimeoutbase, rwvtimeout;
131 1.1 ad struct {
132 1.1 ad struct i2o_param_op_results pr;
133 1.1 ad struct i2o_param_read_results prr;
134 1.1 ad union {
135 1.1 ad struct i2o_param_rbs_cache_control cc;
136 1.1 ad struct i2o_param_rbs_device_info bdi;
137 1.1 ad } p;
138 1.8 ad } __attribute__ ((__packed__)) param;
139 1.1 ad
140 1.20 thorpej sc = device_private(self);
141 1.1 ad ld = &sc->sc_ld;
142 1.20 thorpej iop = device_private(parent);
143 1.1 ad ia = (struct iop_attach_args *)aux;
144 1.2 ad evreg = 0;
145 1.1 ad
146 1.1 ad /* Register us as an initiator. */
147 1.1 ad sc->sc_ii.ii_dv = self;
148 1.1 ad sc->sc_ii.ii_intr = ld_iop_intr;
149 1.6 ad sc->sc_ii.ii_adjqparam = ld_iop_adjqparam;
150 1.1 ad sc->sc_ii.ii_flags = 0;
151 1.2 ad sc->sc_ii.ii_tid = ia->ia_tid;
152 1.6 ad iop_initiator_register(iop, &sc->sc_ii);
153 1.1 ad
154 1.2 ad /* Register another initiator to handle events from the device. */
155 1.2 ad sc->sc_eventii.ii_dv = self;
156 1.2 ad sc->sc_eventii.ii_intr = ld_iop_intr_event;
157 1.8 ad sc->sc_eventii.ii_flags = II_NOTCTX | II_UTILITY;
158 1.2 ad sc->sc_eventii.ii_tid = ia->ia_tid;
159 1.6 ad iop_initiator_register(iop, &sc->sc_eventii);
160 1.6 ad
161 1.6 ad rv = iop_util_eventreg(iop, &sc->sc_eventii,
162 1.16 perry I2O_EVENT_GEN_EVENT_MASK_MODIFIED |
163 1.6 ad I2O_EVENT_GEN_DEVICE_RESET |
164 1.6 ad I2O_EVENT_GEN_STATE_CHANGE |
165 1.6 ad I2O_EVENT_GEN_GENERAL_WARNING);
166 1.6 ad if (rv != 0) {
167 1.27 cegger aprint_error_dev(self, "unable to register for events");
168 1.2 ad goto bad;
169 1.2 ad }
170 1.2 ad evreg = 1;
171 1.2 ad
172 1.6 ad /*
173 1.6 ad * Start out with one queued command. The `iop' driver will adjust
174 1.6 ad * the queue parameters once we're up and running.
175 1.6 ad */
176 1.6 ad ld->sc_maxqueuecnt = 1;
177 1.6 ad
178 1.1 ad ld->sc_maxxfer = IOP_MAX_XFER;
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.6 ad printf(":");
185 1.6 ad iop_print_ident(iop, ia->ia_tid);
186 1.1 ad
187 1.2 ad /*
188 1.2 ad * Claim the device so that we don't get any nasty surprises. Allow
189 1.2 ad * failure.
190 1.2 ad */
191 1.6 ad rv = iop_util_claim(iop, &sc->sc_ii, 0,
192 1.1 ad I2O_UTIL_CLAIM_CAPACITY_SENSITIVE |
193 1.1 ad I2O_UTIL_CLAIM_NO_PEER_SERVICE |
194 1.1 ad I2O_UTIL_CLAIM_NO_MANAGEMENT_SERVICE |
195 1.1 ad I2O_UTIL_CLAIM_PRIMARY_USER);
196 1.6 ad sc->sc_flags = rv ? 0 : LD_IOP_CLAIMED;
197 1.1 ad
198 1.9 ad rv = iop_field_get_all(iop, ia->ia_tid, I2O_PARAM_RBS_DEVICE_INFO,
199 1.9 ad ¶m, sizeof(param), NULL);
200 1.9 ad if (rv != 0)
201 1.1 ad goto bad;
202 1.1 ad
203 1.1 ad ld->sc_secsize = le32toh(param.p.bdi.blocksize);
204 1.1 ad ld->sc_secperunit = (int)
205 1.1 ad (le64toh(param.p.bdi.capacity) / ld->sc_secsize);
206 1.1 ad
207 1.1 ad switch (param.p.bdi.type) {
208 1.1 ad case I2O_RBS_TYPE_DIRECT:
209 1.1 ad typestr = "direct access";
210 1.2 ad enable = 1;
211 1.1 ad break;
212 1.1 ad case I2O_RBS_TYPE_WORM:
213 1.1 ad typestr = "WORM";
214 1.2 ad enable = 0;
215 1.1 ad break;
216 1.1 ad case I2O_RBS_TYPE_CDROM:
217 1.6 ad typestr = "CD-ROM";
218 1.2 ad enable = 0;
219 1.1 ad break;
220 1.1 ad case I2O_RBS_TYPE_OPTICAL:
221 1.1 ad typestr = "optical";
222 1.2 ad enable = 0;
223 1.1 ad break;
224 1.1 ad default:
225 1.1 ad typestr = "unknown";
226 1.2 ad enable = 0;
227 1.1 ad break;
228 1.1 ad }
229 1.1 ad
230 1.14 wiz if ((le32toh(param.p.bdi.capabilities) & I2O_RBS_CAP_REMOVABLE_MEDIA)
231 1.1 ad != 0) {
232 1.14 wiz /* ld->sc_flags = LDF_REMOVABLE; */
233 1.14 wiz fixedstr = "removable";
234 1.2 ad enable = 0;
235 1.2 ad } else
236 1.1 ad fixedstr = "fixed";
237 1.2 ad
238 1.6 ad printf(" %s, %s", typestr, fixedstr);
239 1.1 ad
240 1.1 ad /*
241 1.1 ad * Determine if the device has an private cache. If so, print the
242 1.1 ad * cache size. Even if the device doesn't appear to have a cache,
243 1.6 ad * we perform a flush at shutdown.
244 1.1 ad */
245 1.9 ad rv = iop_field_get_all(iop, ia->ia_tid, I2O_PARAM_RBS_CACHE_CONTROL,
246 1.9 ad ¶m, sizeof(param), NULL);
247 1.9 ad if (rv != 0)
248 1.1 ad goto bad;
249 1.1 ad
250 1.1 ad if ((cachesz = le32toh(param.p.cc.totalcachesize)) != 0)
251 1.1 ad printf(", %dkB cache", cachesz >> 10);
252 1.1 ad
253 1.2 ad printf("\n");
254 1.2 ad
255 1.2 ad /*
256 1.2 ad * Configure the DDM's timeout functions to time out all commands
257 1.6 ad * after 30 seconds.
258 1.2 ad */
259 1.16 perry timeoutbase = htole32(LD_IOP_TIMEOUT * 1000);
260 1.16 perry rwvtimeoutbase = htole32(LD_IOP_TIMEOUT * 1000);
261 1.9 ad rwvtimeout = 0;
262 1.9 ad
263 1.9 ad iop_field_set(iop, ia->ia_tid, I2O_PARAM_RBS_OPERATION,
264 1.9 ad &timeoutbase, sizeof(timeoutbase),
265 1.9 ad I2O_PARAM_RBS_OPERATION_timeoutbase);
266 1.9 ad iop_field_set(iop, ia->ia_tid, I2O_PARAM_RBS_OPERATION,
267 1.9 ad &rwvtimeoutbase, sizeof(rwvtimeoutbase),
268 1.9 ad I2O_PARAM_RBS_OPERATION_rwvtimeoutbase);
269 1.9 ad iop_field_set(iop, ia->ia_tid, I2O_PARAM_RBS_OPERATION,
270 1.9 ad &rwvtimeout, sizeof(rwvtimeout),
271 1.9 ad I2O_PARAM_RBS_OPERATION_rwvtimeoutbase);
272 1.2 ad
273 1.2 ad if (enable)
274 1.2 ad ld->sc_flags |= LDF_ENABLED;
275 1.2 ad else
276 1.27 cegger aprint_error_dev(self, "device not yet supported\n");
277 1.2 ad
278 1.1 ad ldattach(ld);
279 1.1 ad return;
280 1.1 ad
281 1.6 ad bad:
282 1.6 ad ld_iop_unconfig(sc, evreg);
283 1.6 ad }
284 1.6 ad
285 1.6 ad static void
286 1.6 ad ld_iop_unconfig(struct ld_iop_softc *sc, int evreg)
287 1.6 ad {
288 1.6 ad struct iop_softc *iop;
289 1.6 ad
290 1.19 thorpej iop = (struct iop_softc *)device_parent(&sc->sc_ld.sc_dv);
291 1.6 ad
292 1.6 ad if ((sc->sc_flags & LD_IOP_CLAIMED) != 0)
293 1.2 ad iop_util_claim(iop, &sc->sc_ii, 1,
294 1.2 ad I2O_UTIL_CLAIM_PRIMARY_USER);
295 1.6 ad
296 1.6 ad if (evreg) {
297 1.6 ad /*
298 1.16 perry * Mask off events, and wait up to 5 seconds for a reply.
299 1.6 ad * Note that some adapters won't reply to this (XXX We
300 1.6 ad * should check the event capabilities).
301 1.6 ad */
302 1.24 ad mutex_spin_enter(&iop->sc_intrlock);
303 1.6 ad sc->sc_flags &= ~LD_IOP_NEW_EVTMASK;
304 1.24 ad mutex_spin_exit(&iop->sc_intrlock);
305 1.24 ad
306 1.6 ad iop_util_eventreg(iop, &sc->sc_eventii,
307 1.6 ad I2O_EVENT_GEN_EVENT_MASK_MODIFIED);
308 1.24 ad
309 1.24 ad mutex_spin_enter(&iop->sc_intrlock);
310 1.6 ad if ((sc->sc_flags & LD_IOP_NEW_EVTMASK) == 0)
311 1.24 ad cv_timedwait(&sc->sc_eventii.ii_cv,
312 1.24 ad &iop->sc_intrlock, hz * 5);
313 1.24 ad mutex_spin_exit(&iop->sc_intrlock);
314 1.6 ad }
315 1.6 ad
316 1.6 ad iop_initiator_unregister(iop, &sc->sc_eventii);
317 1.1 ad iop_initiator_unregister(iop, &sc->sc_ii);
318 1.1 ad }
319 1.1 ad
320 1.1 ad static int
321 1.2 ad ld_iop_detach(struct device *self, int flags)
322 1.2 ad {
323 1.2 ad struct ld_iop_softc *sc;
324 1.2 ad struct iop_softc *iop;
325 1.4 ad int rv;
326 1.2 ad
327 1.20 thorpej sc = device_private(self);
328 1.20 thorpej iop = device_private(device_parent(self));
329 1.2 ad
330 1.5 ad if ((rv = ldbegindetach(&sc->sc_ld, flags)) != 0)
331 1.4 ad return (rv);
332 1.2 ad
333 1.2 ad /*
334 1.2 ad * Abort any requests queued with the IOP, but allow requests that
335 1.2 ad * are already in progress to complete.
336 1.2 ad */
337 1.2 ad if ((sc->sc_ld.sc_flags & LDF_ENABLED) != 0)
338 1.2 ad iop_util_abort(iop, &sc->sc_ii, 0, 0,
339 1.2 ad I2O_UTIL_ABORT_WILD | I2O_UTIL_ABORT_CLEAN);
340 1.2 ad
341 1.5 ad ldenddetach(&sc->sc_ld);
342 1.2 ad
343 1.6 ad /* Un-claim the target, and un-register our initiators. */
344 1.6 ad if ((sc->sc_ld.sc_flags & LDF_ENABLED) != 0)
345 1.6 ad ld_iop_unconfig(sc, 1);
346 1.2 ad
347 1.2 ad return (0);
348 1.2 ad }
349 1.2 ad
350 1.2 ad static int
351 1.1 ad ld_iop_start(struct ld_softc *ld, struct buf *bp)
352 1.1 ad {
353 1.1 ad struct iop_msg *im;
354 1.1 ad struct iop_softc *iop;
355 1.1 ad struct ld_iop_softc *sc;
356 1.6 ad struct i2o_rbs_block_read *mf;
357 1.6 ad u_int rv, flags, write;
358 1.1 ad u_int64_t ba;
359 1.6 ad u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
360 1.1 ad
361 1.1 ad sc = (struct ld_iop_softc *)ld;
362 1.19 thorpej iop = (struct iop_softc *)device_parent(&ld->sc_dv);
363 1.1 ad
364 1.8 ad im = iop_msg_alloc(iop, 0);
365 1.1 ad im->im_dvcontext = bp;
366 1.1 ad
367 1.1 ad write = ((bp->b_flags & B_READ) == 0);
368 1.1 ad ba = (u_int64_t)bp->b_rawblkno * ld->sc_secsize;
369 1.1 ad
370 1.2 ad /*
371 1.2 ad * Write through the cache when performing synchronous writes. When
372 1.2 ad * performing a read, we don't request that the DDM cache the data,
373 1.2 ad * as there's little advantage to it.
374 1.2 ad */
375 1.1 ad if (write) {
376 1.2 ad if ((bp->b_flags & B_ASYNC) == 0)
377 1.1 ad flags = I2O_RBS_BLOCK_WRITE_CACHE_WT;
378 1.1 ad else
379 1.1 ad flags = I2O_RBS_BLOCK_WRITE_CACHE_WB;
380 1.2 ad } else
381 1.2 ad flags = 0;
382 1.1 ad
383 1.1 ad /*
384 1.1 ad * Fill the message frame. We can use the block_read structure for
385 1.1 ad * both reads and writes, as it's almost identical to the
386 1.1 ad * block_write structure.
387 1.1 ad */
388 1.6 ad mf = (struct i2o_rbs_block_read *)mb;
389 1.6 ad mf->msgflags = I2O_MSGFLAGS(i2o_rbs_block_read);
390 1.6 ad mf->msgfunc = I2O_MSGFUNC(sc->sc_ii.ii_tid,
391 1.1 ad write ? I2O_RBS_BLOCK_WRITE : I2O_RBS_BLOCK_READ);
392 1.6 ad mf->msgictx = sc->sc_ii.ii_ictx;
393 1.6 ad mf->msgtctx = im->im_tctx;
394 1.6 ad mf->flags = flags | (1 << 16); /* flags & time multiplier */
395 1.6 ad mf->datasize = bp->b_bcount;
396 1.6 ad mf->lowoffset = (u_int32_t)ba;
397 1.6 ad mf->highoffset = (u_int32_t)(ba >> 32);
398 1.6 ad
399 1.6 ad /* Map the data transfer and enqueue the command. */
400 1.6 ad rv = iop_msg_map_bio(iop, im, mb, bp->b_data, bp->b_bcount, write);
401 1.6 ad if (rv == 0) {
402 1.8 ad if ((rv = iop_post(iop, mb)) != 0) {
403 1.6 ad iop_msg_unmap(iop, im);
404 1.6 ad iop_msg_free(iop, im);
405 1.6 ad }
406 1.6 ad }
407 1.1 ad return (rv);
408 1.1 ad }
409 1.1 ad
410 1.1 ad static int
411 1.1 ad ld_iop_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
412 1.1 ad {
413 1.1 ad struct iop_msg *im;
414 1.1 ad struct iop_softc *iop;
415 1.1 ad struct ld_iop_softc *sc;
416 1.6 ad struct i2o_rbs_block_write *mf;
417 1.1 ad int rv, bcount;
418 1.1 ad u_int64_t ba;
419 1.6 ad u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
420 1.1 ad
421 1.1 ad sc = (struct ld_iop_softc *)ld;
422 1.19 thorpej iop = (struct iop_softc *)device_parent(&ld->sc_dv);
423 1.1 ad bcount = blkcnt * ld->sc_secsize;
424 1.1 ad ba = (u_int64_t)blkno * ld->sc_secsize;
425 1.8 ad im = iop_msg_alloc(iop, IM_POLL);
426 1.1 ad
427 1.6 ad mf = (struct i2o_rbs_block_write *)mb;
428 1.6 ad mf->msgflags = I2O_MSGFLAGS(i2o_rbs_block_write);
429 1.6 ad mf->msgfunc = I2O_MSGFUNC(sc->sc_ii.ii_tid, I2O_RBS_BLOCK_WRITE);
430 1.6 ad mf->msgictx = sc->sc_ii.ii_ictx;
431 1.6 ad mf->msgtctx = im->im_tctx;
432 1.6 ad mf->flags = I2O_RBS_BLOCK_WRITE_CACHE_WT | (1 << 16);
433 1.6 ad mf->datasize = bcount;
434 1.6 ad mf->lowoffset = (u_int32_t)ba;
435 1.6 ad mf->highoffset = (u_int32_t)(ba >> 32);
436 1.1 ad
437 1.8 ad if ((rv = iop_msg_map(iop, im, mb, data, bcount, 1, NULL)) != 0) {
438 1.6 ad iop_msg_free(iop, im);
439 1.1 ad return (rv);
440 1.1 ad }
441 1.1 ad
442 1.6 ad rv = iop_msg_post(iop, im, mb, LD_IOP_TIMEOUT * 2);
443 1.1 ad iop_msg_unmap(iop, im);
444 1.6 ad iop_msg_free(iop, im);
445 1.1 ad return (rv);
446 1.1 ad }
447 1.1 ad
448 1.1 ad static int
449 1.1 ad ld_iop_flush(struct ld_softc *ld)
450 1.1 ad {
451 1.1 ad struct iop_msg *im;
452 1.1 ad struct iop_softc *iop;
453 1.1 ad struct ld_iop_softc *sc;
454 1.6 ad struct i2o_rbs_cache_flush mf;
455 1.1 ad int rv;
456 1.1 ad
457 1.1 ad sc = (struct ld_iop_softc *)ld;
458 1.19 thorpej iop = (struct iop_softc *)device_parent(&ld->sc_dv);
459 1.8 ad im = iop_msg_alloc(iop, IM_WAIT);
460 1.1 ad
461 1.6 ad mf.msgflags = I2O_MSGFLAGS(i2o_rbs_cache_flush);
462 1.6 ad mf.msgfunc = I2O_MSGFUNC(sc->sc_ii.ii_tid, I2O_RBS_CACHE_FLUSH);
463 1.6 ad mf.msgictx = sc->sc_ii.ii_ictx;
464 1.6 ad mf.msgtctx = im->im_tctx;
465 1.6 ad mf.flags = 1 << 16; /* time multiplier */
466 1.1 ad
467 1.29 simonb /* Ancient disks will return an error here. */
468 1.6 ad rv = iop_msg_post(iop, im, &mf, LD_IOP_TIMEOUT * 2);
469 1.6 ad iop_msg_free(iop, im);
470 1.1 ad return (rv);
471 1.1 ad }
472 1.1 ad
473 1.1 ad void
474 1.1 ad ld_iop_intr(struct device *dv, struct iop_msg *im, void *reply)
475 1.1 ad {
476 1.1 ad struct i2o_rbs_reply *rb;
477 1.1 ad struct buf *bp;
478 1.1 ad struct ld_iop_softc *sc;
479 1.1 ad struct iop_softc *iop;
480 1.6 ad int err, detail;
481 1.1 ad const char *errstr;
482 1.1 ad
483 1.1 ad rb = reply;
484 1.1 ad bp = im->im_dvcontext;
485 1.1 ad sc = (struct ld_iop_softc *)dv;
486 1.19 thorpej iop = (struct iop_softc *)device_parent(dv);
487 1.1 ad
488 1.6 ad err = ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0);
489 1.6 ad
490 1.6 ad if (!err && rb->reqstatus != I2O_STATUS_SUCCESS) {
491 1.6 ad detail = le16toh(rb->detail);
492 1.21 christos if (detail >= __arraycount(ld_iop_errors))
493 1.6 ad errstr = "<unknown>";
494 1.1 ad else
495 1.1 ad errstr = ld_iop_errors[detail];
496 1.27 cegger aprint_error_dev(dv, "error 0x%04x: %s\n", detail, errstr);
497 1.6 ad err = 1;
498 1.6 ad }
499 1.6 ad
500 1.6 ad if (err) {
501 1.1 ad bp->b_error = EIO;
502 1.1 ad bp->b_resid = bp->b_bcount;
503 1.1 ad } else
504 1.6 ad bp->b_resid = bp->b_bcount - le32toh(rb->transfercount);
505 1.1 ad
506 1.1 ad iop_msg_unmap(iop, im);
507 1.6 ad iop_msg_free(iop, im);
508 1.1 ad lddone(&sc->sc_ld, bp);
509 1.2 ad }
510 1.2 ad
511 1.2 ad static void
512 1.23 christos ld_iop_intr_event(struct device *dv, struct iop_msg *im, void *reply)
513 1.2 ad {
514 1.2 ad struct i2o_util_event_register_reply *rb;
515 1.6 ad struct ld_iop_softc *sc;
516 1.24 ad struct iop_softc *iop;
517 1.2 ad u_int event;
518 1.2 ad
519 1.2 ad rb = reply;
520 1.6 ad
521 1.6 ad if ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0)
522 1.6 ad return;
523 1.6 ad
524 1.2 ad event = le32toh(rb->event);
525 1.6 ad sc = (struct ld_iop_softc *)dv;
526 1.2 ad
527 1.6 ad if (event == I2O_EVENT_GEN_EVENT_MASK_MODIFIED) {
528 1.24 ad iop = device_private(device_parent(dv));
529 1.24 ad mutex_spin_enter(&iop->sc_intrlock);
530 1.6 ad sc->sc_flags |= LD_IOP_NEW_EVTMASK;
531 1.24 ad cv_broadcast(&sc->sc_eventii.ii_cv);
532 1.24 ad mutex_spin_exit(&iop->sc_intrlock);
533 1.2 ad return;
534 1.6 ad }
535 1.2 ad
536 1.27 cegger printf("%s: event 0x%08x received\n", device_xname(dv), event);
537 1.6 ad }
538 1.6 ad
539 1.6 ad static void
540 1.6 ad ld_iop_adjqparam(struct device *dv, int mpi)
541 1.6 ad {
542 1.6 ad struct iop_softc *iop;
543 1.6 ad
544 1.6 ad /*
545 1.6 ad * AMI controllers seem to loose the plot if you hand off lots of
546 1.6 ad * queued commands.
547 1.6 ad */
548 1.19 thorpej iop = (struct iop_softc *)device_parent(dv);
549 1.6 ad if (le16toh(I2O_ORG_AMI) == iop->sc_status.orgid && mpi > 64)
550 1.6 ad mpi = 64;
551 1.6 ad
552 1.6 ad ldadjqparam((struct ld_softc *)dv, mpi);
553 1.1 ad }
554