home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v1.zip / DDKX86 / H / STRAT2.H < prev    next >
Text File  |  1995-04-14  |  19KB  |  448 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 = "@(#)strat2.h    6.3 91/04/29";*/
  13. /*static char *SCCSID = "@(#)strat2.h    6.3 91/04/29";*/
  14. /****************************************************************************\
  15. *                                                                            *
  16. * Strat2.inc - definitions for HPFS strategy-2 request list support 10/3/89  *
  17. *                                                                            *
  18. \****************************************************************************/
  19.  
  20.  
  21. /*
  22.  ***************************
  23.  ** Request List Structure *
  24.  ***************************
  25.  *
  26.  * Request Lists have the following format:
  27.  *
  28.  *       ==================================
  29.  *       | BYTE 16   Request List Header  |
  30.  *       | -------------------------------|
  31.  *       | ARRAY     Requests             |
  32.  *       ==================================
  33.  *
  34.  * Where the Request List Header has the following structure:
  35.  */
  36. typedef struct _Req_List_Header { /* RLH */
  37.         ULONG  Count;             /* number of requests in Req List        */
  38.         PVOID  Notify_Address;    /* 16:16 address of notification routine */
  39.         USHORT Request_Control;   /* bitfield of flags defined below       */
  40.         BYTE   Block_Dev_Unit;    /* logical unit number of volume         */
  41.         BYTE   Lst_Status;        /* overall status for Req List           */
  42.         ULONG  y_Done_Count;      /* count of request completed (internal) */
  43.         ULONG  y_PhysAddr;        /* 32 bit phys addr of RLH    (internal) */
  44. } Req_List_Header;
  45.  
  46. /*
  47.  * this redefines some fields for use by DISK01
  48. */
  49. typedef struct _Req_List_Header_1 { /* RLH */
  50.         USHORT Short_Count;     /* number of requests in Req List           */
  51.         USHORT Dummy1;          /* reserved must be zero                    */
  52.         PVOID  Dummy2;          /* 16:16 address of notification routine    */
  53.         USHORT Dummy3;          /* bitfield of flags defined below          */
  54.         BYTE   Dummy4;          /* logical unit number of volume            */
  55.         BYTE   Dummy5;          /* overall status for Req List              */
  56.         USHORT Count_Done;      /* count of request completed (internal)    */
  57.         USHORT Queued;          /* number of RH that caused queuing (int)   */
  58.         USHORT Next_RH;         /* address of next RH to process (internal) */
  59.         USHORT Current_RH;      /* address of RH currently in process (int) */
  60. } Req_List_Header_1;
  61.  
  62. /*
  63.  * List Request Control bit masks  (RLH_Request_Control)
  64.  */
  65. #define RLH_Req_From_PB 0x0001 /* Request came directly from Pinball */
  66. #define RLH_Single_Req  0x0002 /* Single request in list */
  67. #define RLH_Exe_Req_Seq 0x0004 /* Requests to be executed in sequence */
  68. #define RLH_Abort_Err   0x0008 /* Abort on error */
  69. #define RLH_Notify_Err  0x0010 /* Notify immediately on error */
  70. #define RLH_Notify_Done 0x0020 /* Notify on completion */
  71.  
  72. /*
  73.  * List Status bit masks (RLH_Lst_Status)
  74.  *       - low nibble indicates completion status of reqs
  75.  */
  76. #define RLH_No_Req_Queued       0x00 /* No requests queued */
  77. #define RLH_Req_Not_Queued      0x01 /* Some, but not all, requests queued */
  78. #define RLH_All_Req_Queued      0x02 /* All requests queued */
  79. #define RLH_All_Req_Done        0x04 /* All requests done or aborted */
  80. #define RLH_Seq_In_Process      0x08 /* Requests being processed in sequence */
  81. #define RLH_Abort_pendings      0x08 /* Abort list processing in progress */
  82.  
  83. /*
  84.  * List Status bit masks (RLH_Lst_Status)
  85.  *       - high nibble indicates error status of reqs in list
  86.  */
  87. #define RLH_No_Error            0x00 /* No error */
  88. #define RLH_Rec_Error           0x10 /* Recoverable error has occurred */
  89. #define RLH_Unrec_Error         0x20 /* Unrecoverable error has occurred */
  90. #define RLH_Unrec_Error_Retry   0x30 /* Unrecoverable error after retry */
  91.  
  92. /*
  93.  * Individual requests within the request list have the following format:
  94.  *
  95.  *       ===============================
  96.  *       | BYTE 32   Request Header    |
  97.  *       | ----------------------------|
  98.  *       | BYTE      Command-Specific  |
  99.  *       ===============================
  100.  *
  101.  * Where the Request Header has the following structure:
  102.  */
  103. typedef struct _Req_Header { /* RH */
  104.         USHORT Length;          /* offset of the next request           */
  105.         BYTE   Old_Command;     /* reserved, always 1Ch, same offset    */
  106.                                 /* as command code in OS/2 req header   */
  107.         BYTE   Command_Code;    /* Pinball command request code         */
  108.         ULONG  Head_Offset;     /* offset from begin of Req List Header */
  109.         BYTE   Req_Control;     /* control flags bits defined below     */
  110.         BYTE   Priority;        /* Priority of request defined below    */
  111.         BYTE   Status;          /* status bitfield defined below        */
  112.         BYTE   Error_Code;      /* Pinball errors defined below         */
  113.         PVOID  Notify_Address;  /* 16:16 address called when done       */
  114.         ULONG  Hint_Pointer;    /* 16:16 pointer to req packet in list  */
  115.         ULONG  Waiting;         /* Waiting queue link pointer (internal)*/
  116.         ULONG  FT_Orig_Pkt;     /* 32b ptr to original request(internal)*/
  117.         ULONG  Physical;        /* 32 bit phys addr of RLH    (internal)*/
  118. } Req_Header;
  119.  
  120. /* ASM
  121. RHL_Waiting   equ   RH_Waiting + size Req_List_Header
  122. RH_pIORB      equ   word ptr RH_Physical ; pointer back to IORB on queue
  123. */
  124.  
  125. /*
  126.  * Pinball Length flag
  127.  */
  128. #define RH_LAST_REQ     0xFFFF  /* value of Length if last req in list */
  129.  
  130.  
  131. /*
  132.  * Pinball Command Prefix  (RH_Old_Command)
  133.  */
  134. #define PB_REQ_LIST     0x1C /* pinball request list */
  135.  
  136. /*
  137.  * Pinball Command Codes (RH_Command_Code)
  138.  */
  139. #define PB_READ_X     0x1E /* pinball read */
  140. #define PB_WRITE_X    0x1F /* pinball write */
  141. #define PB_WRITEV_X   0x20 /* pinball write/verify */
  142. #define PB_PREFETCH_X 0x21 /* pinball prefetch read */
  143.  
  144. /*
  145.  * Pinball Status (RH_Status) - low nibble
  146.  */
  147. #define RH_NOT_QUEUED   0x00 /* not yet queued */
  148. #define RH_QUEUED       0x01 /* queued and waiting */
  149. #define RH_PROCESSING   0x02 /* in process */
  150. #define RH_DONE         0x04 /* done */
  151.  
  152. /*
  153.  * Pinball Status (RH_Status) - high nibble
  154.  */
  155. #define RH_NO_ERROR             0x00 /* No error                            */
  156. #define RH_RECOV_ERROR          0x10 /* A recoverable error has occurred    */
  157. #define RH_UNREC_ERROR          0x20 /* An unrecoverable error has occurred */
  158. #define RH_UNREC_ERROR_RETRY    0x30 /* An unrecoverable error with retry   */
  159. #define RH_ABORTED              0x40 /* The request was aborted             */
  160.  
  161. /*
  162.  * Pinball Error Codes - see error.inc, device driver error codes
  163.  *
  164.  * Pinball Request Control bit masks (RH_Req_Control)
  165.  */
  166. #define RH_PB_REQUEST       0x01 /* Request came directly from Pinball */
  167. #define RH_NOTIFY_ERROR     0x10 /* Notify on Error */
  168. #define RH_NOTIFY_DONE      0x20 /* Notify on completion */
  169.  
  170. /*
  171.  * Priorities
  172.  */
  173. #define PRIO_PREFETCH           0x00    /* Prefetch requests. */
  174. #define PRIO_LAZY_WRITE         0x01    /* Lazy writer. */
  175. #define PRIO_PAGER_READ_AHEAD   0x02    /* Read ahead, low priority pager I/O */
  176. #define PRIO_BACKGROUND_USER    0x04    /* Background synchronous user I/O. */
  177. #define PRIO_FOREGROUND_USER    0x08    /* Foreground synchronous user I/O. */
  178. #define PRIO_PAGER_HIGH         0x10    /* High priority pager I/O. */
  179. #define PRIO_URGENT             0x80    /* Urgent (e.g. power fail). */
  180.  
  181. /*
  182.  * Pinball Read/Write request list entry
  183.  */
  184. typedef struct _PB_Read_Write { /* PB */
  185.         Req_Header  RqHdr;      /* request header */
  186.         ULONG  Start_Block;     /* start block for data transfer */
  187.         ULONG  Block_Count;     /* number of blocks to transfer */
  188.         ULONG  Blocks_Xferred;  /* number of blocks transferred */
  189.         USHORT RW_Flags;        /* command specific control flags */
  190.         USHORT SG_Desc_Count;   /* number of SG descriptors */
  191.         USHORT SG_Desc_Count2;  /* number of SG descriptors   (internal) */
  192.         USHORT reserved;        /* reserved for dd alignment  (internal) */
  193. } PB_Read_Write;
  194.  
  195. /*
  196.  * Pinball Read/Write flags (PB_RW_Flags)
  197.  */
  198. #define RW_Cache_WriteThru  0x0001 /* Cache write thru */
  199. #define RW_Cache_Req        0x0002 /* Cache the request */
  200.  
  201.  
  202.  
  203. /* ASM
  204.  
  205. PB_SG_Array_Offset              equ size PB_Read_Write
  206.  
  207. */
  208.  
  209. typedef struct _SG_Descriptor { /* SG */
  210.         PVOID  BufferPtr;       /* 32 bit physcial pointer to the buffer */
  211.         ULONG  BufferSize;      /* size of the buffer in bytes */
  212. } SG_Descriptor;
  213.  
  214. typedef SG_Descriptor SGENTRY;
  215. typedef SGENTRY FAR *PSGENTRY;
  216.  
  217. /*
  218. ;; DriverCaps is the the Driver Capabilities structure.  This structure is
  219. ;; used by FSD's to determine the specific features supported by the
  220. ;; device driver.
  221. */
  222. typedef struct _DriverCaps { /* GDC_DD */
  223.     USHORT Reserved ;                /* reserved, set to zero                */
  224.     BYTE   VerMajor ;                /* major version of interface supported */
  225.     BYTE   VerMinor ;                /* minor version of interface supported */
  226.     ULONG  Capabilities ;            /* bitfield for driver capabilties      */
  227.     PVOID  Strategy2 ;               /* entry point for strategy-2           */
  228.     PVOID  EndofInt ;                /* entry point for DD_EndOfInt          */
  229.     PVOID  ChgPriority ;             /* entry point for DD_ChgPriority       */
  230.     PVOID  SetRestPos ;              /* entry point for DD_SetRestPos        */
  231.     PVOID  GetBoundary ;             /* entry point for DD_GetBoundary       */
  232.     } DriverCaps ;
  233.  
  234. typedef DriverCaps FAR * P_DriverCaps ;
  235.  
  236. /*
  237. ;; Driver Capabilites bit mask (GDC_DD_Capabilities)
  238. */
  239. #define GDC_DD_Read2      0x00000001  /* Read2 supported with DMA hardware     */
  240. #define GDC_DD_DMA_Word   0x00000002  /* DMA on word-aligned buffers supported */
  241. #define GDC_DD_DMA_Byte   0x00000006  /* DMA on byte-aligned buffers supported */
  242. #define GDC_DD_Mirror     0x00000008  /* Disk Mirroring supported by driver  */
  243. #define GDC_DD_Duplex     0x00000010  /* Disk Duplexing supported by driver  */
  244. #define GDC_DD_No_Block   0x00000020  /* Driver does not block in Strategy 2 */
  245. #define GDC_DD_16M        0x00000040  /* >16M memory supported               */
  246.  
  247. /*
  248. ;; VolChars is the volume charactieristics table.  This table describes the
  249. ;; physical characteristics of the logical volume, under the simplifying (but
  250. ;; not necessarily true) assumption that this is the only volume on the
  251. ;; physical drive.
  252. */
  253. typedef struct _VolChars { /* VC */
  254.     USHORT VolDescriptor ;           /* see equates below                    */
  255.     USHORT AvgSeekTime ;             /* milliseconds, if unknown, FFFFh      */
  256.     USHORT AvgLatency ;              /* milliseconds, if unknown, FFFFh      */
  257.     USHORT TrackMinBlocks ;          /* blocks on smallest track             */
  258.     USHORT TrackMaxBlocks ;          /* blocks on largest track              */
  259.     USHORT HeadsPerCylinder ;        /* if unknown or not applicable use 1   */
  260.     ULONG  VolCylinderCount ;        /* number of cylinders on volume        */
  261.     ULONG  VolMedianBlock ;          /* block in center of volume for seek   */
  262.     USHORT MaxSGList ;               /* Adapter scatter/gather list limit    */
  263.     } VolChars ;
  264.  
  265. typedef VolChars FAR * P_VolChars ;
  266.  
  267. /*
  268. ;; Volume Descriptor bit masks (VC_VolDescriptor)
  269. */
  270. #define VC_REMOVABLE_MEDIA    0x0001  /* Volume resides on removable media   */
  271. #define VC_READ_ONLY          0x0002  /* Volume is read-only                 */
  272. #define VC_RAM_DISK           0x0004  /* Seek time independant of position   */
  273. #define VC_HWCACHE            0x0008  /* Outboard cache supported            */
  274. #define VC_SCB                0x0010  /* SCB protocol supported              */
  275. #define VC_PREFETCH           0x0020  /* Prefetch read supported             */
  276.  
  277.  
  278. /*
  279.  * The rest of this file is not needed by standard HPFS
  280.  */
  281.  
  282. /* ASM
  283. ;
  284. ;
  285. ;***************************
  286. ;* Queue Linkage Structure *
  287. ;***************************
  288. ;
  289. ; This structure is private to the driver
  290. ;
  291. ; Queue linkage will be allocated from the local data segment. A word
  292. ;       pointer will point to the next link structure in the queue and a
  293. ;       double word will serve as a far pointer to the actual request.
  294. ;
  295. ; The linkage provided in the elements of the Pinball request array will
  296. ;       point back to the queue linkage to fascilitate removal of a request
  297. ;       if a request list was cancelled or a request's priority changed.
  298. ;
  299. NUMQLINKS = 50                          ; number of QLink elements
  300. ;
  301. QLink struc
  302.         QLinkNext               dw ?    ; pointer to next queue link
  303.         QLinkPriority           db ?    ; request priority
  304.         QLinkFlags              db ?    ; pinball indicator
  305.         QLinkRequest            dd ?    ; far pointer to pinball request
  306.         QLinkStartBlock         dd ?    ; disk I/O start block for sort key
  307.         QLinkReqHandle          dw ?    ; used when notifying FT_Done
  308.         QLinkPartNumber         db ?    ; FT partition number
  309.         QLinkDevUnit            db ?    ; device unit number from packet
  310.         QLinkRelBlock           dd ?    ; FT relative start block
  311. QLink ends
  312. ;
  313. ; QLinkFlags Values
  314. ;
  315.         QL_OS2          equ     00h     ; this is standard OS/2 I/O
  316.         QL_Pinball      equ     01h     ; this is HPFS386 I/O
  317.         QL_HPFS386      equ     01h     ; this is HPFS386 I/O
  318.         FT_AUX_PKT      equ     02h     ; this is an auxilliary packet
  319.         FT_MIRROR_IO    equ     04h     ; mirrored I/O
  320. ;
  321. ; end of assembly section
  322. */
  323.  
  324. /* ASM
  325.  
  326. ;***********************************
  327. ;* GetDeviceSupport Request Packet *
  328. ;***********************************
  329.  
  330. */
  331. /* ASM
  332. ;
  333. ;; define the device driver request packet for the get device
  334. ;; capabilities (hex 1d) command
  335. ;
  336. Pkt_1d      struc
  337.                 db  PktHeadSize dup (?) ; device driver request packet header.
  338.                 db  3 dup (?)           ; reserved.
  339. Pkt_1d_DCS_Addr dd  ?                   ; pointer to dcs area in 16:16 format.
  340. Pkt_1d_VCS_Addr dd  ?                   ; pointer to vcs area in 16:16 format.
  341. Pkt_1d      ends
  342.  
  343. access_type_write equ   1
  344. access_type_read  equ   0
  345.  
  346.  
  347. ;
  348. ERROR_INT13_BAD_COMMAND         EQU     01h
  349. ERROR_INT13_DRIVE_NOT_READY     EQU     80h
  350. ;
  351. ;***********************************************************
  352. ;* IOCTL Packet for IOPD_SB - Set Simulated     sectors *  *
  353. ;* NOTE: THIS IS AN INTERNAL IOCTL FOR DEBUG PURPOSES ONLY *
  354. ;***********************************************************
  355.  
  356. IOPD_SB             equ 04Bh    ; category 9 function 4Bh
  357. SSB_MAXCNT          equ 012h    ; only allow 18 simulated     sectors
  358. ;* SSB commands
  359. SSB_SET             equ 0
  360. SSB_CLEAR           equ 1
  361. SSB_CLEARALL        equ 2
  362. SSB_LIST            equ 3
  363.  
  364. IOCTLSETSBAD struc
  365.     ssb_cmd         db  ?
  366.     ssb_cnt         db  ?       ; on return will be
  367.     ssb_sec         dd  ?       ; sector to be marked bad/ cleared
  368. IOCTLSETSBAD ends
  369.  
  370. ;* cnt field returns # of slots clear on a SET cmd and # of slots used
  371. ;* on a clear cmd.
  372.  
  373. ;PBTEST equ 1   ; for Pinball testing, enabling simbad code
  374.  
  375. ;
  376. ; this next routine is two macros for spin-locking
  377. ; critical sections. In the first macro a semaphore
  378. ; is tested for availability. It is tested in such
  379. ; a way start after the first test the data should
  380. ; be in the cache and there should be no more memory
  381. ; accesses. Once it is available we try to grab it
  382. ; and if someone beats us to it, we go back to
  383. ; checking the semaphore in the cache.
  384. ; The second routine simply writes a zero to the
  385. ; semaphore to clear it (and enables interrupts).
  386. ;
  387. STARTCRITICAL macro semaphore
  388.         push    ax
  389.         mov     al, 1
  390. @@:     sti
  391.         cmp     semaphore, 0    ; Q: semaphore available?
  392.         jnz     @B              ;    N: try again
  393.         cli
  394.         xchg    semaphore, al   ; this is where we actually set it
  395.         or      al,al           ; Q: did we set it?
  396.         jnz     @B              ;   N: start over again
  397.         pop     ax
  398.         endm
  399.  
  400. X_STARTCRITICAL macro semaphore
  401.         push    ax
  402.         mov     al, 1
  403. @@:     xchg    semaphore, al
  404.         or      al,al           ; Q: did we set it?
  405.         jnz     @B              ;   N: start over again
  406.         pop     ax
  407.         endm
  408.  
  409. ENDCRITICAL macro semaphore
  410.         mov     semaphore, 0
  411.         sti
  412.         endm
  413.  
  414. X_ENDCRITICAL macro semaphore
  415.         mov     semaphore, 0
  416.         endm
  417.  
  418. ; State Trace Buffer Pointer Mask
  419.         ST_BufferPtr_Mask   equ 0FFFh       ; only 4k state trace buffer
  420. ;       STATETRACE          equ 1           ; enable state trace debugging
  421.  
  422. ; SimBad
  423.         CACHETEST           equ 1           ; enable     Sector Simulation
  424.  
  425. ; Minimum MaxSgList
  426. ; If the scsi card can't handle at least 16 s/g entries then (for fat)
  427. ; volumes feed it strat1.
  428.    FAT_MIN_MAX_SGLIST equ 16
  429.  
  430.  
  431. ; FAT strat2 request packet. Note that the SG field is pre-set for 60 pages.
  432. ; The worst case is around 18 pages. But we need more for the Lazy Writer
  433. ; which will not require more SG_Descriptior but just a few more RB_Read_Write.
  434. ; If we add more PB_Read_Writes then the old FAT strategy2 would not work, so
  435. ; for now we fake it out.
  436.  
  437. fats2   struc
  438. fs2_rlh db      size Req_List_Header dup(?)
  439. fs2_rh  db      size PB_Read_Write dup(?)
  440. fs2_sg  db 60 * size SG_Descriptor dup(?)
  441. fs2_sem dd      ?
  442. fats2   ends
  443.  
  444. ; Used by FAT as the max size of a strat2 req pkt
  445.  
  446. S2_RW_RQPKT_SIZE  EQU   size fats2
  447. */
  448.