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