scsiconf.c revision 1.9.3.3 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.3 mycroft * $Id: scsiconf.c,v 1.9.3.3 1993/11/24 19:19: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.3 mycroft if (!bestmatch)
318 1.9.3.3 mycroft continue;
319 1.9.3.3 mycroft if (!scsi_attachdev(scsi, sc_link,
320 1.9.3.3 mycroft bestmatch->attach_rtn))
321 1.9.3.3 mycroft continue;
322 1.9.3.3 mycroft scsi->sc_link[targ][lun] = sc_link;
323 1.9.3.3 mycroft sc_link = NULL; /* it's been used */
324 1.9.3.2 mycroft if (!(maybe_more)) /* nothing suggests we'll find more */
325 1.9.3.1 mycroft break; /* nothing here, skip to next targ */
326 1.9.3.1 mycroft /* otherwise something says we should look further */
327 1.9.3.1 mycroft }
328 1.9.3.1 mycroft }
329 1.9.3.2 mycroft if (sc_link)
330 1.9.3.1 mycroft free(sc_link, M_TEMP);
331 1.9.3.1 mycroft return 0;
332 1.9.3.1 mycroft }
333 1.9.3.1 mycroft
334 1.9.3.3 mycroft int
335 1.9.3.3 mycroft scsi_targmatch(parent, cf, aux)
336 1.9.3.3 mycroft struct device *parent;
337 1.9.3.3 mycroft struct cfdata *cf;
338 1.9.3.3 mycroft void *aux;
339 1.9.3.3 mycroft {
340 1.9.3.3 mycroft struct scsi_link *sc_link = aux;
341 1.9.3.3 mycroft void (*attach_rtn) () = sc_link->fordriver;
342 1.9.3.3 mycroft
343 1.9.3.3 mycroft if (cf->cf_driver->cd_attach != attach_rtn)
344 1.9.3.3 mycroft return 0;
345 1.9.3.3 mycroft if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != sc_link->target)
346 1.9.3.3 mycroft return 0;
347 1.9.3.3 mycroft if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != sc_link->lun)
348 1.9.3.3 mycroft return 0;
349 1.9.3.3 mycroft
350 1.9.3.3 mycroft return 1;
351 1.9.3.3 mycroft }
352 1.9.3.3 mycroft
353 1.9.3.3 mycroft int
354 1.9.3.3 mycroft scsi_attachdev(scsi, sc_link, attach_rtn)
355 1.9.3.3 mycroft struct scsibus_data *scsi;
356 1.9.3.3 mycroft struct scsi_link *sc_link;
357 1.9.3.3 mycroft void (*attach_rtn) ();
358 1.9.3.3 mycroft {
359 1.9.3.3 mycroft /*
360 1.9.3.3 mycroft * We already know what the device is. We use a special matching
361 1.9.3.3 mycroft * routine which insists that the cfdata is of the right type rather
362 1.9.3.3 mycroft * than putting more intelligence in individual match routines for
363 1.9.3.3 mycroft * each high-level driver. We must have scsi_targmatch() do all of
364 1.9.3.3 mycroft * the comparisons, or we could get stuck in an infinite loop trying
365 1.9.3.3 mycroft * the same device over and over. We use the `fordriver' field of
366 1.9.3.3 mycroft * the scsi_link for now, rather than inventing a new structure just
367 1.9.3.3 mycroft * for the config_search().
368 1.9.3.3 mycroft */
369 1.9.3.3 mycroft sc_link->fordriver = attach_rtn;
370 1.9.3.3 mycroft if (config_found((struct device *)scsi, sc_link, NULL))
371 1.9.3.3 mycroft return 1;
372 1.9.3.3 mycroft
373 1.9.3.3 mycroft printf("No matching config file entry.\n");
374 1.9.3.3 mycroft return 0;
375 1.9.3.3 mycroft }
376 1.9.3.3 mycroft
377 1.9.3.1 mycroft /*
378 1.9.3.1 mycroft * given a target and lu, ask the device what
379 1.9.3.1 mycroft * it is, and find the correct driver table
380 1.9.3.1 mycroft * entry.
381 1.9.3.1 mycroft */
382 1.2 deraadt struct scsidevs *
383 1.9.3.1 mycroft scsi_probedev(sc_link, maybe_more)
384 1.9.3.1 mycroft boolean *maybe_more;
385 1.9.3.1 mycroft struct scsi_link *sc_link;
386 1.1 cgd {
387 1.9.3.1 mycroft u_int8 target = sc_link->target;
388 1.9.3.1 mycroft u_int8 lun = sc_link->lun;
389 1.9.3.1 mycroft struct scsi_adapter *scsi_adapter = sc_link->adapter;
390 1.9.3.1 mycroft struct scsidevs *bestmatch = NULL;
391 1.9.3.1 mycroft char *dtype = NULL, *desc;
392 1.9.3.1 mycroft char *qtype;
393 1.2 deraadt static struct scsi_inquiry_data inqbuf;
394 1.9.3.1 mycroft u_int32 len, qualifier, type;
395 1.9.3.1 mycroft boolean remov;
396 1.9.3.1 mycroft char manu[32];
397 1.9.3.1 mycroft char model[32];
398 1.9.3.1 mycroft char version[32];
399 1.9.3.1 mycroft
400 1.9.3.1 mycroft bzero(&inqbuf, sizeof(inqbuf));
401 1.9.3.1 mycroft /*
402 1.9.3.1 mycroft * Ask the device what it is
403 1.9.3.1 mycroft */
404 1.9.3.1 mycroft #ifdef SCSIDEBUG
405 1.9.3.1 mycroft if (target == DEBUGTARG && lu == DEBUGLUN)
406 1.9.3.1 mycroft sc_link->flags |= DEBUGLEVEL;
407 1.9.3.1 mycroft else
408 1.9.3.1 mycroft sc_link->flags &= ~(SDEV_DB1 | SDEV_DB2 | SDEV_DB3 | SDEV_DB4);
409 1.9.3.1 mycroft #endif /* SCSIDEBUG */
410 1.9.3.1 mycroft /* catch unit attn */
411 1.9.3.1 mycroft scsi_test_unit_ready(sc_link, SCSI_NOSLEEP | SCSI_NOMASK | SCSI_SILENT);
412 1.9.3.1 mycroft #ifdef DOUBTFULL
413 1.9.3.1 mycroft switch (scsi_test_unit_ready(sc_link, SCSI_NOSLEEP | SCSI_NOMASK | SCSI_SILENT)) {
414 1.9.3.1 mycroft case 0: /* said it WAS ready */
415 1.9.3.1 mycroft case EBUSY: /* replied 'NOT READY' but WAS present, continue */
416 1.9.3.1 mycroft case ENXIO:
417 1.9.3.1 mycroft break;
418 1.9.3.1 mycroft case EIO: /* device timed out */
419 1.9.3.1 mycroft case EINVAL: /* Lun not supported */
420 1.9.3.1 mycroft default:
421 1.9.3.1 mycroft return NULL;
422 1.2 deraadt
423 1.9.3.1 mycroft }
424 1.9.3.1 mycroft #endif /*DOUBTFULL*/
425 1.9.3.1 mycroft #ifdef SCSI_2_DEF
426 1.9.3.1 mycroft /* some devices need to be told to go to SCSI2 */
427 1.9.3.1 mycroft /* However some just explode if you tell them this.. leave it out */
428 1.9.3.1 mycroft scsi_change_def(sc_link, SCSI_NOSLEEP | SCSI_NOMASK | SCSI_SILENT);
429 1.9.3.1 mycroft #endif /*SCSI_2_DEF */
430 1.9.3.1 mycroft
431 1.9.3.1 mycroft /* Now go ask the device all about itself */
432 1.9.3.1 mycroft if (scsi_inquire(sc_link, &inqbuf, SCSI_NOSLEEP | SCSI_NOMASK) != 0)
433 1.9.3.1 mycroft return NULL;
434 1.9.3.1 mycroft
435 1.9.3.1 mycroft /*
436 1.9.3.1 mycroft * note what BASIC type of device it is
437 1.9.3.1 mycroft */
438 1.9.3.1 mycroft type = inqbuf.device & SID_TYPE;
439 1.9.3.1 mycroft qualifier = inqbuf.device & SID_QUAL;
440 1.9.3.1 mycroft remov = inqbuf.dev_qual2 & SID_REMOVABLE;
441 1.9.3.1 mycroft
442 1.9.3.1 mycroft /*
443 1.9.3.1 mycroft * Any device qualifier that has the top bit set (qualifier&4 != 0)
444 1.9.3.1 mycroft * is vendor specific and won't match in this switch.
445 1.9.3.1 mycroft */
446 1.9.3.1 mycroft switch (qualifier) {
447 1.9.3.1 mycroft case SID_QUAL_LU_OK:
448 1.2 deraadt qtype = "";
449 1.2 deraadt break;
450 1.9.3.1 mycroft
451 1.9.3.1 mycroft case SID_QUAL_LU_OFFLINE:
452 1.9.3.1 mycroft qtype = ", Unit not Connected!";
453 1.2 deraadt break;
454 1.9.3.1 mycroft
455 1.9.3.1 mycroft case SID_QUAL_RSVD:
456 1.9.3.1 mycroft qtype = ", Reserved Peripheral Qualifier!";
457 1.9.3.1 mycroft *maybe_more = 1;
458 1.9.3.1 mycroft return NULL;
459 1.2 deraadt break;
460 1.9.3.1 mycroft
461 1.9.3.1 mycroft case SID_QUAL_BAD_LU:
462 1.9.3.1 mycroft /*
463 1.9.3.1 mycroft * Check for a non-existent unit. If the device is returning
464 1.9.3.1 mycroft * this much, then we must set the flag that has
465 1.9.3.1 mycroft * the searchers keep looking on other luns.
466 1.9.3.1 mycroft */
467 1.2 deraadt qtype = ", The Target can't support this Unit!";
468 1.9.3.1 mycroft *maybe_more = 1;
469 1.9.3.1 mycroft return NULL;
470 1.9.3.1 mycroft
471 1.2 deraadt default:
472 1.2 deraadt dtype = "vendor specific";
473 1.2 deraadt qtype = "";
474 1.9.3.1 mycroft *maybe_more = 1;
475 1.2 deraadt break;
476 1.2 deraadt }
477 1.9.3.1 mycroft if (dtype == 0) {
478 1.9.3.1 mycroft switch (type) {
479 1.2 deraadt case T_DIRECT:
480 1.2 deraadt dtype = "direct";
481 1.2 deraadt break;
482 1.2 deraadt case T_SEQUENTIAL:
483 1.9.3.1 mycroft dtype = "sequential";
484 1.2 deraadt break;
485 1.2 deraadt case T_PRINTER:
486 1.9.3.1 mycroft dtype = "printer";
487 1.2 deraadt break;
488 1.2 deraadt case T_PROCESSOR:
489 1.9.3.1 mycroft dtype = "processor";
490 1.2 deraadt break;
491 1.2 deraadt case T_READONLY:
492 1.9.3.1 mycroft dtype = "readonly";
493 1.2 deraadt break;
494 1.2 deraadt case T_WORM:
495 1.2 deraadt dtype = "worm";
496 1.2 deraadt break;
497 1.2 deraadt case T_SCANNER:
498 1.9.3.1 mycroft dtype = "scanner";
499 1.2 deraadt break;
500 1.2 deraadt case T_OPTICAL:
501 1.9.3.1 mycroft dtype = "optical";
502 1.2 deraadt break;
503 1.2 deraadt case T_CHANGER:
504 1.2 deraadt dtype = "changer";
505 1.2 deraadt break;
506 1.2 deraadt case T_COMM:
507 1.9.3.1 mycroft dtype = "communication";
508 1.2 deraadt break;
509 1.9.3.1 mycroft case T_NODEVICE:
510 1.9.3.1 mycroft *maybe_more = 1;
511 1.9.3.1 mycroft return NULL;
512 1.2 deraadt default:
513 1.9.3.1 mycroft dtype = NULL;
514 1.2 deraadt break;
515 1.1 cgd }
516 1.1 cgd }
517 1.2 deraadt
518 1.9.3.1 mycroft /*
519 1.9.3.1 mycroft * Then if it's advanced enough, more detailed
520 1.9.3.1 mycroft * information
521 1.9.3.1 mycroft */
522 1.9.3.1 mycroft if ((inqbuf.version & SID_ANSII) > 0) {
523 1.9.3.1 mycroft if ((len = inqbuf.additional_length
524 1.9.3.1 mycroft + ((char *) inqbuf.unused
525 1.9.3.1 mycroft - (char *) &inqbuf))
526 1.9.3.1 mycroft > (sizeof(struct scsi_inquiry_data) - 1))
527 1.9.3.1 mycroft len = sizeof(struct scsi_inquiry_data) - 1;
528 1.2 deraadt desc = inqbuf.vendor;
529 1.9.3.1 mycroft desc[len - (desc - (char *) &inqbuf)] = 0;
530 1.9.3.1 mycroft strncpy(manu, inqbuf.vendor, 8);
531 1.9.3.1 mycroft manu[8] = 0;
532 1.9.3.1 mycroft strncpy(model, inqbuf.product, 16);
533 1.9.3.1 mycroft model[16] = 0;
534 1.9.3.1 mycroft strncpy(version, inqbuf.revision, 4);
535 1.9.3.1 mycroft version[4] = 0;
536 1.9.3.1 mycroft } else
537 1.9.3.1 mycroft /*
538 1.9.3.1 mycroft * If not advanced enough, use default values
539 1.9.3.1 mycroft */
540 1.9.3.1 mycroft {
541 1.2 deraadt desc = "early protocol device";
542 1.9.3.1 mycroft strncpy(manu, "unknown", 8);
543 1.9.3.1 mycroft strncpy(model, "unknown", 16);
544 1.9.3.1 mycroft strncpy(version, "????", 4);
545 1.1 cgd }
546 1.9.3.1 mycroft printf("%s targ %d lun %d: <%s%s%s> SCSI%d ",
547 1.9.3.1 mycroft ((struct device *)sc_link->adapter_softc)->dv_xname,
548 1.9.3.1 mycroft target, lun, manu, model, version,
549 1.9.3.1 mycroft inqbuf.version & SID_ANSII);
550 1.9.3.1 mycroft if (dtype)
551 1.9.3.1 mycroft printf("%s", dtype);
552 1.9 deraadt else
553 1.9.3.1 mycroft printf("type %d", type);
554 1.9.3.1 mycroft printf(" %s\n", remov ? "removable" : "fixed");
555 1.9.3.1 mycroft if (qtype[0])
556 1.9.3.1 mycroft printf("%s targ %d lun %d: qualifier %d(%s)\n",
557 1.9.3.1 mycroft ((struct device *)sc_link->adapter_softc)->dv_xname,
558 1.9.3.1 mycroft target, lun, qualifier, qtype);
559 1.9.3.1 mycroft
560 1.9.3.1 mycroft /*
561 1.9.3.1 mycroft * Try make as good a match as possible with
562 1.9.3.1 mycroft * available sub drivers
563 1.9.3.1 mycroft */
564 1.9.3.1 mycroft bestmatch = selectdev(qualifier, type, remov ? T_REMOV : T_FIXED,
565 1.9.3.1 mycroft manu, model, version);
566 1.9.3.1 mycroft if (bestmatch && bestmatch->flags & SC_MORE_LUS)
567 1.9.3.1 mycroft *maybe_more = 1;
568 1.9.3.1 mycroft return bestmatch;
569 1.1 cgd }
570 1.9.3.3 mycroft
571 1.2 deraadt /*
572 1.2 deraadt * Try make as good a match as possible with
573 1.9.3.1 mycroft * available sub drivers
574 1.2 deraadt */
575 1.2 deraadt struct scsidevs *
576 1.9.3.1 mycroft selectdev(qualifier, type, remov, manu, model, rev)
577 1.9.3.1 mycroft u_int32 qualifier, type;
578 1.9.3.1 mycroft boolean remov;
579 1.9.3.1 mycroft char *manu, *model, *rev;
580 1.2 deraadt {
581 1.9.3.1 mycroft u_int32 numents = (sizeof(knowndevs) / sizeof(struct scsidevs)) - 1;
582 1.9.3.1 mycroft u_int32 count = 0;
583 1.9.3.1 mycroft u_int32 bestmatches = 0;
584 1.9.3.1 mycroft struct scsidevs *bestmatch = (struct scsidevs *) 0;
585 1.9.3.1 mycroft struct scsidevs *thisentry = knowndevs;
586 1.9.3.1 mycroft
587 1.9.3.1 mycroft type |= qualifier; /* why? */
588 1.9.3.1 mycroft
589 1.9.3.1 mycroft thisentry--;
590 1.9.3.1 mycroft while (count++ < numents) {
591 1.9.3.1 mycroft thisentry++;
592 1.9.3.1 mycroft if (type != thisentry->type)
593 1.2 deraadt continue;
594 1.9.3.1 mycroft if (bestmatches < 1) {
595 1.9.3.1 mycroft bestmatches = 1;
596 1.9.3.1 mycroft bestmatch = thisentry;
597 1.1 cgd }
598 1.9.3.1 mycroft if (remov != thisentry->removable)
599 1.1 cgd continue;
600 1.9.3.1 mycroft if (bestmatches < 2) {
601 1.9.3.1 mycroft bestmatches = 2;
602 1.9.3.1 mycroft bestmatch = thisentry;
603 1.9.3.1 mycroft }
604 1.9.3.1 mycroft if (thisentry->flags & SC_SHOWME)
605 1.9.3.1 mycroft printf("\n%s-\n%s-", thisentry->manufacturer, manu);
606 1.9.3.1 mycroft if (strcmp(thisentry->manufacturer, manu))
607 1.1 cgd continue;
608 1.9.3.1 mycroft if (bestmatches < 3) {
609 1.9.3.1 mycroft bestmatches = 3;
610 1.9.3.1 mycroft bestmatch = thisentry;
611 1.9.3.1 mycroft }
612 1.9.3.1 mycroft if (thisentry->flags & SC_SHOWME)
613 1.9.3.1 mycroft printf("\n%s-\n%s-", thisentry->model, model);
614 1.9.3.1 mycroft if (strcmp(thisentry->model, model))
615 1.1 cgd continue;
616 1.9.3.1 mycroft if (bestmatches < 4) {
617 1.9.3.1 mycroft bestmatches = 4;
618 1.9.3.1 mycroft bestmatch = thisentry;
619 1.9.3.1 mycroft }
620 1.9.3.1 mycroft if (thisentry->flags & SC_SHOWME)
621 1.9.3.1 mycroft printf("\n%s-\n%s-", thisentry->version, rev);
622 1.9.3.1 mycroft if (strcmp(thisentry->version, rev))
623 1.1 cgd continue;
624 1.9.3.1 mycroft if (bestmatches < 5) {
625 1.9.3.1 mycroft bestmatches = 5;
626 1.9.3.1 mycroft bestmatch = thisentry;
627 1.1 cgd break;
628 1.1 cgd }
629 1.1 cgd }
630 1.9.3.1 mycroft if (!bestmatch) {
631 1.9.3.1 mycroft #if NUK > 0
632 1.9.3.1 mycroft bestmatch = &unknowndev;
633 1.9.3.1 mycroft #else
634 1.9.3.1 mycroft printf("No explicit device driver match.\n");
635 1.9.3.1 mycroft #endif
636 1.1 cgd }
637 1.9.3.1 mycroft return bestmatch;
638 1.1 cgd }
639