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