Home | History | Annotate | Line # | Download | only in i2o
iopsp.c revision 1.7
      1 /*	$NetBSD: iopsp.c,v 1.7 2001/04/25 17:53:28 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 void	iopsp_scsipi_request(struct scsipi_channel *,
     81 				     scsipi_adapter_req_t, void *);
     82 
     83 struct cfattach iopsp_ca = {
     84 	sizeof(struct iopsp_softc), iopsp_match, iopsp_attach
     85 };
     86 
     87 /*
     88  * Match a supported device.
     89  */
     90 static int
     91 iopsp_match(struct device *parent, struct cfdata *match, void *aux)
     92 {
     93 	struct iop_attach_args *ia;
     94 	struct {
     95 		struct	i2o_param_op_results pr;
     96 		struct	i2o_param_read_results prr;
     97 		struct	i2o_param_hba_ctlr_info ci;
     98 	} __attribute__ ((__packed__)) param;
     99 
    100 	ia = aux;
    101 
    102 	if (ia->ia_class != I2O_CLASS_BUS_ADAPTER_PORT)
    103 		return (0);
    104 
    105 	if (iop_param_op((struct iop_softc *)parent, ia->ia_tid, NULL, 0,
    106 	    I2O_PARAM_HBA_CTLR_INFO, &param, sizeof(param)) != 0)
    107 		return (0);
    108 
    109 	return (param.ci.bustype == I2O_HBA_BUS_SCSI ||
    110 	    param.ci.bustype == I2O_HBA_BUS_FCA);
    111 }
    112 
    113 /*
    114  * Attach a supported device.
    115  */
    116 static void
    117 iopsp_attach(struct device *parent, struct device *self, void *aux)
    118 {
    119 	struct iop_attach_args *ia;
    120 	struct iopsp_softc *sc;
    121 	struct iop_softc *iop;
    122 	struct {
    123 		struct	i2o_param_op_results pr;
    124 		struct	i2o_param_read_results prr;
    125 		union {
    126 			struct	i2o_param_hba_ctlr_info ci;
    127 			struct	i2o_param_hba_scsi_ctlr_info sci;
    128 			struct	i2o_param_hba_scsi_port_info spi;
    129 		} p;
    130 	} __attribute__ ((__packed__)) param;
    131 	int fcal, rv;
    132 #ifdef I2OVERBOSE
    133 	int size;
    134 #endif
    135 
    136 	ia = (struct iop_attach_args *)aux;
    137 	sc = (struct iopsp_softc *)self;
    138 	iop = (struct iop_softc *)parent;
    139 
    140 	/* Register us as an initiator. */
    141 	sc->sc_ii.ii_dv = self;
    142 	sc->sc_ii.ii_intr = iopsp_intr;
    143 	sc->sc_ii.ii_flags = 0;
    144 	sc->sc_ii.ii_tid = ia->ia_tid;
    145 	sc->sc_ii.ii_reconfig = iopsp_reconfig;
    146 	sc->sc_ii.ii_adjqparam = iopsp_adjqparam;
    147 	iop_initiator_register(iop, &sc->sc_ii);
    148 
    149 	rv = iop_param_op(iop, ia->ia_tid, NULL, 0, I2O_PARAM_HBA_CTLR_INFO,
    150 	    &param, sizeof(param));
    151 	if (rv != 0) {
    152 		printf("%s: unable to get parameters (0x%04x; %d)\n",
    153 	    	    sc->sc_dv.dv_xname, I2O_PARAM_HBA_CTLR_INFO, rv);
    154 		goto bad;
    155 	}
    156 
    157 	fcal = (param.p.ci.bustype == I2O_HBA_BUS_FCA);		/* XXX */
    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_param_op(iop, ia->ia_tid, NULL, 0,
    168 	    I2O_PARAM_HBA_SCSI_CTLR_INFO, &param, sizeof(param));
    169 	if (rv != 0) {
    170 		printf("%s: unable to get parameters (0x%04x; %d)\n",
    171 		    sc->sc_dv.dv_xname, I2O_PARAM_HBA_SCSI_CTLR_INFO, rv);
    172 		goto bad;
    173 	}
    174 
    175 #ifdef I2OVERBOSE
    176 	printf("%s: %d-bit, max sync rate %dMHz, initiator ID %d\n",
    177 	    sc->sc_dv.dv_xname, param.p.sci.maxdatawidth,
    178 	    (u_int32_t)le64toh(param.p.sci.maxsyncrate) / 1000,
    179 	    le32toh(param.p.sci.initiatorid));
    180 #endif
    181 
    182 	sc->sc_adapter.adapt_dev = &sc->sc_dv;
    183 	sc->sc_adapter.adapt_nchannels = 1;
    184 	sc->sc_adapter.adapt_openings = 1;
    185 	sc->sc_adapter.adapt_max_periph = 1;
    186 	sc->sc_adapter.adapt_ioctl = iopsp_ioctl;
    187 	sc->sc_adapter.adapt_minphys = minphys;
    188 	sc->sc_adapter.adapt_request = iopsp_scsipi_request;
    189 
    190 	memset(&sc->sc_channel, 0, sizeof(sc->sc_channel));
    191 	sc->sc_channel.chan_adapter = &sc->sc_adapter;
    192 	sc->sc_channel.chan_bustype = &scsi_bustype;
    193 	sc->sc_channel.chan_channel = 0;
    194 	sc->sc_channel.chan_ntargets = fcal ?
    195 	    IOPSP_MAX_FCAL_TARGET : param.p.sci.maxdatawidth;
    196 	sc->sc_channel.chan_nluns = IOPSP_MAX_LUN;
    197 	sc->sc_channel.chan_id = le32toh(param.p.sci.initiatorid);
    198 	sc->sc_channel.chan_flags = SCSIPI_CHAN_NOSETTLE;
    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 		    &param, 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 		rv = iopsp_reconfig(&sc->sc_dv);
    402 
    403 	lockmgr(&iop->sc_conflock, LK_RELEASE, NULL);
    404 	return (rv);
    405 }
    406 
    407 /*
    408  * Start a SCSI command.
    409  */
    410 static void
    411 iopsp_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req,
    412 		     void *arg)
    413 {
    414 	struct scsipi_xfer *xs;
    415 	struct scsipi_periph *periph;
    416 	struct iopsp_softc *sc;
    417 	struct iop_msg *im;
    418 	struct iop_softc *iop;
    419 	struct i2o_scsi_scb_exec *mf;
    420 	int error, flags, tid, s;
    421 	u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
    422 
    423 	sc = (void *)chan->chan_adapter->adapt_dev;
    424 	iop = (struct iop_softc *)sc->sc_dv.dv_parent;
    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, 30*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 		im = iop_msg_alloc(iop, &sc->sc_ii, IM_POLL_INTR |
    464 		    IM_NOSTATUS | ((flags & XS_CTL_POLL) != 0 ? IM_POLL : 0));
    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 
    491 		if (xs->datalen != 0) {
    492 			error = iop_msg_map_bio(iop, im, mb, xs->data,
    493 			    xs->datalen, (flags & XS_CTL_DATA_OUT) == 0);
    494 			if (error) {
    495 				xs->error = XS_DRIVER_STUFFUP;
    496 				iop_msg_free(iop, im);
    497 				scsipi_done(xs);
    498 				return;
    499 			}
    500 			if ((flags & XS_CTL_DATA_IN) == 0)
    501 				mf->flags |= I2O_SCB_FLAG_XFER_TO_DEVICE;
    502 			else
    503 				mf->flags |= I2O_SCB_FLAG_XFER_FROM_DEVICE;
    504 		}
    505 
    506 		s = splbio();
    507 		sc->sc_curqd++;
    508 		splx(s);
    509 
    510 		if (iop_msg_post(iop, im, mb, xs->timeout)) {
    511 			s = splbio();
    512 			sc->sc_curqd--;
    513 			splx(s);
    514 			if (xs->datalen != 0)
    515 				iop_msg_unmap(iop, im);
    516 			iop_msg_free(iop, im);
    517 			xs->error = XS_DRIVER_STUFFUP;
    518 			scsipi_done(xs);
    519 		}
    520 		break;
    521 
    522 	case ADAPTER_REQ_GROW_RESOURCES:
    523 		/*
    524 		 * Not supported.
    525 		 */
    526 		break;
    527 
    528 	case ADAPTER_REQ_SET_XFER_MODE:
    529 		/*
    530 		 * The DDM takes care of this, and we can't modify its
    531 		 * behaviour.
    532 		 */
    533 		break;
    534 	}
    535 }
    536 
    537 #ifdef notyet
    538 /*
    539  * Abort the specified I2O_SCSI_SCB_EXEC message and its associated SCB.
    540  */
    541 static int
    542 iopsp_scsi_abort(struct iopsp_softc *sc, int atid, struct iop_msg *aim)
    543 {
    544 	struct iop_msg *im;
    545 	struct i2o_scsi_scb_abort mf;
    546 	struct iop_softc *iop;
    547 	int rv, s;
    548 
    549 	iop = (struct iop_softc *)sc->sc_dv.dv_parent;
    550 	im = iop_msg_alloc(iop, &sc->sc_ii, IM_POLL);
    551 
    552 	mf.msgflags = I2O_MSGFLAGS(i2o_scsi_scb_abort);
    553 	mf.msgfunc = I2O_MSGFUNC(atid, I2O_SCSI_SCB_ABORT);
    554 	mf.msgictx = sc->sc_ii.ii_ictx;
    555 	mf.msgtctx = im->im_tctx;
    556 	mf.tctxabort = aim->im_tctx;
    557 
    558 	s = splbio();
    559 	rv = iop_msg_post(iop, im, &mf, 30000);
    560 	splx(s);
    561 	iop_msg_free(iop, im);
    562 	return (rv);
    563 }
    564 #endif
    565 
    566 /*
    567  * We have a message which has been processed and replied to by the IOP -
    568  * deal with it.
    569  */
    570 static void
    571 iopsp_intr(struct device *dv, struct iop_msg *im, void *reply)
    572 {
    573 	struct scsipi_xfer *xs;
    574 	struct iopsp_softc *sc;
    575 	struct i2o_scsi_reply *rb;
    576  	struct iop_softc *iop;
    577 	u_int sl;
    578 
    579 	sc = (struct iopsp_softc *)dv;
    580 	xs = (struct scsipi_xfer *)im->im_dvcontext;
    581 	iop = (struct iop_softc *)dv->dv_parent;
    582 	rb = reply;
    583 
    584 	SC_DEBUG(xs->xs_periph, SDEV_DB2, ("iopsp_intr\n"));
    585 
    586 	if ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0) {
    587 		xs->error = XS_DRIVER_STUFFUP;
    588 		xs->resid = xs->datalen;
    589 	} else {
    590 		if (rb->hbastatus != I2O_SCSI_DSC_SUCCESS) {
    591 			switch (rb->hbastatus) {
    592 			case I2O_SCSI_DSC_ADAPTER_BUSY:
    593 			case I2O_SCSI_DSC_SCSI_BUS_RESET:
    594 			case I2O_SCSI_DSC_BUS_BUSY:
    595 				xs->error = XS_BUSY;
    596 				break;
    597 			case I2O_SCSI_DSC_SELECTION_TIMEOUT:
    598 				xs->error = XS_SELTIMEOUT;
    599 				break;
    600 			case I2O_SCSI_DSC_COMMAND_TIMEOUT:
    601 			case I2O_SCSI_DSC_DEVICE_NOT_PRESENT:
    602 			case I2O_SCSI_DSC_LUN_INVALID:
    603 			case I2O_SCSI_DSC_SCSI_TID_INVALID:
    604 				xs->error = XS_TIMEOUT;
    605 				break;
    606 			default:
    607 				xs->error = XS_DRIVER_STUFFUP;
    608 				break;
    609 			}
    610 			printf("%s: HBA status 0x%02x\n", sc->sc_dv.dv_xname,
    611 			   rb->hbastatus);
    612 		} else if (rb->scsistatus != SCSI_OK) {
    613 			switch (rb->scsistatus) {
    614 			case SCSI_CHECK:
    615 				xs->error = XS_SENSE;
    616 				sl = le32toh(rb->senselen);
    617 				if (sl > sizeof(xs->sense.scsi_sense))
    618 					sl = sizeof(xs->sense.scsi_sense);
    619 				memcpy(&xs->sense.scsi_sense, rb->sense, sl);
    620 				break;
    621 			case SCSI_QUEUE_FULL:
    622 			case SCSI_BUSY:
    623 				xs->error = XS_BUSY;
    624 				break;
    625 			default:
    626 				xs->error = XS_DRIVER_STUFFUP;
    627 				break;
    628 			}
    629 		} else
    630 			xs->error = XS_NOERROR;
    631 
    632 		xs->resid = xs->datalen - le32toh(rb->datalen);
    633 		xs->status = rb->scsistatus;
    634 	}
    635 
    636 	/* Free the message wrapper and pass the news to scsipi. */
    637 	if (xs->datalen != 0)
    638 		iop_msg_unmap(iop, im);
    639 	iop_msg_free(iop, im);
    640 
    641 	if (--sc->sc_curqd == sc->sc_adapter.adapt_openings)
    642 		wakeup(&sc->sc_curqd);
    643 
    644 	scsipi_done(xs);
    645 }
    646 
    647 /*
    648  * ioctl hook; used here only to initiate low-level rescans.
    649  */
    650 static int
    651 iopsp_ioctl(struct scsipi_channel *chan, u_long cmd, caddr_t data, int flag,
    652 	    struct proc *p)
    653 {
    654 	int rv;
    655 
    656 	switch (cmd) {
    657 	case SCBUSIOLLSCAN:
    658 		/*
    659 		 * If it's boot time, the bus will have been scanned and the
    660 		 * maps built.  Locking would stop re-configuration, but we
    661 		 * want to fake success.
    662 		 */
    663 		if (p != &proc0)
    664 			rv = iopsp_rescan(
    665 			   (struct iopsp_softc *)chan->chan_adapter->adapt_dev);
    666 		else
    667 			rv = 0;
    668 		break;
    669 
    670 	default:
    671 		rv = ENOTTY;
    672 		break;
    673 	}
    674 
    675 	return (rv);
    676 }
    677 
    678 /*
    679  * The number of openings available to us has changed, so inform scsipi.
    680  */
    681 static void
    682 iopsp_adjqparam(struct device *dv, int mpi)
    683 {
    684 	struct iopsp_softc *sc;
    685 	int s;
    686 
    687 	sc = (struct iopsp_softc *)dv;
    688 
    689 	s = splbio();
    690 	sc->sc_adapter.adapt_openings = mpi;
    691 	if (mpi < sc->sc_curqd)
    692 		tsleep(&sc->sc_curqd, PWAIT, "iopspdrn", 0);
    693 	splx(s);
    694 }
    695