usrScsi.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:14k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* usrScsi.c - SCSI initialization */
  2. /* Copyright 1992-1996 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 02c,17nov96,jdi  doc: made sysScsiConfig() NOMANUAL, since it's in generic BSP.
  7. 02b,16sep96,dat  new macro SYS_SCSI_CONFIG, for rtn sysScsiConfig
  8. 02a,25jul96,jds  major modification of this file. Most of the previous code
  9.                  is commented out.
  10. 01f,09may96,jds  fixed modeData warning with SCSI_AUTO_CONFIG definition
  11. 01e,31aug94,ism  added a #ifdef to keep the RT11 file system from being
  12.  included just because SCSI is included. (SPR #3572)
  13. 01d,11jan93,ccc  removed 2nd parameter from call to scsiAutoConfig().
  14. 01c,24dec92,jdi  removed note about change of 4th param in scsiPhysDevCreate();
  15.  mentioned where usrScsiConfig() is found.
  16. 01b,24sep92,ccc  note about change of 4th parameter in scsiPhysDevCreate().
  17. 01a,18sep92,jcf  written.
  18. */
  19. /*
  20. DESCRIPTION
  21. This file is used to configure and initialize the VxWorks SCSI support.
  22. This file is included by usrConfig.c.
  23. There are many examples that are provided in this file which demonstrate
  24. use of routines to configure various SCSI devices. Such a configuration is
  25. user specific. Therefore, the examples provided in this file should be 
  26. used as a model and customized to the user requirements.
  27. MAKE NO CHANGES TO THIS FILE.
  28. All BSP specific code should be added to
  29. the sysLib.c file or a sysScsi.c file in the BSP directory.  Define the
  30. macro SYS_SCSI_CONFIG to generate the call to sysScsiConfig().
  31. See usrScsiConfig for more info on the SYS_SCSI_CONFIG macro.
  32. SEE ALSO: usrExtra.c
  33. NOMANUAL
  34. */
  35. #ifndef  __INCusrScsic
  36. #define  __INCusrScsic
  37. /*******************************************************************************
  38. *
  39. * usrScsiConfig - configure SCSI peripherals
  40. *
  41. * This code configures the SCSI disks and other peripherals on a SCSI
  42. * controller chain.
  43. *
  44. * The macro SCSI_AUTO_CONFIG will include code to scan all possible device/lun
  45. * id's and to configure a scsiPhysDev structure for each device found.  Of
  46. * course this doesn't include final configuration for disk partitions,
  47. * floppy configuration parameters, or tape system setup.  All of these actions
  48. * must be performed by user code, either through sysScsiConfig(),
  49. * the startup script, or by the application program.
  50. *
  51. * The user may customize this code on a per BSP basis using the SYS_SCSI_CONFIG
  52. * macro.  If defined, then this routine will call the routine sysScsiConfig().
  53. * That routine is to be provided by the BSP, either in sysLib.c or sysScsi.c.
  54. * If SYS_SCSI_CONFIG is not defined, then sysScsiConfig() will not be called
  55. * as part of this routine.
  56. *
  57. * An example sysScsiConfig() routine can be found in target/src/config/usrScsi.c.
  58. * The example code contains sample configurations for a hard disk, a floppy
  59. * disk and a tape unit.
  60. *
  61. * RETURNS: OK or ERROR.
  62. *
  63. * SEE ALSO:
  64. * .pG "I/O System, Local File Systems"
  65. */
  66. STATUS usrScsiConfig (void)
  67.     {
  68. #ifdef SCSI_AUTO_CONFIG
  69.     /* Optional auto-config of physical devices on SCSI bus */
  70.     taskDelay (sysClkRateGet () * 1); /* allow devices to reset */
  71.     printf ("Auto-configuring SCSI bus...nn");
  72.     scsiAutoConfig (pSysScsiCtrl);
  73.     scsiShow (pSysScsiCtrl);
  74.     printf ("n");
  75. #endif /* !SCSI_AUTO_CONFIG */
  76. #ifdef SYS_SCSI_CONFIG
  77.     /* Execute BSP configuration code, if any */
  78.     sysScsiConfig ();
  79. #endif
  80.     return (OK);
  81.     }
  82. #if FALSE /* EXAMPLE CODE ONLY */
  83. /* Data for example code */
  84. SCSI_PHYS_DEV * pSpd20;
  85. SCSI_PHYS_DEV * pSpd31;         /* SCSI_PHYS_DEV ptrs (suffix == ID, LUN) */
  86. SCSI_PHYS_DEV * pSpd40;
  87. BLK_DEV * pSbd0;
  88. BLK_DEV * pSbd1;
  89. BLK_DEV * pSbd2;          /* SCSI_BLK_DEV ptrs for Winchester */
  90. BLK_DEV * pSbdFloppy;     /* ptr to SCSI floppy block device */
  91. SEQ_DEV * pSd0;
  92. TAPE_CONFIG * pTapeConfig;
  93. /*******************************************************************************
  94. *
  95. * sysScsiConfig - Example SCSI device setup code
  96. *
  97. * This is an example of a SCSI routine, that could be added to the BSP sysLib.c
  98. * file to perform SCSI disk/tape setup.  Define SYS_SCSI_CONFIG to have
  99. * the kernel call this routine as part of usrScsiConfig().
  100. *
  101. * Most of the code found here is an example of how to declare a SCSI
  102. * peripheral configuration.  You must edit this routine to reflect the
  103. * actual configuration of your SCSI bus.  This example is found in
  104. * src/config/usrScsi.c.
  105. *
  106. * If you are just getting started, you can test your hardware configuration
  107. * by defining SCSI_AUTO_CONFIG in config.h, which will probe the bus and
  108. * display all devices found.  No device should have the same SCSI bus ID as
  109. * your VxWorks SCSI port (default = 7), or the same as any other device.
  110. * Check for proper bus termination.
  111. *
  112. * There are three configuration examples here that 
  113. * demostrate configuration of a SCSI hard disk (any type), an OMTI 3500 floppy 
  114. * disk, and a tape drive (any type).
  115. *
  116. * The hard disk is divided into two 32-Mbyte partitions and a third
  117. * partition with the remainder of the disk.  The first partition is initialized
  118. * as a dosFs device.  The second and third partitions are initialized as
  119. * rt11Fs devices, each with 256 directory entries.
  120. *
  121. * It is recommended that the first partition (BLK_DEV) on a block device be
  122. * a dosFs device, if the intention is eventually to boot VxWorks from the
  123. * device.  This will simplify the task considerably.
  124. *
  125. * The floppy, since it is a removable medium device, is allowed to have only a
  126. * single partition, and dosFs is the file system of choice for this device,
  127. * since it facilitates media compatibility with IBM PC machines.
  128. *
  129. * While the hard disk configuration is fairly straightforward, the floppy
  130. * setup in this example is a bit intricate.  Note that the
  131. * scsiPhysDevCreate() call is issued twice.  The first time is merely to get
  132. * a "handle" to pass to the scsiModeSelect() function, since the default
  133. * media type is sometimes inappropriate (in the case of generic
  134. * SCSI-to-floppy cards).  After the hardware is correctly configured, the
  135. * handle is discarded via the scsiPhysDevDelete() call, after which a
  136. * second scsiPhysDevCreate() call correctly configures the peripheral.
  137. * (Before the scsiModeSelect() call, the configuration information was
  138. * incorrect.) Also note that following the scsiBlkDevCreate() call, the
  139. * correct values for <sectorsPerTrack> and <nHeads> must be set via the
  140. * scsiBlkDevInit() call.  This is necessary for IBM PC compatibility.
  141. * Similarly, the tape configuration is also a little involved because 
  142. * certain device parameters need to turned off within VxWorks and the
  143. * tape fixed block size needs to be defined, assuming that the tape
  144. * supports fixed blocks.
  145. *
  146. * The last parameter to the dosFsDevInit() call is a pointer to a
  147. * DOS_VOL_CONFIG structure.  By specifying NULL, you are asking
  148. * dosFsDevInit() to read this information off the disk in the drive.  This
  149. * may fail if no disk is present or if the disk has no valid dosFs
  150. * directory.  Should this be the case, you can use the dosFsMkfs() command to
  151. * create a new directory on a disk.  This routine uses default parameters
  152. * (see dosFsLib) that may not be suitable for your application, in which
  153. * case you should use dosFsDevInit() with a pointer to a valid DOS_VOL_CONFIG
  154. * structure that you have created and initialized.  If dosFsDevInit() is
  155. * used, a diskInit() call should be made to write a new directory on the
  156. * disk, if the disk is blank or disposable.
  157. *
  158. * NOTE
  159. * The variable <pSbdFloppy> is global to allow the above calls to be
  160. * made from the VxWorks shell, i.e.:
  161. * .CS
  162. *     -> dosFsMkfs "/fd0/", pSbdFloppy
  163. * .CE
  164. * If a disk is new, use diskFormat() to format it.
  165. *
  166. * INTERNAL
  167. * The fourth parameter passed to scsiPhysDevCreate() is now
  168. * <reqSenseLength> (previously <selTimeout>).
  169. *
  170. * NOMANUAL
  171. */
  172. sysScsiConfig (void)
  173.     {
  174.     UINT which;
  175.     int  scsiId;
  176.     char modeData [4]; /* array for floppy MODE SELECT data */
  177.     SCSI_OPTIONS options;
  178.     /*
  179.      * NOTE: Either of the following global variables may be set or reset
  180.      * from the VxWorks shell. Under 5.0, they should NOT both be set at the
  181.      * same time, or output will be interleaved and hard to read!! They are
  182.      * intended as an aid to trouble-shooting SCSI problems.
  183.      */
  184.     scsiDebug = TRUE; /* enable SCSI debugging output */
  185.     scsiIntsDebug = TRUE; /* enable SCSI interrupt debugging output */
  186.     /*
  187.      * The following section of code provides sample configurations within
  188.      * VxWorks of SCSI peripheral devices and VxWorks file systems. It 
  189.      * should however be noted that the actual parameters provided to
  190.      * scsiPhysDevCreate(), scsiBlkDevCreate(), dosFsDevInit() etc., are
  191.      * highly dependent upon the user environment and should therefore be 
  192.      * modified accordingly.
  193.      */
  194.     /*
  195.      * HARD DRIVE CONFIGURATION
  196.      *
  197.      * In order to configure a hard disk and initialise both dosFs and rt11Fs
  198.      * file systems, the following initialisation code will serve as an
  199.      * example.
  200.      */
  201.     /* configure a SCSI hard disk at busId = 2, LUN = 0 */
  202.     if ((pSpd20 = scsiPhysDevCreate (pSysScsiCtrl, 2, 0, 0, NONE, 0, 0, 0))
  203.         == (SCSI_PHYS_DEV *) NULL)
  204. {
  205.         printErr ("usrScsiConfig: scsiPhysDevCreate failed.n",
  206. 0, 0, 0, 0, 0, 0);
  207. }
  208.     else
  209. {
  210. /* create block devices */
  211.         if (((pSbd0 = scsiBlkDevCreate (pSpd20, 0x10000, 0)) == NULL)       ||
  212.             ((pSbd1 = scsiBlkDevCreate (pSpd20, 0x10000, 0x10000)) == NULL) ||
  213.             ((pSbd2 = scsiBlkDevCreate (pSpd20, 0, 0x20000)) == NULL))
  214.     {
  215.          return (ERROR);
  216.     }
  217.         if ((dosFsDevInit  ("/sd0/", pSbd0, NULL) == NULL) )
  218.     {
  219.     return (ERROR);
  220.     }
  221. #ifdef INCLUDE_RT11FS
  222.     if ((rt11FsDevInit ("/sd1/", pSbd1, 0, 256, TRUE) == NULL) ||
  223.     (rt11FsDevInit ("/sd2/", pSbd2, 0, 256, TRUE) == NULL))
  224.     {
  225.     return (ERROR);
  226.     }
  227. #endif
  228. }
  229.     /* 
  230.      * FLOPPY DRIVE CONFIGURATION
  231.      * 
  232.      * In order to configure a removable media floppy drive with a
  233.      * dosFs file system, the following device specific code will serve
  234.      * as an example. Note that some arguments like mode parameters are
  235.      * highly devcie and vendor specific. Thus, the appropriate peripheral
  236.      * hardware manual should be consulted.
  237.      */
  238.     /* configure floppy at busId = 3, LUN = 1 */
  239.     if ((pSpd31 = scsiPhysDevCreate (pSysScsiCtrl, 3, 1, 0, NONE, 0, 0, 0))
  240. == (SCSI_PHYS_DEV *) NULL)
  241. {
  242.         printErr ("usrScsiConfig: scsiPhysDevCreate failed.n");
  243. return (ERROR);
  244. }
  245.     /* 
  246.      * Zero modeData array, then set byte 1 to "medium code" (0x1b). NOTE:
  247.      * MODE SELECT data is highly device-specific. If your device requires
  248.      * configuration via MODE SELECT, please consult the device's Programmer's
  249.      * Reference for the relevant data format.
  250.      */
  251.     bzero (modeData, sizeof (modeData));
  252.     modeData [1] = 0x1b;
  253.     /* issue the MODE SELECT command to correctly configure floppy controller */
  254.     scsiModeSelect (pSpd31, 1, 0, modeData, sizeof (modeData));
  255.     /*
  256.      * delete and re-create the SCSI_PHYS_DEV so that INQUIRY will return the
  257.      * new device parameters, i.e., correct number of blocks
  258.      */
  259.     scsiPhysDevDelete (pSpd31);
  260.     if ((pSpd31 = scsiPhysDevCreate (pSysScsiCtrl, 3, 1, 0, NONE, 0, 0, 0))
  261. == (SCSI_PHYS_DEV *) NULL)
  262. {
  263.         printErr ("usrScsiConfig: scsiPhysDevCreate failed.n");
  264. return (ERROR);
  265. }
  266.     if ((pSbdFloppy = scsiBlkDevCreate (pSpd31, 0, 0)) == NULL)
  267. {
  268.         printErr ("usrScsiConfig: scsiBlkDevCreate failed.n");
  269. return (ERROR);
  270. }
  271.     /*
  272.      * Fill in the <blksPerTrack> (blocks (or sectors) per track) and <nHeads>
  273.      * (number of heads) BLK_DEV fields, since it is impossible to ascertain
  274.      * this information from the SCSI adapter card. This is important for
  275.      * PC compatibility, primarily.
  276.      */
  277.     scsiBlkDevInit ((SCSI_BLK_DEV *) pSbdFloppy, 15, 2);
  278.     /* Initialize as a dosFs device */
  279.     /*
  280.      * NOTE: pSbdFloppy is declared globally in case the following call
  281.      * fails, in which case dosFsMkfs or dosFsDevInit can be
  282.      * called (from the shell) with pSbdFloppy as an argument
  283.      * (assuming pSbdFloppy != NULL)
  284.      */
  285.     if (dosFsDevInit ("/fd0/", pSbdFloppy, NULL) == NULL)
  286. {
  287.         printErr ("usrScsiConfig: dosFsDevInit failed.n");
  288. return (ERROR);
  289. }
  290.     /* 
  291.      * TAPE DRIVE CONFIGURATION
  292.      * 
  293.      * In order to configure a sequential access tape device and a tapeFs
  294.      * file system, the following code will serve as an example. Note that
  295.      * sequential access and tapeFs support are only available via SCSI-2.
  296.      * To make sure that SCSI-2 is being used, check for the INCLUDE_SCSI2
  297.      * macro definition in the BSP.
  298.      *
  299.      * The tape device does not support synchronous data transfers
  300.      * or wide data transfers. Therefore, turn off the automatic configuration
  301.      * of these features within VxWorks.
  302.      */
  303.     scsiId = 4;
  304.     which = SCSI_SET_OPT_XFER_PARAMS | SCSI_SET_OPT_WIDE_PARAMS;
  305.     options.maxOffset = SCSI_SYNC_XFER_ASYNC_OFFSET;
  306.     options.minPeriod = SCSI_SYNC_XFER_ASYNC_PERIOD;
  307.     options.xferWidth = SCSI_WIDE_XFER_SIZE_NARROW;
  308.     if (scsiTargetOptionsSet (pSysScsiCtrl, scsiId, &options, which) == ERROR)
  309.         {
  310.         printf ("Could not set target option parametersn");
  311.         return (ERROR);
  312.         }
  313.     /* create SCSI physical device and sequential device */
  314.     if ((pSpd40 = scsiPhysDevCreate (pSysScsiCtrl, scsiId, 0,0,NONE,0,0,0)) 
  315.             == NULL)
  316.         {
  317.         printErr ("scsiPhysDevCreate failed.n");
  318.         return (ERROR);
  319.         }
  320.     if ((pSd0 = scsiSeqDevCreate (pSpd40)) == NULL)
  321.         {
  322.         printErr ("scsiSeqDevCreate failed.n");
  323.         return (ERROR);
  324.         }
  325.     /* configure a fixed block and rewind, tape file system */
  326.     pTapeConfig = (TAPE_CONFIG *) calloc (sizeof(TAPE_CONFIG),1);
  327.     pTapeConfig->rewind = TRUE; /* rewind device */
  328.     pTapeConfig->blkSize = 512; /* fixed 512 byte block */ 
  329.     if (tapeFsDevInit ("/tape1", pSd0, pTapeConfig) == NULL)
  330. {
  331. printErr ("tapeFsDevInit failed.n");
  332. return (ERROR);
  333. }
  334.     return (OK);
  335.     }
  336. #endif /*FALSE*/
  337. #endif /* __INCusrScsic */