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