iopsp.c revision 1.2.2.7 1 /* $NetBSD: iopsp.c,v 1.2.2.7 2001/03/27 15:31:52 bouyer Exp $ */
2
3 /*-
4 * Copyright (c) 2000, 2001 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 * Raw SCSI device support for I2O. IOPs present SCSI devices individually;
41 * we group them by controlling port.
42 */
43
44 #include "opt_i2o.h"
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/device.h>
50 #include <sys/queue.h>
51 #include <sys/proc.h>
52 #include <sys/buf.h>
53 #include <sys/endian.h>
54 #include <sys/malloc.h>
55 #include <sys/scsiio.h>
56 #include <sys/lock.h>
57
58 #include <machine/bswap.h>
59 #include <machine/bus.h>
60
61 #include <dev/scsipi/scsi_all.h>
62 #include <dev/scsipi/scsi_disk.h>
63 #include <dev/scsipi/scsipi_all.h>
64 #include <dev/scsipi/scsiconf.h>
65 #include <dev/scsipi/scsi_message.h>
66
67 #include <dev/i2o/i2o.h>
68 #include <dev/i2o/iopio.h>
69 #include <dev/i2o/iopvar.h>
70 #include <dev/i2o/iopspvar.h>
71
72 static void iopsp_adjqparam(struct device *, int);
73 static void iopsp_attach(struct device *, struct device *, void *);
74 static void iopsp_intr(struct device *, struct iop_msg *, void *);
75 static int iopsp_ioctl(struct scsipi_channel *, u_long,
76 caddr_t, int, struct proc *);
77 static int iopsp_match(struct device *, struct cfdata *, void *);
78 static int iopsp_rescan(struct iopsp_softc *);
79 static int iopsp_reconfig(struct device *);
80 static int iopsp_scsi_abort(struct iopsp_softc *, int, struct iop_msg *);
81 static void iopsp_scsipi_request(struct scsipi_channel *,
82 scsipi_adapter_req_t, void *);
83
84 struct cfattach iopsp_ca = {
85 sizeof(struct iopsp_softc), iopsp_match, iopsp_attach
86 };
87
88 /*
89 * Match a supported device.
90 */
91 static int
92 iopsp_match(struct device *parent, struct cfdata *match, void *aux)
93 {
94 struct iop_attach_args *ia;
95 struct {
96 struct i2o_param_op_results pr;
97 struct i2o_param_read_results prr;
98 struct i2o_param_hba_ctlr_info ci;
99 } __attribute__ ((__packed__)) param;
100
101 ia = aux;
102
103 if (ia->ia_class != I2O_CLASS_BUS_ADAPTER_PORT)
104 return (0);
105
106 if (iop_param_op((struct iop_softc *)parent, ia->ia_tid, NULL, 0,
107 I2O_PARAM_HBA_CTLR_INFO, ¶m, sizeof(param)) != 0)
108 return (0);
109
110 return (param.ci.bustype == I2O_HBA_BUS_SCSI ||
111 param.ci.bustype == I2O_HBA_BUS_FCA);
112 }
113
114 /*
115 * Attach a supported device.
116 */
117 static void
118 iopsp_attach(struct device *parent, struct device *self, void *aux)
119 {
120 struct iop_attach_args *ia;
121 struct iopsp_softc *sc;
122 struct iop_softc *iop;
123 struct {
124 struct i2o_param_op_results pr;
125 struct i2o_param_read_results prr;
126 union {
127 struct i2o_param_hba_ctlr_info ci;
128 struct i2o_param_hba_scsi_ctlr_info sci;
129 struct i2o_param_hba_scsi_port_info spi;
130 } p;
131 } __attribute__ ((__packed__)) param;
132 int fcal, rv;
133 #ifdef I2OVERBOSE
134 int size;
135 #endif
136
137 ia = (struct iop_attach_args *)aux;
138 sc = (struct iopsp_softc *)self;
139 iop = (struct iop_softc *)parent;
140
141 /* Register us as an initiator. */
142 sc->sc_ii.ii_dv = self;
143 sc->sc_ii.ii_intr = iopsp_intr;
144 sc->sc_ii.ii_flags = 0;
145 sc->sc_ii.ii_tid = ia->ia_tid;
146 sc->sc_ii.ii_reconfig = iopsp_reconfig;
147 sc->sc_ii.ii_adjqparam = iopsp_adjqparam;
148 iop_initiator_register(iop, &sc->sc_ii);
149
150 rv = iop_param_op(iop, ia->ia_tid, NULL, 0, I2O_PARAM_HBA_CTLR_INFO,
151 ¶m, sizeof(param));
152 if (rv != 0) {
153 printf("%s: unable to get parameters (0x%04x; %d)\n",
154 sc->sc_dv.dv_xname, I2O_PARAM_HBA_CTLR_INFO, rv);
155 goto bad;
156 }
157
158 fcal = (param.p.ci.bustype == I2O_HBA_BUS_FCA); /* XXX */
159
160 /*
161 * Say what the device is. If we can find out what the controling
162 * device is, say what that is too.
163 */
164 printf(": SCSI port");
165 iop_print_ident(iop, ia->ia_tid);
166 printf("\n");
167
168 rv = iop_param_op(iop, ia->ia_tid, NULL, 0,
169 I2O_PARAM_HBA_SCSI_CTLR_INFO, ¶m, sizeof(param));
170 if (rv != 0) {
171 printf("%s: unable to get parameters (0x%04x; %d)\n",
172 sc->sc_dv.dv_xname, I2O_PARAM_HBA_SCSI_CTLR_INFO, rv);
173 goto bad;
174 }
175
176 #ifdef I2OVERBOSE
177 printf("%s: %d-bit, max sync rate %dMHz, initiator ID %d\n",
178 sc->sc_dv.dv_xname, param.p.sci.maxdatawidth,
179 (u_int32_t)le64toh(param.p.sci.maxsyncrate) / 1000,
180 le32toh(param.p.sci.initiatorid));
181 #endif
182
183 sc->sc_adapter.adapt_dev = &sc->sc_dv;
184 sc->sc_adapter.adapt_nchannels = 1;
185 sc->sc_adapter.adapt_openings = 1;
186 sc->sc_adapter.adapt_max_periph = 1;
187 sc->sc_adapter.adapt_ioctl = iopsp_ioctl;
188 sc->sc_adapter.adapt_minphys = minphys;
189 sc->sc_adapter.adapt_request = iopsp_scsipi_request;
190
191 memset(&sc->sc_channel, 0, sizeof(sc->sc_channel));
192 sc->sc_channel.chan_adapter = &sc->sc_adapter;
193 sc->sc_channel.chan_bustype = &scsi_bustype;
194 sc->sc_channel.chan_channel = 0;
195 sc->sc_channel.chan_ntargets = fcal ?
196 IOPSP_MAX_FCAL_TARGET : param.p.sci.maxdatawidth;
197 sc->sc_channel.chan_nluns = IOPSP_MAX_LUN;
198 sc->sc_channel.chan_id = le32toh(param.p.sci.initiatorid);
199
200 #ifdef I2OVERBOSE
201 /*
202 * Allocate the target map. Currently used for informational
203 * purposes only.
204 */
205 size = sc->sc_channel.chan_ntargets * sizeof(struct iopsp_target);
206 sc->sc_targetmap = malloc(size, M_DEVBUF, M_NOWAIT);
207 memset(sc->sc_targetmap, 0, size);
208 #endif
209
210 /* Build the two maps, and attach to scsipi. */
211 if (iopsp_reconfig(self) != 0) {
212 printf("%s: configure failed\n", sc->sc_dv.dv_xname);
213 goto bad;
214 }
215 config_found(self, &sc->sc_channel, scsiprint);
216 return;
217
218 bad:
219 iop_initiator_unregister(iop, &sc->sc_ii);
220 }
221
222 /*
223 * Scan the LCT to determine which devices we control, and enter them into
224 * the maps.
225 */
226 static int
227 iopsp_reconfig(struct device *dv)
228 {
229 struct iopsp_softc *sc;
230 struct iop_softc *iop;
231 struct i2o_lct_entry *le;
232 struct scsipi_channel *sc_chan;
233 struct {
234 struct i2o_param_op_results pr;
235 struct i2o_param_read_results prr;
236 struct i2o_param_scsi_device_info sdi;
237 } __attribute__ ((__packed__)) param;
238 u_int tid, nent, i, targ, lun, size, s, rv, bptid;
239 u_short *tidmap;
240 #ifdef I2OVERBOSE
241 struct iopsp_target *it;
242 int syncrate;
243 #endif
244
245 sc = (struct iopsp_softc *)dv;
246 iop = (struct iop_softc *)sc->sc_dv.dv_parent;
247 sc_chan = &sc->sc_channel;
248
249 /* Anything to do? */
250 if (iop->sc_chgind == sc->sc_chgind)
251 return (0);
252
253 /*
254 * Allocate memory for the target/LUN -> TID map. Use zero to
255 * denote absent targets (zero is the TID of the I2O executive,
256 * and we never address that here).
257 */
258 size = sc_chan->chan_ntargets * (IOPSP_MAX_LUN) * sizeof(u_short);
259 if ((tidmap = malloc(size, M_DEVBUF, M_WAITOK)) == NULL)
260 return (ENOMEM);
261 memset(tidmap, 0, size);
262
263 #ifdef I2OVERBOSE
264 for (i = 0; i < sc_chan->chan_ntargets; i++)
265 sc->sc_targetmap[i].it_flags &= ~IT_PRESENT;
266 #endif
267
268 /*
269 * A quick hack to handle Intel's stacked bus port arrangement.
270 */
271 bptid = sc->sc_ii.ii_tid;
272 nent = iop->sc_nlctent;
273 for (le = iop->sc_lct->entry; nent != 0; nent--, le++)
274 if ((le16toh(le->classid) & 4095) ==
275 I2O_CLASS_BUS_ADAPTER_PORT &&
276 (le32toh(le->usertid) & 4095) == bptid) {
277 bptid = le32toh(le->localtid) & 4095;
278 break;
279 }
280
281 nent = iop->sc_nlctent;
282 for (i = 0, le = iop->sc_lct->entry; i < nent; i++, le++) {
283 if ((le16toh(le->classid) & 4095) != I2O_CLASS_SCSI_PERIPHERAL)
284 continue;
285 if (((le32toh(le->usertid) >> 12) & 4095) != bptid)
286 continue;
287 tid = le32toh(le->localtid) & 4095;
288
289 rv = iop_param_op(iop, tid, NULL, 0, I2O_PARAM_SCSI_DEVICE_INFO,
290 ¶m, sizeof(param));
291 if (rv != 0) {
292 printf("%s: unable to get parameters (0x%04x; %d)\n",
293 sc->sc_dv.dv_xname, I2O_PARAM_SCSI_DEVICE_INFO,
294 rv);
295 continue;
296 }
297 targ = le32toh(param.sdi.identifier);
298 lun = param.sdi.luninfo[1];
299 #if defined(DIAGNOSTIC) || defined(I2ODEBUG)
300 if (targ >= sc_chan->chan_ntargets ||
301 lun >= sc_chan->chan_nluns) {
302 printf("%s: target %d,%d (tid %d): bad target/LUN\n",
303 sc->sc_dv.dv_xname, targ, lun, tid);
304 continue;
305 }
306 #endif
307
308 #ifdef I2OVERBOSE
309 /*
310 * If we've already described this target, and nothing has
311 * changed, then don't describe it again.
312 */
313 it = &sc->sc_targetmap[targ];
314 it->it_flags |= IT_PRESENT;
315 syncrate = ((int)le64toh(param.sdi.negsyncrate) + 500) / 1000;
316 if (it->it_width == param.sdi.negdatawidth &&
317 it->it_offset == param.sdi.negoffset &&
318 it->it_syncrate == syncrate)
319 continue;
320
321 it->it_width = param.sdi.negdatawidth;
322 it->it_offset = param.sdi.negoffset;
323 it->it_syncrate = syncrate;
324
325 printf("%s: target %d (tid %d): %d-bit, ", sc->sc_dv.dv_xname,
326 targ, tid, it->it_width);
327 if (it->it_syncrate == 0)
328 printf("asynchronous\n");
329 else
330 printf("synchronous at %dMHz, offset 0x%x\n",
331 it->it_syncrate, it->it_offset);
332 #endif
333
334 /* Ignore the device if it's in use by somebody else. */
335 if ((le32toh(le->usertid) & 4095) != I2O_TID_NONE) {
336 #ifdef I2OVERBOSE
337 if (sc->sc_tidmap == NULL ||
338 IOPSP_TIDMAP(sc->sc_tidmap, targ, lun) !=
339 IOPSP_TID_INUSE)
340 printf("%s: target %d,%d (tid %d): in use by"
341 " tid %d\n", sc->sc_dv.dv_xname,
342 targ, lun, tid,
343 le32toh(le->usertid) & 4095);
344 #endif
345 IOPSP_TIDMAP(tidmap, targ, lun) = IOPSP_TID_INUSE;
346 } else
347 IOPSP_TIDMAP(tidmap, targ, lun) = (u_short)tid;
348 }
349
350 #ifdef I2OVERBOSE
351 for (i = 0; i < sc_chan->chan_ntargets; i++)
352 if ((sc->sc_targetmap[i].it_flags & IT_PRESENT) == 0)
353 sc->sc_targetmap[i].it_width = 0;
354 #endif
355
356 /* Swap in the new map and return. */
357 s = splbio();
358 if (sc->sc_tidmap != NULL)
359 free(sc->sc_tidmap, M_DEVBUF);
360 sc->sc_tidmap = tidmap;
361 splx(s);
362 sc->sc_chgind = iop->sc_chgind;
363 return (0);
364 }
365
366 /*
367 * Re-scan the bus; to be called from a higher level (e.g. scsipi).
368 */
369 static int
370 iopsp_rescan(struct iopsp_softc *sc)
371 {
372 struct iop_softc *iop;
373 struct iop_msg *im;
374 struct i2o_hba_bus_scan mf;
375 int rv;
376
377 iop = (struct iop_softc *)sc->sc_dv.dv_parent;
378
379 rv = lockmgr(&iop->sc_conflock, LK_EXCLUSIVE, NULL);
380 if (rv != 0) {
381 #ifdef I2ODEBUG
382 printf("iopsp_rescan: unable to acquire lock\n");
383 #endif
384 return (rv);
385 }
386
387 im = iop_msg_alloc(iop, &sc->sc_ii, IM_WAIT);
388
389 mf.msgflags = I2O_MSGFLAGS(i2o_hba_bus_scan);
390 mf.msgfunc = I2O_MSGFUNC(sc->sc_ii.ii_tid, I2O_HBA_BUS_SCAN);
391 mf.msgictx = sc->sc_ii.ii_ictx;
392 mf.msgtctx = im->im_tctx;
393
394 rv = iop_msg_post(iop, im, &mf, 5*60*1000);
395 iop_msg_free(iop, im);
396 if (rv != 0)
397 printf("%s: bus rescan failed (error %d)\n",
398 sc->sc_dv.dv_xname, rv);
399
400 if ((rv = iop_lct_get(iop)) != 0)
401 goto done;
402
403 /* Rebuild the target/LUN -> TID map, release lock, and return. */
404 rv = iopsp_reconfig(&sc->sc_dv);
405 done:
406 lockmgr(&iop->sc_conflock, LK_RELEASE, NULL);
407 return (rv);
408 }
409
410 /*
411 * Start a SCSI command.
412 */
413 static void
414 iopsp_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req,
415 void *arg)
416 {
417 struct scsipi_xfer *xs;
418 struct scsipi_periph *periph;
419 struct iopsp_softc *sc = (void *)chan->chan_adapter->adapt_dev;
420 struct iop_msg *im;
421 struct iop_softc *iop = (struct iop_softc *)sc->sc_dv.dv_parent;
422 struct i2o_scsi_scb_exec *mf;
423 int error, flags, tid, imf;
424 u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
425
426 switch (req) {
427 case ADAPTER_REQ_RUN_XFER:
428 xs = arg;
429 periph = xs->xs_periph;
430 flags = xs->xs_control;
431
432 tid = IOPSP_TIDMAP(sc->sc_tidmap, periph->periph_target,
433 periph->periph_lun);
434 if (tid == IOPSP_TID_ABSENT || tid == IOPSP_TID_INUSE) {
435 xs->error = XS_SELTIMEOUT;
436 scsipi_done(xs);
437 return;
438 }
439
440 SC_DEBUG(periph, SDEV_DB2, ("iopsp_scsi_request run_xfer\n"));
441
442 /* Need to reset the target? */
443 if ((flags & XS_CTL_RESET) != 0) {
444 if (iop_simple_cmd(iop, tid, I2O_SCSI_DEVICE_RESET,
445 sc->sc_ii.ii_ictx, 1, 10*1000) != 0) {
446 #ifdef I2ODEBUG
447 printf("%s: reset failed\n",
448 sc->sc_dv.dv_xname);
449 #endif
450 xs->error = XS_DRIVER_STUFFUP;
451 } else
452 xs->error = XS_NOERROR;
453
454 scsipi_done(xs);
455 return;
456 }
457
458 #if defined(I2ODEBUG) || defined(SCSIDEBUG)
459 if (xs->cmdlen > sizeof(mf->cdb))
460 panic("%s: CDB too large\n", sc->sc_dv.dv_xname);
461 #endif
462
463 imf = (flags & (XS_CTL_POLL | XS_CTL_NOSLEEP)) != 0 ?
464 IM_POLL : 0; im = iop_msg_alloc(iop, &sc->sc_ii, imf);
465 im->im_dvcontext = xs;
466
467 mf = (struct i2o_scsi_scb_exec *)mb;
468 mf->msgflags = I2O_MSGFLAGS(i2o_scsi_scb_exec);
469 mf->msgfunc = I2O_MSGFUNC(tid, I2O_SCSI_SCB_EXEC);
470 mf->msgictx = sc->sc_ii.ii_ictx;
471 mf->msgtctx = im->im_tctx;
472 mf->flags = xs->cmdlen | I2O_SCB_FLAG_ENABLE_DISCONNECT |
473 I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
474 mf->datalen = xs->datalen;
475 memcpy(mf->cdb, xs->cmd, xs->cmdlen);
476
477 switch(xs->xs_tag_type) {
478 case MSG_ORDERED_Q_TAG:
479 mf->flags |= I2O_SCB_FLAG_ORDERED_QUEUE_TAG;
480 break;
481 case MSG_SIMPLE_Q_TAG:
482 mf->flags |= I2O_SCB_FLAG_SIMPLE_QUEUE_TAG;
483 break;
484 case MSG_HEAD_OF_Q_TAG:
485 mf->flags |= I2O_SCB_FLAG_HEAD_QUEUE_TAG;
486 break;
487 default:
488 break;
489 }
490 if (xs->datalen != 0) {
491 error = iop_msg_map_bio(iop, im, mb, xs->data,
492 xs->datalen, (flags & XS_CTL_DATA_OUT) == 0);
493 if (error) {
494 #ifdef I2ODEBUG
495 printf("%s: error %d mapping xfer\n",
496 sc->sc_dv.dv_xname, error);
497 #endif
498 xs->error = XS_DRIVER_STUFFUP;
499 iop_msg_free(iop, im);
500 scsipi_done(xs);
501 return;
502 }
503 if ((flags & XS_CTL_DATA_IN) == 0)
504 mf->flags |= I2O_SCB_FLAG_XFER_TO_DEVICE;
505 else
506 mf->flags |= I2O_SCB_FLAG_XFER_FROM_DEVICE;
507 }
508
509 /*
510 * If the command is allowed to execute asynchronously,
511 * enqueue it with the IOP.
512 */
513 if ((flags & XS_CTL_POLL) == 0) {
514 if (iop_msg_post(iop, im, mb, 0)) {
515 if (xs->datalen != 0)
516 iop_msg_unmap(iop, im);
517 iop_msg_free(iop, im);
518 xs->error = XS_DRIVER_STUFFUP;
519 scsipi_done(xs);
520 }
521 return;
522 }
523
524 if (iop_msg_post(iop, im, mb, xs->timeout)) {
525 scsipi_printaddr(xs->xs_periph);
526 printf("timeout; aborting command\n");
527 if (iopsp_scsi_abort(sc, tid, im)) {
528 scsipi_printaddr(xs->xs_periph);
529 printf("abort failed\n");
530 }
531 xs->error = XS_TIMEOUT;
532 }
533 scsipi_done(xs);
534 return;
535 case ADAPTER_REQ_GROW_RESOURCES:
536 /* XXX Not supported. */
537 return;
538 case ADAPTER_REQ_SET_XFER_MODE:
539 /* XXX Not supported. */
540 return;
541 }
542 }
543
544 /*
545 * Abort the specified I2O_SCSI_SCB_EXEC message and its associated SCB.
546 */
547 static int
548 iopsp_scsi_abort(struct iopsp_softc *sc, int atid, struct iop_msg *aim)
549 {
550 struct iop_msg *im;
551 struct i2o_scsi_scb_abort mf;
552 struct iop_softc *iop;
553 int rv, s;
554
555 iop = (struct iop_softc *)sc->sc_dv.dv_parent;
556 im = iop_msg_alloc(iop, &sc->sc_ii, IM_POLL);
557
558 mf.msgflags = I2O_MSGFLAGS(i2o_scsi_scb_abort);
559 mf.msgfunc = I2O_MSGFUNC(atid, I2O_SCSI_SCB_ABORT);
560 mf.msgictx = sc->sc_ii.ii_ictx;
561 mf.msgtctx = im->im_tctx;
562 mf.tctxabort = aim->im_tctx;
563
564 s = splbio();
565 rv = iop_msg_post(iop, im, &mf, 30000);
566 splx(s);
567 iop_msg_free(iop, im);
568 return (rv);
569 }
570
571 /*
572 * We have a message which has been processed and replied to by the IOP -
573 * deal with it.
574 */
575 static void
576 iopsp_intr(struct device *dv, struct iop_msg *im, void *reply)
577 {
578 struct scsipi_xfer *xs;
579 struct iopsp_softc *sc;
580 struct i2o_scsi_reply *rb;
581 struct iop_softc *iop;
582 u_int sl;
583
584 sc = (struct iopsp_softc *)dv;
585 xs = (struct scsipi_xfer *)im->im_dvcontext;
586 iop = (struct iop_softc *)dv->dv_parent;
587
588 SC_DEBUG(xs->xs_periph, SDEV_DB2, ("iopsp_intr\n"));
589
590 if ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0) {
591 xs->error = XS_DRIVER_STUFFUP;
592 xs->resid = xs->datalen;
593 } else {
594 rb = reply;
595
596 if (rb->hbastatus != I2O_SCSI_DSC_SUCCESS) {
597 switch (rb->hbastatus) {
598 case I2O_SCSI_DSC_ADAPTER_BUSY:
599 case I2O_SCSI_DSC_SCSI_BUS_RESET:
600 case I2O_SCSI_DSC_BUS_BUSY:
601 xs->error = XS_BUSY;
602 break;
603 case I2O_SCSI_DSC_SELECTION_TIMEOUT:
604 xs->error = XS_SELTIMEOUT;
605 break;
606 case I2O_SCSI_DSC_COMMAND_TIMEOUT:
607 case I2O_SCSI_DSC_DEVICE_NOT_PRESENT:
608 case I2O_SCSI_DSC_LUN_INVALID:
609 case I2O_SCSI_DSC_SCSI_TID_INVALID:
610 xs->error = XS_TIMEOUT;
611 break;
612 default:
613 xs->error = XS_DRIVER_STUFFUP;
614 break;
615 }
616 printf("%s: HBA status 0x%02x\n", sc->sc_dv.dv_xname,
617 rb->hbastatus);
618 } else if (rb->scsistatus != SCSI_OK) {
619 switch (rb->scsistatus) {
620 case SCSI_CHECK:
621 xs->error = XS_SENSE;
622 sl = le32toh(rb->senselen);
623 if (sl > sizeof(xs->sense.scsi_sense))
624 sl = sizeof(xs->sense.scsi_sense);
625 memcpy(&xs->sense.scsi_sense, rb->sense, sl);
626 break;
627 case SCSI_QUEUE_FULL:
628 case SCSI_BUSY:
629 xs->error = XS_BUSY;
630 break;
631 default:
632 xs->error = XS_DRIVER_STUFFUP;
633 break;
634 }
635 } else
636 xs->error = XS_NOERROR;
637
638 xs->resid = xs->datalen - le32toh(rb->datalen);
639 xs->status = rb->scsistatus;
640 }
641
642 /* Free the message wrapper and pass the news to scsipi. */
643 if (xs->datalen != 0)
644 iop_msg_unmap(iop, im);
645 iop_msg_free(iop, im);
646 scsipi_done(xs);
647 }
648
649 /*
650 * ioctl hook; used here only to initiate low-level rescans.
651 */
652 static int
653 iopsp_ioctl(struct scsipi_channel *chan, u_long cmd, caddr_t data, int flag,
654 struct proc *p)
655 {
656 int rv;
657
658 switch (cmd) {
659 case SCBUSIOLLSCAN:
660 rv = iopsp_rescan(
661 (struct iopsp_softc *)chan->chan_adapter->adapt_dev);
662 /*
663 * If it's boot time, the bus will have been scanned and the
664 * maps built. Locking would stop re-configuration, but we
665 * want to fake success.
666 */
667 if (p != &proc0)
668 rv = iopsp_rescan(
669 (struct iopsp_softc *)chan->chan_adapter->adapt_dev);
670 else
671 rv = 0;
672 break;
673
674 default:
675 rv = ENOTTY;
676 break;
677 }
678
679 return (rv);
680 }
681
682 /*
683 * The number of openings available to us has changed, so inform scsipi.
684 */
685 static void
686 iopsp_adjqparam(struct device *dv, int mpi)
687 {
688 int s;
689
690 /* XXX */
691 s = splbio();
692 ((struct iopsp_softc *)dv)->sc_adapter.adapt_openings = mpi;
693 splx(s);
694 }
695