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