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