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