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