Mon Apr 25 14:14:22 2011 UTC ()
Don't kill outstanding requests when detaching a scsibus on shutdown.
Both the controller and tyhe targets are still running.


(hannken)
diff -r1.260 -r1.261 src/sys/dev/scsipi/scsiconf.c

cvs diff -r1.260 -r1.261 src/sys/dev/scsipi/scsiconf.c (switch to unified diff)

--- src/sys/dev/scsipi/scsiconf.c 2011/04/18 01:47:28 1.260
+++ src/sys/dev/scsipi/scsiconf.c 2011/04/25 14:14:22 1.261
@@ -1,1040 +1,1042 @@ @@ -1,1040 +1,1042 @@
1/* $NetBSD: scsiconf.c,v 1.260 2011/04/18 01:47:28 rmind Exp $ */ 1/* $NetBSD: scsiconf.c,v 1.261 2011/04/25 14:14:22 hannken Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace 8 * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace
9 * Simulation Facility, NASA Ames Research Center. 9 * Simulation Facility, NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer. 15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright 16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the 17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution. 18 * documentation and/or other materials provided with the distribution.
19 * 19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33/* 33/*
34 * Originally written by Julian Elischer (julian@tfs.com) 34 * Originally written by Julian Elischer (julian@tfs.com)
35 * for TRW Financial Systems for use under the MACH(2.5) operating system. 35 * for TRW Financial Systems for use under the MACH(2.5) operating system.
36 * 36 *
37 * TRW Financial Systems, in accordance with their agreement with Carnegie 37 * TRW Financial Systems, in accordance with their agreement with Carnegie
38 * Mellon University, makes this software available to CMU to distribute 38 * Mellon University, makes this software available to CMU to distribute
39 * or use in any manner that they see fit as long as this message is kept with 39 * or use in any manner that they see fit as long as this message is kept with
40 * the software. For this reason TFS also grants any other persons or 40 * the software. For this reason TFS also grants any other persons or
41 * organisations permission to use or modify this software. 41 * organisations permission to use or modify this software.
42 * 42 *
43 * TFS supplies this software to be publicly redistributed 43 * TFS supplies this software to be publicly redistributed
44 * on the understanding that TFS is not responsible for the correct 44 * on the understanding that TFS is not responsible for the correct
45 * functioning of this software in any circumstances. 45 * functioning of this software in any circumstances.
46 * 46 *
47 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 47 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
48 */ 48 */
49 49
50#include <sys/cdefs.h> 50#include <sys/cdefs.h>
51__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.260 2011/04/18 01:47:28 rmind Exp $"); 51__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.261 2011/04/25 14:14:22 hannken Exp $");
52 52
53#include <sys/param.h> 53#include <sys/param.h>
54#include <sys/systm.h> 54#include <sys/systm.h>
55#include <sys/kernel.h> 55#include <sys/kernel.h>
56#include <sys/proc.h> 56#include <sys/proc.h>
57#include <sys/kthread.h> 57#include <sys/kthread.h>
58#include <sys/malloc.h> 58#include <sys/malloc.h>
59#include <sys/mutex.h> 59#include <sys/mutex.h>
60#include <sys/once.h> 60#include <sys/once.h>
61#include <sys/device.h> 61#include <sys/device.h>
62#include <sys/conf.h> 62#include <sys/conf.h>
63#include <sys/fcntl.h> 63#include <sys/fcntl.h>
64#include <sys/scsiio.h> 64#include <sys/scsiio.h>
65#include <sys/queue.h> 65#include <sys/queue.h>
66 66
67#include <dev/scsipi/scsi_all.h> 67#include <dev/scsipi/scsi_all.h>
68#include <dev/scsipi/scsipi_all.h> 68#include <dev/scsipi/scsipi_all.h>
69#include <dev/scsipi/scsiconf.h> 69#include <dev/scsipi/scsiconf.h>
70 70
71#include "locators.h" 71#include "locators.h"
72 72
73static const struct scsipi_periphsw scsi_probe_dev = { 73static const struct scsipi_periphsw scsi_probe_dev = {
74 NULL, 74 NULL,
75 NULL, 75 NULL,
76 NULL, 76 NULL,
77 NULL, 77 NULL,
78}; 78};
79 79
80struct scsi_initq { 80struct scsi_initq {
81 struct scsipi_channel *sc_channel; 81 struct scsipi_channel *sc_channel;
82 TAILQ_ENTRY(scsi_initq) scsi_initq; 82 TAILQ_ENTRY(scsi_initq) scsi_initq;
83}; 83};
84 84
85static ONCE_DECL(scsi_conf_ctrl); 85static ONCE_DECL(scsi_conf_ctrl);
86static TAILQ_HEAD(, scsi_initq) scsi_initq_head; 86static TAILQ_HEAD(, scsi_initq) scsi_initq_head;
87static kmutex_t scsibus_qlock; 87static kmutex_t scsibus_qlock;
88static kcondvar_t scsibus_qcv; 88static kcondvar_t scsibus_qcv;
89 89
90static int scsi_probe_device(struct scsibus_softc *, int, int); 90static int scsi_probe_device(struct scsibus_softc *, int, int);
91 91
92static int scsibusmatch(device_t, cfdata_t, void *); 92static int scsibusmatch(device_t, cfdata_t, void *);
93static void scsibusattach(device_t, device_t, void *); 93static void scsibusattach(device_t, device_t, void *);
94static int scsibusdetach(device_t, int flags); 94static int scsibusdetach(device_t, int flags);
95static int scsibusrescan(device_t, const char *, const int *); 95static int scsibusrescan(device_t, const char *, const int *);
96static void scsidevdetached(device_t, device_t); 96static void scsidevdetached(device_t, device_t);
97 97
98CFATTACH_DECL3_NEW(scsibus, sizeof(struct scsibus_softc), 98CFATTACH_DECL3_NEW(scsibus, sizeof(struct scsibus_softc),
99 scsibusmatch, scsibusattach, scsibusdetach, NULL, 99 scsibusmatch, scsibusattach, scsibusdetach, NULL,
100 scsibusrescan, scsidevdetached, DVF_DETACH_SHUTDOWN); 100 scsibusrescan, scsidevdetached, DVF_DETACH_SHUTDOWN);
101 101
102extern struct cfdriver scsibus_cd; 102extern struct cfdriver scsibus_cd;
103 103
104static dev_type_open(scsibusopen); 104static dev_type_open(scsibusopen);
105static dev_type_close(scsibusclose); 105static dev_type_close(scsibusclose);
106static dev_type_ioctl(scsibusioctl); 106static dev_type_ioctl(scsibusioctl);
107 107
108const struct cdevsw scsibus_cdevsw = { 108const struct cdevsw scsibus_cdevsw = {
109 scsibusopen, scsibusclose, noread, nowrite, scsibusioctl, 109 scsibusopen, scsibusclose, noread, nowrite, scsibusioctl,
110 nostop, notty, nopoll, nommap, nokqfilter, D_OTHER, 110 nostop, notty, nopoll, nommap, nokqfilter, D_OTHER,
111}; 111};
112 112
113static int scsibusprint(void *, const char *); 113static int scsibusprint(void *, const char *);
114static void scsibus_config(struct scsipi_channel *, void *); 114static void scsibus_config(struct scsipi_channel *, void *);
115 115
116const struct scsipi_bustype scsi_bustype = { 116const struct scsipi_bustype scsi_bustype = {
117 SCSIPI_BUSTYPE_SCSI, 117 SCSIPI_BUSTYPE_SCSI,
118 scsi_scsipi_cmd, 118 scsi_scsipi_cmd,
119 scsipi_interpret_sense, 119 scsipi_interpret_sense,
120 scsi_print_addr, 120 scsi_print_addr,
121 scsi_kill_pending, 121 scsi_kill_pending,
122}; 122};
123 123
124static int 124static int
125scsibus_init(void) 125scsibus_init(void)
126{ 126{
127 127
128 TAILQ_INIT(&scsi_initq_head); 128 TAILQ_INIT(&scsi_initq_head);
129 mutex_init(&scsibus_qlock, MUTEX_DEFAULT, IPL_NONE); 129 mutex_init(&scsibus_qlock, MUTEX_DEFAULT, IPL_NONE);
130 cv_init(&scsibus_qcv, "scsinitq"); 130 cv_init(&scsibus_qcv, "scsinitq");
131 return 0; 131 return 0;
132} 132}
133 133
134int 134int
135scsiprint(void *aux, const char *pnp) 135scsiprint(void *aux, const char *pnp)
136{ 136{
137 struct scsipi_channel *chan = aux; 137 struct scsipi_channel *chan = aux;
138 struct scsipi_adapter *adapt = chan->chan_adapter; 138 struct scsipi_adapter *adapt = chan->chan_adapter;
139 139
140 /* only "scsibus"es can attach to "scsi"s; easy. */ 140 /* only "scsibus"es can attach to "scsi"s; easy. */
141 if (pnp) 141 if (pnp)
142 aprint_normal("scsibus at %s", pnp); 142 aprint_normal("scsibus at %s", pnp);
143 143
144 /* don't print channel if the controller says there can be only one. */ 144 /* don't print channel if the controller says there can be only one. */
145 if (adapt->adapt_nchannels != 1) 145 if (adapt->adapt_nchannels != 1)
146 aprint_normal(" channel %d", chan->chan_channel); 146 aprint_normal(" channel %d", chan->chan_channel);
147 147
148 return (UNCONF); 148 return (UNCONF);
149} 149}
150 150
151static int 151static int
152scsibusmatch(device_t parent, cfdata_t cf, void *aux) 152scsibusmatch(device_t parent, cfdata_t cf, void *aux)
153{ 153{
154 struct scsipi_channel *chan = aux; 154 struct scsipi_channel *chan = aux;
155 155
156 if (chan->chan_bustype->bustype_type != SCSIPI_BUSTYPE_SCSI) 156 if (chan->chan_bustype->bustype_type != SCSIPI_BUSTYPE_SCSI)
157 return 0; 157 return 0;
158 158
159 if (cf->cf_loc[SCSICF_CHANNEL] != chan->chan_channel && 159 if (cf->cf_loc[SCSICF_CHANNEL] != chan->chan_channel &&
160 cf->cf_loc[SCSICF_CHANNEL] != SCSICF_CHANNEL_DEFAULT) 160 cf->cf_loc[SCSICF_CHANNEL] != SCSICF_CHANNEL_DEFAULT)
161 return (0); 161 return (0);
162 162
163 return (1); 163 return (1);
164} 164}
165 165
166static void 166static void
167scsibusattach(device_t parent, device_t self, void *aux) 167scsibusattach(device_t parent, device_t self, void *aux)
168{ 168{
169 struct scsibus_softc *sc = device_private(self); 169 struct scsibus_softc *sc = device_private(self);
170 struct scsipi_channel *chan = aux; 170 struct scsipi_channel *chan = aux;
171 struct scsi_initq *scsi_initq; 171 struct scsi_initq *scsi_initq;
172 172
173 if (!pmf_device_register(self, NULL, NULL)) 173 if (!pmf_device_register(self, NULL, NULL))
174 aprint_error_dev(self, "couldn't establish power handler\n"); 174 aprint_error_dev(self, "couldn't establish power handler\n");
175 175
176 sc->sc_dev = self; 176 sc->sc_dev = self;
177 sc->sc_channel = chan; 177 sc->sc_channel = chan;
178 chan->chan_name = device_xname(sc->sc_dev); 178 chan->chan_name = device_xname(sc->sc_dev);
179 179
180 aprint_naive(": SCSI bus\n"); 180 aprint_naive(": SCSI bus\n");
181 aprint_normal(": %d target%s, %d lun%s per target\n", 181 aprint_normal(": %d target%s, %d lun%s per target\n",
182 chan->chan_ntargets, 182 chan->chan_ntargets,
183 chan->chan_ntargets == 1 ? "" : "s", 183 chan->chan_ntargets == 1 ? "" : "s",
184 chan->chan_nluns, 184 chan->chan_nluns,
185 chan->chan_nluns == 1 ? "" : "s"); 185 chan->chan_nluns == 1 ? "" : "s");
186 186
187 if (scsipi_adapter_addref(chan->chan_adapter)) 187 if (scsipi_adapter_addref(chan->chan_adapter))
188 return; 188 return;
189 189
190 RUN_ONCE(&scsi_conf_ctrl, scsibus_init); 190 RUN_ONCE(&scsi_conf_ctrl, scsibus_init);
191 191
192 /* Initialize the channel structure first */ 192 /* Initialize the channel structure first */
193 chan->chan_init_cb = scsibus_config; 193 chan->chan_init_cb = scsibus_config;
194 chan->chan_init_cb_arg = sc; 194 chan->chan_init_cb_arg = sc;
195 195
196 scsi_initq = malloc(sizeof(struct scsi_initq), M_DEVBUF, M_WAITOK); 196 scsi_initq = malloc(sizeof(struct scsi_initq), M_DEVBUF, M_WAITOK);
197 scsi_initq->sc_channel = chan; 197 scsi_initq->sc_channel = chan;
198 TAILQ_INSERT_TAIL(&scsi_initq_head, scsi_initq, scsi_initq); 198 TAILQ_INSERT_TAIL(&scsi_initq_head, scsi_initq, scsi_initq);
199 config_pending_incr(); 199 config_pending_incr();
200 if (scsipi_channel_init(chan)) { 200 if (scsipi_channel_init(chan)) {
201 aprint_error_dev(sc->sc_dev, "failed to init channel\n"); 201 aprint_error_dev(sc->sc_dev, "failed to init channel\n");
202 return; 202 return;
203 } 203 }
204} 204}
205 205
206static void 206static void
207scsibus_config(struct scsipi_channel *chan, void *arg) 207scsibus_config(struct scsipi_channel *chan, void *arg)
208{ 208{
209 struct scsibus_softc *sc = arg; 209 struct scsibus_softc *sc = arg;
210 struct scsi_initq *scsi_initq; 210 struct scsi_initq *scsi_initq;
211 211
212#ifndef SCSI_DELAY 212#ifndef SCSI_DELAY
213#define SCSI_DELAY 2 213#define SCSI_DELAY 2
214#endif 214#endif
215 if ((chan->chan_flags & SCSIPI_CHAN_NOSETTLE) == 0 && 215 if ((chan->chan_flags & SCSIPI_CHAN_NOSETTLE) == 0 &&
216 SCSI_DELAY > 0) { 216 SCSI_DELAY > 0) {
217 aprint_normal_dev(sc->sc_dev, 217 aprint_normal_dev(sc->sc_dev,
218 "waiting %d seconds for devices to settle...\n", 218 "waiting %d seconds for devices to settle...\n",
219 SCSI_DELAY); 219 SCSI_DELAY);
220 /* ...an identifier we know no one will use... */ 220 /* ...an identifier we know no one will use... */
221 (void) tsleep(scsibus_config, PRIBIO, 221 (void) tsleep(scsibus_config, PRIBIO,
222 "scsidly", SCSI_DELAY * hz); 222 "scsidly", SCSI_DELAY * hz);
223 } 223 }
224 224
225 /* Make sure the devices probe in scsibus order to avoid jitter. */ 225 /* Make sure the devices probe in scsibus order to avoid jitter. */
226 mutex_enter(&scsibus_qlock); 226 mutex_enter(&scsibus_qlock);
227 for (;;) { 227 for (;;) {
228 scsi_initq = TAILQ_FIRST(&scsi_initq_head); 228 scsi_initq = TAILQ_FIRST(&scsi_initq_head);
229 if (scsi_initq->sc_channel == chan) 229 if (scsi_initq->sc_channel == chan)
230 break; 230 break;
231 cv_wait(&scsibus_qcv, &scsibus_qlock); 231 cv_wait(&scsibus_qcv, &scsibus_qlock);
232 } 232 }
233 mutex_exit(&scsibus_qlock); 233 mutex_exit(&scsibus_qlock);
234 234
235 scsi_probe_bus(sc, -1, -1); 235 scsi_probe_bus(sc, -1, -1);
236 236
237 mutex_enter(&scsibus_qlock); 237 mutex_enter(&scsibus_qlock);
238 TAILQ_REMOVE(&scsi_initq_head, scsi_initq, scsi_initq); 238 TAILQ_REMOVE(&scsi_initq_head, scsi_initq, scsi_initq);
239 cv_broadcast(&scsibus_qcv); 239 cv_broadcast(&scsibus_qcv);
240 mutex_exit(&scsibus_qlock); 240 mutex_exit(&scsibus_qlock);
241 241
242 free(scsi_initq, M_DEVBUF); 242 free(scsi_initq, M_DEVBUF);
243 243
244 scsipi_adapter_delref(chan->chan_adapter); 244 scsipi_adapter_delref(chan->chan_adapter);
245 245
246 config_pending_decr(); 246 config_pending_decr();
247} 247}
248 248
249static int 249static int
250scsibusdetach(device_t self, int flags) 250scsibusdetach(device_t self, int flags)
251{ 251{
252 struct scsibus_softc *sc = device_private(self); 252 struct scsibus_softc *sc = device_private(self);
253 struct scsipi_channel *chan = sc->sc_channel; 253 struct scsipi_channel *chan = sc->sc_channel;
254 struct scsipi_periph *periph; 254 struct scsipi_periph *periph;
255 int ctarget, clun; 255 int ctarget, clun;
256 struct scsipi_xfer *xs; 256 struct scsipi_xfer *xs;
257 int error; 257 int error;
258 258
259 pmf_device_deregister(self); 259 pmf_device_deregister(self);
260 260
261 /* 261 /*
262 * Process outstanding commands (which will never complete as the 262 * Process outstanding commands (which will never complete as the
263 * controller is gone). 263 * controller is gone).
264 */ 264 */
265 for (ctarget = 0; ctarget < chan->chan_ntargets; ctarget++) { 265 for (ctarget = 0; ctarget < chan->chan_ntargets; ctarget++) {
266 if (ctarget == chan->chan_id) 266 if (ctarget == chan->chan_id)
267 continue; 267 continue;
268 for (clun = 0; clun < chan->chan_nluns; clun++) { 268 for (clun = 0; clun < chan->chan_nluns; clun++) {
269 periph = scsipi_lookup_periph(chan, ctarget, clun); 269 periph = scsipi_lookup_periph(chan, ctarget, clun);
270 if (periph == NULL) 270 if (periph == NULL)
271 continue; 271 continue;
 272 if ((flags & DETACH_SHUTDOWN) != 0)
 273 return EBUSY;
272 TAILQ_FOREACH(xs, &periph->periph_xferq, device_q) { 274 TAILQ_FOREACH(xs, &periph->periph_xferq, device_q) {
273 callout_stop(&xs->xs_callout); 275 callout_stop(&xs->xs_callout);
274 xs->error = XS_DRIVER_STUFFUP; 276 xs->error = XS_DRIVER_STUFFUP;
275 scsipi_done(xs); 277 scsipi_done(xs);
276 } 278 }
277 } 279 }
278 } 280 }
279 281
280 /* 282 /*
281 * Detach all of the periphs. 283 * Detach all of the periphs.
282 */ 284 */
283 error = scsipi_target_detach(chan, -1, -1, flags); 285 error = scsipi_target_detach(chan, -1, -1, flags);
284 286
285 /* 287 /*
286 * Now shut down the channel. 288 * Now shut down the channel.
287 * XXX only if no errors ? 289 * XXX only if no errors ?
288 */ 290 */
289 scsipi_channel_shutdown(chan); 291 scsipi_channel_shutdown(chan);
290 return (error); 292 return (error);
291} 293}
292 294
293/* 295/*
294 * Probe the requested scsi bus. It must be already set up. 296 * Probe the requested scsi bus. It must be already set up.
295 * target and lun optionally narrow the search if not -1 297 * target and lun optionally narrow the search if not -1
296 */ 298 */
297int 299int
298scsi_probe_bus(struct scsibus_softc *sc, int target, int lun) 300scsi_probe_bus(struct scsibus_softc *sc, int target, int lun)
299{ 301{
300 struct scsipi_channel *chan = sc->sc_channel; 302 struct scsipi_channel *chan = sc->sc_channel;
301 int maxtarget, mintarget, maxlun, minlun; 303 int maxtarget, mintarget, maxlun, minlun;
302 int error; 304 int error;
303 305
304 if (target == -1) { 306 if (target == -1) {
305 maxtarget = chan->chan_ntargets - 1; 307 maxtarget = chan->chan_ntargets - 1;
306 mintarget = 0; 308 mintarget = 0;
307 } else { 309 } else {
308 if (target < 0 || target >= chan->chan_ntargets) 310 if (target < 0 || target >= chan->chan_ntargets)
309 return (EINVAL); 311 return (EINVAL);
310 maxtarget = mintarget = target; 312 maxtarget = mintarget = target;
311 } 313 }
312 314
313 if (lun == -1) { 315 if (lun == -1) {
314 maxlun = chan->chan_nluns - 1; 316 maxlun = chan->chan_nluns - 1;
315 minlun = 0; 317 minlun = 0;
316 } else { 318 } else {
317 if (lun < 0 || lun >= chan->chan_nluns) 319 if (lun < 0 || lun >= chan->chan_nluns)
318 return (EINVAL); 320 return (EINVAL);
319 maxlun = minlun = lun; 321 maxlun = minlun = lun;
320 } 322 }
321 323
322 /* 324 /*
323 * Some HBAs provide an abstracted view of the bus; give them an 325 * Some HBAs provide an abstracted view of the bus; give them an
324 * oppertunity to re-scan it before we do. 326 * oppertunity to re-scan it before we do.
325 */ 327 */
326 if (chan->chan_adapter->adapt_ioctl != NULL) 328 if (chan->chan_adapter->adapt_ioctl != NULL)
327 (*chan->chan_adapter->adapt_ioctl)(chan, SCBUSIOLLSCAN, NULL, 329 (*chan->chan_adapter->adapt_ioctl)(chan, SCBUSIOLLSCAN, NULL,
328 0, curproc); 330 0, curproc);
329 331
330 if ((error = scsipi_adapter_addref(chan->chan_adapter)) != 0) 332 if ((error = scsipi_adapter_addref(chan->chan_adapter)) != 0)
331 return (error); 333 return (error);
332 for (target = mintarget; target <= maxtarget; target++) { 334 for (target = mintarget; target <= maxtarget; target++) {
333 if (target == chan->chan_id) 335 if (target == chan->chan_id)
334 continue; 336 continue;
335 for (lun = minlun; lun <= maxlun; lun++) { 337 for (lun = minlun; lun <= maxlun; lun++) {
336 /* 338 /*
337 * See if there's a device present, and configure it. 339 * See if there's a device present, and configure it.
338 */ 340 */
339 if (scsi_probe_device(sc, target, lun) == 0) 341 if (scsi_probe_device(sc, target, lun) == 0)
340 break; 342 break;
341 /* otherwise something says we should look further */ 343 /* otherwise something says we should look further */
342 } 344 }
343 345
344 /* 346 /*
345 * Now that we've discovered all of the LUNs on this 347 * Now that we've discovered all of the LUNs on this
346 * I_T Nexus, update the xfer mode for all of them 348 * I_T Nexus, update the xfer mode for all of them
347 * that we know about. 349 * that we know about.
348 */ 350 */
349 scsipi_set_xfer_mode(chan, target, 1); 351 scsipi_set_xfer_mode(chan, target, 1);
350 } 352 }
351 scsipi_adapter_delref(chan->chan_adapter); 353 scsipi_adapter_delref(chan->chan_adapter);
352 return (0); 354 return (0);
353} 355}
354 356
355static int 357static int
356scsibusrescan(device_t sc, const char *ifattr, 358scsibusrescan(device_t sc, const char *ifattr,
357 const int *locators) 359 const int *locators)
358{ 360{
359 361
360 KASSERT(ifattr && !strcmp(ifattr, "scsibus")); 362 KASSERT(ifattr && !strcmp(ifattr, "scsibus"));
361 KASSERT(locators); 363 KASSERT(locators);
362 364
363 return (scsi_probe_bus(device_private(sc), 365 return (scsi_probe_bus(device_private(sc),
364 locators[SCSIBUSCF_TARGET], locators[SCSIBUSCF_LUN])); 366 locators[SCSIBUSCF_TARGET], locators[SCSIBUSCF_LUN]));
365} 367}
366 368
367static void 369static void
368scsidevdetached(device_t self, device_t child) 370scsidevdetached(device_t self, device_t child)
369{ 371{
370 struct scsibus_softc *sc = device_private(self); 372 struct scsibus_softc *sc = device_private(self);
371 struct scsipi_channel *chan = sc->sc_channel; 373 struct scsipi_channel *chan = sc->sc_channel;
372 struct scsipi_periph *periph; 374 struct scsipi_periph *periph;
373 int target, lun; 375 int target, lun;
374 376
375 target = device_locator(child, SCSIBUSCF_TARGET); 377 target = device_locator(child, SCSIBUSCF_TARGET);
376 lun = device_locator(child, SCSIBUSCF_LUN); 378 lun = device_locator(child, SCSIBUSCF_LUN);
377 379
378 periph = scsipi_lookup_periph(chan, target, lun); 380 periph = scsipi_lookup_periph(chan, target, lun);
379 KASSERT(periph->periph_dev == child); 381 KASSERT(periph->periph_dev == child);
380 382
381 scsipi_remove_periph(chan, periph); 383 scsipi_remove_periph(chan, periph);
382 free(periph, M_DEVBUF); 384 free(periph, M_DEVBUF);
383} 385}
384 386
385/* 387/*
386 * Print out autoconfiguration information for a subdevice. 388 * Print out autoconfiguration information for a subdevice.
387 * 389 *
388 * This is a slight abuse of 'standard' autoconfiguration semantics, 390 * This is a slight abuse of 'standard' autoconfiguration semantics,
389 * because 'print' functions don't normally print the colon and 391 * because 'print' functions don't normally print the colon and
390 * device information. However, in this case that's better than 392 * device information. However, in this case that's better than
391 * either printing redundant information before the attach message, 393 * either printing redundant information before the attach message,
392 * or having the device driver call a special function to print out 394 * or having the device driver call a special function to print out
393 * the standard device information. 395 * the standard device information.
394 */ 396 */
395static int 397static int
396scsibusprint(void *aux, const char *pnp) 398scsibusprint(void *aux, const char *pnp)
397{ 399{
398 struct scsipibus_attach_args *sa = aux; 400 struct scsipibus_attach_args *sa = aux;
399 struct scsipi_inquiry_pattern *inqbuf; 401 struct scsipi_inquiry_pattern *inqbuf;
400 u_int8_t type; 402 u_int8_t type;
401 const char *dtype; 403 const char *dtype;
402 char vendor[33], product[65], revision[17]; 404 char vendor[33], product[65], revision[17];
403 int target, lun; 405 int target, lun;
404 406
405 if (pnp != NULL) 407 if (pnp != NULL)
406 aprint_normal("%s", pnp); 408 aprint_normal("%s", pnp);
407 409
408 inqbuf = &sa->sa_inqbuf; 410 inqbuf = &sa->sa_inqbuf;
409 411
410 target = sa->sa_periph->periph_target; 412 target = sa->sa_periph->periph_target;
411 lun = sa->sa_periph->periph_lun; 413 lun = sa->sa_periph->periph_lun;
412 type = inqbuf->type & SID_TYPE; 414 type = inqbuf->type & SID_TYPE;
413 415
414 dtype = scsipi_dtype(type); 416 dtype = scsipi_dtype(type);
415 417
416 scsipi_strvis(vendor, 33, inqbuf->vendor, 8); 418 scsipi_strvis(vendor, 33, inqbuf->vendor, 8);
417 scsipi_strvis(product, 65, inqbuf->product, 16); 419 scsipi_strvis(product, 65, inqbuf->product, 16);
418 scsipi_strvis(revision, 17, inqbuf->revision, 4); 420 scsipi_strvis(revision, 17, inqbuf->revision, 4);
419 421
420 aprint_normal(" target %d lun %d: <%s, %s, %s> %s %s", 422 aprint_normal(" target %d lun %d: <%s, %s, %s> %s %s",
421 target, lun, vendor, product, revision, dtype, 423 target, lun, vendor, product, revision, dtype,
422 inqbuf->removable ? "removable" : "fixed"); 424 inqbuf->removable ? "removable" : "fixed");
423 425
424 return (UNCONF); 426 return (UNCONF);
425} 427}
426 428
427static const struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = { 429static const struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
428 {{T_CDROM, T_REMOV, 430 {{T_CDROM, T_REMOV,
429 "CHINON ", "CD-ROM CDS-431 ", ""}, PQUIRK_NOLUNS}, 431 "CHINON ", "CD-ROM CDS-431 ", ""}, PQUIRK_NOLUNS},
430 {{T_CDROM, T_REMOV, 432 {{T_CDROM, T_REMOV,
431 "CHINON ", "CD-ROM CDS-435 ", ""}, PQUIRK_NOLUNS}, 433 "CHINON ", "CD-ROM CDS-435 ", ""}, PQUIRK_NOLUNS},
432 {{T_CDROM, T_REMOV, 434 {{T_CDROM, T_REMOV,
433 "Chinon ", "CD-ROM CDS-525 ", ""}, PQUIRK_NOLUNS}, 435 "Chinon ", "CD-ROM CDS-525 ", ""}, PQUIRK_NOLUNS},
434 {{T_CDROM, T_REMOV, 436 {{T_CDROM, T_REMOV,
435 "CHINON ", "CD-ROM CDS-535 ", ""}, PQUIRK_NOLUNS}, 437 "CHINON ", "CD-ROM CDS-535 ", ""}, PQUIRK_NOLUNS},
436 {{T_CDROM, T_REMOV, 438 {{T_CDROM, T_REMOV,
437 "DEC ", "RRD42 (C) DEC ", ""}, PQUIRK_NOLUNS}, 439 "DEC ", "RRD42 (C) DEC ", ""}, PQUIRK_NOLUNS},
438 {{T_CDROM, T_REMOV, 440 {{T_CDROM, T_REMOV,
439 "DENON ", "DRD-25X ", "V"}, PQUIRK_NOLUNS}, 441 "DENON ", "DRD-25X ", "V"}, PQUIRK_NOLUNS},
440 {{T_CDROM, T_REMOV, 442 {{T_CDROM, T_REMOV,
441 "GENERIC ", "CRD-BP2 ", ""}, PQUIRK_NOLUNS}, 443 "GENERIC ", "CRD-BP2 ", ""}, PQUIRK_NOLUNS},
442 {{T_CDROM, T_REMOV, 444 {{T_CDROM, T_REMOV,
443 "HP ", "C4324/C4325 ", ""}, PQUIRK_NOLUNS}, 445 "HP ", "C4324/C4325 ", ""}, PQUIRK_NOLUNS},
444 {{T_CDROM, T_REMOV, 446 {{T_CDROM, T_REMOV,
445 "IMS ", "CDD521/10 ", "2.06"}, PQUIRK_NOLUNS}, 447 "IMS ", "CDD521/10 ", "2.06"}, PQUIRK_NOLUNS},
446 {{T_CDROM, T_REMOV, 448 {{T_CDROM, T_REMOV,
447 "MATSHITA", "CD-ROM CR-5XX ", "1.0b"}, PQUIRK_NOLUNS}, 449 "MATSHITA", "CD-ROM CR-5XX ", "1.0b"}, PQUIRK_NOLUNS},
448 {{T_CDROM, T_REMOV, 450 {{T_CDROM, T_REMOV,
449 "MEDAVIS ", "RENO CD-ROMX2A ", ""}, PQUIRK_NOLUNS}, 451 "MEDAVIS ", "RENO CD-ROMX2A ", ""}, PQUIRK_NOLUNS},
450 {{T_CDROM, T_REMOV, 452 {{T_CDROM, T_REMOV,
451 "MEDIAVIS", "CDR-H93MV ", "1.3"}, PQUIRK_NOLUNS}, 453 "MEDIAVIS", "CDR-H93MV ", "1.3"}, PQUIRK_NOLUNS},
452 {{T_CDROM, T_REMOV, 454 {{T_CDROM, T_REMOV,
453 "NEC ", "CD-ROM DRIVE:502", ""}, PQUIRK_NOLUNS}, 455 "NEC ", "CD-ROM DRIVE:502", ""}, PQUIRK_NOLUNS},
454 {{T_CDROM, T_REMOV, 456 {{T_CDROM, T_REMOV,
455 "NEC ", "CD-ROM DRIVE:55 ", ""}, PQUIRK_NOLUNS}, 457 "NEC ", "CD-ROM DRIVE:55 ", ""}, PQUIRK_NOLUNS},
456 {{T_CDROM, T_REMOV, 458 {{T_CDROM, T_REMOV,
457 "NEC ", "CD-ROM DRIVE:83 ", ""}, PQUIRK_NOLUNS}, 459 "NEC ", "CD-ROM DRIVE:83 ", ""}, PQUIRK_NOLUNS},
458 {{T_CDROM, T_REMOV, 460 {{T_CDROM, T_REMOV,
459 "NEC ", "CD-ROM DRIVE:84 ", ""}, PQUIRK_NOLUNS}, 461 "NEC ", "CD-ROM DRIVE:84 ", ""}, PQUIRK_NOLUNS},
460 {{T_CDROM, T_REMOV, 462 {{T_CDROM, T_REMOV,
461 "NEC ", "CD-ROM DRIVE:841", ""}, PQUIRK_NOLUNS}, 463 "NEC ", "CD-ROM DRIVE:841", ""}, PQUIRK_NOLUNS},
462 {{T_CDROM, T_REMOV, 464 {{T_CDROM, T_REMOV,
463 "OLYMPUS ", "CDS620E ", "1.1d"}, 465 "OLYMPUS ", "CDS620E ", "1.1d"},
464 PQUIRK_NOLUNS|PQUIRK_NOSYNC|PQUIRK_NOCAPACITY}, 466 PQUIRK_NOLUNS|PQUIRK_NOSYNC|PQUIRK_NOCAPACITY},
465 {{T_CDROM, T_REMOV, 467 {{T_CDROM, T_REMOV,
466 "PIONEER ", "CD-ROM DR-124X ", "1.01"}, PQUIRK_NOLUNS}, 468 "PIONEER ", "CD-ROM DR-124X ", "1.01"}, PQUIRK_NOLUNS},
467 {{T_CDROM, T_REMOV, 469 {{T_CDROM, T_REMOV,
468 "PLEXTOR ", "CD-ROM PX-4XCS ", "1.01"}, 470 "PLEXTOR ", "CD-ROM PX-4XCS ", "1.01"},
469 PQUIRK_NOLUNS|PQUIRK_NOSYNC}, 471 PQUIRK_NOLUNS|PQUIRK_NOSYNC},
470 {{T_CDROM, T_REMOV, 472 {{T_CDROM, T_REMOV,
471 "SONY ", "CD-ROM CDU-541 ", ""}, PQUIRK_NOLUNS}, 473 "SONY ", "CD-ROM CDU-541 ", ""}, PQUIRK_NOLUNS},
472 {{T_CDROM, T_REMOV, 474 {{T_CDROM, T_REMOV,
473 "SONY ", "CD-ROM CDU-55S ", ""}, PQUIRK_NOLUNS}, 475 "SONY ", "CD-ROM CDU-55S ", ""}, PQUIRK_NOLUNS},
474 {{T_CDROM, T_REMOV, 476 {{T_CDROM, T_REMOV,
475 "SONY ", "CD-ROM CDU-561 ", ""}, PQUIRK_NOLUNS}, 477 "SONY ", "CD-ROM CDU-561 ", ""}, PQUIRK_NOLUNS},
476 {{T_CDROM, T_REMOV, 478 {{T_CDROM, T_REMOV,
477 "SONY ", "CD-ROM CDU-76S", ""}, 479 "SONY ", "CD-ROM CDU-76S", ""},
478 PQUIRK_NOLUNS|PQUIRK_NOSYNC|PQUIRK_NOWIDE}, 480 PQUIRK_NOLUNS|PQUIRK_NOSYNC|PQUIRK_NOWIDE},
479 {{T_CDROM, T_REMOV, 481 {{T_CDROM, T_REMOV,
480 "SONY ", "CD-ROM CDU-8003A", ""}, PQUIRK_NOLUNS}, 482 "SONY ", "CD-ROM CDU-8003A", ""}, PQUIRK_NOLUNS},
481 {{T_CDROM, T_REMOV, 483 {{T_CDROM, T_REMOV,
482 "SONY ", "CD-ROM CDU-8012 ", ""}, PQUIRK_NOLUNS}, 484 "SONY ", "CD-ROM CDU-8012 ", ""}, PQUIRK_NOLUNS},
483 {{T_CDROM, T_REMOV, 485 {{T_CDROM, T_REMOV,
484 "TEAC ", "CD-ROM ", "1.06"}, PQUIRK_NOLUNS}, 486 "TEAC ", "CD-ROM ", "1.06"}, PQUIRK_NOLUNS},
485 {{T_CDROM, T_REMOV, 487 {{T_CDROM, T_REMOV,
486 "TEAC ", "CD-ROM CD-56S ", "1.0B"}, PQUIRK_NOLUNS}, 488 "TEAC ", "CD-ROM CD-56S ", "1.0B"}, PQUIRK_NOLUNS},
487 {{T_CDROM, T_REMOV, 489 {{T_CDROM, T_REMOV,
488 "TEXEL ", "CD-ROM ", "1.06"}, PQUIRK_NOLUNS}, 490 "TEXEL ", "CD-ROM ", "1.06"}, PQUIRK_NOLUNS},
489 {{T_CDROM, T_REMOV, 491 {{T_CDROM, T_REMOV,
490 "TEXEL ", "CD-ROM DM-XX24 K", "1.09"}, PQUIRK_NOLUNS}, 492 "TEXEL ", "CD-ROM DM-XX24 K", "1.09"}, PQUIRK_NOLUNS},
491 {{T_CDROM, T_REMOV, 493 {{T_CDROM, T_REMOV,
492 "TEXEL ", "CD-ROM DM-XX24 K", "1.10"}, PQUIRK_NOLUNS}, 494 "TEXEL ", "CD-ROM DM-XX24 K", "1.10"}, PQUIRK_NOLUNS},
493 {{T_CDROM, T_REMOV, 495 {{T_CDROM, T_REMOV,
494 "TOSHIBA ", "XM-4101TASUNSLCD", ""}, PQUIRK_NOLUNS|PQUIRK_NOSYNC}, 496 "TOSHIBA ", "XM-4101TASUNSLCD", ""}, PQUIRK_NOLUNS|PQUIRK_NOSYNC},
495 /* "IBM CDRM00201 !F" 0724 is an IBM OEM Toshiba XM-4101BME */ 497 /* "IBM CDRM00201 !F" 0724 is an IBM OEM Toshiba XM-4101BME */
496 {{T_CDROM, T_REMOV, 498 {{T_CDROM, T_REMOV,
497 "IBM ", "CDRM00201 !F", "0724"}, PQUIRK_NOLUNS|PQUIRK_NOSYNC}, 499 "IBM ", "CDRM00201 !F", "0724"}, PQUIRK_NOLUNS|PQUIRK_NOSYNC},
498 {{T_CDROM, T_REMOV, 500 {{T_CDROM, T_REMOV,
499 "ShinaKen", "CD-ROM DM-3x1S", "1.04"}, PQUIRK_NOLUNS}, 501 "ShinaKen", "CD-ROM DM-3x1S", "1.04"}, PQUIRK_NOLUNS},
500 {{T_CDROM, T_REMOV, 502 {{T_CDROM, T_REMOV,
501 "JVC ", "R2626", ""}, PQUIRK_NOLUNS}, 503 "JVC ", "R2626", ""}, PQUIRK_NOLUNS},
502 {{T_CDROM, T_REMOV, 504 {{T_CDROM, T_REMOV,
503 "YAMAHA", "CRW8424S", ""}, PQUIRK_NOLUNS}, 505 "YAMAHA", "CRW8424S", ""}, PQUIRK_NOLUNS},
504 {{T_CDROM, T_REMOV, 506 {{T_CDROM, T_REMOV,
505 "NEC ", "CD-ROM DRIVE:222", ""}, PQUIRK_NOLUNS|PQUIRK_NOSYNC}, 507 "NEC ", "CD-ROM DRIVE:222", ""}, PQUIRK_NOLUNS|PQUIRK_NOSYNC},
506 508
507 {{T_DIRECT, T_FIXED, 509 {{T_DIRECT, T_FIXED,
508 "MICROP ", "1588-15MBSUN0669", ""}, PQUIRK_AUTOSAVE}, 510 "MICROP ", "1588-15MBSUN0669", ""}, PQUIRK_AUTOSAVE},
509 {{T_DIRECT, T_FIXED, 511 {{T_DIRECT, T_FIXED,
510 "MICROP ", "2217-15MQ1091501", ""}, PQUIRK_NOSYNCCACHE}, 512 "MICROP ", "2217-15MQ1091501", ""}, PQUIRK_NOSYNCCACHE},
511 {{T_OPTICAL, T_REMOV, 513 {{T_OPTICAL, T_REMOV,
512 "EPSON ", "OMD-5010 ", "3.08"}, PQUIRK_NOLUNS}, 514 "EPSON ", "OMD-5010 ", "3.08"}, PQUIRK_NOLUNS},
513 {{T_DIRECT, T_FIXED, 515 {{T_DIRECT, T_FIXED,
514 "ADAPTEC ", "AEC-4412BD", "1.2A"}, PQUIRK_NOMODESENSE}, 516 "ADAPTEC ", "AEC-4412BD", "1.2A"}, PQUIRK_NOMODESENSE},
515 {{T_DIRECT, T_FIXED, 517 {{T_DIRECT, T_FIXED,
516 "ADAPTEC ", "ACB-4000", ""}, PQUIRK_FORCELUNS|PQUIRK_AUTOSAVE|PQUIRK_NOMODESENSE}, 518 "ADAPTEC ", "ACB-4000", ""}, PQUIRK_FORCELUNS|PQUIRK_AUTOSAVE|PQUIRK_NOMODESENSE},
517 {{T_DIRECT, T_FIXED, 519 {{T_DIRECT, T_FIXED,
518 "DEC ", "RZ55 (C) DEC", ""}, PQUIRK_AUTOSAVE}, 520 "DEC ", "RZ55 (C) DEC", ""}, PQUIRK_AUTOSAVE},
519 {{T_DIRECT, T_FIXED, 521 {{T_DIRECT, T_FIXED,
520 "EMULEX ", "MD21/S2 ESDI", "A00"}, 522 "EMULEX ", "MD21/S2 ESDI", "A00"},
521 PQUIRK_FORCELUNS|PQUIRK_AUTOSAVE}, 523 PQUIRK_FORCELUNS|PQUIRK_AUTOSAVE},
522 {{T_DIRECT, T_FIXED, 524 {{T_DIRECT, T_FIXED,
523 "MICROP", "1548-15MZ1077801", "HZ2P"}, PQUIRK_NOTAG}, 525 "MICROP", "1548-15MZ1077801", "HZ2P"}, PQUIRK_NOTAG},
524 {{T_DIRECT, T_FIXED, 526 {{T_DIRECT, T_FIXED,
525 "HP ", "C372", ""}, PQUIRK_NOTAG}, 527 "HP ", "C372", ""}, PQUIRK_NOTAG},
526 {{T_DIRECT, T_FIXED, 528 {{T_DIRECT, T_FIXED,
527 "IBMRAID ", "0662S", ""}, PQUIRK_AUTOSAVE}, 529 "IBMRAID ", "0662S", ""}, PQUIRK_AUTOSAVE},
528 {{T_DIRECT, T_FIXED, 530 {{T_DIRECT, T_FIXED,
529 "IBM ", "0663H", ""}, PQUIRK_AUTOSAVE}, 531 "IBM ", "0663H", ""}, PQUIRK_AUTOSAVE},
530 {{T_DIRECT, T_FIXED, 532 {{T_DIRECT, T_FIXED,
531 "IBM", "0664", ""}, PQUIRK_AUTOSAVE}, 533 "IBM", "0664", ""}, PQUIRK_AUTOSAVE},
532 {{T_DIRECT, T_FIXED, 534 {{T_DIRECT, T_FIXED,
533 /* improperly report DT-only sync mode */ 535 /* improperly report DT-only sync mode */
534 "IBM ", "DXHS36D", ""}, 536 "IBM ", "DXHS36D", ""},
535 PQUIRK_CAP_SYNC|PQUIRK_CAP_WIDE16}, 537 PQUIRK_CAP_SYNC|PQUIRK_CAP_WIDE16},
536 {{T_DIRECT, T_FIXED, 538 {{T_DIRECT, T_FIXED,
537 "IBM ", "DXHS18Y", ""}, 539 "IBM ", "DXHS18Y", ""},
538 PQUIRK_CAP_SYNC|PQUIRK_CAP_WIDE16}, 540 PQUIRK_CAP_SYNC|PQUIRK_CAP_WIDE16},
539 {{T_DIRECT, T_FIXED, 541 {{T_DIRECT, T_FIXED,
540 "IBM ", "H3171-S2", ""}, 542 "IBM ", "H3171-S2", ""},
541 PQUIRK_NOLUNS|PQUIRK_AUTOSAVE}, 543 PQUIRK_NOLUNS|PQUIRK_AUTOSAVE},
542 {{T_DIRECT, T_FIXED, 544 {{T_DIRECT, T_FIXED,
543 "IBM ", "KZ-C", ""}, PQUIRK_AUTOSAVE}, 545 "IBM ", "KZ-C", ""}, PQUIRK_AUTOSAVE},
544 /* Broken IBM disk */ 546 /* Broken IBM disk */
545 {{T_DIRECT, T_FIXED, 547 {{T_DIRECT, T_FIXED,
546 "" , "DFRSS2F", ""}, PQUIRK_AUTOSAVE}, 548 "" , "DFRSS2F", ""}, PQUIRK_AUTOSAVE},
547 {{T_DIRECT, T_FIXED, 549 {{T_DIRECT, T_FIXED,
548 "Initio ", "", ""}, PQUIRK_NOBIGMODESENSE}, 550 "Initio ", "", ""}, PQUIRK_NOBIGMODESENSE},
549 {{T_DIRECT, T_REMOV, 551 {{T_DIRECT, T_REMOV,
550 "MPL ", "MC-DISK- ", ""}, PQUIRK_NOLUNS}, 552 "MPL ", "MC-DISK- ", ""}, PQUIRK_NOLUNS},
551 {{T_DIRECT, T_FIXED, 553 {{T_DIRECT, T_FIXED,
552 "MAXTOR ", "XT-3280 ", ""}, PQUIRK_NOLUNS}, 554 "MAXTOR ", "XT-3280 ", ""}, PQUIRK_NOLUNS},
553 {{T_DIRECT, T_FIXED, 555 {{T_DIRECT, T_FIXED,
554 "MAXTOR ", "XT-4380S ", ""}, PQUIRK_NOLUNS}, 556 "MAXTOR ", "XT-4380S ", ""}, PQUIRK_NOLUNS},
555 {{T_DIRECT, T_FIXED, 557 {{T_DIRECT, T_FIXED,
556 "MAXTOR ", "MXT-1240S ", ""}, PQUIRK_NOLUNS}, 558 "MAXTOR ", "MXT-1240S ", ""}, PQUIRK_NOLUNS},
557 {{T_DIRECT, T_FIXED, 559 {{T_DIRECT, T_FIXED,
558 "MAXTOR ", "XT-4170S ", ""}, PQUIRK_NOLUNS}, 560 "MAXTOR ", "XT-4170S ", ""}, PQUIRK_NOLUNS},
559 {{T_DIRECT, T_FIXED, 561 {{T_DIRECT, T_FIXED,
560 "MAXTOR ", "XT-8760S", ""}, PQUIRK_NOLUNS}, 562 "MAXTOR ", "XT-8760S", ""}, PQUIRK_NOLUNS},
561 {{T_DIRECT, T_FIXED, 563 {{T_DIRECT, T_FIXED,
562 "MAXTOR ", "LXT-213S ", ""}, PQUIRK_NOLUNS}, 564 "MAXTOR ", "LXT-213S ", ""}, PQUIRK_NOLUNS},
563 {{T_DIRECT, T_FIXED, 565 {{T_DIRECT, T_FIXED,
564 "MAXTOR ", "LXT-213S SUN0207", ""}, PQUIRK_NOLUNS}, 566 "MAXTOR ", "LXT-213S SUN0207", ""}, PQUIRK_NOLUNS},
565 {{T_DIRECT, T_FIXED, 567 {{T_DIRECT, T_FIXED,
566 "MAXTOR ", "LXT-200S ", ""}, PQUIRK_NOLUNS}, 568 "MAXTOR ", "LXT-200S ", ""}, PQUIRK_NOLUNS},
567 {{T_DIRECT, T_FIXED, 569 {{T_DIRECT, T_FIXED,
568 "MEGADRV ", "EV1000", ""}, PQUIRK_NOMODESENSE}, 570 "MEGADRV ", "EV1000", ""}, PQUIRK_NOMODESENSE},
569 {{T_DIRECT, T_FIXED, 571 {{T_DIRECT, T_FIXED,
570 "MICROP", "1991-27MZ", ""}, PQUIRK_NOTAG}, 572 "MICROP", "1991-27MZ", ""}, PQUIRK_NOTAG},
571 {{T_DIRECT, T_FIXED, 573 {{T_DIRECT, T_FIXED,
572 "MST ", "SnapLink ", ""}, PQUIRK_NOLUNS}, 574 "MST ", "SnapLink ", ""}, PQUIRK_NOLUNS},
573 {{T_DIRECT, T_FIXED, 575 {{T_DIRECT, T_FIXED,
574 "NEC ", "D3847 ", "0307"}, PQUIRK_NOLUNS}, 576 "NEC ", "D3847 ", "0307"}, PQUIRK_NOLUNS},
575 {{T_DIRECT, T_FIXED, 577 {{T_DIRECT, T_FIXED,
576 "QUANTUM ", "ELS85S ", ""}, PQUIRK_AUTOSAVE}, 578 "QUANTUM ", "ELS85S ", ""}, PQUIRK_AUTOSAVE},
577 {{T_DIRECT, T_FIXED, 579 {{T_DIRECT, T_FIXED,
578 "QUANTUM ", "LPS525S ", ""}, PQUIRK_NOLUNS}, 580 "QUANTUM ", "LPS525S ", ""}, PQUIRK_NOLUNS},
579 {{T_DIRECT, T_FIXED, 581 {{T_DIRECT, T_FIXED,
580 "QUANTUM ", "P105S 910-10-94x", ""}, PQUIRK_NOLUNS}, 582 "QUANTUM ", "P105S 910-10-94x", ""}, PQUIRK_NOLUNS},
581 {{T_DIRECT, T_FIXED, 583 {{T_DIRECT, T_FIXED,
582 "QUANTUM ", "PD1225S ", ""}, PQUIRK_NOLUNS}, 584 "QUANTUM ", "PD1225S ", ""}, PQUIRK_NOLUNS},
583 {{T_DIRECT, T_FIXED, 585 {{T_DIRECT, T_FIXED,
584 "QUANTUM ", "PD210S SUN0207", ""}, PQUIRK_NOLUNS}, 586 "QUANTUM ", "PD210S SUN0207", ""}, PQUIRK_NOLUNS},
585 {{T_DIRECT, T_FIXED, 587 {{T_DIRECT, T_FIXED,
586 "QUANTUM ", "ATLAS IV 9 WLS", "0A0A"}, PQUIRK_CAP_NODT}, 588 "QUANTUM ", "ATLAS IV 9 WLS", "0A0A"}, PQUIRK_CAP_NODT},
587 {{T_DIRECT, T_FIXED, 589 {{T_DIRECT, T_FIXED,
588 "RODIME ", "RO3000S ", ""}, PQUIRK_NOLUNS}, 590 "RODIME ", "RO3000S ", ""}, PQUIRK_NOLUNS},
589 {{T_DIRECT, T_FIXED, 591 {{T_DIRECT, T_FIXED,
590 "SEAGATE ", "ST125N ", ""}, PQUIRK_NOLUNS}, 592 "SEAGATE ", "ST125N ", ""}, PQUIRK_NOLUNS},
591 {{T_DIRECT, T_FIXED, 593 {{T_DIRECT, T_FIXED,
592 "SEAGATE ", "ST157N ", ""}, PQUIRK_NOLUNS}, 594 "SEAGATE ", "ST157N ", ""}, PQUIRK_NOLUNS},
593 {{T_DIRECT, T_FIXED, 595 {{T_DIRECT, T_FIXED,
594 "SEAGATE ", "ST296 ", ""}, PQUIRK_NOLUNS}, 596 "SEAGATE ", "ST296 ", ""}, PQUIRK_NOLUNS},
595 {{T_DIRECT, T_FIXED, 597 {{T_DIRECT, T_FIXED,
596 "SEAGATE ", "ST296N ", ""}, PQUIRK_NOLUNS}, 598 "SEAGATE ", "ST296N ", ""}, PQUIRK_NOLUNS},
597 {{T_DIRECT, T_FIXED, 599 {{T_DIRECT, T_FIXED,
598 "SEAGATE ", "ST318404LC ", ""}, PQUIRK_NOLUNS}, 600 "SEAGATE ", "ST318404LC ", ""}, PQUIRK_NOLUNS},
599 {{T_DIRECT, T_FIXED, 601 {{T_DIRECT, T_FIXED,
600 "SEAGATE ", "ST15150N ", ""}, PQUIRK_NOTAG}, 602 "SEAGATE ", "ST15150N ", ""}, PQUIRK_NOTAG},
601 {{T_DIRECT, T_FIXED, 603 {{T_DIRECT, T_FIXED,
602 "SEAGATE ", "ST19171", ""}, PQUIRK_NOMODESENSE}, 604 "SEAGATE ", "ST19171", ""}, PQUIRK_NOMODESENSE},
603 {{T_DIRECT, T_FIXED, 605 {{T_DIRECT, T_FIXED,
604 "SEAGATE ", "ST32430N", ""}, PQUIRK_CAP_SYNC}, 606 "SEAGATE ", "ST32430N", ""}, PQUIRK_CAP_SYNC},
605 {{T_DIRECT, T_FIXED, 607 {{T_DIRECT, T_FIXED,
606 "SEAGATE ", "ST34501FC ", ""}, PQUIRK_NOMODESENSE}, 608 "SEAGATE ", "ST34501FC ", ""}, PQUIRK_NOMODESENSE},
607 {{T_DIRECT, T_FIXED, 609 {{T_DIRECT, T_FIXED,
608 "SEAGATE ", "SX910800N", ""}, PQUIRK_NOTAG}, 610 "SEAGATE ", "SX910800N", ""}, PQUIRK_NOTAG},
609 {{T_DIRECT, T_FIXED, 611 {{T_DIRECT, T_FIXED,
610 "TOSHIBA ", "MK538FB ", "6027"}, PQUIRK_NOLUNS}, 612 "TOSHIBA ", "MK538FB ", "6027"}, PQUIRK_NOLUNS},
611 {{T_DIRECT, T_FIXED, 613 {{T_DIRECT, T_FIXED,
612 "MICROP ", "1924", ""}, PQUIRK_CAP_SYNC}, 614 "MICROP ", "1924", ""}, PQUIRK_CAP_SYNC},
613 {{T_DIRECT, T_FIXED, 615 {{T_DIRECT, T_FIXED,
614 "FUJITSU ", "M2266", ""}, PQUIRK_CAP_SYNC}, 616 "FUJITSU ", "M2266", ""}, PQUIRK_CAP_SYNC},
615 {{T_DIRECT, T_FIXED, 617 {{T_DIRECT, T_FIXED,
616 "FUJITSU ", "M2624S-512 ", ""}, PQUIRK_CAP_SYNC}, 618 "FUJITSU ", "M2624S-512 ", ""}, PQUIRK_CAP_SYNC},
617 {{T_DIRECT, T_FIXED, 619 {{T_DIRECT, T_FIXED,
618 "SEAGATE ", "SX336704LC" , ""}, PQUIRK_CAP_SYNC | PQUIRK_CAP_WIDE16}, 620 "SEAGATE ", "SX336704LC" , ""}, PQUIRK_CAP_SYNC | PQUIRK_CAP_WIDE16},
619 {{T_DIRECT, T_FIXED, 621 {{T_DIRECT, T_FIXED,
620 "SEAGATE ", "SX173404LC", ""}, PQUIRK_CAP_SYNC | PQUIRK_CAP_WIDE16}, 622 "SEAGATE ", "SX173404LC", ""}, PQUIRK_CAP_SYNC | PQUIRK_CAP_WIDE16},
621 623
622 {{T_DIRECT, T_REMOV, 624 {{T_DIRECT, T_REMOV,
623 "IOMEGA", "ZIP 100", "J.03"}, PQUIRK_NOLUNS|PQUIRK_NOSYNC}, 625 "IOMEGA", "ZIP 100", "J.03"}, PQUIRK_NOLUNS|PQUIRK_NOSYNC},
624 {{T_DIRECT, T_REMOV, 626 {{T_DIRECT, T_REMOV,
625 "INSITE", "I325VM", ""}, PQUIRK_NOLUNS}, 627 "INSITE", "I325VM", ""}, PQUIRK_NOLUNS},
626 628
627 /* XXX: QIC-36 tape behind Emulex adapter. Very broken. */ 629 /* XXX: QIC-36 tape behind Emulex adapter. Very broken. */
628 {{T_SEQUENTIAL, T_REMOV, 630 {{T_SEQUENTIAL, T_REMOV,
629 " ", " ", " "}, PQUIRK_NOLUNS}, 631 " ", " ", " "}, PQUIRK_NOLUNS},
630 {{T_SEQUENTIAL, T_REMOV, 632 {{T_SEQUENTIAL, T_REMOV,
631 "EMULEX ", "MT-02 QIC ", ""}, PQUIRK_NOLUNS}, 633 "EMULEX ", "MT-02 QIC ", ""}, PQUIRK_NOLUNS},
632 {{T_SEQUENTIAL, T_REMOV, 634 {{T_SEQUENTIAL, T_REMOV,
633 "CALIPER ", "CP150 ", ""}, PQUIRK_NOLUNS}, 635 "CALIPER ", "CP150 ", ""}, PQUIRK_NOLUNS},
634 {{T_SEQUENTIAL, T_REMOV, 636 {{T_SEQUENTIAL, T_REMOV,
635 "EXABYTE ", "EXB-8200 ", ""}, PQUIRK_NOLUNS}, 637 "EXABYTE ", "EXB-8200 ", ""}, PQUIRK_NOLUNS},
636 {{T_SEQUENTIAL, T_REMOV, 638 {{T_SEQUENTIAL, T_REMOV,
637 "SONY ", "GY-10C ", ""}, PQUIRK_NOLUNS}, 639 "SONY ", "GY-10C ", ""}, PQUIRK_NOLUNS},
638 {{T_SEQUENTIAL, T_REMOV, 640 {{T_SEQUENTIAL, T_REMOV,
639 "SONY ", "SDT-2000 ", "2.09"}, PQUIRK_NOLUNS}, 641 "SONY ", "SDT-2000 ", "2.09"}, PQUIRK_NOLUNS},
640 {{T_SEQUENTIAL, T_REMOV, 642 {{T_SEQUENTIAL, T_REMOV,
641 "SONY ", "SDT-5000 ", "3."}, PQUIRK_NOSYNC|PQUIRK_NOWIDE}, 643 "SONY ", "SDT-5000 ", "3."}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
642 {{T_SEQUENTIAL, T_REMOV, 644 {{T_SEQUENTIAL, T_REMOV,
643 "SONY ", "SDT-5200 ", "3."}, PQUIRK_NOLUNS}, 645 "SONY ", "SDT-5200 ", "3."}, PQUIRK_NOLUNS},
644 {{T_SEQUENTIAL, T_REMOV, 646 {{T_SEQUENTIAL, T_REMOV,
645 "TANDBERG", " TDC 3600 ", ""}, PQUIRK_NOLUNS}, 647 "TANDBERG", " TDC 3600 ", ""}, PQUIRK_NOLUNS},
646 /* Following entry reported as a Tandberg 3600; ref. PR1933 */ 648 /* Following entry reported as a Tandberg 3600; ref. PR1933 */
647 {{T_SEQUENTIAL, T_REMOV, 649 {{T_SEQUENTIAL, T_REMOV,
648 "ARCHIVE ", "VIPER 150 21247", ""}, PQUIRK_NOLUNS}, 650 "ARCHIVE ", "VIPER 150 21247", ""}, PQUIRK_NOLUNS},
649 /* Following entry for a Cipher ST150S; ref. PR4171 */ 651 /* Following entry for a Cipher ST150S; ref. PR4171 */
650 {{T_SEQUENTIAL, T_REMOV, 652 {{T_SEQUENTIAL, T_REMOV,
651 "ARCHIVE ", "VIPER 1500 21247", "2.2G"}, PQUIRK_NOLUNS}, 653 "ARCHIVE ", "VIPER 1500 21247", "2.2G"}, PQUIRK_NOLUNS},
652 {{T_SEQUENTIAL, T_REMOV, 654 {{T_SEQUENTIAL, T_REMOV,
653 "ARCHIVE ", "Python 28454-XXX", ""}, PQUIRK_NOLUNS}, 655 "ARCHIVE ", "Python 28454-XXX", ""}, PQUIRK_NOLUNS},
654 {{T_SEQUENTIAL, T_REMOV, 656 {{T_SEQUENTIAL, T_REMOV,
655 "WANGTEK ", "5099ES SCSI", ""}, PQUIRK_NOLUNS}, 657 "WANGTEK ", "5099ES SCSI", ""}, PQUIRK_NOLUNS},
656 {{T_SEQUENTIAL, T_REMOV, 658 {{T_SEQUENTIAL, T_REMOV,
657 "WANGTEK ", "5150ES SCSI", ""}, PQUIRK_NOLUNS}, 659 "WANGTEK ", "5150ES SCSI", ""}, PQUIRK_NOLUNS},
658 {{T_SEQUENTIAL, T_REMOV, 660 {{T_SEQUENTIAL, T_REMOV,
659 "WANGTEK ", "SCSI-36", ""}, PQUIRK_NOLUNS}, 661 "WANGTEK ", "SCSI-36", ""}, PQUIRK_NOLUNS},
660 {{T_SEQUENTIAL, T_REMOV, 662 {{T_SEQUENTIAL, T_REMOV,
661 "WangDAT ", "Model 1300 ", "02.4"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE}, 663 "WangDAT ", "Model 1300 ", "02.4"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
662 {{T_SEQUENTIAL, T_REMOV, 664 {{T_SEQUENTIAL, T_REMOV,
663 "WangDAT ", "Model 2600 ", "01.7"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE}, 665 "WangDAT ", "Model 2600 ", "01.7"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
664 {{T_SEQUENTIAL, T_REMOV, 666 {{T_SEQUENTIAL, T_REMOV,
665 "WangDAT ", "Model 3200 ", "02.2"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE}, 667 "WangDAT ", "Model 3200 ", "02.2"}, PQUIRK_NOSYNC|PQUIRK_NOWIDE},
666 {{T_SEQUENTIAL, T_REMOV, 668 {{T_SEQUENTIAL, T_REMOV,
667 "TEAC ", "MT-2ST/N50 ", ""}, PQUIRK_NOLUNS}, 669 "TEAC ", "MT-2ST/N50 ", ""}, PQUIRK_NOLUNS},
668 670
669 {{T_SCANNER, T_FIXED, 671 {{T_SCANNER, T_FIXED,
670 "RICOH ", "IS60 ", "1R08"}, PQUIRK_NOLUNS}, 672 "RICOH ", "IS60 ", "1R08"}, PQUIRK_NOLUNS},
671 {{T_SCANNER, T_FIXED, 673 {{T_SCANNER, T_FIXED,
672 "UMAX ", "Astra 1200S ", "V2.9"}, PQUIRK_NOLUNS}, 674 "UMAX ", "Astra 1200S ", "V2.9"}, PQUIRK_NOLUNS},
673 {{T_SCANNER, T_FIXED, 675 {{T_SCANNER, T_FIXED,
674 "UMAX ", "Astra 1220S ", ""}, PQUIRK_NOLUNS}, 676 "UMAX ", "Astra 1220S ", ""}, PQUIRK_NOLUNS},
675 {{T_SCANNER, T_FIXED, 677 {{T_SCANNER, T_FIXED,
676 "UMAX ", "UMAX S-6E ", "V2.0"}, PQUIRK_NOLUNS}, 678 "UMAX ", "UMAX S-6E ", "V2.0"}, PQUIRK_NOLUNS},
677 {{T_SCANNER, T_FIXED, 679 {{T_SCANNER, T_FIXED,
678 "UMAX ", "UMAX S-12 ", "V2.1"}, PQUIRK_NOLUNS}, 680 "UMAX ", "UMAX S-12 ", "V2.1"}, PQUIRK_NOLUNS},
679 {{T_SCANNER, T_FIXED, 681 {{T_SCANNER, T_FIXED,
680 "ULTIMA ", "A6000C ", ""}, PQUIRK_NOLUNS}, 682 "ULTIMA ", "A6000C ", ""}, PQUIRK_NOLUNS},
681 {{T_PROCESSOR, T_FIXED, 683 {{T_PROCESSOR, T_FIXED,
682 "ESG-SHV", "SCA HSBP M15", ""}, PQUIRK_NOLUNS}, 684 "ESG-SHV", "SCA HSBP M15", ""}, PQUIRK_NOLUNS},
683 {{T_PROCESSOR, T_FIXED, 685 {{T_PROCESSOR, T_FIXED,
684 "SYMBIOS", "", ""}, PQUIRK_NOLUNS}, 686 "SYMBIOS", "", ""}, PQUIRK_NOLUNS},
685 {{T_PROCESSOR, T_FIXED, 687 {{T_PROCESSOR, T_FIXED,
686 "LITRONIC", "PCMCIA ", ""}, PQUIRK_NOLUNS}, 688 "LITRONIC", "PCMCIA ", ""}, PQUIRK_NOLUNS},
687 {{T_CHANGER, T_REMOV, 689 {{T_CHANGER, T_REMOV,
688 "SONY ", "CDL1100 ", ""}, PQUIRK_NOLUNS}, 690 "SONY ", "CDL1100 ", ""}, PQUIRK_NOLUNS},
689 {{T_ENCLOSURE, T_FIXED, 691 {{T_ENCLOSURE, T_FIXED,
690 "SUN ", "SENA ", ""}, PQUIRK_NOLUNS}, 692 "SUN ", "SENA ", ""}, PQUIRK_NOLUNS},
691}; 693};
692 694
693/* 695/*
694 * given a target and lun, ask the device what 696 * given a target and lun, ask the device what
695 * it is, and find the correct driver table 697 * it is, and find the correct driver table
696 * entry. 698 * entry.
697 */ 699 */
698static int 700static int
699scsi_probe_device(struct scsibus_softc *sc, int target, int lun) 701scsi_probe_device(struct scsibus_softc *sc, int target, int lun)
700{ 702{
701 struct scsipi_channel *chan = sc->sc_channel; 703 struct scsipi_channel *chan = sc->sc_channel;
702 struct scsipi_periph *periph; 704 struct scsipi_periph *periph;
703 struct scsipi_inquiry_data inqbuf; 705 struct scsipi_inquiry_data inqbuf;
704 const struct scsi_quirk_inquiry_pattern *finger; 706 const struct scsi_quirk_inquiry_pattern *finger;
705 int checkdtype, priority, docontinue, quirks; 707 int checkdtype, priority, docontinue, quirks;
706 struct scsipibus_attach_args sa; 708 struct scsipibus_attach_args sa;
707 cfdata_t cf; 709 cfdata_t cf;
708 int locs[SCSIBUSCF_NLOCS]; 710 int locs[SCSIBUSCF_NLOCS];
709 device_t chld; 711 device_t chld;
710 712
711 /* 713 /*
712 * Assume no more luns to search after this one. 714 * Assume no more luns to search after this one.
713 * If we successfully get Inquiry data and after 715 * If we successfully get Inquiry data and after
714 * merging quirks we find we can probe for more 716 * merging quirks we find we can probe for more
715 * luns, we will. 717 * luns, we will.
716 */ 718 */
717 docontinue = 0; 719 docontinue = 0;
718 720
719 /* Skip this slot if it is already attached. */ 721 /* Skip this slot if it is already attached. */
720 if (scsipi_lookup_periph(chan, target, lun) != NULL) 722 if (scsipi_lookup_periph(chan, target, lun) != NULL)
721 return (docontinue); 723 return (docontinue);
722 724
723 periph = scsipi_alloc_periph(M_NOWAIT); 725 periph = scsipi_alloc_periph(M_NOWAIT);
724 if (periph == NULL) { 726 if (periph == NULL) {
725#ifdef DIAGNOSTIC 727#ifdef DIAGNOSTIC
726 aprint_error_dev(sc->sc_dev, 728 aprint_error_dev(sc->sc_dev,
727 "cannot allocate periph for target %d lun %d\n", 729 "cannot allocate periph for target %d lun %d\n",
728 target, lun); 730 target, lun);
729#endif 731#endif
730 return (ENOMEM); 732 return (ENOMEM);
731 } 733 }
732 periph->periph_channel = chan; 734 periph->periph_channel = chan;
733 periph->periph_switch = &scsi_probe_dev; 735 periph->periph_switch = &scsi_probe_dev;
734 736
735 periph->periph_target = target; 737 periph->periph_target = target;
736 periph->periph_lun = lun; 738 periph->periph_lun = lun;
737 periph->periph_quirks = chan->chan_defquirks; 739 periph->periph_quirks = chan->chan_defquirks;
738 740
739#ifdef SCSIPI_DEBUG 741#ifdef SCSIPI_DEBUG
740 if (SCSIPI_DEBUG_TYPE == SCSIPI_BUSTYPE_SCSI && 742 if (SCSIPI_DEBUG_TYPE == SCSIPI_BUSTYPE_SCSI &&
741 SCSIPI_DEBUG_TARGET == target && 743 SCSIPI_DEBUG_TARGET == target &&
742 SCSIPI_DEBUG_LUN == lun) 744 SCSIPI_DEBUG_LUN == lun)
743 periph->periph_dbflags |= SCSIPI_DEBUG_FLAGS; 745 periph->periph_dbflags |= SCSIPI_DEBUG_FLAGS;
744#endif 746#endif
745 747
746 /* 748 /*
747 * Ask the device what it is 749 * Ask the device what it is
748 */ 750 */
749 751
750#ifdef SCSI_2_DEF 752#ifdef SCSI_2_DEF
751 /* some devices need to be told to go to SCSI2 */ 753 /* some devices need to be told to go to SCSI2 */
752 /* However some just explode if you tell them this.. leave it out */ 754 /* However some just explode if you tell them this.. leave it out */
753 scsi_change_def(periph, XS_CTL_DISCOVERY | XS_CTL_SILENT); 755 scsi_change_def(periph, XS_CTL_DISCOVERY | XS_CTL_SILENT);
754#endif /* SCSI_2_DEF */ 756#endif /* SCSI_2_DEF */
755 757
756 /* Now go ask the device all about itself. */ 758 /* Now go ask the device all about itself. */
757 memset(&inqbuf, 0, sizeof(inqbuf)); 759 memset(&inqbuf, 0, sizeof(inqbuf));
758 { 760 {
759 u_int8_t *extension = &inqbuf.flags1; 761 u_int8_t *extension = &inqbuf.flags1;
760 int len = 0; 762 int len = 0;
761 while (len < 3) 763 while (len < 3)
762 extension[len++] = '\0'; 764 extension[len++] = '\0';
763 while (len < 3 + 28) 765 while (len < 3 + 28)
764 extension[len++] = ' '; 766 extension[len++] = ' ';
765 while (len < 3 + 28 + 20) 767 while (len < 3 + 28 + 20)
766 extension[len++] = '\0'; 768 extension[len++] = '\0';
767 while (len < 3 + 28 + 20 + 1) 769 while (len < 3 + 28 + 20 + 1)
768 extension[len++] = '\0'; 770 extension[len++] = '\0';
769 while (len < 3 + 28 + 20 + 1 + 1) 771 while (len < 3 + 28 + 20 + 1 + 1)
770 extension[len++] = '\0'; 772 extension[len++] = '\0';
771 while (len < 3 + 28 + 20 + 1 + 1 + (8*2)) 773 while (len < 3 + 28 + 20 + 1 + 1 + (8*2))
772 extension[len++] = ' '; 774 extension[len++] = ' ';
773 } 775 }
774 if (scsipi_inquire(periph, &inqbuf, XS_CTL_DISCOVERY | XS_CTL_SILENT)) 776 if (scsipi_inquire(periph, &inqbuf, XS_CTL_DISCOVERY | XS_CTL_SILENT))
775 goto bad; 777 goto bad;
776 778
777 periph->periph_type = inqbuf.device & SID_TYPE; 779 periph->periph_type = inqbuf.device & SID_TYPE;
778 if (inqbuf.dev_qual2 & SID_REMOVABLE) 780 if (inqbuf.dev_qual2 & SID_REMOVABLE)
779 periph->periph_flags |= PERIPH_REMOVABLE; 781 periph->periph_flags |= PERIPH_REMOVABLE;
780 periph->periph_version = inqbuf.version & SID_ANSII; 782 periph->periph_version = inqbuf.version & SID_ANSII;
781 783
782 /* 784 /*
783 * Any device qualifier that has the top bit set (qualifier&4 != 0) 785 * Any device qualifier that has the top bit set (qualifier&4 != 0)
784 * is vendor specific and won't match in this switch. 786 * is vendor specific and won't match in this switch.
785 * All we do here is throw out bad/negative responses. 787 * All we do here is throw out bad/negative responses.
786 */ 788 */
787 checkdtype = 0; 789 checkdtype = 0;
788 switch (inqbuf.device & SID_QUAL) { 790 switch (inqbuf.device & SID_QUAL) {
789 case SID_QUAL_LU_PRESENT: 791 case SID_QUAL_LU_PRESENT:
790 checkdtype = 1; 792 checkdtype = 1;
791 break; 793 break;
792 794
793 case SID_QUAL_LU_NOTPRESENT: 795 case SID_QUAL_LU_NOTPRESENT:
794 case SID_QUAL_reserved: 796 case SID_QUAL_reserved:
795 case SID_QUAL_LU_NOT_SUPP: 797 case SID_QUAL_LU_NOT_SUPP:
796 goto bad; 798 goto bad;
797 799
798 default: 800 default:
799 break; 801 break;
800 } 802 }
801 803
802 /* Let the adapter driver handle the device separatley if it wants. */ 804 /* Let the adapter driver handle the device separatley if it wants. */
803 if (chan->chan_adapter->adapt_accesschk != NULL && 805 if (chan->chan_adapter->adapt_accesschk != NULL &&
804 (*chan->chan_adapter->adapt_accesschk)(periph, &sa.sa_inqbuf)) 806 (*chan->chan_adapter->adapt_accesschk)(periph, &sa.sa_inqbuf))
805 goto bad; 807 goto bad;
806 808
807 if (checkdtype) { 809 if (checkdtype) {
808 switch (periph->periph_type) { 810 switch (periph->periph_type) {
809 case T_DIRECT: 811 case T_DIRECT:
810 case T_SEQUENTIAL: 812 case T_SEQUENTIAL:
811 case T_PRINTER: 813 case T_PRINTER:
812 case T_PROCESSOR: 814 case T_PROCESSOR:
813 case T_WORM: 815 case T_WORM:
814 case T_CDROM: 816 case T_CDROM:
815 case T_SCANNER: 817 case T_SCANNER:
816 case T_OPTICAL: 818 case T_OPTICAL:
817 case T_CHANGER: 819 case T_CHANGER:
818 case T_COMM: 820 case T_COMM:
819 case T_IT8_1: 821 case T_IT8_1:
820 case T_IT8_2: 822 case T_IT8_2:
821 case T_STORARRAY: 823 case T_STORARRAY:
822 case T_ENCLOSURE: 824 case T_ENCLOSURE:
823 case T_SIMPLE_DIRECT: 825 case T_SIMPLE_DIRECT:
824 case T_OPTIC_CARD_RW: 826 case T_OPTIC_CARD_RW:
825 case T_OBJECT_STORED: 827 case T_OBJECT_STORED:
826 default: 828 default:
827 break; 829 break;
828 case T_NODEVICE: 830 case T_NODEVICE:
829 goto bad; 831 goto bad;
830 } 832 }
831 } 833 }
832 834
833 sa.sa_periph = periph; 835 sa.sa_periph = periph;
834 sa.sa_inqbuf.type = inqbuf.device; 836 sa.sa_inqbuf.type = inqbuf.device;
835 sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ? 837 sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ?
836 T_REMOV : T_FIXED; 838 T_REMOV : T_FIXED;
837 sa.sa_inqbuf.vendor = inqbuf.vendor; 839 sa.sa_inqbuf.vendor = inqbuf.vendor;
838 sa.sa_inqbuf.product = inqbuf.product; 840 sa.sa_inqbuf.product = inqbuf.product;
839 sa.sa_inqbuf.revision = inqbuf.revision; 841 sa.sa_inqbuf.revision = inqbuf.revision;
840 sa.scsipi_info.scsi_version = inqbuf.version; 842 sa.scsipi_info.scsi_version = inqbuf.version;
841 sa.sa_inqptr = &inqbuf; 843 sa.sa_inqptr = &inqbuf;
842 844
843 finger = scsipi_inqmatch( 845 finger = scsipi_inqmatch(
844 &sa.sa_inqbuf, scsi_quirk_patterns, 846 &sa.sa_inqbuf, scsi_quirk_patterns,
845 sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]), 847 sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
846 sizeof(scsi_quirk_patterns[0]), &priority); 848 sizeof(scsi_quirk_patterns[0]), &priority);
847 849
848 if (finger != NULL) 850 if (finger != NULL)
849 quirks = finger->quirks; 851 quirks = finger->quirks;
850 else 852 else
851 quirks = 0; 853 quirks = 0;
852 854
853 /* 855 /*
854 * Determine the operating mode capabilities of the device. 856 * Determine the operating mode capabilities of the device.
855 */ 857 */
856 if (periph->periph_version >= 2) { 858 if (periph->periph_version >= 2) {
857 if ((inqbuf.flags3 & SID_CmdQue) != 0 && 859 if ((inqbuf.flags3 & SID_CmdQue) != 0 &&
858 (quirks & PQUIRK_NOTAG) == 0) 860 (quirks & PQUIRK_NOTAG) == 0)
859 periph->periph_cap |= PERIPH_CAP_TQING; 861 periph->periph_cap |= PERIPH_CAP_TQING;
860 if ((inqbuf.flags3 & SID_Linked) != 0) 862 if ((inqbuf.flags3 & SID_Linked) != 0)
861 periph->periph_cap |= PERIPH_CAP_LINKCMDS; 863 periph->periph_cap |= PERIPH_CAP_LINKCMDS;
862 if ((inqbuf.flags3 & SID_Sync) != 0 && 864 if ((inqbuf.flags3 & SID_Sync) != 0 &&
863 (quirks & PQUIRK_NOSYNC) == 0) 865 (quirks & PQUIRK_NOSYNC) == 0)
864 periph->periph_cap |= PERIPH_CAP_SYNC; 866 periph->periph_cap |= PERIPH_CAP_SYNC;
865 if ((inqbuf.flags3 & SID_WBus16) != 0 && 867 if ((inqbuf.flags3 & SID_WBus16) != 0 &&
866 (quirks & PQUIRK_NOWIDE) == 0) 868 (quirks & PQUIRK_NOWIDE) == 0)
867 periph->periph_cap |= PERIPH_CAP_WIDE16; 869 periph->periph_cap |= PERIPH_CAP_WIDE16;
868 if ((inqbuf.flags3 & SID_WBus32) != 0 && 870 if ((inqbuf.flags3 & SID_WBus32) != 0 &&
869 (quirks & PQUIRK_NOWIDE) == 0) 871 (quirks & PQUIRK_NOWIDE) == 0)
870 periph->periph_cap |= PERIPH_CAP_WIDE32; 872 periph->periph_cap |= PERIPH_CAP_WIDE32;
871 if ((inqbuf.flags3 & SID_SftRe) != 0) 873 if ((inqbuf.flags3 & SID_SftRe) != 0)
872 periph->periph_cap |= PERIPH_CAP_SFTRESET; 874 periph->periph_cap |= PERIPH_CAP_SFTRESET;
873 if ((inqbuf.flags3 & SID_RelAdr) != 0) 875 if ((inqbuf.flags3 & SID_RelAdr) != 0)
874 periph->periph_cap |= PERIPH_CAP_RELADR; 876 periph->periph_cap |= PERIPH_CAP_RELADR;
875 /* SPC-2 */ 877 /* SPC-2 */
876 if (periph->periph_version >= 3 && 878 if (periph->periph_version >= 3 &&
877 !(quirks & PQUIRK_CAP_NODT)){ 879 !(quirks & PQUIRK_CAP_NODT)){
878 /* 880 /*
879 * Report ST clocking though CAP_WIDExx/CAP_SYNC. 881 * Report ST clocking though CAP_WIDExx/CAP_SYNC.
880 * If the device only supports DT, clear these 882 * If the device only supports DT, clear these
881 * flags (DT implies SYNC and WIDE) 883 * flags (DT implies SYNC and WIDE)
882 */ 884 */
883 switch (inqbuf.flags4 & SID_Clocking) { 885 switch (inqbuf.flags4 & SID_Clocking) {
884 case SID_CLOCKING_DT_ONLY: 886 case SID_CLOCKING_DT_ONLY:
885 periph->periph_cap &= 887 periph->periph_cap &=
886 ~(PERIPH_CAP_SYNC | 888 ~(PERIPH_CAP_SYNC |
887 PERIPH_CAP_WIDE16 | 889 PERIPH_CAP_WIDE16 |
888 PERIPH_CAP_WIDE32); 890 PERIPH_CAP_WIDE32);
889 /* FALLTHROUGH */ 891 /* FALLTHROUGH */
890 case SID_CLOCKING_SD_DT: 892 case SID_CLOCKING_SD_DT:
891 periph->periph_cap |= PERIPH_CAP_DT; 893 periph->periph_cap |= PERIPH_CAP_DT;
892 break; 894 break;
893 default: /* ST only or invalid */ 895 default: /* ST only or invalid */
894 /* nothing to do */ 896 /* nothing to do */
895 break; 897 break;
896 } 898 }
897 } 899 }
898 if (periph->periph_version >= 3) { 900 if (periph->periph_version >= 3) {
899 if (inqbuf.flags4 & SID_IUS) 901 if (inqbuf.flags4 & SID_IUS)
900 periph->periph_cap |= PERIPH_CAP_IUS; 902 periph->periph_cap |= PERIPH_CAP_IUS;
901 if (inqbuf.flags4 & SID_QAS) 903 if (inqbuf.flags4 & SID_QAS)
902 periph->periph_cap |= PERIPH_CAP_QAS; 904 periph->periph_cap |= PERIPH_CAP_QAS;
903 } 905 }
904 } 906 }
905 if (quirks & PQUIRK_CAP_SYNC) 907 if (quirks & PQUIRK_CAP_SYNC)
906 periph->periph_cap |= PERIPH_CAP_SYNC; 908 periph->periph_cap |= PERIPH_CAP_SYNC;
907 if (quirks & PQUIRK_CAP_WIDE16) 909 if (quirks & PQUIRK_CAP_WIDE16)
908 periph->periph_cap |= PERIPH_CAP_WIDE16; 910 periph->periph_cap |= PERIPH_CAP_WIDE16;
909 911
910 /* 912 /*
911 * Now apply any quirks from the table. 913 * Now apply any quirks from the table.
912 */ 914 */
913 periph->periph_quirks |= quirks; 915 periph->periph_quirks |= quirks;
914 if (periph->periph_version == 0 && 916 if (periph->periph_version == 0 &&
915 (periph->periph_quirks & PQUIRK_FORCELUNS) == 0) 917 (periph->periph_quirks & PQUIRK_FORCELUNS) == 0)
916 periph->periph_quirks |= PQUIRK_NOLUNS; 918 periph->periph_quirks |= PQUIRK_NOLUNS;
917 919
918 if ((periph->periph_quirks & PQUIRK_NOLUNS) == 0) 920 if ((periph->periph_quirks & PQUIRK_NOLUNS) == 0)
919 docontinue = 1; 921 docontinue = 1;
920 922
921 locs[SCSIBUSCF_TARGET] = target; 923 locs[SCSIBUSCF_TARGET] = target;
922 locs[SCSIBUSCF_LUN] = lun; 924 locs[SCSIBUSCF_LUN] = lun;
923 925
924 if ((cf = config_search_loc(config_stdsubmatch, sc->sc_dev, 926 if ((cf = config_search_loc(config_stdsubmatch, sc->sc_dev,
925 "scsibus", locs, &sa)) != NULL) { 927 "scsibus", locs, &sa)) != NULL) {
926 scsipi_insert_periph(chan, periph); 928 scsipi_insert_periph(chan, periph);
927 /* 929 /*
928 * XXX Can't assign periph_dev here, because we'll 930 * XXX Can't assign periph_dev here, because we'll
929 * XXX need it before config_attach() returns. Must 931 * XXX need it before config_attach() returns. Must
930 * XXX assign it in periph driver. 932 * XXX assign it in periph driver.
931 */ 933 */
932 chld = config_attach_loc(sc->sc_dev, cf, locs, &sa, 934 chld = config_attach_loc(sc->sc_dev, cf, locs, &sa,
933 scsibusprint); 935 scsibusprint);
934 } else { 936 } else {
935 scsibusprint(&sa, device_xname(sc->sc_dev)); 937 scsibusprint(&sa, device_xname(sc->sc_dev));
936 aprint_normal(" not configured\n"); 938 aprint_normal(" not configured\n");
937 goto bad; 939 goto bad;
938 } 940 }
939 941
940 return (docontinue); 942 return (docontinue);
941 943
942bad: 944bad:
943 free(periph, M_DEVBUF); 945 free(periph, M_DEVBUF);
944 return (docontinue); 946 return (docontinue);
945} 947}
946 948
947/****** Entry points for user control of the SCSI bus. ******/ 949/****** Entry points for user control of the SCSI bus. ******/
948 950
949static int 951static int
950scsibusopen(dev_t dev, int flag, int fmt, 952scsibusopen(dev_t dev, int flag, int fmt,
951 struct lwp *l) 953 struct lwp *l)
952{ 954{
953 struct scsibus_softc *sc; 955 struct scsibus_softc *sc;
954 int error, unit = minor(dev); 956 int error, unit = minor(dev);
955 957
956 sc = device_lookup_private(&scsibus_cd, unit); 958 sc = device_lookup_private(&scsibus_cd, unit);
957 if (sc == NULL) 959 if (sc == NULL)
958 return (ENXIO); 960 return (ENXIO);
959 961
960 if (sc->sc_flags & SCSIBUSF_OPEN) 962 if (sc->sc_flags & SCSIBUSF_OPEN)
961 return (EBUSY); 963 return (EBUSY);
962 964
963 if ((error = scsipi_adapter_addref(sc->sc_channel->chan_adapter)) != 0) 965 if ((error = scsipi_adapter_addref(sc->sc_channel->chan_adapter)) != 0)
964 return (error); 966 return (error);
965 967
966 sc->sc_flags |= SCSIBUSF_OPEN; 968 sc->sc_flags |= SCSIBUSF_OPEN;
967 969
968 return (0); 970 return (0);
969} 971}
970 972
971static int 973static int
972scsibusclose(dev_t dev, int flag, int fmt, 974scsibusclose(dev_t dev, int flag, int fmt,
973 struct lwp *l) 975 struct lwp *l)
974{ 976{
975 struct scsibus_softc *sc; 977 struct scsibus_softc *sc;
976 978
977 sc = device_lookup_private(&scsibus_cd, minor(dev)); 979 sc = device_lookup_private(&scsibus_cd, minor(dev));
978 scsipi_adapter_delref(sc->sc_channel->chan_adapter); 980 scsipi_adapter_delref(sc->sc_channel->chan_adapter);
979 981
980 sc->sc_flags &= ~SCSIBUSF_OPEN; 982 sc->sc_flags &= ~SCSIBUSF_OPEN;
981 983
982 return (0); 984 return (0);
983} 985}
984 986
985static int 987static int
986scsibusioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l) 988scsibusioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
987{ 989{
988 struct scsibus_softc *sc; 990 struct scsibus_softc *sc;
989 struct scsipi_channel *chan; 991 struct scsipi_channel *chan;
990 int error; 992 int error;
991 993
992 sc = device_lookup_private(&scsibus_cd, minor(dev)); 994 sc = device_lookup_private(&scsibus_cd, minor(dev));
993 chan = sc->sc_channel; 995 chan = sc->sc_channel;
994 996
995 /* 997 /*
996 * Enforce write permission for ioctls that change the 998 * Enforce write permission for ioctls that change the
997 * state of the bus. Host adapter specific ioctls must 999 * state of the bus. Host adapter specific ioctls must
998 * be checked by the adapter driver. 1000 * be checked by the adapter driver.
999 */ 1001 */
1000 switch (cmd) { 1002 switch (cmd) {
1001 case SCBUSIOSCAN: 1003 case SCBUSIOSCAN:
1002 case SCBUSIODETACH: 1004 case SCBUSIODETACH:
1003 case SCBUSIORESET: 1005 case SCBUSIORESET:
1004 if ((flag & FWRITE) == 0) 1006 if ((flag & FWRITE) == 0)
1005 return (EBADF); 1007 return (EBADF);
1006 } 1008 }
1007 1009
1008 switch (cmd) { 1010 switch (cmd) {
1009 case SCBUSIOSCAN: 1011 case SCBUSIOSCAN:
1010 { 1012 {
1011 struct scbusioscan_args *a = 1013 struct scbusioscan_args *a =
1012 (struct scbusioscan_args *)addr; 1014 (struct scbusioscan_args *)addr;
1013 1015
1014 error = scsi_probe_bus(sc, a->sa_target, a->sa_lun); 1016 error = scsi_probe_bus(sc, a->sa_target, a->sa_lun);
1015 break; 1017 break;
1016 } 1018 }
1017 1019
1018 case SCBUSIODETACH: 1020 case SCBUSIODETACH:
1019 { 1021 {
1020 struct scbusiodetach_args *a = 1022 struct scbusiodetach_args *a =
1021 (struct scbusiodetach_args *)addr; 1023 (struct scbusiodetach_args *)addr;
1022 1024
1023 error = scsipi_target_detach(chan, a->sa_target, a->sa_lun, 0); 1025 error = scsipi_target_detach(chan, a->sa_target, a->sa_lun, 0);
1024 break; 1026 break;
1025 } 1027 }
1026 1028
1027 1029
1028 case SCBUSIORESET: 1030 case SCBUSIORESET:
1029 /* FALLTHROUGH */ 1031 /* FALLTHROUGH */
1030 default: 1032 default:
1031 if (chan->chan_adapter->adapt_ioctl == NULL) 1033 if (chan->chan_adapter->adapt_ioctl == NULL)
1032 error = ENOTTY; 1034 error = ENOTTY;
1033 else 1035 else
1034 error = (*chan->chan_adapter->adapt_ioctl)(chan, 1036 error = (*chan->chan_adapter->adapt_ioctl)(chan,
1035 cmd, addr, flag, l->l_proc); 1037 cmd, addr, flag, l->l_proc);
1036 break; 1038 break;
1037 } 1039 }
1038 1040
1039 return (error); 1041 return (error);
1040} 1042}