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