Annotation of src/sys/dev/scsipi/scsiconf.c, Revision 1.156.2.8
1.156.2.8! nathanw 1: /* $NetBSD: scsiconf.c,v 1.156.2.7 2002/01/08 00:31:49 nathanw Exp $ */
1.14 cgd 2:
1.106 mycroft 3: /*-
1.156.2.2 nathanw 4: * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
1.106 mycroft 5: * All rights reserved.
6: *
7: * This code is derived from software contributed to The NetBSD Foundation
1.111 thorpej 8: * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace
9: * Simulation Facility, NASA Ames Research Center.
1.12 mycroft 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:
1.106 mycroft 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.
1.12 mycroft 26: *
1.106 mycroft 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.
1.12 mycroft 38: */
39:
40: /*
41: * Originally written by Julian Elischer (julian@tfs.com)
1.5 deraadt 42: * for TRW Financial Systems for use under the MACH(2.5) operating system.
1.1 cgd 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.
1.7 cgd 53: *
1.12 mycroft 54: * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
1.1 cgd 55: */
56:
1.156.2.6 nathanw 57: #include <sys/cdefs.h>
1.156.2.8! nathanw 58: __KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.156.2.7 2002/01/08 00:31:49 nathanw Exp $");
1.156.2.6 nathanw 59:
1.10 mycroft 60: #include <sys/param.h>
61: #include <sys/systm.h>
1.128 thorpej 62: #include <sys/kernel.h>
1.156.2.1 nathanw 63: #include <sys/lwp.h>
1.128 thorpej 64: #include <sys/proc.h>
1.156.2.2 nathanw 65: #include <sys/kthread.h>
1.12 mycroft 66: #include <sys/malloc.h>
67: #include <sys/device.h>
1.111 thorpej 68: #include <sys/conf.h>
1.113 thorpej 69: #include <sys/fcntl.h>
1.112 thorpej 70: #include <sys/scsiio.h>
1.10 mycroft 71:
1.88 bouyer 72: #include <dev/scsipi/scsi_all.h>
73: #include <dev/scsipi/scsipi_all.h>
74: #include <dev/scsipi/scsiconf.h>
1.92 enami 75:
1.88 bouyer 76: #include "locators.h"
1.1 cgd 77:
1.156.2.2 nathanw 78: const struct scsipi_periphsw scsi_probe_dev = {
1.12 mycroft 79: NULL,
80: NULL,
81: NULL,
82: NULL,
83: };
84:
1.156.2.2 nathanw 85: int scsi_probe_device __P((struct scsibus_softc *, int, int));
86:
87: int scsibusmatch __P((struct device *, struct cfdata *, void *));
88: void scsibusattach __P((struct device *, struct device *, void *));
89: int scsibusactivate __P((struct device *, enum devact));
90: int scsibusdetach __P((struct device *, int flags));
1.126 thorpej 91:
1.156.2.2 nathanw 92: int scsibussubmatch __P((struct device *, struct cfdata *, void *));
1.12 mycroft 93:
1.53 thorpej 94: struct cfattach scsibus_ca = {
1.126 thorpej 95: sizeof(struct scsibus_softc), scsibusmatch, scsibusattach,
96: scsibusdetach, scsibusactivate,
1.53 thorpej 97: };
98:
1.94 thorpej 99: extern struct cfdriver scsibus_cd;
1.12 mycroft 100:
1.156.2.2 nathanw 101: int scsibusprint __P((void *, const char *));
102: void scsibus_config_interrupts __P((struct device *));
1.51 thorpej 103:
1.111 thorpej 104: cdev_decl(scsibus);
1.62 cgd 105:
1.156.2.2 nathanw 106: const struct scsipi_bustype scsi_bustype = {
107: SCSIPI_BUSTYPE_SCSI,
108: scsi_scsipi_cmd,
109: scsipi_interpret_sense,
110: scsi_print_addr,
111: scsi_kill_pending,
112: };
113:
114: int
115: scsiprint(aux, pnp)
116: void *aux;
117: const char *pnp;
118: {
119: struct scsipi_channel *chan = aux;
120: struct scsipi_adapter *adapt = chan->chan_adapter;
121:
122: /* only "scsibus"es can attach to "scsi"s; easy. */
123: if (pnp)
124: printf("scsibus at %s", pnp);
125:
126: /* don't print channel if the controller says there can be only one. */
127: if (adapt->adapt_nchannels != 1)
128: printf(" channel %d", chan->chan_channel);
129:
130: return (UNCONF);
131: }
132:
1.62 cgd 133: int
1.71 cgd 134: scsibusmatch(parent, cf, aux)
1.62 cgd 135: struct device *parent;
1.71 cgd 136: struct cfdata *cf;
137: void *aux;
1.12 mycroft 138: {
1.156.2.2 nathanw 139: struct scsipi_channel *chan = aux;
1.62 cgd 140:
1.156.2.7 nathanw 141: if (chan->chan_bustype->bustype_type != SCSIPI_BUSTYPE_SCSI)
1.156.2.2 nathanw 142: return 0;
1.62 cgd 143:
1.156.2.2 nathanw 144: if (cf->cf_loc[SCSICF_CHANNEL] != chan->chan_channel &&
1.92 enami 145: cf->cf_loc[SCSICF_CHANNEL] != SCSICF_CHANNEL_DEFAULT)
1.62 cgd 146: return (0);
1.12 mycroft 147:
1.62 cgd 148: return (1);
1.12 mycroft 149: }
150:
151: void
152: scsibusattach(parent, self, aux)
1.88 bouyer 153: struct device *parent, *self;
154: void *aux;
1.12 mycroft 155: {
1.156.2.2 nathanw 156: struct scsibus_softc *sc = (void *) self;
157: struct scsipi_channel *chan = aux;
1.103 thorpej 158:
1.156.2.2 nathanw 159: sc->sc_channel = chan;
1.72 thorpej 160:
1.156.2.2 nathanw 161: /* Initialize the channel structure first */
162: if (scsipi_channel_init(chan)) {
163: printf(": failed to init channel\n");
164: return;
1.72 thorpej 165: }
1.12 mycroft 166:
1.156.2.2 nathanw 167: printf(": %d targets, %d luns per target\n",
168: chan->chan_ntargets, chan->chan_nluns);
169:
170:
1.128 thorpej 171: /*
172: * Defer configuration of the children until interrupts
173: * are enabled.
174: */
175: config_interrupts(self, scsibus_config_interrupts);
176: }
177:
178: void
179: scsibus_config_interrupts(self)
180: struct device *self;
181: {
1.156.2.2 nathanw 182: struct scsibus_softc *sc = (void *) self;
183:
1.132 soren 184: #ifndef SCSI_DELAY
1.12 mycroft 185: #define SCSI_DELAY 2
1.132 soren 186: #endif
1.156.2.2 nathanw 187:
188: if ((sc->sc_channel->chan_flags & SCSIPI_CHAN_NOSETTLE) == 0 &&
189: SCSI_DELAY > 0) {
1.128 thorpej 190: printf("%s: waiting %d seconds for devices to settle...\n",
191: self->dv_xname, SCSI_DELAY);
192: /* ...an identifier we know no one will use... */
193: (void) tsleep(scsibus_config_interrupts, PRIBIO,
194: "scsidly", SCSI_DELAY * hz);
195: }
196:
1.156.2.2 nathanw 197: scsi_probe_bus(sc, -1, -1);
1.12 mycroft 198: }
199:
1.18 mycroft 200: int
1.71 cgd 201: scsibussubmatch(parent, cf, aux)
1.18 mycroft 202: struct device *parent;
1.71 cgd 203: struct cfdata *cf;
204: void *aux;
1.18 mycroft 205: {
1.88 bouyer 206: struct scsipibus_attach_args *sa = aux;
1.156.2.2 nathanw 207: struct scsipi_periph *periph = sa->sa_periph;
1.18 mycroft 208:
1.88 bouyer 209: if (cf->cf_loc[SCSIBUSCF_TARGET] != SCSIBUSCF_TARGET_DEFAULT &&
1.156.2.2 nathanw 210: cf->cf_loc[SCSIBUSCF_TARGET] != periph->periph_target)
1.92 enami 211: return (0);
1.88 bouyer 212: if (cf->cf_loc[SCSIBUSCF_LUN] != SCSIBUSCF_LUN_DEFAULT &&
1.156.2.2 nathanw 213: cf->cf_loc[SCSIBUSCF_LUN] != periph->periph_lun)
1.92 enami 214: return (0);
1.71 cgd 215: return ((*cf->cf_attach->ca_match)(parent, cf, aux));
1.126 thorpej 216: }
217:
218: int
219: scsibusactivate(self, act)
220: struct device *self;
221: enum devact act;
222: {
1.156.2.2 nathanw 223: struct scsibus_softc *sc = (void *) self;
224: struct scsipi_channel *chan = sc->sc_channel;
225: struct scsipi_periph *periph;
1.126 thorpej 226: int target, lun, error = 0, s;
227:
228: s = splbio();
229: switch (act) {
230: case DVACT_ACTIVATE:
231: error = EOPNOTSUPP;
232: break;
233:
234: case DVACT_DEACTIVATE:
1.156.2.2 nathanw 235: for (target = 0; target < chan->chan_ntargets;
236: target++) {
237: if (target == chan->chan_id)
1.126 thorpej 238: continue;
1.156.2.2 nathanw 239: for (lun = 0; lun < chan->chan_nluns; lun++) {
240: periph = scsipi_lookup_periph(chan,
241: target, lun);
242: if (periph == NULL)
1.126 thorpej 243: continue;
1.156.2.2 nathanw 244: error = config_deactivate(periph->periph_dev);
1.126 thorpej 245: if (error)
246: goto out;
247: }
248: }
249: break;
250: }
251: out:
252: splx(s);
253: return (error);
254: }
255:
256: int
257: scsibusdetach(self, flags)
258: struct device *self;
259: int flags;
260: {
1.156.2.2 nathanw 261: struct scsibus_softc *sc = (void *) self;
262: struct scsipi_channel *chan = sc->sc_channel;
1.126 thorpej 263:
1.156.2.2 nathanw 264: /*
265: * Shut down the channel.
266: */
267: scsipi_channel_shutdown(chan);
268:
269: /*
270: * Now detach all of the periphs.
271: */
1.156.2.3 nathanw 272: return scsipi_target_detach(chan, -1, -1, flags);
1.18 mycroft 273: }
274:
1.12 mycroft 275: /*
276: * Probe the requested scsi bus. It must be already set up.
1.18 mycroft 277: * target and lun optionally narrow the search if not -1
1.12 mycroft 278: */
279: int
1.156.2.2 nathanw 280: scsi_probe_bus(sc, target, lun)
281: struct scsibus_softc *sc;
282: int target, lun;
1.12 mycroft 283: {
1.156.2.2 nathanw 284: struct scsipi_channel *chan = sc->sc_channel;
1.18 mycroft 285: int maxtarget, mintarget, maxlun, minlun;
1.116 thorpej 286: int error;
1.12 mycroft 287:
1.18 mycroft 288: if (target == -1) {
1.156.2.2 nathanw 289: maxtarget = chan->chan_ntargets - 1;
1.18 mycroft 290: mintarget = 0;
1.12 mycroft 291: } else {
1.156.2.2 nathanw 292: if (target < 0 || target >= chan->chan_ntargets)
1.92 enami 293: return (EINVAL);
1.18 mycroft 294: maxtarget = mintarget = target;
1.12 mycroft 295: }
1.1 cgd 296:
1.12 mycroft 297: if (lun == -1) {
1.156.2.2 nathanw 298: maxlun = chan->chan_nluns - 1;
1.12 mycroft 299: minlun = 0;
300: } else {
1.156.2.2 nathanw 301: if (lun < 0 || lun >= chan->chan_nluns)
1.92 enami 302: return (EINVAL);
1.12 mycroft 303: maxlun = minlun = lun;
304: }
305:
1.153 ad 306: /*
307: * Some HBAs provide an abstracted view of the bus; give them an
308: * oppertunity to re-scan it before we do.
309: */
1.156.2.2 nathanw 310: if (chan->chan_adapter->adapt_ioctl != NULL)
311: (*chan->chan_adapter->adapt_ioctl)(chan, SCBUSIOLLSCAN, NULL,
1.156.2.1 nathanw 312: 0, curproc->l_proc);
1.153 ad 313:
1.156.2.2 nathanw 314: if ((error = scsipi_adapter_addref(chan->chan_adapter)) != 0)
1.116 thorpej 315: return (error);
1.18 mycroft 316: for (target = mintarget; target <= maxtarget; target++) {
1.156.2.2 nathanw 317: if (target == chan->chan_id)
1.12 mycroft 318: continue;
319: for (lun = minlun; lun <= maxlun; lun++) {
320: /*
1.18 mycroft 321: * See if there's a device present, and configure it.
1.12 mycroft 322: */
1.156.2.2 nathanw 323: if (scsi_probe_device(sc, target, lun) == 0)
1.18 mycroft 324: break;
1.12 mycroft 325: /* otherwise something says we should look further */
326: }
1.156.2.2 nathanw 327:
328: /*
329: * Now that we've discovered all of the LUNs on this
330: * I_T Nexus, update the xfer mode for all of them
331: * that we know about.
332: */
333: scsipi_set_xfer_mode(chan, target, 1);
1.8 deraadt 334: }
1.156.2.2 nathanw 335: scsipi_adapter_delref(chan->chan_adapter);
1.92 enami 336: return (0);
1.12 mycroft 337: }
338:
1.88 bouyer 339: /*
340: * Print out autoconfiguration information for a subdevice.
341: *
342: * This is a slight abuse of 'standard' autoconfiguration semantics,
343: * because 'print' functions don't normally print the colon and
344: * device information. However, in this case that's better than
345: * either printing redundant information before the attach message,
346: * or having the device driver call a special function to print out
347: * the standard device information.
348: */
349: int
350: scsibusprint(aux, pnp)
351: void *aux;
352: const char *pnp;
1.12 mycroft 353: {
1.88 bouyer 354: struct scsipibus_attach_args *sa = aux;
355: struct scsipi_inquiry_pattern *inqbuf;
356: u_int8_t type;
1.156.2.2 nathanw 357: const char *dtype, *qtype;
1.88 bouyer 358: char vendor[33], product[65], revision[17];
359: int target, lun;
360:
361: if (pnp != NULL)
362: printf("%s", pnp);
363:
364: inqbuf = &sa->sa_inqbuf;
365:
1.156.2.2 nathanw 366: target = sa->sa_periph->periph_target;
367: lun = sa->sa_periph->periph_lun;
1.88 bouyer 368: type = inqbuf->type & SID_TYPE;
369:
370: /*
371: * Figure out basic device type and qualifier.
372: */
373: dtype = 0;
374: switch (inqbuf->type & SID_QUAL) {
1.156.2.2 nathanw 375: case SID_QUAL_LU_PRESENT:
1.88 bouyer 376: qtype = "";
377: break;
378:
1.156.2.2 nathanw 379: case SID_QUAL_LU_NOTPRESENT:
1.88 bouyer 380: qtype = " offline";
381: break;
382:
1.156.2.2 nathanw 383: case SID_QUAL_reserved:
384: case SID_QUAL_LU_NOT_SUPP:
1.88 bouyer 385: panic("scsibusprint: impossible qualifier");
1.12 mycroft 386:
1.88 bouyer 387: default:
388: qtype = "";
389: dtype = "vendor-unique";
390: break;
391: }
1.156.2.2 nathanw 392: if (dtype == NULL)
1.88 bouyer 393: dtype = scsipi_dtype(type);
1.2 deraadt 394:
1.104 drochner 395: scsipi_strvis(vendor, 33, inqbuf->vendor, 8);
396: scsipi_strvis(product, 65, inqbuf->product, 16);
397: scsipi_strvis(revision, 17, inqbuf->revision, 4);
1.88 bouyer 398:
1.138 augustss 399: printf(" target %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s",
1.92 enami 400: target, lun, vendor, product, revision,
401: sa->scsipi_info.scsi_version & SID_ANSII, type, dtype,
402: inqbuf->removable ? "removable" : "fixed", qtype);
1.88 bouyer 403:
404: return (UNCONF);
1.12 mycroft 405: }
1.1 cgd 406:
1.154 jdolecek 407: const struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
1.48 christos 408: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 409: "CHINON ", "CD-ROM CDS-431 ", ""}, PQUIRK_NOLUNS},
1.48 christos 410: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 411: "Chinon ", "CD-ROM CDS-525 ", ""}, PQUIRK_NOLUNS},
1.48 christos 412: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 413: "CHINON ", "CD-ROM CDS-535 ", ""}, PQUIRK_NOLUNS},
1.100 thorpej 414: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 415: "DEC ", "RRD42 (C) DEC ", ""}, PQUIRK_NOLUNS},
1.48 christos 416: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 417: "DENON ", "DRD-25X ", "V"}, PQUIRK_NOLUNS},
1.148 bouyer 418: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 419: "GENERIC ", "CRD-BP2 ", ""}, PQUIRK_NOLUNS},
1.83 mycroft 420: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 421: "HP ", "C4324/C4325 ", ""}, PQUIRK_NOLUNS},
1.48 christos 422: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 423: "IMS ", "CDD521/10 ", "2.06"}, PQUIRK_NOLUNS},
1.48 christos 424: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 425: "MATSHITA", "CD-ROM CR-5XX ", "1.0b"}, PQUIRK_NOLUNS},
1.68 mikel 426: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 427: "MEDAVIS ", "RENO CD-ROMX2A ", ""}, PQUIRK_NOLUNS},
1.84 perry 428: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 429: "MEDIAVIS", "CDR-H93MV ", "1.3"}, PQUIRK_NOLUNS},
1.48 christos 430: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 431: "NEC ", "CD-ROM DRIVE:55 ", ""}, PQUIRK_NOLUNS},
1.48 christos 432: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 433: "NEC ", "CD-ROM DRIVE:83 ", ""}, PQUIRK_NOLUNS},
1.48 christos 434: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 435: "NEC ", "CD-ROM DRIVE:84 ", ""}, PQUIRK_NOLUNS},
1.48 christos 436: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 437: "NEC ", "CD-ROM DRIVE:841", ""}, PQUIRK_NOLUNS},
1.70 thorpej 438: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 439: "PIONEER ", "CD-ROM DR-124X ", "1.01"}, PQUIRK_NOLUNS},
1.48 christos 440: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 441: "SONY ", "CD-ROM CDU-541 ", ""}, PQUIRK_NOLUNS},
1.48 christos 442: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 443: "SONY ", "CD-ROM CDU-55S ", ""}, PQUIRK_NOLUNS},
1.130 hwr 444: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 445: "SONY ", "CD-ROM CDU-561 ", ""}, PQUIRK_NOLUNS},
1.48 christos 446: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 447: "SONY ", "CD-ROM CDU-8003A", ""}, PQUIRK_NOLUNS},
1.48 christos 448: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 449: "SONY ", "CD-ROM CDU-8012 ", ""}, PQUIRK_NOLUNS},
1.48 christos 450: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 451: "TEAC ", "CD-ROM ", "1.06"}, PQUIRK_NOLUNS},
1.69 explorer 452: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 453: "TEAC ", "CD-ROM CD-56S ", "1.0B"}, PQUIRK_NOLUNS},
1.48 christos 454: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 455: "TEXEL ", "CD-ROM ", "1.06"}, PQUIRK_NOLUNS},
1.127 nathanw 456: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 457: "TEXEL ", "CD-ROM DM-XX24 K", "1.09"}, PQUIRK_NOLUNS},
1.48 christos 458: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 459: "TEXEL ", "CD-ROM DM-XX24 K", "1.10"}, PQUIRK_NOLUNS},
1.89 pk 460: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 461: "TOSHIBA ", "XM-4101TASUNSLCD", "1755"}, PQUIRK_NOLUNS|PQUIRK_NOSYNC},
462: /* "IBM CDRM00201 !F" 0724 is an IBM OEM Toshiba XM-4101BME */
1.92 enami 463: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 464: "IBM ", "CDRM00201 !F", "0724"}, PQUIRK_NOLUNS|PQUIRK_NOSYNC},
1.98 explorer 465: {{T_CDROM, T_REMOV,
1.156.2.7 nathanw 466: "ShinaKen", "CD-ROM DM-3x1S", "1.04"}, PQUIRK_NOLUNS},
1.137 sjg 467: {{T_CDROM, T_REMOV,
1.156.2.2 nathanw 468: "JVC ", "R2626", ""}, PQUIRK_NOLUNS},
469: {{T_CDROM, T_REMOV,
470: "YAMAHA", "CRW8424S", ""}, PQUIRK_NOLUNS},
1.156 fvdl 471: {{T_CDROM, T_REMOV,
1.156.2.7 nathanw 472: "VMware", "Virtual", "1.0"},
1.156.2.2 nathanw 473: PQUIRK_NOSTARTUNIT|PQUIRK_NODOORLOCK},
1.156 fvdl 474:
1.80 pk 475: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 476: "MICROP ", "1588-15MBSUN0669", ""}, PQUIRK_AUTOSAVE},
1.110 thorpej 477: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 478: "MICROP ", "2217-15MQ1091501", ""}, PQUIRK_NOSYNCCACHE},
1.55 scottr 479: {{T_OPTICAL, T_REMOV,
1.156.2.2 nathanw 480: "EPSON ", "OMD-5010 ", "3.08"}, PQUIRK_NOLUNS},
1.129 hwr 481: {{T_DIRECT, T_FIXED,
1.156.2.7 nathanw 482: "TOSHIBA ","CD-ROM XM-3401TA", "0283"}, PQUIRK_CDROM|PQUIRK_NOLUNS},
1.122 mjacob 483: {{T_DIRECT, T_FIXED,
1.156.2.7 nathanw 484: "TOSHIBA ", "CD-ROM DRIVE:XM", "1971"}, PQUIRK_CDROM|PQUIRK_NOLUNS},
1.143 gmcgarry 485: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 486: "ADAPTEC ", "AEC-4412BD", "1.2A"}, PQUIRK_NOMODESENSE},
1.50 mycroft 487: {{T_DIRECT, T_FIXED,
1.156.2.7 nathanw 488: "ADAPTEC ", "ACB-4000", ""}, PQUIRK_FORCELUNS|PQUIRK_AUTOSAVE|PQUIRK_NOMODESENSE},
489: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 490: "DEC ", "RZ55 (C) DEC", ""}, PQUIRK_AUTOSAVE},
1.48 christos 491: {{T_DIRECT, T_FIXED,
1.156.2.7 nathanw 492: "EMULEX ", "MD21/S2 ESDI", "A00"},
493: PQUIRK_FORCELUNS|PQUIRK_AUTOSAVE},
1.91 bouyer 494: /* Gives non-media hardware failure in response to start-unit command */
495: {{T_DIRECT, T_FIXED,
1.156.2.7 nathanw 496: "HITACHI", "DK515C", "CP16"}, PQUIRK_NOSTARTUNIT},
1.91 bouyer 497: {{T_DIRECT, T_FIXED,
1.156.2.7 nathanw 498: "HITACHI", "DK515C", "CP15"}, PQUIRK_NOSTARTUNIT},
1.76 scottr 499: {{T_DIRECT, T_FIXED,
1.156.2.7 nathanw 500: "MICROP", "1548-15MZ1077801", "HZ2P"}, PQUIRK_NOTAG},
1.156.2.5 nathanw 501: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 502: "HP ", "C372", ""}, PQUIRK_NOTAG},
1.108 mjacob 503: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 504: "IBMRAID ", "0662S", ""}, PQUIRK_AUTOSAVE},
1.76 scottr 505: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 506: "IBM ", "0663H", ""}, PQUIRK_AUTOSAVE},
1.82 thorpej 507: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 508: "IBM", "0664", ""}, PQUIRK_AUTOSAVE},
1.84 perry 509: {{T_DIRECT, T_FIXED,
1.156.2.7 nathanw 510: "IBM ", "H3171-S2", ""},
511: PQUIRK_NOLUNS|PQUIRK_AUTOSAVE},
1.96 scottr 512: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 513: "IBM ", "KZ-C", ""}, PQUIRK_AUTOSAVE},
1.81 thorpej 514: /* Broken IBM disk */
515: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 516: "" , "DFRSS2F", ""}, PQUIRK_AUTOSAVE},
1.87 mjacob 517: {{T_DIRECT, T_REMOV,
1.156.2.2 nathanw 518: "MPL ", "MC-DISK- ", ""}, PQUIRK_NOLUNS},
1.48 christos 519: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 520: "MAXTOR ", "XT-3280 ", ""}, PQUIRK_NOLUNS},
1.48 christos 521: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 522: "MAXTOR ", "XT-4380S ", ""}, PQUIRK_NOLUNS},
1.48 christos 523: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 524: "MAXTOR ", "MXT-1240S ", ""}, PQUIRK_NOLUNS},
1.48 christos 525: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 526: "MAXTOR ", "XT-4170S ", ""}, PQUIRK_NOLUNS},
1.48 christos 527: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 528: "MAXTOR ", "XT-8760S", ""}, PQUIRK_NOLUNS},
1.48 christos 529: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 530: "MAXTOR ", "LXT-213S ", ""}, PQUIRK_NOLUNS},
1.48 christos 531: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 532: "MAXTOR ", "LXT-213S SUN0207", ""}, PQUIRK_NOLUNS},
1.52 thorpej 533: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 534: "MAXTOR ", "LXT-200S ", ""}, PQUIRK_NOLUNS},
1.48 christos 535: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 536: "MEGADRV ", "EV1000", ""}, PQUIRK_NOMODESENSE},
1.90 mjacob 537: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 538: "MST ", "SnapLink ", ""}, PQUIRK_NOLUNS},
1.54 hpeyerl 539: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 540: "NEC ", "D3847 ", "0307"}, PQUIRK_NOLUNS},
1.96 scottr 541: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 542: "QUANTUM ", "ELS85S ", ""}, PQUIRK_AUTOSAVE},
1.48 christos 543: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 544: "QUANTUM ", "LPS525S ", ""}, PQUIRK_NOLUNS},
1.48 christos 545: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 546: "QUANTUM ", "P105S 910-10-94x", ""}, PQUIRK_NOLUNS},
1.48 christos 547: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 548: "QUANTUM ", "PD1225S ", ""}, PQUIRK_NOLUNS},
1.48 christos 549: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 550: "QUANTUM ", "PD210S SUN0207", ""}, PQUIRK_NOLUNS},
1.48 christos 551: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 552: "RODIME ", "RO3000S ", ""}, PQUIRK_NOLUNS},
1.75 scottr 553: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 554: "SEAGATE ", "ST125N ", ""}, PQUIRK_NOLUNS},
1.48 christos 555: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 556: "SEAGATE ", "ST157N ", ""}, PQUIRK_NOLUNS},
1.48 christos 557: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 558: "SEAGATE ", "ST296 ", ""}, PQUIRK_NOLUNS},
1.48 christos 559: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 560: "SEAGATE ", "ST296N ", ""}, PQUIRK_NOLUNS},
1.156.2.8! nathanw 561: {{T_DIRECT, T_FIXED,
! 562: "SEAGATE ", "ST11200N SUN1.05", ""}, PQUIRK_NOTAG},
1.156.2.5 nathanw 563: {{T_DIRECT, T_FIXED,
564: "SEAGATE ", "ST15150N ", ""}, PQUIRK_NOTAG},
1.86 mjacob 565: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 566: "SEAGATE ", "ST19171", ""}, PQUIRK_NOMODESENSE},
1.90 mjacob 567: {{T_DIRECT, T_FIXED,
1.156.2.7 nathanw 568: "SEAGATE ", "ST32430N", ""}, PQUIRK_CAP_SYNC},
569: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 570: "SEAGATE ", "ST34501FC ", ""}, PQUIRK_NOMODESENSE},
1.48 christos 571: {{T_DIRECT, T_FIXED,
1.156.2.2 nathanw 572: "TOSHIBA ", "MK538FB ", "6027"}, PQUIRK_NOLUNS},
1.156 fvdl 573: {{T_DIRECT, T_FIXED,
574: "VMware", "Virtual", "1.0"},
1.156.2.2 nathanw 575: PQUIRK_NOSTARTUNIT|PQUIRK_NODOORLOCK},
1.156.2.7 nathanw 576: {{T_DIRECT, T_FIXED, /* XXX move to umass */
577: "Maxtor 4", "D080H4", "DAH0"}, PQUIRK_NOMODESENSE},
1.156 fvdl 578:
1.58 christos 579: {{T_DIRECT, T_REMOV,
1.156.2.2 nathanw 580: "iomega", "jaz 1GB", ""}, PQUIRK_NOMODESENSE},
1.59 explorer 581: {{T_DIRECT, T_REMOV,
1.156.2.2 nathanw 582: "IOMEGA", "ZIP 100", ""}, PQUIRK_NOMODESENSE},
1.118 leo 583: {{T_DIRECT, T_REMOV,
1.156.2.7 nathanw 584: "IOMEGA", "ZIP 100", "J.03"},
585: PQUIRK_NOMODESENSE|PQUIRK_NOLUNS},
1.85 explorer 586: /* Letting the motor run kills floppy drives and disks quite fast. */
1.67 matthias 587: {{T_DIRECT, T_REMOV,
1.156.2.2 nathanw 588: "TEAC", "FC-1", ""}, PQUIRK_NOSTARTUNIT},
1.145 augustss 589: {{T_DIRECT, T_REMOV,
1.156.2.7 nathanw 590: "INSITE", "I325VM", ""},
591: PQUIRK_NOLUNS|PQUIRK_NODOORLOCK},
1.18 mycroft 592:
1.37 cgd 593: /* XXX: QIC-36 tape behind Emulex adapter. Very broken. */
1.48 christos 594: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 595: " ", " ", " "}, PQUIRK_NOLUNS},
1.48 christos 596: {{T_SEQUENTIAL, T_REMOV,
1.156.2.7 nathanw 597: "EMULEX ", "MT-02 QIC ", ""}, PQUIRK_NOLUNS},
598: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 599: "CALIPER ", "CP150 ", ""}, PQUIRK_NOLUNS},
1.48 christos 600: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 601: "EXABYTE ", "EXB-8200 ", ""}, PQUIRK_NOLUNS},
1.48 christos 602: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 603: "SONY ", "GY-10C ", ""}, PQUIRK_NOLUNS},
1.87 mjacob 604: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 605: "SONY ", "SDT-2000 ", "2.09"}, PQUIRK_NOLUNS},
1.48 christos 606: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 607: "SONY ", "SDT-5000 ", "3."}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
1.48 christos 608: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 609: "SONY ", "SDT-5200 ", "3."}, PQUIRK_NOLUNS},
1.48 christos 610: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 611: "TANDBERG", " TDC 3600 ", ""}, PQUIRK_NOLUNS},
1.47 pk 612: /* Following entry reported as a Tandberg 3600; ref. PR1933 */
1.48 christos 613: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 614: "ARCHIVE ", "VIPER 150 21247", ""}, PQUIRK_NOLUNS},
1.91 bouyer 615: /* Following entry for a Cipher ST150S; ref. PR4171 */
616: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 617: "ARCHIVE ", "VIPER 1500 21247", "2.2G"}, PQUIRK_NOLUNS},
1.80 pk 618: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 619: "ARCHIVE ", "Python 28454-XXX", ""}, PQUIRK_NOLUNS},
1.48 christos 620: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 621: "WANGTEK ", "5099ES SCSI", ""}, PQUIRK_NOLUNS},
1.48 christos 622: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 623: "WANGTEK ", "5150ES SCSI", ""}, PQUIRK_NOLUNS},
1.125 hwr 624: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 625: "WANGTEK ", "SCSI-36", ""}, PQUIRK_NOLUNS},
1.48 christos 626: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 627: "WangDAT ", "Model 1300 ", "02.4"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
1.48 christos 628: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 629: "WangDAT ", "Model 2600 ", "01.7"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
1.48 christos 630: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 631: "WangDAT ", "Model 3200 ", "02.2"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
1.133 nisimura 632: {{T_SEQUENTIAL, T_REMOV,
1.156.2.2 nathanw 633: "TEAC ", "MT-2ST/N50 ", ""}, PQUIRK_NOLUNS},
1.87 mjacob 634:
1.101 bouyer 635: {{T_SCANNER, T_FIXED,
1.156.2.2 nathanw 636: "RICOH ", "IS60 ", "1R08"}, PQUIRK_NOLUNS},
1.99 thorpej 637: {{T_SCANNER, T_FIXED,
1.156.2.2 nathanw 638: "UMAX ", "Astra 1200S ", "V2.9"}, PQUIRK_NOLUNS},
1.102 fvdl 639: {{T_SCANNER, T_FIXED,
1.156.2.2 nathanw 640: "UMAX ", "Astra 1220S ", ""}, PQUIRK_NOLUNS},
1.85 explorer 641: {{T_SCANNER, T_FIXED,
1.156.2.2 nathanw 642: "UMAX ", "UMAX S-6E ", "V2.0"}, PQUIRK_NOLUNS},
1.95 mikel 643: {{T_SCANNER, T_FIXED,
1.156.2.2 nathanw 644: "UMAX ", "UMAX S-12 ", "V2.1"}, PQUIRK_NOLUNS},
1.135 martin 645: {{T_SCANNER, T_FIXED,
1.156.2.7 nathanw 646: "ULTIMA ", "A6000C ", ""}, PQUIRK_NOLUNS},
1.150 mjacob 647: {{T_PROCESSOR, T_FIXED,
1.156.2.7 nathanw 648: "SYMBIOS", "", ""}, PQUIRK_NOLUNS},
1.87 mjacob 649: {{T_PROCESSOR, T_FIXED,
1.156.2.2 nathanw 650: "LITRONIC", "PCMCIA ", ""}, PQUIRK_NOLUNS},
1.109 thorpej 651: {{T_CHANGER, T_REMOV,
1.156.2.2 nathanw 652: "SONY ", "CDL1100 ", ""}, PQUIRK_NOLUNS},
1.119 mjacob 653: {{T_ENCLOSURE, T_FIXED,
1.156.2.7 nathanw 654: "SUN ", "SENA ", ""}, PQUIRK_NOLUNS},
1.18 mycroft 655: };
656:
1.12 mycroft 657: /*
1.95 mikel 658: * given a target and lun, ask the device what
1.12 mycroft 659: * it is, and find the correct driver table
660: * entry.
661: */
1.119 mjacob 662: int
1.156.2.2 nathanw 663: scsi_probe_device(sc, target, lun)
664: struct scsibus_softc *sc;
1.18 mycroft 665: int target, lun;
666: {
1.156.2.2 nathanw 667: struct scsipi_channel *chan = sc->sc_channel;
668: struct scsipi_periph *periph;
1.140 enami 669: struct scsipi_inquiry_data inqbuf;
1.18 mycroft 670: struct scsi_quirk_inquiry_pattern *finger;
1.156.2.2 nathanw 671: int checkdtype, priority, docontinue, quirks;
1.88 bouyer 672: struct scsipibus_attach_args sa;
1.18 mycroft 673: struct cfdata *cf;
674:
1.119 mjacob 675: /*
676: * Assume no more luns to search after this one.
677: * If we successfully get Inquiry data and after
678: * merging quirks we find we can probe for more
679: * luns, we will.
680: */
681: docontinue = 0;
682:
1.18 mycroft 683: /* Skip this slot if it is already attached. */
1.156.2.2 nathanw 684: if (scsipi_lookup_periph(chan, target, lun) != NULL)
1.119 mjacob 685: return (docontinue);
1.18 mycroft 686:
1.156.2.2 nathanw 687: periph = scsipi_alloc_periph(M_NOWAIT);
688: if (periph == NULL) {
689: #ifdef DIAGNOSTIC
690: printf("%s: cannot allocate periph for target %d lun %d\n",
691: sc->sc_dev.dv_xname, target, lun);
692: #endif
693: return (ENOMEM);
694: }
695: periph->periph_channel = chan;
696: periph->periph_switch = &scsi_probe_dev;
697:
698: periph->periph_target = target;
699: periph->periph_lun = lun;
700: periph->periph_quirks = chan->chan_defquirks;
701:
702: #ifdef SCSIPI_DEBUG
703: if (SCSIPI_DEBUG_TYPE == SCSIPI_BUSTYPE_SCSI &&
704: SCSIPI_DEBUG_TARGET == target &&
705: SCSIPI_DEBUG_LUN == lun)
706: periph->periph_dbflags |= SCSIPI_DEBUG_FLAGS;
707: #endif
1.12 mycroft 708:
709: /*
710: * Ask the device what it is
711: */
1.156.2.2 nathanw 712: (void) scsipi_test_unit_ready(periph,
1.128 thorpej 713: XS_CTL_DISCOVERY | XS_CTL_IGNORE_ILLEGAL_REQUEST |
714: XS_CTL_IGNORE_NOT_READY | XS_CTL_IGNORE_MEDIA_CHANGE);
1.18 mycroft 715:
1.23 mycroft 716: #ifdef SCSI_2_DEF
1.12 mycroft 717: /* some devices need to be told to go to SCSI2 */
718: /* However some just explode if you tell them this.. leave it out */
1.156.2.2 nathanw 719: scsi_change_def(periph, XS_CTL_DISCOVERY | XS_CTL_SILENT);
1.18 mycroft 720: #endif /* SCSI_2_DEF */
721:
722: /* Now go ask the device all about itself. */
1.156.2.2 nathanw 723: memset(&inqbuf, 0, sizeof(inqbuf));
724: if (scsipi_inquire(periph, &inqbuf,
1.147 enami 725: XS_CTL_DISCOVERY | XS_CTL_DATA_ONSTACK) != 0)
1.18 mycroft 726: goto bad;
727: {
1.141 dante 728: u_int8_t *extension = &inqbuf.flags1;
1.18 mycroft 729: int len = inqbuf.additional_length;
1.20 mycroft 730: while (len < 3)
1.141 dante 731: extension[len++] = '\0';
1.20 mycroft 732: while (len < 3 + 28)
1.141 dante 733: extension[len++] = ' ';
734: while (len < 3 + 28 + 20)
735: extension[len++] = '\0';
736: while (len < 3 + 28 + 20 + 1)
737: extension[len++] = '\0';
1.142 dante 738: while (len < 3 + 28 + 20 + 1 + 1)
739: extension[len++] = '\0';
740: while (len < 3 + 28 + 20 + 1 + 1 + (8*2))
741: extension[len++] = ' ';
1.18 mycroft 742: }
743:
1.156.2.2 nathanw 744: periph->periph_type = inqbuf.device & SID_TYPE;
745: if (inqbuf.dev_qual2 & SID_REMOVABLE)
746: periph->periph_flags |= PERIPH_REMOVABLE;
747: periph->periph_version = inqbuf.version & SID_ANSII;
1.12 mycroft 748:
749: /*
750: * Any device qualifier that has the top bit set (qualifier&4 != 0)
751: * is vendor specific and won't match in this switch.
1.51 thorpej 752: * All we do here is throw out bad/negative responses.
1.12 mycroft 753: */
1.51 thorpej 754: checkdtype = 0;
1.18 mycroft 755: switch (inqbuf.device & SID_QUAL) {
1.156.2.2 nathanw 756: case SID_QUAL_LU_PRESENT:
757: case SID_QUAL_LU_NOTPRESENT:
1.51 thorpej 758: checkdtype = 1;
1.2 deraadt 759: break;
1.12 mycroft 760:
1.156.2.2 nathanw 761: case SID_QUAL_reserved:
762: case SID_QUAL_LU_NOT_SUPP:
1.18 mycroft 763: goto bad;
1.12 mycroft 764:
1.2 deraadt 765: default:
766: break;
767: }
1.151 ad 768:
769: /* Let the adapter driver handle the device separatley if it wants. */
1.156.2.2 nathanw 770: if (chan->chan_adapter->adapt_accesschk != NULL &&
771: (*chan->chan_adapter->adapt_accesschk)(periph, &sa.sa_inqbuf))
1.151 ad 772: goto bad;
773:
1.149 mjacob 774: if (checkdtype) {
1.156.2.2 nathanw 775: switch (periph->periph_type) {
1.2 deraadt 776: case T_DIRECT:
777: case T_SEQUENTIAL:
778: case T_PRINTER:
779: case T_PROCESSOR:
1.93 thorpej 780: case T_WORM:
1.18 mycroft 781: case T_CDROM:
1.2 deraadt 782: case T_SCANNER:
783: case T_OPTICAL:
784: case T_CHANGER:
785: case T_COMM:
1.93 thorpej 786: case T_IT8_1:
787: case T_IT8_2:
788: case T_STORARRAY:
789: case T_ENCLOSURE:
1.142 dante 790: case T_SIMPLE_DIRECT:
791: case T_OPTIC_CARD_RW:
792: case T_OBJECT_STORED:
1.51 thorpej 793: default:
1.2 deraadt 794: break;
1.12 mycroft 795: case T_NODEVICE:
1.18 mycroft 796: goto bad;
1.1 cgd 797: }
1.149 mjacob 798: }
1.2 deraadt 799:
1.156.2.2 nathanw 800: sa.sa_periph = periph;
801: sa.sa_inqbuf.type = inqbuf.device;
802: sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ?
803: T_REMOV : T_FIXED;
804: sa.sa_inqbuf.vendor = inqbuf.vendor;
805: sa.sa_inqbuf.product = inqbuf.product;
806: sa.sa_inqbuf.revision = inqbuf.revision;
807: sa.scsipi_info.scsi_version = inqbuf.version;
808: sa.sa_inqptr = &inqbuf;
809:
810: finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
811: &sa.sa_inqbuf, (caddr_t)scsi_quirk_patterns,
812: sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
813: sizeof(scsi_quirk_patterns[0]), &priority);
814:
815: if (finger != NULL)
816: quirks = finger->quirks;
817: else
818: quirks = 0;
819:
820: /*
821: * Determine the operating mode capabilities of the device.
822: */
823: if (periph->periph_version >= 2) {
824: if ((inqbuf.flags3 & SID_CmdQue) != 0 &&
825: (quirks & PQUIRK_NOTAG) == 0)
826: periph->periph_cap |= PERIPH_CAP_TQING;
827: if ((inqbuf.flags3 & SID_Linked) != 0)
828: periph->periph_cap |= PERIPH_CAP_LINKCMDS;
829: if ((inqbuf.flags3 & SID_Sync) != 0 &&
830: (quirks & PQUIRK_NOSYNC) == 0)
831: periph->periph_cap |= PERIPH_CAP_SYNC;
832: if ((inqbuf.flags3 & SID_WBus16) != 0 &&
833: (quirks & PQUIRK_NOWIDE) == 0)
834: periph->periph_cap |= PERIPH_CAP_WIDE16;
835: if ((inqbuf.flags3 & SID_WBus32) != 0 &&
836: (quirks & PQUIRK_NOWIDE) == 0)
837: periph->periph_cap |= PERIPH_CAP_WIDE32;
838: if ((inqbuf.flags3 & SID_SftRe) != 0)
839: periph->periph_cap |= PERIPH_CAP_SFTRESET;
840: if ((inqbuf.flags3 & SID_RelAdr) != 0)
841: periph->periph_cap |= PERIPH_CAP_RELADR;
1.156.2.7 nathanw 842: } else {
843: if (quirks & PQUIRK_CAP_SYNC)
844: periph->periph_cap |= PERIPH_CAP_SYNC;
1.156.2.2 nathanw 845: }
846:
847: /*
848: * Now apply any quirks from the table.
849: */
850: periph->periph_quirks |= quirks;
851: if (periph->periph_version == 0 &&
852: (periph->periph_quirks & PQUIRK_FORCELUNS) == 0)
853: periph->periph_quirks |= PQUIRK_NOLUNS;
854:
855: if (periph->periph_quirks & PQUIRK_CDROM) {
856: periph->periph_quirks ^= PQUIRK_CDROM;
857: inqbuf.dev_qual2 |= SID_REMOVABLE;
1.156.2.7 nathanw 858: sa.sa_inqbuf.type = inqbuf.device =
859: ((inqbuf.device & ~SID_REMOVABLE) | T_CDROM);
1.156.2.2 nathanw 860: sa.sa_inqbuf.removable = T_REMOV;
861: }
862:
863: if ((periph->periph_quirks & PQUIRK_NOLUNS) == 0)
864: docontinue = 1;
865:
866: if ((cf = config_search(scsibussubmatch, &sc->sc_dev, &sa)) != NULL) {
867: scsipi_insert_periph(chan, periph);
868: /*
869: * XXX Can't assign periph_dev here, because we'll
870: * XXX need it before config_attach() returns. Must
871: * XXX assign it in periph driver.
872: */
873: (void) config_attach(&sc->sc_dev, cf, &sa, scsibusprint);
1.51 thorpej 874: } else {
1.156.2.2 nathanw 875: scsibusprint(&sa, sc->sc_dev.dv_xname);
1.65 christos 876: printf(" not configured\n");
1.18 mycroft 877: goto bad;
1.51 thorpej 878: }
1.18 mycroft 879:
1.119 mjacob 880: return (docontinue);
1.12 mycroft 881:
1.18 mycroft 882: bad:
1.156.2.2 nathanw 883: free(periph, M_DEVBUF);
1.119 mjacob 884: return (docontinue);
1.111 thorpej 885: }
886:
887: /****** Entry points for user control of the SCSI bus. ******/
888:
889: int
890: scsibusopen(dev, flag, fmt, p)
891: dev_t dev;
892: int flag, fmt;
893: struct proc *p;
894: {
895: struct scsibus_softc *sc;
1.117 thorpej 896: int error, unit = minor(dev);
1.111 thorpej 897:
898: if (unit >= scsibus_cd.cd_ndevs ||
899: (sc = scsibus_cd.cd_devs[unit]) == NULL)
900: return (ENXIO);
901:
1.114 thorpej 902: if (sc->sc_flags & SCSIBUSF_OPEN)
1.111 thorpej 903: return (EBUSY);
1.117 thorpej 904:
1.156.2.2 nathanw 905: if ((error = scsipi_adapter_addref(sc->sc_channel->chan_adapter)) != 0)
1.117 thorpej 906: return (error);
907:
1.114 thorpej 908: sc->sc_flags |= SCSIBUSF_OPEN;
1.111 thorpej 909:
910: return (0);
911: }
912:
913: int
914: scsibusclose(dev, flag, fmt, p)
915: dev_t dev;
916: int flag, fmt;
917: struct proc *p;
918: {
919: struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
1.117 thorpej 920:
1.156.2.2 nathanw 921: scsipi_adapter_delref(sc->sc_channel->chan_adapter);
1.111 thorpej 922:
1.114 thorpej 923: sc->sc_flags &= ~SCSIBUSF_OPEN;
1.111 thorpej 924:
925: return (0);
926: }
927:
928: int
929: scsibusioctl(dev, cmd, addr, flag, p)
930: dev_t dev;
931: u_long cmd;
932: caddr_t addr;
933: int flag;
934: struct proc *p;
935: {
936: struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
1.156.2.2 nathanw 937: struct scsipi_channel *chan = sc->sc_channel;
1.111 thorpej 938: int error;
939:
1.113 thorpej 940: /*
941: * Enforce write permission for ioctls that change the
942: * state of the bus. Host adapter specific ioctls must
943: * be checked by the adapter driver.
944: */
945: switch (cmd) {
946: case SCBUSIOSCAN:
1.156.2.3 nathanw 947: case SCBUSIODETACH:
1.113 thorpej 948: case SCBUSIORESET:
949: if ((flag & FWRITE) == 0)
950: return (EBADF);
951: }
952:
1.111 thorpej 953: switch (cmd) {
1.112 thorpej 954: case SCBUSIOSCAN:
955: {
956: struct scbusioscan_args *a =
957: (struct scbusioscan_args *)addr;
958:
1.156.2.2 nathanw 959: error = scsi_probe_bus(sc, a->sa_target, a->sa_lun);
1.112 thorpej 960: break;
961: }
1.156.2.3 nathanw 962:
963: case SCBUSIODETACH:
964: {
965: struct scbusiodetach_args *a =
966: (struct scbusiodetach_args *)addr;
967:
968: error = scsipi_target_detach(chan, a->sa_target, a->sa_lun, 0);
969: break;
970: }
971:
1.112 thorpej 972:
1.113 thorpej 973: case SCBUSIORESET:
974: /* FALLTHROUGH */
1.111 thorpej 975: default:
1.156.2.2 nathanw 976: if (chan->chan_adapter->adapt_ioctl == NULL)
1.113 thorpej 977: error = ENOTTY;
978: else
1.156.2.2 nathanw 979: error = (*chan->chan_adapter->adapt_ioctl)(chan,
1.113 thorpej 980: cmd, addr, flag, p);
981: break;
1.111 thorpej 982: }
983:
984: return (error);
1.1 cgd 985: }
CVSweb <webmaster@jp.NetBSD.org>