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