iopsp.c revision 1.4.2.7 1 /* $NetBSD: iopsp.c,v 1.4.2.7 2002/02/28 04:13:18 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 <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: iopsp.c,v 1.4.2.7 2002/02/28 04:13:18 nathanw Exp $");
46
47 #include "opt_i2o.h"
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
52 #include <sys/device.h>
53 #include <sys/queue.h>
54 #include <sys/lwp.h>
55 #include <sys/proc.h>
56 #include <sys/buf.h>
57 #include <sys/endian.h>
58 #include <sys/malloc.h>
59 #include <sys/scsiio.h>
60 #include <sys/lock.h>
61
62 #include <machine/bswap.h>
63 #include <machine/bus.h>
64
65 #include <dev/scsipi/scsi_all.h>
66 #include <dev/scsipi/scsi_disk.h>
67 #include <dev/scsipi/scsipi_all.h>
68 #include <dev/scsipi/scsiconf.h>
69 #include <dev/scsipi/scsi_message.h>
70
71 #include <dev/i2o/i2o.h>
72 #include <dev/i2o/iopio.h>
73 #include <dev/i2o/iopvar.h>
74 #include <dev/i2o/iopspvar.h>
75
76 static void iopsp_adjqparam(struct device *, int);
77 static void iopsp_attach(struct device *, struct device *, void *);
78 static void iopsp_intr(struct device *, struct iop_msg *, void *);
79 static int iopsp_ioctl(struct scsipi_channel *, u_long,
80 caddr_t, int, struct proc *);
81 static int iopsp_match(struct device *, struct cfdata *, void *);
82 static int iopsp_rescan(struct iopsp_softc *);
83 static int iopsp_reconfig(struct device *);
84 static void iopsp_scsipi_request(struct scsipi_channel *,
85 scsipi_adapter_req_t, void *);
86
87 struct cfattach iopsp_ca = {
88 sizeof(struct iopsp_softc), iopsp_match, iopsp_attach
89 };
90
91 /*
92 * Match a supported device.
93 */
94 static int
95 iopsp_match(struct device *parent, struct cfdata *match, void *aux)
96 {
97 struct iop_attach_args *ia;
98 struct {
99 struct i2o_param_op_results pr;
100 struct i2o_param_read_results prr;
101 struct i2o_param_hba_ctlr_info ci;
102 } __attribute__ ((__packed__)) param;
103
104 ia = aux;
105
106 if (ia->ia_class != I2O_CLASS_BUS_ADAPTER_PORT)
107 return (0);
108
109 if (iop_field_get_all((struct iop_softc *)parent, ia->ia_tid,
110 I2O_PARAM_HBA_CTLR_INFO, ¶m, sizeof(param), NULL) != 0)
111 return (0);
112
113 return (param.ci.bustype == I2O_HBA_BUS_SCSI ||
114 param.ci.bustype == I2O_HBA_BUS_FCA);
115 }
116
117 /*
118 * Attach a supported device.
119 */
120 static void
121 iopsp_attach(struct device *parent, struct device *self, void *aux)
122 {
123 struct iop_attach_args *ia;
124 struct iopsp_softc *sc;
125 struct iop_softc *iop;
126 struct {
127 struct i2o_param_op_results pr;
128 struct i2o_param_read_results prr;
129 union {
130 struct i2o_param_hba_ctlr_info ci;
131 struct i2o_param_hba_scsi_ctlr_info sci;
132 struct i2o_param_hba_scsi_port_info spi;
133 } p;
134 } __attribute__ ((__packed__)) param;
135 int fc, rv;
136 #ifdef I2OVERBOSE
137 int size;
138 #endif
139
140 ia = (struct iop_attach_args *)aux;
141 sc = (struct iopsp_softc *)self;
142 iop = (struct iop_softc *)parent;
143
144 /* Register us as an initiator. */
145 sc->sc_ii.ii_dv = self;
146 sc->sc_ii.ii_intr = iopsp_intr;
147 sc->sc_ii.ii_flags = 0;
148 sc->sc_ii.ii_tid = ia->ia_tid;
149 sc->sc_ii.ii_reconfig = iopsp_reconfig;
150 sc->sc_ii.ii_adjqparam = iopsp_adjqparam;
151 iop_initiator_register(iop, &sc->sc_ii);
152
153 rv = iop_field_get_all(iop, ia->ia_tid, I2O_PARAM_HBA_CTLR_INFO,
154 ¶m, sizeof(param), NULL);
155 if (rv != 0)
156 goto bad;
157
158 fc = (param.p.ci.bustype == I2O_HBA_BUS_FCA);
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_field_get_all(iop, ia->ia_tid, I2O_PARAM_HBA_SCSI_CTLR_INFO,
169 ¶m, sizeof(param), NULL);
170 if (rv != 0)
171 goto bad;
172
173 #ifdef I2OVERBOSE
174 printf("%s: ", sc->sc_dv.dv_xname);
175 if (fc)
176 printf("FC");
177 else
178 printf("%d-bit", param.p.sci.maxdatawidth);
179 printf(", max sync rate %dMHz, initiator ID %d\n",
180 (u_int32_t)le64toh(param.p.sci.maxsyncrate) / 1000,
181 le32toh(param.p.sci.initiatorid));
182 #endif
183
184 sc->sc_adapter.adapt_dev = &sc->sc_dv;
185 sc->sc_adapter.adapt_nchannels = 1;
186 sc->sc_adapter.adapt_openings = 1;
187 sc->sc_adapter.adapt_max_periph = 1;
188 sc->sc_adapter.adapt_ioctl = iopsp_ioctl;
189 sc->sc_adapter.adapt_minphys = minphys;
190 sc->sc_adapter.adapt_request = iopsp_scsipi_request;
191
192 memset(&sc->sc_channel, 0, sizeof(sc->sc_channel));
193 sc->sc_channel.chan_adapter = &sc->sc_adapter;
194 sc->sc_channel.chan_bustype = &scsi_bustype;
195 sc->sc_channel.chan_channel = 0;
196 sc->sc_channel.chan_ntargets = fc ?
197 IOPSP_MAX_FC_TARGET : param.p.sci.maxdatawidth;
198 sc->sc_channel.chan_nluns = IOPSP_MAX_LUN;
199 sc->sc_channel.chan_id = le32toh(param.p.sci.initiatorid);
200 sc->sc_channel.chan_flags = SCSIPI_CHAN_NOSETTLE;
201
202 #ifdef I2OVERBOSE
203 /*
204 * Allocate the target map. Currently used for informational
205 * purposes only.
206 */
207 size = sc->sc_channel.chan_ntargets * sizeof(struct iopsp_target);
208 sc->sc_targetmap = malloc(size, M_DEVBUF, M_NOWAIT|M_ZERO);
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|M_ZERO)) == NULL)
261 return (ENOMEM);
262
263 #ifdef I2OVERBOSE
264 for (i = 0; i < sc_chan->chan_ntargets; i++)
265 sc->sc_targetmap[i].it_flags &= ~IT_PRESENT;
266 #endif
267
268 /*
269 * A quick hack to handle Intel's stacked bus port arrangement.
270 */
271 bptid = sc->sc_ii.ii_tid;
272 nent = iop->sc_nlctent;
273 for (le = iop->sc_lct->entry; nent != 0; nent--, le++)
274 if ((le16toh(le->classid) & 4095) ==
275 I2O_CLASS_BUS_ADAPTER_PORT &&
276 (le32toh(le->usertid) & 4095) == bptid) {
277 bptid = le16toh(le->localtid) & 4095;
278 break;
279 }
280
281 nent = iop->sc_nlctent;
282 for (i = 0, le = iop->sc_lct->entry; i < nent; i++, le++) {
283 if ((le16toh(le->classid) & 4095) != I2O_CLASS_SCSI_PERIPHERAL)
284 continue;
285 if (((le32toh(le->usertid) >> 12) & 4095) != bptid)
286 continue;
287 tid = le16toh(le->localtid) & 4095;
288
289 rv = iop_field_get_all(iop, tid, I2O_PARAM_SCSI_DEVICE_INFO,
290 ¶m, sizeof(param), NULL);
291 if (rv != 0)
292 continue;
293 targ = le32toh(param.sdi.identifier);
294 lun = param.sdi.luninfo[1];
295 #if defined(DIAGNOSTIC) || defined(I2ODEBUG)
296 if (targ >= sc_chan->chan_ntargets ||
297 lun >= sc_chan->chan_nluns) {
298 printf("%s: target %d,%d (tid %d): bad target/LUN\n",
299 sc->sc_dv.dv_xname, targ, lun, tid);
300 continue;
301 }
302 #endif
303
304 #ifdef I2OVERBOSE
305 /*
306 * If we've already described this target, and nothing has
307 * changed, then don't describe it again.
308 */
309 it = &sc->sc_targetmap[targ];
310 it->it_flags |= IT_PRESENT;
311 syncrate = ((int)le64toh(param.sdi.negsyncrate) + 500) / 1000;
312 if (it->it_width == param.sdi.negdatawidth &&
313 it->it_offset == param.sdi.negoffset &&
314 it->it_syncrate == syncrate)
315 continue;
316
317 it->it_width = param.sdi.negdatawidth;
318 it->it_offset = param.sdi.negoffset;
319 it->it_syncrate = syncrate;
320
321 printf("%s: target %d (tid %d): %d-bit, ", sc->sc_dv.dv_xname,
322 targ, tid, it->it_width);
323 if (it->it_syncrate == 0)
324 printf("asynchronous\n");
325 else
326 printf("synchronous at %dMHz, offset 0x%x\n",
327 it->it_syncrate, it->it_offset);
328 #endif
329
330 /* Ignore the device if it's in use by somebody else. */
331 if ((le32toh(le->usertid) & 4095) != I2O_TID_NONE) {
332 #ifdef I2OVERBOSE
333 if (sc->sc_tidmap == NULL ||
334 IOPSP_TIDMAP(sc->sc_tidmap, targ, lun) !=
335 IOPSP_TID_INUSE)
336 printf("%s: target %d,%d (tid %d): in use by"
337 " tid %d\n", sc->sc_dv.dv_xname,
338 targ, lun, tid,
339 le32toh(le->usertid) & 4095);
340 #endif
341 IOPSP_TIDMAP(tidmap, targ, lun) = IOPSP_TID_INUSE;
342 } else
343 IOPSP_TIDMAP(tidmap, targ, lun) = (u_short)tid;
344 }
345
346 #ifdef I2OVERBOSE
347 for (i = 0; i < sc_chan->chan_ntargets; i++)
348 if ((sc->sc_targetmap[i].it_flags & IT_PRESENT) == 0)
349 sc->sc_targetmap[i].it_width = 0;
350 #endif
351
352 /* Swap in the new map and return. */
353 s = splbio();
354 if (sc->sc_tidmap != NULL)
355 free(sc->sc_tidmap, M_DEVBUF);
356 sc->sc_tidmap = tidmap;
357 splx(s);
358 sc->sc_chgind = iop->sc_chgind;
359 return (0);
360 }
361
362 /*
363 * Re-scan the bus; to be called from a higher level (e.g. scsipi).
364 */
365 static int
366 iopsp_rescan(struct iopsp_softc *sc)
367 {
368 struct iop_softc *iop;
369 struct iop_msg *im;
370 struct i2o_hba_bus_scan mf;
371 int rv;
372
373 iop = (struct iop_softc *)sc->sc_dv.dv_parent;
374
375 rv = lockmgr(&iop->sc_conflock, LK_EXCLUSIVE, NULL);
376 if (rv != 0) {
377 #ifdef I2ODEBUG
378 printf("iopsp_rescan: unable to acquire lock\n");
379 #endif
380 return (rv);
381 }
382
383 im = iop_msg_alloc(iop, IM_WAIT);
384
385 mf.msgflags = I2O_MSGFLAGS(i2o_hba_bus_scan);
386 mf.msgfunc = I2O_MSGFUNC(sc->sc_ii.ii_tid, I2O_HBA_BUS_SCAN);
387 mf.msgictx = sc->sc_ii.ii_ictx;
388 mf.msgtctx = im->im_tctx;
389
390 rv = iop_msg_post(iop, im, &mf, 5*60*1000);
391 iop_msg_free(iop, im);
392 if (rv != 0)
393 printf("%s: bus rescan failed (error %d)\n",
394 sc->sc_dv.dv_xname, rv);
395
396 if ((rv = iop_lct_get(iop)) == 0)
397 rv = iopsp_reconfig(&sc->sc_dv);
398
399 lockmgr(&iop->sc_conflock, LK_RELEASE, NULL);
400 return (rv);
401 }
402
403 /*
404 * Start a SCSI command.
405 */
406 static void
407 iopsp_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req,
408 void *arg)
409 {
410 struct scsipi_xfer *xs;
411 struct scsipi_periph *periph;
412 struct iopsp_softc *sc;
413 struct iop_msg *im;
414 struct iop_softc *iop;
415 struct i2o_scsi_scb_exec *mf;
416 int error, flags, tid, s;
417 u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
418
419 sc = (void *)chan->chan_adapter->adapt_dev;
420 iop = (struct iop_softc *)sc->sc_dv.dv_parent;
421
422 switch (req) {
423 case ADAPTER_REQ_RUN_XFER:
424 xs = arg;
425 periph = xs->xs_periph;
426 flags = xs->xs_control;
427
428 tid = IOPSP_TIDMAP(sc->sc_tidmap, periph->periph_target,
429 periph->periph_lun);
430 if (tid == IOPSP_TID_ABSENT || tid == IOPSP_TID_INUSE) {
431 xs->error = XS_SELTIMEOUT;
432 scsipi_done(xs);
433 return;
434 }
435
436 SC_DEBUG(periph, SCSIPI_DB2, ("iopsp_scsi_request run_xfer\n"));
437
438 /* Need to reset the target? */
439 if ((flags & XS_CTL_RESET) != 0) {
440 if (iop_simple_cmd(iop, tid, I2O_SCSI_DEVICE_RESET,
441 sc->sc_ii.ii_ictx, 1, 30*1000) != 0) {
442 #ifdef I2ODEBUG
443 printf("%s: reset failed\n",
444 sc->sc_dv.dv_xname);
445 #endif
446 xs->error = XS_DRIVER_STUFFUP;
447 } else
448 xs->error = XS_NOERROR;
449
450 scsipi_done(xs);
451 return;
452 }
453
454 #if defined(I2ODEBUG) || defined(SCSIDEBUG)
455 if (xs->cmdlen > sizeof(mf->cdb))
456 panic("%s: CDB too large\n", sc->sc_dv.dv_xname);
457 #endif
458
459 im = iop_msg_alloc(iop, IM_POLL_INTR |
460 IM_NOSTATUS | ((flags & XS_CTL_POLL) != 0 ? IM_POLL : 0));
461 im->im_dvcontext = xs;
462
463 mf = (struct i2o_scsi_scb_exec *)mb;
464 mf->msgflags = I2O_MSGFLAGS(i2o_scsi_scb_exec);
465 mf->msgfunc = I2O_MSGFUNC(tid, I2O_SCSI_SCB_EXEC);
466 mf->msgictx = sc->sc_ii.ii_ictx;
467 mf->msgtctx = im->im_tctx;
468 mf->flags = xs->cmdlen | I2O_SCB_FLAG_ENABLE_DISCONNECT |
469 I2O_SCB_FLAG_SENSE_DATA_IN_MESSAGE;
470 mf->datalen = xs->datalen;
471 memcpy(mf->cdb, xs->cmd, xs->cmdlen);
472
473 switch (xs->xs_tag_type) {
474 case MSG_ORDERED_Q_TAG:
475 mf->flags |= I2O_SCB_FLAG_ORDERED_QUEUE_TAG;
476 break;
477 case MSG_SIMPLE_Q_TAG:
478 mf->flags |= I2O_SCB_FLAG_SIMPLE_QUEUE_TAG;
479 break;
480 case MSG_HEAD_OF_Q_TAG:
481 mf->flags |= I2O_SCB_FLAG_HEAD_QUEUE_TAG;
482 break;
483 default:
484 break;
485 }
486
487 if (xs->datalen != 0) {
488 error = iop_msg_map_bio(iop, im, mb, xs->data,
489 xs->datalen, (flags & XS_CTL_DATA_OUT) == 0);
490 if (error) {
491 xs->error = XS_DRIVER_STUFFUP;
492 iop_msg_free(iop, im);
493 scsipi_done(xs);
494 return;
495 }
496 if ((flags & XS_CTL_DATA_IN) == 0)
497 mf->flags |= I2O_SCB_FLAG_XFER_TO_DEVICE;
498 else
499 mf->flags |= I2O_SCB_FLAG_XFER_FROM_DEVICE;
500 }
501
502 s = splbio();
503 sc->sc_curqd++;
504 splx(s);
505
506 if (iop_msg_post(iop, im, mb, xs->timeout)) {
507 s = splbio();
508 sc->sc_curqd--;
509 splx(s);
510 if (xs->datalen != 0)
511 iop_msg_unmap(iop, im);
512 iop_msg_free(iop, im);
513 xs->error = XS_DRIVER_STUFFUP;
514 scsipi_done(xs);
515 }
516 break;
517
518 case ADAPTER_REQ_GROW_RESOURCES:
519 /*
520 * Not supported.
521 */
522 break;
523
524 case ADAPTER_REQ_SET_XFER_MODE:
525 /*
526 * The DDM takes care of this, and we can't modify its
527 * behaviour.
528 */
529 break;
530 }
531 }
532
533 #ifdef notyet
534 /*
535 * Abort the specified I2O_SCSI_SCB_EXEC message and its associated SCB.
536 */
537 static int
538 iopsp_scsi_abort(struct iopsp_softc *sc, int atid, struct iop_msg *aim)
539 {
540 struct iop_msg *im;
541 struct i2o_scsi_scb_abort mf;
542 struct iop_softc *iop;
543 int rv, s;
544
545 iop = (struct iop_softc *)sc->sc_dv.dv_parent;
546 im = iop_msg_alloc(iop, IM_POLL);
547
548 mf.msgflags = I2O_MSGFLAGS(i2o_scsi_scb_abort);
549 mf.msgfunc = I2O_MSGFUNC(atid, I2O_SCSI_SCB_ABORT);
550 mf.msgictx = sc->sc_ii.ii_ictx;
551 mf.msgtctx = im->im_tctx;
552 mf.tctxabort = aim->im_tctx;
553
554 s = splbio();
555 rv = iop_msg_post(iop, im, &mf, 30000);
556 splx(s);
557 iop_msg_free(iop, im);
558 return (rv);
559 }
560 #endif
561
562 /*
563 * We have a message which has been processed and replied to by the IOP -
564 * deal with it.
565 */
566 static void
567 iopsp_intr(struct device *dv, struct iop_msg *im, void *reply)
568 {
569 struct scsipi_xfer *xs;
570 struct iopsp_softc *sc;
571 struct i2o_scsi_reply *rb;
572 struct iop_softc *iop;
573 u_int sl;
574
575 sc = (struct iopsp_softc *)dv;
576 xs = (struct scsipi_xfer *)im->im_dvcontext;
577 iop = (struct iop_softc *)dv->dv_parent;
578 rb = reply;
579
580 SC_DEBUG(xs->xs_periph, SCSIPI_DB2, ("iopsp_intr\n"));
581
582 if ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0) {
583 xs->error = XS_DRIVER_STUFFUP;
584 xs->resid = xs->datalen;
585 } else {
586 if (rb->hbastatus != I2O_SCSI_DSC_SUCCESS) {
587 switch (rb->hbastatus) {
588 case I2O_SCSI_DSC_ADAPTER_BUSY:
589 case I2O_SCSI_DSC_SCSI_BUS_RESET:
590 case I2O_SCSI_DSC_BUS_BUSY:
591 xs->error = XS_BUSY;
592 break;
593 case I2O_SCSI_DSC_SELECTION_TIMEOUT:
594 xs->error = XS_SELTIMEOUT;
595 break;
596 case I2O_SCSI_DSC_COMMAND_TIMEOUT:
597 case I2O_SCSI_DSC_DEVICE_NOT_PRESENT:
598 case I2O_SCSI_DSC_LUN_INVALID:
599 case I2O_SCSI_DSC_SCSI_TID_INVALID:
600 xs->error = XS_TIMEOUT;
601 break;
602 default:
603 xs->error = XS_DRIVER_STUFFUP;
604 break;
605 }
606 printf("%s: HBA status 0x%02x\n", sc->sc_dv.dv_xname,
607 rb->hbastatus);
608 } else if (rb->scsistatus != SCSI_OK) {
609 switch (rb->scsistatus) {
610 case SCSI_CHECK:
611 xs->error = XS_SENSE;
612 sl = le32toh(rb->senselen);
613 if (sl > sizeof(xs->sense.scsi_sense))
614 sl = sizeof(xs->sense.scsi_sense);
615 memcpy(&xs->sense.scsi_sense, rb->sense, sl);
616 break;
617 case SCSI_QUEUE_FULL:
618 case SCSI_BUSY:
619 xs->error = XS_BUSY;
620 break;
621 default:
622 xs->error = XS_DRIVER_STUFFUP;
623 break;
624 }
625 } else
626 xs->error = XS_NOERROR;
627
628 xs->resid = xs->datalen - le32toh(rb->datalen);
629 xs->status = rb->scsistatus;
630 }
631
632 /* Free the message wrapper and pass the news to scsipi. */
633 if (xs->datalen != 0)
634 iop_msg_unmap(iop, im);
635 iop_msg_free(iop, im);
636
637 if (--sc->sc_curqd == sc->sc_adapter.adapt_openings)
638 wakeup(&sc->sc_curqd);
639
640 scsipi_done(xs);
641 }
642
643 /*
644 * ioctl hook; used here only to initiate low-level rescans.
645 */
646 static int
647 iopsp_ioctl(struct scsipi_channel *chan, u_long cmd, caddr_t data, int flag,
648 struct proc *p)
649 {
650 int rv;
651
652 switch (cmd) {
653 case SCBUSIOLLSCAN:
654 /*
655 * If it's boot time, the bus will have been scanned and the
656 * maps built. Locking would stop re-configuration, but we
657 * want to fake success.
658 */
659 if (p != &proc0)
660 rv = iopsp_rescan(
661 (struct iopsp_softc *)chan->chan_adapter->adapt_dev);
662 else
663 rv = 0;
664 break;
665
666 default:
667 rv = ENOTTY;
668 break;
669 }
670
671 return (rv);
672 }
673
674 /*
675 * The number of openings available to us has changed, so inform scsipi.
676 */
677 static void
678 iopsp_adjqparam(struct device *dv, int mpi)
679 {
680 struct iopsp_softc *sc;
681 int s;
682
683 sc = (struct iopsp_softc *)dv;
684
685 s = splbio();
686 sc->sc_adapter.adapt_openings = mpi;
687 if (mpi < sc->sc_curqd)
688 tsleep(&sc->sc_curqd, PWAIT, "iopspdrn", 0);
689 splx(s);
690 }
691