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