scsiconf.c revision 1.18 1 1.18 mycroft /* $NetBSD: scsiconf.c,v 1.18 1994/12/28 19:43:09 mycroft Exp $ */
2 1.14 cgd
3 1.1 cgd /*
4 1.12 mycroft * Copyright (c) 1994 Charles Hannum. All rights reserved.
5 1.12 mycroft *
6 1.12 mycroft * Redistribution and use in source and binary forms, with or without
7 1.12 mycroft * modification, are permitted provided that the following conditions
8 1.12 mycroft * are met:
9 1.12 mycroft * 1. Redistributions of source code must retain the above copyright
10 1.12 mycroft * notice, this list of conditions and the following disclaimer.
11 1.12 mycroft * 2. Redistributions in binary form must reproduce the above copyright
12 1.12 mycroft * notice, this list of conditions and the following disclaimer in the
13 1.12 mycroft * documentation and/or other materials provided with the distribution.
14 1.12 mycroft * 3. All advertising materials mentioning features or use of this software
15 1.12 mycroft * must display the following acknowledgement:
16 1.12 mycroft * This product includes software developed by Charles Hannum.
17 1.12 mycroft * 4. The name of the author may not be used to endorse or promote products
18 1.12 mycroft * derived from this software without specific prior written permission.
19 1.12 mycroft *
20 1.12 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.12 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.12 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.12 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.12 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.12 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.12 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.12 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.12 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.12 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.12 mycroft */
31 1.12 mycroft
32 1.12 mycroft /*
33 1.12 mycroft * Originally written by Julian Elischer (julian (at) tfs.com)
34 1.5 deraadt * for TRW Financial Systems for use under the MACH(2.5) operating system.
35 1.1 cgd *
36 1.1 cgd * TRW Financial Systems, in accordance with their agreement with Carnegie
37 1.1 cgd * Mellon University, makes this software available to CMU to distribute
38 1.1 cgd * or use in any manner that they see fit as long as this message is kept with
39 1.1 cgd * the software. For this reason TFS also grants any other persons or
40 1.1 cgd * organisations permission to use or modify this software.
41 1.1 cgd *
42 1.1 cgd * TFS supplies this software to be publicly redistributed
43 1.1 cgd * on the understanding that TFS is not responsible for the correct
44 1.1 cgd * functioning of this software in any circumstances.
45 1.7 cgd *
46 1.12 mycroft * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
47 1.1 cgd */
48 1.1 cgd
49 1.10 mycroft #include <sys/types.h>
50 1.10 mycroft #include <sys/param.h>
51 1.10 mycroft #include <sys/systm.h>
52 1.12 mycroft #include <sys/malloc.h>
53 1.12 mycroft #include <sys/device.h>
54 1.10 mycroft
55 1.10 mycroft #include <scsi/scsi_all.h>
56 1.10 mycroft #include <scsi/scsiconf.h>
57 1.1 cgd
58 1.18 mycroft #if 0
59 1.12 mycroft #if NCALS > 0
60 1.18 mycroft { T_PROCESSOR, T_FIXED, 1,
61 1.18 mycroft 0, 0, 0 },
62 1.12 mycroft #endif /* NCALS */
63 1.1 cgd #if NBLL > 0
64 1.18 mycroft { T_PROCESSOR, T_FIXED, 1,
65 1.12 mycroft "AEG ", "READER ", "V1.0" },
66 1.12 mycroft #endif /* NBLL */
67 1.1 cgd #if NKIL > 0
68 1.18 mycroft { T_SCANNER, T_FIXED, 0,
69 1.18 mycroft "KODAK ", "IL Scanner 900 ", 0 },
70 1.12 mycroft #endif /* NKIL */
71 1.18 mycroft #endif
72 1.12 mycroft
73 1.12 mycroft /*
74 1.12 mycroft * Declarations
75 1.12 mycroft */
76 1.18 mycroft void scsi_probedev __P((struct scsibus_softc *, int, int));
77 1.18 mycroft int scsi_probe_bus __P((int bus, int target, int lun));
78 1.12 mycroft
79 1.12 mycroft struct scsi_device probe_switch = {
80 1.12 mycroft NULL,
81 1.12 mycroft NULL,
82 1.12 mycroft NULL,
83 1.12 mycroft NULL,
84 1.12 mycroft };
85 1.12 mycroft
86 1.16 mycroft int scsibusmatch __P((struct device *, void *, void *));
87 1.12 mycroft void scsibusattach __P((struct device *, struct device *, void *));
88 1.12 mycroft
89 1.12 mycroft struct cfdriver scsibuscd = {
90 1.12 mycroft NULL, "scsibus", scsibusmatch, scsibusattach, DV_DULL,
91 1.18 mycroft sizeof(struct scsibus_softc)
92 1.12 mycroft };
93 1.12 mycroft
94 1.12 mycroft int
95 1.17 mycroft scsibusmatch(parent, match, aux)
96 1.12 mycroft struct device *parent;
97 1.17 mycroft void *match, *aux;
98 1.12 mycroft {
99 1.12 mycroft
100 1.12 mycroft return 1;
101 1.12 mycroft }
102 1.12 mycroft
103 1.12 mycroft /*
104 1.12 mycroft * The routine called by the adapter boards to get all their
105 1.12 mycroft * devices configured in.
106 1.12 mycroft */
107 1.12 mycroft void
108 1.12 mycroft scsibusattach(parent, self, aux)
109 1.12 mycroft struct device *parent, *self;
110 1.12 mycroft void *aux;
111 1.12 mycroft {
112 1.18 mycroft struct scsibus_softc *sb = (struct scsibus_softc *)self;
113 1.12 mycroft struct scsi_link *sc_link_proto = aux;
114 1.12 mycroft
115 1.12 mycroft sc_link_proto->scsibus = sb->sc_dev.dv_unit;
116 1.12 mycroft sb->adapter_link = sc_link_proto;
117 1.12 mycroft printf("\n");
118 1.12 mycroft
119 1.12 mycroft #if defined(SCSI_DELAY) && SCSI_DELAY > 2
120 1.12 mycroft printf("%s: waiting for scsi devices to settle\n",
121 1.12 mycroft sb->sc_dev.dv_xname);
122 1.12 mycroft #else /* SCSI_DELAY > 2 */
123 1.12 mycroft #undef SCSI_DELAY
124 1.12 mycroft #define SCSI_DELAY 2
125 1.12 mycroft #endif /* SCSI_DELAY */
126 1.12 mycroft delay(1000000 * SCSI_DELAY);
127 1.12 mycroft
128 1.12 mycroft scsi_probe_bus(sb->sc_dev.dv_unit, -1, -1);
129 1.12 mycroft }
130 1.12 mycroft
131 1.18 mycroft int
132 1.18 mycroft scsibussubmatch(parent, match, aux)
133 1.18 mycroft struct device *parent;
134 1.18 mycroft void *match, *aux;
135 1.18 mycroft {
136 1.18 mycroft struct cfdata *cf = match;
137 1.18 mycroft struct scsibus_attach_args *sa = aux;
138 1.18 mycroft struct scsi_link *sc_link = sa->sa_sc_link;
139 1.18 mycroft
140 1.18 mycroft if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != sc_link->target)
141 1.18 mycroft return 0;
142 1.18 mycroft if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != sc_link->lun)
143 1.18 mycroft return 0;
144 1.18 mycroft return ((*cf->cf_driver->cd_match)(parent, match, aux));
145 1.18 mycroft }
146 1.18 mycroft
147 1.12 mycroft /*
148 1.12 mycroft * Probe the requested scsi bus. It must be already set up.
149 1.12 mycroft * -1 requests all set up scsi busses.
150 1.18 mycroft * target and lun optionally narrow the search if not -1
151 1.12 mycroft */
152 1.12 mycroft int
153 1.18 mycroft scsi_probe_busses(bus, target, lun)
154 1.18 mycroft int bus, target, lun;
155 1.12 mycroft {
156 1.12 mycroft
157 1.12 mycroft if (bus == -1) {
158 1.12 mycroft for (bus = 0; bus < scsibuscd.cd_ndevs; bus++)
159 1.12 mycroft if (scsibuscd.cd_devs[bus])
160 1.18 mycroft scsi_probe_bus(bus, target, lun);
161 1.12 mycroft return 0;
162 1.12 mycroft } else {
163 1.18 mycroft return scsi_probe_bus(bus, target, lun);
164 1.12 mycroft }
165 1.12 mycroft }
166 1.12 mycroft
167 1.12 mycroft /*
168 1.12 mycroft * Probe the requested scsi bus. It must be already set up.
169 1.18 mycroft * target and lun optionally narrow the search if not -1
170 1.12 mycroft */
171 1.12 mycroft int
172 1.18 mycroft scsi_probe_bus(bus, target, lun)
173 1.18 mycroft int bus, target, lun;
174 1.12 mycroft {
175 1.18 mycroft struct scsibus_softc *scsi;
176 1.18 mycroft int maxtarget, mintarget, maxlun, minlun;
177 1.18 mycroft u_int8_t scsi_addr;
178 1.12 mycroft
179 1.12 mycroft if (bus < 0 || bus >= scsibuscd.cd_ndevs)
180 1.12 mycroft return ENXIO;
181 1.12 mycroft scsi = scsibuscd.cd_devs[bus];
182 1.12 mycroft if (!scsi)
183 1.12 mycroft return ENXIO;
184 1.12 mycroft
185 1.18 mycroft scsi_addr = scsi->adapter_link->adapter_target;
186 1.12 mycroft
187 1.18 mycroft if (target == -1) {
188 1.18 mycroft maxtarget = 7;
189 1.18 mycroft mintarget = 0;
190 1.12 mycroft } else {
191 1.18 mycroft if (target < 0 || target > 7)
192 1.12 mycroft return EINVAL;
193 1.18 mycroft maxtarget = mintarget = target;
194 1.12 mycroft }
195 1.1 cgd
196 1.12 mycroft if (lun == -1) {
197 1.12 mycroft maxlun = 7;
198 1.12 mycroft minlun = 0;
199 1.12 mycroft } else {
200 1.12 mycroft if (lun < 0 || lun > 7)
201 1.12 mycroft return EINVAL;
202 1.12 mycroft maxlun = minlun = lun;
203 1.12 mycroft }
204 1.12 mycroft
205 1.18 mycroft for (target = mintarget; target <= maxtarget; target++) {
206 1.18 mycroft if (target == scsi_addr)
207 1.12 mycroft continue;
208 1.12 mycroft for (lun = minlun; lun <= maxlun; lun++) {
209 1.12 mycroft /*
210 1.18 mycroft * See if there's a device present, and configure it.
211 1.12 mycroft */
212 1.18 mycroft scsi_probedev(scsi, target, lun);
213 1.18 mycroft if ((scsi->moreluns & (1 << target)) == 0)
214 1.18 mycroft break;
215 1.12 mycroft /* otherwise something says we should look further */
216 1.12 mycroft }
217 1.8 deraadt }
218 1.12 mycroft return 0;
219 1.12 mycroft }
220 1.12 mycroft
221 1.18 mycroft void
222 1.18 mycroft scsi_strvis(dst, src, len)
223 1.18 mycroft u_char *dst, *src;
224 1.18 mycroft int len;
225 1.12 mycroft {
226 1.12 mycroft
227 1.18 mycroft /* Trim leading and trailing blanks. */
228 1.18 mycroft while (len > 0 && src[0] == ' ')
229 1.18 mycroft ++src, --len;
230 1.18 mycroft while (len > 0 && src[len-1] == ' ')
231 1.18 mycroft --len;
232 1.18 mycroft
233 1.18 mycroft while (len > 0) {
234 1.18 mycroft if (*src < 0x20 || *src >= 0x80) {
235 1.18 mycroft /* non-printable characters */
236 1.18 mycroft *dst++ = '\\';
237 1.18 mycroft *dst++ = (*src & 0300) >> 6;
238 1.18 mycroft *dst++ = (*src & 0070) >> 3;
239 1.18 mycroft *dst++ = (*src & 0007) >> 0;
240 1.18 mycroft } else if (*src == '\\') {
241 1.18 mycroft /* quote characters */
242 1.18 mycroft *dst++ = '\\';
243 1.18 mycroft *dst++ = '\\';
244 1.18 mycroft } else {
245 1.18 mycroft /* normal characters */
246 1.18 mycroft *dst++ = *src;
247 1.18 mycroft }
248 1.18 mycroft ++src, --len;
249 1.18 mycroft }
250 1.2 deraadt
251 1.18 mycroft *dst++ = 0;
252 1.12 mycroft }
253 1.1 cgd
254 1.18 mycroft struct scsi_quirk_inquiry_pattern {
255 1.18 mycroft struct scsi_inquiry_pattern pattern;
256 1.18 mycroft u_int8_t quirks;
257 1.18 mycroft };
258 1.18 mycroft
259 1.18 mycroft struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
260 1.18 mycroft {T_CDROM, T_REMOV,
261 1.18 mycroft "CHINON ", "CD-ROM CDS-431 ", "H42", SDEV_NOLUNS},
262 1.18 mycroft {T_CDROM, T_REMOV,
263 1.18 mycroft "CHINON ", "CD-ROM CDS-535 ", "Q14", SDEV_NOLUNS},
264 1.18 mycroft {T_CDROM, T_REMOV,
265 1.18 mycroft "DENON ", "DRD-25X ", "V", SDEV_NOLUNS},
266 1.18 mycroft {T_CDROM, T_REMOV,
267 1.18 mycroft "IMS ", "CDD521/10 ", "2.06", SDEV_NOLUNS},
268 1.18 mycroft {T_CDROM, T_REMOV,
269 1.18 mycroft "NEC ", "CD-ROM DRIVE:841", "1.0 ", SDEV_NOLUNS},
270 1.18 mycroft {T_CDROM, T_REMOV,
271 1.18 mycroft "SONY ", "CD-ROM CDU-541 ", "4.3d", SDEV_NOLUNS},
272 1.18 mycroft {T_CDROM, T_REMOV,
273 1.18 mycroft "SONY ", "CD-ROM CDU-55S ", "1.0i", SDEV_NOLUNS},
274 1.18 mycroft {T_CDROM, T_REMOV,
275 1.18 mycroft "TEAC ", "CD-ROM ", "1.06", SDEV_NOLUNS},
276 1.18 mycroft {T_CDROM, T_REMOV,
277 1.18 mycroft "TEXEL ", "CD-ROM ", "1.06", SDEV_NOLUNS},
278 1.18 mycroft {T_CDROM, T_REMOV,
279 1.18 mycroft "MEDIAVIS", "CDR-H93MV ", "1.31", SDEV_NOLUNS},
280 1.18 mycroft
281 1.18 mycroft {T_DIRECT, T_FIXED,
282 1.18 mycroft "MAXTOR ", "XT-3280 ", "PR02", SDEV_NOLUNS},
283 1.18 mycroft {T_DIRECT, T_FIXED,
284 1.18 mycroft "MAXTOR ", "XT-4380S ", "B3C", SDEV_NOLUNS},
285 1.18 mycroft {T_DIRECT, T_FIXED,
286 1.18 mycroft "MAXTOR ", "MXT-1240S ", "I1.2", SDEV_NOLUNS},
287 1.18 mycroft {T_DIRECT, T_FIXED,
288 1.18 mycroft "MAXTOR ", "XT-4170S ", "B5A", SDEV_NOLUNS},
289 1.18 mycroft {T_DIRECT, T_FIXED,
290 1.18 mycroft "MAXTOR ", "XT-8760S ", "B7B", SDEV_NOLUNS},
291 1.18 mycroft {T_DIRECT, T_FIXED,
292 1.18 mycroft "RODIME ", "RO3000S ", "2.33", SDEV_NOLUNS},
293 1.18 mycroft {T_DIRECT, T_FIXED,
294 1.18 mycroft "SEAGATE ", "ST157N ", "\004|j", SDEV_NOLUNS},
295 1.18 mycroft {T_DIRECT, T_FIXED,
296 1.18 mycroft "SEAGATE ", "ST296 ", "921", SDEV_NOLUNS},
297 1.18 mycroft {T_DIRECT, T_FIXED,
298 1.18 mycroft "QUANTUM ", "LPS525S ", "3110", SDEV_NOLUNS},
299 1.18 mycroft {T_DIRECT, T_FIXED,
300 1.18 mycroft "QUANTUM ", "PD1225S ", "3110", SDEV_NOLUNS},
301 1.18 mycroft
302 1.18 mycroft {T_SEQUENTIAL, T_REMOV,
303 1.18 mycroft "TANDBERG", " TDC 3600 ", "U07", SDEV_NOLUNS},
304 1.18 mycroft {T_SEQUENTIAL, T_REMOV,
305 1.18 mycroft "WangDAT ", "Model 1300 ", "02.4", SDEV_NOSYNCWIDE},
306 1.18 mycroft {T_SEQUENTIAL, T_REMOV,
307 1.18 mycroft "WangDAT ", "Model 2600 ", "01.7", SDEV_NOSYNCWIDE},
308 1.18 mycroft {T_SEQUENTIAL, T_REMOV,
309 1.18 mycroft "WangDAT ", "Model 3200 ", "02.2", SDEV_NOSYNCWIDE},
310 1.18 mycroft };
311 1.18 mycroft
312 1.12 mycroft /*
313 1.12 mycroft * given a target and lu, ask the device what
314 1.12 mycroft * it is, and find the correct driver table
315 1.12 mycroft * entry.
316 1.12 mycroft */
317 1.18 mycroft void
318 1.18 mycroft scsi_probedev(scsi, target, lun)
319 1.18 mycroft struct scsibus_softc *scsi;
320 1.18 mycroft int target, lun;
321 1.18 mycroft {
322 1.12 mycroft struct scsi_link *sc_link;
323 1.2 deraadt static struct scsi_inquiry_data inqbuf;
324 1.18 mycroft struct scsi_quirk_inquiry_pattern *finger;
325 1.18 mycroft int priority;
326 1.18 mycroft u_int8_t type;
327 1.18 mycroft boolean removable;
328 1.18 mycroft char *dtype, *qtype;
329 1.18 mycroft char vendor[33], product[65], revision[17];
330 1.18 mycroft struct scsibus_attach_args sa;
331 1.18 mycroft struct cfdata *cf;
332 1.18 mycroft
333 1.18 mycroft /* Skip this slot if it is already attached. */
334 1.18 mycroft if (scsi->sc_link[target][lun])
335 1.18 mycroft return;
336 1.18 mycroft
337 1.18 mycroft sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT);
338 1.18 mycroft *sc_link = *scsi->adapter_link;
339 1.18 mycroft sc_link->target = target;
340 1.18 mycroft sc_link->lun = lun;
341 1.18 mycroft sc_link->device = &probe_switch;
342 1.12 mycroft
343 1.12 mycroft /*
344 1.12 mycroft * Ask the device what it is
345 1.12 mycroft */
346 1.12 mycroft #ifdef SCSIDEBUG
347 1.18 mycroft if (target == DEBUGTARGET && lun == DEBUGLUN)
348 1.12 mycroft sc_link->flags |= DEBUGLEVEL;
349 1.12 mycroft else
350 1.12 mycroft sc_link->flags &= ~(SDEV_DB1 | SDEV_DB2 | SDEV_DB3 | SDEV_DB4);
351 1.12 mycroft #endif /* SCSIDEBUG */
352 1.2 deraadt
353 1.18 mycroft (void) scsi_test_unit_ready(sc_link,
354 1.18 mycroft SCSI_AUTOCONF | SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_NOT_READY | SCSI_IGNORE_MEDIA_CHANGE);
355 1.18 mycroft
356 1.12 mycroft #ifdef SCSI_2_DEF
357 1.12 mycroft /* some devices need to be told to go to SCSI2 */
358 1.12 mycroft /* However some just explode if you tell them this.. leave it out */
359 1.18 mycroft scsi_change_def(sc_link, SCSI_AUTOCONF | SCSI_SILENT);
360 1.18 mycroft #endif /* SCSI_2_DEF */
361 1.18 mycroft
362 1.18 mycroft /* Now go ask the device all about itself. */
363 1.18 mycroft bzero(&inqbuf, sizeof(inqbuf));
364 1.18 mycroft if (scsi_inquire(sc_link, &inqbuf, SCSI_AUTOCONF) != 0)
365 1.18 mycroft goto bad;
366 1.18 mycroft
367 1.18 mycroft {
368 1.18 mycroft int len = inqbuf.additional_length;
369 1.18 mycroft u_int8_t *p = inqbuf.unused + len;
370 1.18 mycroft while (p < (u_int8_t *)(&inqbuf + 1))
371 1.18 mycroft *p++ = 0;
372 1.18 mycroft }
373 1.18 mycroft
374 1.18 mycroft finger = (struct scsi_quirk_inquiry_pattern *)scsi_inqmatch(&inqbuf,
375 1.18 mycroft (caddr_t)scsi_quirk_patterns,
376 1.18 mycroft sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
377 1.18 mycroft sizeof(scsi_quirk_patterns[0]), &priority);
378 1.18 mycroft if (priority != 0)
379 1.18 mycroft sc_link->quirks |= finger->quirks;
380 1.18 mycroft if ((inqbuf.version & SID_ANSII) == 0)
381 1.18 mycroft sc_link->quirks |= SDEV_NOLUNS;
382 1.12 mycroft
383 1.18 mycroft if ((sc_link->quirks & SDEV_NOLUNS) == 0)
384 1.18 mycroft scsi->moreluns |= (1 << target);
385 1.12 mycroft
386 1.12 mycroft /*
387 1.12 mycroft * note what BASIC type of device it is
388 1.12 mycroft */
389 1.12 mycroft type = inqbuf.device & SID_TYPE;
390 1.18 mycroft removable = inqbuf.dev_qual2 & SID_REMOVABLE ? 1 : 0;
391 1.18 mycroft
392 1.18 mycroft if (removable)
393 1.18 mycroft sc_link->flags |= SDEV_REMOVABLE;
394 1.12 mycroft
395 1.12 mycroft /*
396 1.12 mycroft * Any device qualifier that has the top bit set (qualifier&4 != 0)
397 1.12 mycroft * is vendor specific and won't match in this switch.
398 1.12 mycroft */
399 1.18 mycroft dtype = 0;
400 1.18 mycroft switch (inqbuf.device & SID_QUAL) {
401 1.12 mycroft case SID_QUAL_LU_OK:
402 1.2 deraadt qtype = "";
403 1.2 deraadt break;
404 1.12 mycroft
405 1.12 mycroft case SID_QUAL_LU_OFFLINE:
406 1.18 mycroft qtype = " offline";
407 1.2 deraadt break;
408 1.12 mycroft
409 1.12 mycroft case SID_QUAL_RSVD:
410 1.12 mycroft case SID_QUAL_BAD_LU:
411 1.18 mycroft goto bad;
412 1.12 mycroft
413 1.2 deraadt default:
414 1.2 deraadt qtype = "";
415 1.18 mycroft dtype = "vendor-unique";
416 1.2 deraadt break;
417 1.2 deraadt }
418 1.12 mycroft if (dtype == 0) {
419 1.12 mycroft switch (type) {
420 1.2 deraadt case T_DIRECT:
421 1.2 deraadt dtype = "direct";
422 1.2 deraadt break;
423 1.2 deraadt case T_SEQUENTIAL:
424 1.12 mycroft dtype = "sequential";
425 1.2 deraadt break;
426 1.2 deraadt case T_PRINTER:
427 1.12 mycroft dtype = "printer";
428 1.2 deraadt break;
429 1.2 deraadt case T_PROCESSOR:
430 1.12 mycroft dtype = "processor";
431 1.2 deraadt break;
432 1.18 mycroft case T_CDROM:
433 1.18 mycroft dtype = "cdrom";
434 1.2 deraadt break;
435 1.2 deraadt case T_WORM:
436 1.2 deraadt dtype = "worm";
437 1.2 deraadt break;
438 1.2 deraadt case T_SCANNER:
439 1.12 mycroft dtype = "scanner";
440 1.2 deraadt break;
441 1.2 deraadt case T_OPTICAL:
442 1.12 mycroft dtype = "optical";
443 1.2 deraadt break;
444 1.2 deraadt case T_CHANGER:
445 1.2 deraadt dtype = "changer";
446 1.2 deraadt break;
447 1.2 deraadt case T_COMM:
448 1.12 mycroft dtype = "communication";
449 1.2 deraadt break;
450 1.12 mycroft case T_NODEVICE:
451 1.18 mycroft goto bad;
452 1.2 deraadt default:
453 1.18 mycroft dtype = "unknown";
454 1.2 deraadt break;
455 1.1 cgd }
456 1.1 cgd }
457 1.2 deraadt
458 1.18 mycroft scsi_strvis(vendor, inqbuf.vendor, 8);
459 1.18 mycroft scsi_strvis(product, inqbuf.product, 16);
460 1.18 mycroft scsi_strvis(revision, inqbuf.revision, 4);
461 1.18 mycroft
462 1.18 mycroft printf("%s targ %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s\n",
463 1.18 mycroft ((struct device *)sc_link->adapter_softc)->dv_xname,
464 1.18 mycroft target, lun, vendor, product, revision,
465 1.18 mycroft inqbuf.version & SID_ANSII, type, dtype,
466 1.18 mycroft removable ? "removable" : "fixed", qtype);
467 1.18 mycroft
468 1.18 mycroft sa.sa_sc_link = sc_link;
469 1.18 mycroft sa.sa_inqbuf = &inqbuf;
470 1.18 mycroft
471 1.18 mycroft if ((cf = config_search(scsibussubmatch, (struct device *)scsi, &sa)) != 0) {
472 1.18 mycroft config_attach((struct device *)scsi, cf, &sa, NULL);
473 1.18 mycroft scsi->sc_link[target][lun] = sc_link;
474 1.12 mycroft } else
475 1.18 mycroft goto bad;
476 1.18 mycroft
477 1.18 mycroft return;
478 1.12 mycroft
479 1.18 mycroft bad:
480 1.18 mycroft free(sc_link, M_DEVBUF);
481 1.18 mycroft return;
482 1.1 cgd }
483 1.1 cgd
484 1.2 deraadt /*
485 1.18 mycroft * Return a priority based on how much of the inquiry data matches
486 1.18 mycroft * the patterns for the particular driver.
487 1.2 deraadt */
488 1.18 mycroft caddr_t
489 1.18 mycroft scsi_inqmatch(inqbuf, base, nmatches, matchsize, bestpriority)
490 1.18 mycroft struct scsi_inquiry_data *inqbuf;
491 1.18 mycroft caddr_t base;
492 1.18 mycroft int nmatches, matchsize;
493 1.18 mycroft int *bestpriority;
494 1.2 deraadt {
495 1.18 mycroft u_int8_t type;
496 1.18 mycroft boolean removable;
497 1.18 mycroft caddr_t bestmatch;
498 1.18 mycroft
499 1.18 mycroft /* Include the qualifier to catch vendor-unique types. */
500 1.18 mycroft type = inqbuf->device;
501 1.18 mycroft removable = inqbuf->dev_qual2 & SID_REMOVABLE ? T_REMOV : T_FIXED;
502 1.18 mycroft
503 1.18 mycroft for (*bestpriority = 0, bestmatch = 0; nmatches--; base += matchsize) {
504 1.18 mycroft struct scsi_inquiry_pattern *match = (void *)base;
505 1.18 mycroft int priority, len;
506 1.18 mycroft
507 1.18 mycroft if (type != match->type)
508 1.1 cgd continue;
509 1.18 mycroft if (removable != match->removable)
510 1.1 cgd continue;
511 1.18 mycroft priority = 2;
512 1.18 mycroft len = strlen(match->vendor);
513 1.18 mycroft if (bcmp(inqbuf->vendor, match->vendor, len))
514 1.1 cgd continue;
515 1.18 mycroft priority += len;
516 1.18 mycroft len = strlen(match->product);
517 1.18 mycroft if (bcmp(inqbuf->product, match->product, len))
518 1.1 cgd continue;
519 1.18 mycroft priority += len;
520 1.18 mycroft len = strlen(match->revision);
521 1.18 mycroft if (bcmp(inqbuf->revision, match->revision, len))
522 1.1 cgd continue;
523 1.18 mycroft priority += len;
524 1.18 mycroft
525 1.18 mycroft #if 0
526 1.18 mycroft printf("scsi_inqmatch: %d/%d/%d <%s, %s, %s>\n",
527 1.18 mycroft priority, match->type, match->removable,
528 1.18 mycroft match->vendor, match->product, match->revision);
529 1.18 mycroft #endif
530 1.18 mycroft if (priority > *bestpriority) {
531 1.18 mycroft *bestpriority = priority;
532 1.18 mycroft bestmatch = base;
533 1.1 cgd }
534 1.1 cgd }
535 1.18 mycroft
536 1.18 mycroft return (bestmatch);
537 1.1 cgd }
538