home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cdrom.zip / DDK / BASE / SRC / DEV / DASD / CDROM / OS2CDROM / cdiorb.c < prev    next >
C/C++ Source or Header  |  1996-06-18  |  78KB  |  2,518 lines

  1. /**************************************************************************
  2.  *
  3.  * SOURCE FILE NAME = CDIORB.C
  4.  *
  5.  * DESCRIPTIVE NAME = IORB managment routines for OS/2 CD-ROM Manager
  6.  *
  7.  * Copyright : COPYRIGHT IBM CORPORATION, 1991, 1992
  8.  *             LICENSED MATERIAL - PROGRAM PROPERTY OF IBM
  9.  *             REFER TO COPYRIGHT INSTRUCTION FORM#G120-2083
  10.  *             RESTRICTED MATERIALS OF IBM
  11.  *             IBM CONFIDENTIAL
  12.  *
  13.  * VERSION = V2.0
  14.  *
  15.  * DATE
  16.  *
  17.  * DESCRIPTION
  18.  *
  19.  * FUNCTIONS   Handles allocation, initialization, and freeing of
  20.  *             I/O request blocks (IORBs) used to communicate with
  21.  *             Adapter Device Drivers (ADDs).
  22.  *
  23.  * ENTRY POINTS:
  24.  *
  25.  * DEPENDENCIES:
  26.  *
  27.  * NOTES
  28.  *
  29.  *
  30.  * STRUCTURES
  31.  *
  32.  * EXTERNAL REFERENCES
  33.  *
  34.  * EXTERNAL FUNCTIONS
  35.  *
  36.  * CHANGE ACTIVITY =
  37.  *  DATE      FLAG        APAR   CHANGE DESCRIPTION
  38.  *  --------  ----------  -----  --------------------------------------
  39.  *  09/08/95  @V135221           Sam Detweiler - CD-ROM changer support
  40.  *  01/06/96  @V147578           Stan Morrow - Teac CD40E sleep mode support
  41.  *
  42.  ****************************************************************************/
  43.  
  44. #include "cdh.h"
  45. #include "cdsony.h"
  46. #include "cdchinon.h"
  47. #include "necdb.h"
  48. #include "tocdb.h"
  49.  
  50.  
  51. /****************************************************************************
  52.  *
  53.  * FUNCTION NAME = AllocIORB
  54.  *
  55.  * DESCRIPTION   = Allocates an IORB.
  56.  *
  57.  *                 USHORT AllocIORB  (NPUNITCB pUnitCB, NPIORB *pIORB)
  58.  *
  59.  * INPUT         = pUnitCB           - UnitCB requesting allocation
  60.  *                 pIORB             - returned pointer to IORB
  61.  *
  62.  * OUTPUT        = USHORT            = 0, IORB allocated
  63.  *                                   ! 0 , IORB not allocated
  64.  *
  65.  * RETURN-NORMAL =
  66.  * RETURN-ERROR  =
  67.  *
  68.  ****************************************************************************/
  69.  
  70. USHORT  AllocIORB(pUnitCB, pIORB)
  71.  
  72. NPUNITCB pUnitCB;
  73. NPIORB   FAR *pIORB;
  74.  
  75. {
  76.    USHORT rc = 0;
  77.  
  78.    PUSHFLAGS;
  79.    DISABLE;                            /* Make sure interrupts are disabled */
  80.  
  81.    /*
  82.    ** Try allocating the dedicated IORB for the requesting unit
  83.    */
  84.    if ( !(pUnitCB->Flags & UCF_IORB_ALLOCATED) )
  85.    {
  86.       pUnitCB->Flags |= UCF_IORB_ALLOCATED;
  87.       *pIORB = pUnitCB->pDedicatedIORB;
  88.    }
  89.    else
  90.    {
  91.      /*
  92.      ** Dedicated IORB already allocated, so get an IORB from the pool.
  93.      */
  94.      if (CB_FreeList != 0)
  95.      {
  96.        *pIORB = (NPIORBH) CB_FreeList;           /* Get IORB from free list */
  97.        CB_FreeList = (NPBYTE) (*pIORB)->pNxtIORB; /* Update free list head  */
  98.      }
  99.      else
  100.        rc = 1;
  101.    }
  102.    /*
  103.    ** Zero fill IORB
  104.    */
  105.    if (rc == 0)
  106.       f_ZeroCB((PBYTE)*pIORB, sizeof(IORB_CDB));
  107.  
  108.    POPFLAGS;
  109.    return(rc);
  110. }
  111.  
  112.  
  113. /****************************************************************************
  114.  *
  115.  * FUNCTION NAME = AllocIORB_Wait
  116.  *
  117.  * DESCRIPTION   = Allocate an IORB, wait until one is available
  118.  *
  119.  *       Allocates an IORB from the Control Block pool and block if one
  120.  *       is not available.
  121.  *
  122.  *       VOID AllocIORB_Wait  (NPUNITCB pUnitCB, NPIORB *pIORB)
  123.  *
  124.  * INPUT         = pUnitCB           - UnitCB requesting allocation
  125.  *                 pIORB             - returned pointer to IORB
  126.  * OUTPUT        =
  127.  *                 VOID
  128.  * RETURN-NORMAL =
  129.  * RETURN-ERROR  =
  130.  *
  131.  ****************************************************************************/
  132.  
  133. VOID  AllocIORB_Wait (pUnitCB, pIORB)
  134.  
  135. NPUNITCB pUnitCB;
  136. NPIORBH  FAR *pIORB;
  137.  
  138. {
  139.    USHORT Allocated = FALSE;
  140.  
  141.    PUSHFLAGS;
  142.    DISABLE;
  143.  
  144.    /*
  145.    ** If init time, then grab the init time iorb
  146.    */
  147.    if (CDFlags & CDF_INIT_TIME)
  148.       *pIORB = (NPIORBH) InitTimeIORB;
  149.  
  150.    /*
  151.    ** Try allocating the dedicated IORB for the requesting unit
  152.    */
  153.    else if ( !(pUnitCB->Flags & UCF_IORB_ALLOCATED) )
  154.    {
  155.       pUnitCB->Flags |= UCF_IORB_ALLOCATED;
  156.       *pIORB = pUnitCB->pDedicatedIORB;
  157.    }
  158.  
  159.    else
  160.    {
  161.       do
  162.       {
  163.          if (CB_FreeList != 0)             /* Allocate from free list       */
  164.          {
  165.             *pIORB = (NPIORBH) CB_FreeList;
  166.             CB_FreeList = (NPBYTE) (*pIORB)->pNxtIORB;       /* Update free */
  167.             Allocated = TRUE;                                /*   list head */
  168.          }
  169.          else                         /* else wait till control block free  */
  170.          {
  171.             PoolSem++;                /* Indicate at least 1 thread blocked */
  172.             _asm { int 3 };
  173.             DevHelp_ProcBlock((ULONG) ppDataSeg, (ULONG)-1, 0);
  174.             DISABLE;
  175.             PoolSem--;                /* Indicate at least 1 thread blocked */
  176.          }
  177.       } while (Allocated == FALSE);
  178.    }
  179.  
  180.    ENABLE;
  181.    /*
  182.    ** Zero fill the IORB
  183.    */
  184.    f_ZeroCB((PBYTE)*pIORB, sizeof(IORB_CDB) );
  185.  
  186.    POPFLAGS;
  187. }
  188.  
  189.  
  190. /****************************************************************************
  191.  *
  192.  * FUNCTION NAME = FreeIORB
  193.  *
  194.  * DESCRIPTION   = Free an IORB.
  195.  *
  196.  *                 VOID FreeIORB  (NPUNITCB pUnitCB, NPIORB pIORB)
  197.  *
  198.  * INPUT         = pUnitCB           - UnitCB requesting deallocation
  199.  *                 pIORB             - IORB to deallocate
  200.  *
  201.  * OUTPUT        = NONE
  202.  *
  203.  * RETURN-NORMAL =
  204.  * RETURN-ERROR  =
  205.  *
  206.  ****************************************************************************/
  207.  
  208. VOID  FreeIORB (pUnitCB, pIORB)
  209.  
  210. NPUNITCB    pUnitCB;
  211. NPIORB_CDB  pIORB;
  212.  
  213. {
  214.    USHORT AwakeCount;
  215.  
  216.    PUSHFLAGS;
  217.    DISABLE;
  218.  
  219.    /*
  220.    ** If the IORB being freed is the unit's dedicated IORB, then simply
  221.    ** clear the UCF_IORB_ALLOCATED flag in the UnitCB, otherwise return
  222.    ** the IORB to the free pool.
  223.    */
  224.    if (pIORB == (NPIORB_CDB) pUnitCB->pDedicatedIORB)
  225.       pUnitCB->Flags &= ~UCF_IORB_ALLOCATED;
  226.    else
  227.    {
  228.       pIORB->apt.iorbh.pNxtIORB = (NPIORBH) CB_FreeList;
  229.       CB_FreeList = (NPBYTE) pIORB;
  230.    }
  231.  
  232.    /*
  233.    ** If anyone waiting on the pool, then wake them up
  234.    */
  235.    if (PoolSem)
  236.    {
  237.       DevHelp_ProcRun((ULONG)ppDataSeg, &AwakeCount);
  238.    }
  239.  
  240.    POPFLAGS;
  241. }
  242.  
  243.  
  244. /****************************************************************************
  245.  *
  246.  * FUNCTION NAME = BuildIORB_DeviceControl
  247.  *
  248.  * DESCRIPTION   = Setup a Device Control IORB
  249.  *
  250.  *       This routine allocates and sets up a Device Control IORB command
  251.  *
  252.  *       BuildIORB_DeviceControl (NPUNITCB pUnitCB, USHORT command_modifier,
  253.  *                                                  NPIORB_CDB FAR *pIORBOut)
  254.  *
  255.  * INPUT         = pUnitCB          - pointer to UnitCB
  256.  *                 command_modifier - IORB command modifier
  257.  *                 pIORBOut         - returned pointer to IORB
  258.  *
  259.  * OUTPUT        = NONE
  260.  *
  261.  * RETURN-NORMAL =
  262.  * RETURN-ERROR  =
  263.  *
  264.  ****************************************************************************/
  265.  
  266. VOID BuildIORB_DeviceControl (pUnitCB, command_modifier, pIORBOut)
  267.  
  268. NPUNITCB   pUnitCB;
  269. USHORT     command_modifier;
  270. NPIORB FAR *pIORBOut;
  271.  
  272. {
  273.     NPIORB pIORB;
  274.  
  275.     AllocIORB_Wait(pUnitCB, (NPIORB FAR *) &pIORB);
  276.  
  277.     pIORB->Length = sizeof(IORB_DEVICE_CONTROL);
  278.     pIORB->UnitHandle = pUnitCB->UnitInfo.UnitHandle;
  279.     pIORB->CommandCode = IOCC_DEVICE_CONTROL;
  280.     pIORB->CommandModifier = command_modifier;
  281.     pIORB->RequestControl = IORB_ASYNC_POST;
  282.     pIORB->NotifyAddress = &NotifyDoneIORB;
  283.  
  284.     *pIORBOut = pIORB;
  285. }
  286.  
  287.  
  288. /****************************************************************************
  289.  *
  290.  * FUNCTION NAME = BuildIORB_Read
  291.  *
  292.  * DESCRIPTION   = Setup IORB for a Read
  293.  *
  294.  *     BuildIORB_Read (NPUNITCB pUnitCB, ULONG LBA, ULONG transfer_length,
  295.  *                       ULONG transfer_addr, NPIORB_CDB FAR *pIORBOut)
  296.  *
  297.  * INPUT         = pUnitCB         - pointer to UnitCB
  298.  *                 LBA             - logical block address
  299.  *                 block_length    - block_length
  300.  *                 transfer_length - count of blocks to transfer
  301.  *                 transfer_addr   - transfer address
  302.  *                 pIORBOut        - returned pointer to IORB
  303.  *
  304.  * OUTPUT        = NONE
  305.  *
  306.  * RETURN-NORMAL =
  307.  * RETURN-ERROR  =
  308.  *
  309.  ****************************************************************************/
  310.  
  311. VOID BuildIORB_Read (pUnitCB, LBA, block_length, transfer_length,
  312.                                                  transfer_addr, pIORBOut)
  313.  
  314. NPUNITCB   pUnitCB;
  315. ULONG      LBA;
  316. USHORT     block_length;
  317. USHORT     transfer_length;
  318. ULONG      transfer_addr;
  319. NPIORB_EXECUTEIO FAR *pIORBOut;
  320.  
  321. {
  322.    NPIORB_EXECUTEIO pIORB;
  323.    NPIORB_DMWORK pDMWork;
  324.  
  325.    AllocIORB_Wait(pUnitCB, (NPIORB FAR *) &pIORB);
  326.  
  327.    pDMWork = (NPIORB_DMWORK) &(pIORB->iorbh.DMWorkSpace);
  328.  
  329.    pIORB->iorbh.Length = sizeof(IORB_EXECUTEIO);
  330.    pIORB->iorbh.UnitHandle = pUnitCB->UnitInfo.UnitHandle;
  331.    pIORB->iorbh.CommandCode = IOCC_EXECUTE_IO;
  332.    pIORB->iorbh.CommandModifier = IOCM_READ;
  333.    pIORB->iorbh.RequestControl = IORB_ASYNC_POST;
  334.    pIORB->iorbh.NotifyAddress = &NotifyDoneIORB;
  335.  
  336.    /*
  337.    ** Setup the scatter/gather list
  338.    */
  339.    pIORB->cSGList = 1;
  340.    pIORB->pSGList = (PVOID) pIORB;
  341.    OFFSETOF(pIORB->pSGList) = (USHORT) ( &(pDMWork->SGList) );
  342.    pIORB->ppSGList =
  343.           (ULONG) (ppDataSeg + (ULONG) ((USHORT) &(pDMWork->SGList)) );
  344.  
  345.    pDMWork->SGList.ppXferBuf = transfer_addr;
  346.    pDMWork->SGList.XferBufLen = transfer_length * block_length;
  347.  
  348.    /*
  349.    ** Set up the rest of the EXECUTE_IO IORB
  350.    */
  351.    pIORB->RBA = LBA;
  352.    pIORB->BlockCount = transfer_length;
  353.    pIORB->BlockSize = block_length;
  354.  
  355.    *pIORBOut = pIORB;
  356. }
  357.  
  358.  
  359. /****************************************************************************
  360.  *
  361.  * FUNCTION NAME = BuildIORB_PassthruCDB
  362.  *
  363.  * DESCRIPTION   = Setup a passthru IORB for a CDB
  364.  *
  365.  *    This routine allocates and sets up a CDB passthru IORB
  366.  *
  367.  *    BuildIORB_PassthruCDB (NPUNITCB pUnitCB, ULONG data_length, ULONG ppData,
  368.  *                                                     NPIORB_CDB FAR *pIORBOut)
  369.  *
  370.  * INPUT         = pUnitCB         - pointer to UnitCB
  371.  *                 data_length     - length of data to transfer
  372.  *                 ppData          - physical address of data buffer
  373.  *                 pIORBOut        - pointer to IORB
  374.  *
  375.  * OUTPUT        = NONE
  376.  *
  377.  * RETURN-NORMAL =
  378.  * RETURN-ERROR  =
  379.  *
  380.  ****************************************************************************/
  381.  
  382. VOID BuildIORB_PassthruCDB (pUnitCB, data_length, ppData, pIORBOut)
  383.  
  384. NPUNITCB        pUnitCB;
  385. ULONG           data_length;
  386. ULONG           ppData;
  387. NPIORB_CDB FAR *pIORBOut;
  388.  
  389. {
  390.    NPIORB_CDB    pIORB;
  391.    NPIORB_DMWORK pDMWork;
  392.  
  393.  
  394.    AllocIORB_Wait(pUnitCB, (NPIORB FAR *) &pIORB);
  395.  
  396.    pDMWork = (NPIORB_DMWORK) &(pIORB->apt.iorbh.DMWorkSpace);
  397.  
  398.    *pIORB = default_iorb_cdb;
  399.  
  400.     pIORB->apt.iorbh.UnitHandle = pUnitCB->UnitInfo.UnitHandle;
  401.     pIORB->apt.iorbh.NotifyAddress = &NotifyDoneIORB;
  402.  
  403.     /*
  404.     ** The pointers to the scat/gather list are always set up even
  405.     ** if no scatter/gather list is needed.  We use the scatter/gather
  406.     ** count field to indicate if the list should be used.  This is
  407.     ** done this way, because some commands require a scat/gat list
  408.     ** in the filter, but not by the CD-ROM Device Manager.
  409.     */
  410.     pIORB->apt.pSGList = (PVOID) pIORB;
  411.     OFFSETOF(pIORB->apt.pSGList) = (USHORT) ( &(pDMWork->SGList) );
  412.     pIORB->apt.ppSGLIST =
  413.           (ULONG) (ppDataSeg + (ULONG) ((USHORT) &(pDMWork->SGList)) );
  414.  
  415.     pDMWork->SGList.ppXferBuf =
  416.                  (ULONG)(ppDataSeg+(ULONG)((USHORT)&(pIORB->CDB_data)));
  417.  
  418.    /*
  419.    ** If data transfer involved, set scatter/gather count to 1
  420.    */
  421.    if (data_length != 0)
  422.    {
  423.       pIORB->apt.cSGList = 1;
  424.       pDMWork->SGList.XferBufLen = data_length;
  425.  
  426.       if (ppData != -1)
  427.          pDMWork->SGList.ppXferBuf = ppData;
  428.    }
  429.  
  430.    /*
  431.    ** Fill in the pointer to the SCSI CDB
  432.    */
  433.    pIORB->apt.pControllerCmd = (PVOID) pIORB;
  434.    OFFSETOF(pIORB->apt.pControllerCmd) = (USHORT) ( &(pIORB->CDB) );
  435.    pIORB->apt.ppSCB =
  436.           (ULONG) (ppDataSeg + (ULONG) ((USHORT) &(pIORB->CDB)) );
  437.  
  438.    /*
  439.    ** Set up the pointers to the status block and sense data block
  440.    */
  441.    (USHORT) pIORB->apt.iorbh.pStatusBlock = (USHORT) ( &(pIORB->status_block) );
  442.    pIORB->apt.iorbh.StatusBlockLen = sizeof(SCSI_STATUS_BLOCK);
  443.  
  444.    pIORB->status_block.ReqSenseLen = sizeof(struct Sense_Data);
  445.    pIORB->status_block.SenseData = (PVOID) pIORB;
  446.    OFFSETOF(pIORB->status_block.SenseData) = (USHORT) (&(pIORB->sense_data));
  447.  
  448.    *pIORBOut = pIORB;
  449. }
  450.  
  451.  
  452. /****************************************************************************
  453.  *
  454.  * FUNCTION NAME = BuildCDB_TestUnitReady
  455.  *
  456.  * DESCRIPTION   = Setup CDB for Test Unit Ready
  457.  *
  458.  *        BuildCDB_TestUnitReady (NPUNITCB pUnitCB, NPIORB_CDB FAR *pIORBOut)
  459.  *
  460.  * INPUT         = pUnitCB         - pointer to UnitCB
  461.  *                 pIORBOut        - returned pointer to IORB
  462.  *
  463.  * OUTPUT        = NONE
  464.  *
  465.  * RETURN-NORMAL =
  466.  * RETURN-ERROR  =
  467.  *
  468.  ****************************************************************************/
  469.  
  470. VOID BuildCDB_TestUnitReady(pUnitCB, pIORBOut)
  471.  
  472. NPUNITCB pUnitCB;
  473. NPIORB_CDB FAR *pIORBOut;
  474.  
  475. {
  476.    NPIORB_CDB pIORB;
  477.  
  478.    struct CDB_TestUnitReady NEAR *pCDB;
  479.  
  480.   /*
  481.   ** Build a CDB passthru IORB
  482.   */
  483.    BuildIORB_PassthruCDB(pUnitCB, 0, 0, (NPIORB_CDB FAR *) &pIORB);
  484.  
  485.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_TestUnitReady);
  486.  
  487.    pCDB = (struct CDB_TestUnitReady NEAR *) &(pIORB->CDB);
  488.    pCDB->OpCode = SCSI_TEST_UNIT_READY;
  489.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  490.    if((pUnitCB->pParentUnitCB!=0) && (pUnitCB->DeviceInfo.product_id_code==TORISAN_C3G))
  491.      {
  492.      *(((NPBYTE)pCDB)+7)=(UCHAR)pUnitCB->pParentUnitCB->DeviceInfo.Slots.Current;
  493.      } /* endif */
  494.  
  495.    *pIORBOut = pIORB;
  496. }
  497.  
  498.  
  499. /****************************************************************************
  500.  *
  501.  * FUNCTION NAME = BuildCDB_RezeroUnit
  502.  *
  503.  * DESCRIPTION   = Setup CDB for Rezero Unit command
  504.  *
  505.  *        BuildCDB_RezeroUnit (NPUNITCB pUnitCB, NPIORB_CDB FAR *pIORBOut)
  506.  *
  507.  * INPUT         = pUnitCB         - pointer to UnitCB
  508.  *                 pIORBOut        - returned pointer to IORB
  509.  *
  510.  * OUTPUT        = NONE
  511.  *
  512.  * RETURN-NORMAL =
  513.  * RETURN-ERROR  =
  514.  *
  515.  ****************************************************************************/
  516.  
  517. VOID BuildCDB_RezeroUnit(pUnitCB, pIORBOut)
  518.  
  519. NPUNITCB pUnitCB;
  520. NPIORB_CDB FAR *pIORBOut;
  521.  
  522. {
  523.    NPIORB_CDB pIORB;
  524.  
  525.    struct CDB_RezeroUnit NEAR *pCDB;
  526.  
  527.   /*
  528.   ** Build a CDB passthru IORB
  529.   */
  530.    BuildIORB_PassthruCDB(pUnitCB, 0, 0, (NPIORB_CDB FAR *) &pIORB);
  531.  
  532.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_RezeroUnit);
  533.  
  534.    pCDB = (struct CDB_RezeroUnit NEAR * ) &(pIORB->CDB);
  535.    pCDB->OpCode = SCSI_REZERO_UNIT;
  536.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  537.  
  538.    *pIORBOut = pIORB;
  539. }
  540.  
  541.  
  542. /****************************************************************************
  543.  *
  544.  * FUNCTION NAME = BuildCDB_RequestSense
  545.  *
  546.  * DESCRIPTION   = Setup CDB for Request Sense Command
  547.  *
  548.  *        BuildCDB_RequestSense (NPUNITCB pUnitCB, NPIORB_CDB FAR *pIORBOut)
  549.  *
  550.  * INPUT         = pUnitCB         - pointer to UnitCB
  551.  *                 pIORBOut        - returned pointer to IORB
  552.  *
  553.  * OUTPUT        =
  554.  *
  555.  * RETURN-NORMAL =
  556.  * RETURN-ERROR  =
  557.  *
  558.  ****************************************************************************/
  559.  
  560. VOID BuildCDB_RequestSense(pUnitCB, pIORBOut)
  561.  
  562. NPUNITCB pUnitCB;
  563. NPIORB_CDB FAR *pIORBOut;
  564.  
  565. {
  566.    NPIORB_CDB    pIORB;
  567.    struct CDB_RequestSense NEAR *pCDB;
  568.  
  569.    /*
  570.    ** Build a CDB passthru IORB
  571.    */
  572.    BuildIORB_PassthruCDB(pUnitCB,
  573.                          sizeof(struct Sense_Data),
  574.                          -1L,
  575.                          (NPIORB_CDB FAR *) &pIORB);
  576.  
  577.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_RezeroUnit);
  578.    pIORB->apt.Flags = PT_DIRECTION_IN;
  579.  
  580.    /*
  581.    ** Setup CDB
  582.    */
  583.    pCDB = (struct CDB_RequestSense NEAR *) &(pIORB->CDB);
  584.    pCDB->OpCode = SCSI_REQUEST_SENSE;
  585.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  586.    pCDB->alloc_length = sizeof(struct Sense_Data);
  587.  
  588.    *pIORBOut = pIORB;
  589. }
  590.  
  591.  
  592. /****************************************************************************
  593.  *
  594.  * FUNCTION NAME = BuildCDB_Read_6
  595.  *
  596.  * DESCRIPTION   = Setup CDB for Read (6) command
  597.  *
  598.  *      BuildCDB_Read_6 (NPUNITCB pUnitCB, ULONG LBA, ULONG transfer_length,
  599.  *                        ULONG transfer_addr, NPIORB_CDB FAR *pIORBOut)
  600.  *
  601.  * INPUT         = pUnitCB         - pointer to UnitCB
  602.  *                 LBA             - logical block address
  603.  *                 block_length    - block_length
  604.  *                 transfer_length - count of blocks to transfer
  605.  *                 transfer_addr   - transfer address
  606.  *                 pIORBOut        - returned pointer to IORB
  607.  *
  608.  * OUTPUT        = NONE
  609.  *
  610.  * RETURN-NORMAL =
  611.  * RETURN-ERROR  =
  612.  *
  613.  ****************************************************************************/
  614.  
  615. VOID BuildCDB_Read_6 (pUnitCB, LBA, block_length, transfer_length,
  616.                                                   transfer_addr, pIORBOut)
  617.  
  618. NPUNITCB   pUnitCB;
  619. ULONG      LBA;
  620. USHORT     block_length;
  621. USHORT     transfer_length;
  622. ULONG      transfer_addr;
  623. NPIORB_CDB FAR *pIORBOut;
  624.  
  625. {
  626.    NPIORB_CDB pIORB;
  627.  
  628.    struct CDB_Read_6   NEAR *pCDB;
  629.  
  630.    union ULONGB  ul_LBA;
  631.    union USHORTB us_transfer_length;
  632.  
  633.    ul_LBA.dword = LBA;
  634.    us_transfer_length.word = transfer_length;
  635.  
  636.    /*
  637.    ** Build a CDB passthru IORB
  638.    */
  639.    BuildIORB_PassthruCDB ( pUnitCB,
  640.                            (ULONG) transfer_length * block_length,
  641.                            transfer_addr,
  642.                            (NPIORB_CDB FAR *) &pIORB );
  643.  
  644.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_Read_6);
  645.    pIORB->apt.Flags = PT_DIRECTION_IN;
  646.  
  647.    /*
  648.    ** Setup the CDB
  649.    */
  650.    pCDB = (struct CDB_Read_6 NEAR *) &(pIORB->CDB);
  651.    pCDB->OpCode = SCSI_READ_6;
  652.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  653.  
  654.    pCDB->LBA_msb            = ul_LBA.ulbytes.byte_2;
  655.    pCDB->LBA.usbytes.byte_0 = ul_LBA.ulbytes.byte_1;
  656.    pCDB->LBA.usbytes.byte_1 = ul_LBA.ulbytes.byte_0;
  657.  
  658.    pCDB->transfer_length = us_transfer_length.usbytes.byte_0;
  659.  
  660.    *pIORBOut = pIORB;
  661. }
  662.  
  663.  
  664. /****************************************************************************
  665.  *
  666.  * FUNCTION NAME = BuildCDB_Read_10
  667.  *
  668.  * DESCRIPTION   = Setup CDB for Read (10) command
  669.  *
  670.  *      BuildCDB_Read_10 (NPUNITCB pUnitCB, ULONG LBA, ULONG transfer_length,
  671.  *                        ULONG transfer_addr, NPIORB_CDB FAR *pIORBOut)
  672.  *
  673.  * INPUT         = pUnitCB         - pointer to UnitCB
  674.  *                 LBA             - logical block address
  675.  *                 block_length    - block_length
  676.  *                 transfer_length - count of blocks to transfer
  677.  *                 transfer_addr   - transfer address
  678.  *                 pIORBOut        - returned pointer to IORB
  679.  *
  680.  * OUTPUT        = NONE
  681.  *
  682.  * RETURN-NORMAL =
  683.  * RETURN-ERROR  =
  684.  *
  685.  ****************************************************************************/
  686.  
  687. VOID BuildCDB_Read_10 (pUnitCB, LBA, block_length, transfer_length,
  688.                                                    transfer_addr, pIORBOut)
  689.  
  690. NPUNITCB   pUnitCB;
  691. ULONG      LBA;
  692. USHORT     block_length;
  693. USHORT     transfer_length;
  694. ULONG      transfer_addr;
  695. NPIORB_CDB FAR *pIORBOut;
  696.  
  697. {
  698.    NPIORB_CDB pIORB;
  699.  
  700.    struct CDB_Read_10  NEAR *pCDB;
  701.  
  702.    union ULONGB  ul_LBA;
  703.    union USHORTB us_transfer_length;
  704.  
  705.    ul_LBA.dword = LBA;
  706.    us_transfer_length.word = transfer_length;
  707.  
  708.    /*
  709.    ** Build a CDB passthru IORB
  710.    */
  711.    BuildIORB_PassthruCDB ( pUnitCB,
  712.                            (ULONG) transfer_length * block_length,
  713.                            transfer_addr,
  714.                            (NPIORB_CDB FAR *) &pIORB );
  715.  
  716.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_Read_10);
  717.    pIORB->apt.Flags = PT_DIRECTION_IN;
  718.  
  719.    /*
  720.    ** Setup the CDB
  721.    */
  722.    pCDB = (struct CDB_Read_10 NEAR *) &(pIORB->CDB);
  723.    pCDB->OpCode = SCSI_READ_10;
  724.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  725.  
  726.    pCDB->LBA.ulbytes.byte_0 = ul_LBA.ulbytes.byte_3;
  727.    pCDB->LBA.ulbytes.byte_1 = ul_LBA.ulbytes.byte_2;
  728.    pCDB->LBA.ulbytes.byte_2 = ul_LBA.ulbytes.byte_1;
  729.    pCDB->LBA.ulbytes.byte_3 = ul_LBA.ulbytes.byte_0;
  730.  
  731.    pCDB->transfer_length.usbytes.byte_0 = us_transfer_length.usbytes.byte_1;
  732.    pCDB->transfer_length.usbytes.byte_1 = us_transfer_length.usbytes.byte_0;
  733.  
  734.    *pIORBOut = pIORB;
  735. }
  736.  
  737.  
  738. /****************************************************************************
  739.  *
  740.  * FUNCTION NAME = BuildCDB_Seek_6
  741.  *
  742.  * DESCRIPTION   = Setup CDB for Seek (6) command
  743.  *
  744.  *      BuildCDB_Seek_6 (NPUNITCB pUnitCB, USHORT address_mode,
  745.  *                                         ULONG LBA, NPIORB_CDB FAR *pIORBOut)
  746.  *
  747.  * INPUT         = pUnitCB         - pointer to UnitCB
  748.  *                 address_mode    - address mode
  749.  *                 LBA             - logical block address
  750.  *                 pIORBOut        - returned pointer to IORB
  751.  *
  752.  * OUTPUT        = NONE
  753.  *
  754.  * RETURN-NORMAL =
  755.  * RETURN-ERROR  =
  756.  *
  757.  ****************************************************************************/
  758.  
  759. VOID BuildCDB_Seek_6 (pUnitCB, LBA, pIORBOut)
  760.  
  761. NPUNITCB   pUnitCB;
  762. ULONG      LBA;
  763. NPIORB_CDB FAR *pIORBOut;
  764.  
  765. {
  766.    NPIORB_CDB pIORB;
  767.    struct CDB_Seek_6   NEAR *pCDB;
  768.  
  769.    union ULONGB ul_LBA;
  770.  
  771.    ul_LBA.dword = LBA;
  772.  
  773.    /*
  774.    ** Build a CDB passthru IORB
  775.    */
  776.    BuildIORB_PassthruCDB(pUnitCB, 0, 0, (NPIORB_CDB FAR *) &pIORB);
  777.  
  778.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_Seek_6);
  779.  
  780.    /*
  781.    ** Setup the CDB
  782.    */
  783.    pCDB = (struct CDB_Seek_6 NEAR *) &(pIORB->CDB);
  784.    pCDB->OpCode = SCSI_SEEK_6;
  785.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  786.  
  787.    pCDB->LBA_msb            = ul_LBA.ulbytes.byte_2;
  788.    pCDB->LBA.usbytes.byte_0 = ul_LBA.ulbytes.byte_1;
  789.    pCDB->LBA.usbytes.byte_1 = ul_LBA.ulbytes.byte_0;
  790.  
  791.    *pIORBOut = pIORB;
  792. }
  793.  
  794.  
  795. /****************************************************************************
  796.  *
  797.  * FUNCTION NAME = BuildCDB_Seek_10
  798.  *
  799.  * DESCRIPTION   = Setup CDB for Seek (10) command
  800.  *
  801.  *     BuildCDB_Seek_10 (NPUNITCB pUnitCB, USHORT address_mode,
  802.  *                                         ULONG LBA, NPIORB_CDB FAR *pIORBOut)
  803.  *
  804.  * INPUT         = pUnitCB         - pointer to UnitCB
  805.  *                 address_mode    - address mode
  806.  *                 LBA             - logical block address
  807.  *                 pIORBOut        - returned pointer to IORB
  808.  *
  809.  * OUTPUT        = NONE
  810.  *
  811.  * RETURN-NORMAL =
  812.  * RETURN-ERROR  =
  813.  *
  814.  ****************************************************************************/
  815.  
  816. VOID BuildCDB_Seek_10(pUnitCB, LBA, pIORBOut)
  817.  
  818. NPUNITCB   pUnitCB;
  819. ULONG      LBA;
  820. NPIORB_CDB FAR *pIORBOut;
  821.  
  822. {
  823.    NPIORB_CDB pIORB;
  824.    struct CDB_Seek_10  NEAR *pCDB;
  825.  
  826.    union ULONGB ul_LBA;
  827.  
  828.    ul_LBA.dword = LBA;
  829.  
  830.    /*
  831.    ** Build a CDB passthru IORB
  832.    */
  833.    BuildIORB_PassthruCDB(pUnitCB, 0, 0, (NPIORB_CDB FAR *) &pIORB);
  834.  
  835.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_Seek_10);
  836.  
  837.    /*
  838.    ** Setup the CDB
  839.    */
  840.    pCDB = (struct CDB_Seek_10 NEAR *) &(pIORB->CDB);
  841.    pCDB->OpCode = SCSI_SEEK_10;
  842.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  843.  
  844.    pCDB->LBA.ulbytes.byte_0 = ul_LBA.ulbytes.byte_3;
  845.    pCDB->LBA.ulbytes.byte_1 = ul_LBA.ulbytes.byte_2;
  846.    pCDB->LBA.ulbytes.byte_2 = ul_LBA.ulbytes.byte_1;
  847.    pCDB->LBA.ulbytes.byte_3 = ul_LBA.ulbytes.byte_0;
  848.  
  849.    *pIORBOut = pIORB;
  850. }
  851.  
  852.  
  853. /****************************************************************************
  854.  *
  855.  * FUNCTION NAME = BuildCDB_Inquiry
  856.  *
  857.  * DESCRIPTION   = Setup SCSI Inquiry Command Descriptor Block
  858.  *
  859.  *         This routine builds a SCSI Inquiry CDB.
  860.  *
  861.  *         BuildCDB_Inquiry (NPUNITCB pUnitCB, NPIORB_CDB FAR *pIORBOut)
  862.  *
  863.  * INPUT         = pUnitCB         - pointer to UnitCB
  864.  *                 pIORBOut        - returned pointer to IORB
  865.  *
  866.  * OUTPUT        = NONE
  867.  *
  868.  * RETURN-NORMAL =
  869.  * RETURN-ERROR  =
  870.  *
  871.  ****************************************************************************/
  872.  
  873. VOID BuildCDB_Inquiry(pUnitCB, pIORBOut)
  874.  
  875. NPUNITCB    pUnitCB;
  876. NPIORB_CDB  FAR *pIORBOut;                     /* ptr to IORB              */
  877. {
  878.   NPIORB_CDB  pIORB;                           /* ptr to IORB              */
  879.  
  880.   struct
  881.   CDB_Inquiry *pCDB;                           /* ptr to CDB               */
  882.  
  883.   /*
  884.   ** Build a CDB passthru IORB
  885.   */
  886.   BuildIORB_PassthruCDB (pUnitCB,
  887.                sizeof(struct Inquiry_Data),
  888.                (ULONG) (ppDataSeg+(ULONG)((USHORT)&(pUnitCB->InquiryData))),
  889.                (NPIORB_CDB FAR *) &pIORB );
  890.  
  891.   pIORB->apt.ControllerCmdLen = sizeof(struct CDB_Inquiry);
  892.   pIORB->apt.Flags |= PT_DIRECTION_IN;
  893.  
  894.   /*
  895.   ** Setup the CDB
  896.   */
  897.   pCDB = (struct CDB_Inquiry NEAR *) &pIORB->CDB;
  898.   pCDB->OpCode = SCSI_INQUIRY;
  899.   pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  900.   pCDB->alloc_length = sizeof(struct Inquiry_Data);
  901.  
  902.   *pIORBOut = pIORB;
  903. }
  904.  
  905.  
  906. /****************************************************************************
  907.  *
  908.  * FUNCTION NAME = BuildCDB_ModeSelect
  909.  *
  910.  * DESCRIPTION   = Setup CDB for Mode Select command
  911.  *
  912.  *                 Note: This routine should not be called by an ATAPI
  913.  *                       device since the 6 byte command is not supported.
  914.  *
  915.  *      BuildCDB_ModeSelect (NPUNITCB pUnitCB, USHORT density_code,
  916.  *                           USHORT block_length, NPIORB_CDB FAR *pIORBOut)
  917.  *
  918.  * INPUT         = pUnitCB         - pointer to UnitCB
  919.  *                 density_code    - density code
  920.  *                 block_length    - block_length
  921.  *                 pIORBOut        - returned pointer to IORB
  922.  *
  923.  * OUTPUT        = NONE
  924.  *
  925.  * RETURN-NORMAL =
  926.  * RETURN-ERROR  =
  927.  *
  928.  ****************************************************************************/
  929.  
  930. VOID BuildCDB_ModeSelect(pUnitCB, density_code, block_length, pIORBOut)
  931.  
  932. NPUNITCB   pUnitCB;
  933. USHORT     density_code;
  934. USHORT     block_length;
  935. NPIORB_CDB FAR *pIORBOut;
  936.  
  937. {
  938.    NPIORB_CDB pIORB;
  939.    USHORT parm_length;
  940.  
  941.    struct CDB_ModeSelect  NEAR *pCDB;
  942.    struct ModeSelectBlockError NEAR *pDescriptor;
  943.  
  944.    if (pUnitCB->DeviceInfo.Audio.capabilities & DCAPS_MODE_WITH_ERR_RECOV)
  945.       parm_length = sizeof(struct ModeSelectBlockError);
  946.    else
  947.       parm_length = sizeof(struct ModeSelectHdr) +
  948.                     sizeof(struct BlockDescriptor);
  949.  
  950.   /*
  951.   ** Build a CDB passthru IORB
  952.   */
  953.    BuildIORB_PassthruCDB (pUnitCB,
  954.                           parm_length,
  955.                           -1L,
  956.                          (NPIORB_CDB FAR *) &pIORB );
  957.  
  958.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_ModeSelect);
  959.  
  960.    /*
  961.    ** Setup the CDB
  962.    */
  963.    pCDB = (struct CDB_ModeSelect NEAR *) &(pIORB->CDB);
  964.    pCDB->OpCode = SCSI_MODE_SELECT;
  965.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  966.    pCDB->PF = 1;
  967.    pCDB->parm_length = parm_length;
  968.  
  969.    /*
  970.    ** Set up the Mode Parameter Header
  971.    */
  972.    pDescriptor = (struct ModeSelectBlockError NEAR *) &(pIORB->CDB_data);
  973.    pDescriptor->ModeSelectHdr.mode_data_length = 0;
  974.    pDescriptor->ModeSelectHdr.medium_type = CD_MEDIUM_DEFAULT;
  975.    pDescriptor->ModeSelectHdr.device_specific_parm = 0;
  976.    pDescriptor->ModeSelectHdr.block_descriptor_len =
  977.                                             sizeof(struct BlockDescriptor);
  978.  
  979.    /*
  980.    ** Setup the Mode Parameter Block Descriptor
  981.    */
  982.    pDescriptor->BlockDescriptor.density_code = (UCHAR) density_code;
  983.  
  984.    pDescriptor->BlockDescriptor.block_count_0  = 0;
  985.    pDescriptor->BlockDescriptor.block_count_1  = 0;
  986.    pDescriptor->BlockDescriptor.block_count_2  = 0;
  987.  
  988.    pDescriptor->BlockDescriptor.block_length_2 =
  989.                                               (UCHAR) (block_length);
  990.    pDescriptor->BlockDescriptor.block_length_1 =
  991.                                               (UCHAR) (block_length >> 8);
  992.    pDescriptor->BlockDescriptor.block_length_0 = 0;
  993.  
  994.    /*
  995.    ** Append Read Error Recovery Page if required
  996.    */
  997.    if (pUnitCB->DeviceInfo.Audio.capabilities & DCAPS_MODE_WITH_ERR_RECOV)
  998.    {
  999.       if (block_length == 2048)
  1000.       {
  1001.          pDescriptor->ReadError.error_parm = 0;      /* Default Error Recov */
  1002.          pDescriptor->ReadError.retry_count = 0x08;
  1003.       }
  1004.       else
  1005.       {
  1006.          pDescriptor->ReadError.error_parm = 0x01;   /* Disable L-EC        */
  1007.          pDescriptor->ReadError.retry_count = 0x00;
  1008.       }
  1009.  
  1010.       pDescriptor->ReadError.page_code = PAGE_READ_ERROR;
  1011.       pDescriptor->ReadError.reserved_1 = 0;
  1012.       pDescriptor->ReadError.PS = 0;
  1013.       pDescriptor->ReadError.page_length = 0x06;
  1014.       pDescriptor->ReadError.reserved_2 = 0;
  1015.       pDescriptor->ReadError.reserved_3 = 0;
  1016.       pDescriptor->ReadError.reserved_4 = 0;
  1017.       pDescriptor->ReadError.reserved_5 = 0;
  1018.    }
  1019.  
  1020.    *pIORBOut = pIORB;
  1021. }
  1022.  
  1023. /****************************************************************************
  1024.  *
  1025.  * FUNCTION NAME = BuildCDB_ModeSelect_6
  1026.  *
  1027.  * DESCRIPTION   = Build CDB for 6 byte Mode Select Command
  1028.  *
  1029.  *        BuildCDB_ModeSelect_6 (NPUNITCB pUnitCB, NPIORB_CDB FAR *pIORBOut)
  1030.  *
  1031.  * INPUT         = pUnitCB         - pointer to UnitCB
  1032.  *                 pIORBOut        - returned pointer to IORB
  1033.  *
  1034.  * OUTPUT        = NONE
  1035.  *
  1036.  * RETURN-NORMAL =
  1037.  * RETURN-ERROR  =
  1038.  *
  1039.  ****************************************************************************/
  1040.  
  1041. VOID BuildCDB_ModeSelect_6 (pUnitCB, pIORBOut)
  1042.  
  1043. NPUNITCB   pUnitCB;
  1044. NPIORB_CDB FAR *pIORBOut;
  1045.  
  1046. {
  1047.    NPIORB_CDB pIORB;
  1048.  
  1049.    struct CDB_ModeSelect  NEAR *pCDB;
  1050.    struct ModeSelectHdr NEAR *pModeSelectHdr;
  1051.  
  1052.   /*
  1053.   ** Build a CDB passthru IORB
  1054.   */
  1055.    BuildIORB_PassthruCDB (pUnitCB,
  1056.                 sizeof(struct ModeSelectParmList),
  1057.                 -1L,
  1058.                 (NPIORB_CDB FAR *) &pIORB );
  1059.  
  1060.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_ModeSelect);
  1061.  
  1062.    /*
  1063.    ** Setup the CDB
  1064.    */
  1065.    pCDB = (struct CDB_ModeSelect NEAR *) &(pIORB->CDB);
  1066.    pCDB->OpCode = SCSI_MODE_SELECT;
  1067.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  1068.    pCDB->PF = 1;
  1069.    pCDB->parm_length = sizeof(struct ModeSelectParmList);
  1070.  
  1071.    /*
  1072.    ** Set up the Mode Parameter Header
  1073.    */
  1074.    pModeSelectHdr = (struct ModeSelectHdr NEAR *) &(pIORB->CDB_data);
  1075.    pModeSelectHdr->mode_data_length = 0;
  1076.    pModeSelectHdr->medium_type = CD_MEDIUM_DEFAULT;
  1077.    pModeSelectHdr->device_specific_parm = 0;
  1078.    pModeSelectHdr->block_descriptor_len = 0;
  1079.  
  1080.  
  1081.    *pIORBOut = pIORB;
  1082. }
  1083.  
  1084.  
  1085. /****************************************************************************
  1086.  *
  1087.  * FUNCTION NAME = BuildCDB_ModeSelect_10
  1088.  *
  1089.  * DESCRIPTION   = Build CDB for 10 byte Mode Select Command
  1090.  *
  1091.  *        BuildCDB_ModeSelect_10 (NPUNITCB pUnitCB, NPIORB_CDB FAR *pIORBOut)
  1092.  *
  1093.  * INPUT         = pUnitCB         - pointer to UnitCB
  1094.  *                 pIORBOut        - returned pointer to IORB
  1095.  *
  1096.  * OUTPUT        = NONE
  1097.  *
  1098.  * RETURN-NORMAL =
  1099.  * RETURN-ERROR  =
  1100.  *
  1101.  ****************************************************************************/
  1102.  
  1103. VOID BuildCDB_ModeSelect_10 (pUnitCB, pIORBOut)
  1104.  
  1105. NPUNITCB   pUnitCB;
  1106. NPIORB_CDB FAR *pIORBOut;
  1107.  
  1108. {
  1109.    NPIORB_CDB pIORB;
  1110.  
  1111.    struct CDB_ModeSelect_10  NEAR *pCDB;
  1112.    struct ModeSelectHdr_10 NEAR *pModeSelectHdr;
  1113.  
  1114.   /*
  1115.   ** Build a CDB passthru IORB
  1116.   */
  1117.    BuildIORB_PassthruCDB (pUnitCB,
  1118.                 sizeof(struct ModeSelectParmList_10),
  1119.                 -1L,
  1120.                 (NPIORB_CDB FAR *) &pIORB );
  1121.  
  1122.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_ModeSelect_10);
  1123.  
  1124.    /*
  1125.    ** Setup the CDB
  1126.    */
  1127.    pCDB = (struct CDB_ModeSelect_10 NEAR *) &(pIORB->CDB);
  1128.    pCDB->OpCode = SCSI_MODE_SELECT_10;
  1129.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  1130.    pCDB->PF = 1;
  1131.    pCDB->parm_length.usbytes.byte_0 = 0;
  1132.    pCDB->parm_length.usbytes.byte_1 = sizeof(struct ModeSelectParmList_10);
  1133.  
  1134.    /*
  1135.    ** Set up the Mode Parameter Header
  1136.    */
  1137.    pModeSelectHdr = (struct ModeSelectHdr_10 NEAR *) &(pIORB->CDB_data);
  1138.    pModeSelectHdr->mode_data_length.word = 0;
  1139.    pModeSelectHdr->medium_type = CD_MEDIUM_DEFAULT;
  1140.    pModeSelectHdr->device_specific_parm = 0;
  1141.    pModeSelectHdr->block_descriptor_len.word = 0;
  1142.  
  1143.  
  1144.    *pIORBOut = pIORB;
  1145. }
  1146. /****************************************************************************
  1147.  *
  1148.  * FUNCTION NAME = BuildCDB_AudioControl
  1149.  *
  1150.  * DESCRIPTION   = Build CDB for audio control
  1151.  *
  1152.  *        Build a Mode Select command for the CD-ROM Audio Control page.
  1153.  *
  1154.  *        BuildCDB_AudioControl (NPUNITCB pUnitCB, NPIORB_CDB FAR *pIORBOut)
  1155.  *
  1156.  * INPUT         = pUnitCB         - pointer to UnitCB
  1157.  *                 pIORBOut        - returned pointer to IORB
  1158.  *
  1159.  * OUTPUT        = NONE
  1160.  *
  1161.  * RETURN-NORMAL =
  1162.  * RETURN-ERROR  =
  1163.  *
  1164.  ****************************************************************************/
  1165.  
  1166. VOID BuildCDB_AudioControl(pUnitCB, pIORBOut)
  1167.  
  1168. NPUNITCB   pUnitCB;
  1169. NPIORB_CDB FAR *pIORBOut;
  1170.  
  1171. {
  1172.    NPIORB_CDB pIORB;
  1173.    struct CDB_ModeSelect_10  NEAR *pCDB;
  1174.  
  1175.    struct Page_AudioCtrl NEAR *pDescriptor;
  1176.    struct Channel *channel;
  1177.    struct Audio   *audio;
  1178.  
  1179.    audio = &pUnitCB->DeviceInfo.Audio;
  1180.    channel = &audio->channel;
  1181.  
  1182.  
  1183.    /*
  1184.    ** Setup up the Mode Select CDB and Mode Parameter Header for either
  1185.    ** the 6 byte Mode Select or 10 byte Mode Select.  ATAPI devices
  1186.    ** only support the 10 byte Mode Select.
  1187.    */
  1188.  
  1189.    if (pUnitCB->DeviceInfo.interface_type == INTERFACE_ATAPI)
  1190.    {
  1191.       BuildCDB_ModeSelect_10 (pUnitCB, (NPIORB_CDB FAR *) &pIORB);
  1192.       (NPBYTE) pDescriptor = (NPBYTE) &(pIORB->CDB_data)
  1193.                                       + sizeof(struct ModeSelectHdr_10);
  1194.       pCDB = (struct CDB_ModeSelect_10 NEAR *) &(pIORB->CDB);
  1195.       pCDB->reserved_2 = PAGE_AUDIO_CONTROL;
  1196.    }
  1197.    else
  1198.    {
  1199.       BuildCDB_ModeSelect_6 (pUnitCB, (NPIORB_CDB FAR *) &pIORB);
  1200.       (NPBYTE) pDescriptor = (NPBYTE) &(pIORB->CDB_data)
  1201.                                       + sizeof(struct ModeSelectHdr);
  1202.    }
  1203.  
  1204.    /*
  1205.    ** Setup the Audio Control page parameters
  1206.    */
  1207.    pDescriptor->page_code = PAGE_AUDIO_CONTROL;
  1208.    pDescriptor->page_length = sizeof(struct Page_AudioCtrl) - 2;
  1209.    pDescriptor->Immed = 1;
  1210.  
  1211.    pDescriptor->output0_select = channel->input_0+1;
  1212.    pDescriptor->output0_volume = channel->volume_0;
  1213.    pDescriptor->output1_select = channel->input_1+1;
  1214.    pDescriptor->output1_volume = channel->volume_1;
  1215.  
  1216.    pDescriptor->output2_select = 0;
  1217.    pDescriptor->output2_volume = 0;
  1218.    pDescriptor->output3_select = 0;
  1219.    pDescriptor->output3_volume = 0;
  1220.  
  1221.    /*
  1222.    ** Adjust the audio control parms based on the audio support features
  1223.    ** of the drive.
  1224.    */
  1225.    /*
  1226.    ** If the volume is set to zero and the drive supports muting, then
  1227.    ** set the channel select to mute.
  1228.    */
  1229.    if (channel->input_0 > 1 || channel->volume_0 == 0)
  1230.    {
  1231.       if (audio->capabilities & DCAPS_MUTE)
  1232.       {
  1233.          pDescriptor->output0_select = CDROM_MUTE;
  1234.       }
  1235.       else
  1236.       {
  1237.          pDescriptor->output0_volume = 0;
  1238.       }
  1239.    }
  1240.  
  1241.    if (channel->input_1 > 1 || channel->volume_1 == 0)
  1242.    {
  1243.       if (audio->capabilities & DCAPS_MUTE)
  1244.       {
  1245.          pDescriptor->output1_select = CDROM_MUTE;
  1246.       }
  1247.       else
  1248.       {
  1249.          pDescriptor->output1_volume = 0;
  1250.       }
  1251.    }
  1252.  
  1253.    /*
  1254.    ** If the drive doesnt support independent volume levels, make sure
  1255.    ** the volume levels for each channel are the same.
  1256.    */
  1257.    if ( ! (audio->capabilities & DCAPS_INDEPENDENT_VOLUME_LEVELS) )
  1258.    {
  1259.       if ( channel->volume_0 > channel->volume_1 )
  1260.       {
  1261.          pDescriptor->output0_volume = channel->volume_0;
  1262.          pDescriptor->output1_volume = channel->volume_0;
  1263.       }
  1264.       else
  1265.       {
  1266.          pDescriptor->output0_volume = channel->volume_1;
  1267.          pDescriptor->output1_volume = channel->volume_1;
  1268.       }
  1269.    }
  1270.    /*
  1271.    ** If the drive doesnt support variable volume settings, then make sure
  1272.    ** the volume is set to the max setting of 0xFF.
  1273.    */
  1274.    if ( !(audio->capabilities & DCAPS_VARIABLE_VOLUME) )
  1275.    {
  1276.       if (pDescriptor->output0_volume > 0)
  1277.           pDescriptor->output0_volume  = 0xFF;
  1278.  
  1279.       if (pDescriptor->output1_volume > 0)
  1280.           pDescriptor->output1_volume  = 0xFF;
  1281.    }
  1282.  
  1283.    /*
  1284.    ** If the request has channels 1 and 2 swapped, and the drive doesnt
  1285.    ** support channel swapping, then unswap the channels so the request
  1286.    ** completes without error.
  1287.    */
  1288.    if (audio->capabilities & DCAPS_NO_CHANNEL_SWAP)
  1289.    {
  1290.       if ( (pDescriptor->output0_select == 2) &&
  1291.            (pDescriptor->output1_select == 1) )
  1292.       {
  1293.          pDescriptor->output0_select = 1;
  1294.          pDescriptor->output1_select = 2;
  1295.       }
  1296.    }
  1297.  
  1298.    /*
  1299.    ** Save the actual volume settings in the UnitCB
  1300.    */
  1301.    pUnitCB->DeviceInfo.Audio.channel.volume_0 =
  1302.          pDescriptor->output0_volume;
  1303.  
  1304.    pUnitCB->DeviceInfo.Audio.channel.volume_1 =
  1305.          pDescriptor->output1_volume;
  1306.  
  1307.    if (pDescriptor->output0_select == 0)
  1308.       pUnitCB->DeviceInfo.Audio.channel.volume_0 = 0;
  1309.  
  1310.    if (pDescriptor->output1_select == 0)
  1311.       pUnitCB->DeviceInfo.Audio.channel.volume_1 = 0;
  1312.  
  1313.    /*
  1314.    ** Make audio page changes for Panasonic 501 drive.
  1315.    ** Left and right channels are reversed on this drive.
  1316.    */
  1317.    if (pUnitCB->DeviceInfo.product_id_code == PANASONIC_501)
  1318.    {
  1319.       pDescriptor->page_code = 0x2E;
  1320.       pDescriptor->output1_volume  = 0x00;
  1321.  
  1322.       if ( (pDescriptor->output0_select == 0) &&
  1323.            (pDescriptor->output1_select == 2) )
  1324.       {
  1325.          pDescriptor->output0_select = 1;
  1326.          pDescriptor->output1_select = 0;;
  1327.       }
  1328.       else
  1329.       {
  1330.          if ( (pDescriptor->output0_select == 1) &&
  1331.               (pDescriptor->output1_select == 0) )
  1332.          {
  1333.             pDescriptor->output0_select = 0;
  1334.             pDescriptor->output1_select = 2;;
  1335.          }
  1336.       }
  1337.    }
  1338.  
  1339.    *pIORBOut = pIORB;
  1340. }
  1341.  
  1342. /****************************************************************************
  1343.  *
  1344.  * FUNCTION NAME = BuildCDB_SenseCapabilities
  1345.  *
  1346.  * DESCRIPTION   = Build CDB for Mode Sense of Capabilities Page
  1347.  *
  1348.  *        Build a Mode Sense command for the CD-ROM Capabilities page.
  1349.  *
  1350.  *        BuildCDB_SenseCapabilities (NPUNITCB pUnitCB, NPIORB_CDB FAR *pIORBOut)
  1351.  *
  1352.  * INPUT         = pUnitCB         - pointer to UnitCB
  1353.  *                 pIORBOut        - returned pointer to IORB
  1354.  *
  1355.  * OUTPUT        = NONE
  1356.  *
  1357.  * RETURN-NORMAL =
  1358.  * RETURN-ERROR  =
  1359.  *
  1360.  ****************************************************************************/
  1361.  
  1362. VOID BuildCDB_SenseCapabilities (pUnitCB, pIORBOut)
  1363.  
  1364. NPUNITCB   pUnitCB;
  1365. NPIORB_CDB FAR *pIORBOut;
  1366.  
  1367. {
  1368.    NPIORB_CDB pIORB;
  1369.    struct CDB_ModeSense_10  NEAR *pCDB;
  1370.  
  1371.   /*
  1372.   ** Build a CDB passthru IORB
  1373.   */
  1374.  
  1375.    BuildIORB_PassthruCDB(pUnitCB,
  1376.                         sizeof(struct CapabilitiesParmList_10),
  1377.                         -1L,
  1378.                         (NPIORB_CDB FAR *) &pIORB );
  1379.  
  1380.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_ModeSense_10);
  1381.    pIORB->apt.Flags |= PT_DIRECTION_IN;
  1382.  
  1383.    /*
  1384.    ** Setup the CDB
  1385.    */
  1386.    pCDB = (struct CDB_ModeSense_10 NEAR *) &(pIORB->CDB);
  1387.    pCDB->OpCode = SCSI_MODE_SENSE_10;
  1388.    pCDB->DBD = 0;
  1389.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  1390.    pCDB->page_code = PAGE_CAPABILITIES;
  1391.    pCDB->PC = PC_DEFAULT;
  1392.    pCDB->alloc_length.usbytes.byte_0 = 0;
  1393.    pCDB->alloc_length.usbytes.byte_1 = sizeof(struct CapabilitiesParmList_10);
  1394.    pCDB->control = 0;
  1395.  
  1396.    *pIORBOut = pIORB;
  1397.  
  1398. }
  1399.  
  1400.  
  1401. /****************************************************************************
  1402.  *
  1403.  * FUNCTION NAME = BuildCDB_PreventAllowRemoval
  1404.  *
  1405.  * DESCRIPTION   = Setup CDB for Prevent Allow Media Removal
  1406.  *
  1407.  *                 BuildCDB_PreventAllowRemoval (NPUNITCB pUnitCB,  flag,
  1408.  *                                               NPIORB_CDB FAR *pIORBOut)
  1409.  *
  1410.  * INPUT         = pUnitCB         - pointer to UnitCB
  1411.  *                 flag            - prevent-allow flag
  1412.  *                                   0 = allow medium removal
  1413.  *                                   1 = prevent medium removal
  1414.  *                 pIORBOut        - returned pointer to IORB
  1415.  *
  1416.  * OUTPUT        = NONE
  1417.  *
  1418.  * RETURN-NORMAL =
  1419.  * RETURN-ERROR  =
  1420.  *
  1421.  ****************************************************************************/
  1422.  
  1423. VOID BuildCDB_PreventAllowRemoval (pUnitCB, flag, pIORBOut)
  1424.  
  1425. NPUNITCB pUnitCB;
  1426. USHORT   flag;
  1427. NPIORB_CDB FAR *pIORBOut;
  1428.  
  1429. {
  1430.    NPIORB_CDB pIORB;
  1431.  
  1432.    struct CDB_PreventAllowRemoval NEAR *pCDB;
  1433.  
  1434.    /*
  1435.    ** Build a CDB passthru IORB
  1436.    */
  1437.    BuildIORB_PassthruCDB(pUnitCB, 0, 0, (NPIORB_CDB FAR *) &pIORB);
  1438.  
  1439.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_PreventAllowRemoval);
  1440.  
  1441.    /*
  1442.    ** Setup the CDB
  1443.    */
  1444.    pCDB = (struct CDB_PreventAllowRemoval NEAR *) &(pIORB->CDB);
  1445.    pCDB->OpCode = SCSI_LOCK_UNLOCK;
  1446.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  1447.  
  1448.    pCDB->prevent = flag;
  1449.  
  1450.    *pIORBOut = pIORB;
  1451. }
  1452.  
  1453.  
  1454. /****************************************************************************
  1455.  *
  1456.  * FUNCTION NAME = BuildCDB_ReadCapacity
  1457.  *
  1458.  * DESCRIPTION   = Setup CDB for Read Capacity Command
  1459.  *
  1460.  *      BuildCDB_ReadCapacity (NPUNITCB pUnitCB, NPIORB_CDB FAR *pIORBOut)
  1461.  *
  1462.  * INPUT         = pUnitCB         - pointer to UnitCB
  1463.  *                 pIORBOut        - returned pointer to IORB
  1464.  *
  1465.  * OUTPUT        =
  1466.  *
  1467.  * RETURN-NORMAL = NONE
  1468.  * RETURN-ERROR  =
  1469.  *
  1470.  ****************************************************************************/
  1471.  
  1472. VOID BuildCDB_ReadCapacity(pUnitCB, pIORBOut)
  1473.  
  1474. NPUNITCB        pUnitCB;
  1475. NPIORB_CDB FAR *pIORBOut;
  1476.  
  1477. {
  1478.   NPIORB_CDB pIORB;
  1479.  
  1480.   struct CDB_ReadCapacity *pCDB;               /* ptr to CDB               */
  1481.  
  1482.   /*
  1483.   ** Build a CDB passthru IORB
  1484.   */
  1485.   BuildIORB_PassthruCDB(pUnitCB,
  1486.                         sizeof(struct ReadCapacity_Data),
  1487.                         -1L,
  1488.                         (NPIORB_CDB FAR *) &pIORB );
  1489.  
  1490.   pIORB->apt.ControllerCmdLen = sizeof(struct CDB_ReadCapacity);
  1491.   pIORB->apt.Flags |= PT_DIRECTION_IN;
  1492.  
  1493.   /*
  1494.   ** Setup the CDB
  1495.   */
  1496.   pCDB = (struct CDB_ReadCapacity NEAR *) &pIORB->CDB;
  1497.   pCDB->OpCode = SCSI_READ_CAPACITY;
  1498.   pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  1499.   pCDB->RelAdr = 0;
  1500.   pCDB->LBA.dword = 0;
  1501.   pCDB->PMI = 0;
  1502.   pCDB->control = 0;
  1503.  
  1504.   *pIORBOut = pIORB;
  1505.  
  1506. }
  1507.  
  1508.  
  1509. /****************************************************************************
  1510.  *
  1511.  * FUNCTION NAME = BuildCDB_ReadSubChannel
  1512.  *
  1513.  * DESCRIPTION   = Setup CDB for Read Sub-Channel command
  1514.  *
  1515.  *        BuildCDB_ReadSubChannel (NPUNITCB pUnitCB, USHORT data_format,
  1516.  *                                                 NPIORB_CDB FAR *pIORBOut)
  1517.  *
  1518.  * INPUT         = pUnitCB         - pointer to UnitCB
  1519.  *                 data_format     - Sub-channel data format to return
  1520.  *                 pIORBOut        - returned pointer to IORB
  1521.  *
  1522.  * OUTPUT        = NONE
  1523.  *
  1524.  * RETURN-NORMAL =
  1525.  * RETURN-ERROR  =
  1526.  *
  1527.  ****************************************************************************/
  1528.  
  1529. VOID BuildCDB_ReadSubChannel(pUnitCB, data_format, pIORBOut)
  1530.  
  1531. NPUNITCB        pUnitCB;
  1532. USHORT          data_format;
  1533. NPIORB_CDB FAR *pIORBOut;
  1534.  
  1535. {
  1536.   NPIORB_CDB pIORB;
  1537.   struct CDB_ReadSubChannel *pCDB;               /* ptr to CDB               */
  1538.   UCHAR data_size;
  1539.  
  1540.   /*
  1541.   ** Build a CDB passthru IORB
  1542.   */
  1543.   switch (data_format)
  1544.   {
  1545.      case RSC_Q_SUB_CHANNEL:
  1546.         data_size = sizeof(struct SubQ_Channel_Data);
  1547.         break;
  1548.  
  1549.      case RSC_CURRENT_POSITION:
  1550.         data_size = sizeof(struct SubChannel_Position);
  1551.         break;
  1552.  
  1553.      case RSC_MEDIA_CAT_NUM:
  1554.         data_size = sizeof(struct SubChannel_Media_Cat);
  1555.         break;
  1556.  
  1557.      case RSC_TRACK_ISRC:
  1558.         data_size = sizeof(struct SubChannel_ISRC);
  1559.         break;
  1560.   }
  1561.  
  1562.  
  1563.   BuildIORB_PassthruCDB(pUnitCB,
  1564.                         (ULONG) data_size,
  1565.                         -1L,
  1566.                         (NPIORB_CDB FAR *) &pIORB);
  1567.  
  1568.   pIORB->apt.ControllerCmdLen = sizeof(struct CDB_ReadSubChannel);
  1569.   pIORB->apt.Flags |= PT_DIRECTION_IN;
  1570.  
  1571.   /*
  1572.   ** Setup the CDB
  1573.   */
  1574.   pCDB = (struct CDB_ReadSubChannel NEAR *) &pIORB->CDB;
  1575.   pCDB->OpCode = SCSI_READ_SUB_CHAN;
  1576.   pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  1577.   pCDB->MSF = 1;
  1578.   pCDB->SubQ = 1;
  1579.   pCDB->data_format = (UCHAR) data_format;
  1580.   pCDB->track_number = 0;
  1581.   pCDB->control = 0;
  1582.   pCDB->alloc_length.usbytes.byte_0 = 0;
  1583.   pCDB->alloc_length.usbytes.byte_1 = data_size;
  1584.  
  1585.  
  1586.   *pIORBOut = pIORB;
  1587.  
  1588. }
  1589.  
  1590.  
  1591. /****************************************************************************
  1592.  *
  1593.  * FUNCTION NAME = BuildCDB_ReadTOC
  1594.  *
  1595.  * DESCRIPTION   = Setup CDB for Read TOC command
  1596.  *
  1597.  *      BuildCDB_ReadCapacity (NPUNITCB pUnitCB, USHORT track_number,
  1598.  *                                               USHORT count,
  1599.  *                                               NPIORB_CDB FAR *pIORBOut)
  1600.  *
  1601.  * INPUT         = pUnitCB         - pointer to UnitCB
  1602.  *                 track_number    - track number
  1603.  *                 count           - count of descriptors to return
  1604.  *                 pIORBOut        - returned pointer to IORB
  1605.  *
  1606.  * OUTPUT        = NONE
  1607.  *
  1608.  * RETURN-NORMAL =
  1609.  * RETURN-ERROR  =
  1610.  *
  1611.  ****************************************************************************/
  1612.  
  1613. VOID  BuildCDB_ReadTOC (pUnitCB, track_number, count, pIORBOut)
  1614.  
  1615. NPUNITCB pUnitCB;
  1616. USHORT   track_number;
  1617. USHORT   count;
  1618. NPIORB_CDB FAR *pIORBOut;
  1619.  
  1620. {
  1621.   NPIORB_CDB pIORB;
  1622.   USHORT alloc_length;
  1623.  
  1624.   struct CDB_ReadTOC *pCDB;               /* ptr to CDB               */
  1625.  
  1626.   /*
  1627.   ** Build a CDB passthru IORB
  1628.   */
  1629.   alloc_length =  sizeof(struct TOC_Hdr) +
  1630.                   (sizeof(struct TOC_Descriptor) * count);
  1631.  
  1632.   BuildIORB_PassthruCDB(pUnitCB,
  1633.                         (ULONG) alloc_length,
  1634.                         -1L,
  1635.                         (NPIORB_CDB FAR *) &pIORB );
  1636.  
  1637.   pIORB->apt.ControllerCmdLen = sizeof(struct CDB_ReadTOC);
  1638.   pIORB->apt.Flags |= PT_DIRECTION_IN;
  1639.  
  1640.   /*
  1641.   ** Setup the CDB
  1642.   */
  1643.   pCDB = (struct CDB_ReadTOC NEAR *) &pIORB->CDB;
  1644.   pCDB->OpCode = SCSI_READ_TOC;
  1645.   pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  1646.   pCDB->MSF = 1;
  1647.   pCDB->starting_track = track_number;
  1648.   pCDB->alloc_length.usbytes.byte_0 = 0;
  1649.   pCDB->alloc_length.usbytes.byte_1 = alloc_length;
  1650.   pCDB->control = 0;
  1651.  
  1652.   *pIORBOut = pIORB;
  1653.  
  1654.  
  1655.   if (pUnitCB->DeviceInfo.product_id_code == HITACHI_3750)
  1656.        DevHelp_ProcBlock( (ULONG) ppDataSeg, (ULONG) 500, 0);
  1657.  
  1658. }
  1659.  
  1660.  
  1661. /****************************************************************************
  1662.  *
  1663.  * FUNCTION NAME = BuildCDB_ReadHeader
  1664.  *
  1665.  * DESCRIPTION   = Setup CDB for Read Header command
  1666.  *
  1667.  *     BuildCDB_ReadHeader (NPUNITCB pUnitCB, ULONG LBA, NPIORB FAR *pIORB);
  1668.  *
  1669.  * INPUT         = pUnitCB         - pointer to UnitCB
  1670.  *                 LBA             - Sub-channel data format to return
  1671.  *                 pIORBOut        - returned pointer to IORB
  1672.  *
  1673.  * OUTPUT        = NONE
  1674.  *
  1675.  * RETURN-NORMAL =
  1676.  * RETURN-ERROR  =
  1677.  *
  1678.  ****************************************************************************/
  1679.  
  1680. VOID BuildCDB_ReadHeader (pUnitCB, LBA, pIORBOut)
  1681.  
  1682. NPUNITCB   pUnitCB;
  1683. ULONG      LBA;
  1684. NPIORB_CDB FAR *pIORBOut;
  1685. {
  1686.  
  1687.   NPIORB_CDB pIORB;
  1688.  
  1689.   struct CDB_ReadHeader *pCDB;               /* ptr to CDB               */
  1690.  
  1691.   /*
  1692.   ** Build a CDB passthru IORB
  1693.   */
  1694.   BuildIORB_PassthruCDB(pUnitCB,
  1695.                         sizeof(struct ReadHeader_Data),
  1696.                         -1L,
  1697.                         (NPIORB_CDB FAR *) &pIORB );
  1698.  
  1699.   pIORB->apt.ControllerCmdLen = sizeof(struct CDB_ReadHeader);
  1700.   pIORB->apt.Flags |= PT_DIRECTION_IN;
  1701.  
  1702.   /*
  1703.   ** Setup the CDB
  1704.   */
  1705.   pCDB = (struct CDB_ReadHeader NEAR *) &pIORB->CDB;
  1706.   pCDB->OpCode = SCSI_READ_HEADER;
  1707.   pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  1708.   pCDB->MSF = 0;
  1709.   pCDB->LBA.dword = LBA;
  1710.   pCDB->alloc_length.usbytes.byte_0 = 0;
  1711.   pCDB->alloc_length.usbytes.byte_1 = sizeof(struct ReadHeader_Data);
  1712.   pCDB->control = 0;
  1713.  
  1714.   *pIORBOut = pIORB;
  1715.  
  1716. }
  1717.  
  1718.  
  1719. /****************************************************************************
  1720.  *
  1721.  * FUNCTION NAME = BuildCDB_PauseResume
  1722.  *
  1723.  * DESCRIPTION   = Setup CDB for Pause Resume command
  1724.  *       BuildCDB_PauseResume (NPUNITCB pUnitCB,  resume_flag,
  1725.  *                                               NPIORB_CDB FAR *pIORBOut)
  1726.  *
  1727.  * INPUT         = pUnitCB         - pointer to UnitCB
  1728.  *                 resume_flag     - 1 = resume, 0 = pause
  1729.  *                 pIORBOut        - returned pointer to IORB
  1730.  *
  1731.  * OUTPUT        = NONE
  1732.  *
  1733.  * RETURN-NORMAL =
  1734.  * RETURN-ERROR  =
  1735.  *
  1736.  ****************************************************************************/
  1737.  
  1738. VOID BuildCDB_PauseResume (pUnitCB, resume_flag, pIORBOut)
  1739.  
  1740. NPUNITCB pUnitCB;
  1741. USHORT   resume_flag;
  1742. NPIORB_CDB FAR *pIORBOut;
  1743.  
  1744. {
  1745.    NPIORB_CDB pIORB;
  1746.  
  1747.    struct CDB_PauseResume NEAR *pCDB;
  1748.  
  1749.   /*
  1750.   ** Build a CDB passthru IORB
  1751.   */
  1752.    BuildIORB_PassthruCDB(pUnitCB, 0, 0, (NPIORB_CDB FAR *) &pIORB);
  1753.  
  1754.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_PauseResume);
  1755.  
  1756.    pCDB = (struct CDB_PauseResume NEAR * ) &(pIORB->CDB);
  1757.    pCDB->OpCode = SCSI_PAUSE_RESUME;
  1758.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  1759.    pCDB->resume = resume_flag;
  1760.  
  1761.    *pIORBOut = pIORB;
  1762. }
  1763.  
  1764.  
  1765. /****************************************************************************
  1766.  *
  1767.  * FUNCTION NAME = BuildCDB_StartStopUnit
  1768.  *
  1769.  * DESCRIPTION   = Setup CDB for Start Stop Unit command
  1770.  *
  1771.  *       BuildCDB_StartStopUnit (NPUNITCB pUnitCB,  flag,
  1772.  *                                               NPIORB_CDB FAR *pIORBOut)
  1773.  *
  1774.  * INPUT         = pUnitCB         - pointer to UnitCB
  1775.  *                 flag            - start-stop flag
  1776.  *                 pIORBOut        - returned pointer to IORB
  1777.  *
  1778.  * OUTPUT        = NONE
  1779.  *
  1780.  * RETURN-NORMAL =
  1781.  * RETURN-ERROR  =
  1782.  *
  1783.  ****************************************************************************/
  1784.  
  1785. VOID BuildCDB_StartStopUnit (pUnitCB, type, pIORBOut)
  1786.  
  1787. NPUNITCB pUnitCB;
  1788. USHORT   type;
  1789. NPIORB_CDB FAR *pIORBOut;
  1790.  
  1791. {
  1792.    NPIORB_CDB pIORB;
  1793.  
  1794.    struct CDB_StartStopUnit NEAR *pCDB;
  1795.  
  1796.    /*
  1797.    ** Build a CDB passthru IORB
  1798.    */
  1799.    BuildIORB_PassthruCDB(pUnitCB, 0, 0, (NPIORB_CDB FAR *) &pIORB);
  1800.  
  1801.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_StartStopUnit);
  1802.  
  1803.    /*
  1804.    ** Setup the CDB
  1805.    */
  1806.    pCDB = (struct CDB_StartStopUnit NEAR *) &(pIORB->CDB);
  1807.    pCDB->OpCode = SCSI_START_STOP_UNIT;
  1808.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  1809.  
  1810.  
  1811.    switch (type)
  1812.    {
  1813.       case CDBF_START:
  1814.          pCDB->start = 1;
  1815.          pCDB->LoEj = 0;
  1816.          break;
  1817.  
  1818.       case CDBF_EJECT:
  1819.          pCDB->start = 0;
  1820.          pCDB->LoEj = 1;
  1821.          break;
  1822.  
  1823.       case CDBF_CLOSE_TRAY:
  1824.          pCDB->start = 1;
  1825.          pCDB->LoEj = 1;
  1826.          break;
  1827.    }
  1828.  
  1829.  
  1830.    *pIORBOut = pIORB;
  1831. }
  1832.  
  1833.  
  1834. /****************************************************************************
  1835.  *
  1836.  * FUNCTION NAME = BuildCDB_PlayAudio_MSF
  1837.  *
  1838.  * DESCRIPTION   = Setup CDB for Play Audio MSF
  1839.  *
  1840.  *       BuildCDB_PlayAudio_MSF (NPUNITCB pUnitCB, AddressType start,
  1841.  *                                                 AddressType end,
  1842.  *                                                 NPIORB_CDB FAR *pIORBOut)
  1843.  *
  1844.  * INPUT         = pUnitCB         - pointer to UnitCB
  1845.  *                 start           - starting address in MSF format
  1846.  *                 end             - ending address in MSF format
  1847.  *                 pIORBOut        - returned pointer to IORB
  1848.  *
  1849.  * OUTPUT        = NONE
  1850.  *
  1851.  * RETURN-NORMAL =
  1852.  * RETURN-ERROR  =
  1853.  *
  1854.  ****************************************************************************/
  1855.  
  1856. VOID BuildCDB_PlayAudio_MSF (pUnitCB, start, end, pIORBOut)
  1857.  
  1858. NPUNITCB pUnitCB;
  1859. union AddressType start;
  1860. union AddressType end;
  1861. NPIORB_CDB FAR *pIORBOut;
  1862.  
  1863. {
  1864.    NPIORB_CDB pIORB;
  1865.  
  1866.    struct CDB_PlayAudio_MSF NEAR *pCDB;
  1867.  
  1868.   /*
  1869.   ** Build a CDB passthru IORB
  1870.   */
  1871.    BuildIORB_PassthruCDB(pUnitCB, 0, 0, (NPIORB_CDB FAR *) &pIORB);
  1872.  
  1873.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_PlayAudio_MSF);
  1874.  
  1875.    pCDB = (struct CDB_PlayAudio_MSF NEAR * ) &(pIORB->CDB);
  1876.    pCDB->OpCode = SCSI_PLAY_MSF;
  1877.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  1878.  
  1879.    pCDB->starting_M = start.ul_redbook.min;
  1880.    pCDB->starting_S = start.ul_redbook.sec;
  1881.    pCDB->starting_F = start.ul_redbook.frame;
  1882.  
  1883.    pCDB->ending_M =   end.ul_redbook.min;
  1884.    pCDB->ending_S =   end.ul_redbook.sec;
  1885.    pCDB->ending_F =   end.ul_redbook.frame;
  1886.  
  1887.    *pIORBOut = pIORB;
  1888. }
  1889. /*
  1890. ** ** The following commands are **
  1891. ** ** ATAPI unique.              **
  1892. */
  1893.  
  1894. /****************************************************************************
  1895.  *
  1896.  * FUNCTION NAME = ATAPI_BuildCDB_ReadCD
  1897.  *
  1898.  * DESCRIPTION   = Setup CDB for ATAPI Read CD command
  1899.  *
  1900.  *  ATAPI_BuildCDB_ReadCD (NPUNITCB pUnitCB, ULONG LBA, ULONG transfer_length,
  1901.  *                     ULONG transfer_addr, NPIORB_CDB FAR *pIORBOut)
  1902.  *
  1903.  * INPUT         = pUnitCB         - pointer to UnitCB
  1904.  *                 LBA             - logical block address
  1905.  *                 transfer_length - count of blocks to transfer
  1906.  *                 transfer_addr   - transfer address
  1907.  *                 pIORBOut        - returned pointer to IORB
  1908.  *
  1909.  * OUTPUT        = NONE
  1910.  *
  1911.  * RETURN-NORMAL =
  1912.  * RETURN-ERROR  =
  1913.  *
  1914.  ****************************************************************************/
  1915.  
  1916. VOID ATAPI_BuildCDB_ReadCD (pUnitCB, LBA, transfer_length, transfer_addr,
  1917.                                                              pIORBOut)
  1918.  
  1919. NPUNITCB   pUnitCB;
  1920. ULONG      LBA;
  1921. USHORT     transfer_length;
  1922. ULONG      transfer_addr;
  1923. NPIORB_CDB FAR *pIORBOut;
  1924.  
  1925. {
  1926.    NPIORB_CDB pIORB;
  1927.  
  1928.    struct CDB_ReadCD  NEAR *pCDB;
  1929.  
  1930.    union ULONGB  ul_LBA;
  1931.    union USHORTB us_transfer_length;
  1932.  
  1933.    ul_LBA.dword = LBA;
  1934.    us_transfer_length.word = transfer_length;
  1935.  
  1936.    /*
  1937.    ** Build a CDB passthru IORB
  1938.    */
  1939.    BuildIORB_PassthruCDB ( pUnitCB,
  1940.                            (ULONG) transfer_length * 2352,
  1941.                            transfer_addr,
  1942.                            (NPIORB_CDB FAR *) &pIORB );
  1943.  
  1944.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_ReadCD);
  1945.    pIORB->apt.Flags = PT_DIRECTION_IN;
  1946.  
  1947.    /*
  1948.    ** Setup the CDB
  1949.    */
  1950.    pCDB = (struct CDB_ReadCD NEAR *) &(pIORB->CDB);
  1951.    pCDB->OpCode = ATAPI_READ_CD;
  1952.    pCDB->data_type = RCD_TYPE_ANY;
  1953.  
  1954.    pCDB->LBA.ulbytes.byte_0 = ul_LBA.ulbytes.byte_3;
  1955.    pCDB->LBA.ulbytes.byte_1 = ul_LBA.ulbytes.byte_2;
  1956.    pCDB->LBA.ulbytes.byte_2 = ul_LBA.ulbytes.byte_1;
  1957.    pCDB->LBA.ulbytes.byte_3 = ul_LBA.ulbytes.byte_0;
  1958.  
  1959.    pCDB->transfer_length_msb = 0;
  1960.    pCDB->transfer_length = us_transfer_length.usbytes.byte_1;
  1961.    pCDB->transfer_length_lsb = us_transfer_length.usbytes.byte_0;
  1962.  
  1963.    pCDB->error_flag = RCD_ERRFLG_NONE;
  1964.    pCDB->edc_ecc = 1;
  1965.    pCDB->user_data = 1;
  1966.    pCDB->headers = RCD_HEADER_ALL;
  1967.    pCDB->sync = 1;
  1968.    pCDB->subchannel = RCD_SUB_NONE;
  1969.  
  1970.  
  1971.    *pIORBOut = pIORB;
  1972. }
  1973.  
  1974.  
  1975.  
  1976.  
  1977. /*
  1978. ** ** The following commands are **
  1979. ** ** vendor unique.             **
  1980. */
  1981.  
  1982. /****************************************************************************
  1983.  *
  1984.  * FUNCTION NAME = Sony_BuildCDB_Read_CDDA
  1985.  *
  1986.  * DESCRIPTION   = Setup CDB for Read CD-DA command
  1987.  *
  1988.  *  Sony_BuildCDB_Read_CDDA (NPUNITCB pUnitCB, ULONG LBA, ULONG transfer_length,
  1989.  *                     ULONG transfer_addr, NPIORB_CDB FAR *pIORBOut)
  1990.  *
  1991.  * INPUT         = pUnitCB         - pointer to UnitCB
  1992.  *                 LBA             - logical block address
  1993.  *                 transfer_length - count of blocks to transfer
  1994.  *                 transfer_addr   - transfer address
  1995.  *                 pIORBOut        - returned pointer to IORB
  1996.  *
  1997.  * OUTPUT        = NONE
  1998.  *
  1999.  * RETURN-NORMAL =
  2000.  * RETURN-ERROR  =
  2001.  *
  2002.  ****************************************************************************/
  2003.  
  2004. VOID Sony_BuildCDB_Read_CDDA (pUnitCB, LBA, transfer_length, transfer_addr,
  2005.                                                              pIORBOut)
  2006.  
  2007. NPUNITCB   pUnitCB;
  2008. ULONG      LBA;
  2009. USHORT     transfer_length;
  2010. ULONG      transfer_addr;
  2011. NPIORB_CDB FAR *pIORBOut;
  2012.  
  2013. {
  2014.    NPIORB_CDB pIORB;
  2015.  
  2016.    struct Sony_CDB_Read_CDDA  NEAR *pCDB;
  2017.  
  2018.    union ULONGB  ul_LBA;
  2019.    union USHORTB us_transfer_length;
  2020.  
  2021.    ul_LBA.dword = LBA;
  2022.    us_transfer_length.word = transfer_length;
  2023.  
  2024.    /*
  2025.    ** Build a CDB passthru IORB
  2026.    */
  2027.    BuildIORB_PassthruCDB ( pUnitCB,
  2028.                            (ULONG) transfer_length * 2352,
  2029.                            transfer_addr,
  2030.                            (NPIORB_CDB FAR *) &pIORB );
  2031.  
  2032.    pIORB->apt.ControllerCmdLen = sizeof(struct Sony_CDB_Read_CDDA);
  2033.    pIORB->apt.Flags = PT_DIRECTION_IN;
  2034.  
  2035.    /*
  2036.    ** Setup the CDB
  2037.    */
  2038.    pCDB = (struct Sony_CDB_Read_CDDA NEAR *) &(pIORB->CDB);
  2039.    pCDB->OpCode = SONY_READ_CDDA;
  2040.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  2041.  
  2042.    pCDB->LBA.ulbytes.byte_0 = ul_LBA.ulbytes.byte_3;
  2043.    pCDB->LBA.ulbytes.byte_1 = ul_LBA.ulbytes.byte_2;
  2044.    pCDB->LBA.ulbytes.byte_2 = ul_LBA.ulbytes.byte_1;
  2045.    pCDB->LBA.ulbytes.byte_3 = ul_LBA.ulbytes.byte_0;
  2046.  
  2047.    pCDB->transfer_length.ulbytes.byte_0 = 0;
  2048.    pCDB->transfer_length.ulbytes.byte_1 = 0;
  2049.    pCDB->transfer_length.ulbytes.byte_2 = us_transfer_length.usbytes.byte_1;
  2050.    pCDB->transfer_length.ulbytes.byte_3 = us_transfer_length.usbytes.byte_0;
  2051.  
  2052.    pCDB->sub_code = CDDA_SUBCODE_2352;
  2053.  
  2054.    *pIORBOut = pIORB;
  2055. }
  2056.  
  2057.  
  2058. /****************************************************************************
  2059.  *
  2060.  * FUNCTION NAME = Sony_BuildCDB_Read_CDXA
  2061.  *
  2062.  * DESCRIPTION   = Setup CDB for Read CD-XA command
  2063.  *
  2064.  *  Sony_BuildCDB_Read_CDXA (NPUNITCB pUnitCB, ULONG LBA, ULONG transfer_length,
  2065.  *                     ULONG transfer_addr, NPIORB_CDB FAR *pIORBOut)
  2066.  *
  2067.  * INPUT         = pUnitCB         - pointer to UnitCB
  2068.  *                 LBA             - logical block address
  2069.  *                 block_length    - block_length
  2070.  *                 transfer_length - count of blocks to transfer
  2071.  *                 transfer_addr   - transfer address
  2072.  *                 pIORBOut        - returned pointer to IORB
  2073.  *
  2074.  * OUTPUT        = NONE
  2075.  *
  2076.  * RETURN-NORMAL =
  2077.  * RETURN-ERROR  =
  2078.  *
  2079.  ****************************************************************************/
  2080.  
  2081. VOID Sony_BuildCDB_Read_CDXA (pUnitCB, LBA, block_length, transfer_length,
  2082.                                        transfer_addr, format, pIORBOut)
  2083.  
  2084. NPUNITCB   pUnitCB;
  2085. ULONG      LBA;
  2086. USHORT     block_length;
  2087. USHORT     transfer_length;
  2088. ULONG      transfer_addr;
  2089. USHORT     format;
  2090. NPIORB_CDB FAR *pIORBOut;
  2091.  
  2092. {
  2093.    NPIORB_CDB pIORB;
  2094.  
  2095.    struct Sony_CDB_Read_CDXA  NEAR *pCDB;
  2096.  
  2097.    union ULONGB  ul_LBA;
  2098.    union USHORTB us_transfer_length;
  2099.  
  2100.    ul_LBA.dword = LBA;
  2101.    us_transfer_length.word = transfer_length;
  2102.  
  2103.    /*
  2104.    ** Build a CDB passthru IORB
  2105.    */
  2106.    BuildIORB_PassthruCDB ( pUnitCB,
  2107.                            (ULONG) transfer_length * block_length,
  2108.                            transfer_addr,
  2109.                            (NPIORB_CDB FAR *) &pIORB );
  2110.  
  2111.    pIORB->apt.ControllerCmdLen = sizeof(struct Sony_CDB_Read_CDXA);
  2112.    pIORB->apt.Flags = PT_DIRECTION_IN;
  2113.  
  2114.    /*
  2115.    ** Setup the CDB
  2116.    */
  2117.    pCDB = (struct Sony_CDB_Read_CDXA NEAR *) &(pIORB->CDB);
  2118.    pCDB->OpCode = SONY_READ_CDXA;
  2119.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  2120.  
  2121.    pCDB->LBA.ulbytes.byte_0 = ul_LBA.ulbytes.byte_3;
  2122.    pCDB->LBA.ulbytes.byte_1 = ul_LBA.ulbytes.byte_2;
  2123.    pCDB->LBA.ulbytes.byte_2 = ul_LBA.ulbytes.byte_1;
  2124.    pCDB->LBA.ulbytes.byte_3 = ul_LBA.ulbytes.byte_0;
  2125.  
  2126.    pCDB->transfer_length.ulbytes.byte_0 = 0;
  2127.    pCDB->transfer_length.ulbytes.byte_1 = 0;
  2128.    pCDB->transfer_length.ulbytes.byte_2 = us_transfer_length.usbytes.byte_1;
  2129.    pCDB->transfer_length.ulbytes.byte_3 = us_transfer_length.usbytes.byte_0;
  2130.  
  2131.    pCDB->format = format;
  2132.  
  2133.    *pIORBOut = pIORB;
  2134. }
  2135.  
  2136.  
  2137.  
  2138. ;/***************************************************************************
  2139. ;*
  2140. ;* FUNCTION NAME = Tosh_BuildCDB_ReadDiskInfo
  2141. ;*
  2142. ;* DESCRIPTION   = Setup CDB for Toshiba Read Disk Info
  2143. ;*
  2144. ;*                 Tosh_BuildCDB_ReadDiskInfo (NPUNITCB pUnitCB, USHORT type,
  2145. ;*                                             NPIORB_CDB FAR *pIORBOut)
  2146. ;*
  2147. ;* INPUT         = pUnitCB         - pointer to UnitCB
  2148. ;*                 type            - type of disc info to retrieve
  2149. ;*                 pIORBOut        - returned pointer to IORB
  2150. ;*
  2151. ;* OUTPUT        =
  2152. ;*
  2153. ;* RETURN-NORMAL =
  2154. ;* RETURN-ERROR  =
  2155. ;*
  2156. ;**************************************************************************/
  2157.  
  2158. VOID Tosh_BuildCDB_ReadDiskInfo (pUnitCB, type, pIORBOut)
  2159.  
  2160. NPUNITCB   pUnitCB;
  2161. USHORT     type;
  2162. NPIORB_CDB FAR *pIORBOut;
  2163.  
  2164. {
  2165.    NPIORB_CDB pIORB;
  2166.  
  2167.    struct TOSH_CDB_ReadDiskInfo  NEAR *pCDB;
  2168.  
  2169.    /*
  2170.    ** Build a CDB passthru IORB
  2171.    */
  2172.    BuildIORB_PassthruCDB ( pUnitCB,
  2173.                            sizeof(union TOSH_ReadDiskInfo_Data),
  2174.                            -1L,
  2175.                            (NPIORB_CDB FAR *) &pIORB );
  2176.  
  2177.    pIORB->apt.ControllerCmdLen = sizeof(struct TOSH_CDB_ReadDiskInfo);
  2178.    pIORB->apt.Flags = PT_DIRECTION_IN;
  2179.  
  2180.    /*
  2181.    ** Setup the CDB
  2182.    */
  2183.    pCDB = (struct TOSH_CDB_ReadDiskInfo NEAR *) &(pIORB->CDB);
  2184.  
  2185.    pCDB->OpCode = TOSH_READ_DISK_INFO;
  2186.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  2187.    pCDB->type = type;
  2188.    pCDB->track_number = 0;
  2189.  
  2190.  
  2191.    *pIORBOut = pIORB;
  2192. }
  2193.  
  2194.  
  2195. ;/***************************************************************************
  2196. ;*
  2197. ;* FUNCTION NAME = Chinon_BuildCDB_GetLastSession
  2198. ;*
  2199. ;* DESCRIPTION   = Setup CDB for Chinon Get Last Session address
  2200. ;*
  2201. ;*                 Chinon_BuildCDB_GetLastSession (NPUNITCB pUnitCB,
  2202. ;*                                                 NPIORB_CDB FAR *pIORBOut)
  2203. ;*
  2204. ;* INPUT         = pUnitCB         - pointer to UnitCB
  2205. ;*                 pIORBOut        - returned pointer to IORB
  2206. ;*
  2207. ;* OUTPUT        =
  2208. ;*
  2209. ;* RETURN-NORMAL =
  2210. ;* RETURN-ERROR  =
  2211. ;*
  2212. ;**************************************************************************/
  2213.  
  2214. VOID Chinon_BuildCDB_GetLastSession (pUnitCB, pIORBOut)
  2215.  
  2216. NPUNITCB   pUnitCB;
  2217. NPIORB_CDB FAR *pIORBOut;
  2218.  
  2219. {
  2220.    NPIORB_CDB pIORB;
  2221.  
  2222.    struct CHINON_CDB_GetLastSession  NEAR *pCDB;
  2223.  
  2224.    /*
  2225.    ** Build a CDB passthru IORB
  2226.    */
  2227.    BuildIORB_PassthruCDB ( pUnitCB,
  2228.                            sizeof(struct CHINON_LastSessionData),
  2229.                            -1L,
  2230.                            (NPIORB_CDB FAR *) &pIORB );
  2231.  
  2232.    pIORB->apt.ControllerCmdLen = sizeof(struct CHINON_CDB_GetLastSession);
  2233.    pIORB->apt.Flags = PT_DIRECTION_IN;
  2234.  
  2235.    /*
  2236.    ** Setup the CDB
  2237.    */
  2238.    pCDB = (struct CHINON_CDB_GetLastSession NEAR *) &(pIORB->CDB);
  2239.  
  2240.    pCDB->OpCode = CHINON_GET_LAST_SESSION;
  2241.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  2242.  
  2243.  
  2244.    *pIORBOut = pIORB;
  2245. }
  2246.  
  2247.  
  2248. ;/***************************************************************************
  2249. ;*
  2250. ;* FUNCTION NAME = NEC_BuildCDB_GetLastSession
  2251. ;*
  2252. ;* DESCRIPTION   = Setup CDB for NEC Get Last Session address
  2253. ;*
  2254. ;*                 NEC_BuildCDB_GetLastSession (NPUNITCB pUnitCB,
  2255. ;*                                                 NPIORB_CDB FAR *pIORBOut)
  2256. ;*
  2257. ;* INPUT         = pUnitCB         - pointer to UnitCB
  2258. ;*                 pIORBOut        - returned pointer to IORB
  2259. ;*
  2260. ;* OUTPUT        =
  2261. ;*
  2262. ;* RETURN-NORMAL =
  2263. ;* RETURN-ERROR  =
  2264. ;*
  2265. ;**************************************************************************/
  2266.  
  2267. VOID NEC_BuildCDB_GetLastSession (pUnitCB, pIORBOut)
  2268.  
  2269. NPUNITCB   pUnitCB;
  2270. NPIORB_CDB FAR *pIORBOut;
  2271.  
  2272. {
  2273.    NPIORB_CDB pIORB;
  2274.  
  2275.    NEC_CDB_ReadTOC NEAR *pCDB;
  2276.  
  2277.    /*
  2278.    ** Build a CDB passthru IORB
  2279.    */
  2280.    BuildIORB_PassthruCDB ( pUnitCB,
  2281.                            sizeof(NEC_DATA_PointInfo) +
  2282.                            sizeof(NEC_DATA_Point),
  2283.                            -1L,
  2284.                            (NPIORB_CDB FAR *) &pIORB );
  2285.  
  2286.    pIORB->apt.ControllerCmdLen = sizeof(NEC_CDB_ReadTOC);
  2287.    pIORB->apt.Flags = PT_DIRECTION_IN;
  2288.  
  2289.    /*
  2290.    ** Setup the CDB
  2291.    */
  2292.    pCDB = (NEC_CDB_ReadTOC NEAR *) &(pIORB->CDB);
  2293.  
  2294.    pCDB->OpCode = NEC_READ_TOC;
  2295.    pCDB->data_type = NEC_POINT_INFO;
  2296.    pCDB->TNO = 0xB0;
  2297.  
  2298.    *pIORBOut = pIORB;
  2299. }
  2300.  
  2301.  
  2302. ;/***************************************************************************
  2303. ;*
  2304. ;* FUNCTION NAME = ADD_BuildCDB_ReadDiskInfo
  2305. ;*
  2306. ;* DESCRIPTION   = Setup CDB for Read Disk Info
  2307. ;*
  2308. ;*                  ADD_BuildCDB_ReadDiskInfo (NPUNITCB pUnitCB, USHORT type,
  2309. ;*                                             NPIORB_CDB FAR *pIORBOut)
  2310. ;*
  2311. ;* INPUT         = pUnitCB         - pointer to UnitCB
  2312. ;*                 type            - type of disc info to retrieve
  2313. ;*                 pIORBOut        - returned pointer to IORB
  2314. ;*
  2315. ;* OUTPUT        =
  2316. ;*
  2317. ;* RETURN-NORMAL =
  2318. ;* RETURN-ERROR  =
  2319. ;*
  2320. ;**************************************************************************/
  2321.  
  2322. VOID ADD_BuildCDB_ReadDiskInfo (pUnitCB, type, pIORBOut)
  2323.  
  2324. NPUNITCB   pUnitCB;
  2325. USHORT     type;
  2326. NPIORB_CDB FAR *pIORBOut;
  2327.  
  2328. {
  2329.    NPIORB_CDB pIORB;
  2330.  
  2331.    struct ADD_CDB_ReadDiskInfo  NEAR *pCDB;
  2332.  
  2333.    /*
  2334.    ** Build a CDB passthru IORB
  2335.    */
  2336.    BuildIORB_PassthruCDB ( pUnitCB,
  2337.                            sizeof(union ADD_ReadDiskInfo_Data),
  2338.                            -1L,
  2339.                            (NPIORB_CDB FAR *) &pIORB );
  2340.  
  2341.    pIORB->apt.ControllerCmdLen = sizeof(struct ADD_CDB_ReadDiskInfo);
  2342.    pIORB->apt.Flags = PT_DIRECTION_IN;
  2343.  
  2344.    /*
  2345.    ** Setup the CDB
  2346.    */
  2347.    pCDB = (struct ADD_CDB_ReadDiskInfo NEAR *) &(pIORB->CDB);
  2348.  
  2349.    pCDB->OpCode = ADD_READ_DISK_INFO;
  2350.    pCDB->LUN = pUnitCB->UnitInfo.UnitSCSILUN;
  2351.    pCDB->type = type;
  2352.  
  2353.  
  2354.    *pIORBOut = pIORB;
  2355. }
  2356.  
  2357. ;/************************************************************************* //SD@135221
  2358. ;*                                                                          //SD@135221
  2359. ;* FUNCTION NAME = BuildCDB_MechanismStatus                                 //SD@135221
  2360. ;*                                                                          //SD@135221
  2361. ;* DESCRIPTION   = Setup CDB for ATAPI Changer status info                  //SD@135221
  2362. ;*                                                                          //SD@135221
  2363. ;*                  BuildCDB_MechanismStatus (NPUNITCB pUnitCB,             //SD@135221
  2364. ;*                                            NPIORB_CDB FAR *pIORBOut)     //SD@135221
  2365. ;*                                                                          //SD@135221
  2366. ;* INPUT         = pUnitCB         - pointer to UnitCB                      //SD@135221
  2367. ;*                 pIORBOut        - returned pointer to IORB               //SD@135221
  2368. ;*                                                                          //SD@135221
  2369. ;* OUTPUT        =                                                          //SD@135221
  2370. ;*                                                                          //SD@135221
  2371. ;* RETURN-NORMAL =                                                          //SD@135221
  2372. ;* RETURN-ERROR  =                                                          //SD@135221
  2373. ;*                                                                          //SD@135221
  2374. ;**************************************************************************///SD@135221
  2375.                                                                             //SD@135221
  2376. VOID BuildCDB_MechanismStatus(pUnitCB, pIORBOut,size)                       //SD@135221
  2377.                                                                             //SD@135221
  2378. NPUNITCB   pUnitCB;                                                         //SD@135221
  2379. USHORT     size;                                                            //SD@135221
  2380. NPIORB_CDB FAR *pIORBOut;                                                   //SD@135221
  2381.                                                                             //SD@135221
  2382. {                                                                           //SD@135221
  2383.    NPIORB_CDB pIORB;                                                        //SD@135221
  2384.    union USHORTB slottable_size;                                            //SD@135221
  2385.                                                                             //SD@135221
  2386.    struct CDB_MechanismStatus NEAR *pCDB;                                   //SD@135221
  2387.                                                                             //SD@135221
  2388.    /*                                                                       //SD@135221
  2389.    ** Build a CDB passthru IORB                                             //SD@135221
  2390.    */                                                                       //SD@135221
  2391.    BuildIORB_PassthruCDB ( pUnitCB,                                         //SD@135221
  2392.                            size,                                            //SD@135221
  2393.                            -1L,                                             //SD@135221
  2394.                            (NPIORB_CDB FAR *) &pIORB );                     //SD@135221
  2395.                                                                             //SD@135221
  2396.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_MechanismStatus);        //SD@135221
  2397.    pIORB->apt.Flags = PT_DIRECTION_IN;                                      //SD@135221
  2398.                                                                             //SD@135221
  2399.    /*                                                                       //SD@135221
  2400.    ** Setup the CDB                                                         //SD@135221
  2401.    */                                                                       //SD@135221
  2402.    pCDB = (struct CDB_MechanismStatus NEAR *) &(pIORB->CDB);                //SD@135221
  2403.                                                                             //SD@135221
  2404.    pCDB->OpCode = ATAPI_MECHANISM_STATUS;                                   //SD@135221
  2405.    slottable_size.word=size;                                                //SD@135221
  2406.    pCDB->Allocation_Length.usbytes.byte_0=slottable_size.usbytes.byte_1;    //SD@135221
  2407.    pCDB->Allocation_Length.usbytes.byte_1=slottable_size.usbytes.byte_0;    //SD@135221
  2408.                                                                             //SD@135221
  2409.    *pIORBOut = pIORB;                                                       //SD@135221
  2410. }                                                                           //SD@135221
  2411.                                                                             //SD@135221
  2412. ;/************************************************************************* //SD@135221
  2413. ;*                                                                          //SD@135221
  2414. ;* FUNCTION NAME = BuildCDB_ChangerLoad                                     //SD@135221
  2415. ;*                                                                          //SD@135221
  2416. ;* DESCRIPTION   = Setup CDB for ATAPI Changer status info                  //SD@135221
  2417. ;*                                                                          //SD@135221
  2418. ;*                  BuildCDB_ChangerLoad (NPUNITCB pUnitCB,                 //SD@135221
  2419. ;*                                        NPIORB_CDB FAR *pIORBOut          //SD@135221
  2420. ;*                                        USHORT Slot)                      //SD@135221
  2421. ;*                                                                          //SD@135221
  2422. ;* INPUT         = pUnitCB         - pointer to UnitCB                      //SD@135221
  2423. ;*                 pIORBOut        - returned pointer to IORB               //SD@135221
  2424. ;*                 Slot            - slot to make active                    //SD@135221
  2425. ;*                                                                          //SD@135221
  2426. ;* OUTPUT        =                                                          //SD@135221
  2427. ;*                                                                          //SD@135221
  2428. ;* RETURN-NORMAL =                                                          //SD@135221
  2429. ;* RETURN-ERROR  =                                                          //SD@135221
  2430. ;*                                                                          //SD@135221
  2431. ;**************************************************************************///SD@135221
  2432.                                                                             //SD@135221
  2433. VOID BuildCDB_ChangerLoad(pUnitCB, pIORBOut,Slot)                           //SD@135221
  2434.                                                                             //SD@135221
  2435. NPUNITCB   pUnitCB;                                                         //SD@135221
  2436. USHORT     Slot;                                                            //SD@135221
  2437. NPIORB_CDB FAR *pIORBOut;                                                   //SD@135221
  2438.                                                                             //SD@135221
  2439. {                                                                           //SD@135221
  2440.    NPIORB_CDB pIORB;                                                        //SD@135221
  2441.                                                                             //SD@135221
  2442.    struct CDB_LoadSLot NEAR *pCDB;                                          //SD@135221
  2443.                                                                             //SD@135221
  2444.    /*                                                                       //SD@135221
  2445.    ** Build a CDB passthru IORB                                             //SD@135221
  2446.    */                                                                       //SD@135221
  2447.    BuildIORB_PassthruCDB ( pUnitCB,                                         //SD@135221
  2448.                            sizeof(struct CDB_LoadSLot),                     //SD@135221
  2449.                            -1L,                                             //SD@135221
  2450.                            (NPIORB_CDB FAR *) &pIORB );                     //SD@135221
  2451.                                                                             //SD@135221
  2452.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_LoadSLot);               //SD@135221
  2453.    pIORB->apt.Flags = PT_DIRECTION_IN;                                      //SD@135221
  2454.                                                                             //SD@135221
  2455.    /*                                                                       //SD@135221
  2456.    ** Setup the CDB                                                         //SD@135221
  2457.    */                                                                       //SD@135221
  2458.    pCDB = (struct CDB_LoadSLot NEAR *) &(pIORB->CDB);                       //SD@135221
  2459.                                                                             //SD@135221
  2460.    pCDB->OpCode = ATAPI_CHANGER_LOAD;                                       //SD@135221
  2461.    if(pUnitCB->DeviceInfo.product_id_code==TORISAN_C3G)                     //SD@135221
  2462.      {                                                                      //SD@135221
  2463.      ((NPIORB_CDB)pIORB)->CDB.byte_7 = (UCHAR) Slot;                        //SD@135221
  2464.      } /* endif */                                                          //SD@135221
  2465.    else                                                                     //SD@135221
  2466.      {                                                                      //SD@135221
  2467.      pCDB->LoUnLo=TRUE;                                                     //SD@135221
  2468.      pCDB->Immed=FALSE;                                                     //SD@135221
  2469.      pCDB->Start =TRUE;                                                     //SD@135221
  2470.      pCDB->NewSlot =(UCHAR)Slot;                                            //SD@135221
  2471.      } /* endelse */                                                        //SD@135221
  2472.                                                                             //SD@135221
  2473.                                                                             //SD@135221
  2474.    *pIORBOut = pIORB;                                                       //SD@135221
  2475. }                                                                           //SD@135221
  2476.                                                                             //SD@135221
  2477. /*********************************************************************@V147578
  2478.  *                                                                    @V147578
  2479.  * FUNCTION NAME = BuildCDB_EnablePMMode                              @V147578
  2480.  *                                                                    @V147578
  2481.  * DESCRIPTION   = Setup CDB for Enable PM Mode command               @V147578
  2482.  *       BuildCDB_PauseResume (NPUNITCB pUnitCB,                      @V147578
  2483.  *                             NPIORB_CDB FAR *pIORBOut)              @V147578
  2484.  *                                                                    @V147578
  2485.  * INPUT         = pUnitCB         - pointer to UnitCB                @V147578
  2486.  *                 pIORBOut        - returned pointer to IORB         @V147578
  2487.  *                                                                    @V147578
  2488.  * OUTPUT        = NONE                                               @V147578
  2489.  *                                                                    @V147578
  2490.  * RETURN-NORMAL =                                                    @V147578
  2491.  * RETURN-ERROR  =                                                    @V147578
  2492.  *                                                                    @V147578
  2493.  *********************************************************************@V147578*/
  2494.                                                                     /*@V147578*/
  2495. VOID BuildCDB_EnablePMMode (pUnitCB, pIORBOut)                      /*@V147578*/
  2496.                                                                     /*@V147578*/
  2497. NPUNITCB pUnitCB;                                                   /*@V147578*/
  2498. NPIORB_CDB FAR *pIORBOut;                                           /*@V147578*/
  2499.                                                                     /*@V147578*/
  2500. {                                                                   /*@V147578*/
  2501.    NPIORB_CDB pIORB;                                                /*@V147578*/
  2502.                                                                     /*@V147578*/
  2503.    struct CDB_EnablePMMode NEAR *pCDB;                              /*@V147578*/
  2504.                                                                     /*@V147578*/
  2505.   /*                                                                  @V147578
  2506.   ** Build a CDB passthru IORB                                        @V147578
  2507.   */                                                                /*@V147578*/
  2508.    BuildIORB_PassthruCDB(pUnitCB, 0, 0, (NPIORB_CDB FAR *) &pIORB); /*@V147578*/
  2509.                                                                     /*@V147578*/
  2510.    pIORB->apt.ControllerCmdLen = sizeof(struct CDB_EnablePMMode);   /*@V147578*/
  2511.                                                                     /*@V147578*/
  2512.    pCDB = (struct CDB_EnablePMMode * ) &(pIORB->CDB);               /*@V147578*/
  2513.    pCDB->OpCode = ATA_ENABLE_PM_MODE;                               /*@V147578*/
  2514.                                                                     /*@V147578*/
  2515.    *pIORBOut = pIORB;                                               /*@V147578*/
  2516. }                                                                   /*@V147578*/
  2517.  
  2518.