Home | History | Annotate | Line # | Download | only in scsipi
scsiconf.c revision 1.48
      1 /*	$NetBSD: scsiconf.c,v 1.48 1996/02/14 21:47:27 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994 Charles Hannum.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Charles Hannum.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * Originally written by Julian Elischer (julian (at) tfs.com)
     34  * for TRW Financial Systems for use under the MACH(2.5) operating system.
     35  *
     36  * TRW Financial Systems, in accordance with their agreement with Carnegie
     37  * Mellon University, makes this software available to CMU to distribute
     38  * or use in any manner that they see fit as long as this message is kept with
     39  * the software. For this reason TFS also grants any other persons or
     40  * organisations permission to use or modify this software.
     41  *
     42  * TFS supplies this software to be publicly redistributed
     43  * on the understanding that TFS is not responsible for the correct
     44  * functioning of this software in any circumstances.
     45  *
     46  * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
     47  */
     48 
     49 #include <sys/types.h>
     50 #include <sys/param.h>
     51 #include <sys/systm.h>
     52 #include <sys/malloc.h>
     53 #include <sys/device.h>
     54 #include <sys/cpu.h>
     55 
     56 #include <scsi/scsi_all.h>
     57 #include <scsi/scsiconf.h>
     58 
     59 #if 0
     60 #if NCALS > 0
     61 	{ T_PROCESSOR, T_FIXED, 1,
     62 	  0, 0, 0 },
     63 #endif	/* NCALS */
     64 #if NBLL > 0
     65 	{ T_PROCESSOR, T_FIXED, 1,
     66 	  "AEG     ", "READER          ", "V1.0" },
     67 #endif	/* NBLL */
     68 #if NKIL > 0
     69 	{ T_SCANNER, T_FIXED, 0,
     70 	  "KODAK   ", "IL Scanner 900  ", 0 },
     71 #endif	/* NKIL */
     72 #endif
     73 
     74 /*
     75  * Declarations
     76  */
     77 void scsi_probedev __P((struct scsibus_softc *, int, int));
     78 int scsi_probe_bus __P((int bus, int target, int lun));
     79 void scsi_strvis __P((u_char *, u_char *, int));
     80 
     81 struct scsi_device probe_switch = {
     82 	NULL,
     83 	NULL,
     84 	NULL,
     85 	NULL,
     86 };
     87 
     88 int scsibusmatch __P((struct device *, void *, void *));
     89 void scsibusattach __P((struct device *, struct device *, void *));
     90 int scsibussubmatch __P((struct device *, void *, void *));
     91 
     92 struct cfdriver scsibuscd = {
     93 	NULL, "scsibus", scsibusmatch, scsibusattach, DV_DULL,
     94 	sizeof(struct scsibus_softc)
     95 };
     96 
     97 int
     98 scsibusmatch(parent, match, aux)
     99         struct device *parent;
    100         void *match, *aux;
    101 {
    102 
    103 	return 1;
    104 }
    105 
    106 /*
    107  * The routine called by the adapter boards to get all their
    108  * devices configured in.
    109  */
    110 void
    111 scsibusattach(parent, self, aux)
    112         struct device *parent, *self;
    113         void *aux;
    114 {
    115 	struct scsibus_softc *sb = (struct scsibus_softc *)self;
    116 	struct scsi_link *sc_link_proto = aux;
    117 
    118 	sc_link_proto->scsibus = sb->sc_dev.dv_unit;
    119 	sb->adapter_link = sc_link_proto;
    120 	printf("\n");
    121 
    122 #if defined(SCSI_DELAY) && SCSI_DELAY > 2
    123 	printf("%s: waiting for scsi devices to settle\n",
    124 		sb->sc_dev.dv_xname);
    125 #else	/* SCSI_DELAY > 2 */
    126 #undef	SCSI_DELAY
    127 #define SCSI_DELAY 2
    128 #endif	/* SCSI_DELAY */
    129 	delay(1000000 * SCSI_DELAY);
    130 
    131 	scsi_probe_bus(sb->sc_dev.dv_unit, -1, -1);
    132 }
    133 
    134 int
    135 scsibussubmatch(parent, match, aux)
    136 	struct device *parent;
    137 	void *match, *aux;
    138 {
    139 	struct cfdata *cf = match;
    140 	struct scsibus_attach_args *sa = aux;
    141 	struct scsi_link *sc_link = sa->sa_sc_link;
    142 
    143 	if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != sc_link->target)
    144 		return 0;
    145 	if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != sc_link->lun)
    146 		return 0;
    147 	return ((*cf->cf_driver->cd_match)(parent, match, aux));
    148 }
    149 
    150 /*
    151  * Probe the requested scsi bus. It must be already set up.
    152  * -1 requests all set up scsi busses.
    153  * target and lun optionally narrow the search if not -1
    154  */
    155 int
    156 scsi_probe_busses(bus, target, lun)
    157 	int bus, target, lun;
    158 {
    159 
    160 	if (bus == -1) {
    161 		for (bus = 0; bus < scsibuscd.cd_ndevs; bus++)
    162 			if (scsibuscd.cd_devs[bus])
    163 				scsi_probe_bus(bus, target, lun);
    164 		return 0;
    165 	} else {
    166 		return scsi_probe_bus(bus, target, lun);
    167 	}
    168 }
    169 
    170 /*
    171  * Probe the requested scsi bus. It must be already set up.
    172  * target and lun optionally narrow the search if not -1
    173  */
    174 int
    175 scsi_probe_bus(bus, target, lun)
    176 	int bus, target, lun;
    177 {
    178 	struct scsibus_softc *scsi;
    179 	int maxtarget, mintarget, maxlun, minlun;
    180 	u_int8_t scsi_addr;
    181 
    182 	if (bus < 0 || bus >= scsibuscd.cd_ndevs)
    183 		return ENXIO;
    184 	scsi = scsibuscd.cd_devs[bus];
    185 	if (!scsi)
    186 		return ENXIO;
    187 
    188 	scsi_addr = scsi->adapter_link->adapter_target;
    189 
    190 	if (target == -1) {
    191 		maxtarget = 7;
    192 		mintarget = 0;
    193 	} else {
    194 		if (target < 0 || target > 7)
    195 			return EINVAL;
    196 		maxtarget = mintarget = target;
    197 	}
    198 
    199 	if (lun == -1) {
    200 		maxlun = 7;
    201 		minlun = 0;
    202 	} else {
    203 		if (lun < 0 || lun > 7)
    204 			return EINVAL;
    205 		maxlun = minlun = lun;
    206 	}
    207 
    208 	for (target = mintarget; target <= maxtarget; target++) {
    209 		if (target == scsi_addr)
    210 			continue;
    211 		for (lun = minlun; lun <= maxlun; lun++) {
    212 			/*
    213 			 * See if there's a device present, and configure it.
    214 			 */
    215 			scsi_probedev(scsi, target, lun);
    216 			if ((scsi->moreluns & (1 << target)) == 0)
    217 				break;
    218 			/* otherwise something says we should look further */
    219 		}
    220 	}
    221 	return 0;
    222 }
    223 
    224 void
    225 scsi_strvis(dst, src, len)
    226 	u_char *dst, *src;
    227 	int len;
    228 {
    229 
    230 	/* Trim leading and trailing blanks and NULs. */
    231 	while (len > 0 && (src[0] == ' ' || src[0] == '\0'))
    232 		++src, --len;
    233 	while (len > 0 && (src[len-1] == ' ' || src[len-1] == '\0'))
    234 		--len;
    235 
    236 	while (len > 0) {
    237 		if (*src < 0x20 || *src >= 0x80) {
    238 			/* non-printable characters */
    239 			*dst++ = '\\';
    240 			*dst++ = ((*src & 0300) >> 6) + '0';
    241 			*dst++ = ((*src & 0070) >> 3) + '0';
    242 			*dst++ = ((*src & 0007) >> 0) + '0';
    243 		} else if (*src == '\\') {
    244 			/* quote characters */
    245 			*dst++ = '\\';
    246 			*dst++ = '\\';
    247 		} else {
    248 			/* normal characters */
    249 			*dst++ = *src;
    250 		}
    251 		++src, --len;
    252 	}
    253 
    254 	*dst++ = 0;
    255 }
    256 
    257 struct scsi_quirk_inquiry_pattern {
    258 	struct scsi_inquiry_pattern pattern;
    259 	u_int8_t quirks;
    260 };
    261 
    262 struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
    263 	{{T_CDROM, T_REMOV,
    264 	 "CHINON  ", "CD-ROM CDS-431  ", ""},     SDEV_NOLUNS},
    265 	{{T_CDROM, T_REMOV,
    266 	 "Chinon  ", "CD-ROM CDS-525  ", ""},     SDEV_NOLUNS},
    267 	{{T_CDROM, T_REMOV,
    268 	 "CHINON  ", "CD-ROM CDS-535  ", ""},     SDEV_NOLUNS},
    269 	{{T_CDROM, T_REMOV,
    270 	 "DENON   ", "DRD-25X         ", "V"},    SDEV_NOLUNS},
    271 	{{T_CDROM, T_REMOV,
    272 	 "IMS     ", "CDD521/10       ", "2.06"}, SDEV_NOLUNS},
    273 	{{T_CDROM, T_REMOV,
    274 	 "MEDIAVIS", "CDR-H93MV       ", "1.31"}, SDEV_NOLUNS},
    275 	{{T_CDROM, T_REMOV,
    276 	 "NEC     ", "CD-ROM DRIVE:55 ", ""},     SDEV_NOLUNS},
    277 	{{T_CDROM, T_REMOV,
    278 	 "NEC     ", "CD-ROM DRIVE:83 ", ""},     SDEV_NOLUNS},
    279 	{{T_CDROM, T_REMOV,
    280 	 "NEC     ", "CD-ROM DRIVE:84 ", ""},     SDEV_NOLUNS},
    281 	{{T_CDROM, T_REMOV,
    282 	 "NEC     ", "CD-ROM DRIVE:841", ""},     SDEV_NOLUNS},
    283 	{{T_CDROM, T_REMOV,
    284 	 "SONY    ", "CD-ROM CDU-541  ", ""},     SDEV_NOLUNS},
    285 	{{T_CDROM, T_REMOV,
    286 	 "SONY    ", "CD-ROM CDU-55S  ", ""},     SDEV_NOLUNS},
    287 	{{T_CDROM, T_REMOV,
    288 	 "SONY    ", "CD-ROM CDU-8003A", ""},     SDEV_NOLUNS},
    289 	{{T_CDROM, T_REMOV,
    290 	 "SONY    ", "CD-ROM CDU-8012 ", ""},     SDEV_NOLUNS},
    291 	{{T_CDROM, T_REMOV,
    292 	 "TEAC    ", "CD-ROM          ", "1.06"}, SDEV_NOLUNS},
    293 	{{T_CDROM, T_REMOV,
    294 	 "TEXEL   ", "CD-ROM          ", "1.06"}, SDEV_NOLUNS},
    295 	{{T_CDROM, T_REMOV,
    296 	 "TEXEL   ", "CD-ROM DM-XX24 K", "1.10"}, SDEV_NOLUNS},
    297 
    298 	{{T_DIRECT, T_FIXED,
    299 	 "EMULEX  ", "MD21/S2     ESDI", "A00"},  SDEV_FORCELUNS},
    300 	{{T_DIRECT, T_FIXED,
    301 	 "MAXTOR  ", "XT-3280         ", ""},     SDEV_NOLUNS},
    302 	{{T_DIRECT, T_FIXED,
    303 	 "MAXTOR  ", "XT-4380S        ", ""},     SDEV_NOLUNS},
    304 	{{T_DIRECT, T_FIXED,
    305 	 "MAXTOR  ", "MXT-1240S       ", ""},     SDEV_NOLUNS},
    306 	{{T_DIRECT, T_FIXED,
    307 	 "MAXTOR  ", "XT-4170S        ", ""},     SDEV_NOLUNS},
    308 	{{T_DIRECT, T_FIXED,
    309 	 "MAXTOR  ", "XT-8760S        ", ""},     SDEV_NOLUNS},
    310 	{{T_DIRECT, T_FIXED,
    311 	 "MAXTOR  ", "LXT-213S        ", ""},     SDEV_NOLUNS},
    312 	{{T_DIRECT, T_FIXED,
    313 	 "MAXTOR  ", "LXT-213S SUN0207", ""},     SDEV_NOLUNS},
    314 	{{T_DIRECT, T_FIXED,
    315 	 "MST     ", "SnapLink        ", ""},     SDEV_NOLUNS},
    316 	{{T_DIRECT, T_FIXED,
    317 	 "QUANTUM ", "LPS525S         ", ""},     SDEV_NOLUNS},
    318 	{{T_DIRECT, T_FIXED,
    319 	 "QUANTUM ", "P105S 910-10-94x", ""},     SDEV_NOLUNS},
    320 	{{T_DIRECT, T_FIXED,
    321 	 "QUANTUM ", "PD1225S         ", ""},     SDEV_NOLUNS},
    322 	{{T_DIRECT, T_FIXED,
    323 	 "QUANTUM ", "PD210S   SUN0207", ""},     SDEV_NOLUNS},
    324 	{{T_DIRECT, T_FIXED,
    325 	 "RODIME  ", "RO3000S         ", ""},     SDEV_NOLUNS},
    326 	{{T_DIRECT, T_FIXED,
    327 	 "SEAGATE ", "ST157N          ", ""},     SDEV_NOLUNS},
    328 	{{T_DIRECT, T_FIXED,
    329 	 "SEAGATE ", "ST296           ", ""},     SDEV_NOLUNS},
    330 	{{T_DIRECT, T_FIXED,
    331 	 "SEAGATE ", "ST296N          ", ""},     SDEV_NOLUNS},
    332 	{{T_DIRECT, T_FIXED,
    333 	 "TOSHIBA ", "MK538FB         ", "6027"}, SDEV_NOLUNS},
    334 
    335 	/* XXX: QIC-36 tape behind Emulex adapter.  Very broken. */
    336 	{{T_SEQUENTIAL, T_REMOV,
    337 	 "        ", "                ", "    "}, SDEV_NOLUNS},
    338 	{{T_SEQUENTIAL, T_REMOV,
    339 	 "CALIPER ", "CP150           ", ""},     SDEV_NOLUNS},
    340 	{{T_SEQUENTIAL, T_REMOV,
    341 	 "EXABYTE ", "EXB-8200        ", ""},     SDEV_NOLUNS},
    342 	{{T_SEQUENTIAL, T_REMOV,
    343 	 "SONY    ", "SDT-2000        ", "2.09"}, SDEV_NOLUNS},
    344 	{{T_SEQUENTIAL, T_REMOV,
    345 	 "SONY    ", "SDT-5000        ", "3."},   SDEV_NOSYNCWIDE},
    346 	{{T_SEQUENTIAL, T_REMOV,
    347 	 "SONY    ", "SDT-5200        ", "3."},   SDEV_NOLUNS},
    348 	{{T_SEQUENTIAL, T_REMOV,
    349 	 "TANDBERG", " TDC 3600       ", ""},     SDEV_NOLUNS},
    350 	/* Following entry reported as a Tandberg 3600; ref. PR1933 */
    351 	{{T_SEQUENTIAL, T_REMOV,
    352 	 "ARCHIVE ", "VIPER 150  21247", ""},     SDEV_NOLUNS},
    353 	{{T_SEQUENTIAL, T_REMOV,
    354 	 "WANGTEK ", "5099ES SCSI",      ""},     SDEV_NOLUNS},
    355 	{{T_SEQUENTIAL, T_REMOV,
    356 	 "WANGTEK ", "5150ES SCSI",      ""},     SDEV_NOLUNS},
    357 	{{T_SEQUENTIAL, T_REMOV,
    358 	 "WangDAT ", "Model 1300      ", "02.4"}, SDEV_NOSYNCWIDE},
    359 	{{T_SEQUENTIAL, T_REMOV,
    360 	 "WangDAT ", "Model 2600      ", "01.7"}, SDEV_NOSYNCWIDE},
    361 	{{T_SEQUENTIAL, T_REMOV,
    362 	 "WangDAT ", "Model 3200      ", "02.2"}, SDEV_NOSYNCWIDE},
    363 };
    364 
    365 /*
    366  * given a target and lu, ask the device what
    367  * it is, and find the correct driver table
    368  * entry.
    369  */
    370 void
    371 scsi_probedev(scsi, target, lun)
    372 	struct scsibus_softc *scsi;
    373 	int target, lun;
    374 {
    375 	struct scsi_link *sc_link;
    376 	static struct scsi_inquiry_data inqbuf;
    377 	struct scsi_quirk_inquiry_pattern *finger;
    378 	int priority;
    379 	u_int8_t type;
    380 	boolean removable;
    381 	char *dtype, *qtype;
    382 	char vendor[33], product[65], revision[17];
    383 	struct scsibus_attach_args sa;
    384 	struct cfdata *cf;
    385 
    386 	/* Skip this slot if it is already attached. */
    387 	if (scsi->sc_link[target][lun])
    388 		return;
    389 
    390 	sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT);
    391 	*sc_link = *scsi->adapter_link;
    392 	sc_link->target = target;
    393 	sc_link->lun = lun;
    394 	sc_link->device = &probe_switch;
    395 
    396 	/*
    397 	 * Ask the device what it is
    398 	 */
    399 #ifdef SCSIDEBUG
    400 	if (target == DEBUGTARGET && lun == DEBUGLUN)
    401 		sc_link->flags |= DEBUGLEVEL;
    402 #endif /* SCSIDEBUG */
    403 
    404 	(void) scsi_test_unit_ready(sc_link,
    405 	    SCSI_AUTOCONF | SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_NOT_READY | SCSI_IGNORE_MEDIA_CHANGE);
    406 
    407 #ifdef SCSI_2_DEF
    408 	/* some devices need to be told to go to SCSI2 */
    409 	/* However some just explode if you tell them this.. leave it out */
    410 	scsi_change_def(sc_link, SCSI_AUTOCONF | SCSI_SILENT);
    411 #endif /* SCSI_2_DEF */
    412 
    413 	/* Now go ask the device all about itself. */
    414 	bzero(&inqbuf, sizeof(inqbuf));
    415 	if (scsi_inquire(sc_link, &inqbuf, SCSI_AUTOCONF) != 0)
    416 		goto bad;
    417 
    418 	{
    419 		int len = inqbuf.additional_length;
    420 		while (len < 3)
    421 			inqbuf.unused[len++] = '\0';
    422 		while (len < 3 + 28)
    423 			inqbuf.unused[len++] = ' ';
    424 	}
    425 
    426 	finger = (struct scsi_quirk_inquiry_pattern *)scsi_inqmatch(&inqbuf,
    427 	    (caddr_t)scsi_quirk_patterns,
    428 	    sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
    429 	    sizeof(scsi_quirk_patterns[0]), &priority);
    430 	if (priority != 0)
    431 		sc_link->quirks |= finger->quirks;
    432 	if ((inqbuf.version & SID_ANSII) == 0 &&
    433 	    (sc_link->quirks & SDEV_FORCELUNS) == 0)
    434 		sc_link->quirks |= SDEV_NOLUNS;
    435 
    436 	if ((sc_link->quirks & SDEV_NOLUNS) == 0)
    437 		scsi->moreluns |= (1 << target);
    438 
    439 	/*
    440 	 * note what BASIC type of device it is
    441 	 */
    442 	type = inqbuf.device & SID_TYPE;
    443 	removable = inqbuf.dev_qual2 & SID_REMOVABLE ? 1 : 0;
    444 
    445 	if (removable)
    446 		sc_link->flags |= SDEV_REMOVABLE;
    447 
    448 	/*
    449 	 * Any device qualifier that has the top bit set (qualifier&4 != 0)
    450 	 * is vendor specific and won't match in this switch.
    451 	 */
    452 	dtype = 0;
    453 	switch (inqbuf.device & SID_QUAL) {
    454 	case SID_QUAL_LU_OK:
    455 		qtype = "";
    456 		break;
    457 
    458 	case SID_QUAL_LU_OFFLINE:
    459 		qtype = " offline";
    460 		break;
    461 
    462 	case SID_QUAL_RSVD:
    463 	case SID_QUAL_BAD_LU:
    464 		goto bad;
    465 
    466 	default:
    467 		qtype = "";
    468 		dtype = "vendor-unique";
    469 		break;
    470 	}
    471 	if (dtype == 0) {
    472 		switch (type) {
    473 		case T_DIRECT:
    474 			dtype = "direct";
    475 			break;
    476 		case T_SEQUENTIAL:
    477 			dtype = "sequential";
    478 			break;
    479 		case T_PRINTER:
    480 			dtype = "printer";
    481 			break;
    482 		case T_PROCESSOR:
    483 			dtype = "processor";
    484 			break;
    485 		case T_CDROM:
    486 			dtype = "cdrom";
    487 			break;
    488 		case T_WORM:
    489 			dtype = "worm";
    490 			break;
    491 		case T_SCANNER:
    492 			dtype = "scanner";
    493 			break;
    494 		case T_OPTICAL:
    495 			dtype = "optical";
    496 			break;
    497 		case T_CHANGER:
    498 			dtype = "changer";
    499 			break;
    500 		case T_COMM:
    501 			dtype = "communication";
    502 			break;
    503 		case T_NODEVICE:
    504 			goto bad;
    505 		default:
    506 			dtype = "unknown";
    507 			break;
    508 		}
    509 	}
    510 
    511 	scsi_strvis(vendor, inqbuf.vendor, 8);
    512 	scsi_strvis(product, inqbuf.product, 16);
    513 	scsi_strvis(revision, inqbuf.revision, 4);
    514 
    515 	printf("%s targ %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s\n",
    516 	    ((struct device *)sc_link->adapter_softc)->dv_xname,
    517 	    target, lun, vendor, product, revision,
    518 	    inqbuf.version & SID_ANSII, type, dtype,
    519 	    removable ? "removable" : "fixed", qtype);
    520 
    521 	sa.sa_sc_link = sc_link;
    522 	sa.sa_inqbuf = &inqbuf;
    523 
    524 	if ((cf = config_search(scsibussubmatch, (struct device *)scsi, &sa)) != 0) {
    525 		scsi->sc_link[target][lun] = sc_link;
    526 		config_attach((struct device *)scsi, cf, &sa, NULL);
    527 	} else
    528 		goto bad;
    529 
    530 	return;
    531 
    532 bad:
    533 	free(sc_link, M_DEVBUF);
    534 	return;
    535 }
    536 
    537 /*
    538  * Return a priority based on how much of the inquiry data matches
    539  * the patterns for the particular driver.
    540  */
    541 caddr_t
    542 scsi_inqmatch(inqbuf, base, nmatches, matchsize, bestpriority)
    543 	struct scsi_inquiry_data *inqbuf;
    544 	caddr_t base;
    545 	int nmatches, matchsize;
    546 	int *bestpriority;
    547 {
    548 	u_int8_t type;
    549 	boolean removable;
    550 	caddr_t bestmatch;
    551 
    552 	/* Include the qualifier to catch vendor-unique types. */
    553 	type = inqbuf->device;
    554 	removable = inqbuf->dev_qual2 & SID_REMOVABLE ? T_REMOV : T_FIXED;
    555 
    556 	for (*bestpriority = 0, bestmatch = 0; nmatches--; base += matchsize) {
    557 		struct scsi_inquiry_pattern *match = (void *)base;
    558 		int priority, len;
    559 
    560 		if (type != match->type)
    561 			continue;
    562 		if (removable != match->removable)
    563 			continue;
    564 		priority = 2;
    565 		len = strlen(match->vendor);
    566 		if (bcmp(inqbuf->vendor, match->vendor, len))
    567 			continue;
    568 		priority += len;
    569 		len = strlen(match->product);
    570 		if (bcmp(inqbuf->product, match->product, len))
    571 			continue;
    572 		priority += len;
    573 		len = strlen(match->revision);
    574 		if (bcmp(inqbuf->revision, match->revision, len))
    575 			continue;
    576 		priority += len;
    577 
    578 #if SCSIDEBUG
    579 		printf("scsi_inqmatch: %d/%d/%d <%s, %s, %s>\n",
    580 		    priority, match->type, match->removable,
    581 		    match->vendor, match->product, match->revision);
    582 #endif
    583 		if (priority > *bestpriority) {
    584 			*bestpriority = priority;
    585 			bestmatch = base;
    586 		}
    587 	}
    588 
    589 	return (bestmatch);
    590 }
    591