Home | History | Annotate | Line # | Download | only in scsipi
scsiconf.c revision 1.170
      1 /*	$NetBSD: scsiconf.c,v 1.170 2001/11/19 22:50:00 tsutsui Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace
      9  * Simulation Facility, NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *        This product includes software developed by the NetBSD
     22  *        Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * Originally written by Julian Elischer (julian (at) tfs.com)
     42  * for TRW Financial Systems for use under the MACH(2.5) operating system.
     43  *
     44  * TRW Financial Systems, in accordance with their agreement with Carnegie
     45  * Mellon University, makes this software available to CMU to distribute
     46  * or use in any manner that they see fit as long as this message is kept with
     47  * the software. For this reason TFS also grants any other persons or
     48  * organisations permission to use or modify this software.
     49  *
     50  * TFS supplies this software to be publicly redistributed
     51  * on the understanding that TFS is not responsible for the correct
     52  * functioning of this software in any circumstances.
     53  *
     54  * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
     55  */
     56 
     57 #include <sys/cdefs.h>
     58 __KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.170 2001/11/19 22:50:00 tsutsui Exp $");
     59 
     60 #include <sys/param.h>
     61 #include <sys/systm.h>
     62 #include <sys/kernel.h>
     63 #include <sys/proc.h>
     64 #include <sys/kthread.h>
     65 #include <sys/malloc.h>
     66 #include <sys/device.h>
     67 #include <sys/conf.h>
     68 #include <sys/fcntl.h>
     69 #include <sys/scsiio.h>
     70 
     71 #include <dev/scsipi/scsi_all.h>
     72 #include <dev/scsipi/scsipi_all.h>
     73 #include <dev/scsipi/scsiconf.h>
     74 
     75 #include "locators.h"
     76 
     77 const struct scsipi_periphsw scsi_probe_dev = {
     78 	NULL,
     79 	NULL,
     80 	NULL,
     81 	NULL,
     82 };
     83 
     84 int	scsi_probe_device __P((struct scsibus_softc *, int, int));
     85 
     86 int	scsibusmatch __P((struct device *, struct cfdata *, void *));
     87 void	scsibusattach __P((struct device *, struct device *, void *));
     88 int	scsibusactivate __P((struct device *, enum devact));
     89 int	scsibusdetach __P((struct device *, int flags));
     90 
     91 int	scsibussubmatch __P((struct device *, struct cfdata *, void *));
     92 
     93 struct cfattach scsibus_ca = {
     94 	sizeof(struct scsibus_softc), scsibusmatch, scsibusattach,
     95 	    scsibusdetach, scsibusactivate,
     96 };
     97 
     98 extern struct cfdriver scsibus_cd;
     99 
    100 int	scsibusprint __P((void *, const char *));
    101 void	scsibus_config_interrupts __P((struct device *));
    102 
    103 cdev_decl(scsibus);
    104 
    105 const struct scsipi_bustype scsi_bustype = {
    106 	SCSIPI_BUSTYPE_SCSI,
    107 	scsi_scsipi_cmd,
    108 	scsipi_interpret_sense,
    109 	scsi_print_addr,
    110 	scsi_kill_pending,
    111 };
    112 
    113 int
    114 scsiprint(aux, pnp)
    115 	void *aux;
    116 	const char *pnp;
    117 {
    118 	struct scsipi_channel *chan = aux;
    119 	struct scsipi_adapter *adapt = chan->chan_adapter;
    120 
    121 	/* only "scsibus"es can attach to "scsi"s; easy. */
    122 	if (pnp)
    123 		printf("scsibus at %s", pnp);
    124 
    125 	/* don't print channel if the controller says there can be only one. */
    126 	if (adapt->adapt_nchannels != 1)
    127 		printf(" channel %d", chan->chan_channel);
    128 
    129 	return (UNCONF);
    130 }
    131 
    132 int
    133 scsibusmatch(parent, cf, aux)
    134 	struct device *parent;
    135 	struct cfdata *cf;
    136 	void *aux;
    137 {
    138 	struct scsipi_channel *chan = aux;
    139 
    140 	if (chan->type != BUS_SCSI)
    141 		return 0;
    142 
    143 	if (cf->cf_loc[SCSICF_CHANNEL] != chan->chan_channel &&
    144 	    cf->cf_loc[SCSICF_CHANNEL] != SCSICF_CHANNEL_DEFAULT)
    145 		return (0);
    146 
    147 	return (1);
    148 }
    149 
    150 void
    151 scsibusattach(parent, self, aux)
    152 	struct device *parent, *self;
    153 	void *aux;
    154 {
    155 	struct scsibus_softc *sc = (void *) self;
    156 	struct scsipi_channel *chan = aux;
    157 
    158 	sc->sc_channel = chan;
    159 
    160 	/* Initialize the channel structure first */
    161 	if (scsipi_channel_init(chan)) {
    162 		printf(": failed to init channel\n");
    163 		return;
    164 	}
    165 
    166 	printf(": %d targets, %d luns per target\n",
    167 	    chan->chan_ntargets, chan->chan_nluns);
    168 
    169 
    170 	/*
    171 	 * Defer configuration of the children until interrupts
    172 	 * are enabled.
    173 	 */
    174 	config_interrupts(self, scsibus_config_interrupts);
    175 }
    176 
    177 void
    178 scsibus_config_interrupts(self)
    179 	struct device *self;
    180 {
    181 	struct scsibus_softc *sc = (void *) self;
    182 
    183 #ifndef SCSI_DELAY
    184 #define SCSI_DELAY 2
    185 #endif
    186 
    187 	if ((sc->sc_channel->chan_flags & SCSIPI_CHAN_NOSETTLE) == 0 &&
    188 	    SCSI_DELAY > 0) {
    189 		printf("%s: waiting %d seconds for devices to settle...\n",
    190 		    self->dv_xname, SCSI_DELAY);
    191 		/* ...an identifier we know no one will use... */
    192 		(void) tsleep(scsibus_config_interrupts, PRIBIO,
    193 		    "scsidly", SCSI_DELAY * hz);
    194 	}
    195 
    196 	scsi_probe_bus(sc, -1, -1);
    197 }
    198 
    199 int
    200 scsibussubmatch(parent, cf, aux)
    201 	struct device *parent;
    202 	struct cfdata *cf;
    203 	void *aux;
    204 {
    205 	struct scsipibus_attach_args *sa = aux;
    206 	struct scsipi_periph *periph = sa->sa_periph;
    207 
    208 	if (cf->cf_loc[SCSIBUSCF_TARGET] != SCSIBUSCF_TARGET_DEFAULT &&
    209 	    cf->cf_loc[SCSIBUSCF_TARGET] != periph->periph_target)
    210 		return (0);
    211 	if (cf->cf_loc[SCSIBUSCF_LUN] != SCSIBUSCF_LUN_DEFAULT &&
    212 	    cf->cf_loc[SCSIBUSCF_LUN] != periph->periph_lun)
    213 		return (0);
    214 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    215 }
    216 
    217 int
    218 scsibusactivate(self, act)
    219 	struct device *self;
    220 	enum devact act;
    221 {
    222 	struct scsibus_softc *sc = (void *) self;
    223 	struct scsipi_channel *chan = sc->sc_channel;
    224 	struct scsipi_periph *periph;
    225 	int target, lun, error = 0, s;
    226 
    227 	s = splbio();
    228 	switch (act) {
    229 	case DVACT_ACTIVATE:
    230 		error = EOPNOTSUPP;
    231 		break;
    232 
    233 	case DVACT_DEACTIVATE:
    234 		for (target = 0; target < chan->chan_ntargets;
    235 		     target++) {
    236 			if (target == chan->chan_id)
    237 				continue;
    238 			for (lun = 0; lun < chan->chan_nluns; lun++) {
    239 				periph = scsipi_lookup_periph(chan,
    240 				    target, lun);
    241 				if (periph == NULL)
    242 					continue;
    243 				error = config_deactivate(periph->periph_dev);
    244 				if (error)
    245 					goto out;
    246 			}
    247 		}
    248 		break;
    249 	}
    250  out:
    251 	splx(s);
    252 	return (error);
    253 }
    254 
    255 int
    256 scsibusdetach(self, flags)
    257 	struct device *self;
    258 	int flags;
    259 {
    260 	struct scsibus_softc *sc = (void *) self;
    261 	struct scsipi_channel *chan = sc->sc_channel;
    262 
    263 	/*
    264 	 * Shut down the channel.
    265 	 */
    266 	scsipi_channel_shutdown(chan);
    267 
    268 	/*
    269 	 * Now detach all of the periphs.
    270 	 */
    271 	return scsipi_target_detach(chan, -1, -1, flags);
    272 }
    273 
    274 /*
    275  * Probe the requested scsi bus. It must be already set up.
    276  * target and lun optionally narrow the search if not -1
    277  */
    278 int
    279 scsi_probe_bus(sc, target, lun)
    280 	struct scsibus_softc *sc;
    281 	int target, lun;
    282 {
    283 	struct scsipi_channel *chan = sc->sc_channel;
    284 	int maxtarget, mintarget, maxlun, minlun;
    285 	int error;
    286 
    287 	if (target == -1) {
    288 		maxtarget = chan->chan_ntargets - 1;
    289 		mintarget = 0;
    290 	} else {
    291 		if (target < 0 || target >= chan->chan_ntargets)
    292 			return (EINVAL);
    293 		maxtarget = mintarget = target;
    294 	}
    295 
    296 	if (lun == -1) {
    297 		maxlun = chan->chan_nluns - 1;
    298 		minlun = 0;
    299 	} else {
    300 		if (lun < 0 || lun >= chan->chan_nluns)
    301 			return (EINVAL);
    302 		maxlun = minlun = lun;
    303 	}
    304 
    305 	/*
    306 	 * Some HBAs provide an abstracted view of the bus; give them an
    307 	 * oppertunity to re-scan it before we do.
    308 	 */
    309 	if (chan->chan_adapter->adapt_ioctl != NULL)
    310 		(*chan->chan_adapter->adapt_ioctl)(chan, SCBUSIOLLSCAN, NULL,
    311 		    0, curproc);
    312 
    313 	if ((error = scsipi_adapter_addref(chan->chan_adapter)) != 0)
    314 		return (error);
    315 	for (target = mintarget; target <= maxtarget; target++) {
    316 		if (target == chan->chan_id)
    317 			continue;
    318 		for (lun = minlun; lun <= maxlun; lun++) {
    319 			/*
    320 			 * See if there's a device present, and configure it.
    321 			 */
    322 			if (scsi_probe_device(sc, target, lun) == 0)
    323 				break;
    324 			/* otherwise something says we should look further */
    325 		}
    326 
    327 		/*
    328 		 * Now that we've discovered all of the LUNs on this
    329 		 * I_T Nexus, update the xfer mode for all of them
    330 		 * that we know about.
    331 		 */
    332 		scsipi_set_xfer_mode(chan, target, 1);
    333 	}
    334 	scsipi_adapter_delref(chan->chan_adapter);
    335 	return (0);
    336 }
    337 
    338 /*
    339  * Print out autoconfiguration information for a subdevice.
    340  *
    341  * This is a slight abuse of 'standard' autoconfiguration semantics,
    342  * because 'print' functions don't normally print the colon and
    343  * device information.  However, in this case that's better than
    344  * either printing redundant information before the attach message,
    345  * or having the device driver call a special function to print out
    346  * the standard device information.
    347  */
    348 int
    349 scsibusprint(aux, pnp)
    350 	void *aux;
    351 	const char *pnp;
    352 {
    353 	struct scsipibus_attach_args *sa = aux;
    354 	struct scsipi_inquiry_pattern *inqbuf;
    355 	u_int8_t type;
    356 	const char *dtype, *qtype;
    357 	char vendor[33], product[65], revision[17];
    358 	int target, lun;
    359 
    360 	if (pnp != NULL)
    361 		printf("%s", pnp);
    362 
    363 	inqbuf = &sa->sa_inqbuf;
    364 
    365 	target = sa->sa_periph->periph_target;
    366 	lun = sa->sa_periph->periph_lun;
    367 	type = inqbuf->type & SID_TYPE;
    368 
    369 	/*
    370 	 * Figure out basic device type and qualifier.
    371 	 */
    372 	dtype = 0;
    373 	switch (inqbuf->type & SID_QUAL) {
    374 	case SID_QUAL_LU_PRESENT:
    375 		qtype = "";
    376 		break;
    377 
    378 	case SID_QUAL_LU_NOTPRESENT:
    379 		qtype = " offline";
    380 		break;
    381 
    382 	case SID_QUAL_reserved:
    383 	case SID_QUAL_LU_NOT_SUPP:
    384 		panic("scsibusprint: impossible qualifier");
    385 
    386 	default:
    387 		qtype = "";
    388 		dtype = "vendor-unique";
    389 		break;
    390 	}
    391 	if (dtype == NULL)
    392 		dtype = scsipi_dtype(type);
    393 
    394 	scsipi_strvis(vendor, 33, inqbuf->vendor, 8);
    395 	scsipi_strvis(product, 65, inqbuf->product, 16);
    396 	scsipi_strvis(revision, 17, inqbuf->revision, 4);
    397 
    398 	printf(" target %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s",
    399 	    target, lun, vendor, product, revision,
    400 	    sa->scsipi_info.scsi_version & SID_ANSII, type, dtype,
    401 	    inqbuf->removable ? "removable" : "fixed", qtype);
    402 
    403 	return (UNCONF);
    404 }
    405 
    406 const struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
    407 	{{T_CDROM, T_REMOV,
    408 	 "CHINON  ", "CD-ROM CDS-431  ", ""},     PQUIRK_NOLUNS},
    409 	{{T_CDROM, T_REMOV,
    410 	 "Chinon  ", "CD-ROM CDS-525  ", ""},     PQUIRK_NOLUNS},
    411 	{{T_CDROM, T_REMOV,
    412 	 "CHINON  ", "CD-ROM CDS-535  ", ""},     PQUIRK_NOLUNS},
    413 	{{T_CDROM, T_REMOV,
    414 	 "DEC     ", "RRD42   (C) DEC ", ""},     PQUIRK_NOLUNS},
    415 	{{T_CDROM, T_REMOV,
    416 	 "DENON   ", "DRD-25X         ", "V"},    PQUIRK_NOLUNS},
    417 	{{T_CDROM, T_REMOV,
    418 	 "GENERIC ", "CRD-BP2         ", ""},     PQUIRK_NOLUNS},
    419 	{{T_CDROM, T_REMOV,
    420 	 "HP      ", "C4324/C4325     ", ""},     PQUIRK_NOLUNS},
    421 	{{T_CDROM, T_REMOV,
    422 	 "IMS     ", "CDD521/10       ", "2.06"}, PQUIRK_NOLUNS},
    423 	{{T_CDROM, T_REMOV,
    424 	 "MATSHITA", "CD-ROM CR-5XX   ", "1.0b"}, PQUIRK_NOLUNS},
    425 	{{T_CDROM, T_REMOV,
    426 	 "MEDAVIS ", "RENO CD-ROMX2A  ", ""},     PQUIRK_NOLUNS},
    427 	{{T_CDROM, T_REMOV,
    428 	 "MEDIAVIS", "CDR-H93MV       ", "1.3"},  PQUIRK_NOLUNS},
    429 	{{T_CDROM, T_REMOV,
    430 	 "NEC     ", "CD-ROM DRIVE:55 ", ""},     PQUIRK_NOLUNS},
    431 	{{T_CDROM, T_REMOV,
    432 	 "NEC     ", "CD-ROM DRIVE:83 ", ""},     PQUIRK_NOLUNS},
    433 	{{T_CDROM, T_REMOV,
    434 	 "NEC     ", "CD-ROM DRIVE:84 ", ""},     PQUIRK_NOLUNS},
    435 	{{T_CDROM, T_REMOV,
    436 	 "NEC     ", "CD-ROM DRIVE:841", ""},     PQUIRK_NOLUNS},
    437 	{{T_CDROM, T_REMOV,
    438 	 "PIONEER ", "CD-ROM DR-124X  ", "1.01"}, PQUIRK_NOLUNS},
    439 	{{T_CDROM, T_REMOV,
    440 	 "SONY    ", "CD-ROM CDU-541  ", ""},     PQUIRK_NOLUNS},
    441 	{{T_CDROM, T_REMOV,
    442 	 "SONY    ", "CD-ROM CDU-55S  ", ""},     PQUIRK_NOLUNS},
    443 	{{T_CDROM, T_REMOV,
    444 	 "SONY    ", "CD-ROM CDU-561  ", ""},     PQUIRK_NOLUNS},
    445 	{{T_CDROM, T_REMOV,
    446 	 "SONY    ", "CD-ROM CDU-8003A", ""},     PQUIRK_NOLUNS},
    447 	{{T_CDROM, T_REMOV,
    448 	 "SONY    ", "CD-ROM CDU-8012 ", ""},     PQUIRK_NOLUNS},
    449 	{{T_CDROM, T_REMOV,
    450 	 "TEAC    ", "CD-ROM          ", "1.06"}, PQUIRK_NOLUNS},
    451 	{{T_CDROM, T_REMOV,
    452 	 "TEAC    ", "CD-ROM CD-56S   ", "1.0B"}, PQUIRK_NOLUNS},
    453 	{{T_CDROM, T_REMOV,
    454 	 "TEXEL   ", "CD-ROM          ", "1.06"}, PQUIRK_NOLUNS},
    455 	{{T_CDROM, T_REMOV,
    456 	 "TEXEL   ", "CD-ROM DM-XX24 K", "1.09"}, PQUIRK_NOLUNS},
    457 	{{T_CDROM, T_REMOV,
    458 	 "TEXEL   ", "CD-ROM DM-XX24 K", "1.10"}, PQUIRK_NOLUNS},
    459 	{{T_CDROM, T_REMOV,
    460 	 "TOSHIBA ", "XM-4101TASUNSLCD", "1755"}, PQUIRK_NOLUNS|PQUIRK_NOSYNC},
    461 	/* "IBM CDRM00201     !F" 0724 is an IBM OEM Toshiba XM-4101BME */
    462 	{{T_CDROM, T_REMOV,
    463 	 "IBM     ", "CDRM00201     !F", "0724"}, PQUIRK_NOLUNS|PQUIRK_NOSYNC},
    464 	{{T_CDROM, T_REMOV,
    465 	 "ShinaKen", "CD-ROM DM-3x1S",   "1.04"}, PQUIRK_NOLUNS},
    466 	{{T_CDROM, T_REMOV,
    467 	 "JVC     ", "R2626",            ""},     PQUIRK_NOLUNS},
    468 	{{T_CDROM, T_REMOV,
    469 	 "YAMAHA", "CRW8424S",           ""},     PQUIRK_NOLUNS},
    470 	{{T_CDROM, T_REMOV,
    471 	 "VMware", "Virtual",            "1.0"},
    472 				PQUIRK_NOSTARTUNIT|PQUIRK_NODOORLOCK},
    473 	{{T_CDROM, T_REMOV,
    474 	 "LITE-ON", "LTR-12101B",        "LS38"}, PQUIRK_ONLYBIG},
    475 
    476 	{{T_DIRECT, T_FIXED,
    477 	 "MICROP  ", "1588-15MBSUN0669", ""},     PQUIRK_AUTOSAVE},
    478 	{{T_DIRECT, T_FIXED,
    479 	 "MICROP  ", "2217-15MQ1091501", ""},     PQUIRK_NOSYNCCACHE},
    480 	{{T_OPTICAL, T_REMOV,
    481 	 "EPSON   ", "OMD-5010        ", "3.08"}, PQUIRK_NOLUNS},
    482 	{{T_DIRECT, T_FIXED,
    483 	 "TOSHIBA ","CD-ROM XM-3401TA",  "0283"}, PQUIRK_CDROM|PQUIRK_NOLUNS},
    484 	{{T_DIRECT, T_FIXED,
    485 	 "TOSHIBA ", "CD-ROM DRIVE:XM",  "1971"}, PQUIRK_CDROM|PQUIRK_NOLUNS},
    486 	{{T_DIRECT, T_FIXED,
    487 	 "ADAPTEC ", "AEC-4412BD",       "1.2A"}, PQUIRK_NOMODESENSE},
    488 	{{T_DIRECT, T_FIXED,
    489 	 "DEC     ", "RZ55     (C) DEC", ""},     PQUIRK_AUTOSAVE},
    490 	{{T_DIRECT, T_FIXED,
    491 	 "EMULEX  ", "MD21/S2     ESDI", "A00"},
    492 				PQUIRK_FORCELUNS|PQUIRK_AUTOSAVE},
    493 	/* Gives non-media hardware failure in response to start-unit command */
    494 	{{T_DIRECT, T_FIXED,
    495 	 "HITACHI", "DK515C",            "CP16"}, PQUIRK_NOSTARTUNIT},
    496 	{{T_DIRECT, T_FIXED,
    497 	 "HITACHI", "DK515C",            "CP15"}, PQUIRK_NOSTARTUNIT},
    498 	{{T_DIRECT, T_FIXED,
    499 	 "MICROP",  "1548-15MZ1077801",  "HZ2P"}, PQUIRK_NOTAG},
    500 	{{T_DIRECT, T_FIXED,
    501 	 "HP      ", "C372",             ""},     PQUIRK_NOTAG},
    502 	{{T_DIRECT, T_FIXED,
    503 	 "IBMRAID ", "0662S",		 ""},     PQUIRK_AUTOSAVE},
    504 	{{T_DIRECT, T_FIXED,
    505 	 "IBM     ", "0663H",		 ""},     PQUIRK_AUTOSAVE},
    506 	{{T_DIRECT, T_FIXED,
    507 	 "IBM",	     "0664",		 ""},     PQUIRK_AUTOSAVE},
    508 	{{T_DIRECT, T_FIXED,
    509 	 "IBM     ", "H3171-S2",	 ""},
    510 				PQUIRK_NOLUNS|PQUIRK_AUTOSAVE},
    511 	{{T_DIRECT, T_FIXED,
    512 	 "IBM     ", "KZ-C",		 ""},	  PQUIRK_AUTOSAVE},
    513 	/* Broken IBM disk */
    514 	{{T_DIRECT, T_FIXED,
    515 	 ""	   , "DFRSS2F",		 ""},	  PQUIRK_AUTOSAVE},
    516 	{{T_DIRECT, T_REMOV,
    517 	 "MPL     ", "MC-DISK-        ", ""},     PQUIRK_NOLUNS},
    518 	{{T_DIRECT, T_FIXED,
    519 	 "MAXTOR  ", "XT-3280         ", ""},     PQUIRK_NOLUNS},
    520 	{{T_DIRECT, T_FIXED,
    521 	 "MAXTOR  ", "XT-4380S        ", ""},     PQUIRK_NOLUNS},
    522 	{{T_DIRECT, T_FIXED,
    523 	 "MAXTOR  ", "MXT-1240S       ", ""},     PQUIRK_NOLUNS},
    524 	{{T_DIRECT, T_FIXED,
    525 	 "MAXTOR  ", "XT-4170S        ", ""},     PQUIRK_NOLUNS},
    526 	{{T_DIRECT, T_FIXED,
    527 	 "MAXTOR  ", "XT-8760S",         ""},     PQUIRK_NOLUNS},
    528 	{{T_DIRECT, T_FIXED,
    529 	 "MAXTOR  ", "LXT-213S        ", ""},     PQUIRK_NOLUNS},
    530 	{{T_DIRECT, T_FIXED,
    531 	 "MAXTOR  ", "LXT-213S SUN0207", ""},     PQUIRK_NOLUNS},
    532 	{{T_DIRECT, T_FIXED,
    533 	 "MAXTOR  ", "LXT-200S        ", ""},     PQUIRK_NOLUNS},
    534 	{{T_DIRECT, T_FIXED,
    535 	 "MEGADRV ", "EV1000",           ""},     PQUIRK_NOMODESENSE},
    536 	{{T_DIRECT, T_FIXED,
    537 	 "MST     ", "SnapLink        ", ""},     PQUIRK_NOLUNS},
    538 	{{T_DIRECT, T_FIXED,
    539 	 "NEC     ", "D3847           ", "0307"}, PQUIRK_NOLUNS},
    540 	{{T_DIRECT, T_FIXED,
    541 	 "QUANTUM ", "ELS85S          ", ""},     PQUIRK_AUTOSAVE},
    542 	{{T_DIRECT, T_FIXED,
    543 	 "QUANTUM ", "LPS525S         ", ""},     PQUIRK_NOLUNS},
    544 	{{T_DIRECT, T_FIXED,
    545 	 "QUANTUM ", "P105S 910-10-94x", ""},     PQUIRK_NOLUNS},
    546 	{{T_DIRECT, T_FIXED,
    547 	 "QUANTUM ", "PD1225S         ", ""},     PQUIRK_NOLUNS},
    548 	{{T_DIRECT, T_FIXED,
    549 	 "QUANTUM ", "PD210S   SUN0207", ""},     PQUIRK_NOLUNS},
    550 	{{T_DIRECT, T_FIXED,
    551 	 "RODIME  ", "RO3000S         ", ""},     PQUIRK_NOLUNS},
    552 	{{T_DIRECT, T_FIXED,
    553 	 "SEAGATE ", "ST125N          ", ""},     PQUIRK_NOLUNS},
    554 	{{T_DIRECT, T_FIXED,
    555 	 "SEAGATE ", "ST157N          ", ""},     PQUIRK_NOLUNS},
    556 	{{T_DIRECT, T_FIXED,
    557 	 "SEAGATE ", "ST296           ", ""},     PQUIRK_NOLUNS},
    558 	{{T_DIRECT, T_FIXED,
    559 	 "SEAGATE ", "ST296N          ", ""},     PQUIRK_NOLUNS},
    560 	{{T_DIRECT, T_FIXED,
    561 	 "SEAGATE ", "ST15150N        ", ""},     PQUIRK_NOTAG},
    562 	{{T_DIRECT, T_FIXED,
    563 	 "SEAGATE ", "ST19171",          ""},     PQUIRK_NOMODESENSE},
    564 	{{T_DIRECT, T_FIXED,
    565 	 "SEAGATE ", "ST32430N",         ""},     PQUIRK_CAP_SYNC},
    566 	{{T_DIRECT, T_FIXED,
    567 	 "SEAGATE ", "ST34501FC       ", ""},     PQUIRK_NOMODESENSE},
    568 	{{T_DIRECT, T_FIXED,
    569 	 "TOSHIBA ", "MK538FB         ", "6027"}, PQUIRK_NOLUNS},
    570 	{{T_DIRECT, T_FIXED,
    571 	 "VMware", "Virtual",           "1.0"},
    572 				PQUIRK_NOSTARTUNIT|PQUIRK_NODOORLOCK},
    573 
    574 	{{T_DIRECT, T_REMOV,
    575 	 "iomega", "jaz 1GB", 		 ""},	  PQUIRK_NOMODESENSE},
    576 	{{T_DIRECT, T_REMOV,
    577 	 "IOMEGA", "ZIP 100",		 ""},	  PQUIRK_NOMODESENSE},
    578 	{{T_DIRECT, T_REMOV,
    579 	 "IOMEGA", "ZIP 100",		 "J.03"},
    580 				PQUIRK_NOMODESENSE|PQUIRK_NOLUNS},
    581 	/* Letting the motor run kills floppy drives and disks quite fast. */
    582 	{{T_DIRECT, T_REMOV,
    583 	 "TEAC", "FC-1",		 ""},	  PQUIRK_NOSTARTUNIT},
    584 
    585 	{{T_DIRECT, T_REMOV,
    586 	 "Y-E DATA", "USB-FDU",          "3.04"}, PQUIRK_NOMODESENSE},
    587 	{{T_DIRECT, T_REMOV,
    588 	 "TEAC", "FD-05PUB",             "1026"}, PQUIRK_NOMODESENSE},
    589 	{{T_DIRECT, T_REMOV,
    590 	 "M-Sys", "DiskOnKey",           "2.01"}, PQUIRK_NOMODESENSE
    591 	      | PQUIRK_NODOORLOCK | PQUIRK_ONLYBIG | PQUIRK_NOBIGMODESENSE},
    592 	{{T_DIRECT, T_REMOV,
    593 	 "INSITE", "I325VM",             ""},
    594 				PQUIRK_NOLUNS|PQUIRK_NODOORLOCK},
    595 
    596 	/* XXX: QIC-36 tape behind Emulex adapter.  Very broken. */
    597 	{{T_SEQUENTIAL, T_REMOV,
    598 	 "        ", "                ", "    "}, PQUIRK_NOLUNS},
    599 	{{T_SEQUENTIAL, T_REMOV,
    600 	 "CALIPER ", "CP150           ", ""},     PQUIRK_NOLUNS},
    601 	{{T_SEQUENTIAL, T_REMOV,
    602 	 "EXABYTE ", "EXB-8200        ", ""},     PQUIRK_NOLUNS},
    603 	{{T_SEQUENTIAL, T_REMOV,
    604 	 "SONY    ", "GY-10C          ", ""},     PQUIRK_NOLUNS},
    605 	{{T_SEQUENTIAL, T_REMOV,
    606 	 "SONY    ", "SDT-2000        ", "2.09"}, PQUIRK_NOLUNS},
    607 	{{T_SEQUENTIAL, T_REMOV,
    608 	 "SONY    ", "SDT-5000        ", "3."},   PQUIRK_NOSYNC|PQUIRK_NOWIDE},
    609 	{{T_SEQUENTIAL, T_REMOV,
    610 	 "SONY    ", "SDT-5200        ", "3."},   PQUIRK_NOLUNS},
    611 	{{T_SEQUENTIAL, T_REMOV,
    612 	 "TANDBERG", " TDC 3600       ", ""},     PQUIRK_NOLUNS},
    613 	/* Following entry reported as a Tandberg 3600; ref. PR1933 */
    614 	{{T_SEQUENTIAL, T_REMOV,
    615 	 "ARCHIVE ", "VIPER 150  21247", ""},     PQUIRK_NOLUNS},
    616 	/* Following entry for a Cipher ST150S; ref. PR4171 */
    617 	{{T_SEQUENTIAL, T_REMOV,
    618 	 "ARCHIVE ", "VIPER 1500 21247", "2.2G"}, PQUIRK_NOLUNS},
    619 	{{T_SEQUENTIAL, T_REMOV,
    620 	 "ARCHIVE ", "Python 28454-XXX", ""},     PQUIRK_NOLUNS},
    621 	{{T_SEQUENTIAL, T_REMOV,
    622 	 "WANGTEK ", "5099ES SCSI",      ""},     PQUIRK_NOLUNS},
    623 	{{T_SEQUENTIAL, T_REMOV,
    624 	 "WANGTEK ", "5150ES SCSI",      ""},     PQUIRK_NOLUNS},
    625 	{{T_SEQUENTIAL, T_REMOV,
    626 	 "WANGTEK ", "SCSI-36",		 ""},     PQUIRK_NOLUNS},
    627 	{{T_SEQUENTIAL, T_REMOV,
    628 	 "WangDAT ", "Model 1300      ", "02.4"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
    629 	{{T_SEQUENTIAL, T_REMOV,
    630 	 "WangDAT ", "Model 2600      ", "01.7"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
    631 	{{T_SEQUENTIAL, T_REMOV,
    632 	 "WangDAT ", "Model 3200      ", "02.2"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
    633 	{{T_SEQUENTIAL, T_REMOV,
    634 	 "TEAC    ", "MT-2ST/N50      ", ""},     PQUIRK_NOLUNS},
    635 
    636 	{{T_SCANNER, T_FIXED,
    637 	 "RICOH   ", "IS60            ", "1R08"}, PQUIRK_NOLUNS},
    638 	{{T_SCANNER, T_FIXED,
    639 	 "UMAX    ", "Astra 1200S     ", "V2.9"}, PQUIRK_NOLUNS},
    640 	{{T_SCANNER, T_FIXED,
    641 	 "UMAX    ", "Astra 1220S     ", ""},     PQUIRK_NOLUNS},
    642 	{{T_SCANNER, T_FIXED,
    643 	 "UMAX    ", "UMAX S-6E       ", "V2.0"}, PQUIRK_NOLUNS},
    644 	{{T_SCANNER, T_FIXED,
    645 	 "UMAX    ", "UMAX S-12       ", "V2.1"}, PQUIRK_NOLUNS},
    646 	{{T_SCANNER, T_FIXED,
    647 	 "ULTIMA  ", "A6000C          ", ""},     PQUIRK_NOLUNS},
    648 	{{T_PROCESSOR, T_FIXED,
    649 	 "SYMBIOS",  "",                 ""},     PQUIRK_NOLUNS},
    650 	{{T_PROCESSOR, T_FIXED,
    651 	 "LITRONIC", "PCMCIA          ", ""},     PQUIRK_NOLUNS},
    652 	{{T_CHANGER, T_REMOV,
    653 	 "SONY    ", "CDL1100         ", ""},     PQUIRK_NOLUNS},
    654 	{{T_ENCLOSURE, T_FIXED,
    655 	 "SUN     ", "SENA            ", ""},     PQUIRK_NOLUNS},
    656 };
    657 
    658 /*
    659  * given a target and lun, ask the device what
    660  * it is, and find the correct driver table
    661  * entry.
    662  */
    663 int
    664 scsi_probe_device(sc, target, lun)
    665 	struct scsibus_softc *sc;
    666 	int target, lun;
    667 {
    668 	struct scsipi_channel *chan = sc->sc_channel;
    669 	struct scsipi_periph *periph;
    670 	struct scsipi_inquiry_data inqbuf;
    671 	struct scsi_quirk_inquiry_pattern *finger;
    672 	int checkdtype, priority, docontinue, quirks;
    673 	struct scsipibus_attach_args sa;
    674 	struct cfdata *cf;
    675 
    676 	/*
    677 	 * Assume no more luns to search after this one.
    678 	 * If we successfully get Inquiry data and after
    679 	 * merging quirks we find we can probe for more
    680 	 * luns, we will.
    681 	 */
    682 	docontinue = 0;
    683 
    684 	/* Skip this slot if it is already attached. */
    685 	if (scsipi_lookup_periph(chan, target, lun) != NULL)
    686 		return (docontinue);
    687 
    688 	periph = scsipi_alloc_periph(M_NOWAIT);
    689 	if (periph == NULL) {
    690 #ifdef	DIAGNOSTIC
    691 		printf("%s: cannot allocate periph for target %d lun %d\n",
    692 		    sc->sc_dev.dv_xname, target, lun);
    693 #endif
    694 		return (ENOMEM);
    695 	}
    696 	periph->periph_channel = chan;
    697 	periph->periph_switch = &scsi_probe_dev;
    698 
    699 	periph->periph_target = target;
    700 	periph->periph_lun = lun;
    701 	periph->periph_quirks = chan->chan_defquirks;
    702 
    703 #ifdef SCSIPI_DEBUG
    704 	if (SCSIPI_DEBUG_TYPE == SCSIPI_BUSTYPE_SCSI &&
    705 	    SCSIPI_DEBUG_TARGET == target &&
    706 	    SCSIPI_DEBUG_LUN == lun)
    707 		periph->periph_dbflags |= SCSIPI_DEBUG_FLAGS;
    708 #endif
    709 
    710 	/*
    711 	 * Ask the device what it is
    712 	 */
    713 	(void) scsipi_test_unit_ready(periph,
    714 	    XS_CTL_DISCOVERY | XS_CTL_IGNORE_ILLEGAL_REQUEST |
    715 	    XS_CTL_IGNORE_NOT_READY | XS_CTL_IGNORE_MEDIA_CHANGE);
    716 
    717 #ifdef SCSI_2_DEF
    718 	/* some devices need to be told to go to SCSI2 */
    719 	/* However some just explode if you tell them this.. leave it out */
    720 	scsi_change_def(periph, XS_CTL_DISCOVERY | XS_CTL_SILENT);
    721 #endif /* SCSI_2_DEF */
    722 
    723 	/* Now go ask the device all about itself. */
    724 	memset(&inqbuf, 0, sizeof(inqbuf));
    725 	if (scsipi_inquire(periph, &inqbuf,
    726 	    XS_CTL_DISCOVERY | XS_CTL_DATA_ONSTACK) != 0)
    727 		goto bad;
    728 	{
    729 		u_int8_t *extension = &inqbuf.flags1;
    730 		int len = inqbuf.additional_length;
    731 		while (len < 3)
    732 			extension[len++] = '\0';
    733 		while (len < 3 + 28)
    734 			extension[len++] = ' ';
    735 		while (len < 3 + 28 + 20)
    736 			extension[len++] = '\0';
    737 		while (len < 3 + 28 + 20 + 1)
    738 			extension[len++] = '\0';
    739 		while (len < 3 + 28 + 20 + 1 + 1)
    740 			extension[len++] = '\0';
    741 		while (len < 3 + 28 + 20 + 1 + 1 + (8*2))
    742 			extension[len++] = ' ';
    743 	}
    744 
    745 	periph->periph_type = inqbuf.device & SID_TYPE;
    746 	if (inqbuf.dev_qual2 & SID_REMOVABLE)
    747 		periph->periph_flags |= PERIPH_REMOVABLE;
    748 	periph->periph_version = inqbuf.version & SID_ANSII;
    749 
    750 	/*
    751 	 * Any device qualifier that has the top bit set (qualifier&4 != 0)
    752 	 * is vendor specific and won't match in this switch.
    753 	 * All we do here is throw out bad/negative responses.
    754 	 */
    755 	checkdtype = 0;
    756 	switch (inqbuf.device & SID_QUAL) {
    757 	case SID_QUAL_LU_PRESENT:
    758 	case SID_QUAL_LU_NOTPRESENT:
    759 		checkdtype = 1;
    760 		break;
    761 
    762 	case SID_QUAL_reserved:
    763 	case SID_QUAL_LU_NOT_SUPP:
    764 		goto bad;
    765 
    766 	default:
    767 		break;
    768 	}
    769 
    770 	/* Let the adapter driver handle the device separatley if it wants. */
    771 	if (chan->chan_adapter->adapt_accesschk != NULL &&
    772 	    (*chan->chan_adapter->adapt_accesschk)(periph, &sa.sa_inqbuf))
    773 		goto bad;
    774 
    775 	if (checkdtype) {
    776 		switch (periph->periph_type) {
    777 		case T_DIRECT:
    778 		case T_SEQUENTIAL:
    779 		case T_PRINTER:
    780 		case T_PROCESSOR:
    781 		case T_WORM:
    782 		case T_CDROM:
    783 		case T_SCANNER:
    784 		case T_OPTICAL:
    785 		case T_CHANGER:
    786 		case T_COMM:
    787 		case T_IT8_1:
    788 		case T_IT8_2:
    789 		case T_STORARRAY:
    790 		case T_ENCLOSURE:
    791 		case T_SIMPLE_DIRECT:
    792 		case T_OPTIC_CARD_RW:
    793 		case T_OBJECT_STORED:
    794 		default:
    795 			break;
    796 		case T_NODEVICE:
    797 			goto bad;
    798 		}
    799 	}
    800 
    801 	sa.sa_periph = periph;
    802 	sa.sa_inqbuf.type = inqbuf.device;
    803 	sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ?
    804 	    T_REMOV : T_FIXED;
    805 	sa.sa_inqbuf.vendor = inqbuf.vendor;
    806 	sa.sa_inqbuf.product = inqbuf.product;
    807 	sa.sa_inqbuf.revision = inqbuf.revision;
    808 	sa.scsipi_info.scsi_version = inqbuf.version;
    809 	sa.sa_inqptr = &inqbuf;
    810 
    811 	finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
    812 	    &sa.sa_inqbuf, (caddr_t)scsi_quirk_patterns,
    813 	    sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
    814 	    sizeof(scsi_quirk_patterns[0]), &priority);
    815 
    816 	if (finger != NULL)
    817 		quirks = finger->quirks;
    818 	else
    819 		quirks = 0;
    820 
    821 	/*
    822 	 * Determine the operating mode capabilities of the device.
    823 	 */
    824 	if (periph->periph_version >= 2) {
    825 		if ((inqbuf.flags3 & SID_CmdQue) != 0 &&
    826 		    (quirks & PQUIRK_NOTAG) == 0)
    827 			periph->periph_cap |= PERIPH_CAP_TQING;
    828 		if ((inqbuf.flags3 & SID_Linked) != 0)
    829 			periph->periph_cap |= PERIPH_CAP_LINKCMDS;
    830 		if ((inqbuf.flags3 & SID_Sync) != 0 &&
    831 		    (quirks & PQUIRK_NOSYNC) == 0)
    832 			periph->periph_cap |= PERIPH_CAP_SYNC;
    833 		if ((inqbuf.flags3 & SID_WBus16) != 0 &&
    834 		    (quirks & PQUIRK_NOWIDE) == 0)
    835 			periph->periph_cap |= PERIPH_CAP_WIDE16;
    836 		if ((inqbuf.flags3 & SID_WBus32) != 0 &&
    837 		    (quirks & PQUIRK_NOWIDE) == 0)
    838 			periph->periph_cap |= PERIPH_CAP_WIDE32;
    839 		if ((inqbuf.flags3 & SID_SftRe) != 0)
    840 			periph->periph_cap |= PERIPH_CAP_SFTRESET;
    841 		if ((inqbuf.flags3 & SID_RelAdr) != 0)
    842 			periph->periph_cap |= PERIPH_CAP_RELADR;
    843 	} else {
    844 		if (quirks & PQUIRK_CAP_SYNC)
    845 			periph->periph_cap |= PERIPH_CAP_SYNC;
    846 	}
    847 
    848 	/*
    849 	 * Now apply any quirks from the table.
    850 	 */
    851 	periph->periph_quirks |= quirks;
    852 	if (periph->periph_version == 0 &&
    853 	    (periph->periph_quirks & PQUIRK_FORCELUNS) == 0)
    854 		periph->periph_quirks |= PQUIRK_NOLUNS;
    855 
    856 	if (periph->periph_quirks & PQUIRK_CDROM) {
    857 		periph->periph_quirks ^= PQUIRK_CDROM;
    858 		inqbuf.dev_qual2 |= SID_REMOVABLE;
    859 		sa.sa_inqbuf.type = inqbuf.device =
    860 		    ((inqbuf.device & ~SID_REMOVABLE) | T_CDROM);
    861 		sa.sa_inqbuf.removable = T_REMOV;
    862 	}
    863 
    864 	if ((periph->periph_quirks & PQUIRK_NOLUNS) == 0)
    865 		docontinue = 1;
    866 
    867 	if ((cf = config_search(scsibussubmatch, &sc->sc_dev, &sa)) != NULL) {
    868 		scsipi_insert_periph(chan, periph);
    869 		/*
    870 		 * XXX Can't assign periph_dev here, because we'll
    871 		 * XXX need it before config_attach() returns.  Must
    872 		 * XXX assign it in periph driver.
    873 		 */
    874 		(void) config_attach(&sc->sc_dev, cf, &sa, scsibusprint);
    875 	} else {
    876 		scsibusprint(&sa, sc->sc_dev.dv_xname);
    877 		printf(" not configured\n");
    878 		goto bad;
    879 	}
    880 
    881 	return (docontinue);
    882 
    883 bad:
    884 	free(periph, M_DEVBUF);
    885 	return (docontinue);
    886 }
    887 
    888 /****** Entry points for user control of the SCSI bus. ******/
    889 
    890 int
    891 scsibusopen(dev, flag, fmt, p)
    892 	dev_t dev;
    893 	int flag, fmt;
    894 	struct proc *p;
    895 {
    896 	struct scsibus_softc *sc;
    897 	int error, unit = minor(dev);
    898 
    899 	if (unit >= scsibus_cd.cd_ndevs ||
    900 	    (sc = scsibus_cd.cd_devs[unit]) == NULL)
    901 		return (ENXIO);
    902 
    903 	if (sc->sc_flags & SCSIBUSF_OPEN)
    904 		return (EBUSY);
    905 
    906 	if ((error = scsipi_adapter_addref(sc->sc_channel->chan_adapter)) != 0)
    907 		return (error);
    908 
    909 	sc->sc_flags |= SCSIBUSF_OPEN;
    910 
    911 	return (0);
    912 }
    913 
    914 int
    915 scsibusclose(dev, flag, fmt, p)
    916 	dev_t dev;
    917 	int flag, fmt;
    918 	struct proc *p;
    919 {
    920 	struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
    921 
    922 	scsipi_adapter_delref(sc->sc_channel->chan_adapter);
    923 
    924 	sc->sc_flags &= ~SCSIBUSF_OPEN;
    925 
    926 	return (0);
    927 }
    928 
    929 int
    930 scsibusioctl(dev, cmd, addr, flag, p)
    931 	dev_t dev;
    932 	u_long cmd;
    933 	caddr_t addr;
    934 	int flag;
    935 	struct proc *p;
    936 {
    937 	struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
    938 	struct scsipi_channel *chan = sc->sc_channel;
    939 	int error;
    940 
    941 	/*
    942 	 * Enforce write permission for ioctls that change the
    943 	 * state of the bus.  Host adapter specific ioctls must
    944 	 * be checked by the adapter driver.
    945 	 */
    946 	switch (cmd) {
    947 	case SCBUSIOSCAN:
    948 	case SCBUSIODETACH:
    949 	case SCBUSIORESET:
    950 		if ((flag & FWRITE) == 0)
    951 			return (EBADF);
    952 	}
    953 
    954 	switch (cmd) {
    955 	case SCBUSIOSCAN:
    956 	    {
    957 		struct scbusioscan_args *a =
    958 		    (struct scbusioscan_args *)addr;
    959 
    960 		error = scsi_probe_bus(sc, a->sa_target, a->sa_lun);
    961 		break;
    962 	    }
    963 
    964 	case SCBUSIODETACH:
    965 	    {
    966 		struct scbusiodetach_args *a =
    967 		    (struct scbusiodetach_args *)addr;
    968 
    969 		error = scsipi_target_detach(chan, a->sa_target, a->sa_lun, 0);
    970 		break;
    971 	    }
    972 
    973 
    974 	case SCBUSIORESET:
    975 		/* FALLTHROUGH */
    976 	default:
    977 		if (chan->chan_adapter->adapt_ioctl == NULL)
    978 			error = ENOTTY;
    979 		else
    980 			error = (*chan->chan_adapter->adapt_ioctl)(chan,
    981 			    cmd, addr, flag, p);
    982 		break;
    983 	}
    984 
    985 	return (error);
    986 }
    987