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