Home | History | Annotate | Line # | Download | only in scsipi
scsiconf.c revision 1.119
      1 /*	$NetBSD: scsiconf.c,v 1.119 1998/12/05 19:39:23 mjacob Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 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/types.h>
     58 #include <sys/param.h>
     59 #include <sys/systm.h>
     60 #include <sys/malloc.h>
     61 #include <sys/device.h>
     62 #include <sys/conf.h>
     63 #include <sys/fcntl.h>
     64 #include <sys/scsiio.h>
     65 
     66 #include <dev/scsipi/scsi_all.h>
     67 #include <dev/scsipi/scsipi_all.h>
     68 #include <dev/scsipi/scsiconf.h>
     69 
     70 #include "locators.h"
     71 
     72 #if 0
     73 #if NCALS > 0
     74 	{ T_PROCESSOR, T_FIXED, 1,
     75 	  0, 0, 0 },
     76 #endif	/* NCALS */
     77 #if NBLL > 0
     78 	{ T_PROCESSOR, T_FIXED, 1,
     79 	  "AEG     ", "READER          ", "V1.0" },
     80 #endif	/* NBLL */
     81 #if NKIL > 0
     82 	{ T_SCANNER, T_FIXED, 0,
     83 	  "KODAK   ", "IL Scanner 900  ", 0 },
     84 #endif	/* NKIL */
     85 #endif
     86 
     87 /*
     88  * Declarations
     89  */
     90 int scsi_probedev __P((struct scsibus_softc *, int, int));
     91 int scsi_probe_bus __P((int bus, int target, int lun));
     92 
     93 struct scsipi_device probe_switch = {
     94 	NULL,
     95 	NULL,
     96 	NULL,
     97 	NULL,
     98 };
     99 
    100 int scsibusmatch __P((struct device *, struct cfdata *, void *));
    101 void scsibusattach __P((struct device *, struct device *, void *));
    102 int scsibussubmatch __P((struct device *, struct cfdata *, void *));
    103 
    104 struct cfattach scsibus_ca = {
    105 	sizeof(struct scsibus_softc), scsibusmatch, scsibusattach
    106 };
    107 
    108 extern struct cfdriver scsibus_cd;
    109 
    110 int scsibusprint __P((void *, const char *));
    111 
    112 cdev_decl(scsibus);
    113 
    114 int
    115 scsiprint(aux, pnp)
    116 	void *aux;
    117 	const char *pnp;
    118 {
    119 	struct scsipi_link *l = aux;
    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 (l->scsipi_scsi.channel != SCSI_CHANNEL_ONLY_ONE)
    127 		printf(" channel %d", l->scsipi_scsi.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_link *l = aux;
    139 	int channel;
    140 
    141 	/*
    142 	 * Allow single-channel controllers to specify their channel
    143 	 * in a special way, so that it's not printed.
    144 	 */
    145 	channel = (l->scsipi_scsi.channel != SCSI_CHANNEL_ONLY_ONE) ?
    146 	    l->scsipi_scsi.channel : 0;
    147 
    148 	if (cf->cf_loc[SCSICF_CHANNEL] != channel &&
    149 	    cf->cf_loc[SCSICF_CHANNEL] != SCSICF_CHANNEL_DEFAULT)
    150 		return (0);
    151 
    152 	return (1);
    153 }
    154 
    155 /*
    156  * The routine called by the adapter boards to get all their
    157  * devices configured in.
    158  */
    159 void
    160 scsibusattach(parent, self, aux)
    161 	struct device *parent, *self;
    162 	void *aux;
    163 {
    164 	struct scsibus_softc *sb = (struct scsibus_softc *)self;
    165 	struct scsipi_link *sc_link_proto = aux;
    166 	size_t nbytes;
    167 	int i;
    168 
    169 	sc_link_proto->scsipi_scsi.scsibus = sb->sc_dev.dv_unit;
    170 	sc_link_proto->scsipi_cmd = scsi_scsipi_cmd;
    171 	sc_link_proto->scsipi_interpret_sense = scsipi_interpret_sense;
    172 	sc_link_proto->sc_print_addr = scsi_print_addr;
    173 
    174 	sb->adapter_link = sc_link_proto;
    175 	sb->sc_maxtarget = sc_link_proto->scsipi_scsi.max_target;
    176 	sb->sc_maxlun = sc_link_proto->scsipi_scsi.max_lun;
    177 	printf(": %d targets, %d luns per target\n",
    178 	    sb->sc_maxtarget + 1, sb->sc_maxlun + 1);
    179 
    180 	/* Initialize shared data. */
    181 	scsipi_init();
    182 
    183 	nbytes = (sb->sc_maxtarget + 1) * sizeof(struct scsipi_link **);
    184 	sb->sc_link = (struct scsipi_link ***)malloc(nbytes, M_DEVBUF,
    185 	    M_NOWAIT);
    186 	if (sb->sc_link == NULL)
    187 		panic("scsibusattach: can't allocate target links");
    188 
    189 	nbytes = (((int) sb->sc_maxlun) + 1) * sizeof(struct scsipi_link *);
    190 	for (i = 0; i <= sb->sc_maxtarget; i++) {
    191 		sb->sc_link[i] = (struct scsipi_link **)malloc(nbytes,
    192 		    M_DEVBUF, M_NOWAIT);
    193 		if (sb->sc_link[i] == NULL)
    194 			panic("scsibusattach: can't allocate lun links");
    195 		bzero(sb->sc_link[i], nbytes);
    196 	}
    197 
    198 #if defined(SCSI_DELAY) && SCSI_DELAY > 2
    199 	printf("%s: waiting for scsi devices to settle\n",
    200 	    sb->sc_dev.dv_xname);
    201 #else	/* SCSI_DELAY > 2 */
    202 #undef	SCSI_DELAY
    203 #define SCSI_DELAY 2
    204 #endif	/* SCSI_DELAY */
    205 	delay(1000000 * SCSI_DELAY);
    206 
    207 	scsi_probe_bus(sb->sc_dev.dv_unit, -1, -1);
    208 }
    209 
    210 int
    211 scsibussubmatch(parent, cf, aux)
    212 	struct device *parent;
    213 	struct cfdata *cf;
    214 	void *aux;
    215 {
    216 	struct scsipibus_attach_args *sa = aux;
    217 	struct scsipi_link *sc_link = sa->sa_sc_link;
    218 
    219 	if (cf->cf_loc[SCSIBUSCF_TARGET] != SCSIBUSCF_TARGET_DEFAULT &&
    220 	    cf->cf_loc[SCSIBUSCF_TARGET] != sc_link->scsipi_scsi.target)
    221 		return (0);
    222 	if (cf->cf_loc[SCSIBUSCF_LUN] != SCSIBUSCF_LUN_DEFAULT &&
    223 	    cf->cf_loc[SCSIBUSCF_LUN] != sc_link->scsipi_scsi.lun)
    224 		return (0);
    225 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    226 }
    227 
    228 /*
    229  * Probe the requested scsi bus. It must be already set up.
    230  * -1 requests all set up scsi busses.
    231  * target and lun optionally narrow the search if not -1
    232  */
    233 int
    234 scsi_probe_busses(bus, target, lun)
    235 	int bus, target, lun;
    236 {
    237 
    238 	if (bus == -1) {
    239 		for (bus = 0; bus < scsibus_cd.cd_ndevs; bus++)
    240 			if (scsibus_cd.cd_devs[bus])
    241 				scsi_probe_bus(bus, target, lun);
    242 		return (0);
    243 	} else
    244 		return (scsi_probe_bus(bus, target, lun));
    245 }
    246 
    247 /*
    248  * Probe the requested scsi bus. It must be already set up.
    249  * target and lun optionally narrow the search if not -1
    250  */
    251 int
    252 scsi_probe_bus(bus, target, lun)
    253 	int bus, target, lun;
    254 {
    255 	struct scsibus_softc *scsi;
    256 	int maxtarget, mintarget, maxlun, minlun;
    257 	u_int8_t scsi_addr;
    258 	int error;
    259 
    260 	if (bus < 0 || bus >= scsibus_cd.cd_ndevs)
    261 		return (ENXIO);
    262 	scsi = scsibus_cd.cd_devs[bus];
    263 	if (scsi == NULL)
    264 		return (ENXIO);
    265 
    266 	scsi_addr = scsi->adapter_link->scsipi_scsi.adapter_target;
    267 
    268 	if (target == -1) {
    269 		maxtarget = scsi->sc_maxtarget;
    270 		mintarget = 0;
    271 	} else {
    272 		if (target < 0 || target > scsi->sc_maxtarget)
    273 			return (EINVAL);
    274 		maxtarget = mintarget = target;
    275 	}
    276 
    277 	if (lun == -1) {
    278 		maxlun = scsi->sc_maxlun;
    279 		minlun = 0;
    280 	} else {
    281 		if (lun < 0 || lun > scsi->sc_maxlun)
    282 			return (EINVAL);
    283 		maxlun = minlun = lun;
    284 	}
    285 
    286 	if ((error = scsipi_adapter_addref(scsi->adapter_link)) != 0)
    287 		return (error);
    288 	for (target = mintarget; target <= maxtarget; target++) {
    289 		if (target == scsi_addr)
    290 			continue;
    291 		for (lun = minlun; lun <= maxlun; lun++) {
    292 			/*
    293 			 * See if there's a device present, and configure it.
    294 			 */
    295 			if (scsi_probedev(scsi, target, lun) == 0) {
    296 				break;
    297 			}
    298 			/* otherwise something says we should look further */
    299 		}
    300 	}
    301 	scsipi_adapter_delref(scsi->adapter_link);
    302 	return (0);
    303 }
    304 
    305 /*
    306  * Print out autoconfiguration information for a subdevice.
    307  *
    308  * This is a slight abuse of 'standard' autoconfiguration semantics,
    309  * because 'print' functions don't normally print the colon and
    310  * device information.  However, in this case that's better than
    311  * either printing redundant information before the attach message,
    312  * or having the device driver call a special function to print out
    313  * the standard device information.
    314  */
    315 int
    316 scsibusprint(aux, pnp)
    317 	void *aux;
    318 	const char *pnp;
    319 {
    320 	struct scsipibus_attach_args *sa = aux;
    321 	struct scsipi_inquiry_pattern *inqbuf;
    322 	u_int8_t type;
    323 	char *dtype, *qtype;
    324 	char vendor[33], product[65], revision[17];
    325 	int target, lun;
    326 
    327 	if (pnp != NULL)
    328 		printf("%s", pnp);
    329 
    330 	inqbuf = &sa->sa_inqbuf;
    331 
    332 	target = sa->sa_sc_link->scsipi_scsi.target;
    333 	lun = sa->sa_sc_link->scsipi_scsi.lun;
    334 
    335 	type = inqbuf->type & SID_TYPE;
    336 
    337 	/*
    338 	 * Figure out basic device type and qualifier.
    339 	 */
    340 	dtype = 0;
    341 	switch (inqbuf->type & SID_QUAL) {
    342 	case SID_QUAL_LU_OK:
    343 		qtype = "";
    344 		break;
    345 
    346 	case SID_QUAL_LU_OFFLINE:
    347 		qtype = " offline";
    348 		break;
    349 
    350 	case SID_QUAL_RSVD:
    351 	case SID_QUAL_BAD_LU:
    352 		panic("scsibusprint: impossible qualifier");
    353 
    354 	default:
    355 		qtype = "";
    356 		dtype = "vendor-unique";
    357 		break;
    358 	}
    359 	if (dtype == 0)
    360 		dtype = scsipi_dtype(type);
    361 
    362 	scsipi_strvis(vendor, 33, inqbuf->vendor, 8);
    363 	scsipi_strvis(product, 65, inqbuf->product, 16);
    364 	scsipi_strvis(revision, 17, inqbuf->revision, 4);
    365 
    366 	printf(" targ %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s",
    367 	    target, lun, vendor, product, revision,
    368 	    sa->scsipi_info.scsi_version & SID_ANSII, type, dtype,
    369 	    inqbuf->removable ? "removable" : "fixed", qtype);
    370 
    371 	return (UNCONF);
    372 }
    373 
    374 struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
    375 	{{T_CDROM, T_REMOV,
    376 	 "CHINON  ", "CD-ROM CDS-431  ", ""},     SDEV_NOLUNS},
    377 	{{T_CDROM, T_REMOV,
    378 	 "Chinon  ", "CD-ROM CDS-525  ", ""},     SDEV_NOLUNS},
    379 	{{T_CDROM, T_REMOV,
    380 	 "CHINON  ", "CD-ROM CDS-535  ", ""},     SDEV_NOLUNS},
    381 	{{T_CDROM, T_REMOV,
    382 	 "DEC     ", "RRD42   (C) DEC ", ""},     SDEV_NOLUNS},
    383 	{{T_CDROM, T_REMOV,
    384 	 "DENON   ", "DRD-25X         ", "V"},    SDEV_NOLUNS},
    385 	{{T_CDROM, T_REMOV,
    386 	 "HP      ", "C4324/C4325     ", ""},     SDEV_NOLUNS},
    387 	{{T_CDROM, T_REMOV,
    388 	 "IMS     ", "CDD521/10       ", "2.06"}, SDEV_NOLUNS},
    389 	{{T_CDROM, T_REMOV,
    390 	 "MATSHITA", "CD-ROM CR-5XX   ", "1.0b"}, SDEV_NOLUNS},
    391 	{{T_CDROM, T_REMOV,
    392 	 "MEDAVIS ", "RENO CD-ROMX2A  ", ""},     SDEV_NOLUNS},
    393 	{{T_CDROM, T_REMOV,
    394 	 "MEDIAVIS", "CDR-H93MV       ", "1.3"},  SDEV_NOLUNS},
    395 	{{T_CDROM, T_REMOV,
    396 	 "NEC     ", "CD-ROM DRIVE:55 ", ""},     SDEV_NOLUNS},
    397 	{{T_CDROM, T_REMOV,
    398 	 "NEC     ", "CD-ROM DRIVE:83 ", ""},     SDEV_NOLUNS},
    399 	{{T_CDROM, T_REMOV,
    400 	 "NEC     ", "CD-ROM DRIVE:84 ", ""},     SDEV_NOLUNS},
    401 	{{T_CDROM, T_REMOV,
    402 	 "NEC     ", "CD-ROM DRIVE:841", ""},     SDEV_NOLUNS},
    403 	{{T_CDROM, T_REMOV,
    404 	 "PIONEER ", "CD-ROM DR-124X  ", "1.01"}, SDEV_NOLUNS},
    405 	{{T_CDROM, T_REMOV,
    406 	 "SONY    ", "CD-ROM CDU-541  ", ""},     SDEV_NOLUNS},
    407 	{{T_CDROM, T_REMOV,
    408 	 "SONY    ", "CD-ROM CDU-55S  ", ""},     SDEV_NOLUNS},
    409 	{{T_CDROM, T_REMOV,
    410 	 "SONY    ", "CD-ROM CDU-8003A", ""},     SDEV_NOLUNS},
    411 	{{T_CDROM, T_REMOV,
    412 	 "SONY    ", "CD-ROM CDU-8012 ", ""},     SDEV_NOLUNS},
    413 	{{T_CDROM, T_REMOV,
    414 	 "TEAC    ", "CD-ROM          ", "1.06"}, SDEV_NOLUNS},
    415 	{{T_CDROM, T_REMOV,
    416 	 "TEAC    ", "CD-ROM CD-56S   ", "1.0B"}, SDEV_NOLUNS},
    417 	{{T_CDROM, T_REMOV,
    418 	 "TEXEL   ", "CD-ROM          ", "1.06"}, SDEV_NOLUNS},
    419 	{{T_CDROM, T_REMOV,
    420 	 "TEXEL   ", "CD-ROM DM-XX24 K", "1.10"}, SDEV_NOLUNS},
    421 	{{T_CDROM, T_REMOV,
    422 	 "TOSHIBA ", "XM-4101TASUNSLCD", "1755"}, SDEV_NOLUNS},
    423 	{{T_CDROM, T_REMOV,
    424 	 "ShinaKen", "CD-ROM DM-3x1S", "1.04"}, SDEV_NOLUNS},
    425 	{{T_CDROM, T_REMOV,
    426 	 "JVC     ", "R2626           ", "1.55"}, SDEV_NOLUNS},
    427 	{{T_DIRECT, T_FIXED,
    428 	 "MICROP  ", "1588-15MBSUN0669", ""},     SDEV_AUTOSAVE},
    429 	{{T_DIRECT, T_FIXED,
    430 	 "MICROP  ", "2217-15MQ1091501", ""},     SDEV_NOSYNCCACHE},
    431 	{{T_OPTICAL, T_REMOV,
    432 	 "EPSON   ", "OMD-5010        ", "3.08"}, SDEV_NOLUNS},
    433 
    434 	{{T_DIRECT, T_FIXED,
    435 	 "DEC     ", "RZ55     (C) DEC", ""},     SDEV_AUTOSAVE},
    436 	{{T_DIRECT, T_FIXED,
    437 	 "EMULEX  ", "MD21/S2     ESDI", "A00"},  SDEV_FORCELUNS|SDEV_AUTOSAVE},
    438 	/* Gives non-media hardware failure in response to start-unit command */
    439 	{{T_DIRECT, T_FIXED,
    440 	 "HITACHI", "DK515C",		"CP16"},  SDEV_NOSTARTUNIT},
    441 	{{T_DIRECT, T_FIXED,
    442 	 "HITACHI", "DK515C",		"CP15"},  SDEV_NOSTARTUNIT},
    443 	{{T_DIRECT, T_FIXED,
    444 	 "HP      ", "C372",             ""},     SDEV_NOTAG},
    445 	{{T_DIRECT, T_FIXED,
    446 	 "IBMRAID ", "0662S",		 ""},     SDEV_AUTOSAVE},
    447 	{{T_DIRECT, T_FIXED,
    448 	 "IBM     ", "0663H",		 ""},     SDEV_AUTOSAVE},
    449 	{{T_DIRECT, T_FIXED,
    450 	 "IBM",	     "0664",		 ""},     SDEV_AUTOSAVE},
    451 	{{T_DIRECT, T_FIXED,
    452 	 "IBM     ", "H3171-S2",	 ""},	  SDEV_NOLUNS|SDEV_AUTOSAVE},
    453 	{{T_DIRECT, T_FIXED,
    454 	 "IBM     ", "KZ-C",		 ""},	  SDEV_AUTOSAVE},
    455 	/* Broken IBM disk */
    456 	{{T_DIRECT, T_FIXED,
    457 	 ""	   , "DFRSS2F",		 ""},	  SDEV_AUTOSAVE},
    458 	{{T_DIRECT, T_REMOV,
    459 	 "MPL     ", "MC-DISK-        ", ""},     SDEV_NOLUNS},
    460 	{{T_DIRECT, T_FIXED,
    461 	 "MAXTOR  ", "XT-3280         ", ""},     SDEV_NOLUNS},
    462 	{{T_DIRECT, T_FIXED,
    463 	 "MAXTOR  ", "XT-4380S        ", ""},     SDEV_NOLUNS},
    464 	{{T_DIRECT, T_FIXED,
    465 	 "MAXTOR  ", "MXT-1240S       ", ""},     SDEV_NOLUNS},
    466 	{{T_DIRECT, T_FIXED,
    467 	 "MAXTOR  ", "XT-4170S        ", ""},     SDEV_NOLUNS},
    468 	{{T_DIRECT, T_FIXED,
    469 	 "MAXTOR  ", "XT-8760S",         ""},     SDEV_NOLUNS},
    470 	{{T_DIRECT, T_FIXED,
    471 	 "MAXTOR  ", "LXT-213S        ", ""},     SDEV_NOLUNS},
    472 	{{T_DIRECT, T_FIXED,
    473 	 "MAXTOR  ", "LXT-213S SUN0207", ""},     SDEV_NOLUNS},
    474 	{{T_DIRECT, T_FIXED,
    475 	 "MAXTOR  ", "LXT-200S        ", ""},     SDEV_NOLUNS},
    476 	{{T_DIRECT, T_FIXED,
    477 	 "MEGADRV ", "EV1000",           ""},     SDEV_NOMODESENSE},
    478 	{{T_DIRECT, T_FIXED,
    479 	 "MST     ", "SnapLink        ", ""},     SDEV_NOLUNS},
    480 	{{T_DIRECT, T_FIXED,
    481 	 "NEC     ", "D3847           ", "0307"}, SDEV_NOLUNS},
    482 	{{T_DIRECT, T_FIXED,
    483 	 "QUANTUM ", "ELS85S          ", ""},     SDEV_AUTOSAVE},
    484 	{{T_DIRECT, T_FIXED,
    485 	 "QUANTUM ", "LPS525S         ", ""},     SDEV_NOLUNS},
    486 	{{T_DIRECT, T_FIXED,
    487 	 "QUANTUM ", "P105S 910-10-94x", ""},     SDEV_NOLUNS},
    488 	{{T_DIRECT, T_FIXED,
    489 	 "QUANTUM ", "PD1225S         ", ""},     SDEV_NOLUNS},
    490 	{{T_DIRECT, T_FIXED,
    491 	 "QUANTUM ", "PD210S   SUN0207", ""},     SDEV_NOLUNS},
    492 	{{T_DIRECT, T_FIXED,
    493 	 "RODIME  ", "RO3000S         ", ""},     SDEV_NOLUNS},
    494 	{{T_DIRECT, T_FIXED,
    495 	 "SEAGATE ", "ST125N          ", ""},     SDEV_NOLUNS},
    496 	{{T_DIRECT, T_FIXED,
    497 	 "SEAGATE ", "ST157N          ", ""},     SDEV_NOLUNS},
    498 	{{T_DIRECT, T_FIXED,
    499 	 "SEAGATE ", "ST296           ", ""},     SDEV_NOLUNS},
    500 	{{T_DIRECT, T_FIXED,
    501 	 "SEAGATE ", "ST296N          ", ""},     SDEV_NOLUNS},
    502 	{{T_DIRECT, T_FIXED,
    503 	 "SEAGATE ", "ST19171FC", ""},            SDEV_NOMODESENSE},
    504 	{{T_DIRECT, T_FIXED,
    505 	 "SEAGATE ", "ST34501FC       ", ""},     SDEV_NOMODESENSE},
    506 	{{T_DIRECT, T_FIXED,
    507 	 "TOSHIBA ", "MK538FB         ", "6027"}, SDEV_NOLUNS},
    508 	{{T_DIRECT, T_REMOV,
    509 	 "iomega", "jaz 1GB", 		 ""},	  SDEV_NOMODESENSE},
    510 	{{T_DIRECT, T_REMOV,
    511 	 "IOMEGA", "ZIP 100",		 ""},	  SDEV_NOMODESENSE},
    512 	{{T_DIRECT, T_REMOV,
    513 	 "IOMEGA", "ZIP 100",		 "J.03"}, SDEV_NOMODESENSE|SDEV_NOLUNS},
    514 	/* Letting the motor run kills floppy drives and disks quite fast. */
    515 	{{T_DIRECT, T_REMOV,
    516 	 "TEAC", "FC-1",		 ""},	  SDEV_NOSTARTUNIT},
    517 
    518 	/* XXX: QIC-36 tape behind Emulex adapter.  Very broken. */
    519 	{{T_SEQUENTIAL, T_REMOV,
    520 	 "        ", "                ", "    "}, SDEV_NOLUNS},
    521 	{{T_SEQUENTIAL, T_REMOV,
    522 	 "CALIPER ", "CP150           ", ""},     SDEV_NOLUNS},
    523 	{{T_SEQUENTIAL, T_REMOV,
    524 	 "EXABYTE ", "EXB-8200        ", ""},     SDEV_NOLUNS},
    525 	{{T_SEQUENTIAL, T_REMOV,
    526 	 "SONY    ", "GY-10C          ", ""},     SDEV_NOLUNS},
    527 	{{T_SEQUENTIAL, T_REMOV,
    528 	 "SONY    ", "SDT-2000        ", "2.09"}, SDEV_NOLUNS},
    529 	{{T_SEQUENTIAL, T_REMOV,
    530 	 "SONY    ", "SDT-5000        ", "3."},   SDEV_NOSYNC|SDEV_NOWIDE},
    531 	{{T_SEQUENTIAL, T_REMOV,
    532 	 "SONY    ", "SDT-5200        ", "3."},   SDEV_NOLUNS},
    533 	{{T_SEQUENTIAL, T_REMOV,
    534 	 "TANDBERG", " TDC 3600       ", ""},     SDEV_NOLUNS},
    535 	/* Following entry reported as a Tandberg 3600; ref. PR1933 */
    536 	{{T_SEQUENTIAL, T_REMOV,
    537 	 "ARCHIVE ", "VIPER 150  21247", ""},     SDEV_NOLUNS},
    538 	/* Following entry for a Cipher ST150S; ref. PR4171 */
    539 	{{T_SEQUENTIAL, T_REMOV,
    540 	 "ARCHIVE ", "VIPER 1500 21247", "2.2G"}, SDEV_NOLUNS},
    541 	{{T_SEQUENTIAL, T_REMOV,
    542 	 "ARCHIVE ", "Python 28454-XXX", ""},     SDEV_NOLUNS},
    543 	{{T_SEQUENTIAL, T_REMOV,
    544 	 "WANGTEK ", "5099ES SCSI",      ""},     SDEV_NOLUNS},
    545 	{{T_SEQUENTIAL, T_REMOV,
    546 	 "WANGTEK ", "5150ES SCSI",      ""},     SDEV_NOLUNS},
    547 	{{T_SEQUENTIAL, T_REMOV,
    548 	 "WangDAT ", "Model 1300      ", "02.4"}, SDEV_NOSYNC|SDEV_NOWIDE},
    549 	{{T_SEQUENTIAL, T_REMOV,
    550 	 "WangDAT ", "Model 2600      ", "01.7"}, SDEV_NOSYNC|SDEV_NOWIDE},
    551 	{{T_SEQUENTIAL, T_REMOV,
    552 	 "WangDAT ", "Model 3200      ", "02.2"}, SDEV_NOSYNC|SDEV_NOWIDE},
    553 
    554 	{{T_SCANNER, T_FIXED,
    555 	 "RICOH   ", "IS60            ", "1R08"}, SDEV_NOLUNS},
    556 	{{T_SCANNER, T_FIXED,
    557 	 "UMAX    ", "Astra 1200S     ", "V2.9"}, SDEV_NOLUNS},
    558 	{{T_SCANNER, T_FIXED,
    559 	 "UMAX    ", "Astra 1220S     ", "V1.2"}, SDEV_NOLUNS},
    560 	{{T_SCANNER, T_FIXED,
    561 	 "UMAX    ", "UMAX S-6E       ", "V2.0"}, SDEV_NOLUNS},
    562 	{{T_SCANNER, T_FIXED,
    563 	 "UMAX    ", "UMAX S-12       ", "V2.1"}, SDEV_NOLUNS},
    564 
    565 	{{T_PROCESSOR, T_FIXED,
    566 	 "LITRONIC", "PCMCIA          ", ""},     SDEV_NOLUNS},
    567 
    568 	{{T_CHANGER, T_REMOV,
    569 	 "SONY    ", "CDL1100         ", ""},     SDEV_NOLUNS},
    570 
    571 	{{T_ENCLOSURE, T_FIXED,
    572 	 "SUN     ", "SENA            ", "1.07"}, SDEV_NOLUNS},
    573 };
    574 
    575 /*
    576  * given a target and lun, ask the device what
    577  * it is, and find the correct driver table
    578  * entry.
    579  */
    580 int
    581 scsi_probedev(scsi, target, lun)
    582 	struct scsibus_softc *scsi;
    583 	int target, lun;
    584 {
    585 	struct scsipi_link *sc_link;
    586 	static struct scsipi_inquiry_data inqbuf;
    587 	struct scsi_quirk_inquiry_pattern *finger;
    588 	int checkdtype, priority, docontinue;
    589 	struct scsipibus_attach_args sa;
    590 	struct cfdata *cf;
    591 
    592 	/*
    593 	 * Assume no more luns to search after this one.
    594 	 * If we successfully get Inquiry data and after
    595 	 * merging quirks we find we can probe for more
    596 	 * luns, we will.
    597 	 */
    598 	docontinue = 0;
    599 
    600 	/* Skip this slot if it is already attached. */
    601 	if (scsi->sc_link[target][lun] != NULL)
    602 		return (docontinue);
    603 
    604 	sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT);
    605 	*sc_link = *scsi->adapter_link;
    606 	sc_link->scsipi_scsi.target = target;
    607 	sc_link->scsipi_scsi.lun = lun;
    608 	sc_link->device = &probe_switch;
    609 
    610 	/*
    611 	 * Ask the device what it is
    612 	 */
    613 #if defined(SCSIDEBUG) && DEBUGTYPE == BUS_SCSI
    614 	if (target == DEBUGTARGET && lun == DEBUGLUN)
    615 		sc_link->flags |= DEBUGLEVEL;
    616 #endif /* SCSIDEBUG */
    617 
    618 	(void) scsipi_test_unit_ready(sc_link,
    619 	    SCSI_AUTOCONF | SCSI_IGNORE_ILLEGAL_REQUEST |
    620 	    SCSI_IGNORE_NOT_READY | SCSI_IGNORE_MEDIA_CHANGE);
    621 
    622 #ifdef SCSI_2_DEF
    623 	/* some devices need to be told to go to SCSI2 */
    624 	/* However some just explode if you tell them this.. leave it out */
    625 	scsi_change_def(sc_link, SCSI_AUTOCONF | SCSI_SILENT);
    626 #endif /* SCSI_2_DEF */
    627 
    628 	/* Now go ask the device all about itself. */
    629 	bzero(&inqbuf, sizeof(inqbuf));
    630 	if (scsipi_inquire(sc_link, &inqbuf, SCSI_AUTOCONF) != 0)
    631 		goto bad;
    632 
    633 	{
    634 		int len = inqbuf.additional_length;
    635 		while (len < 3)
    636 			inqbuf.unused[len++] = '\0';
    637 		while (len < 3 + 28)
    638 			inqbuf.unused[len++] = ' ';
    639 	}
    640 
    641 	sa.sa_sc_link = sc_link;
    642 	sa.sa_inqbuf.type = inqbuf.device;
    643 	sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ?
    644 	    T_REMOV : T_FIXED;
    645 	sa.sa_inqbuf.vendor = inqbuf.vendor;
    646 	sa.sa_inqbuf.product = inqbuf.product;
    647 	sa.sa_inqbuf.revision = inqbuf.revision;
    648 	sa.scsipi_info.scsi_version = inqbuf.version;
    649 
    650 	finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
    651 	    &sa.sa_inqbuf, (caddr_t)scsi_quirk_patterns,
    652 	    sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
    653 	    sizeof(scsi_quirk_patterns[0]), &priority);
    654 
    655 	/*
    656 	 * Based upon the inquiry flags we got back, and if we're
    657 	 * at SCSI-2 or better, set some limiting quirks.
    658 	 */
    659 	if ((inqbuf.version & SID_ANSII) >= 2) {
    660 		if ((inqbuf.flags & SID_CmdQue) == 0)
    661 			sc_link->quirks |= SDEV_NOTAG;
    662 		if ((inqbuf.flags & SID_Sync) == 0)
    663 			sc_link->quirks |= SDEV_NOSYNC;
    664 		if ((inqbuf.flags & SID_WBus16) == 0)
    665 			sc_link->quirks |= SDEV_NOWIDE;
    666 	}
    667 	/*
    668 	 * Now apply any quirks from the table.
    669 	 */
    670 	if (priority != 0)
    671 		sc_link->quirks |= finger->quirks;
    672 	if ((inqbuf.version & SID_ANSII) == 0 &&
    673 	    (sc_link->quirks & SDEV_FORCELUNS) == 0)
    674 		sc_link->quirks |= SDEV_NOLUNS;
    675 	sc_link->scsipi_scsi.scsi_version = inqbuf.version;
    676 
    677 	if ((sc_link->quirks & SDEV_NOLUNS) == 0)
    678 		docontinue = 1;
    679 
    680 	/*
    681 	 * note what BASIC type of device it is
    682 	 */
    683 	if ((inqbuf.dev_qual2 & SID_REMOVABLE) != 0)
    684 		sc_link->flags |= SDEV_REMOVABLE;
    685 
    686 	/*
    687 	 * Any device qualifier that has the top bit set (qualifier&4 != 0)
    688 	 * is vendor specific and won't match in this switch.
    689 	 * All we do here is throw out bad/negative responses.
    690 	 */
    691 	checkdtype = 0;
    692 	switch (inqbuf.device & SID_QUAL) {
    693 	case SID_QUAL_LU_OK:
    694 	case SID_QUAL_LU_OFFLINE:
    695 		checkdtype = 1;
    696 		break;
    697 
    698 	case SID_QUAL_RSVD:
    699 	case SID_QUAL_BAD_LU:
    700 		goto bad;
    701 
    702 	default:
    703 		break;
    704 	}
    705 	if (checkdtype)
    706 		switch (inqbuf.device & SID_TYPE) {
    707 		case T_DIRECT:
    708 		case T_SEQUENTIAL:
    709 		case T_PRINTER:
    710 		case T_PROCESSOR:
    711 		case T_WORM:
    712 		case T_CDROM:
    713 		case T_SCANNER:
    714 		case T_OPTICAL:
    715 		case T_CHANGER:
    716 		case T_COMM:
    717 		case T_IT8_1:
    718 		case T_IT8_2:
    719 		case T_STORARRAY:
    720 		case T_ENCLOSURE:
    721 		default:
    722 			break;
    723 		case T_NODEVICE:
    724 			goto bad;
    725 		}
    726 
    727 	if ((cf = config_search(scsibussubmatch, (struct device *)scsi,
    728 	    &sa)) != NULL) {
    729 		scsi->sc_link[target][lun] = sc_link;
    730 		config_attach((struct device *)scsi, cf, &sa, scsibusprint);
    731 	} else {
    732 		scsibusprint(&sa, scsi->sc_dev.dv_xname);
    733 		printf(" not configured\n");
    734 		goto bad;
    735 	}
    736 
    737 	return (docontinue);
    738 
    739 bad:
    740 	free(sc_link, M_DEVBUF);
    741 	return (docontinue);
    742 }
    743 
    744 /****** Entry points for user control of the SCSI bus. ******/
    745 
    746 int
    747 scsibusopen(dev, flag, fmt, p)
    748 	dev_t dev;
    749 	int flag, fmt;
    750 	struct proc *p;
    751 {
    752 	struct scsibus_softc *sc;
    753 	int error, unit = minor(dev);
    754 
    755 	if (unit >= scsibus_cd.cd_ndevs ||
    756 	    (sc = scsibus_cd.cd_devs[unit]) == NULL)
    757 		return (ENXIO);
    758 
    759 	if (sc->sc_flags & SCSIBUSF_OPEN)
    760 		return (EBUSY);
    761 
    762 	if ((error = scsipi_adapter_addref(sc->adapter_link)) != 0)
    763 		return (error);
    764 
    765 	sc->sc_flags |= SCSIBUSF_OPEN;
    766 
    767 	return (0);
    768 }
    769 
    770 int
    771 scsibusclose(dev, flag, fmt, p)
    772 	dev_t dev;
    773 	int flag, fmt;
    774 	struct proc *p;
    775 {
    776 	struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
    777 
    778 	scsipi_adapter_delref(sc->adapter_link);
    779 
    780 	sc->sc_flags &= ~SCSIBUSF_OPEN;
    781 
    782 	return (0);
    783 }
    784 
    785 int
    786 scsibusioctl(dev, cmd, addr, flag, p)
    787 	dev_t dev;
    788 	u_long cmd;
    789 	caddr_t addr;
    790 	int flag;
    791 	struct proc *p;
    792 {
    793 	struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
    794 	struct scsipi_link *sc_link = sc->adapter_link;
    795 	int error;
    796 
    797 	/*
    798 	 * Enforce write permission for ioctls that change the
    799 	 * state of the bus.  Host adapter specific ioctls must
    800 	 * be checked by the adapter driver.
    801 	 */
    802 	switch (cmd) {
    803 	case SCBUSIOSCAN:
    804 	case SCBUSIORESET:
    805 		if ((flag & FWRITE) == 0)
    806 			return (EBADF);
    807 	}
    808 
    809 	switch (cmd) {
    810 	case SCBUSIOSCAN:
    811 	    {
    812 		struct scbusioscan_args *a =
    813 		    (struct scbusioscan_args *)addr;
    814 
    815 		/* XXX Change interface to this function. */
    816 		error = scsi_probe_busses(minor(dev), a->sa_target,
    817 		    a->sa_lun);
    818 		break;
    819 	    }
    820 
    821 	case SCBUSIORESET:
    822 		/* FALLTHROUGH */
    823 	default:
    824 		if (sc_link->adapter->scsipi_ioctl == NULL)
    825 			error = ENOTTY;
    826 		else
    827 			error = (*sc_link->adapter->scsipi_ioctl)(sc_link,
    828 			    cmd, addr, flag, p);
    829 		break;
    830 	}
    831 
    832 	return (error);
    833 }
    834