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