scsi_pass.c revision 40398
1/*
2 * Copyright (c) 1997, 1998 Justin T. Gibbs.
3 * Copyright (c) 1997, 1998 Kenneth D. Merry.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions, and the following disclaimer,
11 *    without modification, immediately at the beginning of the file.
12 * 2. The name of the author may not be used to endorse or promote products
13 *    derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 *      $Id: scsi_pass.c,v 1.2 1998/09/16 00:11:53 ken Exp $
28 */
29
30#include <sys/param.h>
31#include <sys/queue.h>
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/types.h>
35#include <sys/buf.h>
36#include <sys/dkbad.h>
37#include <sys/disklabel.h>
38#include <sys/diskslice.h>
39#include <sys/malloc.h>
40#include <sys/fcntl.h>
41#include <sys/stat.h>
42#include <sys/conf.h>
43#include <sys/buf.h>
44#include <sys/proc.h>
45#include <sys/cdio.h>
46#include <sys/errno.h>
47#include <sys/devicestat.h>
48
49#include <cam/cam.h>
50#include <cam/cam_ccb.h>
51#include <cam/cam_extend.h>
52#include <cam/cam_periph.h>
53#include <cam/cam_xpt_periph.h>
54#include <cam/cam_debug.h>
55
56#include <cam/scsi/scsi_all.h>
57#include <cam/scsi/scsi_message.h>
58#include <cam/scsi/scsi_da.h>
59#include <cam/scsi/scsi_pass.h>
60
61typedef enum {
62	PASS_FLAG_OPEN			= 0x01,
63	PASS_FLAG_LOCKED		= 0x02,
64	PASS_FLAG_INVALID		= 0x04
65} pass_flags;
66
67typedef enum {
68	PASS_STATE_NORMAL
69} pass_state;
70
71typedef enum {
72	PASS_CCB_BUFFER_IO,
73	PASS_CCB_WAITING
74} pass_ccb_types;
75
76#define ccb_type	ppriv_field0
77#define ccb_bp		ppriv_ptr1
78
79struct pass_softc {
80	pass_state	state;
81	pass_flags	flags;
82	u_int8_t	pd_type;
83	struct		buf_queue_head buf_queue;
84	union ccb	saved_ccb;
85	struct devstat	device_stats;
86#ifdef DEVFS
87	void		*pass_devfs_token;
88	void		*ctl_devfs_token;
89#endif
90};
91
92#ifndef MIN
93#define MIN(x,y) ((x<y) ? x : y)
94#endif
95
96#define PASS_CDEV_MAJOR 31
97
98static	d_open_t	passopen;
99static	d_read_t	passread;
100static	d_write_t	passwrite;
101static	d_close_t	passclose;
102static	d_ioctl_t	passioctl;
103static	d_strategy_t	passstrategy;
104
105static	periph_init_t	passinit;
106static	periph_ctor_t	passregister;
107static	periph_dtor_t	passcleanup;
108static	periph_start_t	passstart;
109static	void		passasync(void *callback_arg, u_int32_t code,
110				  struct cam_path *path, void *arg);
111static	void		passdone(struct cam_periph *periph,
112				 union ccb *done_ccb);
113static	int		passerror(union ccb *ccb, u_int32_t cam_flags,
114				  u_int32_t sense_flags);
115static 	int		passsendccb(struct cam_periph *periph, union ccb *ccb,
116				    union ccb *inccb);
117
118static struct periph_driver passdriver =
119{
120	passinit, "pass",
121	TAILQ_HEAD_INITIALIZER(passdriver.units), /* generation */ 0
122};
123
124DATA_SET(periphdriver_set, passdriver);
125
126static struct cdevsw pass_cdevsw =
127{
128	/*d_open*/	passopen,
129	/*d_close*/	passclose,
130	/*d_read*/	passread,
131	/*d_write*/	passwrite,
132	/*d_ioctl*/	passioctl,
133	/*d_stop*/	nostop,
134	/*d_reset*/	noreset,
135	/*d_devtotty*/	nodevtotty,
136	/*d_poll*/	seltrue,
137	/*d_mmap*/	nommap,
138	/*d_strategy*/	passstrategy,
139	/*d_name*/	"pass",
140	/*d_spare*/	NULL,
141	/*d_maj*/	-1,
142	/*d_dump*/	nodump,
143	/*d_psize*/	nopsize,
144	/*d_flags*/	0,
145	/*d_maxio*/	0,
146	/*b_maj*/	-1
147};
148
149static struct extend_array *passperiphs;
150
151static void
152passinit(void)
153{
154	cam_status status;
155	struct cam_path *path;
156
157	/*
158	 * Create our extend array for storing the devices we attach to.
159	 */
160	passperiphs = cam_extend_new();
161	if (passperiphs == NULL) {
162		printf("passm: Failed to alloc extend array!\n");
163		return;
164	}
165
166	/*
167	 * Install a global async callback.  This callback will
168	 * receive async callbacks like "new device found".
169	 */
170	status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID,
171				 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
172
173	if (status == CAM_REQ_CMP) {
174		struct ccb_setasync csa;
175
176                xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5);
177                csa.ccb_h.func_code = XPT_SASYNC_CB;
178                csa.event_enable = AC_FOUND_DEVICE;
179                csa.callback = passasync;
180                csa.callback_arg = NULL;
181                xpt_action((union ccb *)&csa);
182		status = csa.ccb_h.status;
183                xpt_free_path(path);
184        }
185
186	if (status != CAM_REQ_CMP) {
187		printf("pass: Failed to attach master async callback "
188		       "due to status 0x%x!\n", status);
189	} else {
190		dev_t dev;
191
192		/* If we were successfull, register our devsw */
193		dev = makedev(PASS_CDEV_MAJOR, 0);
194		cdevsw_add(&dev, &pass_cdevsw, NULL);
195	}
196
197}
198
199static void
200passcleanup(struct cam_periph *periph)
201{
202	cam_extend_release(passperiphs, periph->unit_number);
203
204	if (bootverbose) {
205		xpt_print_path(periph->path);
206		printf("removing device entry\n");
207	}
208	free(periph->softc, M_DEVBUF);
209}
210
211static void
212passasync(void *callback_arg, u_int32_t code,
213	  struct cam_path *path, void *arg)
214{
215	struct cam_periph *periph;
216
217	periph = (struct cam_periph *)callback_arg;
218
219	switch (code) {
220	case AC_FOUND_DEVICE:
221	{
222		struct ccb_getdev *cgd;
223		cam_status status;
224
225		cgd = (struct ccb_getdev *)arg;
226
227		/*
228		 * Allocate a peripheral instance for
229		 * this device and start the probe
230		 * process.
231		 */
232		status = cam_periph_alloc(passregister, passcleanup, passstart,
233					  "pass", CAM_PERIPH_BIO,
234					  cgd->ccb_h.path, passasync,
235					  AC_FOUND_DEVICE, cgd);
236
237		if (status != CAM_REQ_CMP
238		 && status != CAM_REQ_INPROG)
239			printf("passasync: Unable to attach new device "
240				"due to status 0x%x\n", status);
241
242		break;
243	}
244	case AC_LOST_DEVICE:
245	{
246		int s;
247		struct pass_softc *softc;
248		struct buf *q_bp;
249		struct ccb_setasync csa;
250
251		softc = (struct pass_softc *)periph->softc;
252
253		/*
254		 * Insure that no other async callbacks that
255		 * might affect this peripheral can come through.
256		 */
257		s = splcam();
258
259		/*
260		 * De-register any async callbacks.
261		 */
262		xpt_setup_ccb(&csa.ccb_h, periph->path,
263			      /* priority */ 5);
264		csa.ccb_h.func_code = XPT_SASYNC_CB;
265		csa.event_enable = 0;
266		csa.callback = passasync;
267		csa.callback_arg = periph;
268		xpt_action((union ccb *)&csa);
269
270		softc->flags |= PASS_FLAG_INVALID;
271
272		/*
273		 * Return all queued I/O with ENXIO.
274		 * XXX Handle any transactions queued to the card
275		 *     with XPT_ABORT_CCB.
276		 */
277		while ((q_bp = bufq_first(&softc->buf_queue)) != NULL){
278			bufq_remove(&softc->buf_queue, q_bp);
279			q_bp->b_resid = q_bp->b_bcount;
280			q_bp->b_error = ENXIO;
281			q_bp->b_flags |= B_ERROR;
282			biodone(q_bp);
283		}
284		devstat_remove_entry(&softc->device_stats);
285
286		if (bootverbose) {
287			xpt_print_path(periph->path);
288			printf("lost device\n");
289		}
290
291		splx(s);
292
293		cam_periph_invalidate(periph);
294		break;
295	}
296	case AC_TRANSFER_NEG:
297	case AC_SENT_BDR:
298	case AC_SCSI_AEN:
299	case AC_UNSOL_RESEL:
300	case AC_BUS_RESET:
301	default:
302		break;
303	}
304}
305
306static cam_status
307passregister(struct cam_periph *periph, void *arg)
308{
309	struct pass_softc *softc;
310	struct ccb_setasync csa;
311	struct ccb_getdev *cgd;
312
313	cgd = (struct ccb_getdev *)arg;
314	if (periph == NULL) {
315		printf("passregister: periph was NULL!!\n");
316		return(CAM_REQ_CMP_ERR);
317	}
318
319	if (cgd == NULL) {
320		printf("passregister: no getdev CCB, can't register device\n");
321		return(CAM_REQ_CMP_ERR);
322	}
323
324	softc = (struct pass_softc *)malloc(sizeof(*softc),
325					    M_DEVBUF, M_NOWAIT);
326
327	if (softc == NULL) {
328		printf("passregister: Unable to probe new device. "
329		       "Unable to allocate softc\n");
330		return(CAM_REQ_CMP_ERR);
331	}
332
333	bzero(softc, sizeof(*softc));
334	softc->state = PASS_STATE_NORMAL;
335	softc->pd_type = cgd->pd_type;
336	bufq_init(&softc->buf_queue);
337
338	periph->softc = softc;
339
340	cam_extend_set(passperiphs, periph->unit_number, periph);
341	/*
342	 * We pass in 0 for a blocksize, since we don't
343	 * know what the blocksize of this device is, if
344	 * it even has a blocksize.
345	 */
346	devstat_add_entry(&softc->device_stats, "pass", periph->unit_number,
347			  0, DEVSTAT_NO_BLOCKSIZE | DEVSTAT_NO_ORDERED_TAGS,
348			  cgd->pd_type |
349			  DEVSTAT_TYPE_IF_SCSI |
350			  DEVSTAT_TYPE_PASS);
351	/*
352	 * Add an async callback so that we get
353	 * notified if this device goes away.
354	 */
355	xpt_setup_ccb(&csa.ccb_h, periph->path, /* priority */ 5);
356	csa.ccb_h.func_code = XPT_SASYNC_CB;
357	csa.event_enable = AC_LOST_DEVICE;
358	csa.callback = passasync;
359	csa.callback_arg = periph;
360	xpt_action((union ccb *)&csa);
361
362	if (bootverbose)
363		xpt_announce_periph(periph, NULL);
364
365	return(CAM_REQ_CMP);
366}
367
368static int
369passopen(dev_t dev, int flags, int fmt, struct proc *p)
370{
371	struct cam_periph *periph;
372	struct pass_softc *softc;
373	int unit, error;
374
375	error = 0; /* default to no error */
376
377	/* unit = dkunit(dev); */
378	/* XXX KDM fix this */
379	unit = minor(dev) & 0xff;
380
381	periph = cam_extend_get(passperiphs, unit);
382
383	if (periph == NULL)
384		return (ENXIO);
385
386	softc = (struct pass_softc *)periph->softc;
387
388	if (softc->flags & PASS_FLAG_INVALID)
389		return(ENXIO);
390
391	/*
392	 * Only allow read-write access.
393	 */
394	if (((flags & FWRITE) == 0) || ((flags & FREAD) == 0))
395		return(EPERM);
396
397	/*
398	 * We don't allow nonblocking access.
399	 */
400	if ((flags & O_NONBLOCK) != 0) {
401		printf("%s%d: can't do nonblocking accesss\n",
402			periph->periph_name,
403			periph->unit_number);
404		return(ENODEV);
405	}
406
407	if ((error = cam_periph_lock(periph, PRIBIO | PCATCH)) != 0)
408		return (error);
409
410	if ((softc->flags & PASS_FLAG_OPEN) == 0) {
411		if (cam_periph_acquire(periph) != CAM_REQ_CMP)
412			return(ENXIO);
413		softc->flags |= PASS_FLAG_OPEN;
414	}
415
416	cam_periph_unlock(periph);
417
418	return (error);
419}
420
421static int
422passclose(dev_t dev, int flag, int fmt, struct proc *p)
423{
424	struct 	cam_periph *periph;
425	struct	pass_softc *softc;
426	int	unit, error;
427
428	/* unit = dkunit(dev); */
429	/* XXX KDM fix this */
430	unit = minor(dev) & 0xff;
431
432	periph = cam_extend_get(passperiphs, unit);
433	if (periph == NULL)
434		return (ENXIO);
435
436	softc = (struct pass_softc *)periph->softc;
437
438	if ((error = cam_periph_lock(periph, PRIBIO)) != 0)
439		return (error);
440
441	softc->flags &= ~PASS_FLAG_OPEN;
442
443	cam_periph_unlock(periph);
444	cam_periph_release(periph);
445
446	return (0);
447}
448
449static int
450passread(dev_t dev, struct uio *uio, int ioflag)
451{
452	return(physio(passstrategy, NULL, dev, 1, minphys, uio));
453}
454
455static int
456passwrite(dev_t dev, struct uio *uio, int ioflag)
457{
458	return(physio(passstrategy, NULL, dev, 0, minphys, uio));
459}
460
461/*
462 * Actually translate the requested transfer into one the physical driver
463 * can understand.  The transfer is described by a buf and will include
464 * only one physical transfer.
465 */
466static void
467passstrategy(struct buf *bp)
468{
469	struct cam_periph *periph;
470	struct pass_softc *softc;
471	u_int  unit;
472	int    s;
473
474	/*
475	 * The read/write interface for the passthrough driver doesn't
476	 * really work right now.  So, we just pass back EINVAL to tell the
477	 * user to go away.
478	 */
479	bp->b_error = EINVAL;
480	goto bad;
481
482	/* unit = dkunit(bp->b_dev); */
483	/* XXX KDM fix this */
484	unit = minor(bp->b_dev) & 0xff;
485
486	periph = cam_extend_get(passperiphs, unit);
487	if (periph == NULL) {
488		bp->b_error = ENXIO;
489		goto bad;
490	}
491	softc = (struct pass_softc *)periph->softc;
492
493	/*
494	 * Odd number of bytes or negative offset
495	 */
496	/* valid request?  */
497	if (bp->b_blkno < 0) {
498		bp->b_error = EINVAL;
499		goto bad;
500        }
501
502	/*
503	 * Mask interrupts so that the pack cannot be invalidated until
504	 * after we are in the queue.  Otherwise, we might not properly
505	 * clean up one of the buffers.
506	 */
507	s = splbio();
508
509	bufq_insert_tail(&softc->buf_queue, bp);
510
511	splx(s);
512
513	/*
514	 * Schedule ourselves for performing the work.
515	 */
516	xpt_schedule(periph, /* XXX priority */1);
517
518	return;
519bad:
520	bp->b_flags |= B_ERROR;
521
522	/*
523	 * Correctly set the buf to indicate a completed xfer
524	 */
525	bp->b_resid = bp->b_bcount;
526	biodone(bp);
527	return;
528}
529
530static void
531passstart(struct cam_periph *periph, union ccb *start_ccb)
532{
533	struct pass_softc *softc;
534	int s;
535
536	softc = (struct pass_softc *)periph->softc;
537
538	switch (softc->state) {
539	case PASS_STATE_NORMAL:
540	{
541		struct buf *bp;
542
543		s = splbio();
544		bp = bufq_first(&softc->buf_queue);
545		if (periph->immediate_priority <= periph->pinfo.priority) {
546			start_ccb->ccb_h.ccb_type = PASS_CCB_WAITING;
547			SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
548					  periph_links.sle);
549			periph->immediate_priority = CAM_PRIORITY_NONE;
550			splx(s);
551			wakeup(&periph->ccb_list);
552		} else if (bp == NULL) {
553			splx(s);
554			xpt_release_ccb(start_ccb);
555		} else {
556
557			bufq_remove(&softc->buf_queue, bp);
558
559			devstat_start_transaction(&softc->device_stats);
560
561			/*
562			 * XXX JGibbs -
563			 * Interpret the contents of the bp as a CCB
564			 * and pass it to a routine shared by our ioctl
565			 * code and passtart.
566			 * For now, just biodone it with EIO so we don't
567			 * hang.
568			 */
569			bp->b_error = EIO;
570			bp->b_flags |= B_ERROR;
571			bp->b_resid = bp->b_bcount;
572			biodone(bp);
573			bp = bufq_first(&softc->buf_queue);
574			splx(s);
575
576			xpt_action(start_ccb);
577
578		}
579		if (bp != NULL) {
580			/* Have more work to do, so ensure we stay scheduled */
581			xpt_schedule(periph, /* XXX priority */1);
582		}
583		break;
584	}
585	}
586}
587static void
588passdone(struct cam_periph *periph, union ccb *done_ccb)
589{
590	struct pass_softc *softc;
591	struct ccb_scsiio *csio;
592
593	softc = (struct pass_softc *)periph->softc;
594	csio = &done_ccb->csio;
595	switch (csio->ccb_h.ccb_type) {
596	case PASS_CCB_BUFFER_IO:
597	{
598		struct buf		*bp;
599		cam_status		status;
600		u_int8_t		scsi_status;
601		devstat_trans_flags	ds_flags;
602
603		status = done_ccb->ccb_h.status;
604		scsi_status = done_ccb->csio.scsi_status;
605		bp = (struct buf *)done_ccb->ccb_h.ccb_bp;
606		/* XXX handle errors */
607		if (!(((status & CAM_STATUS_MASK) == CAM_REQ_CMP)
608		  && (scsi_status == SCSI_STATUS_OK))) {
609			int error;
610
611			if ((error = passerror(done_ccb, 0, 0)) == ERESTART) {
612				/*
613				 * A retry was scheuled, so
614				 * just return.
615				 */
616				return;
617			}
618
619			/*
620			 * XXX unfreeze the queue after we complete
621			 * the abort process
622			 */
623			bp->b_error = error;
624			bp->b_flags |= B_ERROR;
625		}
626
627		if ((done_ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
628			ds_flags = DEVSTAT_READ;
629		else if ((done_ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT)
630			ds_flags = DEVSTAT_WRITE;
631		else
632			ds_flags = DEVSTAT_NO_DATA;
633
634		devstat_end_transaction(&softc->device_stats, bp->b_bcount,
635					done_ccb->csio.tag_action & 0xf,
636					ds_flags);
637
638		biodone(bp);
639		break;
640	}
641	case PASS_CCB_WAITING:
642	{
643		/* Caller will release the CCB */
644		wakeup(&done_ccb->ccb_h.cbfcnp);
645		return;
646	}
647	}
648	xpt_release_ccb(done_ccb);
649}
650
651static int
652passioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
653{
654	struct 	cam_periph *periph;
655	struct	pass_softc *softc;
656	u_int8_t unit;
657	int      error;
658
659
660	/* unit = dkunit(dev); */
661	/* XXX KDM fix this */
662	unit = minor(dev) & 0xff;
663
664	periph = cam_extend_get(passperiphs, unit);
665
666	if (periph == NULL)
667		return(ENXIO);
668
669	softc = (struct pass_softc *)periph->softc;
670
671	error = 0;
672
673	switch (cmd) {
674
675	case CAMIOCOMMAND:
676	{
677		union ccb *inccb;
678		union ccb *ccb;
679
680		inccb = (union ccb *)addr;
681		ccb = cam_periph_getccb(periph, inccb->ccb_h.pinfo.priority);
682
683		error = passsendccb(periph, ccb, inccb);
684
685		xpt_release_ccb(ccb);
686
687		break;
688	}
689	default:
690		error = cam_periph_ioctl(periph, cmd, addr, passerror);
691		break;
692	}
693
694	return(error);
695}
696
697/*
698 * Generally, "ccb" should be the CCB supplied by the kernel.  "inccb"
699 * should be the CCB that is copied in from the user.
700 */
701static int
702passsendccb(struct cam_periph *periph, union ccb *ccb, union ccb *inccb)
703{
704	struct pass_softc *softc;
705	struct cam_periph_map_info mapinfo;
706	int error, need_unmap;
707
708	softc = (struct pass_softc *)periph->softc;
709
710	need_unmap = 0;
711
712	/*
713	 * There are some fields in the CCB header that need to be
714	 * preserved, the rest we get from the user.
715	 */
716	xpt_merge_ccb(ccb, inccb);
717
718	/*
719	 * There's no way for the user to have a completion
720	 * function, so we put our own completion function in here.
721	 */
722	ccb->ccb_h.cbfcnp = passdone;
723
724	/*
725	 * We only attempt to map the user memory into kernel space
726	 * if they haven't passed in a physical memory pointer,
727	 * and if there is actually an I/O operation to perform.
728	 * Right now cam_periph_mapmem() only supports SCSI and device
729	 * match CCBs.  For the SCSI CCBs, we only pass the CCB in if
730	 * there's actually data to map.  cam_periph_mapmem() will do the
731	 * right thing, even if there isn't data to map, but since CCBs
732	 * without data are a reasonably common occurance (e.g. test unit
733	 * ready), it will save a few cycles if we check for it here.
734	 */
735	if (((ccb->ccb_h.flags & CAM_DATA_PHYS) == 0)
736	 && (((ccb->ccb_h.func_code == XPT_SCSI_IO)
737	    && ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE))
738	  || (ccb->ccb_h.func_code == XPT_DEV_MATCH))) {
739
740		bzero(&mapinfo, sizeof(mapinfo));
741
742		error = cam_periph_mapmem(ccb, &mapinfo);
743
744		/*
745		 * cam_periph_mapmem returned an error, we can't continue.
746		 * Return the error to the user.
747		 */
748		if (error)
749			return(error);
750
751		/*
752		 * We successfully mapped the memory in, so we need to
753		 * unmap it when the transaction is done.
754		 */
755		need_unmap = 1;
756	}
757
758	/*
759	 * If the user wants us to perform any error recovery, then honor
760	 * that request.  Otherwise, it's up to the user to perform any
761	 * error recovery.
762	 */
763	error = cam_periph_runccb(ccb,
764				  (ccb->ccb_h.flags & CAM_PASS_ERR_RECOVER) ?
765				  passerror : NULL,
766				  /* cam_flags */ 0,
767				  /* sense_flags */SF_RETRY_UA,
768				  &softc->device_stats);
769
770	if (need_unmap != 0)
771		cam_periph_unmapmem(ccb, &mapinfo);
772
773	ccb->ccb_h.cbfcnp = NULL;
774	ccb->ccb_h.periph_priv = inccb->ccb_h.periph_priv;
775	bcopy(ccb, inccb, sizeof(union ccb));
776
777	return(error);
778}
779
780static int
781passerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
782{
783	struct cam_periph *periph;
784	struct pass_softc *softc;
785
786	periph = xpt_path_periph(ccb->ccb_h.path);
787	softc = (struct pass_softc *)periph->softc;
788
789	return(cam_periph_error(ccb, cam_flags, sense_flags,
790				 &softc->saved_ccb));
791}
792