iopsp.c revision 1.4.2.3 1 /* $NetBSD: iopsp.c,v 1.4.2.3 2001/06/21 20:01:49 nathanw Exp $ */
2
3 /*-
4 * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Raw SCSI device support for I2O. IOPs present SCSI devices individually;
41 * we group them by controlling port.
42 */
43
44 #include "opt_i2o.h"
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/device.h>
50 #include <sys/queue.h>
51 #include <sys/lwp.h>
52 #include <sys/proc.h>
53 #include <sys/buf.h>
54 #include <sys/endian.h>
55 #include <sys/malloc.h>
56 #include <sys/scsiio.h>
57 #include <sys/lock.h>
58
59 #include <machine/bswap.h>
60 #include <machine/bus.h>
61
62 #include <dev/scsipi/scsi_all.h>
63 #include <dev/scsipi/scsi_disk.h>
64 #include <dev/scsipi/scsipi_all.h>
65 #include <dev/scsipi/scsiconf.h>
66 #include <dev/scsipi/scsi_message.h>
67
68 #include <dev/i2o/i2o.h>
69 #include <dev/i2o/iopio.h>
70 #include <dev/i2o/iopvar.h>
71 #include <dev/i2o/iopspvar.h>
72
73 static void iopsp_adjqparam(struct device *, int);
74 static void iopsp_attach(struct device *, struct device *, void *);
75 static void iopsp_intr(struct device *, struct iop_msg *, void *);
76 static int iopsp_ioctl(struct scsipi_channel *, u_long,
77 caddr_t, int, struct proc *);
78 static int iopsp_match(struct device *, struct cfdata *, void *);
79 static int iopsp_rescan(struct iopsp_softc *);
80 static int iopsp_reconfig(struct device *);
81 static void iopsp_scsipi_request(struct scsipi_channel *,
82 scsipi_adapter_req_t, void *);
83
84 struct cfattach iopsp_ca = {
85 sizeof(struct iopsp_softc), iopsp_match, iopsp_attach
86 };
87
88 /*
89 * Match a supported device.
90 */
91 static int
92 iopsp_match(struct device *parent, struct cfdata *match, void *aux)
93 {
94 struct iop_attach_args *ia;
95 struct {
96 struct i2o_param_op_results pr;
97 struct i2o_param_read_results prr;
98 struct i2o_param_hba_ctlr_info ci;
99 } __attribute__ ((__packed__)) param;
100
101 ia = aux;
102
103 if (ia->ia_class != I2O_CLASS_BUS_ADAPTER_PORT)
104 return (0);
105
106 if (iop_param_op((struct iop_softc *)parent, ia->ia_tid, NULL, 0,
107 I2O_PARAM_HBA_CTLR_INFO, ¶m, sizeof(param)) != 0)
108 return (0);
109
110 return (param.ci.bustype == I2O_HBA_BUS_SCSI ||
111 param.ci.bustype == I2O_HBA_BUS_FCA);
112 }
113
114 /*
115 * Attach a supported device.
116 */
117 static void
118 iopsp_attach(struct device *parent, struct device *self, void *aux)
119 {
120 struct iop_attach_args *ia;
121 struct iopsp_softc *sc;
122 struct iop_softc *iop;
123 struct {
124 struct i2o_param_op_results pr;
125 struct i2o_param_read_results prr;
126 union {
127 struct i2o_param_hba_ctlr_info ci;
128 struct i2o_param_hba_scsi_ctlr_info sci;
129 struct i2o_param_hba_scsi_port_info spi;
130 } p;
131 } __attribute__ ((__packed__)) param;
132 int fcal, rv;
133 #ifdef I2OVERBOSE
134 int size;
135 #endif
136
137 ia = (struct iop_attach_args *)aux;
138 sc = (struct iopsp_softc *)self;
139 iop = (struct iop_softc *)parent;
140
141 /* Register us as an initiator. */
142 sc->sc_ii.ii_dv = self;
143 sc->sc_ii.ii_intr = iopsp_intr;
144 sc->sc_ii.ii_flags = 0;
145 sc->sc_ii.ii_tid = ia->ia_tid;
146 sc->sc_ii.ii_reconfig = iopsp_reconfig;
147 sc->sc_ii.ii_adjqparam = iopsp_adjqparam;
148 iop_initiator_register(iop, &sc->sc_ii);
149
150 rv = iop_param_op(iop, ia->ia_tid, NULL, 0, I2O_PARAM_HBA_CTLR_INFO,
151 ¶m, sizeof(param));
152 if (rv != 0) {
153 printf("%s: unable to get parameters (0x%04x; %d)\n",
154 sc->sc_dv.dv_xname, I2O_PARAM_HBA_CTLR_INFO, rv);
155 goto bad;
156 }
157
158 fcal = (param.p.ci.bustype == I2O_HBA_BUS_FCA); /* XXX */
159
160 /*
161 * Say what the device is. If we can find out what the controling
162 * device is, say what that is too.
163 */
164 printf(": SCSI port");
165 iop_print_ident(iop, ia->ia_tid);
166 printf("\n");
167
168 rv = iop_param_op(iop, ia->ia_tid, NULL, 0,
169 I2O_PARAM_HBA_SCSI_CTLR_INFO, ¶m, sizeof(param));
170 if (rv != 0) {
171 printf("%s: unable to get parameters (0x%04x; %d)\n",
172 sc->sc_dv.dv_xname, I2O_PARAM_HBA_SCSI_CTLR_INFO, rv);
173 goto bad;
174 }
175
176 #ifdef I2OVERBOSE
177 printf("%s: %d-bit, max sync rate %dMHz, initiator ID %d\n",
178 sc->sc_dv.dv_xname, param.p.sci.maxdatawidth,
179 (u_int32_t)le64toh(param.p.sci.maxsyncrate) / 1000,
180 le32toh(param.p.sci.initiatorid));
181 #endif
182
183 sc->sc_adapter.adapt_dev = &sc->sc_dv;
184 sc->sc_adapter.adapt_nchannels = 1;
185 sc->sc_adapter.adapt_openings = 1;
186 sc->sc_adapter.adapt_max_periph = 1;
187 sc->sc_adapter.adapt_ioctl = iopsp_ioctl;
188 sc->sc_adapter.adapt_minphys = minphys;
189 sc->sc_adapter.adapt_request = iopsp_scsipi_request;
190
191 memset(&sc->sc_channel, 0, sizeof(sc->sc_channel));
192 sc->sc_channel.chan_adapter = &sc->sc_adapter;
193 sc->sc_channel.chan_bustype = &scsi_bustype;
194 sc->sc_channel.chan_channel = 0;
195 sc->sc_channel.chan_ntargets = fcal ?
196 IOPSP_MAX_FCAL_TARGET : param.p.sci.maxdatawidth;
197 sc->sc_channel.chan_nluns = IOPSP_MAX_LUN;
198 sc->sc_channel.chan_id = le32toh(param.p.sci.initiatorid);
199 sc->sc_channel.chan_flags = SCSIPI_CHAN_NOSETTLE;
200
201 #ifdef I2OVERBOSE
202 /*
203 * Allocate the target map. Currently used for informational
204 * purposes only.
205 */
206 size = sc->sc_channel.chan_ntargets * sizeof(struct iopsp_target);
207 sc->sc_targetmap = malloc(size, M_DEVBUF, M_NOWAIT);
208 memset(sc->sc_targetmap, 0, size);
209 #endif
210
211 /* Build the two maps, and attach to scsipi. */
212 if (iopsp_reconfig(self) != 0) {
213 printf("%s: configure failed\n", sc->sc_dv.dv_xname);
214 goto bad;
215 }
216 config_found(self, &sc->sc_channel, scsiprint);
217 return;
218
219 bad:
220 iop_initiator_unregister(iop, &sc->sc_ii);
221 }
222
223 /*
224 * Scan the LCT to determine which devices we control, and enter them into
225 * the maps.
226 */
227 static int
228 iopsp_reconfig(struct device *dv)
229 {
230 struct iopsp_softc *sc;
231 struct iop_softc *iop;
232 struct i2o_lct_entry *le;
233 struct scsipi_channel *sc_chan;
234 struct {
235 struct i2o_param_op_results pr;
236 struct i2o_param_read_results prr;
237 struct i2o_param_scsi_device_info sdi;
238 } __attribute__ ((__packed__)) param;
239 u_int tid, nent, i, targ, lun, size, s, rv, bptid;
240 u_short *tidmap;
241 #ifdef I2OVERBOSE
242 struct iopsp_target *it;
243 int syncrate;
244 #endif
245
246 sc = (struct iopsp_softc *)dv;
247 iop = (struct iop_softc *)sc->sc_dv.dv_parent;
248 sc_chan = &sc->sc_channel;
249
250 /* Anything to do? */
251 if (iop->sc_chgind == sc->sc_chgind)
252 return (0);
253
254 /*
255 * Allocate memory for the target/LUN -> TID map. Use zero to
256 * denote absent targets (zero is the TID of the I2O executive,
257 * and we never address that here).
258 */
259 size = sc_chan->chan_ntargets * (IOPSP_MAX_LUN) * sizeof(u_short);
260 if ((tidmap = malloc(size, M_DEVBUF, M_WAITOK)) == NULL)
261 return (ENOMEM);
262 memset(tidmap, 0, size);
263
264 #ifdef I2OVERBOSE
265 for (i = 0; i < sc_chan->chan_ntargets; i++)
266 sc->sc_targetmap[i].it_flags &= ~IT_PRESENT;
267 #endif
268
269 /*
270 * A quick hack to handle Intel's stacked bus port arrangement.
271 */
272 bptid = sc->sc_ii.ii_tid;
273 nent = iop->sc_nlctent;
274 for (le = iop->sc_lct->entry; nent != 0; nent--, le++)
275 if ((le16toh(le->classid) & 4095) ==
276 I2O_CLASS_BUS_ADAPTER_PORT &&
277 (le32toh(le->usertid) & 4095) == bptid) {
278 bptid = le32toh(le->localtid) & 4095;
279 break;
280 }
281
282 nent = iop->sc_nlctent;
283 for (i = 0, le = iop->sc_lct->entry; i < nent; i++, le++) {
284 if ((le16toh(le->classid) & 4095) != I2O_CLASS_SCSI_PERIPHERAL)
285 continue;
286 if (((le32toh(le->usertid) >> 12) & 4095) != bptid)
287 continue;
288 tid = le32toh(le->localtid) & 4095;
289
290 rv = iop_param_op(iop, tid, NULL, 0, I2O_PARAM_SCSI_DEVICE_INFO,
291 ¶m, sizeof(param));
292 if (rv != 0) {
293 printf("%s: unable to get parameters (0x%04x; %d)\n",
294 sc->sc_dv.dv_xname, I2O_PARAM_SCSI_DEVICE_INFO,
295 rv);
296 continue;
297 }
298 targ = le32toh(param.sdi.identifier);
299 lun = param.sdi.luninfo[1];
300 #if defined(DIAGNOSTIC) || defined(I2ODEBUG)
301 if (targ >= sc_chan->chan_ntargets ||
302 lun >= sc_chan->chan_nluns) {
303 printf("%s: target %d,%d (tid %d): bad target/LUN\n",
304 sc->sc_dv.dv_xname, targ, lun, tid);
305 continue;
306 }
307 #endif
308
309 #ifdef I2OVERBOSE
310 /*
311 * If we've already described this target, and nothing has
312 * changed, then don't describe it again.
313 */
314 it = &sc->sc_targetmap[targ];
315 it->it_flags |= IT_PRESENT;
316 syncrate = ((int)le64toh(param.sdi.negsyncrate) + 500) / 1000;
317 if (it->it_width == param.sdi.negdatawidth &&
318 it->it_offset == param.sdi.negoffset &&
319 it->it_syncrate == syncrate)
320 continue;
321
322 it->it_width = param.sdi.negdatawidth;
323 it->it_offset = param.sdi.negoffset;
324 it->it_syncrate = syncrate;
325
326 printf("%s: target %d (tid %d): %d-bit, ", sc->sc_dv.dv_xname,
327 targ, tid, it->it_width);
328 if (it->it_syncrate == 0)
329 printf("asynchronous\n");
330 else
331 printf("synchronous at %dMHz, offset 0x%x\n",
332 it->it_syncrate, it->it_offset);
333 #endif
334
335 /* Ignore the device if it's in use by somebody else. */
336 if ((le32toh(le->usertid) & 4095) != I2O_TID_NONE) {
337 #ifdef I2OVERBOSE
338 if (sc->sc_tidmap == NULL ||
339 IOPSP_TIDMAP(sc->sc_tidmap, targ, lun) !=
340 IOPSP_TID_INUSE)
341 printf("%s: target %d,%d (tid %d): in use by"
342 " tid %d\n", sc->sc_dv.dv_xname,
343 targ, lun, tid,
344 le32toh(le->usertid) & 4095);
345 #endif
346 IOPSP_TIDMAP(tidmap, targ, lun) = IOPSP_TID_INUSE;
347 } else
348 IOPSP_TIDMAP(tidmap, targ, lun) = (u_short)tid;
349 }
350
351 #ifdef I2OVERBOSE
352 for (i = 0; i < sc_chan->chan_ntargets; i++)
353 if ((sc->sc_targetmap[i].it_flags & IT_PRESENT) == 0)
354 sc->sc_targetmap[i].it_width = 0;
355 #endif
356
357 /* Swap in the new map and return. */
358 s = splbio();
359 if (sc->sc_tidmap != NULL)
360 free(sc->sc_tidmap, M_DEVBUF);
361 sc->sc_tidmap = tidmap;
362 splx(s);
363 sc->sc_chgind = iop->sc_chgind;
364 return (0);
365 }
366
367 /*
368 * Re-scan the bus; to be called from a higher level (e.g. scsipi).
369 */
370 static int
371 iopsp_rescan(struct iopsp_softc *sc)
372 {
373 struct iop_softc *iop;
374 struct iop_msg *im;
375 struct i2o_hba_bus_scan mf;
376 int rv;
377
378 iop = (struct iop_softc *)sc->sc_dv.dv_parent;
379
380 rv = lockmgr(&iop->sc_conflock, LK_EXCLUSIVE, NULL);
381 if (rv != 0) {
382 #ifdef I2ODEBUG
383 printf("iopsp_rescan: unable to acquire lock\n");
384 #endif
385 return (rv);
386 }
387
388 im = iop_msg_alloc(iop, &sc->sc_ii, IM_WAIT);
389
390 mf.msgflags = I2O_MSGFLAGS(i2o_hba_bus_scan);
391 mf.msgfunc = I2O_MSGFUNC(sc->sc_ii.ii_tid, I2O_HBA_BUS_SCAN);
392 mf.msgictx = sc->sc_ii.ii_ictx;
393 mf.msgtctx = im->im_tctx;
394
395 rv = iop_msg_post(iop, im, &mf, 5*60*1000);
396 iop_msg_free(iop, im);
397 if (rv != 0)
398 printf("%s: bus rescan failed (error %d)\n",
399 sc->sc_dv.dv_xname, rv);
400
401 if ((rv = iop_lct_get(iop)) == 0)
402 rv = iopsp_reconfig(&sc->sc_dv);
403
404 lockmgr(&iop->sc_conflock, LK_RELEASE, NULL);
405 return (rv);
406 }
407
408 /*
409 * Start a SCSI command.
410 */
411 static void
412 iopsp_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req,
413 void *arg)
414 {
415 struct scsipi_xfer *xs;
416 struct scsipi_periph *periph;
417 struct iopsp_softc *sc;
418 struct iop_msg *im;
419 struct iop_softc *iop;
420 struct i2o_scsi_scb_exec *mf;
421 int error, flags, tid, s;
422 u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
423
424 sc = (void *)chan->chan_adapter->adapt_dev;
425 iop = (struct iop_softc *)sc->sc_dv.dv_parent;
426
427 switch (req) {
428 case ADAPTER_REQ_RUN_XFER:
429 xs = arg;
430 periph = xs->xs_periph;
431 flags = xs->xs_control;
432
433 tid = IOPSP_TIDMAP(sc->sc_tidmap, periph->periph_target,
434 periph->periph_lun);
435 if (tid == IOPSP_TID_ABSENT || tid == IOPSP_TID_INUSE) {
436 xs->error = XS_SELTIMEOUT;
437 scsipi_done(xs);
438 return;
439 }
440
441 SC_DEBUG(periph, SDEV_DB2, ("iopsp_scsi_request run_xfer\n"));
442
443 /* Need to reset the target? */
444 if ((flags & XS_CTL_RESET) != 0) {
445 if (iop_simple_cmd(iop, tid, I2O_SCSI_DEVICE_RESET,
446 sc->sc_ii.ii_ictx, 1, 30*1000) != 0) {
447 #ifdef I2ODEBUG
448 printf("%s: reset failed\n",
449 sc->sc_dv.dv_xname);
450 #endif
451 xs->error = XS_DRIVER_STUFFUP;
452 } else
453 xs->error = XS_NOERROR;
454
455 scsipi_done(xs);
456 return;
457 }
458
459 #if defined(I2ODEBUG) || defined(SCSIDEBUG)
460 if (xs->cmdlen > sizeof(mf->cdb))
461 panic("%s: CDB too large\n", sc->sc_dv.dv_xname);
462 #endif
463
464 im = iop_msg_alloc(iop, &sc->sc_ii, IM_POLL_INTR |
465 IM_NOSTATUS | ((flags & XS_CTL_POLL) != 0 ? IM_POLL : 0));
466 im->im_dvcontext = xs;
467
468 mf = (struct i2o_scsi_scb_exec *)mb;
469 mf->msgflags = I2O_MSGFLAGS(i2o_scsi_scb_exec);
470 mf->msgfunc = I2O_MSGFUNC(tid, I2O_SCSI_SCB_EXEC);
471 mf->msgictx = sc->sc_ii.ii_ictx;
472 mf->msgtctx = im->im_tctx;
473 mf->flags = xs->cmdlen | I2O_SCB_FLAG_ENABLE_DISCONNECT |
474 I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
475 mf->datalen = xs->datalen;
476 memcpy(mf->cdb, xs->cmd, xs->cmdlen);
477
478 switch (xs->xs_tag_type) {
479 case MSG_ORDERED_Q_TAG:
480 mf->flags |= I2O_SCB_FLAG_ORDERED_QUEUE_TAG;
481 break;
482 case MSG_SIMPLE_Q_TAG:
483 mf->flags |= I2O_SCB_FLAG_SIMPLE_QUEUE_TAG;
484 break;
485 case MSG_HEAD_OF_Q_TAG:
486 mf->flags |= I2O_SCB_FLAG_HEAD_QUEUE_TAG;
487 break;
488 default:
489 break;
490 }
491
492 if (xs->datalen != 0) {
493 error = iop_msg_map_bio(iop, im, mb, xs->data,
494 xs->datalen, (flags & XS_CTL_DATA_OUT) == 0);
495 if (error) {
496 xs->error = XS_DRIVER_STUFFUP;
497 iop_msg_free(iop, im);
498 scsipi_done(xs);
499 return;
500 }
501 if ((flags & XS_CTL_DATA_IN) == 0)
502 mf->flags |= I2O_SCB_FLAG_XFER_TO_DEVICE;
503 else
504 mf->flags |= I2O_SCB_FLAG_XFER_FROM_DEVICE;
505 }
506
507 s = splbio();
508 sc->sc_curqd++;
509 splx(s);
510
511 if (iop_msg_post(iop, im, mb, xs->timeout)) {
512 s = splbio();
513 sc->sc_curqd--;
514 splx(s);
515 if (xs->datalen != 0)
516 iop_msg_unmap(iop, im);
517 iop_msg_free(iop, im);
518 xs->error = XS_DRIVER_STUFFUP;
519 scsipi_done(xs);
520 }
521 break;
522
523 case ADAPTER_REQ_GROW_RESOURCES:
524 /*
525 * Not supported.
526 */
527 break;
528
529 case ADAPTER_REQ_SET_XFER_MODE:
530 /*
531 * The DDM takes care of this, and we can't modify its
532 * behaviour.
533 */
534 break;
535 }
536 }
537
538 #ifdef notyet
539 /*
540 * Abort the specified I2O_SCSI_SCB_EXEC message and its associated SCB.
541 */
542 static int
543 iopsp_scsi_abort(struct iopsp_softc *sc, int atid, struct iop_msg *aim)
544 {
545 struct iop_msg *im;
546 struct i2o_scsi_scb_abort mf;
547 struct iop_softc *iop;
548 int rv, s;
549
550 iop = (struct iop_softc *)sc->sc_dv.dv_parent;
551 im = iop_msg_alloc(iop, &sc->sc_ii, IM_POLL);
552
553 mf.msgflags = I2O_MSGFLAGS(i2o_scsi_scb_abort);
554 mf.msgfunc = I2O_MSGFUNC(atid, I2O_SCSI_SCB_ABORT);
555 mf.msgictx = sc->sc_ii.ii_ictx;
556 mf.msgtctx = im->im_tctx;
557 mf.tctxabort = aim->im_tctx;
558
559 s = splbio();
560 rv = iop_msg_post(iop, im, &mf, 30000);
561 splx(s);
562 iop_msg_free(iop, im);
563 return (rv);
564 }
565 #endif
566
567 /*
568 * We have a message which has been processed and replied to by the IOP -
569 * deal with it.
570 */
571 static void
572 iopsp_intr(struct device *dv, struct iop_msg *im, void *reply)
573 {
574 struct scsipi_xfer *xs;
575 struct iopsp_softc *sc;
576 struct i2o_scsi_reply *rb;
577 struct iop_softc *iop;
578 u_int sl;
579
580 sc = (struct iopsp_softc *)dv;
581 xs = (struct scsipi_xfer *)im->im_dvcontext;
582 iop = (struct iop_softc *)dv->dv_parent;
583 rb = reply;
584
585 SC_DEBUG(xs->xs_periph, SDEV_DB2, ("iopsp_intr\n"));
586
587 if ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0) {
588 xs->error = XS_DRIVER_STUFFUP;
589 xs->resid = xs->datalen;
590 } else {
591 if (rb->hbastatus != I2O_SCSI_DSC_SUCCESS) {
592 switch (rb->hbastatus) {
593 case I2O_SCSI_DSC_ADAPTER_BUSY:
594 case I2O_SCSI_DSC_SCSI_BUS_RESET:
595 case I2O_SCSI_DSC_BUS_BUSY:
596 xs->error = XS_BUSY;
597 break;
598 case I2O_SCSI_DSC_SELECTION_TIMEOUT:
599 xs->error = XS_SELTIMEOUT;
600 break;
601 case I2O_SCSI_DSC_COMMAND_TIMEOUT:
602 case I2O_SCSI_DSC_DEVICE_NOT_PRESENT:
603 case I2O_SCSI_DSC_LUN_INVALID:
604 case I2O_SCSI_DSC_SCSI_TID_INVALID:
605 xs->error = XS_TIMEOUT;
606 break;
607 default:
608 xs->error = XS_DRIVER_STUFFUP;
609 break;
610 }
611 printf("%s: HBA status 0x%02x\n", sc->sc_dv.dv_xname,
612 rb->hbastatus);
613 } else if (rb->scsistatus != SCSI_OK) {
614 switch (rb->scsistatus) {
615 case SCSI_CHECK:
616 xs->error = XS_SENSE;
617 sl = le32toh(rb->senselen);
618 if (sl > sizeof(xs->sense.scsi_sense))
619 sl = sizeof(xs->sense.scsi_sense);
620 memcpy(&xs->sense.scsi_sense, rb->sense, sl);
621 break;
622 case SCSI_QUEUE_FULL:
623 case SCSI_BUSY:
624 xs->error = XS_BUSY;
625 break;
626 default:
627 xs->error = XS_DRIVER_STUFFUP;
628 break;
629 }
630 } else
631 xs->error = XS_NOERROR;
632
633 xs->resid = xs->datalen - le32toh(rb->datalen);
634 xs->status = rb->scsistatus;
635 }
636
637 /* Free the message wrapper and pass the news to scsipi. */
638 if (xs->datalen != 0)
639 iop_msg_unmap(iop, im);
640 iop_msg_free(iop, im);
641
642 if (--sc->sc_curqd == sc->sc_adapter.adapt_openings)
643 wakeup(&sc->sc_curqd);
644
645 scsipi_done(xs);
646 }
647
648 /*
649 * ioctl hook; used here only to initiate low-level rescans.
650 */
651 static int
652 iopsp_ioctl(struct scsipi_channel *chan, u_long cmd, caddr_t data, int flag,
653 struct proc *p)
654 {
655 int rv;
656
657 switch (cmd) {
658 case SCBUSIOLLSCAN:
659 /*
660 * If it's boot time, the bus will have been scanned and the
661 * maps built. Locking would stop re-configuration, but we
662 * want to fake success.
663 */
664 if (p != &proc0)
665 rv = iopsp_rescan(
666 (struct iopsp_softc *)chan->chan_adapter->adapt_dev);
667 else
668 rv = 0;
669 break;
670
671 default:
672 rv = ENOTTY;
673 break;
674 }
675
676 return (rv);
677 }
678
679 /*
680 * The number of openings available to us has changed, so inform scsipi.
681 */
682 static void
683 iopsp_adjqparam(struct device *dv, int mpi)
684 {
685 struct iopsp_softc *sc;
686 int s;
687
688 sc = (struct iopsp_softc *)dv;
689
690 s = splbio();
691 sc->sc_adapter.adapt_openings = mpi;
692 if (mpi < sc->sc_curqd)
693 tsleep(&sc->sc_curqd, PWAIT, "iopspdrn", 0);
694 splx(s);
695 }
696