scsiconf.c revision 1.125 1 /* $NetBSD: scsiconf.c,v 1.125 1999/09/09 20:06:52 hwr Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace
9 * Simulation Facility, NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * Originally written by Julian Elischer (julian (at) tfs.com)
42 * for TRW Financial Systems for use under the MACH(2.5) operating system.
43 *
44 * TRW Financial Systems, in accordance with their agreement with Carnegie
45 * Mellon University, makes this software available to CMU to distribute
46 * or use in any manner that they see fit as long as this message is kept with
47 * the software. For this reason TFS also grants any other persons or
48 * organisations permission to use or modify this software.
49 *
50 * TFS supplies this software to be publicly redistributed
51 * on the understanding that TFS is not responsible for the correct
52 * functioning of this software in any circumstances.
53 *
54 * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
55 */
56
57 #include <sys/types.h>
58 #include <sys/param.h>
59 #include <sys/systm.h>
60 #include <sys/malloc.h>
61 #include <sys/device.h>
62 #include <sys/conf.h>
63 #include <sys/fcntl.h>
64 #include <sys/scsiio.h>
65
66 #include <dev/scsipi/scsi_all.h>
67 #include <dev/scsipi/scsipi_all.h>
68 #include <dev/scsipi/scsiconf.h>
69
70 #include "locators.h"
71
72 #if 0
73 #if NCALS > 0
74 { T_PROCESSOR, T_FIXED, 1,
75 0, 0, 0 },
76 #endif /* NCALS */
77 #if NBLL > 0
78 { T_PROCESSOR, T_FIXED, 1,
79 "AEG ", "READER ", "V1.0" },
80 #endif /* NBLL */
81 #if NKIL > 0
82 { T_SCANNER, T_FIXED, 0,
83 "KODAK ", "IL Scanner 900 ", 0 },
84 #endif /* NKIL */
85 #endif
86
87 /*
88 * Declarations
89 */
90 int scsi_probedev __P((struct scsibus_softc *, int, int));
91 int scsi_probe_bus __P((int bus, int target, int lun));
92
93 struct scsipi_device probe_switch = {
94 NULL,
95 NULL,
96 NULL,
97 NULL,
98 };
99
100 int scsibusmatch __P((struct device *, struct cfdata *, void *));
101 void scsibusattach __P((struct device *, struct device *, void *));
102 int scsibussubmatch __P((struct device *, struct cfdata *, void *));
103
104 struct cfattach scsibus_ca = {
105 sizeof(struct scsibus_softc), scsibusmatch, scsibusattach
106 };
107
108 extern struct cfdriver scsibus_cd;
109
110 int scsibusprint __P((void *, const char *));
111
112 cdev_decl(scsibus);
113
114 int
115 scsiprint(aux, pnp)
116 void *aux;
117 const char *pnp;
118 {
119 struct scsipi_link *l = aux;
120
121 /* only "scsibus"es can attach to "scsi"s; easy. */
122 if (pnp)
123 printf("scsibus at %s", pnp);
124
125 /* don't print channel if the controller says there can be only one. */
126 if (l->scsipi_scsi.channel != SCSI_CHANNEL_ONLY_ONE)
127 printf(" channel %d", l->scsipi_scsi.channel);
128
129 return (UNCONF);
130 }
131
132 int
133 scsibusmatch(parent, cf, aux)
134 struct device *parent;
135 struct cfdata *cf;
136 void *aux;
137 {
138 struct scsipi_link *l = aux;
139 int channel;
140
141 /*
142 * Allow single-channel controllers to specify their channel
143 * in a special way, so that it's not printed.
144 */
145 channel = (l->scsipi_scsi.channel != SCSI_CHANNEL_ONLY_ONE) ?
146 l->scsipi_scsi.channel : 0;
147
148 if (cf->cf_loc[SCSICF_CHANNEL] != channel &&
149 cf->cf_loc[SCSICF_CHANNEL] != SCSICF_CHANNEL_DEFAULT)
150 return (0);
151
152 return (1);
153 }
154
155 /*
156 * The routine called by the adapter boards to get all their
157 * devices configured in.
158 */
159 void
160 scsibusattach(parent, self, aux)
161 struct device *parent, *self;
162 void *aux;
163 {
164 struct scsibus_softc *sb = (struct scsibus_softc *)self;
165 struct scsipi_link *sc_link_proto = aux;
166 size_t nbytes;
167 int i;
168
169 sc_link_proto->scsipi_scsi.scsibus = sb->sc_dev.dv_unit;
170 sc_link_proto->scsipi_cmd = scsi_scsipi_cmd;
171 sc_link_proto->scsipi_interpret_sense = scsipi_interpret_sense;
172 sc_link_proto->sc_print_addr = scsi_print_addr;
173
174 sb->adapter_link = sc_link_proto;
175 sb->sc_maxtarget = sc_link_proto->scsipi_scsi.max_target;
176 sb->sc_maxlun = sc_link_proto->scsipi_scsi.max_lun;
177 printf(": %d targets, %d luns per target\n",
178 sb->sc_maxtarget + 1, sb->sc_maxlun + 1);
179
180 /* Initialize shared data. */
181 scsipi_init();
182
183 nbytes = (sb->sc_maxtarget + 1) * sizeof(struct scsipi_link **);
184 sb->sc_link = (struct scsipi_link ***)malloc(nbytes, M_DEVBUF,
185 M_NOWAIT);
186 if (sb->sc_link == NULL)
187 panic("scsibusattach: can't allocate target links");
188
189 nbytes = (((int) sb->sc_maxlun) + 1) * sizeof(struct scsipi_link *);
190 for (i = 0; i <= sb->sc_maxtarget; i++) {
191 sb->sc_link[i] = (struct scsipi_link **)malloc(nbytes,
192 M_DEVBUF, M_NOWAIT);
193 if (sb->sc_link[i] == NULL)
194 panic("scsibusattach: can't allocate lun links");
195 bzero(sb->sc_link[i], nbytes);
196 }
197
198 #if defined(SCSI_DELAY) && SCSI_DELAY > 2
199 printf("%s: waiting for scsi devices to settle\n",
200 sb->sc_dev.dv_xname);
201 #else /* SCSI_DELAY > 2 */
202 #undef SCSI_DELAY
203 #define SCSI_DELAY 2
204 #endif /* SCSI_DELAY */
205 delay(1000000 * SCSI_DELAY);
206
207 scsi_probe_bus(sb->sc_dev.dv_unit, -1, -1);
208 }
209
210 int
211 scsibussubmatch(parent, cf, aux)
212 struct device *parent;
213 struct cfdata *cf;
214 void *aux;
215 {
216 struct scsipibus_attach_args *sa = aux;
217 struct scsipi_link *sc_link = sa->sa_sc_link;
218
219 if (cf->cf_loc[SCSIBUSCF_TARGET] != SCSIBUSCF_TARGET_DEFAULT &&
220 cf->cf_loc[SCSIBUSCF_TARGET] != sc_link->scsipi_scsi.target)
221 return (0);
222 if (cf->cf_loc[SCSIBUSCF_LUN] != SCSIBUSCF_LUN_DEFAULT &&
223 cf->cf_loc[SCSIBUSCF_LUN] != sc_link->scsipi_scsi.lun)
224 return (0);
225 return ((*cf->cf_attach->ca_match)(parent, cf, aux));
226 }
227
228 /*
229 * Probe the requested scsi bus. It must be already set up.
230 * -1 requests all set up scsi busses.
231 * target and lun optionally narrow the search if not -1
232 */
233 int
234 scsi_probe_busses(bus, target, lun)
235 int bus, target, lun;
236 {
237
238 if (bus == -1) {
239 for (bus = 0; bus < scsibus_cd.cd_ndevs; bus++)
240 if (scsibus_cd.cd_devs[bus])
241 scsi_probe_bus(bus, target, lun);
242 return (0);
243 } else
244 return (scsi_probe_bus(bus, target, lun));
245 }
246
247 /*
248 * Probe the requested scsi bus. It must be already set up.
249 * target and lun optionally narrow the search if not -1
250 */
251 int
252 scsi_probe_bus(bus, target, lun)
253 int bus, target, lun;
254 {
255 struct scsibus_softc *scsi;
256 int maxtarget, mintarget, maxlun, minlun;
257 u_int8_t scsi_addr;
258 int error;
259
260 if (bus < 0 || bus >= scsibus_cd.cd_ndevs)
261 return (ENXIO);
262 scsi = scsibus_cd.cd_devs[bus];
263 if (scsi == NULL)
264 return (ENXIO);
265
266 scsi_addr = scsi->adapter_link->scsipi_scsi.adapter_target;
267
268 if (target == -1) {
269 maxtarget = scsi->sc_maxtarget;
270 mintarget = 0;
271 } else {
272 if (target < 0 || target > scsi->sc_maxtarget)
273 return (EINVAL);
274 maxtarget = mintarget = target;
275 }
276
277 if (lun == -1) {
278 maxlun = scsi->sc_maxlun;
279 minlun = 0;
280 } else {
281 if (lun < 0 || lun > scsi->sc_maxlun)
282 return (EINVAL);
283 maxlun = minlun = lun;
284 }
285
286 if ((error = scsipi_adapter_addref(scsi->adapter_link)) != 0)
287 return (error);
288 for (target = mintarget; target <= maxtarget; target++) {
289 if (target == scsi_addr)
290 continue;
291 for (lun = minlun; lun <= maxlun; lun++) {
292 /*
293 * See if there's a device present, and configure it.
294 */
295 if (scsi_probedev(scsi, target, lun) == 0) {
296 break;
297 }
298 /* otherwise something says we should look further */
299 }
300 }
301 scsipi_adapter_delref(scsi->adapter_link);
302 return (0);
303 }
304
305 /*
306 * Print out autoconfiguration information for a subdevice.
307 *
308 * This is a slight abuse of 'standard' autoconfiguration semantics,
309 * because 'print' functions don't normally print the colon and
310 * device information. However, in this case that's better than
311 * either printing redundant information before the attach message,
312 * or having the device driver call a special function to print out
313 * the standard device information.
314 */
315 int
316 scsibusprint(aux, pnp)
317 void *aux;
318 const char *pnp;
319 {
320 struct scsipibus_attach_args *sa = aux;
321 struct scsipi_inquiry_pattern *inqbuf;
322 u_int8_t type;
323 char *dtype, *qtype;
324 char vendor[33], product[65], revision[17];
325 int target, lun;
326
327 if (pnp != NULL)
328 printf("%s", pnp);
329
330 inqbuf = &sa->sa_inqbuf;
331
332 target = sa->sa_sc_link->scsipi_scsi.target;
333 lun = sa->sa_sc_link->scsipi_scsi.lun;
334
335 type = inqbuf->type & SID_TYPE;
336
337 /*
338 * Figure out basic device type and qualifier.
339 */
340 dtype = 0;
341 switch (inqbuf->type & SID_QUAL) {
342 case SID_QUAL_LU_OK:
343 qtype = "";
344 break;
345
346 case SID_QUAL_LU_OFFLINE:
347 qtype = " offline";
348 break;
349
350 case SID_QUAL_RSVD:
351 case SID_QUAL_BAD_LU:
352 panic("scsibusprint: impossible qualifier");
353
354 default:
355 qtype = "";
356 dtype = "vendor-unique";
357 break;
358 }
359 if (dtype == 0)
360 dtype = scsipi_dtype(type);
361
362 scsipi_strvis(vendor, 33, inqbuf->vendor, 8);
363 scsipi_strvis(product, 65, inqbuf->product, 16);
364 scsipi_strvis(revision, 17, inqbuf->revision, 4);
365
366 printf(" targ %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s",
367 target, lun, vendor, product, revision,
368 sa->scsipi_info.scsi_version & SID_ANSII, type, dtype,
369 inqbuf->removable ? "removable" : "fixed", qtype);
370
371 return (UNCONF);
372 }
373
374 struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
375 {{T_CDROM, T_REMOV,
376 "CHINON ", "CD-ROM CDS-431 ", ""}, SDEV_NOLUNS},
377 {{T_CDROM, T_REMOV,
378 "Chinon ", "CD-ROM CDS-525 ", ""}, SDEV_NOLUNS},
379 {{T_CDROM, T_REMOV,
380 "CHINON ", "CD-ROM CDS-535 ", ""}, SDEV_NOLUNS},
381 {{T_CDROM, T_REMOV,
382 "DEC ", "RRD42 (C) DEC ", ""}, SDEV_NOLUNS},
383 {{T_CDROM, T_REMOV,
384 "DENON ", "DRD-25X ", "V"}, SDEV_NOLUNS},
385 {{T_CDROM, T_REMOV,
386 "HP ", "C4324/C4325 ", ""}, SDEV_NOLUNS},
387 {{T_CDROM, T_REMOV,
388 "IMS ", "CDD521/10 ", "2.06"}, SDEV_NOLUNS},
389 {{T_CDROM, T_REMOV,
390 "MATSHITA", "CD-ROM CR-5XX ", "1.0b"}, SDEV_NOLUNS},
391 {{T_CDROM, T_REMOV,
392 "MEDAVIS ", "RENO CD-ROMX2A ", ""}, SDEV_NOLUNS},
393 {{T_CDROM, T_REMOV,
394 "MEDIAVIS", "CDR-H93MV ", "1.3"}, SDEV_NOLUNS},
395 {{T_CDROM, T_REMOV,
396 "NEC ", "CD-ROM DRIVE:55 ", ""}, SDEV_NOLUNS},
397 {{T_CDROM, T_REMOV,
398 "NEC ", "CD-ROM DRIVE:83 ", ""}, SDEV_NOLUNS},
399 {{T_CDROM, T_REMOV,
400 "NEC ", "CD-ROM DRIVE:84 ", ""}, SDEV_NOLUNS},
401 {{T_CDROM, T_REMOV,
402 "NEC ", "CD-ROM DRIVE:841", ""}, SDEV_NOLUNS},
403 {{T_CDROM, T_REMOV,
404 "PIONEER ", "CD-ROM DR-124X ", "1.01"}, SDEV_NOLUNS},
405 {{T_CDROM, T_REMOV,
406 "SONY ", "CD-ROM CDU-541 ", ""}, SDEV_NOLUNS},
407 {{T_CDROM, T_REMOV,
408 "SONY ", "CD-ROM CDU-55S ", ""}, SDEV_NOLUNS},
409 {{T_CDROM, T_REMOV,
410 "SONY ", "CD-ROM CDU-8003A", ""}, SDEV_NOLUNS},
411 {{T_CDROM, T_REMOV,
412 "SONY ", "CD-ROM CDU-8012 ", ""}, SDEV_NOLUNS},
413 {{T_CDROM, T_REMOV,
414 "TEAC ", "CD-ROM ", "1.06"}, SDEV_NOLUNS},
415 {{T_CDROM, T_REMOV,
416 "TEAC ", "CD-ROM CD-56S ", "1.0B"}, SDEV_NOLUNS},
417 {{T_CDROM, T_REMOV,
418 "TEXEL ", "CD-ROM ", "1.06"}, SDEV_NOLUNS},
419 {{T_CDROM, T_REMOV,
420 "TEXEL ", "CD-ROM DM-XX24 K", "1.10"}, SDEV_NOLUNS},
421 {{T_CDROM, T_REMOV,
422 "TOSHIBA ", "XM-4101TASUNSLCD", "1755"}, SDEV_NOLUNS},
423 {{T_CDROM, T_REMOV,
424 "ShinaKen", "CD-ROM DM-3x1S", "1.04"}, SDEV_NOLUNS},
425 {{T_CDROM, T_REMOV,
426 "JVC ", "R2626", ""}, SDEV_NOLUNS},
427 {{T_DIRECT, T_FIXED,
428 "MICROP ", "1588-15MBSUN0669", ""}, SDEV_AUTOSAVE},
429 {{T_DIRECT, T_FIXED,
430 "MICROP ", "2217-15MQ1091501", ""}, SDEV_NOSYNCCACHE},
431 {{T_OPTICAL, T_REMOV,
432 "EPSON ", "OMD-5010 ", "3.08"}, SDEV_NOLUNS},
433
434 {{T_DIRECT, T_FIXED,
435 "ADAPTEC ", "AEC-4412BD", "1.2A"}, SDEV_NOMODESENSE},
436 {{T_DIRECT, T_FIXED,
437 "DEC ", "RZ55 (C) DEC", ""}, SDEV_AUTOSAVE},
438 {{T_DIRECT, T_FIXED,
439 "EMULEX ", "MD21/S2 ESDI", "A00"}, SDEV_FORCELUNS|SDEV_AUTOSAVE},
440 /* Gives non-media hardware failure in response to start-unit command */
441 {{T_DIRECT, T_FIXED,
442 "HITACHI", "DK515C", "CP16"}, SDEV_NOSTARTUNIT},
443 {{T_DIRECT, T_FIXED,
444 "HITACHI", "DK515C", "CP15"}, SDEV_NOSTARTUNIT},
445 {{T_DIRECT, T_FIXED,
446 "HP ", "C372", ""}, SDEV_NOTAG},
447 {{T_DIRECT, T_FIXED,
448 "IBMRAID ", "0662S", ""}, SDEV_AUTOSAVE},
449 {{T_DIRECT, T_FIXED,
450 "IBM ", "0663H", ""}, SDEV_AUTOSAVE},
451 {{T_DIRECT, T_FIXED,
452 "IBM", "0664", ""}, SDEV_AUTOSAVE},
453 {{T_DIRECT, T_FIXED,
454 "IBM ", "H3171-S2", ""}, SDEV_NOLUNS|SDEV_AUTOSAVE},
455 {{T_DIRECT, T_FIXED,
456 "IBM ", "KZ-C", ""}, SDEV_AUTOSAVE},
457 /* Broken IBM disk */
458 {{T_DIRECT, T_FIXED,
459 "" , "DFRSS2F", ""}, SDEV_AUTOSAVE},
460 {{T_DIRECT, T_REMOV,
461 "MPL ", "MC-DISK- ", ""}, SDEV_NOLUNS},
462 {{T_DIRECT, T_FIXED,
463 "MAXTOR ", "XT-3280 ", ""}, SDEV_NOLUNS},
464 {{T_DIRECT, T_FIXED,
465 "MAXTOR ", "XT-4380S ", ""}, SDEV_NOLUNS},
466 {{T_DIRECT, T_FIXED,
467 "MAXTOR ", "MXT-1240S ", ""}, SDEV_NOLUNS},
468 {{T_DIRECT, T_FIXED,
469 "MAXTOR ", "XT-4170S ", ""}, SDEV_NOLUNS},
470 {{T_DIRECT, T_FIXED,
471 "MAXTOR ", "XT-8760S", ""}, SDEV_NOLUNS},
472 {{T_DIRECT, T_FIXED,
473 "MAXTOR ", "LXT-213S ", ""}, SDEV_NOLUNS},
474 {{T_DIRECT, T_FIXED,
475 "MAXTOR ", "LXT-213S SUN0207", ""}, SDEV_NOLUNS},
476 {{T_DIRECT, T_FIXED,
477 "MAXTOR ", "LXT-200S ", ""}, SDEV_NOLUNS},
478 {{T_DIRECT, T_FIXED,
479 "MEGADRV ", "EV1000", ""}, SDEV_NOMODESENSE},
480 {{T_DIRECT, T_FIXED,
481 "MST ", "SnapLink ", ""}, SDEV_NOLUNS},
482 {{T_DIRECT, T_FIXED,
483 "NEC ", "D3847 ", "0307"}, SDEV_NOLUNS},
484 {{T_DIRECT, T_FIXED,
485 "QUANTUM ", "ELS85S ", ""}, SDEV_AUTOSAVE},
486 {{T_DIRECT, T_FIXED,
487 "QUANTUM ", "LPS525S ", ""}, SDEV_NOLUNS},
488 {{T_DIRECT, T_FIXED,
489 "QUANTUM ", "P105S 910-10-94x", ""}, SDEV_NOLUNS},
490 {{T_DIRECT, T_FIXED,
491 "QUANTUM ", "PD1225S ", ""}, SDEV_NOLUNS},
492 {{T_DIRECT, T_FIXED,
493 "QUANTUM ", "PD210S SUN0207", ""}, SDEV_NOLUNS},
494 {{T_DIRECT, T_FIXED,
495 "RODIME ", "RO3000S ", ""}, SDEV_NOLUNS},
496 {{T_DIRECT, T_FIXED,
497 "SEAGATE ", "ST125N ", ""}, SDEV_NOLUNS},
498 {{T_DIRECT, T_FIXED,
499 "SEAGATE ", "ST157N ", ""}, SDEV_NOLUNS},
500 {{T_DIRECT, T_FIXED,
501 "SEAGATE ", "ST296 ", ""}, SDEV_NOLUNS},
502 {{T_DIRECT, T_FIXED,
503 "SEAGATE ", "ST296N ", ""}, SDEV_NOLUNS},
504 {{T_DIRECT, T_FIXED,
505 "SEAGATE ", "ST19171", ""}, SDEV_NOMODESENSE},
506 {{T_DIRECT, T_FIXED,
507 "SEAGATE ", "ST34501FC ", ""}, SDEV_NOMODESENSE},
508 {{T_DIRECT, T_FIXED,
509 "TOSHIBA ", "MK538FB ", "6027"}, SDEV_NOLUNS},
510 {{T_DIRECT, T_REMOV,
511 "iomega", "jaz 1GB", ""}, SDEV_NOMODESENSE},
512 {{T_DIRECT, T_REMOV,
513 "IOMEGA", "ZIP 100", ""}, SDEV_NOMODESENSE},
514 {{T_DIRECT, T_REMOV,
515 "IOMEGA", "ZIP 100", "J.03"}, SDEV_NOMODESENSE|SDEV_NOLUNS},
516 /* Letting the motor run kills floppy drives and disks quite fast. */
517 {{T_DIRECT, T_REMOV,
518 "TEAC", "FC-1", ""}, SDEV_NOSTARTUNIT},
519
520 /* XXX: QIC-36 tape behind Emulex adapter. Very broken. */
521 {{T_SEQUENTIAL, T_REMOV,
522 " ", " ", " "}, SDEV_NOLUNS},
523 {{T_SEQUENTIAL, T_REMOV,
524 "CALIPER ", "CP150 ", ""}, SDEV_NOLUNS},
525 {{T_SEQUENTIAL, T_REMOV,
526 "EXABYTE ", "EXB-8200 ", ""}, SDEV_NOLUNS},
527 {{T_SEQUENTIAL, T_REMOV,
528 "SONY ", "GY-10C ", ""}, SDEV_NOLUNS},
529 {{T_SEQUENTIAL, T_REMOV,
530 "SONY ", "SDT-2000 ", "2.09"}, SDEV_NOLUNS},
531 {{T_SEQUENTIAL, T_REMOV,
532 "SONY ", "SDT-5000 ", "3."}, SDEV_NOSYNC|SDEV_NOWIDE},
533 {{T_SEQUENTIAL, T_REMOV,
534 "SONY ", "SDT-5200 ", "3."}, SDEV_NOLUNS},
535 {{T_SEQUENTIAL, T_REMOV,
536 "TANDBERG", " TDC 3600 ", ""}, SDEV_NOLUNS},
537 /* Following entry reported as a Tandberg 3600; ref. PR1933 */
538 {{T_SEQUENTIAL, T_REMOV,
539 "ARCHIVE ", "VIPER 150 21247", ""}, SDEV_NOLUNS},
540 /* Following entry for a Cipher ST150S; ref. PR4171 */
541 {{T_SEQUENTIAL, T_REMOV,
542 "ARCHIVE ", "VIPER 1500 21247", "2.2G"}, SDEV_NOLUNS},
543 {{T_SEQUENTIAL, T_REMOV,
544 "ARCHIVE ", "Python 28454-XXX", ""}, SDEV_NOLUNS},
545 {{T_SEQUENTIAL, T_REMOV,
546 "WANGTEK ", "5099ES SCSI", ""}, SDEV_NOLUNS},
547 {{T_SEQUENTIAL, T_REMOV,
548 "WANGTEK ", "5150ES SCSI", ""}, SDEV_NOLUNS},
549 {{T_SEQUENTIAL, T_REMOV,
550 "WANGTEK ", "SCSI-36", ""}, SDEV_NOLUNS},
551 {{T_SEQUENTIAL, T_REMOV,
552 "WangDAT ", "Model 1300 ", "02.4"}, SDEV_NOSYNC|SDEV_NOWIDE},
553 {{T_SEQUENTIAL, T_REMOV,
554 "WangDAT ", "Model 2600 ", "01.7"}, SDEV_NOSYNC|SDEV_NOWIDE},
555 {{T_SEQUENTIAL, T_REMOV,
556 "WangDAT ", "Model 3200 ", "02.2"}, SDEV_NOSYNC|SDEV_NOWIDE},
557
558 {{T_SCANNER, T_FIXED,
559 "RICOH ", "IS60 ", "1R08"}, SDEV_NOLUNS},
560 {{T_SCANNER, T_FIXED,
561 "UMAX ", "Astra 1200S ", "V2.9"}, SDEV_NOLUNS},
562 {{T_SCANNER, T_FIXED,
563 "UMAX ", "Astra 1220S ", ""}, SDEV_NOLUNS},
564 {{T_SCANNER, T_FIXED,
565 "UMAX ", "UMAX S-6E ", "V2.0"}, SDEV_NOLUNS},
566 {{T_SCANNER, T_FIXED,
567 "UMAX ", "UMAX S-12 ", "V2.1"}, SDEV_NOLUNS},
568
569 {{T_PROCESSOR, T_FIXED,
570 "LITRONIC", "PCMCIA ", ""}, SDEV_NOLUNS},
571
572 {{T_CHANGER, T_REMOV,
573 "SONY ", "CDL1100 ", ""}, SDEV_NOLUNS},
574
575 {{T_ENCLOSURE, T_FIXED,
576 "SUN ", "SENA ", "1.07"}, SDEV_NOLUNS},
577 };
578
579 /*
580 * given a target and lun, ask the device what
581 * it is, and find the correct driver table
582 * entry.
583 */
584 int
585 scsi_probedev(scsi, target, lun)
586 struct scsibus_softc *scsi;
587 int target, lun;
588 {
589 struct scsipi_link *sc_link;
590 static struct scsipi_inquiry_data inqbuf;
591 struct scsi_quirk_inquiry_pattern *finger;
592 int checkdtype, priority, docontinue;
593 struct scsipibus_attach_args sa;
594 struct cfdata *cf;
595
596 /*
597 * Assume no more luns to search after this one.
598 * If we successfully get Inquiry data and after
599 * merging quirks we find we can probe for more
600 * luns, we will.
601 */
602 docontinue = 0;
603
604 /* Skip this slot if it is already attached. */
605 if (scsi->sc_link[target][lun] != NULL)
606 return (docontinue);
607
608 sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT);
609 *sc_link = *scsi->adapter_link;
610 sc_link->scsipi_scsi.target = target;
611 sc_link->scsipi_scsi.lun = lun;
612 sc_link->device = &probe_switch;
613 TAILQ_INIT(&sc_link->pending_xfers);
614
615 /*
616 * Ask the device what it is
617 */
618 #if defined(SCSIDEBUG) && DEBUGTYPE == BUS_SCSI
619 if (target == DEBUGTARGET && lun == DEBUGLUN)
620 sc_link->flags |= DEBUGLEVEL;
621 #endif /* SCSIDEBUG */
622
623 (void) scsipi_test_unit_ready(sc_link,
624 SCSI_AUTOCONF | SCSI_IGNORE_ILLEGAL_REQUEST |
625 SCSI_IGNORE_NOT_READY | SCSI_IGNORE_MEDIA_CHANGE);
626
627 #ifdef SCSI_2_DEF
628 /* some devices need to be told to go to SCSI2 */
629 /* However some just explode if you tell them this.. leave it out */
630 scsi_change_def(sc_link, SCSI_AUTOCONF | SCSI_SILENT);
631 #endif /* SCSI_2_DEF */
632
633 /* Now go ask the device all about itself. */
634 bzero(&inqbuf, sizeof(inqbuf));
635 if (scsipi_inquire(sc_link, &inqbuf, SCSI_AUTOCONF) != 0)
636 goto bad;
637
638 {
639 int len = inqbuf.additional_length;
640 while (len < 3)
641 inqbuf.unused[len++] = '\0';
642 while (len < 3 + 28)
643 inqbuf.unused[len++] = ' ';
644 }
645
646 sa.sa_sc_link = sc_link;
647 sa.sa_inqbuf.type = inqbuf.device;
648 sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ?
649 T_REMOV : T_FIXED;
650 sa.sa_inqbuf.vendor = inqbuf.vendor;
651 sa.sa_inqbuf.product = inqbuf.product;
652 sa.sa_inqbuf.revision = inqbuf.revision;
653 sa.scsipi_info.scsi_version = inqbuf.version;
654
655 finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
656 &sa.sa_inqbuf, (caddr_t)scsi_quirk_patterns,
657 sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
658 sizeof(scsi_quirk_patterns[0]), &priority);
659
660 /*
661 * Based upon the inquiry flags we got back, and if we're
662 * at SCSI-2 or better, set some limiting quirks.
663 */
664 if ((inqbuf.version & SID_ANSII) >= 2) {
665 if ((inqbuf.flags & SID_CmdQue) == 0)
666 sc_link->quirks |= SDEV_NOTAG;
667 if ((inqbuf.flags & SID_Sync) == 0)
668 sc_link->quirks |= SDEV_NOSYNC;
669 if ((inqbuf.flags & SID_WBus16) == 0)
670 sc_link->quirks |= SDEV_NOWIDE;
671 }
672 /*
673 * Now apply any quirks from the table.
674 */
675 if (priority != 0)
676 sc_link->quirks |= finger->quirks;
677 if ((inqbuf.version & SID_ANSII) == 0 &&
678 (sc_link->quirks & SDEV_FORCELUNS) == 0)
679 sc_link->quirks |= SDEV_NOLUNS;
680 sc_link->scsipi_scsi.scsi_version = inqbuf.version;
681
682 if ((sc_link->quirks & SDEV_NOLUNS) == 0)
683 docontinue = 1;
684
685 /*
686 * note what BASIC type of device it is
687 */
688 if ((inqbuf.dev_qual2 & SID_REMOVABLE) != 0)
689 sc_link->flags |= SDEV_REMOVABLE;
690
691 /*
692 * Any device qualifier that has the top bit set (qualifier&4 != 0)
693 * is vendor specific and won't match in this switch.
694 * All we do here is throw out bad/negative responses.
695 */
696 checkdtype = 0;
697 switch (inqbuf.device & SID_QUAL) {
698 case SID_QUAL_LU_OK:
699 case SID_QUAL_LU_OFFLINE:
700 checkdtype = 1;
701 break;
702
703 case SID_QUAL_RSVD:
704 case SID_QUAL_BAD_LU:
705 goto bad;
706
707 default:
708 break;
709 }
710 if (checkdtype)
711 switch (inqbuf.device & SID_TYPE) {
712 case T_DIRECT:
713 case T_SEQUENTIAL:
714 case T_PRINTER:
715 case T_PROCESSOR:
716 case T_WORM:
717 case T_CDROM:
718 case T_SCANNER:
719 case T_OPTICAL:
720 case T_CHANGER:
721 case T_COMM:
722 case T_IT8_1:
723 case T_IT8_2:
724 case T_STORARRAY:
725 case T_ENCLOSURE:
726 default:
727 break;
728 case T_NODEVICE:
729 goto bad;
730 }
731
732 if ((cf = config_search(scsibussubmatch, (struct device *)scsi,
733 &sa)) != NULL) {
734 scsi->sc_link[target][lun] = sc_link;
735 config_attach((struct device *)scsi, cf, &sa, scsibusprint);
736 } else {
737 scsibusprint(&sa, scsi->sc_dev.dv_xname);
738 printf(" not configured\n");
739 goto bad;
740 }
741
742 return (docontinue);
743
744 bad:
745 free(sc_link, M_DEVBUF);
746 return (docontinue);
747 }
748
749 /****** Entry points for user control of the SCSI bus. ******/
750
751 int
752 scsibusopen(dev, flag, fmt, p)
753 dev_t dev;
754 int flag, fmt;
755 struct proc *p;
756 {
757 struct scsibus_softc *sc;
758 int error, unit = minor(dev);
759
760 if (unit >= scsibus_cd.cd_ndevs ||
761 (sc = scsibus_cd.cd_devs[unit]) == NULL)
762 return (ENXIO);
763
764 if (sc->sc_flags & SCSIBUSF_OPEN)
765 return (EBUSY);
766
767 if ((error = scsipi_adapter_addref(sc->adapter_link)) != 0)
768 return (error);
769
770 sc->sc_flags |= SCSIBUSF_OPEN;
771
772 return (0);
773 }
774
775 int
776 scsibusclose(dev, flag, fmt, p)
777 dev_t dev;
778 int flag, fmt;
779 struct proc *p;
780 {
781 struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
782
783 scsipi_adapter_delref(sc->adapter_link);
784
785 sc->sc_flags &= ~SCSIBUSF_OPEN;
786
787 return (0);
788 }
789
790 int
791 scsibusioctl(dev, cmd, addr, flag, p)
792 dev_t dev;
793 u_long cmd;
794 caddr_t addr;
795 int flag;
796 struct proc *p;
797 {
798 struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
799 struct scsipi_link *sc_link = sc->adapter_link;
800 int error;
801
802 /*
803 * Enforce write permission for ioctls that change the
804 * state of the bus. Host adapter specific ioctls must
805 * be checked by the adapter driver.
806 */
807 switch (cmd) {
808 case SCBUSIOSCAN:
809 case SCBUSIORESET:
810 if ((flag & FWRITE) == 0)
811 return (EBADF);
812 }
813
814 switch (cmd) {
815 case SCBUSIOSCAN:
816 {
817 struct scbusioscan_args *a =
818 (struct scbusioscan_args *)addr;
819
820 /* XXX Change interface to this function. */
821 error = scsi_probe_busses(minor(dev), a->sa_target,
822 a->sa_lun);
823 break;
824 }
825
826 case SCBUSIORESET:
827 /* FALLTHROUGH */
828 default:
829 if (sc_link->adapter->scsipi_ioctl == NULL)
830 error = ENOTTY;
831 else
832 error = (*sc_link->adapter->scsipi_ioctl)(sc_link,
833 cmd, addr, flag, p);
834 break;
835 }
836
837 return (error);
838 }
839