scsiconf.c revision 1.51 1 /* $NetBSD: scsiconf.c,v 1.51 1996/03/05 00:15:12 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 "MST ", "SnapLink ", ""}, SDEV_NOLUNS},
319 {{T_DIRECT, T_FIXED,
320 "QUANTUM ", "LPS525S ", ""}, SDEV_NOLUNS},
321 {{T_DIRECT, T_FIXED,
322 "QUANTUM ", "P105S 910-10-94x", ""}, SDEV_NOLUNS},
323 {{T_DIRECT, T_FIXED,
324 "QUANTUM ", "PD1225S ", ""}, SDEV_NOLUNS},
325 {{T_DIRECT, T_FIXED,
326 "QUANTUM ", "PD210S SUN0207", ""}, SDEV_NOLUNS},
327 {{T_DIRECT, T_FIXED,
328 "RODIME ", "RO3000S ", ""}, SDEV_NOLUNS},
329 {{T_DIRECT, T_FIXED,
330 "SEAGATE ", "ST157N ", ""}, SDEV_NOLUNS},
331 {{T_DIRECT, T_FIXED,
332 "SEAGATE ", "ST296 ", ""}, SDEV_NOLUNS},
333 {{T_DIRECT, T_FIXED,
334 "SEAGATE ", "ST296N ", ""}, SDEV_NOLUNS},
335 {{T_DIRECT, T_FIXED,
336 "TOSHIBA ", "MK538FB ", "6027"}, SDEV_NOLUNS},
337
338 /* XXX: QIC-36 tape behind Emulex adapter. Very broken. */
339 {{T_SEQUENTIAL, T_REMOV,
340 " ", " ", " "}, SDEV_NOLUNS},
341 {{T_SEQUENTIAL, T_REMOV,
342 "CALIPER ", "CP150 ", ""}, SDEV_NOLUNS},
343 {{T_SEQUENTIAL, T_REMOV,
344 "EXABYTE ", "EXB-8200 ", ""}, SDEV_NOLUNS},
345 {{T_SEQUENTIAL, T_REMOV,
346 "SONY ", "SDT-2000 ", "2.09"}, SDEV_NOLUNS},
347 {{T_SEQUENTIAL, T_REMOV,
348 "SONY ", "SDT-5000 ", "3."}, SDEV_NOSYNCWIDE},
349 {{T_SEQUENTIAL, T_REMOV,
350 "SONY ", "SDT-5200 ", "3."}, SDEV_NOLUNS},
351 {{T_SEQUENTIAL, T_REMOV,
352 "TANDBERG", " TDC 3600 ", ""}, SDEV_NOLUNS},
353 /* Following entry reported as a Tandberg 3600; ref. PR1933 */
354 {{T_SEQUENTIAL, T_REMOV,
355 "ARCHIVE ", "VIPER 150 21247", ""}, SDEV_NOLUNS},
356 {{T_SEQUENTIAL, T_REMOV,
357 "WANGTEK ", "5099ES SCSI", ""}, SDEV_NOLUNS},
358 {{T_SEQUENTIAL, T_REMOV,
359 "WANGTEK ", "5150ES SCSI", ""}, SDEV_NOLUNS},
360 {{T_SEQUENTIAL, T_REMOV,
361 "WangDAT ", "Model 1300 ", "02.4"}, SDEV_NOSYNCWIDE},
362 {{T_SEQUENTIAL, T_REMOV,
363 "WangDAT ", "Model 2600 ", "01.7"}, SDEV_NOSYNCWIDE},
364 {{T_SEQUENTIAL, T_REMOV,
365 "WangDAT ", "Model 3200 ", "02.2"}, SDEV_NOSYNCWIDE},
366 };
367
368 /*
369 * Print out autoconfiguration information for a subdevice.
370 *
371 * This is a slight abuse of 'standard' autoconfiguration semantics,
372 * because 'print' functions don't normally print the colon and
373 * device information. However, in this case that's better than
374 * either printing redundant information before the attach message,
375 * or having the device driver call a special function to print out
376 * the standard device information.
377 */
378 int
379 scsibusprint(aux, pnp)
380 void *aux;
381 char *pnp;
382 {
383 struct scsibus_attach_args *sa = aux;
384 struct scsi_inquiry_data *inqbuf;
385 u_int8_t type;
386 boolean removable;
387 char *dtype, *qtype;
388 char vendor[33], product[65], revision[17];
389 int target, lun;
390
391 if (pnp != NULL)
392 printf("%s", pnp);
393
394 inqbuf = sa->sa_inqbuf;
395
396 target = sa->sa_sc_link->target;
397 lun = sa->sa_sc_link->lun;
398
399 type = inqbuf->device & SID_TYPE;
400 removable = inqbuf->dev_qual2 & SID_REMOVABLE ? 1 : 0;
401
402 /*
403 * Figure out basic device type and qualifier.
404 */
405 dtype = 0;
406 switch (inqbuf->device & SID_QUAL) {
407 case SID_QUAL_LU_OK:
408 qtype = "";
409 break;
410
411 case SID_QUAL_LU_OFFLINE:
412 qtype = " offline";
413 break;
414
415 case SID_QUAL_RSVD:
416 case SID_QUAL_BAD_LU:
417 panic("scsibusprint: impossible qualifier");
418
419 default:
420 qtype = "";
421 dtype = "vendor-unique";
422 break;
423 }
424 if (dtype == 0) {
425 switch (type) {
426 case T_DIRECT:
427 dtype = "direct";
428 break;
429 case T_SEQUENTIAL:
430 dtype = "sequential";
431 break;
432 case T_PRINTER:
433 dtype = "printer";
434 break;
435 case T_PROCESSOR:
436 dtype = "processor";
437 break;
438 case T_CDROM:
439 dtype = "cdrom";
440 break;
441 case T_WORM:
442 dtype = "worm";
443 break;
444 case T_SCANNER:
445 dtype = "scanner";
446 break;
447 case T_OPTICAL:
448 dtype = "optical";
449 break;
450 case T_CHANGER:
451 dtype = "changer";
452 break;
453 case T_COMM:
454 dtype = "communication";
455 break;
456 case T_NODEVICE:
457 panic("scsibusprint: impossible device type");
458 default:
459 dtype = "unknown";
460 break;
461 }
462 }
463
464 scsi_strvis(vendor, inqbuf->vendor, 8);
465 scsi_strvis(product, inqbuf->product, 16);
466 scsi_strvis(revision, inqbuf->revision, 4);
467
468 printf(" targ %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s",
469 target, lun, vendor, product, revision,
470 inqbuf->version & SID_ANSII, type, dtype,
471 removable ? "removable" : "fixed", qtype);
472
473 return (UNCONF);
474 }
475
476 /*
477 * given a target and lu, ask the device what
478 * it is, and find the correct driver table
479 * entry.
480 */
481 void
482 scsi_probedev(scsi, target, lun)
483 struct scsibus_softc *scsi;
484 int target, lun;
485 {
486 struct scsi_link *sc_link;
487 static struct scsi_inquiry_data inqbuf;
488 struct scsi_quirk_inquiry_pattern *finger;
489 int checkdtype, priority;
490 struct scsibus_attach_args sa;
491 struct cfdata *cf;
492
493 /* Skip this slot if it is already attached. */
494 if (scsi->sc_link[target][lun])
495 return;
496
497 sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT);
498 *sc_link = *scsi->adapter_link;
499 sc_link->target = target;
500 sc_link->lun = lun;
501 sc_link->device = &probe_switch;
502
503 /*
504 * Ask the device what it is
505 */
506 #ifdef SCSIDEBUG
507 if (target == DEBUGTARGET && lun == DEBUGLUN)
508 sc_link->flags |= DEBUGLEVEL;
509 #endif /* SCSIDEBUG */
510
511 (void) scsi_test_unit_ready(sc_link,
512 SCSI_AUTOCONF | SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_NOT_READY | SCSI_IGNORE_MEDIA_CHANGE);
513
514 #ifdef SCSI_2_DEF
515 /* some devices need to be told to go to SCSI2 */
516 /* However some just explode if you tell them this.. leave it out */
517 scsi_change_def(sc_link, SCSI_AUTOCONF | SCSI_SILENT);
518 #endif /* SCSI_2_DEF */
519
520 /* Now go ask the device all about itself. */
521 bzero(&inqbuf, sizeof(inqbuf));
522 if (scsi_inquire(sc_link, &inqbuf, SCSI_AUTOCONF) != 0)
523 goto bad;
524
525 {
526 int len = inqbuf.additional_length;
527 while (len < 3)
528 inqbuf.unused[len++] = '\0';
529 while (len < 3 + 28)
530 inqbuf.unused[len++] = ' ';
531 }
532
533 finger = (struct scsi_quirk_inquiry_pattern *)scsi_inqmatch(&inqbuf,
534 (caddr_t)scsi_quirk_patterns,
535 sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
536 sizeof(scsi_quirk_patterns[0]), &priority);
537 if (priority != 0)
538 sc_link->quirks |= finger->quirks;
539 if ((inqbuf.version & SID_ANSII) == 0 &&
540 (sc_link->quirks & SDEV_FORCELUNS) == 0)
541 sc_link->quirks |= SDEV_NOLUNS;
542
543 if ((sc_link->quirks & SDEV_NOLUNS) == 0)
544 scsi->moreluns |= (1 << target);
545
546 /*
547 * note what BASIC type of device it is
548 */
549 if ((inqbuf.dev_qual2 & SID_REMOVABLE) != 0)
550 sc_link->flags |= SDEV_REMOVABLE;
551
552 /*
553 * Any device qualifier that has the top bit set (qualifier&4 != 0)
554 * is vendor specific and won't match in this switch.
555 * All we do here is throw out bad/negative responses.
556 */
557 checkdtype = 0;
558 switch (inqbuf.device & SID_QUAL) {
559 case SID_QUAL_LU_OK:
560 case SID_QUAL_LU_OFFLINE:
561 checkdtype = 1;
562 break;
563
564 case SID_QUAL_RSVD:
565 case SID_QUAL_BAD_LU:
566 goto bad;
567
568 default:
569 break;
570 }
571 if (checkdtype) {
572 switch (inqbuf.device & SID_TYPE) {
573 case T_DIRECT:
574 case T_SEQUENTIAL:
575 case T_PRINTER:
576 case T_PROCESSOR:
577 case T_CDROM:
578 case T_WORM:
579 case T_SCANNER:
580 case T_OPTICAL:
581 case T_CHANGER:
582 case T_COMM:
583 default:
584 break;
585 case T_NODEVICE:
586 goto bad;
587 }
588 }
589
590 sa.sa_sc_link = sc_link;
591 sa.sa_inqbuf = &inqbuf;
592
593 if ((cf = config_search(scsibussubmatch, (struct device *)scsi, &sa)) != 0) {
594 scsi->sc_link[target][lun] = sc_link;
595 config_attach((struct device *)scsi, cf, &sa, scsibusprint);
596 } else {
597 scsibusprint(&sa, scsi->sc_dev.dv_xname);
598 printf(" not configured\n");
599 goto bad;
600 }
601
602 return;
603
604 bad:
605 free(sc_link, M_DEVBUF);
606 return;
607 }
608
609 /*
610 * Return a priority based on how much of the inquiry data matches
611 * the patterns for the particular driver.
612 */
613 caddr_t
614 scsi_inqmatch(inqbuf, base, nmatches, matchsize, bestpriority)
615 struct scsi_inquiry_data *inqbuf;
616 caddr_t base;
617 int nmatches, matchsize;
618 int *bestpriority;
619 {
620 u_int8_t type;
621 boolean removable;
622 caddr_t bestmatch;
623
624 /* Include the qualifier to catch vendor-unique types. */
625 type = inqbuf->device;
626 removable = inqbuf->dev_qual2 & SID_REMOVABLE ? T_REMOV : T_FIXED;
627
628 for (*bestpriority = 0, bestmatch = 0; nmatches--; base += matchsize) {
629 struct scsi_inquiry_pattern *match = (void *)base;
630 int priority, len;
631
632 if (type != match->type)
633 continue;
634 if (removable != match->removable)
635 continue;
636 priority = 2;
637 len = strlen(match->vendor);
638 if (bcmp(inqbuf->vendor, match->vendor, len))
639 continue;
640 priority += len;
641 len = strlen(match->product);
642 if (bcmp(inqbuf->product, match->product, len))
643 continue;
644 priority += len;
645 len = strlen(match->revision);
646 if (bcmp(inqbuf->revision, match->revision, len))
647 continue;
648 priority += len;
649
650 #if SCSIDEBUG
651 printf("scsi_inqmatch: %d/%d/%d <%s, %s, %s>\n",
652 priority, match->type, match->removable,
653 match->vendor, match->product, match->revision);
654 #endif
655 if (priority > *bestpriority) {
656 *bestpriority = priority;
657 bestmatch = base;
658 }
659 }
660
661 return (bestmatch);
662 }
663