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