scsi_pt.c revision 74840
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 * $FreeBSD: head/sys/cam/scsi/scsi_pt.c 74840 2001-03-27 05:45:52Z ken $ 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/bio.h> 37#include <sys/devicestat.h> 38#include <sys/malloc.h> 39#include <sys/conf.h> 40#include <sys/ptio.h> 41 42#include <cam/cam.h> 43#include <cam/cam_ccb.h> 44#include <cam/cam_extend.h> 45#include <cam/cam_periph.h> 46#include <cam/cam_xpt_periph.h> 47#include <cam/cam_debug.h> 48 49#include <cam/scsi/scsi_all.h> 50#include <cam/scsi/scsi_message.h> 51#include <cam/scsi/scsi_pt.h> 52 53#include "opt_pt.h" 54 55typedef enum { 56 PT_STATE_PROBE, 57 PT_STATE_NORMAL 58} pt_state; 59 60typedef enum { 61 PT_FLAG_NONE = 0x00, 62 PT_FLAG_OPEN = 0x01, 63 PT_FLAG_DEVICE_INVALID = 0x02, 64 PT_FLAG_RETRY_UA = 0x04 65} pt_flags; 66 67typedef enum { 68 PT_CCB_BUFFER_IO = 0x01, 69 PT_CCB_WAITING = 0x02, 70 PT_CCB_RETRY_UA = 0x04, 71 PT_CCB_BUFFER_IO_UA = PT_CCB_BUFFER_IO|PT_CCB_RETRY_UA 72} pt_ccb_state; 73 74/* Offsets into our private area for storing information */ 75#define ccb_state ppriv_field0 76#define ccb_bp ppriv_ptr1 77 78struct pt_softc { 79 struct bio_queue_head bio_queue; 80 struct devstat device_stats; 81 LIST_HEAD(, ccb_hdr) pending_ccbs; 82 pt_state state; 83 pt_flags flags; 84 union ccb saved_ccb; 85 int io_timeout; 86 dev_t dev; 87}; 88 89static d_open_t ptopen; 90static d_close_t ptclose; 91static d_strategy_t ptstrategy; 92static periph_init_t ptinit; 93static void ptasync(void *callback_arg, u_int32_t code, 94 struct cam_path *path, void *arg); 95static periph_ctor_t ptctor; 96static periph_oninv_t ptoninvalidate; 97static periph_dtor_t ptdtor; 98static periph_start_t ptstart; 99static void ptdone(struct cam_periph *periph, 100 union ccb *done_ccb); 101static d_ioctl_t ptioctl; 102static int pterror(union ccb *ccb, u_int32_t cam_flags, 103 u_int32_t sense_flags); 104 105void scsi_send_receive(struct ccb_scsiio *csio, u_int32_t retries, 106 void (*cbfcnp)(struct cam_periph *, union ccb *), 107 u_int tag_action, int readop, u_int byte2, 108 u_int32_t xfer_len, u_int8_t *data_ptr, 109 u_int8_t sense_len, u_int32_t timeout); 110 111static struct periph_driver ptdriver = 112{ 113 ptinit, "pt", 114 TAILQ_HEAD_INITIALIZER(ptdriver.units), /* generation */ 0 115}; 116 117PERIPHDRIVER_DECLARE(pt, ptdriver); 118 119#define PT_CDEV_MAJOR 61 120 121static struct cdevsw pt_cdevsw = { 122 /* open */ ptopen, 123 /* close */ ptclose, 124 /* read */ physread, 125 /* write */ physwrite, 126 /* ioctl */ ptioctl, 127 /* poll */ nopoll, 128 /* mmap */ nommap, 129 /* strategy */ ptstrategy, 130 /* name */ "pt", 131 /* maj */ PT_CDEV_MAJOR, 132 /* dump */ nodump, 133 /* psize */ nopsize, 134 /* flags */ 0, 135}; 136 137static struct extend_array *ptperiphs; 138 139#ifndef SCSI_PT_DEFAULT_TIMEOUT 140#define SCSI_PT_DEFAULT_TIMEOUT 60 141#endif 142 143static int 144ptopen(dev_t dev, int flags, int fmt, struct proc *p) 145{ 146 struct cam_periph *periph; 147 struct pt_softc *softc; 148 int unit; 149 int error; 150 int s; 151 152 unit = minor(dev); 153 periph = cam_extend_get(ptperiphs, unit); 154 if (periph == NULL) 155 return (ENXIO); 156 157 softc = (struct pt_softc *)periph->softc; 158 159 s = splsoftcam(); 160 if (softc->flags & PT_FLAG_DEVICE_INVALID) { 161 splx(s); 162 return(ENXIO); 163 } 164 165 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, 166 ("ptopen: dev=%s (unit %d)\n", devtoname(dev), unit)); 167 168 if ((error = cam_periph_lock(periph, PRIBIO|PCATCH)) != 0) { 169 splx(s); 170 return (error); /* error code from tsleep */ 171 } 172 173 splx(s); 174 175 if ((softc->flags & PT_FLAG_OPEN) == 0) { 176 if (cam_periph_acquire(periph) != CAM_REQ_CMP) 177 error = ENXIO; 178 else 179 softc->flags |= PT_FLAG_OPEN; 180 } else 181 error = EBUSY; 182 183 cam_periph_unlock(periph); 184 return (error); 185} 186 187static int 188ptclose(dev_t dev, int flag, int fmt, struct proc *p) 189{ 190 struct cam_periph *periph; 191 struct pt_softc *softc; 192 int unit; 193 int error; 194 195 unit = minor(dev); 196 periph = cam_extend_get(ptperiphs, unit); 197 if (periph == NULL) 198 return (ENXIO); 199 200 softc = (struct pt_softc *)periph->softc; 201 202 if ((error = cam_periph_lock(periph, PRIBIO)) != 0) 203 return (error); /* error code from tsleep */ 204 205 softc->flags &= ~PT_FLAG_OPEN; 206 cam_periph_unlock(periph); 207 cam_periph_release(periph); 208 return (0); 209} 210 211/* 212 * Actually translate the requested transfer into one the physical driver 213 * can understand. The transfer is described by a buf and will include 214 * only one physical transfer. 215 */ 216static void 217ptstrategy(struct bio *bp) 218{ 219 struct cam_periph *periph; 220 struct pt_softc *softc; 221 u_int unit; 222 int s; 223 224 unit = minor(bp->bio_dev); 225 periph = cam_extend_get(ptperiphs, unit); 226 if (periph == NULL) { 227 bp->bio_error = ENXIO; 228 goto bad; 229 } 230 softc = (struct pt_softc *)periph->softc; 231 232 /* 233 * Mask interrupts so that the pack cannot be invalidated until 234 * after we are in the queue. Otherwise, we might not properly 235 * clean up one of the buffers. 236 */ 237 s = splbio(); 238 239 /* 240 * If the device has been made invalid, error out 241 */ 242 if ((softc->flags & PT_FLAG_DEVICE_INVALID)) { 243 splx(s); 244 bp->bio_error = ENXIO; 245 goto bad; 246 } 247 248 /* 249 * Place it in the queue of disk activities for this disk 250 */ 251 bioq_insert_tail(&softc->bio_queue, bp); 252 253 splx(s); 254 255 /* 256 * Schedule ourselves for performing the work. 257 */ 258 xpt_schedule(periph, /* XXX priority */1); 259 260 return; 261bad: 262 bp->bio_flags |= BIO_ERROR; 263 264 /* 265 * Correctly set the buf to indicate a completed xfer 266 */ 267 bp->bio_resid = bp->bio_bcount; 268 biodone(bp); 269} 270 271static void 272ptinit(void) 273{ 274 cam_status status; 275 struct cam_path *path; 276 277 /* 278 * Create our extend array for storing the devices we attach to. 279 */ 280 ptperiphs = cam_extend_new(); 281 if (ptperiphs == NULL) { 282 printf("pt: Failed to alloc extend array!\n"); 283 return; 284 } 285 286 /* 287 * Install a global async callback. This callback will 288 * receive async callbacks like "new device found". 289 */ 290 status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID, 291 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD); 292 293 if (status == CAM_REQ_CMP) { 294 struct ccb_setasync csa; 295 296 xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5); 297 csa.ccb_h.func_code = XPT_SASYNC_CB; 298 csa.event_enable = AC_FOUND_DEVICE; 299 csa.callback = ptasync; 300 csa.callback_arg = NULL; 301 xpt_action((union ccb *)&csa); 302 status = csa.ccb_h.status; 303 xpt_free_path(path); 304 } 305 306 if (status != CAM_REQ_CMP) { 307 printf("pt: Failed to attach master async callback " 308 "due to status 0x%x!\n", status); 309 } 310} 311 312static cam_status 313ptctor(struct cam_periph *periph, void *arg) 314{ 315 struct pt_softc *softc; 316 struct ccb_setasync csa; 317 struct ccb_getdev *cgd; 318 319 cgd = (struct ccb_getdev *)arg; 320 if (periph == NULL) { 321 printf("ptregister: periph was NULL!!\n"); 322 return(CAM_REQ_CMP_ERR); 323 } 324 325 if (cgd == NULL) { 326 printf("ptregister: no getdev CCB, can't register device\n"); 327 return(CAM_REQ_CMP_ERR); 328 } 329 330 softc = (struct pt_softc *)malloc(sizeof(*softc),M_DEVBUF,M_NOWAIT); 331 332 if (softc == NULL) { 333 printf("daregister: Unable to probe new device. " 334 "Unable to allocate softc\n"); 335 return(CAM_REQ_CMP_ERR); 336 } 337 338 bzero(softc, sizeof(*softc)); 339 LIST_INIT(&softc->pending_ccbs); 340 softc->state = PT_STATE_NORMAL; 341 bioq_init(&softc->bio_queue); 342 343 softc->io_timeout = SCSI_PT_DEFAULT_TIMEOUT * 1000; 344 345 periph->softc = softc; 346 347 cam_extend_set(ptperiphs, periph->unit_number, periph); 348 349 devstat_add_entry(&softc->device_stats, "pt", 350 periph->unit_number, 0, 351 DEVSTAT_NO_BLOCKSIZE, 352 SID_TYPE(&cgd->inq_data) | DEVSTAT_TYPE_IF_SCSI, 353 DEVSTAT_PRIORITY_OTHER); 354 355 softc->dev = make_dev(&pt_cdevsw, periph->unit_number, UID_ROOT, 356 GID_OPERATOR, 0600, "%s%d", periph->periph_name, 357 periph->unit_number); 358 /* 359 * Add async callbacks for bus reset and 360 * bus device reset calls. I don't bother 361 * checking if this fails as, in most cases, 362 * the system will function just fine without 363 * them and the only alternative would be to 364 * not attach the device on failure. 365 */ 366 xpt_setup_ccb(&csa.ccb_h, periph->path, /*priority*/5); 367 csa.ccb_h.func_code = XPT_SASYNC_CB; 368 csa.event_enable = AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE; 369 csa.callback = ptasync; 370 csa.callback_arg = periph; 371 xpt_action((union ccb *)&csa); 372 373 /* Tell the user we've attached to the device */ 374 xpt_announce_periph(periph, NULL); 375 376 return(CAM_REQ_CMP); 377} 378 379static void 380ptoninvalidate(struct cam_periph *periph) 381{ 382 int s; 383 struct pt_softc *softc; 384 struct bio *q_bp; 385 struct ccb_setasync csa; 386 387 softc = (struct pt_softc *)periph->softc; 388 389 /* 390 * De-register any async callbacks. 391 */ 392 xpt_setup_ccb(&csa.ccb_h, periph->path, 393 /* priority */ 5); 394 csa.ccb_h.func_code = XPT_SASYNC_CB; 395 csa.event_enable = 0; 396 csa.callback = ptasync; 397 csa.callback_arg = periph; 398 xpt_action((union ccb *)&csa); 399 400 softc->flags |= PT_FLAG_DEVICE_INVALID; 401 402 /* 403 * Although the oninvalidate() routines are always called at 404 * splsoftcam, we need to be at splbio() here to keep the buffer 405 * queue from being modified while we traverse it. 406 */ 407 s = splbio(); 408 409 /* 410 * Return all queued I/O with ENXIO. 411 * XXX Handle any transactions queued to the card 412 * with XPT_ABORT_CCB. 413 */ 414 while ((q_bp = bioq_first(&softc->bio_queue)) != NULL){ 415 bioq_remove(&softc->bio_queue, q_bp); 416 q_bp->bio_resid = q_bp->bio_bcount; 417 q_bp->bio_error = ENXIO; 418 q_bp->bio_flags |= BIO_ERROR; 419 biodone(q_bp); 420 } 421 422 splx(s); 423 424 xpt_print_path(periph->path); 425 printf("lost device\n"); 426} 427 428static void 429ptdtor(struct cam_periph *periph) 430{ 431 struct pt_softc *softc; 432 433 softc = (struct pt_softc *)periph->softc; 434 435 devstat_remove_entry(&softc->device_stats); 436 437 destroy_dev(softc->dev); 438 439 cam_extend_release(ptperiphs, periph->unit_number); 440 xpt_print_path(periph->path); 441 printf("removing device entry\n"); 442 free(softc, M_DEVBUF); 443} 444 445static void 446ptasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg) 447{ 448 struct cam_periph *periph; 449 450 periph = (struct cam_periph *)callback_arg; 451 switch (code) { 452 case AC_FOUND_DEVICE: 453 { 454 struct ccb_getdev *cgd; 455 cam_status status; 456 457 cgd = (struct ccb_getdev *)arg; 458 459 if (SID_TYPE(&cgd->inq_data) != T_PROCESSOR) 460 break; 461 462 /* 463 * Allocate a peripheral instance for 464 * this device and start the probe 465 * process. 466 */ 467 status = cam_periph_alloc(ptctor, ptoninvalidate, ptdtor, 468 ptstart, "pt", CAM_PERIPH_BIO, 469 cgd->ccb_h.path, ptasync, 470 AC_FOUND_DEVICE, cgd); 471 472 if (status != CAM_REQ_CMP 473 && status != CAM_REQ_INPROG) 474 printf("ptasync: Unable to attach to new device " 475 "due to status 0x%x\n", status); 476 break; 477 } 478 case AC_SENT_BDR: 479 case AC_BUS_RESET: 480 { 481 struct pt_softc *softc; 482 struct ccb_hdr *ccbh; 483 int s; 484 485 softc = (struct pt_softc *)periph->softc; 486 s = splsoftcam(); 487 /* 488 * Don't fail on the expected unit attention 489 * that will occur. 490 */ 491 softc->flags |= PT_FLAG_RETRY_UA; 492 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le) 493 ccbh->ccb_state |= PT_CCB_RETRY_UA; 494 splx(s); 495 /* FALLTHROUGH */ 496 } 497 default: 498 cam_periph_async(periph, code, path, arg); 499 break; 500 } 501} 502 503static void 504ptstart(struct cam_periph *periph, union ccb *start_ccb) 505{ 506 struct pt_softc *softc; 507 struct bio *bp; 508 int s; 509 510 softc = (struct pt_softc *)periph->softc; 511 512 /* 513 * See if there is a buf with work for us to do.. 514 */ 515 s = splbio(); 516 bp = bioq_first(&softc->bio_queue); 517 if (periph->immediate_priority <= periph->pinfo.priority) { 518 CAM_DEBUG_PRINT(CAM_DEBUG_SUBTRACE, 519 ("queuing for immediate ccb\n")); 520 start_ccb->ccb_h.ccb_state = PT_CCB_WAITING; 521 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h, 522 periph_links.sle); 523 periph->immediate_priority = CAM_PRIORITY_NONE; 524 splx(s); 525 wakeup(&periph->ccb_list); 526 } else if (bp == NULL) { 527 splx(s); 528 xpt_release_ccb(start_ccb); 529 } else { 530 int oldspl; 531 532 bioq_remove(&softc->bio_queue, bp); 533 534 devstat_start_transaction(&softc->device_stats); 535 536 scsi_send_receive(&start_ccb->csio, 537 /*retries*/4, 538 ptdone, 539 MSG_SIMPLE_Q_TAG, 540 bp->bio_cmd == BIO_READ, 541 /*byte2*/0, 542 bp->bio_bcount, 543 bp->bio_data, 544 /*sense_len*/SSD_FULL_SIZE, 545 /*timeout*/softc->io_timeout); 546 547 start_ccb->ccb_h.ccb_state = PT_CCB_BUFFER_IO; 548 549 /* 550 * Block out any asyncronous callbacks 551 * while we touch the pending ccb list. 552 */ 553 oldspl = splcam(); 554 LIST_INSERT_HEAD(&softc->pending_ccbs, &start_ccb->ccb_h, 555 periph_links.le); 556 splx(oldspl); 557 558 start_ccb->ccb_h.ccb_bp = bp; 559 bp = bioq_first(&softc->bio_queue); 560 splx(s); 561 562 xpt_action(start_ccb); 563 564 if (bp != NULL) { 565 /* Have more work to do, so ensure we stay scheduled */ 566 xpt_schedule(periph, /* XXX priority */1); 567 } 568 } 569} 570 571static void 572ptdone(struct cam_periph *periph, union ccb *done_ccb) 573{ 574 struct pt_softc *softc; 575 struct ccb_scsiio *csio; 576 577 softc = (struct pt_softc *)periph->softc; 578 csio = &done_ccb->csio; 579 switch (csio->ccb_h.ccb_state) { 580 case PT_CCB_BUFFER_IO: 581 case PT_CCB_BUFFER_IO_UA: 582 { 583 struct bio *bp; 584 int oldspl; 585 586 bp = (struct bio *)done_ccb->ccb_h.ccb_bp; 587 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 588 int error; 589 int s; 590 int sf; 591 592 if ((csio->ccb_h.ccb_state & PT_CCB_RETRY_UA) != 0) 593 sf = SF_RETRY_UA; 594 else 595 sf = 0; 596 597 error = pterror(done_ccb, CAM_RETRY_SELTO, sf); 598 if (error == ERESTART) { 599 /* 600 * A retry was scheuled, so 601 * just return. 602 */ 603 return; 604 } 605 if (error != 0) { 606 struct bio *q_bp; 607 608 s = splbio(); 609 610 if (error == ENXIO) { 611 /* 612 * Catastrophic error. Mark our device 613 * as invalid. 614 */ 615 xpt_print_path(periph->path); 616 printf("Invalidating device\n"); 617 softc->flags |= PT_FLAG_DEVICE_INVALID; 618 } 619 620 /* 621 * return all queued I/O with EIO, so that 622 * the client can retry these I/Os in the 623 * proper order should it attempt to recover. 624 */ 625 while ((q_bp = bioq_first(&softc->bio_queue)) 626 != NULL) { 627 bioq_remove(&softc->bio_queue, q_bp); 628 q_bp->bio_resid = q_bp->bio_bcount; 629 q_bp->bio_error = EIO; 630 q_bp->bio_flags |= BIO_ERROR; 631 biodone(q_bp); 632 } 633 splx(s); 634 bp->bio_error = error; 635 bp->bio_resid = bp->bio_bcount; 636 bp->bio_flags |= BIO_ERROR; 637 } else { 638 bp->bio_resid = csio->resid; 639 bp->bio_error = 0; 640 if (bp->bio_resid != 0) { 641 /* Short transfer ??? */ 642 bp->bio_flags |= BIO_ERROR; 643 } 644 } 645 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) 646 cam_release_devq(done_ccb->ccb_h.path, 647 /*relsim_flags*/0, 648 /*reduction*/0, 649 /*timeout*/0, 650 /*getcount_only*/0); 651 } else { 652 bp->bio_resid = csio->resid; 653 if (bp->bio_resid != 0) 654 bp->bio_flags |= BIO_ERROR; 655 } 656 657 /* 658 * Block out any asyncronous callbacks 659 * while we touch the pending ccb list. 660 */ 661 oldspl = splcam(); 662 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le); 663 splx(oldspl); 664 665 devstat_end_transaction_bio(&softc->device_stats, bp); 666 biodone(bp); 667 break; 668 } 669 case PT_CCB_WAITING: 670 /* Caller will release the CCB */ 671 wakeup(&done_ccb->ccb_h.cbfcnp); 672 return; 673 } 674 xpt_release_ccb(done_ccb); 675} 676 677static int 678pterror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags) 679{ 680 struct pt_softc *softc; 681 struct cam_periph *periph; 682 683 periph = xpt_path_periph(ccb->ccb_h.path); 684 softc = (struct pt_softc *)periph->softc; 685 686 return(cam_periph_error(ccb, cam_flags, sense_flags, 687 &softc->saved_ccb)); 688} 689 690static int 691ptioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) 692{ 693 struct cam_periph *periph; 694 struct pt_softc *softc; 695 int unit; 696 int error; 697 698 unit = minor(dev); 699 periph = cam_extend_get(ptperiphs, unit); 700 701 if (periph == NULL) 702 return(ENXIO); 703 704 softc = (struct pt_softc *)periph->softc; 705 706 if ((error = cam_periph_lock(periph, PRIBIO|PCATCH)) != 0) { 707 return (error); /* error code from tsleep */ 708 } 709 710 switch(cmd) { 711 case PTIOCGETTIMEOUT: 712 if (softc->io_timeout >= 1000) 713 *(int *)addr = softc->io_timeout / 1000; 714 else 715 *(int *)addr = 0; 716 break; 717 case PTIOCSETTIMEOUT: 718 { 719 int s; 720 721 if (*(int *)addr < 1) { 722 error = EINVAL; 723 break; 724 } 725 726 s = splsoftcam(); 727 softc->io_timeout = *(int *)addr * 1000; 728 splx(s); 729 730 break; 731 } 732 default: 733 error = cam_periph_ioctl(periph, cmd, addr, pterror); 734 break; 735 } 736 737 cam_periph_unlock(periph); 738 739 return(error); 740} 741 742void 743scsi_send_receive(struct ccb_scsiio *csio, u_int32_t retries, 744 void (*cbfcnp)(struct cam_periph *, union ccb *), 745 u_int tag_action, int readop, u_int byte2, 746 u_int32_t xfer_len, u_int8_t *data_ptr, u_int8_t sense_len, 747 u_int32_t timeout) 748{ 749 struct scsi_send_receive *scsi_cmd; 750 751 scsi_cmd = (struct scsi_send_receive *)&csio->cdb_io.cdb_bytes; 752 scsi_cmd->opcode = readop ? RECEIVE : SEND; 753 scsi_cmd->byte2 = byte2; 754 scsi_ulto3b(xfer_len, scsi_cmd->xfer_len); 755 scsi_cmd->control = 0; 756 757 cam_fill_csio(csio, 758 retries, 759 cbfcnp, 760 /*flags*/readop ? CAM_DIR_IN : CAM_DIR_OUT, 761 tag_action, 762 data_ptr, 763 xfer_len, 764 sense_len, 765 sizeof(*scsi_cmd), 766 timeout); 767} 768