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