Home | History | Annotate | Line # | Download | only in scsipi
scsiconf.c revision 1.106
      1 /*	$NetBSD: scsiconf.c,v 1.106 1998/08/17 00:49:02 mycroft 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.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Originally written by Julian Elischer (julian (at) tfs.com)
     41  * for TRW Financial Systems for use under the MACH(2.5) operating system.
     42  *
     43  * TRW Financial Systems, in accordance with their agreement with Carnegie
     44  * Mellon University, makes this software available to CMU to distribute
     45  * or use in any manner that they see fit as long as this message is kept with
     46  * the software. For this reason TFS also grants any other persons or
     47  * organisations permission to use or modify this software.
     48  *
     49  * TFS supplies this software to be publicly redistributed
     50  * on the understanding that TFS is not responsible for the correct
     51  * functioning of this software in any circumstances.
     52  *
     53  * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
     54  */
     55 
     56 #include <sys/types.h>
     57 #include <sys/param.h>
     58 #include <sys/systm.h>
     59 #include <sys/malloc.h>
     60 #include <sys/device.h>
     61 
     62 #include <dev/scsipi/scsi_all.h>
     63 #include <dev/scsipi/scsipi_all.h>
     64 #include <dev/scsipi/scsiconf.h>
     65 
     66 #include "locators.h"
     67 
     68 #if 0
     69 #if NCALS > 0
     70 	{ T_PROCESSOR, T_FIXED, 1,
     71 	  0, 0, 0 },
     72 #endif	/* NCALS */
     73 #if NBLL > 0
     74 	{ T_PROCESSOR, T_FIXED, 1,
     75 	  "AEG     ", "READER          ", "V1.0" },
     76 #endif	/* NBLL */
     77 #if NKIL > 0
     78 	{ T_SCANNER, T_FIXED, 0,
     79 	  "KODAK   ", "IL Scanner 900  ", 0 },
     80 #endif	/* NKIL */
     81 #endif
     82 
     83 /*
     84  * Declarations
     85  */
     86 void scsi_probedev __P((struct scsibus_softc *, int, int));
     87 int scsi_probe_bus __P((int bus, int target, int lun));
     88 
     89 struct scsipi_device probe_switch = {
     90 	NULL,
     91 	NULL,
     92 	NULL,
     93 	NULL,
     94 };
     95 
     96 #ifdef __BROKEN_INDIRECT_CONFIG
     97 int scsibusmatch __P((struct device *, void *, void *));
     98 #else
     99 int scsibusmatch __P((struct device *, struct cfdata *, void *));
    100 #endif
    101 void scsibusattach __P((struct device *, struct device *, void *));
    102 #ifdef __BROKEN_INDIRECT_CONFIG
    103 int scsibussubmatch __P((struct device *, void *, void *));
    104 #else
    105 int scsibussubmatch __P((struct device *, struct cfdata *, void *));
    106 #endif
    107 
    108 struct cfattach scsibus_ca = {
    109 	sizeof(struct scsibus_softc), scsibusmatch, scsibusattach
    110 };
    111 
    112 extern struct cfdriver scsibus_cd;
    113 
    114 int scsibusprint __P((void *, const char *));
    115 
    116 
    117 int
    118 scsiprint(aux, pnp)
    119 	void *aux;
    120 	const char *pnp;
    121 {
    122 	struct scsipi_link *l = aux;
    123 
    124 	/* only "scsibus"es can attach to "scsi"s; easy. */
    125 	if (pnp)
    126 		printf("scsibus at %s", pnp);
    127 
    128 	/* don't print channel if the controller says there can be only one. */
    129 	if (l->scsipi_scsi.channel != SCSI_CHANNEL_ONLY_ONE)
    130 		printf(" channel %d", l->scsipi_scsi.channel);
    131 
    132 	return (UNCONF);
    133 }
    134 
    135 int
    136 #ifdef __BROKEN_INDIRECT_CONFIG
    137 scsibusmatch(parent, match, aux)
    138 #else
    139 scsibusmatch(parent, cf, aux)
    140 #endif
    141 	struct device *parent;
    142 #ifdef __BROKEN_INDIRECT_CONFIG
    143 	void *match;
    144 #else
    145 	struct cfdata *cf;
    146 #endif
    147 	void *aux;
    148 {
    149 #ifdef __BROKEN_INDIRECT_CONFIG
    150 	struct cfdata *cf = match;
    151 #endif
    152 	struct scsipi_link *l = aux;
    153 	int channel;
    154 
    155 	/*
    156 	 * Allow single-channel controllers to specify their channel
    157 	 * in a special way, so that it's not printed.
    158 	 */
    159 	channel = (l->scsipi_scsi.channel != SCSI_CHANNEL_ONLY_ONE) ?
    160 	    l->scsipi_scsi.channel : 0;
    161 
    162 	if (cf->cf_loc[SCSICF_CHANNEL] != channel &&
    163 	    cf->cf_loc[SCSICF_CHANNEL] != SCSICF_CHANNEL_DEFAULT)
    164 		return (0);
    165 
    166 	return (1);
    167 }
    168 
    169 /*
    170  * The routine called by the adapter boards to get all their
    171  * devices configured in.
    172  */
    173 void
    174 scsibusattach(parent, self, aux)
    175 	struct device *parent, *self;
    176 	void *aux;
    177 {
    178 	struct scsibus_softc *sb = (struct scsibus_softc *)self;
    179 	struct scsipi_link *sc_link_proto = aux;
    180 	size_t nbytes;
    181 	int i;
    182 
    183 	sc_link_proto->scsipi_scsi.scsibus = sb->sc_dev.dv_unit;
    184 	sc_link_proto->scsipi_cmd = scsi_scsipi_cmd;
    185 	sc_link_proto->scsipi_interpret_sense = scsi_interpret_sense;
    186 	sc_link_proto->sc_print_addr = scsi_print_addr;
    187 
    188 	sb->adapter_link = sc_link_proto;
    189 	sb->sc_maxtarget = sc_link_proto->scsipi_scsi.max_target;
    190 	printf(": %d targets\n", sb->sc_maxtarget + 1);
    191 
    192 	/* Initialize shared data. */
    193 	scsipi_init();
    194 
    195 	nbytes = sb->sc_maxtarget * sizeof(struct scsipi_link **);
    196 	sb->sc_link = (struct scsipi_link ***)malloc(nbytes, M_DEVBUF,
    197 	    M_NOWAIT);
    198 	if (sb->sc_link == NULL)
    199 		panic("scsibusattach: can't allocate target links");
    200 
    201 	nbytes = 8 * sizeof(struct scsipi_link *);
    202 	for (i = 0; i <= sb->sc_maxtarget; i++) {
    203 		sb->sc_link[i] = (struct scsipi_link **)malloc(nbytes,
    204 		    M_DEVBUF, M_NOWAIT);
    205 		if (sb->sc_link[i] == NULL)
    206 			panic("scsibusattach: can't allocate lun links");
    207 		bzero(sb->sc_link[i], nbytes);
    208 	}
    209 
    210 #if defined(SCSI_DELAY) && SCSI_DELAY > 2
    211 	printf("%s: waiting for scsi devices to settle\n",
    212 	    sb->sc_dev.dv_xname);
    213 #else	/* SCSI_DELAY > 2 */
    214 #undef	SCSI_DELAY
    215 #define SCSI_DELAY 2
    216 #endif	/* SCSI_DELAY */
    217 	delay(1000000 * SCSI_DELAY);
    218 
    219 	scsi_probe_bus(sb->sc_dev.dv_unit, -1, -1);
    220 }
    221 
    222 int
    223 #ifdef __BROKEN_INDIRECT_CONFIG
    224 scsibussubmatch(parent, match, aux)
    225 #else
    226 scsibussubmatch(parent, cf, aux)
    227 #endif
    228 	struct device *parent;
    229 #ifdef __BROKEN_INDIRECT_CONFIG
    230 	void *match;
    231 #else
    232 	struct cfdata *cf;
    233 #endif
    234 	void *aux;
    235 {
    236 #ifdef __BROKEN_INDIRECT_CONFIG
    237 	struct cfdata *cf = match;
    238 #endif
    239 	struct scsipibus_attach_args *sa = aux;
    240 	struct scsipi_link *sc_link = sa->sa_sc_link;
    241 
    242 	if (cf->cf_loc[SCSIBUSCF_TARGET] != SCSIBUSCF_TARGET_DEFAULT &&
    243 	    cf->cf_loc[SCSIBUSCF_TARGET] != sc_link->scsipi_scsi.target)
    244 		return (0);
    245 	if (cf->cf_loc[SCSIBUSCF_LUN] != SCSIBUSCF_LUN_DEFAULT &&
    246 	    cf->cf_loc[SCSIBUSCF_LUN] != sc_link->scsipi_scsi.lun)
    247 		return (0);
    248 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    249 }
    250 
    251 /*
    252  * Probe the requested scsi bus. It must be already set up.
    253  * -1 requests all set up scsi busses.
    254  * target and lun optionally narrow the search if not -1
    255  */
    256 int
    257 scsi_probe_busses(bus, target, lun)
    258 	int bus, target, lun;
    259 {
    260 
    261 	if (bus == -1) {
    262 		for (bus = 0; bus < scsibus_cd.cd_ndevs; bus++)
    263 			if (scsibus_cd.cd_devs[bus])
    264 				scsi_probe_bus(bus, target, lun);
    265 		return (0);
    266 	} else
    267 		return (scsi_probe_bus(bus, target, lun));
    268 }
    269 
    270 /*
    271  * Probe the requested scsi bus. It must be already set up.
    272  * target and lun optionally narrow the search if not -1
    273  */
    274 int
    275 scsi_probe_bus(bus, target, lun)
    276 	int bus, target, lun;
    277 {
    278 	struct scsibus_softc *scsi;
    279 	int maxtarget, mintarget, maxlun, minlun;
    280 	u_int8_t scsi_addr;
    281 
    282 	if (bus < 0 || bus >= scsibus_cd.cd_ndevs)
    283 		return (ENXIO);
    284 	scsi = scsibus_cd.cd_devs[bus];
    285 	if (scsi == NULL)
    286 		return (ENXIO);
    287 
    288 	scsi_addr = scsi->adapter_link->scsipi_scsi.adapter_target;
    289 
    290 	if (target == -1) {
    291 		maxtarget = scsi->sc_maxtarget;
    292 		mintarget = 0;
    293 	} else {
    294 		if (target < 0 || target > scsi->sc_maxtarget)
    295 			return (EINVAL);
    296 		maxtarget = mintarget = target;
    297 	}
    298 
    299 	if (lun == -1) {
    300 		maxlun = 7;
    301 		minlun = 0;
    302 	} else {
    303 		if (lun < 0 || lun > 7)
    304 			return (EINVAL);
    305 		maxlun = minlun = lun;
    306 	}
    307 
    308 	for (target = mintarget; target <= maxtarget; target++) {
    309 		if (target == scsi_addr)
    310 			continue;
    311 		for (lun = minlun; lun <= maxlun; lun++) {
    312 			/*
    313 			 * See if there's a device present, and configure it.
    314 			 */
    315 			scsi_probedev(scsi, target, lun);
    316 			if ((scsi->moreluns & (1 << target)) == 0)
    317 				break;
    318 			/* otherwise something says we should look further */
    319 		}
    320 	}
    321 	return (0);
    322 }
    323 
    324 /*
    325  * Print out autoconfiguration information for a subdevice.
    326  *
    327  * This is a slight abuse of 'standard' autoconfiguration semantics,
    328  * because 'print' functions don't normally print the colon and
    329  * device information.  However, in this case that's better than
    330  * either printing redundant information before the attach message,
    331  * or having the device driver call a special function to print out
    332  * the standard device information.
    333  */
    334 int
    335 scsibusprint(aux, pnp)
    336 	void *aux;
    337 	const char *pnp;
    338 {
    339 	struct scsipibus_attach_args *sa = aux;
    340 	struct scsipi_inquiry_pattern *inqbuf;
    341 	u_int8_t type;
    342 	char *dtype, *qtype;
    343 	char vendor[33], product[65], revision[17];
    344 	int target, lun;
    345 
    346 	if (pnp != NULL)
    347 		printf("%s", pnp);
    348 
    349 	inqbuf = &sa->sa_inqbuf;
    350 
    351 	target = sa->sa_sc_link->scsipi_scsi.target;
    352 	lun = sa->sa_sc_link->scsipi_scsi.lun;
    353 
    354 	type = inqbuf->type & SID_TYPE;
    355 
    356 	/*
    357 	 * Figure out basic device type and qualifier.
    358 	 */
    359 	dtype = 0;
    360 	switch (inqbuf->type & SID_QUAL) {
    361 	case SID_QUAL_LU_OK:
    362 		qtype = "";
    363 		break;
    364 
    365 	case SID_QUAL_LU_OFFLINE:
    366 		qtype = " offline";
    367 		break;
    368 
    369 	case SID_QUAL_RSVD:
    370 	case SID_QUAL_BAD_LU:
    371 		panic("scsibusprint: impossible qualifier");
    372 
    373 	default:
    374 		qtype = "";
    375 		dtype = "vendor-unique";
    376 		break;
    377 	}
    378 	if (dtype == 0)
    379 		dtype = scsipi_dtype(type);
    380 
    381 	scsipi_strvis(vendor, 33, inqbuf->vendor, 8);
    382 	scsipi_strvis(product, 65, inqbuf->product, 16);
    383 	scsipi_strvis(revision, 17, inqbuf->revision, 4);
    384 
    385 	printf(" targ %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s",
    386 	    target, lun, vendor, product, revision,
    387 	    sa->scsipi_info.scsi_version & SID_ANSII, type, dtype,
    388 	    inqbuf->removable ? "removable" : "fixed", qtype);
    389 
    390 	return (UNCONF);
    391 }
    392 
    393 struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
    394 	{{T_CDROM, T_REMOV,
    395 	 "CHINON  ", "CD-ROM CDS-431  ", ""},     SDEV_NOLUNS},
    396 	{{T_CDROM, T_REMOV,
    397 	 "Chinon  ", "CD-ROM CDS-525  ", ""},     SDEV_NOLUNS},
    398 	{{T_CDROM, T_REMOV,
    399 	 "CHINON  ", "CD-ROM CDS-535  ", ""},     SDEV_NOLUNS},
    400 	{{T_CDROM, T_REMOV,
    401 	 "DEC     ", "RRD42   (C) DEC ", ""},     SDEV_NOLUNS},
    402 	{{T_CDROM, T_REMOV,
    403 	 "DENON   ", "DRD-25X         ", "V"},    SDEV_NOLUNS},
    404 	{{T_CDROM, T_REMOV,
    405 	 "HP      ", "C4324/C4325     ", ""},     SDEV_NOLUNS},
    406 	{{T_CDROM, T_REMOV,
    407 	 "IMS     ", "CDD521/10       ", "2.06"}, SDEV_NOLUNS},
    408 	{{T_CDROM, T_REMOV,
    409 	 "MATSHITA", "CD-ROM CR-5XX   ", "1.0b"}, SDEV_NOLUNS},
    410 	{{T_CDROM, T_REMOV,
    411 	 "MEDAVIS ", "RENO CD-ROMX2A  ", ""},     SDEV_NOLUNS},
    412 	{{T_CDROM, T_REMOV,
    413 	 "MEDIAVIS", "CDR-H93MV       ", "1.3"},  SDEV_NOLUNS},
    414 	{{T_CDROM, T_REMOV,
    415 	 "NEC     ", "CD-ROM DRIVE:55 ", ""},     SDEV_NOLUNS},
    416 	{{T_CDROM, T_REMOV,
    417 	 "NEC     ", "CD-ROM DRIVE:83 ", ""},     SDEV_NOLUNS},
    418 	{{T_CDROM, T_REMOV,
    419 	 "NEC     ", "CD-ROM DRIVE:84 ", ""},     SDEV_NOLUNS},
    420 	{{T_CDROM, T_REMOV,
    421 	 "NEC     ", "CD-ROM DRIVE:841", ""},     SDEV_NOLUNS},
    422 	{{T_CDROM, T_REMOV,
    423 	 "PIONEER ", "CD-ROM DR-124X  ", "1.01"}, SDEV_NOLUNS},
    424 	{{T_CDROM, T_REMOV,
    425 	 "SONY    ", "CD-ROM CDU-541  ", ""},     SDEV_NOLUNS},
    426 	{{T_CDROM, T_REMOV,
    427 	 "SONY    ", "CD-ROM CDU-55S  ", ""},     SDEV_NOLUNS},
    428 	{{T_CDROM, T_REMOV,
    429 	 "SONY    ", "CD-ROM CDU-8003A", ""},     SDEV_NOLUNS},
    430 	{{T_CDROM, T_REMOV,
    431 	 "SONY    ", "CD-ROM CDU-8012 ", ""},     SDEV_NOLUNS},
    432 	{{T_CDROM, T_REMOV,
    433 	 "TEAC    ", "CD-ROM          ", "1.06"}, SDEV_NOLUNS},
    434 	{{T_CDROM, T_REMOV,
    435 	 "TEAC    ", "CD-ROM CD-56S   ", "1.0B"}, SDEV_NOLUNS},
    436 	{{T_CDROM, T_REMOV,
    437 	 "TEXEL   ", "CD-ROM          ", "1.06"}, SDEV_NOLUNS},
    438 	{{T_CDROM, T_REMOV,
    439 	 "TEXEL   ", "CD-ROM DM-XX24 K", "1.10"}, SDEV_NOLUNS},
    440 	{{T_CDROM, T_REMOV,
    441 	 "TOSHIBA ", "XM-4101TASUNSLCD", "1755"}, SDEV_NOLUNS},
    442 	{{T_CDROM, T_REMOV,
    443 	 "ShinaKen", "CD-ROM DM-3x1S", "1.04"}, SDEV_NOLUNS},
    444 	{{T_CDROM, T_REMOV,
    445 	 "JVC     ", "R2626           ", "1.55"}, SDEV_NOLUNS},
    446 	{{T_DIRECT, T_FIXED,
    447 	 "MICROP  ", "1588-15MBSUN0669", ""},     SDEV_AUTOSAVE},
    448 	{{T_OPTICAL, T_REMOV,
    449 	 "EPSON   ", "OMD-5010        ", "3.08"}, SDEV_NOLUNS},
    450 
    451 	{{T_DIRECT, T_FIXED,
    452 	 "DEC     ", "RZ55     (C) DEC", ""},     SDEV_AUTOSAVE},
    453 	{{T_DIRECT, T_FIXED,
    454 	 "EMULEX  ", "MD21/S2     ESDI", "A00"},  SDEV_FORCELUNS|SDEV_AUTOSAVE},
    455 	/* Gives non-media hardware failure in response to start-unit command */
    456 	{{T_DIRECT, T_FIXED,
    457 	 "HITACHI", "DK515C",		"CP16"},  SDEV_NOSTARTUNIT},
    458 	{{T_DIRECT, T_FIXED,
    459 	 "HITACHI", "DK515C",		"CP15"},  SDEV_NOSTARTUNIT},
    460 	{{T_DIRECT, T_FIXED,
    461 	 "IBMRAID ", "0662S",		 ""},     SDEV_AUTOSAVE},
    462 	{{T_DIRECT, T_FIXED,
    463 	 "IBM     ", "0663H",		 ""},     SDEV_AUTOSAVE},
    464 	{{T_DIRECT, T_FIXED,
    465 	 "IBM",	     "0664",		 ""},     SDEV_AUTOSAVE},
    466 	{{T_DIRECT, T_FIXED,
    467 	 "IBM     ", "H3171-S2",	 ""},	  SDEV_NOLUNS|SDEV_AUTOSAVE},
    468 	{{T_DIRECT, T_FIXED,
    469 	 "IBM     ", "KZ-C",		 ""},	  SDEV_AUTOSAVE},
    470 	/* Broken IBM disk */
    471 	{{T_DIRECT, T_FIXED,
    472 	 ""	   , "DFRSS2F",		 ""},	  SDEV_AUTOSAVE},
    473 	{{T_DIRECT, T_REMOV,
    474 	 "MPL     ", "MC-DISK-        ", ""},     SDEV_NOLUNS},
    475 	{{T_DIRECT, T_FIXED,
    476 	 "MAXTOR  ", "XT-3280         ", ""},     SDEV_NOLUNS},
    477 	{{T_DIRECT, T_FIXED,
    478 	 "MAXTOR  ", "XT-4380S        ", ""},     SDEV_NOLUNS},
    479 	{{T_DIRECT, T_FIXED,
    480 	 "MAXTOR  ", "MXT-1240S       ", ""},     SDEV_NOLUNS},
    481 	{{T_DIRECT, T_FIXED,
    482 	 "MAXTOR  ", "XT-4170S        ", ""},     SDEV_NOLUNS},
    483 	{{T_DIRECT, T_FIXED,
    484 	 "MAXTOR  ", "XT-8760S",         ""},     SDEV_NOLUNS},
    485 	{{T_DIRECT, T_FIXED,
    486 	 "MAXTOR  ", "LXT-213S        ", ""},     SDEV_NOLUNS},
    487 	{{T_DIRECT, T_FIXED,
    488 	 "MAXTOR  ", "LXT-213S SUN0207", ""},     SDEV_NOLUNS},
    489 	{{T_DIRECT, T_FIXED,
    490 	 "MAXTOR  ", "LXT-200S        ", ""},     SDEV_NOLUNS},
    491 	{{T_DIRECT, T_FIXED,
    492 	 "MEGADRV ", "EV1000",           ""},     SDEV_NOMODESENSE},
    493 	{{T_DIRECT, T_FIXED,
    494 	 "MST     ", "SnapLink        ", ""},     SDEV_NOLUNS},
    495 	{{T_DIRECT, T_FIXED,
    496 	 "NEC     ", "D3847           ", "0307"}, SDEV_NOLUNS},
    497 	{{T_DIRECT, T_FIXED,
    498 	 "QUANTUM ", "ELS85S          ", ""},     SDEV_AUTOSAVE},
    499 	{{T_DIRECT, T_FIXED,
    500 	 "QUANTUM ", "LPS525S         ", ""},     SDEV_NOLUNS},
    501 	{{T_DIRECT, T_FIXED,
    502 	 "QUANTUM ", "P105S 910-10-94x", ""},     SDEV_NOLUNS},
    503 	{{T_DIRECT, T_FIXED,
    504 	 "QUANTUM ", "PD1225S         ", ""},     SDEV_NOLUNS},
    505 	{{T_DIRECT, T_FIXED,
    506 	 "QUANTUM ", "PD210S   SUN0207", ""},     SDEV_NOLUNS},
    507 	{{T_DIRECT, T_FIXED,
    508 	 "RODIME  ", "RO3000S         ", ""},     SDEV_NOLUNS},
    509 	{{T_DIRECT, T_FIXED,
    510 	 "SEAGATE ", "ST125N          ", ""},     SDEV_NOLUNS},
    511 	{{T_DIRECT, T_FIXED,
    512 	 "SEAGATE ", "ST157N          ", ""},     SDEV_NOLUNS},
    513 	{{T_DIRECT, T_FIXED,
    514 	 "SEAGATE ", "ST296           ", ""},     SDEV_NOLUNS},
    515 	{{T_DIRECT, T_FIXED,
    516 	 "SEAGATE ", "ST296N          ", ""},     SDEV_NOLUNS},
    517 	{{T_DIRECT, T_FIXED,
    518 	 "SEAGATE ", "ST19171FC", ""},            SDEV_NOMODESENSE},
    519 	{{T_DIRECT, T_FIXED,
    520 	 "SEAGATE ", "ST34501FC       ", ""},     SDEV_NOMODESENSE},
    521 	{{T_DIRECT, T_FIXED,
    522 	 "TOSHIBA ", "MK538FB         ", "6027"}, SDEV_NOLUNS},
    523 	{{T_DIRECT, T_REMOV,
    524 	 "iomega", "jaz 1GB", 		 ""},	  SDEV_NOMODESENSE},
    525 	{{T_DIRECT, T_REMOV,
    526 	 "IOMEGA", "ZIP 100",		 ""},	  SDEV_NOMODESENSE},
    527 	/* Letting the motor run kills floppy drives and disks quite fast. */
    528 	{{T_DIRECT, T_REMOV,
    529 	 "TEAC", "FC-1",		 ""},	  SDEV_NOSTARTUNIT},
    530 
    531 	/* XXX: QIC-36 tape behind Emulex adapter.  Very broken. */
    532 	{{T_SEQUENTIAL, T_REMOV,
    533 	 "        ", "                ", "    "}, SDEV_NOLUNS},
    534 	{{T_SEQUENTIAL, T_REMOV,
    535 	 "CALIPER ", "CP150           ", ""},     SDEV_NOLUNS},
    536 	{{T_SEQUENTIAL, T_REMOV,
    537 	 "EXABYTE ", "EXB-8200        ", ""},     SDEV_NOLUNS},
    538 	{{T_SEQUENTIAL, T_REMOV,
    539 	 "SONY    ", "GY-10C          ", ""},     SDEV_NOLUNS},
    540 	{{T_SEQUENTIAL, T_REMOV,
    541 	 "SONY    ", "SDT-2000        ", "2.09"}, SDEV_NOLUNS},
    542 	{{T_SEQUENTIAL, T_REMOV,
    543 	 "SONY    ", "SDT-5000        ", "3."},   SDEV_NOSYNCWIDE},
    544 	{{T_SEQUENTIAL, T_REMOV,
    545 	 "SONY    ", "SDT-5200        ", "3."},   SDEV_NOLUNS},
    546 	{{T_SEQUENTIAL, T_REMOV,
    547 	 "TANDBERG", " TDC 3600       ", ""},     SDEV_NOLUNS},
    548 	/* Following entry reported as a Tandberg 3600; ref. PR1933 */
    549 	{{T_SEQUENTIAL, T_REMOV,
    550 	 "ARCHIVE ", "VIPER 150  21247", ""},     SDEV_NOLUNS},
    551 	/* Following entry for a Cipher ST150S; ref. PR4171 */
    552 	{{T_SEQUENTIAL, T_REMOV,
    553 	 "ARCHIVE ", "VIPER 1500 21247", "2.2G"}, SDEV_NOLUNS},
    554 	{{T_SEQUENTIAL, T_REMOV,
    555 	 "ARCHIVE ", "Python 28454-XXX", ""},     SDEV_NOLUNS},
    556 	{{T_SEQUENTIAL, T_REMOV,
    557 	 "WANGTEK ", "5099ES SCSI",      ""},     SDEV_NOLUNS},
    558 	{{T_SEQUENTIAL, T_REMOV,
    559 	 "WANGTEK ", "5150ES SCSI",      ""},     SDEV_NOLUNS},
    560 	{{T_SEQUENTIAL, T_REMOV,
    561 	 "WangDAT ", "Model 1300      ", "02.4"}, SDEV_NOSYNCWIDE},
    562 	{{T_SEQUENTIAL, T_REMOV,
    563 	 "WangDAT ", "Model 2600      ", "01.7"}, SDEV_NOSYNCWIDE},
    564 	{{T_SEQUENTIAL, T_REMOV,
    565 	 "WangDAT ", "Model 3200      ", "02.2"}, SDEV_NOSYNCWIDE},
    566 
    567 	{{T_SCANNER, T_FIXED,
    568 	 "RICOH   ", "IS60            ", "1R08"}, SDEV_NOLUNS},
    569 	{{T_SCANNER, T_FIXED,
    570 	 "UMAX    ", "Astra 1200S     ", "V2.9"}, SDEV_NOLUNS},
    571 	{{T_SCANNER, T_FIXED,
    572 	 "UMAX    ", "Astra 1220S     ", "V1.2"}, SDEV_NOLUNS},
    573 	{{T_SCANNER, T_FIXED,
    574 	 "UMAX    ", "UMAX S-6E       ", "V2.0"}, SDEV_NOLUNS},
    575 	{{T_SCANNER, T_FIXED,
    576 	 "UMAX    ", "UMAX S-12       ", "V2.1"}, SDEV_NOLUNS},
    577 
    578 	{{T_PROCESSOR, T_FIXED,
    579 	 "LITRONIC", "PCMCIA          ", ""},     SDEV_NOLUNS},
    580 };
    581 
    582 /*
    583  * given a target and lun, ask the device what
    584  * it is, and find the correct driver table
    585  * entry.
    586  */
    587 void
    588 scsi_probedev(scsi, target, lun)
    589 	struct scsibus_softc *scsi;
    590 	int target, lun;
    591 {
    592 	struct scsipi_link *sc_link;
    593 	static struct scsipi_inquiry_data inqbuf;
    594 	struct scsi_quirk_inquiry_pattern *finger;
    595 	int checkdtype, priority;
    596 	struct scsipibus_attach_args sa;
    597 	struct cfdata *cf;
    598 
    599 	/* Skip this slot if it is already attached. */
    600 	if (scsi->sc_link[target][lun] != NULL)
    601 		return;
    602 
    603 	sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT);
    604 	*sc_link = *scsi->adapter_link;
    605 	sc_link->scsipi_scsi.target = target;
    606 	sc_link->scsipi_scsi.lun = lun;
    607 	sc_link->device = &probe_switch;
    608 
    609 	/*
    610 	 * Ask the device what it is
    611 	 */
    612 #if defined(SCSIDEBUG) && DEBUGTYPE == BUS_SCSI
    613 	if (target == DEBUGTARGET && lun == DEBUGLUN)
    614 		sc_link->flags |= DEBUGLEVEL;
    615 #endif /* SCSIDEBUG */
    616 
    617 	(void) scsipi_test_unit_ready(sc_link,
    618 	    SCSI_AUTOCONF | SCSI_IGNORE_ILLEGAL_REQUEST |
    619 	    SCSI_IGNORE_NOT_READY | SCSI_IGNORE_MEDIA_CHANGE);
    620 
    621 #ifdef SCSI_2_DEF
    622 	/* some devices need to be told to go to SCSI2 */
    623 	/* However some just explode if you tell them this.. leave it out */
    624 	scsi_change_def(sc_link, SCSI_AUTOCONF | SCSI_SILENT);
    625 #endif /* SCSI_2_DEF */
    626 
    627 	/* Now go ask the device all about itself. */
    628 	bzero(&inqbuf, sizeof(inqbuf));
    629 	if (scsipi_inquire(sc_link, &inqbuf, SCSI_AUTOCONF) != 0)
    630 		goto bad;
    631 
    632 	{
    633 		int len = inqbuf.additional_length;
    634 		while (len < 3)
    635 			inqbuf.unused[len++] = '\0';
    636 		while (len < 3 + 28)
    637 			inqbuf.unused[len++] = ' ';
    638 	}
    639 
    640 	sa.sa_sc_link = sc_link;
    641 	sa.sa_inqbuf.type = inqbuf.device;
    642 	sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ?
    643 	    T_REMOV : T_FIXED;
    644 	sa.sa_inqbuf.vendor = inqbuf.vendor;
    645 	sa.sa_inqbuf.product = inqbuf.product;
    646 	sa.sa_inqbuf.revision = inqbuf.revision;
    647 	sa.scsipi_info.scsi_version = inqbuf.version;
    648 
    649 	finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
    650 	    &sa.sa_inqbuf, (caddr_t)scsi_quirk_patterns,
    651 	    sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
    652 	    sizeof(scsi_quirk_patterns[0]), &priority);
    653 	if (priority != 0)
    654 		sc_link->quirks |= finger->quirks;
    655 	if ((inqbuf.version & SID_ANSII) == 0 &&
    656 	    (sc_link->quirks & SDEV_FORCELUNS) == 0)
    657 		sc_link->quirks |= SDEV_NOLUNS;
    658 	sc_link->scsipi_scsi.scsi_version = inqbuf.version;
    659 
    660 	if ((sc_link->quirks & SDEV_NOLUNS) == 0)
    661 		scsi->moreluns |= (1 << target);
    662 
    663 	/*
    664 	 * note what BASIC type of device it is
    665 	 */
    666 	if ((inqbuf.dev_qual2 & SID_REMOVABLE) != 0)
    667 		sc_link->flags |= SDEV_REMOVABLE;
    668 
    669 	/*
    670 	 * Any device qualifier that has the top bit set (qualifier&4 != 0)
    671 	 * is vendor specific and won't match in this switch.
    672 	 * All we do here is throw out bad/negative responses.
    673 	 */
    674 	checkdtype = 0;
    675 	switch (inqbuf.device & SID_QUAL) {
    676 	case SID_QUAL_LU_OK:
    677 	case SID_QUAL_LU_OFFLINE:
    678 		checkdtype = 1;
    679 		break;
    680 
    681 	case SID_QUAL_RSVD:
    682 	case SID_QUAL_BAD_LU:
    683 		goto bad;
    684 
    685 	default:
    686 		break;
    687 	}
    688 	if (checkdtype)
    689 		switch (inqbuf.device & SID_TYPE) {
    690 		case T_DIRECT:
    691 		case T_SEQUENTIAL:
    692 		case T_PRINTER:
    693 		case T_PROCESSOR:
    694 		case T_WORM:
    695 		case T_CDROM:
    696 		case T_SCANNER:
    697 		case T_OPTICAL:
    698 		case T_CHANGER:
    699 		case T_COMM:
    700 		case T_IT8_1:
    701 		case T_IT8_2:
    702 		case T_STORARRAY:
    703 		case T_ENCLOSURE:
    704 		default:
    705 			break;
    706 		case T_NODEVICE:
    707 			goto bad;
    708 		}
    709 
    710 	if ((cf = config_search(scsibussubmatch, (struct device *)scsi,
    711 	    &sa)) != NULL) {
    712 		scsi->sc_link[target][lun] = sc_link;
    713 		config_attach((struct device *)scsi, cf, &sa, scsibusprint);
    714 	} else {
    715 		scsibusprint(&sa, scsi->sc_dev.dv_xname);
    716 		printf(" not configured\n");
    717 		goto bad;
    718 	}
    719 
    720 	return;
    721 
    722 bad:
    723 	free(sc_link, M_DEVBUF);
    724 	return;
    725 }
    726