scsi_pt.c revision 43819
1/*
2 * Implementation of SCSI Processor Target Peripheral driver for CAM.
3 *
4 * Copyright (c) 1998 Justin T. Gibbs.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions, and the following disclaimer,
12 *    without modification, immediately at the beginning of the file.
13 * 2. The name of the author may not be used to endorse or promote products
14 *    derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 *      $Id: scsi_pt.c,v 1.4 1998/11/22 23:44:47 ken Exp $
29 */
30
31#include <sys/param.h>
32#include <sys/queue.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/types.h>
36#include <sys/buf.h>
37#include <sys/devicestat.h>
38#include <sys/malloc.h>
39#include <sys/conf.h>
40
41#include <cam/cam.h>
42#include <cam/cam_ccb.h>
43#include <cam/cam_extend.h>
44#include <cam/cam_periph.h>
45#include <cam/cam_xpt_periph.h>
46#include <cam/cam_debug.h>
47
48#include <cam/scsi/scsi_all.h>
49#include <cam/scsi/scsi_message.h>
50#include <cam/scsi/scsi_pt.h>
51
52typedef enum {
53	PT_STATE_PROBE,
54	PT_STATE_NORMAL
55} pt_state;
56
57typedef enum {
58	PT_FLAG_NONE		= 0x00,
59	PT_FLAG_OPEN		= 0x01,
60	PT_FLAG_DEVICE_INVALID	= 0x02,
61	PT_FLAG_RETRY_UA	= 0x04
62} pt_flags;
63
64typedef enum {
65	PT_CCB_BUFFER_IO	= 0x01,
66	PT_CCB_WAITING		= 0x02,
67	PT_CCB_RETRY_UA		= 0x04,
68	PT_CCB_BUFFER_IO_UA	= PT_CCB_BUFFER_IO|PT_CCB_RETRY_UA
69} pt_ccb_state;
70
71/* Offsets into our private area for storing information */
72#define ccb_state	ppriv_field0
73#define ccb_bp		ppriv_ptr1
74
75struct pt_softc {
76	struct	 buf_queue_head buf_queue;
77	struct	 devstat device_stats;
78	LIST_HEAD(, ccb_hdr) pending_ccbs;
79	pt_state state;
80	pt_flags flags;
81	union	 ccb saved_ccb;
82};
83
84static	d_open_t	ptopen;
85static	d_read_t	ptread;
86static	d_write_t	ptwrite;
87static	d_close_t	ptclose;
88static	d_strategy_t	ptstrategy;
89static	periph_init_t	ptinit;
90static	void		ptasync(void *callback_arg, u_int32_t code,
91				struct cam_path *path, void *arg);
92static	periph_ctor_t	ptctor;
93static	periph_oninv_t	ptoninvalidate;
94static	periph_dtor_t	ptdtor;
95static	periph_start_t	ptstart;
96static	void		ptdone(struct cam_periph *periph,
97			       union ccb *done_ccb);
98static  int		pterror(union ccb *ccb, u_int32_t cam_flags,
99				u_int32_t sense_flags);
100
101void	scsi_send_receive(struct ccb_scsiio *csio, u_int32_t retries,
102			  void (*cbfcnp)(struct cam_periph *, union ccb *),
103			  u_int tag_action, int readop, u_int byte2,
104			  u_int32_t xfer_len, u_int8_t *data_ptr,
105			  u_int8_t sense_len, u_int32_t timeout);
106
107static struct periph_driver ptdriver =
108{
109	ptinit, "pt",
110	TAILQ_HEAD_INITIALIZER(ptdriver.units), /* generation */ 0
111};
112
113DATA_SET(periphdriver_set, ptdriver);
114
115#define PT_CDEV_MAJOR 61
116
117static struct cdevsw pt_cdevsw =
118{
119	/*d_open*/	ptopen,
120	/*d_close*/	ptclose,
121	/*d_read*/	ptread,
122	/*d_write*/	ptwrite,
123	/*d_ioctl*/	noioctl,
124	/*d_stop*/	nostop,
125	/*d_reset*/	noreset,
126	/*d_devtotty*/	nodevtotty,
127	/*d_poll*/	seltrue,
128	/*d_mmap*/	nommap,
129	/*d_strategy*/	ptstrategy,
130	/*d_name*/	"pt",
131	/*d_spare*/	NULL,
132	/*d_maj*/	-1,
133	/*d_dump*/	nodump,
134	/*d_psize*/	nopsize,
135	/*d_flags*/	0,
136	/*d_maxio*/	0,
137	/*b_maj*/	-1
138};
139
140static struct extend_array *ptperiphs;
141
142static int
143ptopen(dev_t dev, int flags, int fmt, struct proc *p)
144{
145	struct cam_periph *periph;
146	struct pt_softc *softc;
147	int unit;
148	int error;
149	int s;
150
151	unit = minor(dev);
152	periph = cam_extend_get(ptperiphs, unit);
153	if (periph == NULL)
154		return (ENXIO);
155
156	softc = (struct pt_softc *)periph->softc;
157
158	s = splsoftcam();
159	if (softc->flags & PT_FLAG_DEVICE_INVALID) {
160		splx(s);
161		return(ENXIO);
162	}
163
164	CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
165	    ("ptopen: dev=0x%x (unit %d)\n", dev, unit));
166
167	if ((error = cam_periph_lock(periph, PRIBIO|PCATCH)) != 0) {
168		splx(s);
169		return (error); /* error code from tsleep */
170	}
171
172	splx(s);
173
174	if ((softc->flags & PT_FLAG_OPEN) == 0) {
175		if (cam_periph_acquire(periph) != CAM_REQ_CMP)
176			error = ENXIO;
177		else
178			softc->flags |= PT_FLAG_OPEN;
179	} else
180		error = EBUSY;
181
182	cam_periph_unlock(periph);
183	return (error);
184}
185
186static int
187ptclose(dev_t dev, int flag, int fmt, struct proc *p)
188{
189	struct	cam_periph *periph;
190	struct	pt_softc *softc;
191	int	unit;
192	int	error;
193
194	unit = minor(dev);
195	periph = cam_extend_get(ptperiphs, unit);
196	if (periph == NULL)
197		return (ENXIO);
198
199	softc = (struct pt_softc *)periph->softc;
200
201	if ((error = cam_periph_lock(periph, PRIBIO)) != 0)
202		return (error); /* error code from tsleep */
203
204	softc->flags &= ~PT_FLAG_OPEN;
205	cam_periph_unlock(periph);
206	cam_periph_release(periph);
207	return (0);
208}
209
210static int
211ptread(dev_t dev, struct uio *uio, int ioflag)
212{
213	return(physio(ptstrategy, NULL, dev, 1, minphys, uio));
214}
215
216static int
217ptwrite(dev_t dev, struct uio *uio, int ioflag)
218{
219	return(physio(ptstrategy, NULL, dev, 0, minphys, uio));
220}
221
222/*
223 * Actually translate the requested transfer into one the physical driver
224 * can understand.  The transfer is described by a buf and will include
225 * only one physical transfer.
226 */
227static void
228ptstrategy(struct buf *bp)
229{
230	struct cam_periph *periph;
231	struct pt_softc *softc;
232	u_int  unit;
233	int    s;
234
235	unit = minor(bp->b_dev);
236	periph = cam_extend_get(ptperiphs, unit);
237	if (periph == NULL) {
238		bp->b_error = ENXIO;
239		goto bad;
240	}
241	softc = (struct pt_softc *)periph->softc;
242
243	/*
244	 * Mask interrupts so that the pack cannot be invalidated until
245	 * after we are in the queue.  Otherwise, we might not properly
246	 * clean up one of the buffers.
247	 */
248	s = splbio();
249
250	/*
251	 * If the device has been made invalid, error out
252	 */
253	if ((softc->flags & PT_FLAG_DEVICE_INVALID)) {
254		splx(s);
255		bp->b_error = ENXIO;
256		goto bad;
257	}
258
259	/*
260	 * Place it in the queue of disk activities for this disk
261	 */
262	bufq_insert_tail(&softc->buf_queue, bp);
263
264	splx(s);
265
266	/*
267	 * Schedule ourselves for performing the work.
268	 */
269	xpt_schedule(periph, /* XXX priority */1);
270
271	return;
272bad:
273	bp->b_flags |= B_ERROR;
274
275	/*
276	 * Correctly set the buf to indicate a completed xfer
277	 */
278	bp->b_resid = bp->b_bcount;
279	biodone(bp);
280}
281
282static void
283ptinit(void)
284{
285	cam_status status;
286	struct cam_path *path;
287
288	/*
289	 * Create our extend array for storing the devices we attach to.
290	 */
291	ptperiphs = cam_extend_new();
292	if (ptperiphs == NULL) {
293		printf("pt: Failed to alloc extend array!\n");
294		return;
295	}
296
297	/*
298	 * Install a global async callback.  This callback will
299	 * receive async callbacks like "new device found".
300	 */
301	status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID,
302				 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
303
304	if (status == CAM_REQ_CMP) {
305		struct ccb_setasync csa;
306
307                xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5);
308                csa.ccb_h.func_code = XPT_SASYNC_CB;
309                csa.event_enable = AC_FOUND_DEVICE;
310                csa.callback = ptasync;
311                csa.callback_arg = NULL;
312                xpt_action((union ccb *)&csa);
313		status = csa.ccb_h.status;
314                xpt_free_path(path);
315        }
316
317	if (status != CAM_REQ_CMP) {
318		printf("pt: Failed to attach master async callback "
319		       "due to status 0x%x!\n", status);
320	} else {
321		/* If we were successfull, register our devsw */
322		dev_t dev;
323
324		dev = makedev(PT_CDEV_MAJOR, 0);
325		cdevsw_add(&dev,&pt_cdevsw, NULL);
326	}
327}
328
329static cam_status
330ptctor(struct cam_periph *periph, void *arg)
331{
332	struct pt_softc *softc;
333	struct ccb_setasync csa;
334	struct ccb_getdev *cgd;
335
336	cgd = (struct ccb_getdev *)arg;
337	if (periph == NULL) {
338		printf("ptregister: periph was NULL!!\n");
339		return(CAM_REQ_CMP_ERR);
340	}
341
342	if (cgd == NULL) {
343		printf("ptregister: no getdev CCB, can't register device\n");
344		return(CAM_REQ_CMP_ERR);
345	}
346
347	softc = (struct pt_softc *)malloc(sizeof(*softc),M_DEVBUF,M_NOWAIT);
348
349	if (softc == NULL) {
350		printf("daregister: Unable to probe new device. "
351		       "Unable to allocate softc\n");
352		return(CAM_REQ_CMP_ERR);
353	}
354
355	bzero(softc, sizeof(*softc));
356	LIST_INIT(&softc->pending_ccbs);
357	softc->state = PT_STATE_NORMAL;
358	bufq_init(&softc->buf_queue);
359
360	periph->softc = softc;
361
362	cam_extend_set(ptperiphs, periph->unit_number, periph);
363
364	/*
365	 * The DA driver supports a blocksize, but
366	 * we don't know the blocksize until we do
367	 * a read capacity.  So, set a flag to
368	 * indicate that the blocksize is
369	 * unavailable right now.  We'll clear the
370	 * flag as soon as we've done a read capacity.
371	 */
372	devstat_add_entry(&softc->device_stats, "pt",
373			  periph->unit_number, 0,
374			  DEVSTAT_NO_BLOCKSIZE,
375			  cgd->pd_type | DEVSTAT_TYPE_IF_SCSI,
376			  DEVSTAT_PRIORITY_OTHER);
377
378	/*
379	 * Add async callbacks for bus reset and
380	 * bus device reset calls.  I don't bother
381	 * checking if this fails as, in most cases,
382	 * the system will function just fine without
383	 * them and the only alternative would be to
384	 * not attach the device on failure.
385	 */
386	xpt_setup_ccb(&csa.ccb_h, periph->path, /*priority*/5);
387	csa.ccb_h.func_code = XPT_SASYNC_CB;
388	csa.event_enable = AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE;
389	csa.callback = ptasync;
390	csa.callback_arg = periph;
391	xpt_action((union ccb *)&csa);
392
393	/* Tell the user we've attached to the device */
394	xpt_announce_periph(periph, NULL);
395
396	return(CAM_REQ_CMP);
397}
398
399static void
400ptoninvalidate(struct cam_periph *periph)
401{
402	int s;
403	struct pt_softc *softc;
404	struct buf *q_bp;
405	struct ccb_setasync csa;
406
407	softc = (struct pt_softc *)periph->softc;
408
409	/*
410	 * De-register any async callbacks.
411	 */
412	xpt_setup_ccb(&csa.ccb_h, periph->path,
413		      /* priority */ 5);
414	csa.ccb_h.func_code = XPT_SASYNC_CB;
415	csa.event_enable = 0;
416	csa.callback = ptasync;
417	csa.callback_arg = periph;
418	xpt_action((union ccb *)&csa);
419
420	softc->flags |= PT_FLAG_DEVICE_INVALID;
421
422	/*
423	 * Although the oninvalidate() routines are always called at
424	 * splsoftcam, we need to be at splbio() here to keep the buffer
425	 * queue from being modified while we traverse it.
426	 */
427	s = splbio();
428
429	/*
430	 * Return all queued I/O with ENXIO.
431	 * XXX Handle any transactions queued to the card
432	 *     with XPT_ABORT_CCB.
433	 */
434	while ((q_bp = bufq_first(&softc->buf_queue)) != NULL){
435		bufq_remove(&softc->buf_queue, q_bp);
436		q_bp->b_resid = q_bp->b_bcount;
437		q_bp->b_error = ENXIO;
438		q_bp->b_flags |= B_ERROR;
439		biodone(q_bp);
440	}
441
442	splx(s);
443
444	xpt_print_path(periph->path);
445	printf("lost device\n");
446}
447
448static void
449ptdtor(struct cam_periph *periph)
450{
451	struct pt_softc *softc;
452
453	softc = (struct pt_softc *)periph->softc;
454
455	devstat_remove_entry(&softc->device_stats);
456
457	cam_extend_release(ptperiphs, periph->unit_number);
458	xpt_print_path(periph->path);
459	printf("removing device entry\n");
460	free(softc, M_DEVBUF);
461}
462
463static void
464ptasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
465{
466	struct cam_periph *periph;
467
468	periph = (struct cam_periph *)callback_arg;
469	switch (code) {
470	case AC_FOUND_DEVICE:
471	{
472		struct ccb_getdev *cgd;
473		cam_status status;
474
475		cgd = (struct ccb_getdev *)arg;
476
477		if (cgd->pd_type != T_PROCESSOR)
478			break;
479
480		/*
481		 * Allocate a peripheral instance for
482		 * this device and start the probe
483		 * process.
484		 */
485		status = cam_periph_alloc(ptctor, ptoninvalidate, ptdtor,
486					  ptstart, "pt", CAM_PERIPH_BIO,
487					  cgd->ccb_h.path, ptasync,
488					  AC_FOUND_DEVICE, cgd);
489
490		if (status != CAM_REQ_CMP
491		 && status != CAM_REQ_INPROG)
492			printf("ptasync: Unable to attach to new device "
493				"due to status 0x%x\n", status);
494		break;
495	}
496	case AC_LOST_DEVICE:
497	{
498		cam_periph_invalidate(periph);
499		break;
500	}
501	case AC_SENT_BDR:
502	case AC_BUS_RESET:
503	{
504		struct pt_softc *softc;
505		struct ccb_hdr *ccbh;
506		int s;
507
508		softc = (struct pt_softc *)periph->softc;
509		s = splsoftcam();
510		/*
511		 * Don't fail on the expected unit attention
512		 * that will occur.
513		 */
514		softc->flags |= PT_FLAG_RETRY_UA;
515		for (ccbh = LIST_FIRST(&softc->pending_ccbs);
516		     ccbh != NULL; ccbh = LIST_NEXT(ccbh, periph_links.le))
517			ccbh->ccb_state |= PT_CCB_RETRY_UA;
518		splx(s);
519		break;
520	}
521	case AC_TRANSFER_NEG:
522	case AC_SCSI_AEN:
523	case AC_UNSOL_RESEL:
524	default:
525		break;
526	}
527}
528
529static void
530ptstart(struct cam_periph *periph, union ccb *start_ccb)
531{
532	struct pt_softc *softc;
533	struct buf *bp;
534	int s;
535
536	softc = (struct pt_softc *)periph->softc;
537
538	/*
539	 * See if there is a buf with work for us to do..
540	 */
541	s = splbio();
542	bp = bufq_first(&softc->buf_queue);
543	if (periph->immediate_priority <= periph->pinfo.priority) {
544		CAM_DEBUG_PRINT(CAM_DEBUG_SUBTRACE,
545				("queuing for immediate ccb\n"));
546		start_ccb->ccb_h.ccb_state = PT_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		int oldspl;
557
558		bufq_remove(&softc->buf_queue, bp);
559
560		devstat_start_transaction(&softc->device_stats);
561
562		scsi_send_receive(&start_ccb->csio,
563				  /*retries*/4,
564				  ptdone,
565				  MSG_SIMPLE_Q_TAG,
566				  bp->b_flags & B_READ,
567				  /*byte2*/0,
568				  bp->b_bcount,
569				  bp->b_data,
570				  /*sense_len*/SSD_FULL_SIZE,
571				  /*timeout*/10000);
572
573		start_ccb->ccb_h.ccb_state = PT_CCB_BUFFER_IO;
574
575		/*
576		 * Block out any asyncronous callbacks
577		 * while we touch the pending ccb list.
578		 */
579		oldspl = splcam();
580		LIST_INSERT_HEAD(&softc->pending_ccbs, &start_ccb->ccb_h,
581				 periph_links.le);
582		splx(oldspl);
583
584		start_ccb->ccb_h.ccb_bp = bp;
585		bp = bufq_first(&softc->buf_queue);
586		splx(s);
587
588		xpt_action(start_ccb);
589
590		if (bp != NULL) {
591			/* Have more work to do, so ensure we stay scheduled */
592			xpt_schedule(periph, /* XXX priority */1);
593		}
594	}
595}
596
597static void
598ptdone(struct cam_periph *periph, union ccb *done_ccb)
599{
600	struct pt_softc *softc;
601	struct ccb_scsiio *csio;
602
603	softc = (struct pt_softc *)periph->softc;
604	csio = &done_ccb->csio;
605	switch (csio->ccb_h.ccb_state) {
606	case PT_CCB_BUFFER_IO:
607	case PT_CCB_BUFFER_IO_UA:
608	{
609		struct buf *bp;
610		int    oldspl;
611
612		bp = (struct buf *)done_ccb->ccb_h.ccb_bp;
613		if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
614			int error;
615			int s;
616			int sf;
617
618			if ((csio->ccb_h.ccb_state & PT_CCB_RETRY_UA) != 0)
619				sf = SF_RETRY_UA;
620			else
621				sf = 0;
622
623			if ((error = pterror(done_ccb, 0, sf)) == ERESTART) {
624				/*
625				 * A retry was scheuled, so
626				 * just return.
627				 */
628				return;
629			}
630			if (error != 0) {
631				struct buf *q_bp;
632
633				s = splbio();
634
635				if (error == ENXIO) {
636					/*
637					 * Catastrophic error.  Mark our device
638					 * as invalid.
639					 */
640					xpt_print_path(periph->path);
641					printf("Invalidating device\n");
642					softc->flags |= PT_FLAG_DEVICE_INVALID;
643				}
644
645				/*
646				 * return all queued I/O with EIO, so that
647				 * the client can retry these I/Os in the
648				 * proper order should it attempt to recover.
649				 */
650				while ((q_bp = bufq_first(&softc->buf_queue))
651					!= NULL) {
652					bufq_remove(&softc->buf_queue, q_bp);
653					q_bp->b_resid = q_bp->b_bcount;
654					q_bp->b_error = EIO;
655					q_bp->b_flags |= B_ERROR;
656					biodone(q_bp);
657				}
658				splx(s);
659				bp->b_error = error;
660				bp->b_resid = bp->b_bcount;
661				bp->b_flags |= B_ERROR;
662			} else {
663				bp->b_resid = csio->resid;
664				bp->b_error = 0;
665				if (bp->b_resid != 0) {
666					/* Short transfer ??? */
667					bp->b_flags |= B_ERROR;
668				}
669			}
670			if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
671				cam_release_devq(done_ccb->ccb_h.path,
672						 /*relsim_flags*/0,
673						 /*reduction*/0,
674						 /*timeout*/0,
675						 /*getcount_only*/0);
676		} else {
677			bp->b_resid = csio->resid;
678			if (bp->b_resid != 0)
679				bp->b_flags |= B_ERROR;
680		}
681
682		/*
683		 * Block out any asyncronous callbacks
684		 * while we touch the pending ccb list.
685		 */
686		oldspl = splcam();
687		LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
688		splx(oldspl);
689
690		devstat_end_transaction(&softc->device_stats,
691					bp->b_bcount - bp->b_resid,
692					done_ccb->csio.tag_action & 0xf,
693					(bp->b_flags & B_READ) ? DEVSTAT_READ
694							       : DEVSTAT_WRITE);
695
696		biodone(bp);
697		break;
698	}
699	case PT_CCB_WAITING:
700		/* Caller will release the CCB */
701		wakeup(&done_ccb->ccb_h.cbfcnp);
702		return;
703	}
704	xpt_release_ccb(done_ccb);
705}
706
707static int
708pterror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
709{
710	struct pt_softc	  *softc;
711	struct cam_periph *periph;
712
713	periph = xpt_path_periph(ccb->ccb_h.path);
714	softc = (struct pt_softc *)periph->softc;
715
716	return(cam_periph_error(ccb, cam_flags, sense_flags,
717				&softc->saved_ccb));
718}
719
720void
721scsi_send_receive(struct ccb_scsiio *csio, u_int32_t retries,
722		  void (*cbfcnp)(struct cam_periph *, union ccb *),
723		  u_int tag_action, int readop, u_int byte2,
724		  u_int32_t xfer_len, u_int8_t *data_ptr, u_int8_t sense_len,
725		  u_int32_t timeout)
726{
727	struct scsi_send_receive *scsi_cmd;
728
729	scsi_cmd = (struct scsi_send_receive *)&csio->cdb_io.cdb_bytes;
730	scsi_cmd->opcode = readop ? RECEIVE : SEND;
731	scsi_cmd->byte2 = byte2;
732	scsi_ulto3b(xfer_len, scsi_cmd->xfer_len);
733	scsi_cmd->control = 0;
734
735	cam_fill_csio(csio,
736		      retries,
737		      cbfcnp,
738		      /*flags*/readop ? CAM_DIR_IN : CAM_DIR_OUT,
739		      tag_action,
740		      data_ptr,
741		      xfer_len,
742		      sense_len,
743		      sizeof(*scsi_cmd),
744		      timeout);
745}
746