home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / DASD / OS2SCSI / SCINIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-14  |  11.6 KB  |  270 lines

  1. /*DDK*************************************************************************/
  2. /*                                                                           */
  3. /* COPYRIGHT    Copyright (C) 1995 IBM Corporation                           */
  4. /*                                                                           */
  5. /*    The following IBM OS/2 WARP source code is provided to you solely for  */
  6. /*    the purpose of assisting you in your development of OS/2 WARP device   */
  7. /*    drivers. You may use this code in accordance with the IBM License      */
  8. /*    Agreement provided in the IBM Device Driver Source Kit for OS/2. This  */
  9. /*    Copyright statement may not be removed.                                */
  10. /*                                                                           */
  11. /*****************************************************************************/
  12. /*static char *SCCSID = "src/dev/dasd/os2scsi/scinit.c, scsy, ddk_subset, b_bdd.032 93/03/19";*/
  13. /**************************************************************************
  14.  *
  15.  * SOURCE FILE NAME = SCINIT.C
  16.  *
  17.  * DESCRIPTIVE NAME = OS2SCSI.DMD - OS/2 SCSI.SYS Emulation
  18.  *
  19.  *
  20.  *
  21.  * VERSION = V2.0
  22.  *
  23.  * DATE
  24.  *
  25.  * DESCRIPTION : Initialization routines
  26.  *
  27.  *
  28.  *
  29. */
  30.  
  31. #define INCL_NOBASEAPI
  32. #define INCL_NOPMAPI
  33. #include "os2.h"
  34. #include "strat2.h"
  35. #include "reqpkt.h"
  36. #include "devclass.h"
  37. #include "dhcalls.h"
  38. #include "scb.h"
  39. #include "scsi.h"
  40. #include "iorb.h"
  41. #include "scscsi.h"
  42. #include "scgen.h"
  43. #include "scproto.h"
  44.  
  45.  
  46.  
  47. extern    UNITCB         UnitCB[1];            /* UnitCB allocated here       */
  48. extern    PFN            Device_Help;          /* far ptr to devhelp function */
  49. extern    USHORT         NumDrivers;           /* num of adapter drivers      */
  50. extern    USHORT         NumUnitCBs;           /* num of unit control blocks  */
  51. extern    PVOID          pDataSeg;             /* Our data segment pointer    */
  52. extern    ULONG          plDataSeg;            /* Our data segment pointer    */
  53. extern    UCHAR          Pool[];
  54.  
  55. #define   ERR_FNCALL     ((USHORT) 0xFFFF)     /* Indicates error in fn call. */
  56.  
  57. /********************** START OF SPECIFICATIONS *****************************
  58. *                                                                           *
  59. * SUBROUTINE NAME:  DriveInit                                               *
  60. *                                                                           *
  61. * DESCRIPTIVE NAME: Device Driver Initialize routine                        *
  62. *                                                                           *
  63. * FUNCTION:  This routine sets up unit control block and sets output        *
  64. *            information required in request packet.                        *
  65. *                                                                           *
  66. * ENTRY POINT:      DriveInit                                               *
  67. *                                                                           *
  68. * LINKAGE:          Call Near                                               *
  69. *                                                                           *
  70. * INPUT:            Pointer to Init Reuqest Packet                          *
  71. *                                                                           *
  72. * EXIT-NORMAL:      Status code in request packet                           *
  73. *                                                                           *
  74. * EXIT-ERROR:       Status code in request packet                           *
  75. *                                                                           *
  76. *********************** END OF SPECIFICATIONS *******************************/
  77.  
  78. USHORT far f_DriveInit(pRP)
  79. PRPINITIN  pRP;
  80. {
  81.   USHORT     rc;
  82.   NPBYTE     pNextFreeCB;                 /* ptr to next free control blk     */
  83.   PRPINITOUT pRPO = (PRPINITOUT) pRP;     /* Output for Init RP               */
  84.  
  85.  
  86.   Device_Help = pRP->DevHlpEP;            /* Save ptr to devhelp function     */
  87.   pDataSeg = (PVOID) &pDataSeg;           /* Set up pointer to data segment   */
  88.   OFFSETOF(pDataSeg) = 0;
  89.  
  90.   rc = DevHelp_VirtToLin((USHORT) (SELECTOROF(pDataSeg)),
  91.                          (ULONG) (OFFSETOF(pDataSeg)),
  92.                          (PLIN) &plDataSeg);  /* Save lin addr of data seg    */
  93.  
  94.  
  95.   NumUnitCBs = Build_UnitCBs();           /* Build unit control blocks        */
  96.   if ((NumUnitCBs!=0) && (NumUnitCBs!=ERR_FNCALL))
  97.   {                                       /* If there's units to control.     */
  98.  
  99.      pRPO->Unit     = 0;
  100.      pRPO->CodeEnd  = (USHORT)f_DriveInit;/* Set length of code segment       */
  101.  
  102.      pRPO->DataEnd  = SetAdditionalData();
  103.      pRPO->BPBArray = 0;                  /* Set address of BPB ptr array     */
  104.  
  105.      return(STDON);                       /* Set status                       */
  106.   }
  107.   else                                    /* no media or Init failure         */
  108.   {
  109.      pRPO->Unit     = 0;                  /* Set zero for the number of unit  */
  110.      pRPO->CodeEnd  = 0;                  /* Set length of code segment       */
  111.      pRPO->DataEnd  = 0;                  /* Set length of data segment       */
  112.      pRPO->BPBArray = 0;                  /* Set address of BPB ptr array     */
  113.  
  114.      if (NumUnitCBs == 0)                 /* Quiet fail if no units           */
  115.         return( 0x8115 /*ERROR_I24_QUIET_INIT_FAIL*/ );
  116.      else
  117.         return(STDON + STERR);            /* Noisy fail on program exception. */
  118.   }
  119. }
  120.  
  121.  
  122. /********************** START OF SPECIFICATIONS *****************************
  123. *                                                                           *
  124. * SUBROUTINE NAME:  Build_UnitCBs                                           *
  125. *                                                                           *
  126. * DESCRIPTIVE NAME: Build Unit Control Blocks  (UnitCBs)                    *
  127. *                                                                           *
  128. * FUNCTION:  This routine issues DevHelp comand to get each device driver's *
  129. *            entry point and IORB device table request for each driver to   *
  130. *            get information about the device.                              *
  131. *            Unit Control Block are created by these information.           *
  132. *                                                                           *
  133. * ENTRY POINT:      Build_UnitCBs                                           *
  134. *                                                                           *
  135. * LINKAGE:          Call Near                                               *
  136. *                                                                           *
  137. * INPUT:                                                                    *
  138. *                                                                           *
  139. * EXIT-NORMAL:      UnitCBs will be filled up for each physical unit.       *
  140. *                   NumUnitCBs = Number of UnitCBs built                    *
  141. *                                                                           *
  142. * EXIT-ERROR:       0                   => No units to support.             *
  143. *                   ERR_FNCALL (0xFFFF) => DevHelp failure.                 *
  144. *                                                                           *
  145. *********************** END OF SPECIFICATIONS *******************************/
  146.  
  147. unsigned near Build_UnitCBs()
  148.  
  149. {
  150.   struct DevClassTableStruc far *pDriverTable;  /*  ptr to registered ADD EPs */
  151.  
  152.   NPIORB                npIORB;          /* far ptr to IORB                   */
  153.   NPIORB_CONFIGURATION  npIORBDT;        /* far ptr to IORB                   */
  154.  
  155.   NPADAPTERINFO         npAdapterInfo;   /* near ptr to AdapterInfo           */
  156.  
  157.   void                  (far *DriverEP)(); /* Driver entry point              */
  158.  
  159.   NPINITDATA            npInitData;      /* Pointer to init data              */
  160.  
  161.   NPUCB                 npUCB;
  162.  
  163.   NPQELE                npQEle;
  164.  
  165.   USHORT                rc;
  166.   USHORT                iAdapter;
  167.   USHORT                iDriver;
  168.   USHORT                UnitIndex;
  169.   USHORT                iUnit = 0;
  170.   USHORT                i;
  171.  
  172.   /*--------------------------------------------------------------------*/
  173.   /* Get the adapter device tables for each adapter driver and create   */
  174.   /* the unit control blocks (UnitCBs) from the returned tables.        */
  175.   /*--------------------------------------------------------------------*/
  176.  
  177.   /*--------------------------------------*/
  178.   /* Position INIT DATA after UNITCB pool */
  179.   /*--------------------------------------*/
  180.  
  181.   npInitData = (NPINITDATA)((NPBYTE)Pool + (sizeof(UNITCB) * MAX_SCSI_DEVICES));
  182.  
  183.   npUCB      = UnitCB;
  184.  
  185.   rc = DevHelp_GetDOSVar((USHORT) DHGETDOSV_DEVICECLASSTABLE, 1,
  186.                          (PPVOID) &pDriverTable);
  187.  
  188.   if (!rc)
  189.   {
  190.      /*----------------------------------------------------*/
  191.      /* For each .ADD registered in the DEVICE CLASS TABLE */
  192.      /*----------------------------------------------------*/
  193.  
  194.      NumDrivers = pDriverTable->DCCount;
  195.      for (iDriver= 0; iDriver < NumDrivers; iDriver++)
  196.      {
  197.         npIORBDT = (NPIORB_CONFIGURATION)(npInitData->ScratchIORB);
  198.         npIORB   = (NPIORB) npIORBDT;
  199.         CLEAR_IORB_BUFF;
  200.  
  201.         npIORB->Length                 = sizeof(IORB_CONFIGURATION);
  202.         npIORB->CommandCode            = IOCC_CONFIGURATION;
  203.         npIORB->CommandModifier        = IOCM_GET_DEVICE_TABLE;
  204.  
  205.         npIORBDT->pDeviceTable         = (PDEVICETABLE)(npInitData->ScratchBuffer);
  206.         npIORBDT->DeviceTableLen       = sizeof(npInitData->ScratchBuffer);
  207.  
  208.         OFFSETOF(DriverEP)   = pDriverTable->DCTableEntries[iDriver].DCOffset;
  209.         SELECTOROF(DriverEP) = pDriverTable->DCTableEntries[iDriver].DCSelector;
  210.  
  211.         (*DriverEP)((PIORB_CONFIGURATION)npIORB);
  212.  
  213.         if (npIORB->Status & IORB_ERROR)
  214.           continue;
  215.  
  216.         /*----------------------------------------*/
  217.         /* For each adapter supported by this ADD */
  218.         /*----------------------------------------*/
  219.  
  220.         for (iAdapter = 0;
  221.              iAdapter < npIORBDT->pDeviceTable->TotalAdapters;
  222.              iAdapter++                                       )
  223.         {
  224.            npAdapterInfo = npIORBDT->pDeviceTable->pAdapter[iAdapter];
  225.  
  226.  
  227.            /*------------------------------*/
  228.            /* For each Unit on the adapter */
  229.            /*------------------------------*/
  230.  
  231.            for (UnitIndex = 0;
  232.                 UnitIndex < npAdapterInfo->AdapterUnits;
  233.                 UnitIndex++                              )
  234.            {
  235.               if (iUnit > MAX_SCSI_DEVICES )
  236.                 continue;
  237.  
  238.               if (!(npAdapterInfo->UnitInfo[UnitIndex].UnitFlags & UF_NOSCSI_SUPT))
  239.               {
  240.                  npUCB->UnitInfo          = npAdapterInfo->UnitInfo[UnitIndex];
  241.                  npUCB->AdapterDriverEP   = DriverEP;
  242.                  npUCB->Timeout           = DEFAULT_TIMEOUT;
  243.                  npUCB->Index             = iUnit;
  244.  
  245.                  if (npAdapterInfo->AdapterFlags & AF_IBM_SCB)
  246.                     npUCB->IntUnitFlags    |= IUF_IBM_SCB;
  247.  
  248.                  npQEle = npUCB->TimeOutQFree = &npUCB->TimeOutQ[0];
  249.  
  250.                  for (i = 0; i < MAX_TIMEOUT_ENTRIES-1; i++, npQEle++ )
  251.                  {
  252.                     npQEle->Next = npQEle+1;
  253.                  }
  254.  
  255.                  iUnit++;                /* Increment Index of UnitCB */
  256.                  npUCB++;
  257.               }
  258.  
  259.            }  /* end unit loop */
  260.         }  /* end adapter loop */
  261.      }  /* end driver loop */
  262.  
  263.                                          /* => just support MAX */
  264.      return(iUnit);
  265.   }
  266.   else
  267.      return(ERR_FNCALL);
  268. }
  269.  
  270.