home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / amiga / programm / 12562 < prev    next >
Encoding:
Text File  |  1992-08-21  |  5.2 KB  |  224 lines

  1. Path: sparky!uunet!dtix!darwin.sura.net!jvnc.net!netnews.upenn.edu!dsinc!bagate!cbmvax!jesup
  2. From: jesup@cbmvax.commodore.com (Randell Jesup)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Sending SCSI Direct commands on an A3000
  5. Message-ID: <34573@cbmvax.commodore.com>
  6. Date: 22 Aug 92 00:54:04 GMT
  7. References: <2p_nf!-.harp@netcom.com>
  8. Reply-To: jesup@cbmvax.commodore.com (Randell Jesup)
  9. Organization: Commodore, West Chester, PA
  10. Lines: 212
  11.  
  12. harp@netcom.com (Gregory O. Harp) writes:
  13. >
  14. >I need some pointers on sending SCSI Direct commands to a device
  15. >plugged into my A3000.
  16. >
  17. >First of all, if someone already has a program that allows the user to
  18. >send various commands I'd appreciate it if they would tell me how I
  19.  
  20.     This should get you started.  One of these days I should get around to
  21. releasing scsidirect.c which uses these routines to allow you to play around
  22. with innumerable scsi commands (it's built around the same engine as the
  23. "dos_calls" program).
  24.  
  25.     Randell
  26.  
  27. /* scsi.c */
  28.  
  29. #include <exec/types.h>
  30. #include <exec/memory.h>
  31. #include <exec/io.h>
  32. #include <devices/trackdisk.h>
  33. #include <devices/scsidisk.h>
  34.  
  35. #include <clib/exec_protos.h>
  36. #include <clib/alib_protos.h>
  37.  
  38. #include <stdio.h>
  39.  
  40. #include "scsi.h"
  41.  
  42. #define SAME 0
  43.  
  44. #define AllocNew(t)    ((struct t *) AllocMem(sizeof(struct t),MEMF_CLEAR))
  45.  
  46. extern char *device;
  47. extern int  unit;
  48.  
  49. struct IOStdReq *ior = NULL;
  50. struct MsgPort *port = NULL;
  51. int opened=FALSE;
  52.  
  53. void closedevice(void);
  54.  
  55. void closedevice ()
  56. {
  57.     if (opened)
  58.         CloseDevice(ior);
  59.     if (ior)
  60.         DeleteStdIO(ior);
  61.     if (port)
  62.         DeletePort(port);
  63.  
  64.     opened = 0;
  65.     ior = NULL;
  66.     port = NULL;
  67. }
  68.  
  69. int
  70. opendevice (char *device, int unit)
  71. {
  72.     int i = 0;
  73.  
  74.     if (!(port = CreatePort(0L,0L)))
  75.         goto cleanup;
  76.     if (!(ior = CreateStdIO(port)))
  77.         goto cleanup;
  78.  
  79.     printf("Opening device %s, unit %ld\n",device,unit);
  80.  
  81.     if (i = OpenDevice(device,unit,
  82.                (struct IORequest *) ior,0L))
  83.     {
  84.         printf("error %ld on open\n",i);
  85.         goto cleanup;
  86.     }
  87.     return 0;
  88.  
  89. cleanup:
  90.     closedevice();
  91.     return i;
  92. }
  93.  
  94. /* do any SCSI command using the supplied iorequest, ret 0=success or error */
  95. /* data must be word aligned and dmaable */
  96. /* ditto for command */
  97.  
  98. UBYTE  sensedata[255];
  99. struct SCSICmd cmdblk;
  100.  
  101. int DoSCSI (struct IOStdReq *ior,
  102.            UWORD *command,
  103.            ULONG clen,
  104.            UWORD *data,
  105.            ULONG dlen,
  106.            ULONG flags);
  107.  
  108. void SendSCSI (struct IOStdReq *ior,
  109.              UWORD *command,
  110.              ULONG clen,
  111.              UWORD *data,
  112.              ULONG dlen,
  113.              ULONG flags);
  114.  
  115. int
  116. DoSCSI (struct IOStdReq *ior,
  117.            UWORD *command,
  118.            ULONG clen,
  119.            UWORD *data,
  120.            ULONG dlen,
  121.            ULONG flags)/* only a ubyte used for actual xfer, rest for this rtn */
  122. {
  123.  
  124.     SendSCSI(ior,command,clen,data,dlen,flags);
  125.     WaitIO((struct IORequest *) ior);
  126.  
  127. #ifdef TEST_SCSI
  128. printf("direct scsi return error %d, status %d\n",ior->io_Error,cmdblk.scsi_Status);
  129. if (cmdblk.scsi_SenseActual)
  130. {
  131. int i;
  132. printf("Sense data (length %d) = 0x",cmdblk.scsi_SenseActual);
  133. for(i = 0; i < cmdblk.scsi_SenseActual; i++)
  134. printf("%02.2x",sensedata[i]);
  135. printf("\n");
  136. }
  137. #endif
  138.     if (cmdblk.scsi_Status)
  139.         return (int) cmdblk.scsi_Status;
  140.  
  141.     return (int) ior->io_Error;    /* see scsidisk.h for errors */
  142. }
  143.  
  144. void
  145. SendSCSI (struct IOStdReq *ior,
  146.              UWORD *command,
  147.              ULONG clen,
  148.              UWORD *data,
  149.              ULONG dlen,
  150.              ULONG flags)/* only a ubyte used for actual xfer, rest for this rtn */
  151. {
  152.     /* first set up ior */
  153.     ior->io_Data    = (APTR) &cmdblk;
  154.     ior->io_Length  = sizeof(cmdblk);
  155.     ior->io_Actual  = ior->io_Offset = 0;
  156.     ior->io_Command = HD_SCSICMD;
  157.  
  158.     /* now set up cmdblk */
  159.     cmdblk.scsi_Data      = data;
  160.     cmdblk.scsi_Length    = dlen;
  161.     cmdblk.scsi_Actual    = 0;
  162.     cmdblk.scsi_Command   = (UBYTE *) command;
  163.     cmdblk.scsi_CmdLength = clen;
  164.     cmdblk.scsi_CmdActual = 0;
  165.     cmdblk.scsi_Flags     = flags & 0xff; /* probably not needed */
  166.     cmdblk.scsi_Status    = 0;
  167.     cmdblk.scsi_SenseData = sensedata;
  168.     cmdblk.scsi_SenseLength = sizeof(sensedata);
  169.     cmdblk.scsi_SenseActual = 0;
  170. /*    cmdblk.scsi_NextLinked  = NULL;*/
  171.  
  172.     SendIO((struct IORequest *) ior);
  173. }
  174.  
  175.  
  176. /* scsi.h */
  177.  
  178. #define S_TEST_UNIT_READY    0x00
  179. #define S_REZERO_UNIT        0x01
  180. #define S_REQUEST_SENSE        0x03
  181. #define S_FORMAT_UNIT        0x04
  182. #define S_REASSIGN_BLOCKS    0x07
  183. #define S_READ            0x08
  184. #define S_WRITE            0x0a
  185. #define S_SEEK            0x0b
  186. #define S_INQUIRY        0x12
  187. #define S_MODE_SELECT        0x15
  188. #define S_RESERVE        0x16
  189. #define S_RELEASE        0x17
  190. #define S_COPY            0x18
  191. #define S_MODE_SENSE        0x1a
  192. #define S_START_STOP_UNIT    0x1b
  193. #define S_PREVENT_ALLOW_REMOVAL    0x1e
  194. #define S_READ_CAPACITY     0x25
  195. #define S_READ10        0x28
  196. #define S_WRITE10        0x2a
  197. #define S_WRITE_VERIFY        0x2e
  198. #define S_VERIFY        0x2F
  199. #define S_PREFETCH        0x34
  200. #define S_SYNCHRONIZE_CACHE    0x35
  201. #define    S_LOCK_UNLOCK_CACHE    0x36
  202. #define S_READ_DEFECT_DATA    0x37
  203. #define S_WRITE_BUFFER        0x3b
  204. #define S_READ_BUFFER        0x3c
  205. #define S_MODE_SELECT_10    0x55
  206. #define S_MODE_SENSE_10        0x5a
  207.  
  208. /* sense codes */
  209. #define CHECK_CONDITION        0x02
  210.  
  211. /* sense keys */
  212. #define RECOVERED_ERROR        0x01
  213. #define MEDIUM_ERROR        0x03
  214. #define HARDWARE_ERROR        0x04
  215. #define ILLEGAL_REQUEST        0x05
  216.  
  217. -- 
  218. "Rev on the redline, you're on your own; seems like a lifetime, but soon it's
  219.  gone..."  Foreigner
  220. -
  221. Randell Jesup, Jack-of-quite-a-few-trades, Commodore Engineering.
  222. {uunet|rutgers}!cbmvax!jesup, jesup@cbmvax.cbm.commodore.com  BIX: rjesup  
  223. Disclaimer: Nothing I say is anything other than my personal opinion.
  224.