scsiconf.c revision 1.130.2.2 1 /* $NetBSD: scsiconf.c,v 1.130.2.2 1999/10/20 22:54:09 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1998, 1999 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/kernel.h>
61 #include <sys/proc.h>
62 #include <sys/kthread.h>
63 #include <sys/malloc.h>
64 #include <sys/device.h>
65 #include <sys/conf.h>
66 #include <sys/fcntl.h>
67 #include <sys/scsiio.h>
68
69 #include <dev/scsipi/scsi_all.h>
70 #include <dev/scsipi/scsipi_all.h>
71 #include <dev/scsipi/scsiconf.h>
72
73 #include "locators.h"
74
75 const struct scsipi_periphsw scsi_probe_dev = {
76 NULL,
77 NULL,
78 NULL,
79 NULL,
80 };
81
82 int scsi_probe_device __P((struct scsibus_softc *, int, int));
83
84 int scsibusmatch __P((struct device *, struct cfdata *, void *));
85 void scsibusattach __P((struct device *, struct device *, void *));
86 int scsibusactivate __P((struct device *, enum devact));
87 int scsibusdetach __P((struct device *, int flags));
88
89 int scsibussubmatch __P((struct device *, struct cfdata *, void *));
90
91 struct cfattach scsibus_ca = {
92 sizeof(struct scsibus_softc), scsibusmatch, scsibusattach,
93 scsibusdetach, scsibusactivate,
94 };
95
96 extern struct cfdriver scsibus_cd;
97
98 int scsibusprint __P((void *, const char *));
99 void scsibus_config_interrupts __P((struct device *));
100
101 cdev_decl(scsibus);
102
103 const struct scsipi_bustype scsi_bustype = {
104 SCSIPI_BUSTYPE_SCSI,
105 scsi_scsipi_cmd,
106 scsipi_interpret_sense,
107 scsi_print_addr,
108 scsi_kill_pending,
109 };
110
111 int
112 scsiprint(aux, pnp)
113 void *aux;
114 const char *pnp;
115 {
116 struct scsipi_channel *chan = aux;
117 struct scsipi_adapter *adapt = chan->chan_adapter;
118
119 /* only "scsibus"es can attach to "scsi"s; easy. */
120 if (pnp)
121 printf("scsibus at %s", pnp);
122
123 /* don't print channel if the controller says there can be only one. */
124 if (adapt->adapt_nchannels != 1)
125 printf(" channel %d", chan->chan_channel);
126
127 return (UNCONF);
128 }
129
130 int
131 scsibusmatch(parent, cf, aux)
132 struct device *parent;
133 struct cfdata *cf;
134 void *aux;
135 {
136 struct scsipi_channel *chan = aux;
137
138 if (cf->cf_loc[SCSICF_CHANNEL] != chan->chan_channel &&
139 cf->cf_loc[SCSICF_CHANNEL] != SCSICF_CHANNEL_DEFAULT)
140 return (0);
141
142 return (1);
143 }
144
145 void
146 scsibusattach(parent, self, aux)
147 struct device *parent, *self;
148 void *aux;
149 {
150 struct scsibus_softc *sc = (void *) self;
151 struct scsipi_channel *chan = aux;
152
153 sc->sc_channel = chan;
154
155 printf(": %d targets, %d luns per target\n",
156 chan->chan_ntargets, chan->chan_nluns);
157
158 /* Initialize the channel. */
159 scsipi_channel_init(chan);
160
161 /*
162 * Defer configuration of the children until interrupts
163 * are enabled.
164 */
165 config_interrupts(self, scsibus_config_interrupts);
166 }
167
168 void
169 scsibus_config_interrupts(self)
170 struct device *self;
171 {
172 struct scsibus_softc *sc = (void *) self;
173
174 #if defined(SCSI_DELAY) && SCSI_DELAY > 2
175 #else /* SCSI_DELAY > 2 */
176 #undef SCSI_DELAY
177 #define SCSI_DELAY 2
178 #endif /* SCSI_DELAY */
179
180 if (SCSI_DELAY > 0) {
181 printf("%s: waiting %d seconds for devices to settle...\n",
182 self->dv_xname, SCSI_DELAY);
183 /* ...an identifier we know no one will use... */
184 (void) tsleep(scsibus_config_interrupts, PRIBIO,
185 "scsidly", SCSI_DELAY * hz);
186 }
187
188 scsi_probe_bus(sc, -1, -1);
189 }
190
191 int
192 scsibussubmatch(parent, cf, aux)
193 struct device *parent;
194 struct cfdata *cf;
195 void *aux;
196 {
197 struct scsipibus_attach_args *sa = aux;
198 struct scsipi_periph *periph = sa->sa_periph;
199
200 if (cf->cf_loc[SCSIBUSCF_TARGET] != SCSIBUSCF_TARGET_DEFAULT &&
201 cf->cf_loc[SCSIBUSCF_TARGET] != periph->periph_target)
202 return (0);
203 if (cf->cf_loc[SCSIBUSCF_LUN] != SCSIBUSCF_LUN_DEFAULT &&
204 cf->cf_loc[SCSIBUSCF_LUN] != periph->periph_lun)
205 return (0);
206 return ((*cf->cf_attach->ca_match)(parent, cf, aux));
207 }
208
209 int
210 scsibusactivate(self, act)
211 struct device *self;
212 enum devact act;
213 {
214 struct scsibus_softc *sc = (void *) self;
215 struct scsipi_channel *chan = sc->sc_channel;
216 struct scsipi_periph *periph;
217 int target, lun, error = 0, s;
218
219 s = splbio();
220 switch (act) {
221 case DVACT_ACTIVATE:
222 error = EOPNOTSUPP;
223 break;
224
225 case DVACT_DEACTIVATE:
226 for (target = 0; target < chan->chan_ntargets;
227 target++) {
228 if (target == chan->chan_id)
229 continue;
230 for (lun = 0; lun < chan->chan_nluns; lun++) {
231 periph = chan->chan_periphs[target][lun];
232 if (periph == NULL)
233 continue;
234 error = config_deactivate(periph->periph_dev);
235 if (error)
236 goto out;
237 }
238 }
239 break;
240 }
241 out:
242 splx(s);
243 return (error);
244 }
245
246 int
247 scsibusdetach(self, flags)
248 struct device *self;
249 int flags;
250 {
251 struct scsibus_softc *sc = (void *) self;
252 struct scsipi_channel *chan = sc->sc_channel;
253 struct scsipi_periph *periph;
254 int target, lun, error;
255
256 for (target = 0; target < chan->chan_ntargets; target++) {
257 if (target == chan->chan_id)
258 continue;
259 for (lun = 0; lun < chan->chan_nluns; lun++) {
260 periph = chan->chan_periphs[target][lun];
261 if (periph == NULL)
262 continue;
263 error = config_detach(periph->periph_dev, flags);
264 if (error)
265 return (error);
266 free(periph, M_DEVBUF);
267 chan->chan_periphs[target][lun] = NULL;
268 }
269 }
270 return (0);
271 }
272
273 /*
274 * Probe the requested scsi bus. It must be already set up.
275 * target and lun optionally narrow the search if not -1
276 */
277 int
278 scsi_probe_bus(sc, target, lun)
279 struct scsibus_softc *sc;
280 int target, lun;
281 {
282 struct scsipi_channel *chan = sc->sc_channel;
283 int maxtarget, mintarget, maxlun, minlun;
284 int error;
285
286 if (target == -1) {
287 maxtarget = chan->chan_ntargets - 1;
288 mintarget = 0;
289 } else {
290 if (target < 0 || target >= chan->chan_ntargets)
291 return (EINVAL);
292 maxtarget = mintarget = target;
293 }
294
295 if (lun == -1) {
296 maxlun = chan->chan_nluns - 1;
297 minlun = 0;
298 } else {
299 if (lun < 0 || lun >= chan->chan_nluns)
300 return (EINVAL);
301 maxlun = minlun = lun;
302 }
303
304 if ((error = scsipi_adapter_addref(chan->chan_adapter)) != 0)
305 return (error);
306 for (target = mintarget; target <= maxtarget; target++) {
307 if (target == chan->chan_id)
308 continue;
309 for (lun = minlun; lun <= maxlun; lun++) {
310 /*
311 * See if there's a device present, and configure it.
312 */
313 if (scsi_probe_device(sc, target, lun) == 0)
314 break;
315 /* otherwise something says we should look further */
316 }
317 }
318 scsipi_adapter_delref(chan->chan_adapter);
319 return (0);
320 }
321
322 /*
323 * Print out autoconfiguration information for a subdevice.
324 *
325 * This is a slight abuse of 'standard' autoconfiguration semantics,
326 * because 'print' functions don't normally print the colon and
327 * device information. However, in this case that's better than
328 * either printing redundant information before the attach message,
329 * or having the device driver call a special function to print out
330 * the standard device information.
331 */
332 int
333 scsibusprint(aux, pnp)
334 void *aux;
335 const char *pnp;
336 {
337 struct scsipibus_attach_args *sa = aux;
338 struct scsipi_inquiry_pattern *inqbuf;
339 u_int8_t type;
340 const char *dtype, *qtype;
341 char vendor[33], product[65], revision[17];
342 int target, lun;
343
344 if (pnp != NULL)
345 printf("%s", pnp);
346
347 inqbuf = &sa->sa_inqbuf;
348
349 target = sa->sa_periph->periph_target;
350 lun = sa->sa_periph->periph_lun;
351 type = inqbuf->type & SID_TYPE;
352
353 /*
354 * Figure out basic device type and qualifier.
355 */
356 dtype = 0;
357 switch (inqbuf->type & SID_QUAL) {
358 case SID_QUAL_LU_PRESENT:
359 qtype = "";
360 break;
361
362 case SID_QUAL_LU_NOTPRESENT:
363 qtype = " offline";
364 break;
365
366 case SID_QUAL_reserved:
367 case SID_QUAL_LU_NOT_SUPP:
368 panic("scsibusprint: impossible qualifier");
369
370 default:
371 qtype = "";
372 dtype = "vendor-unique";
373 break;
374 }
375 if (dtype == NULL)
376 dtype = scsipi_dtype(type);
377
378 scsipi_strvis(vendor, 33, inqbuf->vendor, 8);
379 scsipi_strvis(product, 65, inqbuf->product, 16);
380 scsipi_strvis(revision, 17, inqbuf->revision, 4);
381
382 printf(" target %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s",
383 target, lun, vendor, product, revision,
384 sa->scsipi_info.scsi_version & SID_ANSII, type, dtype,
385 inqbuf->removable ? "removable" : "fixed", qtype);
386
387 return (UNCONF);
388 }
389
390 struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
391 {{T_CDROM, T_REMOV,
392 "CHINON ", "CD-ROM CDS-431 ", ""}, PQUIRK_NOLUNS},
393 {{T_CDROM, T_REMOV,
394 "Chinon ", "CD-ROM CDS-525 ", ""}, PQUIRK_NOLUNS},
395 {{T_CDROM, T_REMOV,
396 "CHINON ", "CD-ROM CDS-535 ", ""}, PQUIRK_NOLUNS},
397 {{T_CDROM, T_REMOV,
398 "DEC ", "RRD42 (C) DEC ", ""}, PQUIRK_NOLUNS},
399 {{T_CDROM, T_REMOV,
400 "DENON ", "DRD-25X ", "V"}, PQUIRK_NOLUNS},
401 {{T_CDROM, T_REMOV,
402 "HP ", "C4324/C4325 ", ""}, PQUIRK_NOLUNS},
403 {{T_CDROM, T_REMOV,
404 "IMS ", "CDD521/10 ", "2.06"}, PQUIRK_NOLUNS},
405 {{T_CDROM, T_REMOV,
406 "MATSHITA", "CD-ROM CR-5XX ", "1.0b"}, PQUIRK_NOLUNS},
407 {{T_CDROM, T_REMOV,
408 "MEDAVIS ", "RENO CD-ROMX2A ", ""}, PQUIRK_NOLUNS},
409 {{T_CDROM, T_REMOV,
410 "MEDIAVIS", "CDR-H93MV ", "1.3"}, PQUIRK_NOLUNS},
411 {{T_CDROM, T_REMOV,
412 "NEC ", "CD-ROM DRIVE:55 ", ""}, PQUIRK_NOLUNS},
413 {{T_CDROM, T_REMOV,
414 "NEC ", "CD-ROM DRIVE:83 ", ""}, PQUIRK_NOLUNS},
415 {{T_CDROM, T_REMOV,
416 "NEC ", "CD-ROM DRIVE:84 ", ""}, PQUIRK_NOLUNS},
417 {{T_CDROM, T_REMOV,
418 "NEC ", "CD-ROM DRIVE:841", ""}, PQUIRK_NOLUNS},
419 {{T_CDROM, T_REMOV,
420 "PIONEER ", "CD-ROM DR-124X ", "1.01"}, PQUIRK_NOLUNS},
421 {{T_CDROM, T_REMOV,
422 "SONY ", "CD-ROM CDU-541 ", ""}, PQUIRK_NOLUNS},
423 {{T_CDROM, T_REMOV,
424 "SONY ", "CD-ROM CDU-55S ", ""}, PQUIRK_NOLUNS},
425 {{T_CDROM, T_REMOV,
426 "SONY ", "CD-ROM CDU-561 ", ""}, PQUIRK_NOLUNS},
427 {{T_CDROM, T_REMOV,
428 "SONY ", "CD-ROM CDU-8003A", ""}, PQUIRK_NOLUNS},
429 {{T_CDROM, T_REMOV,
430 "SONY ", "CD-ROM CDU-8012 ", ""}, PQUIRK_NOLUNS},
431 {{T_CDROM, T_REMOV,
432 "TEAC ", "CD-ROM ", "1.06"}, PQUIRK_NOLUNS},
433 {{T_CDROM, T_REMOV,
434 "TEAC ", "CD-ROM CD-56S ", "1.0B"}, PQUIRK_NOLUNS},
435 {{T_CDROM, T_REMOV,
436 "TEXEL ", "CD-ROM ", "1.06"}, PQUIRK_NOLUNS},
437 {{T_CDROM, T_REMOV,
438 "TEXEL ", "CD-ROM DM-XX24 K", "1.09"}, PQUIRK_NOLUNS},
439 {{T_CDROM, T_REMOV,
440 "TEXEL ", "CD-ROM DM-XX24 K", "1.10"}, PQUIRK_NOLUNS},
441 {{T_CDROM, T_REMOV,
442 "TOSHIBA ", "XM-4101TASUNSLCD", "1755"}, PQUIRK_NOLUNS},
443 {{T_CDROM, T_REMOV,
444 "ShinaKen", "CD-ROM DM-3x1S", "1.04"}, PQUIRK_NOLUNS},
445 {{T_CDROM, T_REMOV,
446 "JVC ", "R2626", ""}, PQUIRK_NOLUNS},
447 {{T_DIRECT, T_FIXED,
448 "MICROP ", "1588-15MBSUN0669", ""}, PQUIRK_AUTOSAVE},
449 {{T_DIRECT, T_FIXED,
450 "MICROP ", "2217-15MQ1091501", ""}, PQUIRK_NOSYNCCACHE},
451 {{T_OPTICAL, T_REMOV,
452 "EPSON ", "OMD-5010 ", "3.08"}, PQUIRK_NOLUNS},
453
454 {{T_DIRECT, T_FIXED,
455 "TOSHIBA ","CD-ROM XM-3401TA", "0283"}, PQUIRK_CDROM|PQUIRK_NOLUNS},
456 {{T_DIRECT, T_FIXED,
457 "ADAPTEC ", "AEC-4412BD", "1.2A"}, PQUIRK_NOMODESENSE},
458 {{T_DIRECT, T_FIXED,
459 "DEC ", "RZ55 (C) DEC", ""}, PQUIRK_AUTOSAVE},
460 {{T_DIRECT, T_FIXED,
461 "EMULEX ", "MD21/S2 ESDI", "A00"}, PQUIRK_FORCELUNS|PQUIRK_AUTOSAVE},
462 /* Gives non-media hardware failure in response to start-unit command */
463 {{T_DIRECT, T_FIXED,
464 "HITACHI", "DK515C", "CP16"}, PQUIRK_NOSTARTUNIT},
465 {{T_DIRECT, T_FIXED,
466 "HITACHI", "DK515C", "CP15"}, PQUIRK_NOSTARTUNIT},
467 {{T_DIRECT, T_FIXED,
468 "HP ", "C372", ""}, PQUIRK_NOTAG},
469 {{T_DIRECT, T_FIXED,
470 "IBMRAID ", "0662S", ""}, PQUIRK_AUTOSAVE},
471 {{T_DIRECT, T_FIXED,
472 "IBM ", "0663H", ""}, PQUIRK_AUTOSAVE},
473 {{T_DIRECT, T_FIXED,
474 "IBM", "0664", ""}, PQUIRK_AUTOSAVE},
475 {{T_DIRECT, T_FIXED,
476 "IBM ", "H3171-S2", ""}, PQUIRK_NOLUNS|PQUIRK_AUTOSAVE},
477 {{T_DIRECT, T_FIXED,
478 "IBM ", "KZ-C", ""}, PQUIRK_AUTOSAVE},
479 /* Broken IBM disk */
480 {{T_DIRECT, T_FIXED,
481 "" , "DFRSS2F", ""}, PQUIRK_AUTOSAVE},
482 {{T_DIRECT, T_REMOV,
483 "MPL ", "MC-DISK- ", ""}, PQUIRK_NOLUNS},
484 {{T_DIRECT, T_FIXED,
485 "MAXTOR ", "XT-3280 ", ""}, PQUIRK_NOLUNS},
486 {{T_DIRECT, T_FIXED,
487 "MAXTOR ", "XT-4380S ", ""}, PQUIRK_NOLUNS},
488 {{T_DIRECT, T_FIXED,
489 "MAXTOR ", "MXT-1240S ", ""}, PQUIRK_NOLUNS},
490 {{T_DIRECT, T_FIXED,
491 "MAXTOR ", "XT-4170S ", ""}, PQUIRK_NOLUNS},
492 {{T_DIRECT, T_FIXED,
493 "MAXTOR ", "XT-8760S", ""}, PQUIRK_NOLUNS},
494 {{T_DIRECT, T_FIXED,
495 "MAXTOR ", "LXT-213S ", ""}, PQUIRK_NOLUNS},
496 {{T_DIRECT, T_FIXED,
497 "MAXTOR ", "LXT-213S SUN0207", ""}, PQUIRK_NOLUNS},
498 {{T_DIRECT, T_FIXED,
499 "MAXTOR ", "LXT-200S ", ""}, PQUIRK_NOLUNS},
500 {{T_DIRECT, T_FIXED,
501 "MEGADRV ", "EV1000", ""}, PQUIRK_NOMODESENSE},
502 {{T_DIRECT, T_FIXED,
503 "MST ", "SnapLink ", ""}, PQUIRK_NOLUNS},
504 {{T_DIRECT, T_FIXED,
505 "NEC ", "D3847 ", "0307"}, PQUIRK_NOLUNS},
506 {{T_DIRECT, T_FIXED,
507 "QUANTUM ", "ELS85S ", ""}, PQUIRK_AUTOSAVE},
508 {{T_DIRECT, T_FIXED,
509 "QUANTUM ", "LPS525S ", ""}, PQUIRK_NOLUNS},
510 {{T_DIRECT, T_FIXED,
511 "QUANTUM ", "P105S 910-10-94x", ""}, PQUIRK_NOLUNS},
512 {{T_DIRECT, T_FIXED,
513 "QUANTUM ", "PD1225S ", ""}, PQUIRK_NOLUNS},
514 {{T_DIRECT, T_FIXED,
515 "QUANTUM ", "PD210S SUN0207", ""}, PQUIRK_NOLUNS},
516 {{T_DIRECT, T_FIXED,
517 "RODIME ", "RO3000S ", ""}, PQUIRK_NOLUNS},
518 {{T_DIRECT, T_FIXED,
519 "SEAGATE ", "ST125N ", ""}, PQUIRK_NOLUNS},
520 {{T_DIRECT, T_FIXED,
521 "SEAGATE ", "ST157N ", ""}, PQUIRK_NOLUNS},
522 {{T_DIRECT, T_FIXED,
523 "SEAGATE ", "ST296 ", ""}, PQUIRK_NOLUNS},
524 {{T_DIRECT, T_FIXED,
525 "SEAGATE ", "ST296N ", ""}, PQUIRK_NOLUNS},
526 {{T_DIRECT, T_FIXED,
527 "SEAGATE ", "ST19171", ""}, PQUIRK_NOMODESENSE},
528 {{T_DIRECT, T_FIXED,
529 "SEAGATE ", "ST34501FC ", ""}, PQUIRK_NOMODESENSE},
530 {{T_DIRECT, T_FIXED,
531 "TOSHIBA ", "MK538FB ", "6027"}, PQUIRK_NOLUNS},
532 {{T_DIRECT, T_REMOV,
533 "iomega", "jaz 1GB", ""}, PQUIRK_NOMODESENSE},
534 {{T_DIRECT, T_REMOV,
535 "IOMEGA", "ZIP 100", ""}, PQUIRK_NOMODESENSE},
536 {{T_DIRECT, T_REMOV,
537 "IOMEGA", "ZIP 100", "J.03"}, PQUIRK_NOMODESENSE|PQUIRK_NOLUNS},
538 /* Letting the motor run kills floppy drives and disks quite fast. */
539 {{T_DIRECT, T_REMOV,
540 "TEAC", "FC-1", ""}, PQUIRK_NOSTARTUNIT},
541
542 /* XXX: QIC-36 tape behind Emulex adapter. Very broken. */
543 {{T_SEQUENTIAL, T_REMOV,
544 " ", " ", " "}, PQUIRK_NOLUNS},
545 {{T_SEQUENTIAL, T_REMOV,
546 "CALIPER ", "CP150 ", ""}, PQUIRK_NOLUNS},
547 {{T_SEQUENTIAL, T_REMOV,
548 "EXABYTE ", "EXB-8200 ", ""}, PQUIRK_NOLUNS},
549 {{T_SEQUENTIAL, T_REMOV,
550 "SONY ", "GY-10C ", ""}, PQUIRK_NOLUNS},
551 {{T_SEQUENTIAL, T_REMOV,
552 "SONY ", "SDT-2000 ", "2.09"}, PQUIRK_NOLUNS},
553 {{T_SEQUENTIAL, T_REMOV,
554 "SONY ", "SDT-5000 ", "3."}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
555 {{T_SEQUENTIAL, T_REMOV,
556 "SONY ", "SDT-5200 ", "3."}, PQUIRK_NOLUNS},
557 {{T_SEQUENTIAL, T_REMOV,
558 "TANDBERG", " TDC 3600 ", ""}, PQUIRK_NOLUNS},
559 /* Following entry reported as a Tandberg 3600; ref. PR1933 */
560 {{T_SEQUENTIAL, T_REMOV,
561 "ARCHIVE ", "VIPER 150 21247", ""}, PQUIRK_NOLUNS},
562 /* Following entry for a Cipher ST150S; ref. PR4171 */
563 {{T_SEQUENTIAL, T_REMOV,
564 "ARCHIVE ", "VIPER 1500 21247", "2.2G"}, PQUIRK_NOLUNS},
565 {{T_SEQUENTIAL, T_REMOV,
566 "ARCHIVE ", "Python 28454-XXX", ""}, PQUIRK_NOLUNS},
567 {{T_SEQUENTIAL, T_REMOV,
568 "WANGTEK ", "5099ES SCSI", ""}, PQUIRK_NOLUNS},
569 {{T_SEQUENTIAL, T_REMOV,
570 "WANGTEK ", "5150ES SCSI", ""}, PQUIRK_NOLUNS},
571 {{T_SEQUENTIAL, T_REMOV,
572 "WANGTEK ", "SCSI-36", ""}, PQUIRK_NOLUNS},
573 {{T_SEQUENTIAL, T_REMOV,
574 "WangDAT ", "Model 1300 ", "02.4"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
575 {{T_SEQUENTIAL, T_REMOV,
576 "WangDAT ", "Model 2600 ", "01.7"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
577 {{T_SEQUENTIAL, T_REMOV,
578 "WangDAT ", "Model 3200 ", "02.2"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
579
580 {{T_SCANNER, T_FIXED,
581 "RICOH ", "IS60 ", "1R08"}, PQUIRK_NOLUNS},
582 {{T_SCANNER, T_FIXED,
583 "UMAX ", "Astra 1200S ", "V2.9"}, PQUIRK_NOLUNS},
584 {{T_SCANNER, T_FIXED,
585 "UMAX ", "Astra 1220S ", ""}, PQUIRK_NOLUNS},
586 {{T_SCANNER, T_FIXED,
587 "UMAX ", "UMAX S-6E ", "V2.0"}, PQUIRK_NOLUNS},
588 {{T_SCANNER, T_FIXED,
589 "UMAX ", "UMAX S-12 ", "V2.1"}, PQUIRK_NOLUNS},
590
591 {{T_PROCESSOR, T_FIXED,
592 "LITRONIC", "PCMCIA ", ""}, PQUIRK_NOLUNS},
593
594 {{T_CHANGER, T_REMOV,
595 "SONY ", "CDL1100 ", ""}, PQUIRK_NOLUNS},
596
597 {{T_ENCLOSURE, T_FIXED,
598 "SUN ", "SENA ", "1.07"}, PQUIRK_NOLUNS},
599 };
600
601 /*
602 * given a target and lun, ask the device what
603 * it is, and find the correct driver table
604 * entry.
605 */
606 int
607 scsi_probe_device(sc, target, lun)
608 struct scsibus_softc *sc;
609 int target, lun;
610 {
611 struct scsipi_channel *chan = sc->sc_channel;
612 struct scsipi_periph *periph;
613 struct scsipi_inquiry_data inqbuf;
614 struct scsi_quirk_inquiry_pattern *finger;
615 int i, checkdtype, priority, docontinue, quirks, s;
616 struct scsipibus_attach_args sa;
617 struct cfdata *cf;
618
619 /*
620 * Assume no more luns to search after this one.
621 * If we successfully get Inquiry data and after
622 * merging quirks we find we can probe for more
623 * luns, we will.
624 */
625 docontinue = 0;
626
627 /* Skip this slot if it is already attached. */
628 if (chan->chan_periphs[target][lun] != NULL)
629 return (docontinue);
630
631 periph = malloc(sizeof(*periph), M_DEVBUF, M_WAITOK);
632 memset(periph, 0, sizeof(*periph));
633
634 periph->periph_dev = NULL;
635 periph->periph_channel = chan;
636 periph->periph_switch = &scsi_probe_dev;
637
638 /*
639 * Start with one command opening. The periph driver
640 * will grow this if it knows it can take advantage of it.
641 */
642 periph->periph_openings = 1;
643 periph->periph_active = 0;
644
645 periph->periph_target = target;
646 periph->periph_lun = lun;
647
648 for (i = 0; i < PERIPH_NTAGWORDS; i++)
649 periph->periph_freetags[i] = 0xffffffff;
650
651 TAILQ_INIT(&periph->periph_xferq);
652
653 /*
654 * Ask the device what it is
655 */
656 #if defined(SCSIDEBUG) && DEBUGTYPE == BUS_SCSI
657 if (target == DEBUGTARGET && lun == DEBUGLUN)
658 sc_link->flags |= DEBUGLEVEL;
659 #endif /* SCSIDEBUG */
660
661 (void) scsipi_test_unit_ready(periph,
662 XS_CTL_DISCOVERY | XS_CTL_IGNORE_ILLEGAL_REQUEST |
663 XS_CTL_IGNORE_NOT_READY | XS_CTL_IGNORE_MEDIA_CHANGE);
664
665 #ifdef SCSI_2_DEF
666 /* some devices need to be told to go to SCSI2 */
667 /* However some just explode if you tell them this.. leave it out */
668 scsi_change_def(periph, XS_CTL_DISCOVERY | XS_CTL_SILENT);
669 #endif /* SCSI_2_DEF */
670
671 /* Now go ask the device all about itself. */
672 memset(&inqbuf, 0, sizeof(inqbuf));
673 if (scsipi_inquire(periph, &inqbuf, XS_CTL_DISCOVERY) != 0)
674 goto bad;
675 {
676 int len = inqbuf.additional_length;
677 while (len < 3)
678 inqbuf.unused[len++] = '\0';
679 while (len < 3 + 28)
680 inqbuf.unused[len++] = ' ';
681 }
682
683 periph->periph_type = inqbuf.device & SID_TYPE;
684 if (inqbuf.dev_qual2 & SID_REMOVABLE)
685 periph->periph_flags |= PERIPH_REMOVABLE;
686 periph->periph_version = inqbuf.version & SID_ANSII;
687
688 /*
689 * Any device qualifier that has the top bit set (qualifier&4 != 0)
690 * is vendor specific and won't match in this switch.
691 * All we do here is throw out bad/negative responses.
692 */
693 checkdtype = 0;
694 switch (inqbuf.device & SID_QUAL) {
695 case SID_QUAL_LU_PRESENT:
696 case SID_QUAL_LU_NOTPRESENT:
697 checkdtype = 1;
698 break;
699
700 case SID_QUAL_reserved:
701 case SID_QUAL_LU_NOT_SUPP:
702 goto bad;
703
704 default:
705 break;
706 }
707 if (checkdtype) {
708 switch (periph->periph_type) {
709 case T_DIRECT:
710 case T_SEQUENTIAL:
711 case T_PRINTER:
712 case T_PROCESSOR:
713 case T_WORM:
714 case T_CDROM:
715 case T_SCANNER:
716 case T_OPTICAL:
717 case T_CHANGER:
718 case T_COMM:
719 case T_IT8_1:
720 case T_IT8_2:
721 case T_STORARRAY:
722 case T_ENCLOSURE:
723 default:
724 break;
725 case T_NODEVICE:
726 goto bad;
727 }
728 }
729
730 sa.sa_periph = periph;
731 sa.sa_inqbuf.type = inqbuf.device;
732 sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ?
733 T_REMOV : T_FIXED;
734 sa.sa_inqbuf.vendor = inqbuf.vendor;
735 sa.sa_inqbuf.product = inqbuf.product;
736 sa.sa_inqbuf.revision = inqbuf.revision;
737 sa.scsipi_info.scsi_version = inqbuf.version;
738
739 finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
740 &sa.sa_inqbuf, (caddr_t)scsi_quirk_patterns,
741 sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
742 sizeof(scsi_quirk_patterns[0]), &priority);
743
744 if (finger != NULL)
745 quirks = finger->quirks;
746 else
747 quirks = 0;
748
749 /*
750 * Determine the operating mode capabilities of the device.
751 */
752 if (periph->periph_version >= 2) {
753 if ((inqbuf.flags & SID_CmdQue) != 0 &&
754 (quirks & PQUIRK_NOTAG) == 0)
755 periph->periph_cap |= PERIPH_CAP_TQING;
756 if ((inqbuf.flags & SID_Linked) != 0)
757 periph->periph_cap |= PERIPH_CAP_LINKCMDS;
758 if ((inqbuf.flags & SID_Sync) != 0 &&
759 (quirks & PQUIRK_NOSYNC) == 0)
760 periph->periph_cap |= PERIPH_CAP_SYNC;
761 if ((inqbuf.flags & SID_WBus16) != 0 &&
762 (quirks & PQUIRK_NOWIDE) == 0)
763 periph->periph_cap |= PERIPH_CAP_WIDE16;
764 if ((inqbuf.flags & SID_WBus32) != 0 &&
765 (quirks & PQUIRK_NOWIDE) == 0)
766 periph->periph_cap |= PERIPH_CAP_WIDE32;
767 if ((inqbuf.flags & SID_SftRe) != 0)
768 periph->periph_cap |= PERIPH_CAP_SFTRESET;
769 if ((inqbuf.flags & SID_RelAdr) != 0)
770 periph->periph_cap |= PERIPH_CAP_RELADR;
771 }
772
773 /*
774 * Now apply any quirks from the table.
775 */
776 periph->periph_quirks |= quirks;
777 if (periph->periph_version == 0 &&
778 (periph->periph_quirks & PQUIRK_FORCELUNS) == 0)
779 periph->periph_quirks |= PQUIRK_NOLUNS;
780
781 if ((periph->periph_quirks & PQUIRK_NOLUNS) == 0)
782 docontinue = 1;
783
784 if ((cf = config_search(scsibussubmatch, &sc->sc_dev, &sa)) != NULL) {
785 chan->chan_periphs[target][lun] = periph;
786 /*
787 * XXX Can't assign periph_dev here, because we'll
788 * XXX need it before config_attach() returns. Must
789 * XXX assign it in periph driver.
790 */
791 (void) config_attach(&sc->sc_dev, cf, &sa, scsibusprint);
792
793 if (lun == 0) {
794 /*
795 * Issue a request to the adapter to negotiate the best
796 * possible xfer mode given our capabilities.
797 */
798 s = splbio();
799 scsipi_adapter_request(chan, ADAPTER_REQ_SET_XFER_MODE,
800 periph);
801 splx(s);
802
803 /*
804 * Issue a dummy command; some adapters can only really
805 * do xfer mode negotiation when performing a command.
806 */
807 (void) scsipi_test_unit_ready(periph,
808 XS_CTL_DISCOVERY | XS_CTL_IGNORE_ILLEGAL_REQUEST |
809 XS_CTL_IGNORE_NOT_READY |
810 XS_CTL_IGNORE_MEDIA_CHANGE);
811
812 /*
813 * Now get the xfer mode settings.
814 */
815 s = splbio();
816 scsipi_adapter_request(chan, ADAPTER_REQ_GET_XFER_MODE,
817 periph);
818 splx(s);
819 } else {
820 /*
821 * Not the first LUN; devices of this sort inherit
822 * the xfer mode paramters of the I_T Nexus, masked
823 * by their own capabilities.
824 */
825 struct scsipi_periph *itperiph =
826 scsipi_lookup_periph(chan, target, 0);
827 if (itperiph != NULL) {
828 periph->periph_mode =
829 itperiph->periph_mode & periph->periph_cap;
830 periph->periph_period = itperiph->periph_period;
831 periph->periph_offset = itperiph->periph_offset;
832 periph->periph_flags |=
833 itperiph->periph_flags & PERIPH_MODE_VALID;
834 }
835 }
836 scsipi_print_xfer_mode(periph);
837 } else {
838 scsibusprint(&sa, sc->sc_dev.dv_xname);
839 printf(" not configured\n");
840 goto bad;
841 }
842
843 return (docontinue);
844
845 bad:
846 free(periph, M_DEVBUF);
847 return (docontinue);
848 }
849
850 /****** Entry points for user control of the SCSI bus. ******/
851
852 int
853 scsibusopen(dev, flag, fmt, p)
854 dev_t dev;
855 int flag, fmt;
856 struct proc *p;
857 {
858 struct scsibus_softc *sc;
859 int error, unit = minor(dev);
860
861 if (unit >= scsibus_cd.cd_ndevs ||
862 (sc = scsibus_cd.cd_devs[unit]) == NULL)
863 return (ENXIO);
864
865 if (sc->sc_flags & SCSIBUSF_OPEN)
866 return (EBUSY);
867
868 if ((error = scsipi_adapter_addref(sc->sc_channel->chan_adapter)) != 0)
869 return (error);
870
871 sc->sc_flags |= SCSIBUSF_OPEN;
872
873 return (0);
874 }
875
876 int
877 scsibusclose(dev, flag, fmt, p)
878 dev_t dev;
879 int flag, fmt;
880 struct proc *p;
881 {
882 struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
883
884 scsipi_adapter_delref(sc->sc_channel->chan_adapter);
885
886 sc->sc_flags &= ~SCSIBUSF_OPEN;
887
888 return (0);
889 }
890
891 int
892 scsibusioctl(dev, cmd, addr, flag, p)
893 dev_t dev;
894 u_long cmd;
895 caddr_t addr;
896 int flag;
897 struct proc *p;
898 {
899 struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
900 struct scsipi_channel *chan = sc->sc_channel;
901 int error;
902
903 /*
904 * Enforce write permission for ioctls that change the
905 * state of the bus. Host adapter specific ioctls must
906 * be checked by the adapter driver.
907 */
908 switch (cmd) {
909 case SCBUSIOSCAN:
910 case SCBUSIORESET:
911 if ((flag & FWRITE) == 0)
912 return (EBADF);
913 }
914
915 switch (cmd) {
916 case SCBUSIOSCAN:
917 {
918 struct scbusioscan_args *a =
919 (struct scbusioscan_args *)addr;
920
921 error = scsi_probe_bus(sc, a->sa_target, a->sa_lun);
922 break;
923 }
924
925 case SCBUSIORESET:
926 /* FALLTHROUGH */
927 default:
928 if (chan->chan_adapter->adapt_ioctl == NULL)
929 error = ENOTTY;
930 else
931 error = (*chan->chan_adapter->adapt_ioctl)(chan,
932 cmd, addr, flag, p);
933 break;
934 }
935
936 return (error);
937 }
938