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