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