Home | History | Annotate | Line # | Download | only in scsipi
scsiconf.c revision 1.45
      1 /*	$NetBSD: scsiconf.c,v 1.45 1995/12/11 04:43:01 mycroft 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 
     55 #include <scsi/scsi_all.h>
     56 #include <scsi/scsiconf.h>
     57 
     58 #if 0
     59 #if NCALS > 0
     60 	{ T_PROCESSOR, T_FIXED, 1,
     61 	  0, 0, 0 },
     62 #endif	/* NCALS */
     63 #if NBLL > 0
     64 	{ T_PROCESSOR, T_FIXED, 1,
     65 	  "AEG     ", "READER          ", "V1.0" },
     66 #endif	/* NBLL */
     67 #if NKIL > 0
     68 	{ T_SCANNER, T_FIXED, 0,
     69 	  "KODAK   ", "IL Scanner 900  ", 0 },
     70 #endif	/* NKIL */
     71 #endif
     72 
     73 /*
     74  * Declarations
     75  */
     76 void scsi_probedev __P((struct scsibus_softc *, int, int));
     77 int scsi_probe_bus __P((int bus, int target, int lun));
     78 
     79 struct scsi_device probe_switch = {
     80 	NULL,
     81 	NULL,
     82 	NULL,
     83 	NULL,
     84 };
     85 
     86 int scsibusmatch __P((struct device *, void *, void *));
     87 void scsibusattach __P((struct device *, struct device *, void *));
     88 
     89 struct cfdriver scsibuscd = {
     90 	NULL, "scsibus", scsibusmatch, scsibusattach, DV_DULL,
     91 	sizeof(struct scsibus_softc)
     92 };
     93 
     94 int
     95 scsibusmatch(parent, match, aux)
     96         struct device *parent;
     97         void *match, *aux;
     98 {
     99 
    100 	return 1;
    101 }
    102 
    103 /*
    104  * The routine called by the adapter boards to get all their
    105  * devices configured in.
    106  */
    107 void
    108 scsibusattach(parent, self, aux)
    109         struct device *parent, *self;
    110         void *aux;
    111 {
    112 	struct scsibus_softc *sb = (struct scsibus_softc *)self;
    113 	struct scsi_link *sc_link_proto = aux;
    114 
    115 	sc_link_proto->scsibus = sb->sc_dev.dv_unit;
    116 	sb->adapter_link = sc_link_proto;
    117 	printf("\n");
    118 
    119 #if defined(SCSI_DELAY) && SCSI_DELAY > 2
    120 	printf("%s: waiting for scsi devices to settle\n",
    121 		sb->sc_dev.dv_xname);
    122 #else	/* SCSI_DELAY > 2 */
    123 #undef	SCSI_DELAY
    124 #define SCSI_DELAY 2
    125 #endif	/* SCSI_DELAY */
    126 	delay(1000000 * SCSI_DELAY);
    127 
    128 	scsi_probe_bus(sb->sc_dev.dv_unit, -1, -1);
    129 }
    130 
    131 int
    132 scsibussubmatch(parent, match, aux)
    133 	struct device *parent;
    134 	void *match, *aux;
    135 {
    136 	struct cfdata *cf = match;
    137 	struct scsibus_attach_args *sa = aux;
    138 	struct scsi_link *sc_link = sa->sa_sc_link;
    139 
    140 	if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != sc_link->target)
    141 		return 0;
    142 	if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != sc_link->lun)
    143 		return 0;
    144 	return ((*cf->cf_driver->cd_match)(parent, match, aux));
    145 }
    146 
    147 /*
    148  * Probe the requested scsi bus. It must be already set up.
    149  * -1 requests all set up scsi busses.
    150  * target and lun optionally narrow the search if not -1
    151  */
    152 int
    153 scsi_probe_busses(bus, target, lun)
    154 	int bus, target, lun;
    155 {
    156 
    157 	if (bus == -1) {
    158 		for (bus = 0; bus < scsibuscd.cd_ndevs; bus++)
    159 			if (scsibuscd.cd_devs[bus])
    160 				scsi_probe_bus(bus, target, lun);
    161 		return 0;
    162 	} else {
    163 		return scsi_probe_bus(bus, target, lun);
    164 	}
    165 }
    166 
    167 /*
    168  * Probe the requested scsi bus. It must be already set up.
    169  * target and lun optionally narrow the search if not -1
    170  */
    171 int
    172 scsi_probe_bus(bus, target, lun)
    173 	int bus, target, lun;
    174 {
    175 	struct scsibus_softc *scsi;
    176 	int maxtarget, mintarget, maxlun, minlun;
    177 	u_int8_t scsi_addr;
    178 
    179 	if (bus < 0 || bus >= scsibuscd.cd_ndevs)
    180 		return ENXIO;
    181 	scsi = scsibuscd.cd_devs[bus];
    182 	if (!scsi)
    183 		return ENXIO;
    184 
    185 	scsi_addr = scsi->adapter_link->adapter_target;
    186 
    187 	if (target == -1) {
    188 		maxtarget = 7;
    189 		mintarget = 0;
    190 	} else {
    191 		if (target < 0 || target > 7)
    192 			return EINVAL;
    193 		maxtarget = mintarget = target;
    194 	}
    195 
    196 	if (lun == -1) {
    197 		maxlun = 7;
    198 		minlun = 0;
    199 	} else {
    200 		if (lun < 0 || lun > 7)
    201 			return EINVAL;
    202 		maxlun = minlun = lun;
    203 	}
    204 
    205 	for (target = mintarget; target <= maxtarget; target++) {
    206 		if (target == scsi_addr)
    207 			continue;
    208 		for (lun = minlun; lun <= maxlun; lun++) {
    209 			/*
    210 			 * See if there's a device present, and configure it.
    211 			 */
    212 			scsi_probedev(scsi, target, lun);
    213 			if ((scsi->moreluns & (1 << target)) == 0)
    214 				break;
    215 			/* otherwise something says we should look further */
    216 		}
    217 	}
    218 	return 0;
    219 }
    220 
    221 void
    222 scsi_strvis(dst, src, len)
    223 	u_char *dst, *src;
    224 	int len;
    225 {
    226 
    227 	/* Trim leading and trailing blanks and NULs. */
    228 	while (len > 0 && (src[0] == ' ' || src[0] == '\0'))
    229 		++src, --len;
    230 	while (len > 0 && (src[len-1] == ' ' || src[len-1] == '\0'))
    231 		--len;
    232 
    233 	while (len > 0) {
    234 		if (*src < 0x20 || *src >= 0x80) {
    235 			/* non-printable characters */
    236 			*dst++ = '\\';
    237 			*dst++ = ((*src & 0300) >> 6) + '0';
    238 			*dst++ = ((*src & 0070) >> 3) + '0';
    239 			*dst++ = ((*src & 0007) >> 0) + '0';
    240 		} else if (*src == '\\') {
    241 			/* quote characters */
    242 			*dst++ = '\\';
    243 			*dst++ = '\\';
    244 		} else {
    245 			/* normal characters */
    246 			*dst++ = *src;
    247 		}
    248 		++src, --len;
    249 	}
    250 
    251 	*dst++ = 0;
    252 }
    253 
    254 struct scsi_quirk_inquiry_pattern {
    255 	struct scsi_inquiry_pattern pattern;
    256 	u_int8_t quirks;
    257 };
    258 
    259 struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
    260 	{T_CDROM, T_REMOV,
    261 	 "CHINON  ", "CD-ROM CDS-431  ", "",     SDEV_NOLUNS},
    262 	{T_CDROM, T_REMOV,
    263 	 "CHINON  ", "CD-ROM CDS-535  ", "",     SDEV_NOLUNS},
    264 	{T_CDROM, T_REMOV,
    265 	 "DENON   ", "DRD-25X         ", "V",    SDEV_NOLUNS},
    266 	{T_CDROM, T_REMOV,
    267 	 "IMS     ", "CDD521/10       ", "2.06", SDEV_NOLUNS},
    268 	{T_CDROM, T_REMOV,
    269 	 "MEDIAVIS", "CDR-H93MV       ", "1.31", SDEV_NOLUNS},
    270 	{T_CDROM, T_REMOV,
    271 	 "NEC     ", "CD-ROM DRIVE:55 ", "",     SDEV_NOLUNS},
    272 	{T_CDROM, T_REMOV,
    273 	 "NEC     ", "CD-ROM DRIVE:83 ", "",     SDEV_NOLUNS},
    274 	{T_CDROM, T_REMOV,
    275 	 "NEC     ", "CD-ROM DRIVE:84 ", "",     SDEV_NOLUNS},
    276 	{T_CDROM, T_REMOV,
    277 	 "NEC     ", "CD-ROM DRIVE:841", "",     SDEV_NOLUNS},
    278 	{T_CDROM, T_REMOV,
    279 	 "SONY    ", "CD-ROM CDU-541  ", "",     SDEV_NOLUNS},
    280 	{T_CDROM, T_REMOV,
    281 	 "SONY    ", "CD-ROM CDU-55S  ", "",     SDEV_NOLUNS},
    282 	{T_CDROM, T_REMOV,
    283 	 "SONY    ", "CD-ROM CDU-8003A", "",     SDEV_NOLUNS},
    284 	{T_CDROM, T_REMOV,
    285 	 "SONY    ", "CD-ROM CDU-8012 ", "",     SDEV_NOLUNS},
    286 	{T_CDROM, T_REMOV,
    287 	 "TEAC    ", "CD-ROM          ", "1.06", SDEV_NOLUNS},
    288 	{T_CDROM, T_REMOV,
    289 	 "TEXEL   ", "CD-ROM          ", "1.06", SDEV_NOLUNS},
    290 	{T_CDROM, T_REMOV,
    291 	 "TEXEL   ", "CD-ROM DM-XX24 K", "1.10", SDEV_NOLUNS},
    292 
    293 	{T_DIRECT, T_FIXED,
    294 	 "EMULEX  ", "MD21/S2     ESDI", "A00",  SDEV_FORCELUNS},
    295 	{T_DIRECT, T_FIXED,
    296 	 "MAXTOR  ", "XT-3280         ", "",     SDEV_NOLUNS},
    297 	{T_DIRECT, T_FIXED,
    298 	 "MAXTOR  ", "XT-4380S        ", "",     SDEV_NOLUNS},
    299 	{T_DIRECT, T_FIXED,
    300 	 "MAXTOR  ", "MXT-1240S       ", "",     SDEV_NOLUNS},
    301 	{T_DIRECT, T_FIXED,
    302 	 "MAXTOR  ", "XT-4170S        ", "",     SDEV_NOLUNS},
    303 	{T_DIRECT, T_FIXED,
    304 	 "MAXTOR  ", "XT-8760S        ", "",     SDEV_NOLUNS},
    305 	{T_DIRECT, T_FIXED,
    306 	 "MAXTOR  ", "LXT-213S        ", "",     SDEV_NOLUNS},
    307 	{T_DIRECT, T_FIXED,
    308 	 "MAXTOR  ", "LXT-213S SUN0207", "",     SDEV_NOLUNS},
    309 	{T_DIRECT, T_FIXED,
    310 	 "MST     ", "SnapLink        ", "",     SDEV_NOLUNS},
    311 	{T_DIRECT, T_FIXED,
    312 	 "QUANTUM ", "LPS525S         ", "",     SDEV_NOLUNS},
    313 	{T_DIRECT, T_FIXED,
    314 	 "QUANTUM ", "P105S 910-10-94x", "",     SDEV_NOLUNS},
    315 	{T_DIRECT, T_FIXED,
    316 	 "QUANTUM ", "PD1225S         ", "",     SDEV_NOLUNS},
    317 	{T_DIRECT, T_FIXED,
    318 	 "QUANTUM ", "PD210S   SUN0207", "",     SDEV_NOLUNS},
    319 	{T_DIRECT, T_FIXED,
    320 	 "RODIME  ", "RO3000S         ", "",     SDEV_NOLUNS},
    321 	{T_DIRECT, T_FIXED,
    322 	 "SEAGATE ", "ST157N          ", "",     SDEV_NOLUNS},
    323 	{T_DIRECT, T_FIXED,
    324 	 "SEAGATE ", "ST296           ", "",     SDEV_NOLUNS},
    325 	{T_DIRECT, T_FIXED,
    326 	 "SEAGATE ", "ST296N          ", "",     SDEV_NOLUNS},
    327 	{T_DIRECT, T_FIXED,
    328 	 "TOSHIBA ", "MK538FB         ", "6027", SDEV_NOLUNS},
    329 
    330 	/* XXX: QIC-36 tape behind Emulex adapter.  Very broken. */
    331 	{T_SEQUENTIAL, T_REMOV,
    332 	 "        ", "                ", "    ", SDEV_NOLUNS},
    333 	{T_SEQUENTIAL, T_REMOV,
    334 	 "CALIPER ", "CP150           ", "",     SDEV_NOLUNS},
    335 	{T_SEQUENTIAL, T_REMOV,
    336 	 "EXABYTE ", "EXB-8200        ", "",     SDEV_NOLUNS},
    337 	{T_SEQUENTIAL, T_REMOV,
    338 	 "SONY    ", "SDT-2000        ", "2.09", SDEV_NOLUNS},
    339 	{T_SEQUENTIAL, T_REMOV,
    340 	 "SONY    ", "SDT-5000        ", "3.",   SDEV_NOSYNCWIDE},
    341 	{T_SEQUENTIAL, T_REMOV,
    342 	 "SONY    ", "SDT-5200        ", "3.",   SDEV_NOLUNS},
    343 	{T_SEQUENTIAL, T_REMOV,
    344 	 "TANDBERG", " TDC 3600       ", "",     SDEV_NOLUNS},
    345 	{T_SEQUENTIAL, T_REMOV,
    346 	 "WANGTEK ", "5099ES SCSI",      "",     SDEV_NOLUNS},
    347 	{T_SEQUENTIAL, T_REMOV,
    348 	 "WANGTEK ", "5150ES SCSI",      "",     SDEV_NOLUNS},
    349 	{T_SEQUENTIAL, T_REMOV,
    350 	 "WangDAT ", "Model 1300      ", "02.4", SDEV_NOSYNCWIDE},
    351 	{T_SEQUENTIAL, T_REMOV,
    352 	 "WangDAT ", "Model 2600      ", "01.7", SDEV_NOSYNCWIDE},
    353 	{T_SEQUENTIAL, T_REMOV,
    354 	 "WangDAT ", "Model 3200      ", "02.2", SDEV_NOSYNCWIDE},
    355 };
    356 
    357 /*
    358  * given a target and lu, ask the device what
    359  * it is, and find the correct driver table
    360  * entry.
    361  */
    362 void
    363 scsi_probedev(scsi, target, lun)
    364 	struct scsibus_softc *scsi;
    365 	int target, lun;
    366 {
    367 	struct scsi_link *sc_link;
    368 	static struct scsi_inquiry_data inqbuf;
    369 	struct scsi_quirk_inquiry_pattern *finger;
    370 	int priority;
    371 	u_int8_t type;
    372 	boolean removable;
    373 	char *dtype, *qtype;
    374 	char vendor[33], product[65], revision[17];
    375 	struct scsibus_attach_args sa;
    376 	struct cfdata *cf;
    377 
    378 	/* Skip this slot if it is already attached. */
    379 	if (scsi->sc_link[target][lun])
    380 		return;
    381 
    382 	sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT);
    383 	*sc_link = *scsi->adapter_link;
    384 	sc_link->target = target;
    385 	sc_link->lun = lun;
    386 	sc_link->device = &probe_switch;
    387 
    388 	/*
    389 	 * Ask the device what it is
    390 	 */
    391 #ifdef SCSIDEBUG
    392 	if (target == DEBUGTARGET && lun == DEBUGLUN)
    393 		sc_link->flags |= DEBUGLEVEL;
    394 #endif /* SCSIDEBUG */
    395 
    396 	(void) scsi_test_unit_ready(sc_link,
    397 	    SCSI_AUTOCONF | SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_NOT_READY | SCSI_IGNORE_MEDIA_CHANGE);
    398 
    399 #ifdef SCSI_2_DEF
    400 	/* some devices need to be told to go to SCSI2 */
    401 	/* However some just explode if you tell them this.. leave it out */
    402 	scsi_change_def(sc_link, SCSI_AUTOCONF | SCSI_SILENT);
    403 #endif /* SCSI_2_DEF */
    404 
    405 	/* Now go ask the device all about itself. */
    406 	bzero(&inqbuf, sizeof(inqbuf));
    407 	if (scsi_inquire(sc_link, &inqbuf, SCSI_AUTOCONF) != 0)
    408 		goto bad;
    409 
    410 	{
    411 		int len = inqbuf.additional_length;
    412 		while (len < 3)
    413 			inqbuf.unused[len++] = '\0';
    414 		while (len < 3 + 28)
    415 			inqbuf.unused[len++] = ' ';
    416 	}
    417 
    418 	finger = (struct scsi_quirk_inquiry_pattern *)scsi_inqmatch(&inqbuf,
    419 	    (caddr_t)scsi_quirk_patterns,
    420 	    sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
    421 	    sizeof(scsi_quirk_patterns[0]), &priority);
    422 	if (priority != 0)
    423 		sc_link->quirks |= finger->quirks;
    424 	if ((inqbuf.version & SID_ANSII) == 0 &&
    425 	    (sc_link->quirks & SDEV_FORCELUNS) == 0)
    426 		sc_link->quirks |= SDEV_NOLUNS;
    427 
    428 	if ((sc_link->quirks & SDEV_NOLUNS) == 0)
    429 		scsi->moreluns |= (1 << target);
    430 
    431 	/*
    432 	 * note what BASIC type of device it is
    433 	 */
    434 	type = inqbuf.device & SID_TYPE;
    435 	removable = inqbuf.dev_qual2 & SID_REMOVABLE ? 1 : 0;
    436 
    437 	if (removable)
    438 		sc_link->flags |= SDEV_REMOVABLE;
    439 
    440 	/*
    441 	 * Any device qualifier that has the top bit set (qualifier&4 != 0)
    442 	 * is vendor specific and won't match in this switch.
    443 	 */
    444 	dtype = 0;
    445 	switch (inqbuf.device & SID_QUAL) {
    446 	case SID_QUAL_LU_OK:
    447 		qtype = "";
    448 		break;
    449 
    450 	case SID_QUAL_LU_OFFLINE:
    451 		qtype = " offline";
    452 		break;
    453 
    454 	case SID_QUAL_RSVD:
    455 	case SID_QUAL_BAD_LU:
    456 		goto bad;
    457 
    458 	default:
    459 		qtype = "";
    460 		dtype = "vendor-unique";
    461 		break;
    462 	}
    463 	if (dtype == 0) {
    464 		switch (type) {
    465 		case T_DIRECT:
    466 			dtype = "direct";
    467 			break;
    468 		case T_SEQUENTIAL:
    469 			dtype = "sequential";
    470 			break;
    471 		case T_PRINTER:
    472 			dtype = "printer";
    473 			break;
    474 		case T_PROCESSOR:
    475 			dtype = "processor";
    476 			break;
    477 		case T_CDROM:
    478 			dtype = "cdrom";
    479 			break;
    480 		case T_WORM:
    481 			dtype = "worm";
    482 			break;
    483 		case T_SCANNER:
    484 			dtype = "scanner";
    485 			break;
    486 		case T_OPTICAL:
    487 			dtype = "optical";
    488 			break;
    489 		case T_CHANGER:
    490 			dtype = "changer";
    491 			break;
    492 		case T_COMM:
    493 			dtype = "communication";
    494 			break;
    495 		case T_NODEVICE:
    496 			goto bad;
    497 		default:
    498 			dtype = "unknown";
    499 			break;
    500 		}
    501 	}
    502 
    503 	scsi_strvis(vendor, inqbuf.vendor, 8);
    504 	scsi_strvis(product, inqbuf.product, 16);
    505 	scsi_strvis(revision, inqbuf.revision, 4);
    506 
    507 	printf("%s targ %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s\n",
    508 	    ((struct device *)sc_link->adapter_softc)->dv_xname,
    509 	    target, lun, vendor, product, revision,
    510 	    inqbuf.version & SID_ANSII, type, dtype,
    511 	    removable ? "removable" : "fixed", qtype);
    512 
    513 	sa.sa_sc_link = sc_link;
    514 	sa.sa_inqbuf = &inqbuf;
    515 
    516 	if ((cf = config_search(scsibussubmatch, (struct device *)scsi, &sa)) != 0) {
    517 		scsi->sc_link[target][lun] = sc_link;
    518 		config_attach((struct device *)scsi, cf, &sa, NULL);
    519 	} else
    520 		goto bad;
    521 
    522 	return;
    523 
    524 bad:
    525 	free(sc_link, M_DEVBUF);
    526 	return;
    527 }
    528 
    529 /*
    530  * Return a priority based on how much of the inquiry data matches
    531  * the patterns for the particular driver.
    532  */
    533 caddr_t
    534 scsi_inqmatch(inqbuf, base, nmatches, matchsize, bestpriority)
    535 	struct scsi_inquiry_data *inqbuf;
    536 	caddr_t base;
    537 	int nmatches, matchsize;
    538 	int *bestpriority;
    539 {
    540 	u_int8_t type;
    541 	boolean removable;
    542 	caddr_t bestmatch;
    543 
    544 	/* Include the qualifier to catch vendor-unique types. */
    545 	type = inqbuf->device;
    546 	removable = inqbuf->dev_qual2 & SID_REMOVABLE ? T_REMOV : T_FIXED;
    547 
    548 	for (*bestpriority = 0, bestmatch = 0; nmatches--; base += matchsize) {
    549 		struct scsi_inquiry_pattern *match = (void *)base;
    550 		int priority, len;
    551 
    552 		if (type != match->type)
    553 			continue;
    554 		if (removable != match->removable)
    555 			continue;
    556 		priority = 2;
    557 		len = strlen(match->vendor);
    558 		if (bcmp(inqbuf->vendor, match->vendor, len))
    559 			continue;
    560 		priority += len;
    561 		len = strlen(match->product);
    562 		if (bcmp(inqbuf->product, match->product, len))
    563 			continue;
    564 		priority += len;
    565 		len = strlen(match->revision);
    566 		if (bcmp(inqbuf->revision, match->revision, len))
    567 			continue;
    568 		priority += len;
    569 
    570 #if SCSIDEBUG
    571 		printf("scsi_inqmatch: %d/%d/%d <%s, %s, %s>\n",
    572 		    priority, match->type, match->removable,
    573 		    match->vendor, match->product, match->revision);
    574 #endif
    575 		if (priority > *bestpriority) {
    576 			*bestpriority = priority;
    577 			bestmatch = base;
    578 		}
    579 	}
    580 
    581 	return (bestmatch);
    582 }
    583