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