Home | History | Annotate | Line # | Download | only in i2o
iopsp.c revision 1.4.2.4
      1 /*	$NetBSD: iopsp.c,v 1.4.2.4 2001/08/24 00:09:10 nathanw 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/lwp.h>
     52 #include <sys/proc.h>
     53 #include <sys/buf.h>
     54 #include <sys/endian.h>
     55 #include <sys/malloc.h>
     56 #include <sys/scsiio.h>
     57 #include <sys/lock.h>
     58 
     59 #include <machine/bswap.h>
     60 #include <machine/bus.h>
     61 
     62 #include <dev/scsipi/scsi_all.h>
     63 #include <dev/scsipi/scsi_disk.h>
     64 #include <dev/scsipi/scsipi_all.h>
     65 #include <dev/scsipi/scsiconf.h>
     66 #include <dev/scsipi/scsi_message.h>
     67 
     68 #include <dev/i2o/i2o.h>
     69 #include <dev/i2o/iopio.h>
     70 #include <dev/i2o/iopvar.h>
     71 #include <dev/i2o/iopspvar.h>
     72 
     73 static void	iopsp_adjqparam(struct device *, int);
     74 static void	iopsp_attach(struct device *, struct device *, void *);
     75 static void	iopsp_intr(struct device *, struct iop_msg *, void *);
     76 static int	iopsp_ioctl(struct scsipi_channel *, u_long,
     77 			    caddr_t, int, struct proc *);
     78 static int	iopsp_match(struct device *, struct cfdata *, void *);
     79 static int	iopsp_rescan(struct iopsp_softc *);
     80 static int	iopsp_reconfig(struct device *);
     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, &param, 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 fc, 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 	    &param, 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 	fc = (param.p.ci.bustype == I2O_HBA_BUS_FCA);
    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, &param, 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: ", 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.adapt_dev = &sc->sc_dv;
    188 	sc->sc_adapter.adapt_nchannels = 1;
    189 	sc->sc_adapter.adapt_openings = 1;
    190 	sc->sc_adapter.adapt_max_periph = 1;
    191 	sc->sc_adapter.adapt_ioctl = iopsp_ioctl;
    192 	sc->sc_adapter.adapt_minphys = minphys;
    193 	sc->sc_adapter.adapt_request = iopsp_scsipi_request;
    194 
    195 	memset(&sc->sc_channel, 0, sizeof(sc->sc_channel));
    196 	sc->sc_channel.chan_adapter = &sc->sc_adapter;
    197 	sc->sc_channel.chan_bustype = &scsi_bustype;
    198 	sc->sc_channel.chan_channel = 0;
    199 	sc->sc_channel.chan_ntargets = fc ?
    200 	    IOPSP_MAX_FC_TARGET : param.p.sci.maxdatawidth;
    201 	sc->sc_channel.chan_nluns = IOPSP_MAX_LUN;
    202 	sc->sc_channel.chan_id = le32toh(param.p.sci.initiatorid);
    203 	sc->sc_channel.chan_flags = SCSIPI_CHAN_NOSETTLE;
    204 
    205 #ifdef I2OVERBOSE
    206 	/*
    207 	 * Allocate the target map.  Currently used for informational
    208 	 * purposes only.
    209 	 */
    210 	size = sc->sc_channel.chan_ntargets * sizeof(struct iopsp_target);
    211 	sc->sc_targetmap = malloc(size, M_DEVBUF, M_NOWAIT);
    212 	memset(sc->sc_targetmap, 0, size);
    213 #endif
    214 
    215  	/* Build the two maps, and attach to scsipi. */
    216 	if (iopsp_reconfig(self) != 0) {
    217 		printf("%s: configure failed\n", sc->sc_dv.dv_xname);
    218 		goto bad;
    219 	}
    220 	config_found(self, &sc->sc_channel, scsiprint);
    221 	return;
    222 
    223  bad:
    224 	iop_initiator_unregister(iop, &sc->sc_ii);
    225 }
    226 
    227 /*
    228  * Scan the LCT to determine which devices we control, and enter them into
    229  * the maps.
    230  */
    231 static int
    232 iopsp_reconfig(struct device *dv)
    233 {
    234 	struct iopsp_softc *sc;
    235 	struct iop_softc *iop;
    236 	struct i2o_lct_entry *le;
    237 	struct scsipi_channel *sc_chan;
    238 	struct {
    239 		struct	i2o_param_op_results pr;
    240 		struct	i2o_param_read_results prr;
    241 		struct	i2o_param_scsi_device_info sdi;
    242 	} __attribute__ ((__packed__)) param;
    243 	u_int tid, nent, i, targ, lun, size, s, rv, bptid;
    244 	u_short *tidmap;
    245 #ifdef I2OVERBOSE
    246 	struct iopsp_target *it;
    247 	int syncrate;
    248 #endif
    249 
    250 	sc = (struct iopsp_softc *)dv;
    251 	iop = (struct iop_softc *)sc->sc_dv.dv_parent;
    252 	sc_chan = &sc->sc_channel;
    253 
    254 	/* Anything to do? */
    255 	if (iop->sc_chgind == sc->sc_chgind)
    256 		return (0);
    257 
    258 	/*
    259 	 * Allocate memory for the target/LUN -> TID map.  Use zero to
    260 	 * denote absent targets (zero is the TID of the I2O executive,
    261 	 * and we never address that here).
    262 	 */
    263 	size = sc_chan->chan_ntargets * (IOPSP_MAX_LUN) * 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_chan->chan_ntargets; 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_param_op(iop, tid, NULL, 0, I2O_PARAM_SCSI_DEVICE_INFO,
    295 		    &param, sizeof(param));
    296 		if (rv != 0) {
    297 			printf("%s: unable to get parameters (0x%04x; %d)\n",
    298 			    sc->sc_dv.dv_xname, I2O_PARAM_SCSI_DEVICE_INFO,
    299 			    rv);
    300 			continue;
    301 		}
    302 		targ = le32toh(param.sdi.identifier);
    303 		lun = param.sdi.luninfo[1];
    304 #if defined(DIAGNOSTIC) || defined(I2ODEBUG)
    305 		if (targ >= sc_chan->chan_ntargets ||
    306 		    lun >= sc_chan->chan_nluns) {
    307 			printf("%s: target %d,%d (tid %d): bad target/LUN\n",
    308 			    sc->sc_dv.dv_xname, targ, lun, tid);
    309 			continue;
    310 		}
    311 #endif
    312 
    313 #ifdef I2OVERBOSE
    314 		/*
    315 		 * If we've already described this target, and nothing has
    316 		 * changed, then don't describe it again.
    317 		 */
    318 		it = &sc->sc_targetmap[targ];
    319 		it->it_flags |= IT_PRESENT;
    320 		syncrate = ((int)le64toh(param.sdi.negsyncrate) + 500) / 1000;
    321 		if (it->it_width == param.sdi.negdatawidth &&
    322 		    it->it_offset == param.sdi.negoffset &&
    323 		    it->it_syncrate == syncrate)
    324 			continue;
    325 
    326 		it->it_width = param.sdi.negdatawidth;
    327 		it->it_offset = param.sdi.negoffset;
    328 		it->it_syncrate = syncrate;
    329 
    330 		printf("%s: target %d (tid %d): %d-bit, ", sc->sc_dv.dv_xname,
    331 		    targ, tid, it->it_width);
    332 		if (it->it_syncrate == 0)
    333 			printf("asynchronous\n");
    334 		else
    335 			printf("synchronous at %dMHz, offset 0x%x\n",
    336 			    it->it_syncrate, it->it_offset);
    337 #endif
    338 
    339 		/* Ignore the device if it's in use by somebody else. */
    340 		if ((le32toh(le->usertid) & 4095) != I2O_TID_NONE) {
    341 #ifdef I2OVERBOSE
    342 			if (sc->sc_tidmap == NULL ||
    343 			    IOPSP_TIDMAP(sc->sc_tidmap, targ, lun) !=
    344 			    IOPSP_TID_INUSE)
    345 				printf("%s: target %d,%d (tid %d): in use by"
    346 				    " tid %d\n", sc->sc_dv.dv_xname,
    347 				    targ, lun, tid,
    348 				    le32toh(le->usertid) & 4095);
    349 #endif
    350 			IOPSP_TIDMAP(tidmap, targ, lun) = IOPSP_TID_INUSE;
    351 		} else
    352 			IOPSP_TIDMAP(tidmap, targ, lun) = (u_short)tid;
    353 	}
    354 
    355 #ifdef I2OVERBOSE
    356 	for (i = 0; i < sc_chan->chan_ntargets; i++)
    357 		if ((sc->sc_targetmap[i].it_flags & IT_PRESENT) == 0)
    358 			sc->sc_targetmap[i].it_width = 0;
    359 #endif
    360 
    361 	/* Swap in the new map and return. */
    362 	s = splbio();
    363 	if (sc->sc_tidmap != NULL)
    364 		free(sc->sc_tidmap, M_DEVBUF);
    365 	sc->sc_tidmap = tidmap;
    366 	splx(s);
    367 	sc->sc_chgind = iop->sc_chgind;
    368 	return (0);
    369 }
    370 
    371 /*
    372  * Re-scan the bus; to be called from a higher level (e.g. scsipi).
    373  */
    374 static int
    375 iopsp_rescan(struct iopsp_softc *sc)
    376 {
    377 	struct iop_softc *iop;
    378 	struct iop_msg *im;
    379 	struct i2o_hba_bus_scan mf;
    380 	int rv;
    381 
    382 	iop = (struct iop_softc *)sc->sc_dv.dv_parent;
    383 
    384 	rv = lockmgr(&iop->sc_conflock, LK_EXCLUSIVE, NULL);
    385 	if (rv != 0) {
    386 #ifdef I2ODEBUG
    387 		printf("iopsp_rescan: unable to acquire lock\n");
    388 #endif
    389 		return (rv);
    390 	}
    391 
    392 	im = iop_msg_alloc(iop, IM_WAIT);
    393 
    394 	mf.msgflags = I2O_MSGFLAGS(i2o_hba_bus_scan);
    395 	mf.msgfunc = I2O_MSGFUNC(sc->sc_ii.ii_tid, I2O_HBA_BUS_SCAN);
    396 	mf.msgictx = sc->sc_ii.ii_ictx;
    397 	mf.msgtctx = im->im_tctx;
    398 
    399 	rv = iop_msg_post(iop, im, &mf, 5*60*1000);
    400 	iop_msg_free(iop, im);
    401 	if (rv != 0)
    402 		printf("%s: bus rescan failed (error %d)\n",
    403 		    sc->sc_dv.dv_xname, rv);
    404 
    405 	if ((rv = iop_lct_get(iop)) == 0)
    406 		rv = iopsp_reconfig(&sc->sc_dv);
    407 
    408 	lockmgr(&iop->sc_conflock, LK_RELEASE, NULL);
    409 	return (rv);
    410 }
    411 
    412 /*
    413  * Start a SCSI command.
    414  */
    415 static void
    416 iopsp_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req,
    417 		     void *arg)
    418 {
    419 	struct scsipi_xfer *xs;
    420 	struct scsipi_periph *periph;
    421 	struct iopsp_softc *sc;
    422 	struct iop_msg *im;
    423 	struct iop_softc *iop;
    424 	struct i2o_scsi_scb_exec *mf;
    425 	int error, flags, tid, s;
    426 	u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
    427 
    428 	sc = (void *)chan->chan_adapter->adapt_dev;
    429 	iop = (struct iop_softc *)sc->sc_dv.dv_parent;
    430 
    431 	switch (req) {
    432 	case ADAPTER_REQ_RUN_XFER:
    433 		xs = arg;
    434 		periph = xs->xs_periph;
    435 		flags = xs->xs_control;
    436 
    437 		tid = IOPSP_TIDMAP(sc->sc_tidmap, periph->periph_target,
    438 		    periph->periph_lun);
    439 		if (tid == IOPSP_TID_ABSENT || tid == IOPSP_TID_INUSE) {
    440 			xs->error = XS_SELTIMEOUT;
    441 			scsipi_done(xs);
    442 			return;
    443 		}
    444 
    445 		SC_DEBUG(periph, SCSIPI_DB2, ("iopsp_scsi_request run_xfer\n"));
    446 
    447 		/* Need to reset the target? */
    448 		if ((flags & XS_CTL_RESET) != 0) {
    449 			if (iop_simple_cmd(iop, tid, I2O_SCSI_DEVICE_RESET,
    450 			    sc->sc_ii.ii_ictx, 1, 30*1000) != 0) {
    451 #ifdef I2ODEBUG
    452 				printf("%s: reset failed\n",
    453 				    sc->sc_dv.dv_xname);
    454 #endif
    455 				xs->error = XS_DRIVER_STUFFUP;
    456 			} else
    457 				xs->error = XS_NOERROR;
    458 
    459 			scsipi_done(xs);
    460 			return;
    461 		}
    462 
    463 #if defined(I2ODEBUG) || defined(SCSIDEBUG)
    464 		if (xs->cmdlen > sizeof(mf->cdb))
    465 			panic("%s: CDB too large\n", sc->sc_dv.dv_xname);
    466 #endif
    467 
    468 		im = iop_msg_alloc(iop, IM_POLL_INTR |
    469 		    IM_NOSTATUS | ((flags & XS_CTL_POLL) != 0 ? IM_POLL : 0));
    470 		im->im_dvcontext = xs;
    471 
    472 		mf = (struct i2o_scsi_scb_exec *)mb;
    473 		mf->msgflags = I2O_MSGFLAGS(i2o_scsi_scb_exec);
    474 		mf->msgfunc = I2O_MSGFUNC(tid, I2O_SCSI_SCB_EXEC);
    475 		mf->msgictx = sc->sc_ii.ii_ictx;
    476 		mf->msgtctx = im->im_tctx;
    477 		mf->flags = xs->cmdlen | I2O_SCB_FLAG_ENABLE_DISCONNECT |
    478 		    I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
    479 		mf->datalen = xs->datalen;
    480 		memcpy(mf->cdb, xs->cmd, xs->cmdlen);
    481 
    482 		switch (xs->xs_tag_type) {
    483 		case MSG_ORDERED_Q_TAG:
    484 			mf->flags |= I2O_SCB_FLAG_ORDERED_QUEUE_TAG;
    485 			break;
    486 		case MSG_SIMPLE_Q_TAG:
    487 			mf->flags |= I2O_SCB_FLAG_SIMPLE_QUEUE_TAG;
    488 			break;
    489 		case MSG_HEAD_OF_Q_TAG:
    490 			mf->flags |= I2O_SCB_FLAG_HEAD_QUEUE_TAG;
    491 			break;
    492 		default:
    493 			break;
    494 		}
    495 
    496 		if (xs->datalen != 0) {
    497 			error = iop_msg_map_bio(iop, im, mb, xs->data,
    498 			    xs->datalen, (flags & XS_CTL_DATA_OUT) == 0);
    499 			if (error) {
    500 				xs->error = XS_DRIVER_STUFFUP;
    501 				iop_msg_free(iop, im);
    502 				scsipi_done(xs);
    503 				return;
    504 			}
    505 			if ((flags & XS_CTL_DATA_IN) == 0)
    506 				mf->flags |= I2O_SCB_FLAG_XFER_TO_DEVICE;
    507 			else
    508 				mf->flags |= I2O_SCB_FLAG_XFER_FROM_DEVICE;
    509 		}
    510 
    511 		s = splbio();
    512 		sc->sc_curqd++;
    513 		splx(s);
    514 
    515 		if (iop_msg_post(iop, im, mb, xs->timeout)) {
    516 			s = splbio();
    517 			sc->sc_curqd--;
    518 			splx(s);
    519 			if (xs->datalen != 0)
    520 				iop_msg_unmap(iop, im);
    521 			iop_msg_free(iop, im);
    522 			xs->error = XS_DRIVER_STUFFUP;
    523 			scsipi_done(xs);
    524 		}
    525 		break;
    526 
    527 	case ADAPTER_REQ_GROW_RESOURCES:
    528 		/*
    529 		 * Not supported.
    530 		 */
    531 		break;
    532 
    533 	case ADAPTER_REQ_SET_XFER_MODE:
    534 		/*
    535 		 * The DDM takes care of this, and we can't modify its
    536 		 * behaviour.
    537 		 */
    538 		break;
    539 	}
    540 }
    541 
    542 #ifdef notyet
    543 /*
    544  * Abort the specified I2O_SCSI_SCB_EXEC message and its associated SCB.
    545  */
    546 static int
    547 iopsp_scsi_abort(struct iopsp_softc *sc, int atid, struct iop_msg *aim)
    548 {
    549 	struct iop_msg *im;
    550 	struct i2o_scsi_scb_abort mf;
    551 	struct iop_softc *iop;
    552 	int rv, s;
    553 
    554 	iop = (struct iop_softc *)sc->sc_dv.dv_parent;
    555 	im = iop_msg_alloc(iop, IM_POLL);
    556 
    557 	mf.msgflags = I2O_MSGFLAGS(i2o_scsi_scb_abort);
    558 	mf.msgfunc = I2O_MSGFUNC(atid, I2O_SCSI_SCB_ABORT);
    559 	mf.msgictx = sc->sc_ii.ii_ictx;
    560 	mf.msgtctx = im->im_tctx;
    561 	mf.tctxabort = aim->im_tctx;
    562 
    563 	s = splbio();
    564 	rv = iop_msg_post(iop, im, &mf, 30000);
    565 	splx(s);
    566 	iop_msg_free(iop, im);
    567 	return (rv);
    568 }
    569 #endif
    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 	rb = reply;
    588 
    589 	SC_DEBUG(xs->xs_periph, SCSIPI_DB2, ("iopsp_intr\n"));
    590 
    591 	if ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0) {
    592 		xs->error = XS_DRIVER_STUFFUP;
    593 		xs->resid = xs->datalen;
    594 	} else {
    595 		if (rb->hbastatus != I2O_SCSI_DSC_SUCCESS) {
    596 			switch (rb->hbastatus) {
    597 			case I2O_SCSI_DSC_ADAPTER_BUSY:
    598 			case I2O_SCSI_DSC_SCSI_BUS_RESET:
    599 			case I2O_SCSI_DSC_BUS_BUSY:
    600 				xs->error = XS_BUSY;
    601 				break;
    602 			case I2O_SCSI_DSC_SELECTION_TIMEOUT:
    603 				xs->error = XS_SELTIMEOUT;
    604 				break;
    605 			case I2O_SCSI_DSC_COMMAND_TIMEOUT:
    606 			case I2O_SCSI_DSC_DEVICE_NOT_PRESENT:
    607 			case I2O_SCSI_DSC_LUN_INVALID:
    608 			case I2O_SCSI_DSC_SCSI_TID_INVALID:
    609 				xs->error = XS_TIMEOUT;
    610 				break;
    611 			default:
    612 				xs->error = XS_DRIVER_STUFFUP;
    613 				break;
    614 			}
    615 			printf("%s: HBA status 0x%02x\n", sc->sc_dv.dv_xname,
    616 			   rb->hbastatus);
    617 		} else if (rb->scsistatus != SCSI_OK) {
    618 			switch (rb->scsistatus) {
    619 			case SCSI_CHECK:
    620 				xs->error = XS_SENSE;
    621 				sl = le32toh(rb->senselen);
    622 				if (sl > sizeof(xs->sense.scsi_sense))
    623 					sl = sizeof(xs->sense.scsi_sense);
    624 				memcpy(&xs->sense.scsi_sense, rb->sense, sl);
    625 				break;
    626 			case SCSI_QUEUE_FULL:
    627 			case SCSI_BUSY:
    628 				xs->error = XS_BUSY;
    629 				break;
    630 			default:
    631 				xs->error = XS_DRIVER_STUFFUP;
    632 				break;
    633 			}
    634 		} else
    635 			xs->error = XS_NOERROR;
    636 
    637 		xs->resid = xs->datalen - le32toh(rb->datalen);
    638 		xs->status = rb->scsistatus;
    639 	}
    640 
    641 	/* Free the message wrapper and pass the news to scsipi. */
    642 	if (xs->datalen != 0)
    643 		iop_msg_unmap(iop, im);
    644 	iop_msg_free(iop, im);
    645 
    646 	if (--sc->sc_curqd == sc->sc_adapter.adapt_openings)
    647 		wakeup(&sc->sc_curqd);
    648 
    649 	scsipi_done(xs);
    650 }
    651 
    652 /*
    653  * ioctl hook; used here only to initiate low-level rescans.
    654  */
    655 static int
    656 iopsp_ioctl(struct scsipi_channel *chan, u_long cmd, caddr_t data, int flag,
    657 	    struct proc *p)
    658 {
    659 	int rv;
    660 
    661 	switch (cmd) {
    662 	case SCBUSIOLLSCAN:
    663 		/*
    664 		 * If it's boot time, the bus will have been scanned and the
    665 		 * maps built.  Locking would stop re-configuration, but we
    666 		 * want to fake success.
    667 		 */
    668 		if (p != &proc0)
    669 			rv = iopsp_rescan(
    670 			   (struct iopsp_softc *)chan->chan_adapter->adapt_dev);
    671 		else
    672 			rv = 0;
    673 		break;
    674 
    675 	default:
    676 		rv = ENOTTY;
    677 		break;
    678 	}
    679 
    680 	return (rv);
    681 }
    682 
    683 /*
    684  * The number of openings available to us has changed, so inform scsipi.
    685  */
    686 static void
    687 iopsp_adjqparam(struct device *dv, int mpi)
    688 {
    689 	struct iopsp_softc *sc;
    690 	int s;
    691 
    692 	sc = (struct iopsp_softc *)dv;
    693 
    694 	s = splbio();
    695 	sc->sc_adapter.adapt_openings = mpi;
    696 	if (mpi < sc->sc_curqd)
    697 		tsleep(&sc->sc_curqd, PWAIT, "iopspdrn", 0);
    698 	splx(s);
    699 }
    700