Home | History | Annotate | Line # | Download | only in i2o
iopsp.c revision 1.26
      1 /*	$NetBSD: iopsp.c,v 1.26 2007/02/15 15:40:51 ad 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.26 2007/02/15 15:40:51 ad 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 
     60 #include <sys/bswap.h>
     61 #include <machine/bus.h>
     62 
     63 #include <dev/scsipi/scsi_all.h>
     64 #include <dev/scsipi/scsi_disk.h>
     65 #include <dev/scsipi/scsipi_all.h>
     66 #include <dev/scsipi/scsiconf.h>
     67 #include <dev/scsipi/scsi_message.h>
     68 
     69 #include <dev/i2o/i2o.h>
     70 #include <dev/i2o/iopio.h>
     71 #include <dev/i2o/iopvar.h>
     72 #include <dev/i2o/iopspvar.h>
     73 
     74 static void	iopsp_adjqparam(struct device *, int);
     75 static void	iopsp_attach(struct device *, struct device *, void *);
     76 static void	iopsp_intr(struct device *, struct iop_msg *, void *);
     77 static int	iopsp_ioctl(struct scsipi_channel *, u_long,
     78 			    caddr_t, int, struct proc *);
     79 static int	iopsp_match(struct device *, struct cfdata *, void *);
     80 static int	iopsp_rescan(struct iopsp_softc *);
     81 static int	iopsp_reconfig(struct device *);
     82 static void	iopsp_scsipi_request(struct scsipi_channel *,
     83 				     scsipi_adapter_req_t, void *);
     84 
     85 CFATTACH_DECL(iopsp, sizeof(struct iopsp_softc),
     86     iopsp_match, iopsp_attach, NULL, NULL);
     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_field_get_all((struct iop_softc *)parent, ia->ia_tid,
    107 	    I2O_PARAM_HBA_CTLR_INFO, &param, sizeof(param), NULL) != 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 fc, rv;
    133 #ifdef I2OVERBOSE
    134 	int size;
    135 #endif
    136 
    137 	ia = (struct iop_attach_args *)aux;
    138 	sc = device_private(self);
    139 	iop = device_private(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_field_get_all(iop, ia->ia_tid, I2O_PARAM_HBA_CTLR_INFO,
    151 	    &param, sizeof(param), NULL);
    152 	if (rv != 0)
    153 		goto bad;
    154 
    155 	fc = (param.p.ci.bustype == I2O_HBA_BUS_FCA);
    156 
    157 	/*
    158 	 * Say what the device is.  If we can find out what the controling
    159 	 * device is, say what that is too.
    160 	 */
    161 	printf(": SCSI port");
    162 	iop_print_ident(iop, ia->ia_tid);
    163 	printf("\n");
    164 
    165 	rv = iop_field_get_all(iop, ia->ia_tid, I2O_PARAM_HBA_SCSI_CTLR_INFO,
    166 	    &param, sizeof(param), NULL);
    167 	if (rv != 0)
    168 		goto bad;
    169 
    170 #ifdef I2OVERBOSE
    171 	printf("%s: ", sc->sc_dv.dv_xname);
    172 	if (fc)
    173 		printf("FC");
    174 	else
    175 		printf("%d-bit", param.p.sci.maxdatawidth);
    176 	printf(", max sync rate %dMHz, initiator ID %d\n",
    177 	    (u_int32_t)le64toh(param.p.sci.maxsyncrate) / 1000,
    178 	    le32toh(param.p.sci.initiatorid));
    179 #endif
    180 
    181 	sc->sc_openings = 1;
    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 *)device_parent(&sc->sc_dv);
    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 		    &param, 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 			it->it_width = param.sdi.negdatawidth;
    315 			it->it_offset = param.sdi.negoffset;
    316 			it->it_syncrate = syncrate;
    317 
    318 			printf("%s: target %d (tid %d): %d-bit, ",
    319 			    sc->sc_dv.dv_xname, targ, tid, it->it_width);
    320 			if (it->it_syncrate == 0)
    321 				printf("asynchronous\n");
    322 			else
    323 				printf("synchronous at %dMHz, offset 0x%x\n",
    324 				    it->it_syncrate, it->it_offset);
    325 		}
    326 #endif
    327 
    328 		/* Ignore the device if it's in use by somebody else. */
    329 		if ((le32toh(le->usertid) & 4095) != I2O_TID_NONE) {
    330 #ifdef I2OVERBOSE
    331 			if (sc->sc_tidmap == NULL ||
    332 			    IOPSP_TIDMAP(sc->sc_tidmap, targ, lun) !=
    333 			    IOPSP_TID_INUSE)
    334 				printf("%s: target %d,%d (tid %d): in use by"
    335 				    " tid %d\n", sc->sc_dv.dv_xname,
    336 				    targ, lun, tid,
    337 				    le32toh(le->usertid) & 4095);
    338 #endif
    339 			IOPSP_TIDMAP(tidmap, targ, lun) = IOPSP_TID_INUSE;
    340 		} else
    341 			IOPSP_TIDMAP(tidmap, targ, lun) = (u_short)tid;
    342 	}
    343 
    344 #ifdef I2OVERBOSE
    345 	for (i = 0; i < sc_chan->chan_ntargets; i++)
    346 		if ((sc->sc_targetmap[i].it_flags & IT_PRESENT) == 0)
    347 			sc->sc_targetmap[i].it_width = 0;
    348 #endif
    349 
    350 	/* Swap in the new map and return. */
    351 	s = splbio();
    352 	if (sc->sc_tidmap != NULL)
    353 		free(sc->sc_tidmap, M_DEVBUF);
    354 	sc->sc_tidmap = tidmap;
    355 	splx(s);
    356 	sc->sc_chgind = iop->sc_chgind;
    357 	return (0);
    358 }
    359 
    360 /*
    361  * Re-scan the bus; to be called from a higher level (e.g. scsipi).
    362  */
    363 static int
    364 iopsp_rescan(struct iopsp_softc *sc)
    365 {
    366 	struct iop_softc *iop;
    367 	struct iop_msg *im;
    368 	struct i2o_hba_bus_scan mf;
    369 	int rv;
    370 
    371 	iop = (struct iop_softc *)device_parent(&sc->sc_dv);
    372 
    373 	mutex_enter(&iop->sc_conflock);
    374 	im = iop_msg_alloc(iop, IM_WAIT);
    375 
    376 	mf.msgflags = I2O_MSGFLAGS(i2o_hba_bus_scan);
    377 	mf.msgfunc = I2O_MSGFUNC(sc->sc_ii.ii_tid, I2O_HBA_BUS_SCAN);
    378 	mf.msgictx = sc->sc_ii.ii_ictx;
    379 	mf.msgtctx = im->im_tctx;
    380 
    381 	rv = iop_msg_post(iop, im, &mf, 5*60*1000);
    382 	iop_msg_free(iop, im);
    383 	if (rv != 0)
    384 		printf("%s: bus rescan failed (error %d)\n",
    385 		    sc->sc_dv.dv_xname, rv);
    386 
    387 	if ((rv = iop_lct_get(iop)) == 0)
    388 		rv = iopsp_reconfig(&sc->sc_dv);
    389 
    390 	mutex_exit(&iop->sc_conflock);
    391 	return (rv);
    392 }
    393 
    394 /*
    395  * Start a SCSI command.
    396  */
    397 static void
    398 iopsp_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req,
    399 		     void *arg)
    400 {
    401 	struct scsipi_xfer *xs;
    402 	struct scsipi_periph *periph;
    403 	struct iopsp_softc *sc;
    404 	struct iop_msg *im;
    405 	struct iop_softc *iop;
    406 	struct i2o_scsi_scb_exec *mf;
    407 	int error, flags, tid;
    408 	u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
    409 
    410 	sc = (void *)chan->chan_adapter->adapt_dev;
    411 	iop = (struct iop_softc *)device_parent(&sc->sc_dv);
    412 
    413 	switch (req) {
    414 	case ADAPTER_REQ_RUN_XFER:
    415 		xs = arg;
    416 		periph = xs->xs_periph;
    417 		flags = xs->xs_control;
    418 
    419 		SC_DEBUG(periph, SCSIPI_DB2, ("iopsp_scsi_request run_xfer\n"));
    420 
    421 		tid = IOPSP_TIDMAP(sc->sc_tidmap, periph->periph_target,
    422 		    periph->periph_lun);
    423 		if (tid == IOPSP_TID_ABSENT || tid == IOPSP_TID_INUSE) {
    424 			xs->error = XS_SELTIMEOUT;
    425 			scsipi_done(xs);
    426 			return;
    427 		}
    428 
    429 		/* Need to reset the target? */
    430 		if ((flags & XS_CTL_RESET) != 0) {
    431 			if (iop_simple_cmd(iop, tid, I2O_SCSI_DEVICE_RESET,
    432 			    sc->sc_ii.ii_ictx, 1, 30*1000) != 0) {
    433 #ifdef I2ODEBUG
    434 				printf("%s: reset failed\n",
    435 				    sc->sc_dv.dv_xname);
    436 #endif
    437 				xs->error = XS_DRIVER_STUFFUP;
    438 			} else
    439 				xs->error = XS_NOERROR;
    440 
    441 			scsipi_done(xs);
    442 			return;
    443 		}
    444 
    445 #if defined(I2ODEBUG) || defined(SCSIDEBUG)
    446 		if (xs->cmdlen > sizeof(mf->cdb))
    447 			panic("%s: CDB too large", sc->sc_dv.dv_xname);
    448 #endif
    449 
    450 		im = iop_msg_alloc(iop, IM_POLL_INTR |
    451 		    IM_NOSTATUS | ((flags & XS_CTL_POLL) != 0 ? IM_POLL : 0));
    452 		im->im_dvcontext = xs;
    453 
    454 		mf = (struct i2o_scsi_scb_exec *)mb;
    455 		mf->msgflags = I2O_MSGFLAGS(i2o_scsi_scb_exec);
    456 		mf->msgfunc = I2O_MSGFUNC(tid, I2O_SCSI_SCB_EXEC);
    457 		mf->msgictx = sc->sc_ii.ii_ictx;
    458 		mf->msgtctx = im->im_tctx;
    459 		mf->flags = xs->cmdlen | I2O_SCB_FLAG_ENABLE_DISCONNECT |
    460 		    I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
    461 		mf->datalen = xs->datalen;
    462 		memcpy(mf->cdb, xs->cmd, xs->cmdlen);
    463 
    464 		switch (xs->xs_tag_type) {
    465 		case MSG_ORDERED_Q_TAG:
    466 			mf->flags |= I2O_SCB_FLAG_ORDERED_QUEUE_TAG;
    467 			break;
    468 		case MSG_SIMPLE_Q_TAG:
    469 			mf->flags |= I2O_SCB_FLAG_SIMPLE_QUEUE_TAG;
    470 			break;
    471 		case MSG_HEAD_OF_Q_TAG:
    472 			mf->flags |= I2O_SCB_FLAG_HEAD_QUEUE_TAG;
    473 			break;
    474 		default:
    475 			break;
    476 		}
    477 
    478 		if (xs->datalen != 0) {
    479 			error = iop_msg_map_bio(iop, im, mb, xs->data,
    480 			    xs->datalen, (flags & XS_CTL_DATA_OUT) == 0);
    481 			if (error) {
    482 				xs->error = XS_DRIVER_STUFFUP;
    483 				iop_msg_free(iop, im);
    484 				scsipi_done(xs);
    485 				return;
    486 			}
    487 			if ((flags & XS_CTL_DATA_IN) == 0)
    488 				mf->flags |= I2O_SCB_FLAG_XFER_TO_DEVICE;
    489 			else
    490 				mf->flags |= I2O_SCB_FLAG_XFER_FROM_DEVICE;
    491 		}
    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 		}
    500 		break;
    501 
    502 	case ADAPTER_REQ_GROW_RESOURCES:
    503 		/*
    504 		 * Not supported.
    505 		 */
    506 		break;
    507 
    508 	case ADAPTER_REQ_SET_XFER_MODE:
    509 		/*
    510 		 * The DDM takes care of this, and we can't modify its
    511 		 * behaviour.
    512 		 */
    513 		break;
    514 	}
    515 }
    516 
    517 #ifdef notyet
    518 /*
    519  * Abort the specified I2O_SCSI_SCB_EXEC message and its associated SCB.
    520  */
    521 static int
    522 iopsp_scsi_abort(struct iopsp_softc *sc, int atid, struct iop_msg *aim)
    523 {
    524 	struct iop_msg *im;
    525 	struct i2o_scsi_scb_abort mf;
    526 	struct iop_softc *iop;
    527 	int rv, s;
    528 
    529 	iop = (struct iop_softc *)device_parent(&sc->sc_dv);
    530 	im = iop_msg_alloc(iop, IM_POLL);
    531 
    532 	mf.msgflags = I2O_MSGFLAGS(i2o_scsi_scb_abort);
    533 	mf.msgfunc = I2O_MSGFUNC(atid, I2O_SCSI_SCB_ABORT);
    534 	mf.msgictx = sc->sc_ii.ii_ictx;
    535 	mf.msgtctx = im->im_tctx;
    536 	mf.tctxabort = aim->im_tctx;
    537 
    538 	s = splbio();
    539 	rv = iop_msg_post(iop, im, &mf, 30000);
    540 	splx(s);
    541 	iop_msg_free(iop, im);
    542 	return (rv);
    543 }
    544 #endif
    545 
    546 /*
    547  * We have a message which has been processed and replied to by the IOP -
    548  * deal with it.
    549  */
    550 static void
    551 iopsp_intr(struct device *dv, struct iop_msg *im, void *reply)
    552 {
    553 	struct scsipi_xfer *xs;
    554 	struct iopsp_softc *sc;
    555 	struct i2o_scsi_reply *rb;
    556  	struct iop_softc *iop;
    557 	u_int sl;
    558 
    559 	sc = (struct iopsp_softc *)dv;
    560 	xs = (struct scsipi_xfer *)im->im_dvcontext;
    561 	iop = (struct iop_softc *)device_parent(dv);
    562 	rb = reply;
    563 
    564 	SC_DEBUG(xs->xs_periph, SCSIPI_DB2, ("iopsp_intr\n"));
    565 
    566 	if ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0) {
    567 		xs->error = XS_DRIVER_STUFFUP;
    568 		xs->resid = xs->datalen;
    569 	} else {
    570 		if (rb->hbastatus != I2O_SCSI_DSC_SUCCESS) {
    571 			switch (rb->hbastatus) {
    572 			case I2O_SCSI_DSC_ADAPTER_BUSY:
    573 			case I2O_SCSI_DSC_SCSI_BUS_RESET:
    574 			case I2O_SCSI_DSC_BUS_BUSY:
    575 				xs->error = XS_BUSY;
    576 				break;
    577 			case I2O_SCSI_DSC_SELECTION_TIMEOUT:
    578 				xs->error = XS_SELTIMEOUT;
    579 				break;
    580 			case I2O_SCSI_DSC_COMMAND_TIMEOUT:
    581 			case I2O_SCSI_DSC_DEVICE_NOT_PRESENT:
    582 			case I2O_SCSI_DSC_LUN_INVALID:
    583 			case I2O_SCSI_DSC_SCSI_TID_INVALID:
    584 				xs->error = XS_TIMEOUT;
    585 				break;
    586 			default:
    587 				xs->error = XS_DRIVER_STUFFUP;
    588 				break;
    589 			}
    590 			printf("%s: HBA status 0x%02x\n", sc->sc_dv.dv_xname,
    591 			   rb->hbastatus);
    592 		} else if (rb->scsistatus != SCSI_OK) {
    593 			switch (rb->scsistatus) {
    594 			case SCSI_CHECK:
    595 				xs->error = XS_SENSE;
    596 				sl = le32toh(rb->senselen);
    597 				if (sl > sizeof(xs->sense.scsi_sense))
    598 					sl = sizeof(xs->sense.scsi_sense);
    599 				memcpy(&xs->sense.scsi_sense, rb->sense, sl);
    600 				break;
    601 			case SCSI_QUEUE_FULL:
    602 			case SCSI_BUSY:
    603 				xs->error = XS_BUSY;
    604 				break;
    605 			default:
    606 				xs->error = XS_DRIVER_STUFFUP;
    607 				break;
    608 			}
    609 		} else
    610 			xs->error = XS_NOERROR;
    611 
    612 		xs->resid = xs->datalen - le32toh(rb->datalen);
    613 		xs->status = rb->scsistatus;
    614 	}
    615 
    616 	/* Free the message wrapper and pass the news to scsipi. */
    617 	if (xs->datalen != 0)
    618 		iop_msg_unmap(iop, im);
    619 	iop_msg_free(iop, im);
    620 
    621 	scsipi_done(xs);
    622 }
    623 
    624 /*
    625  * ioctl hook; used here only to initiate low-level rescans.
    626  */
    627 static int
    628 iopsp_ioctl(struct scsipi_channel *chan, u_long cmd, caddr_t data,
    629     int flag, struct proc *p)
    630 {
    631 	int rv;
    632 
    633 	switch (cmd) {
    634 	case SCBUSIOLLSCAN:
    635 		/*
    636 		 * If it's boot time, the bus will have been scanned and the
    637 		 * maps built.  Locking would stop re-configuration, but we
    638 		 * want to fake success.
    639 		 */
    640 		if (p != &proc0)
    641 			rv = iopsp_rescan(
    642 			   (struct iopsp_softc *)chan->chan_adapter->adapt_dev);
    643 		else
    644 			rv = 0;
    645 		break;
    646 
    647 	default:
    648 		rv = ENOTTY;
    649 		break;
    650 	}
    651 
    652 	return (rv);
    653 }
    654 
    655 /*
    656  * The number of openings available to us has changed, so inform scsipi.
    657  */
    658 static void
    659 iopsp_adjqparam(struct device *dv, int mpi)
    660 {
    661 	struct iopsp_softc *sc;
    662 	int s;
    663 
    664 	sc = (struct iopsp_softc *)dv;
    665 
    666 	s = splbio();
    667 	sc->sc_adapter.adapt_openings += mpi - sc->sc_openings;
    668 	sc->sc_openings = mpi;
    669 	splx(s);
    670 }
    671