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