scsiconf.c revision 1.130.2.4 1 /* $NetBSD: scsiconf.c,v 1.130.2.4 1999/11/01 22:54:19 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 /*
319 * Now that we've discovered all of the LUNs on this
320 * I_T Nexus, update the xfer mode for all of them
321 * that we know about.
322 */
323 scsipi_set_xfer_mode(chan, target, 1);
324 }
325 scsipi_adapter_delref(chan->chan_adapter);
326 return (0);
327 }
328
329 /*
330 * Print out autoconfiguration information for a subdevice.
331 *
332 * This is a slight abuse of 'standard' autoconfiguration semantics,
333 * because 'print' functions don't normally print the colon and
334 * device information. However, in this case that's better than
335 * either printing redundant information before the attach message,
336 * or having the device driver call a special function to print out
337 * the standard device information.
338 */
339 int
340 scsibusprint(aux, pnp)
341 void *aux;
342 const char *pnp;
343 {
344 struct scsipibus_attach_args *sa = aux;
345 struct scsipi_inquiry_pattern *inqbuf;
346 u_int8_t type;
347 const char *dtype, *qtype;
348 char vendor[33], product[65], revision[17];
349 int target, lun;
350
351 if (pnp != NULL)
352 printf("%s", pnp);
353
354 inqbuf = &sa->sa_inqbuf;
355
356 target = sa->sa_periph->periph_target;
357 lun = sa->sa_periph->periph_lun;
358 type = inqbuf->type & SID_TYPE;
359
360 /*
361 * Figure out basic device type and qualifier.
362 */
363 dtype = 0;
364 switch (inqbuf->type & SID_QUAL) {
365 case SID_QUAL_LU_PRESENT:
366 qtype = "";
367 break;
368
369 case SID_QUAL_LU_NOTPRESENT:
370 qtype = " offline";
371 break;
372
373 case SID_QUAL_reserved:
374 case SID_QUAL_LU_NOT_SUPP:
375 panic("scsibusprint: impossible qualifier");
376
377 default:
378 qtype = "";
379 dtype = "vendor-unique";
380 break;
381 }
382 if (dtype == NULL)
383 dtype = scsipi_dtype(type);
384
385 scsipi_strvis(vendor, 33, inqbuf->vendor, 8);
386 scsipi_strvis(product, 65, inqbuf->product, 16);
387 scsipi_strvis(revision, 17, inqbuf->revision, 4);
388
389 printf(" target %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s",
390 target, lun, vendor, product, revision,
391 sa->scsipi_info.scsi_version & SID_ANSII, type, dtype,
392 inqbuf->removable ? "removable" : "fixed", qtype);
393
394 return (UNCONF);
395 }
396
397 struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
398 {{T_CDROM, T_REMOV,
399 "CHINON ", "CD-ROM CDS-431 ", ""}, PQUIRK_NOLUNS},
400 {{T_CDROM, T_REMOV,
401 "Chinon ", "CD-ROM CDS-525 ", ""}, PQUIRK_NOLUNS},
402 {{T_CDROM, T_REMOV,
403 "CHINON ", "CD-ROM CDS-535 ", ""}, PQUIRK_NOLUNS},
404 {{T_CDROM, T_REMOV,
405 "DEC ", "RRD42 (C) DEC ", ""}, PQUIRK_NOLUNS},
406 {{T_CDROM, T_REMOV,
407 "DENON ", "DRD-25X ", "V"}, PQUIRK_NOLUNS},
408 {{T_CDROM, T_REMOV,
409 "HP ", "C4324/C4325 ", ""}, PQUIRK_NOLUNS},
410 {{T_CDROM, T_REMOV,
411 "IMS ", "CDD521/10 ", "2.06"}, PQUIRK_NOLUNS},
412 {{T_CDROM, T_REMOV,
413 "MATSHITA", "CD-ROM CR-5XX ", "1.0b"}, PQUIRK_NOLUNS},
414 {{T_CDROM, T_REMOV,
415 "MEDAVIS ", "RENO CD-ROMX2A ", ""}, PQUIRK_NOLUNS},
416 {{T_CDROM, T_REMOV,
417 "MEDIAVIS", "CDR-H93MV ", "1.3"}, PQUIRK_NOLUNS},
418 {{T_CDROM, T_REMOV,
419 "NEC ", "CD-ROM DRIVE:55 ", ""}, PQUIRK_NOLUNS},
420 {{T_CDROM, T_REMOV,
421 "NEC ", "CD-ROM DRIVE:83 ", ""}, PQUIRK_NOLUNS},
422 {{T_CDROM, T_REMOV,
423 "NEC ", "CD-ROM DRIVE:84 ", ""}, PQUIRK_NOLUNS},
424 {{T_CDROM, T_REMOV,
425 "NEC ", "CD-ROM DRIVE:841", ""}, PQUIRK_NOLUNS},
426 {{T_CDROM, T_REMOV,
427 "PIONEER ", "CD-ROM DR-124X ", "1.01"}, PQUIRK_NOLUNS},
428 {{T_CDROM, T_REMOV,
429 "SONY ", "CD-ROM CDU-541 ", ""}, PQUIRK_NOLUNS},
430 {{T_CDROM, T_REMOV,
431 "SONY ", "CD-ROM CDU-55S ", ""}, PQUIRK_NOLUNS},
432 {{T_CDROM, T_REMOV,
433 "SONY ", "CD-ROM CDU-561 ", ""}, PQUIRK_NOLUNS},
434 {{T_CDROM, T_REMOV,
435 "SONY ", "CD-ROM CDU-8003A", ""}, PQUIRK_NOLUNS},
436 {{T_CDROM, T_REMOV,
437 "SONY ", "CD-ROM CDU-8012 ", ""}, PQUIRK_NOLUNS},
438 {{T_CDROM, T_REMOV,
439 "TEAC ", "CD-ROM ", "1.06"}, PQUIRK_NOLUNS},
440 {{T_CDROM, T_REMOV,
441 "TEAC ", "CD-ROM CD-56S ", "1.0B"}, PQUIRK_NOLUNS},
442 {{T_CDROM, T_REMOV,
443 "TEXEL ", "CD-ROM ", "1.06"}, PQUIRK_NOLUNS},
444 {{T_CDROM, T_REMOV,
445 "TEXEL ", "CD-ROM DM-XX24 K", "1.09"}, PQUIRK_NOLUNS},
446 {{T_CDROM, T_REMOV,
447 "TEXEL ", "CD-ROM DM-XX24 K", "1.10"}, PQUIRK_NOLUNS},
448 {{T_CDROM, T_REMOV,
449 "TOSHIBA ", "XM-4101TASUNSLCD", "1755"}, PQUIRK_NOLUNS},
450 {{T_CDROM, T_REMOV,
451 "ShinaKen", "CD-ROM DM-3x1S", "1.04"}, PQUIRK_NOLUNS},
452 {{T_CDROM, T_REMOV,
453 "JVC ", "R2626", ""}, PQUIRK_NOLUNS},
454 {{T_DIRECT, T_FIXED,
455 "MICROP ", "1588-15MBSUN0669", ""}, PQUIRK_AUTOSAVE},
456 {{T_DIRECT, T_FIXED,
457 "MICROP ", "2217-15MQ1091501", ""}, PQUIRK_NOSYNCCACHE},
458 {{T_OPTICAL, T_REMOV,
459 "EPSON ", "OMD-5010 ", "3.08"}, PQUIRK_NOLUNS},
460
461 {{T_DIRECT, T_FIXED,
462 "TOSHIBA ","CD-ROM XM-3401TA", "0283"}, PQUIRK_CDROM|PQUIRK_NOLUNS},
463 {{T_DIRECT, T_FIXED,
464 "ADAPTEC ", "AEC-4412BD", "1.2A"}, PQUIRK_NOMODESENSE},
465 {{T_DIRECT, T_FIXED,
466 "DEC ", "RZ55 (C) DEC", ""}, PQUIRK_AUTOSAVE},
467 {{T_DIRECT, T_FIXED,
468 "EMULEX ", "MD21/S2 ESDI", "A00"}, PQUIRK_FORCELUNS|PQUIRK_AUTOSAVE},
469 /* Gives non-media hardware failure in response to start-unit command */
470 {{T_DIRECT, T_FIXED,
471 "HITACHI", "DK515C", "CP16"}, PQUIRK_NOSTARTUNIT},
472 {{T_DIRECT, T_FIXED,
473 "HITACHI", "DK515C", "CP15"}, PQUIRK_NOSTARTUNIT},
474 {{T_DIRECT, T_FIXED,
475 "HP ", "C372", ""}, PQUIRK_NOTAG},
476 {{T_DIRECT, T_FIXED,
477 "IBMRAID ", "0662S", ""}, PQUIRK_AUTOSAVE},
478 {{T_DIRECT, T_FIXED,
479 "IBM ", "0663H", ""}, PQUIRK_AUTOSAVE},
480 {{T_DIRECT, T_FIXED,
481 "IBM", "0664", ""}, PQUIRK_AUTOSAVE},
482 {{T_DIRECT, T_FIXED,
483 "IBM ", "H3171-S2", ""}, PQUIRK_NOLUNS|PQUIRK_AUTOSAVE},
484 {{T_DIRECT, T_FIXED,
485 "IBM ", "KZ-C", ""}, PQUIRK_AUTOSAVE},
486 /* Broken IBM disk */
487 {{T_DIRECT, T_FIXED,
488 "" , "DFRSS2F", ""}, PQUIRK_AUTOSAVE},
489 {{T_DIRECT, T_REMOV,
490 "MPL ", "MC-DISK- ", ""}, PQUIRK_NOLUNS},
491 {{T_DIRECT, T_FIXED,
492 "MAXTOR ", "XT-3280 ", ""}, PQUIRK_NOLUNS},
493 {{T_DIRECT, T_FIXED,
494 "MAXTOR ", "XT-4380S ", ""}, PQUIRK_NOLUNS},
495 {{T_DIRECT, T_FIXED,
496 "MAXTOR ", "MXT-1240S ", ""}, PQUIRK_NOLUNS},
497 {{T_DIRECT, T_FIXED,
498 "MAXTOR ", "XT-4170S ", ""}, PQUIRK_NOLUNS},
499 {{T_DIRECT, T_FIXED,
500 "MAXTOR ", "XT-8760S", ""}, PQUIRK_NOLUNS},
501 {{T_DIRECT, T_FIXED,
502 "MAXTOR ", "LXT-213S ", ""}, PQUIRK_NOLUNS},
503 {{T_DIRECT, T_FIXED,
504 "MAXTOR ", "LXT-213S SUN0207", ""}, PQUIRK_NOLUNS},
505 {{T_DIRECT, T_FIXED,
506 "MAXTOR ", "LXT-200S ", ""}, PQUIRK_NOLUNS},
507 {{T_DIRECT, T_FIXED,
508 "MEGADRV ", "EV1000", ""}, PQUIRK_NOMODESENSE},
509 {{T_DIRECT, T_FIXED,
510 "MST ", "SnapLink ", ""}, PQUIRK_NOLUNS},
511 {{T_DIRECT, T_FIXED,
512 "NEC ", "D3847 ", "0307"}, PQUIRK_NOLUNS},
513 {{T_DIRECT, T_FIXED,
514 "QUANTUM ", "ELS85S ", ""}, PQUIRK_AUTOSAVE},
515 {{T_DIRECT, T_FIXED,
516 "QUANTUM ", "LPS525S ", ""}, PQUIRK_NOLUNS},
517 {{T_DIRECT, T_FIXED,
518 "QUANTUM ", "P105S 910-10-94x", ""}, PQUIRK_NOLUNS},
519 {{T_DIRECT, T_FIXED,
520 "QUANTUM ", "PD1225S ", ""}, PQUIRK_NOLUNS},
521 {{T_DIRECT, T_FIXED,
522 "QUANTUM ", "PD210S SUN0207", ""}, PQUIRK_NOLUNS},
523 {{T_DIRECT, T_FIXED,
524 "RODIME ", "RO3000S ", ""}, PQUIRK_NOLUNS},
525 {{T_DIRECT, T_FIXED,
526 "SEAGATE ", "ST125N ", ""}, PQUIRK_NOLUNS},
527 {{T_DIRECT, T_FIXED,
528 "SEAGATE ", "ST157N ", ""}, PQUIRK_NOLUNS},
529 {{T_DIRECT, T_FIXED,
530 "SEAGATE ", "ST296 ", ""}, PQUIRK_NOLUNS},
531 {{T_DIRECT, T_FIXED,
532 "SEAGATE ", "ST296N ", ""}, PQUIRK_NOLUNS},
533 {{T_DIRECT, T_FIXED,
534 "SEAGATE ", "ST19171", ""}, PQUIRK_NOMODESENSE},
535 {{T_DIRECT, T_FIXED,
536 "SEAGATE ", "ST34501FC ", ""}, PQUIRK_NOMODESENSE},
537 {{T_DIRECT, T_FIXED,
538 "TOSHIBA ", "MK538FB ", "6027"}, PQUIRK_NOLUNS},
539 {{T_DIRECT, T_REMOV,
540 "iomega", "jaz 1GB", ""}, PQUIRK_NOMODESENSE},
541 {{T_DIRECT, T_REMOV,
542 "IOMEGA", "ZIP 100", ""}, PQUIRK_NOMODESENSE},
543 {{T_DIRECT, T_REMOV,
544 "IOMEGA", "ZIP 100", "J.03"}, PQUIRK_NOMODESENSE|PQUIRK_NOLUNS},
545 /* Letting the motor run kills floppy drives and disks quite fast. */
546 {{T_DIRECT, T_REMOV,
547 "TEAC", "FC-1", ""}, PQUIRK_NOSTARTUNIT},
548
549 /* XXX: QIC-36 tape behind Emulex adapter. Very broken. */
550 {{T_SEQUENTIAL, T_REMOV,
551 " ", " ", " "}, PQUIRK_NOLUNS},
552 {{T_SEQUENTIAL, T_REMOV,
553 "CALIPER ", "CP150 ", ""}, PQUIRK_NOLUNS},
554 {{T_SEQUENTIAL, T_REMOV,
555 "EXABYTE ", "EXB-8200 ", ""}, PQUIRK_NOLUNS},
556 {{T_SEQUENTIAL, T_REMOV,
557 "SONY ", "GY-10C ", ""}, PQUIRK_NOLUNS},
558 {{T_SEQUENTIAL, T_REMOV,
559 "SONY ", "SDT-2000 ", "2.09"}, PQUIRK_NOLUNS},
560 {{T_SEQUENTIAL, T_REMOV,
561 "SONY ", "SDT-5000 ", "3."}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
562 {{T_SEQUENTIAL, T_REMOV,
563 "SONY ", "SDT-5200 ", "3."}, PQUIRK_NOLUNS},
564 {{T_SEQUENTIAL, T_REMOV,
565 "TANDBERG", " TDC 3600 ", ""}, PQUIRK_NOLUNS},
566 /* Following entry reported as a Tandberg 3600; ref. PR1933 */
567 {{T_SEQUENTIAL, T_REMOV,
568 "ARCHIVE ", "VIPER 150 21247", ""}, PQUIRK_NOLUNS},
569 /* Following entry for a Cipher ST150S; ref. PR4171 */
570 {{T_SEQUENTIAL, T_REMOV,
571 "ARCHIVE ", "VIPER 1500 21247", "2.2G"}, PQUIRK_NOLUNS},
572 {{T_SEQUENTIAL, T_REMOV,
573 "ARCHIVE ", "Python 28454-XXX", ""}, PQUIRK_NOLUNS},
574 {{T_SEQUENTIAL, T_REMOV,
575 "WANGTEK ", "5099ES SCSI", ""}, PQUIRK_NOLUNS},
576 {{T_SEQUENTIAL, T_REMOV,
577 "WANGTEK ", "5150ES SCSI", ""}, PQUIRK_NOLUNS},
578 {{T_SEQUENTIAL, T_REMOV,
579 "WANGTEK ", "SCSI-36", ""}, PQUIRK_NOLUNS},
580 {{T_SEQUENTIAL, T_REMOV,
581 "WangDAT ", "Model 1300 ", "02.4"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
582 {{T_SEQUENTIAL, T_REMOV,
583 "WangDAT ", "Model 2600 ", "01.7"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
584 {{T_SEQUENTIAL, T_REMOV,
585 "WangDAT ", "Model 3200 ", "02.2"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
586
587 {{T_SCANNER, T_FIXED,
588 "RICOH ", "IS60 ", "1R08"}, PQUIRK_NOLUNS},
589 {{T_SCANNER, T_FIXED,
590 "UMAX ", "Astra 1200S ", "V2.9"}, PQUIRK_NOLUNS},
591 {{T_SCANNER, T_FIXED,
592 "UMAX ", "Astra 1220S ", ""}, PQUIRK_NOLUNS},
593 {{T_SCANNER, T_FIXED,
594 "UMAX ", "UMAX S-6E ", "V2.0"}, PQUIRK_NOLUNS},
595 {{T_SCANNER, T_FIXED,
596 "UMAX ", "UMAX S-12 ", "V2.1"}, PQUIRK_NOLUNS},
597
598 {{T_PROCESSOR, T_FIXED,
599 "LITRONIC", "PCMCIA ", ""}, PQUIRK_NOLUNS},
600
601 {{T_CHANGER, T_REMOV,
602 "SONY ", "CDL1100 ", ""}, PQUIRK_NOLUNS},
603
604 {{T_ENCLOSURE, T_FIXED,
605 "SUN ", "SENA ", "1.07"}, PQUIRK_NOLUNS},
606 };
607
608 /*
609 * given a target and lun, ask the device what
610 * it is, and find the correct driver table
611 * entry.
612 */
613 int
614 scsi_probe_device(sc, target, lun)
615 struct scsibus_softc *sc;
616 int target, lun;
617 {
618 struct scsipi_channel *chan = sc->sc_channel;
619 struct scsipi_periph *periph;
620 struct scsipi_inquiry_data inqbuf;
621 struct scsi_quirk_inquiry_pattern *finger;
622 int i, checkdtype, priority, docontinue, quirks;
623 struct scsipibus_attach_args sa;
624 struct cfdata *cf;
625
626 /*
627 * Assume no more luns to search after this one.
628 * If we successfully get Inquiry data and after
629 * merging quirks we find we can probe for more
630 * luns, we will.
631 */
632 docontinue = 0;
633
634 /* Skip this slot if it is already attached. */
635 if (chan->chan_periphs[target][lun] != NULL)
636 return (docontinue);
637
638 periph = malloc(sizeof(*periph), M_DEVBUF, M_WAITOK);
639 memset(periph, 0, sizeof(*periph));
640
641 periph->periph_dev = NULL;
642 periph->periph_channel = chan;
643 periph->periph_switch = &scsi_probe_dev;
644
645 /*
646 * Start with one command opening. The periph driver
647 * will grow this if it knows it can take advantage of it.
648 */
649 periph->periph_openings = 1;
650 periph->periph_active = 0;
651
652 periph->periph_target = target;
653 periph->periph_lun = lun;
654
655 for (i = 0; i < PERIPH_NTAGWORDS; i++)
656 periph->periph_freetags[i] = 0xffffffff;
657
658 TAILQ_INIT(&periph->periph_xferq);
659
660 #ifdef SCSIPI_DEBUG
661 if (SCSIPI_DEBUG_TYPE == SCSIPI_BUSTYPE_SCSI &&
662 SCSIPI_DEBUG_TARGET == target &&
663 SCSIPI_DEBUG_LUN == lun)
664 periph->periph_dbflags |= SCSIPI_DEBUG_FLAGS;
665 #endif
666
667 /*
668 * Ask the device what it is
669 */
670 (void) scsipi_test_unit_ready(periph,
671 XS_CTL_DISCOVERY | XS_CTL_IGNORE_ILLEGAL_REQUEST |
672 XS_CTL_IGNORE_NOT_READY | XS_CTL_IGNORE_MEDIA_CHANGE);
673
674 #ifdef SCSI_2_DEF
675 /* some devices need to be told to go to SCSI2 */
676 /* However some just explode if you tell them this.. leave it out */
677 scsi_change_def(periph, XS_CTL_DISCOVERY | XS_CTL_SILENT);
678 #endif /* SCSI_2_DEF */
679
680 /* Now go ask the device all about itself. */
681 memset(&inqbuf, 0, sizeof(inqbuf));
682 if (scsipi_inquire(periph, &inqbuf, XS_CTL_DISCOVERY) != 0)
683 goto bad;
684 {
685 int len = inqbuf.additional_length;
686 while (len < 3)
687 inqbuf.unused[len++] = '\0';
688 while (len < 3 + 28)
689 inqbuf.unused[len++] = ' ';
690 }
691
692 periph->periph_type = inqbuf.device & SID_TYPE;
693 if (inqbuf.dev_qual2 & SID_REMOVABLE)
694 periph->periph_flags |= PERIPH_REMOVABLE;
695 periph->periph_version = inqbuf.version & SID_ANSII;
696
697 /*
698 * Any device qualifier that has the top bit set (qualifier&4 != 0)
699 * is vendor specific and won't match in this switch.
700 * All we do here is throw out bad/negative responses.
701 */
702 checkdtype = 0;
703 switch (inqbuf.device & SID_QUAL) {
704 case SID_QUAL_LU_PRESENT:
705 case SID_QUAL_LU_NOTPRESENT:
706 checkdtype = 1;
707 break;
708
709 case SID_QUAL_reserved:
710 case SID_QUAL_LU_NOT_SUPP:
711 goto bad;
712
713 default:
714 break;
715 }
716 if (checkdtype) {
717 switch (periph->periph_type) {
718 case T_DIRECT:
719 case T_SEQUENTIAL:
720 case T_PRINTER:
721 case T_PROCESSOR:
722 case T_WORM:
723 case T_CDROM:
724 case T_SCANNER:
725 case T_OPTICAL:
726 case T_CHANGER:
727 case T_COMM:
728 case T_IT8_1:
729 case T_IT8_2:
730 case T_STORARRAY:
731 case T_ENCLOSURE:
732 default:
733 break;
734 case T_NODEVICE:
735 goto bad;
736 }
737 }
738
739 sa.sa_periph = periph;
740 sa.sa_inqbuf.type = inqbuf.device;
741 sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ?
742 T_REMOV : T_FIXED;
743 sa.sa_inqbuf.vendor = inqbuf.vendor;
744 sa.sa_inqbuf.product = inqbuf.product;
745 sa.sa_inqbuf.revision = inqbuf.revision;
746 sa.scsipi_info.scsi_version = inqbuf.version;
747
748 finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
749 &sa.sa_inqbuf, (caddr_t)scsi_quirk_patterns,
750 sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
751 sizeof(scsi_quirk_patterns[0]), &priority);
752
753 if (finger != NULL)
754 quirks = finger->quirks;
755 else
756 quirks = 0;
757
758 /*
759 * Determine the operating mode capabilities of the device.
760 */
761 if (periph->periph_version >= 2) {
762 if ((inqbuf.flags & SID_CmdQue) != 0 &&
763 (quirks & PQUIRK_NOTAG) == 0)
764 periph->periph_cap |= PERIPH_CAP_TQING;
765 if ((inqbuf.flags & SID_Linked) != 0)
766 periph->periph_cap |= PERIPH_CAP_LINKCMDS;
767 if ((inqbuf.flags & SID_Sync) != 0 &&
768 (quirks & PQUIRK_NOSYNC) == 0)
769 periph->periph_cap |= PERIPH_CAP_SYNC;
770 if ((inqbuf.flags & SID_WBus16) != 0 &&
771 (quirks & PQUIRK_NOWIDE) == 0)
772 periph->periph_cap |= PERIPH_CAP_WIDE16;
773 if ((inqbuf.flags & SID_WBus32) != 0 &&
774 (quirks & PQUIRK_NOWIDE) == 0)
775 periph->periph_cap |= PERIPH_CAP_WIDE32;
776 if ((inqbuf.flags & SID_SftRe) != 0)
777 periph->periph_cap |= PERIPH_CAP_SFTRESET;
778 if ((inqbuf.flags & SID_RelAdr) != 0)
779 periph->periph_cap |= PERIPH_CAP_RELADR;
780 }
781
782 /*
783 * Now apply any quirks from the table.
784 */
785 periph->periph_quirks |= quirks;
786 if (periph->periph_version == 0 &&
787 (periph->periph_quirks & PQUIRK_FORCELUNS) == 0)
788 periph->periph_quirks |= PQUIRK_NOLUNS;
789
790 if ((periph->periph_quirks & PQUIRK_NOLUNS) == 0)
791 docontinue = 1;
792
793 if ((cf = config_search(scsibussubmatch, &sc->sc_dev, &sa)) != NULL) {
794 chan->chan_periphs[target][lun] = periph;
795 /*
796 * XXX Can't assign periph_dev here, because we'll
797 * XXX need it before config_attach() returns. Must
798 * XXX assign it in periph driver.
799 */
800 (void) config_attach(&sc->sc_dev, cf, &sa, scsibusprint);
801 } else {
802 scsibusprint(&sa, sc->sc_dev.dv_xname);
803 printf(" not configured\n");
804 goto bad;
805 }
806
807 return (docontinue);
808
809 bad:
810 free(periph, M_DEVBUF);
811 return (docontinue);
812 }
813
814 /****** Entry points for user control of the SCSI bus. ******/
815
816 int
817 scsibusopen(dev, flag, fmt, p)
818 dev_t dev;
819 int flag, fmt;
820 struct proc *p;
821 {
822 struct scsibus_softc *sc;
823 int error, unit = minor(dev);
824
825 if (unit >= scsibus_cd.cd_ndevs ||
826 (sc = scsibus_cd.cd_devs[unit]) == NULL)
827 return (ENXIO);
828
829 if (sc->sc_flags & SCSIBUSF_OPEN)
830 return (EBUSY);
831
832 if ((error = scsipi_adapter_addref(sc->sc_channel->chan_adapter)) != 0)
833 return (error);
834
835 sc->sc_flags |= SCSIBUSF_OPEN;
836
837 return (0);
838 }
839
840 int
841 scsibusclose(dev, flag, fmt, p)
842 dev_t dev;
843 int flag, fmt;
844 struct proc *p;
845 {
846 struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
847
848 scsipi_adapter_delref(sc->sc_channel->chan_adapter);
849
850 sc->sc_flags &= ~SCSIBUSF_OPEN;
851
852 return (0);
853 }
854
855 int
856 scsibusioctl(dev, cmd, addr, flag, p)
857 dev_t dev;
858 u_long cmd;
859 caddr_t addr;
860 int flag;
861 struct proc *p;
862 {
863 struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
864 struct scsipi_channel *chan = sc->sc_channel;
865 int error;
866
867 /*
868 * Enforce write permission for ioctls that change the
869 * state of the bus. Host adapter specific ioctls must
870 * be checked by the adapter driver.
871 */
872 switch (cmd) {
873 case SCBUSIOSCAN:
874 case SCBUSIORESET:
875 if ((flag & FWRITE) == 0)
876 return (EBADF);
877 }
878
879 switch (cmd) {
880 case SCBUSIOSCAN:
881 {
882 struct scbusioscan_args *a =
883 (struct scbusioscan_args *)addr;
884
885 error = scsi_probe_bus(sc, a->sa_target, a->sa_lun);
886 break;
887 }
888
889 case SCBUSIORESET:
890 /* FALLTHROUGH */
891 default:
892 if (chan->chan_adapter->adapt_ioctl == NULL)
893 error = ENOTTY;
894 else
895 error = (*chan->chan_adapter->adapt_ioctl)(chan,
896 cmd, addr, flag, p);
897 break;
898 }
899
900 return (error);
901 }
902