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