scsiconf.c revision 1.16 1 1.16 mycroft /* $NetBSD: scsiconf.c,v 1.16 1994/11/03 22:05:08 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.1 cgd #include "st.h"
59 1.1 cgd #include "sd.h"
60 1.1 cgd #include "ch.h"
61 1.1 cgd #include "cd.h"
62 1.12 mycroft #include "uk.h"
63 1.12 mycroft #include "su.h"
64 1.12 mycroft
65 1.12 mycroft #ifdef TFS
66 1.12 mycroft #include "bll.h"
67 1.12 mycroft #include "cals.h"
68 1.12 mycroft #include "kil.h"
69 1.12 mycroft #include "scan.h"
70 1.12 mycroft #else /* TFS */
71 1.1 cgd #define NBLL 0
72 1.1 cgd #define NCALS 0
73 1.1 cgd #define NKIL 0
74 1.12 mycroft #define NSCAN 0
75 1.12 mycroft #endif /* TFS */
76 1.12 mycroft
77 1.12 mycroft /*
78 1.12 mycroft * The structure of known drivers for autoconfiguration
79 1.12 mycroft */
80 1.12 mycroft struct scsidevs {
81 1.13 mycroft char *devname;
82 1.12 mycroft u_int32 type;
83 1.12 mycroft boolean removable;
84 1.13 mycroft int flags; /* 1 show my comparisons during boot(debug) */
85 1.12 mycroft #define SC_SHOWME 0x01
86 1.12 mycroft #define SC_ONE_LU 0x00
87 1.12 mycroft #define SC_MORE_LUS 0x02
88 1.13 mycroft char *manufacturer;
89 1.13 mycroft char *model;
90 1.13 mycroft char *version;
91 1.13 mycroft };
92 1.12 mycroft
93 1.12 mycroft #if NUK > 0
94 1.12 mycroft static struct scsidevs unknowndev = {
95 1.12 mycroft "uk", -1, 0, SC_MORE_LUS,
96 1.12 mycroft "standard", "any", "any"
97 1.12 mycroft };
98 1.12 mycroft #endif /*NUK*/
99 1.12 mycroft
100 1.12 mycroft static struct scsidevs knowndevs[] = {
101 1.1 cgd #if NSD > 0
102 1.12 mycroft { "sd", T_DIRECT, T_FIXED, SC_ONE_LU,
103 1.12 mycroft "standard", "any", "any" },
104 1.12 mycroft { "sd", T_DIRECT, T_FIXED, SC_ONE_LU,
105 1.12 mycroft "MAXTOR ", "XT-4170S ", "B5A " },
106 1.12 mycroft #endif /* NSD */
107 1.1 cgd #if NST > 0
108 1.12 mycroft { "st", T_SEQUENTIAL, T_REMOV, SC_ONE_LU,
109 1.12 mycroft "standard", "any", "any" },
110 1.12 mycroft #endif /* NST */
111 1.12 mycroft #if NCALS > 0
112 1.12 mycroft { "cals", T_PROCESSOR, T_FIXED, SC_MORE_LUS,
113 1.12 mycroft "standard", "any", "any" },
114 1.12 mycroft #endif /* NCALS */
115 1.1 cgd #if NCH > 0
116 1.12 mycroft { "ch", T_CHANGER, T_REMOV, SC_ONE_LU,
117 1.12 mycroft "standard", "any", "any" },
118 1.12 mycroft #endif /* NCH */
119 1.1 cgd #if NCD > 0
120 1.12 mycroft #ifndef UKTEST /* make cdroms unrecognised to test the uk driver */
121 1.12 mycroft { "cd", T_READONLY, T_REMOV, SC_ONE_LU,
122 1.12 mycroft "SONY ", "CD-ROM CDU-8012 ", "3.1a" },
123 1.12 mycroft { "cd", T_READONLY, T_REMOV, SC_MORE_LUS,
124 1.12 mycroft "PIONEER ", "CD-ROM DRM-600 ", "any" },
125 1.12 mycroft #endif
126 1.12 mycroft #endif /* NCD */
127 1.1 cgd #if NBLL > 0
128 1.12 mycroft { "bll", T_PROCESSOR, T_FIXED, SC_MORE_LUS,
129 1.12 mycroft "AEG ", "READER ", "V1.0" },
130 1.12 mycroft #endif /* NBLL */
131 1.1 cgd #if NKIL > 0
132 1.12 mycroft { "kil", T_SCANNER, T_FIXED, SC_ONE_LU,
133 1.12 mycroft "KODAK ", "IL Scanner 900 ", "any" },
134 1.12 mycroft #endif /* NKIL */
135 1.12 mycroft { 0 }
136 1.12 mycroft };
137 1.12 mycroft
138 1.12 mycroft /*
139 1.12 mycroft * Declarations
140 1.12 mycroft */
141 1.12 mycroft struct scsidevs *scsi_probedev();
142 1.12 mycroft struct scsidevs *selectdev();
143 1.12 mycroft int scsi_probe_bus __P((int bus, int targ, int lun));
144 1.12 mycroft
145 1.12 mycroft struct scsi_device probe_switch = {
146 1.12 mycroft NULL,
147 1.12 mycroft NULL,
148 1.12 mycroft NULL,
149 1.12 mycroft NULL,
150 1.12 mycroft "probe",
151 1.12 mycroft 0,
152 1.12 mycroft };
153 1.12 mycroft
154 1.16 mycroft int scsibusmatch __P((struct device *, void *, void *));
155 1.12 mycroft void scsibusattach __P((struct device *, struct device *, void *));
156 1.12 mycroft
157 1.12 mycroft struct cfdriver scsibuscd = {
158 1.12 mycroft NULL, "scsibus", scsibusmatch, scsibusattach, DV_DULL,
159 1.12 mycroft sizeof(struct scsibus_data)
160 1.12 mycroft };
161 1.12 mycroft
162 1.12 mycroft int
163 1.12 mycroft scsibusmatch(parent, cf, aux)
164 1.12 mycroft struct device *parent;
165 1.16 mycroft void *match;
166 1.12 mycroft void *aux;
167 1.12 mycroft {
168 1.12 mycroft
169 1.12 mycroft return 1;
170 1.12 mycroft }
171 1.12 mycroft
172 1.12 mycroft /*
173 1.12 mycroft * The routine called by the adapter boards to get all their
174 1.12 mycroft * devices configured in.
175 1.12 mycroft */
176 1.12 mycroft void
177 1.12 mycroft scsibusattach(parent, self, aux)
178 1.12 mycroft struct device *parent, *self;
179 1.12 mycroft void *aux;
180 1.12 mycroft {
181 1.12 mycroft struct scsibus_data *sb = (struct scsibus_data *)self;
182 1.12 mycroft struct scsi_link *sc_link_proto = aux;
183 1.12 mycroft
184 1.12 mycroft sc_link_proto->scsibus = sb->sc_dev.dv_unit;
185 1.12 mycroft sb->adapter_link = sc_link_proto;
186 1.12 mycroft printf("\n");
187 1.12 mycroft
188 1.12 mycroft #if defined(SCSI_DELAY) && SCSI_DELAY > 2
189 1.12 mycroft printf("%s: waiting for scsi devices to settle\n",
190 1.12 mycroft sb->sc_dev.dv_xname);
191 1.12 mycroft #else /* SCSI_DELAY > 2 */
192 1.12 mycroft #undef SCSI_DELAY
193 1.12 mycroft #define SCSI_DELAY 2
194 1.12 mycroft #endif /* SCSI_DELAY */
195 1.12 mycroft delay(1000000 * SCSI_DELAY);
196 1.12 mycroft
197 1.12 mycroft scsi_probe_bus(sb->sc_dev.dv_unit, -1, -1);
198 1.12 mycroft }
199 1.12 mycroft
200 1.12 mycroft /*
201 1.12 mycroft * Probe the requested scsi bus. It must be already set up.
202 1.12 mycroft * -1 requests all set up scsi busses.
203 1.12 mycroft * targ and lun optionally narrow the search if not -1
204 1.12 mycroft */
205 1.12 mycroft int
206 1.12 mycroft scsi_probe_busses(bus, targ, lun)
207 1.12 mycroft int bus, targ, lun;
208 1.12 mycroft {
209 1.12 mycroft
210 1.12 mycroft if (bus == -1) {
211 1.12 mycroft for (bus = 0; bus < scsibuscd.cd_ndevs; bus++)
212 1.12 mycroft if (scsibuscd.cd_devs[bus])
213 1.12 mycroft scsi_probe_bus(bus, targ, lun);
214 1.12 mycroft return 0;
215 1.12 mycroft } else {
216 1.12 mycroft return scsi_probe_bus(bus, targ, lun);
217 1.12 mycroft }
218 1.12 mycroft }
219 1.12 mycroft
220 1.12 mycroft /*
221 1.12 mycroft * Probe the requested scsi bus. It must be already set up.
222 1.12 mycroft * targ and lun optionally narrow the search if not -1
223 1.12 mycroft */
224 1.12 mycroft int
225 1.12 mycroft scsi_probe_bus(bus, targ, lun)
226 1.12 mycroft int bus, targ, lun;
227 1.12 mycroft {
228 1.12 mycroft struct scsibus_data *scsi;
229 1.12 mycroft int maxtarg, mintarg, maxlun, minlun;
230 1.12 mycroft struct scsi_link *sc_link_proto;
231 1.12 mycroft u_int8 scsi_addr ;
232 1.12 mycroft struct scsidevs *bestmatch = NULL;
233 1.12 mycroft struct scsi_link *sc_link = NULL;
234 1.12 mycroft boolean maybe_more;
235 1.12 mycroft
236 1.12 mycroft if (bus < 0 || bus >= scsibuscd.cd_ndevs)
237 1.12 mycroft return ENXIO;
238 1.12 mycroft scsi = scsibuscd.cd_devs[bus];
239 1.12 mycroft if (!scsi)
240 1.12 mycroft return ENXIO;
241 1.12 mycroft
242 1.12 mycroft sc_link_proto = scsi->adapter_link;
243 1.12 mycroft scsi_addr = sc_link_proto->adapter_targ;
244 1.12 mycroft
245 1.12 mycroft if (targ == -1) {
246 1.12 mycroft maxtarg = 7;
247 1.12 mycroft mintarg = 0;
248 1.12 mycroft } else {
249 1.12 mycroft if (targ < 0 || targ > 7)
250 1.12 mycroft return EINVAL;
251 1.12 mycroft maxtarg = mintarg = targ;
252 1.12 mycroft }
253 1.1 cgd
254 1.12 mycroft if (lun == -1) {
255 1.12 mycroft maxlun = 7;
256 1.12 mycroft minlun = 0;
257 1.12 mycroft } else {
258 1.12 mycroft if (lun < 0 || lun > 7)
259 1.12 mycroft return EINVAL;
260 1.12 mycroft maxlun = minlun = lun;
261 1.12 mycroft }
262 1.12 mycroft
263 1.12 mycroft for (targ = mintarg; targ <= maxtarg; targ++) {
264 1.12 mycroft maybe_more = 0; /* by default only check 1 lun */
265 1.12 mycroft #if 0 /* XXXX */
266 1.12 mycroft if (targ == scsi_addr)
267 1.12 mycroft continue;
268 1.12 mycroft #endif
269 1.12 mycroft for (lun = minlun; lun <= maxlun; lun++) {
270 1.12 mycroft /*
271 1.12 mycroft * The spot appears to already have something
272 1.12 mycroft * linked in, skip past it. Must be doing a 'reprobe'
273 1.12 mycroft */
274 1.12 mycroft if (scsi->sc_link[targ][lun]) {
275 1.12 mycroft /* don't do this one, but check other luns */
276 1.12 mycroft maybe_more = 1;
277 1.12 mycroft continue;
278 1.12 mycroft }
279 1.12 mycroft /*
280 1.12 mycroft * If we presently don't have a link block
281 1.12 mycroft * then allocate one to use while probing
282 1.12 mycroft */
283 1.12 mycroft if (!sc_link) {
284 1.12 mycroft sc_link = malloc(sizeof(*sc_link), M_TEMP, M_NOWAIT);
285 1.12 mycroft *sc_link = *sc_link_proto; /* struct copy */
286 1.12 mycroft sc_link->opennings = 1;
287 1.12 mycroft sc_link->device = &probe_switch;
288 1.12 mycroft }
289 1.12 mycroft sc_link->target = targ;
290 1.12 mycroft sc_link->lun = lun;
291 1.12 mycroft bestmatch = scsi_probedev(sc_link, &maybe_more);
292 1.12 mycroft /*
293 1.12 mycroft * We already know what the device is. We use a
294 1.12 mycroft * special matching routine which insists that the
295 1.12 mycroft * cfdata is of the right type rather than putting
296 1.12 mycroft * more intelligence in individual match routines for
297 1.12 mycroft * each high-level driver. We must have
298 1.12 mycroft * scsi_targmatch() do all of the comparisons, or we
299 1.12 mycroft * could get stuck in an infinite loop trying the same
300 1.12 mycroft * device repeatedly. We use the `fordriver' field of
301 1.12 mycroft * the scsi_link for now, rather than inventing a new
302 1.12 mycroft * structure just for the config_search().
303 1.12 mycroft */
304 1.12 mycroft if (bestmatch) {
305 1.12 mycroft sc_link->fordriver = bestmatch->devname;
306 1.12 mycroft if (config_found((struct device *)scsi,
307 1.12 mycroft sc_link, NULL)) {
308 1.12 mycroft scsi->sc_link[targ][lun] = sc_link;
309 1.12 mycroft sc_link = NULL; /* it's been used */
310 1.12 mycroft } else
311 1.12 mycroft printf("No matching config entry.\n");
312 1.12 mycroft }
313 1.12 mycroft if (!maybe_more)/* nothing suggests we'll find more */
314 1.12 mycroft break; /* nothing here, skip to next targ */
315 1.12 mycroft /* otherwise something says we should look further */
316 1.12 mycroft }
317 1.8 deraadt }
318 1.12 mycroft if (sc_link)
319 1.12 mycroft free(sc_link, M_TEMP);
320 1.12 mycroft return 0;
321 1.12 mycroft }
322 1.12 mycroft
323 1.12 mycroft int
324 1.16 mycroft scsi_targmatch(parent, match, aux)
325 1.12 mycroft struct device *parent;
326 1.16 mycroft void *match;
327 1.12 mycroft void *aux;
328 1.12 mycroft {
329 1.16 mycroft struct cfdata *cf = match;
330 1.12 mycroft struct scsi_link *sc_link = aux;
331 1.12 mycroft char *devname = sc_link->fordriver;
332 1.12 mycroft
333 1.15 mycroft if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != sc_link->target)
334 1.12 mycroft return 0;
335 1.15 mycroft if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != sc_link->lun)
336 1.12 mycroft return 0;
337 1.12 mycroft if (strcmp(cf->cf_driver->cd_name, devname))
338 1.12 mycroft return 0;
339 1.2 deraadt
340 1.12 mycroft return 1;
341 1.12 mycroft }
342 1.1 cgd
343 1.12 mycroft /*
344 1.12 mycroft * given a target and lu, ask the device what
345 1.12 mycroft * it is, and find the correct driver table
346 1.12 mycroft * entry.
347 1.12 mycroft */
348 1.2 deraadt struct scsidevs *
349 1.12 mycroft scsi_probedev(sc_link, maybe_more)
350 1.12 mycroft boolean *maybe_more;
351 1.12 mycroft struct scsi_link *sc_link;
352 1.1 cgd {
353 1.12 mycroft u_int8 target = sc_link->target;
354 1.12 mycroft u_int8 lun = sc_link->lun;
355 1.12 mycroft struct scsi_adapter *scsi_adapter = sc_link->adapter;
356 1.12 mycroft struct scsidevs *bestmatch = NULL;
357 1.12 mycroft char *dtype = NULL, *desc;
358 1.12 mycroft char *qtype;
359 1.2 deraadt static struct scsi_inquiry_data inqbuf;
360 1.12 mycroft u_int32 len, qualifier, type;
361 1.12 mycroft boolean remov;
362 1.12 mycroft char manu[32];
363 1.12 mycroft char model[32];
364 1.12 mycroft char version[32];
365 1.12 mycroft
366 1.12 mycroft bzero(&inqbuf, sizeof(inqbuf));
367 1.12 mycroft /*
368 1.12 mycroft * Ask the device what it is
369 1.12 mycroft */
370 1.12 mycroft #ifdef SCSIDEBUG
371 1.12 mycroft if (target == DEBUGTARG && lun == DEBUGLUN)
372 1.12 mycroft sc_link->flags |= DEBUGLEVEL;
373 1.12 mycroft else
374 1.12 mycroft sc_link->flags &= ~(SDEV_DB1 | SDEV_DB2 | SDEV_DB3 | SDEV_DB4);
375 1.12 mycroft #endif /* SCSIDEBUG */
376 1.12 mycroft /* catch unit attn */
377 1.12 mycroft scsi_test_unit_ready(sc_link, SCSI_NOSLEEP | SCSI_NOMASK | SCSI_SILENT);
378 1.12 mycroft #ifdef DOUBTFULL
379 1.12 mycroft switch (scsi_test_unit_ready(sc_link, SCSI_NOSLEEP | SCSI_NOMASK | SCSI_SILENT)) {
380 1.12 mycroft case 0: /* said it WAS ready */
381 1.12 mycroft case EBUSY: /* replied 'NOT READY' but WAS present, continue */
382 1.12 mycroft case ENXIO:
383 1.12 mycroft break;
384 1.12 mycroft case EIO: /* device timed out */
385 1.12 mycroft case EINVAL: /* Lun not supported */
386 1.12 mycroft default:
387 1.12 mycroft return NULL;
388 1.2 deraadt
389 1.12 mycroft }
390 1.12 mycroft #endif /*DOUBTFULL*/
391 1.12 mycroft #ifdef SCSI_2_DEF
392 1.12 mycroft /* some devices need to be told to go to SCSI2 */
393 1.12 mycroft /* However some just explode if you tell them this.. leave it out */
394 1.12 mycroft scsi_change_def(sc_link, SCSI_NOSLEEP | SCSI_NOMASK | SCSI_SILENT);
395 1.12 mycroft #endif /*SCSI_2_DEF */
396 1.12 mycroft
397 1.12 mycroft /* Now go ask the device all about itself */
398 1.12 mycroft if (scsi_inquire(sc_link, &inqbuf, SCSI_NOSLEEP | SCSI_NOMASK) != 0)
399 1.12 mycroft return NULL;
400 1.12 mycroft
401 1.12 mycroft /*
402 1.12 mycroft * note what BASIC type of device it is
403 1.12 mycroft */
404 1.12 mycroft type = inqbuf.device & SID_TYPE;
405 1.12 mycroft qualifier = inqbuf.device & SID_QUAL;
406 1.12 mycroft remov = inqbuf.dev_qual2 & SID_REMOVABLE;
407 1.12 mycroft
408 1.12 mycroft /*
409 1.12 mycroft * Any device qualifier that has the top bit set (qualifier&4 != 0)
410 1.12 mycroft * is vendor specific and won't match in this switch.
411 1.12 mycroft */
412 1.12 mycroft switch (qualifier) {
413 1.12 mycroft case SID_QUAL_LU_OK:
414 1.2 deraadt qtype = "";
415 1.2 deraadt break;
416 1.12 mycroft
417 1.12 mycroft case SID_QUAL_LU_OFFLINE:
418 1.12 mycroft qtype = ", Unit not Connected!";
419 1.2 deraadt break;
420 1.12 mycroft
421 1.12 mycroft case SID_QUAL_RSVD:
422 1.12 mycroft qtype = ", Reserved Peripheral Qualifier!";
423 1.12 mycroft *maybe_more = 1;
424 1.12 mycroft return NULL;
425 1.2 deraadt break;
426 1.12 mycroft
427 1.12 mycroft case SID_QUAL_BAD_LU:
428 1.12 mycroft /*
429 1.12 mycroft * Check for a non-existent unit. If the device is returning
430 1.12 mycroft * this much, then we must set the flag that has
431 1.12 mycroft * the searchers keep looking on other luns.
432 1.12 mycroft */
433 1.2 deraadt qtype = ", The Target can't support this Unit!";
434 1.12 mycroft *maybe_more = 1;
435 1.12 mycroft return NULL;
436 1.12 mycroft
437 1.2 deraadt default:
438 1.2 deraadt dtype = "vendor specific";
439 1.2 deraadt qtype = "";
440 1.12 mycroft *maybe_more = 1;
441 1.2 deraadt break;
442 1.2 deraadt }
443 1.12 mycroft if (dtype == 0) {
444 1.12 mycroft switch (type) {
445 1.2 deraadt case T_DIRECT:
446 1.2 deraadt dtype = "direct";
447 1.2 deraadt break;
448 1.2 deraadt case T_SEQUENTIAL:
449 1.12 mycroft dtype = "sequential";
450 1.2 deraadt break;
451 1.2 deraadt case T_PRINTER:
452 1.12 mycroft dtype = "printer";
453 1.2 deraadt break;
454 1.2 deraadt case T_PROCESSOR:
455 1.12 mycroft dtype = "processor";
456 1.2 deraadt break;
457 1.2 deraadt case T_READONLY:
458 1.12 mycroft dtype = "readonly";
459 1.2 deraadt break;
460 1.2 deraadt case T_WORM:
461 1.2 deraadt dtype = "worm";
462 1.2 deraadt break;
463 1.2 deraadt case T_SCANNER:
464 1.12 mycroft dtype = "scanner";
465 1.2 deraadt break;
466 1.2 deraadt case T_OPTICAL:
467 1.12 mycroft dtype = "optical";
468 1.2 deraadt break;
469 1.2 deraadt case T_CHANGER:
470 1.2 deraadt dtype = "changer";
471 1.2 deraadt break;
472 1.2 deraadt case T_COMM:
473 1.12 mycroft dtype = "communication";
474 1.2 deraadt break;
475 1.12 mycroft case T_NODEVICE:
476 1.12 mycroft *maybe_more = 1;
477 1.12 mycroft return NULL;
478 1.2 deraadt default:
479 1.12 mycroft dtype = NULL;
480 1.2 deraadt break;
481 1.1 cgd }
482 1.1 cgd }
483 1.2 deraadt
484 1.12 mycroft /*
485 1.12 mycroft * Then if it's advanced enough, more detailed
486 1.12 mycroft * information
487 1.12 mycroft */
488 1.12 mycroft if ((inqbuf.version & SID_ANSII) > 0) {
489 1.12 mycroft if ((len = inqbuf.additional_length
490 1.12 mycroft + ((char *) inqbuf.unused
491 1.12 mycroft - (char *) &inqbuf))
492 1.12 mycroft > (sizeof(struct scsi_inquiry_data) - 1))
493 1.12 mycroft len = sizeof(struct scsi_inquiry_data) - 1;
494 1.2 deraadt desc = inqbuf.vendor;
495 1.12 mycroft desc[len - (desc - (char *) &inqbuf)] = 0;
496 1.12 mycroft strncpy(manu, inqbuf.vendor, 8);
497 1.12 mycroft manu[8] = 0;
498 1.12 mycroft strncpy(model, inqbuf.product, 16);
499 1.12 mycroft model[16] = 0;
500 1.12 mycroft strncpy(version, inqbuf.revision, 4);
501 1.12 mycroft version[4] = 0;
502 1.12 mycroft } else
503 1.12 mycroft /*
504 1.12 mycroft * If not advanced enough, use default values
505 1.12 mycroft */
506 1.12 mycroft {
507 1.2 deraadt desc = "early protocol device";
508 1.12 mycroft strncpy(manu, "unknown", 8);
509 1.12 mycroft strncpy(model, "unknown", 16);
510 1.12 mycroft strncpy(version, "????", 4);
511 1.2 deraadt }
512 1.12 mycroft printf("%s targ %d lun %d: <%s%s%s> SCSI%d ",
513 1.12 mycroft ((struct device *)sc_link->adapter_softc)->dv_xname,
514 1.12 mycroft target, lun, manu, model, version,
515 1.12 mycroft inqbuf.version & SID_ANSII);
516 1.12 mycroft if (dtype)
517 1.12 mycroft printf("%s", dtype);
518 1.9 deraadt else
519 1.12 mycroft printf("type %d", type);
520 1.12 mycroft printf(" %s\n", remov ? "removable" : "fixed");
521 1.12 mycroft if (qtype[0])
522 1.12 mycroft printf("%s targ %d lun %d: qualifier %d(%s)\n",
523 1.12 mycroft ((struct device *)sc_link->adapter_softc)->dv_xname,
524 1.12 mycroft target, lun, qualifier, qtype);
525 1.12 mycroft
526 1.12 mycroft /*
527 1.12 mycroft * Try make as good a match as possible with
528 1.12 mycroft * available sub drivers
529 1.12 mycroft */
530 1.12 mycroft bestmatch = selectdev(qualifier, type, remov ? T_REMOV : T_FIXED,
531 1.12 mycroft manu, model, version);
532 1.12 mycroft if (bestmatch && bestmatch->flags & SC_MORE_LUS)
533 1.12 mycroft *maybe_more = 1;
534 1.12 mycroft return bestmatch;
535 1.1 cgd }
536 1.1 cgd
537 1.2 deraadt /*
538 1.2 deraadt * Try make as good a match as possible with
539 1.12 mycroft * available sub drivers
540 1.2 deraadt */
541 1.2 deraadt struct scsidevs *
542 1.12 mycroft selectdev(qualifier, type, remov, manu, model, rev)
543 1.12 mycroft u_int32 qualifier, type;
544 1.12 mycroft boolean remov;
545 1.12 mycroft char *manu, *model, *rev;
546 1.2 deraadt {
547 1.12 mycroft u_int32 numents = (sizeof(knowndevs) / sizeof(struct scsidevs)) - 1;
548 1.12 mycroft u_int32 count = 0;
549 1.12 mycroft u_int32 bestmatches = 0;
550 1.12 mycroft struct scsidevs *bestmatch = (struct scsidevs *) 0;
551 1.12 mycroft struct scsidevs *thisentry = knowndevs;
552 1.12 mycroft
553 1.12 mycroft type |= qualifier; /* why? */
554 1.12 mycroft
555 1.12 mycroft thisentry--;
556 1.12 mycroft while (count++ < numents) {
557 1.12 mycroft thisentry++;
558 1.12 mycroft if (type != thisentry->type)
559 1.1 cgd continue;
560 1.12 mycroft if (bestmatches < 1) {
561 1.12 mycroft bestmatches = 1;
562 1.12 mycroft bestmatch = thisentry;
563 1.1 cgd }
564 1.12 mycroft if (remov != thisentry->removable)
565 1.1 cgd continue;
566 1.12 mycroft if (bestmatches < 2) {
567 1.12 mycroft bestmatches = 2;
568 1.12 mycroft bestmatch = thisentry;
569 1.12 mycroft }
570 1.12 mycroft if (thisentry->flags & SC_SHOWME)
571 1.12 mycroft printf("\n%s-\n%s-", thisentry->manufacturer, manu);
572 1.12 mycroft if (strcmp(thisentry->manufacturer, manu))
573 1.1 cgd continue;
574 1.12 mycroft if (bestmatches < 3) {
575 1.12 mycroft bestmatches = 3;
576 1.12 mycroft bestmatch = thisentry;
577 1.12 mycroft }
578 1.12 mycroft if (thisentry->flags & SC_SHOWME)
579 1.12 mycroft printf("\n%s-\n%s-", thisentry->model, model);
580 1.12 mycroft if (strcmp(thisentry->model, model))
581 1.1 cgd continue;
582 1.12 mycroft if (bestmatches < 4) {
583 1.12 mycroft bestmatches = 4;
584 1.12 mycroft bestmatch = thisentry;
585 1.12 mycroft }
586 1.12 mycroft if (thisentry->flags & SC_SHOWME)
587 1.12 mycroft printf("\n%s-\n%s-", thisentry->version, rev);
588 1.12 mycroft if (strcmp(thisentry->version, rev))
589 1.1 cgd continue;
590 1.12 mycroft if (bestmatches < 5) {
591 1.12 mycroft bestmatches = 5;
592 1.12 mycroft bestmatch = thisentry;
593 1.1 cgd break;
594 1.1 cgd }
595 1.1 cgd }
596 1.12 mycroft #if NUK > 0
597 1.12 mycroft if (!bestmatch)
598 1.12 mycroft bestmatch = &unknowndev;
599 1.12 mycroft #endif
600 1.12 mycroft if (!bestmatch)
601 1.12 mycroft printf("No matching driver.\n");
602 1.12 mycroft return bestmatch;
603 1.1 cgd }
604