Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

456 lines
12 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Copyright (c) 1997 Parallel Technologies, Inc. All Rights Reserved.
  4. Module Name:
  5. ptilink.h
  6. Abstract:
  7. This file defines the interface for the Parallel Technologies
  8. DirectParallel IO driver.
  9. This driver doubles as an NT device driver and an export library.
  10. Author:
  11. Norbert P. Kusters 4-Jan-1995
  12. Jay Lowe, Parallel Technologies, Inc.
  13. Revision History:
  14. --*/
  15. #ifndef _PTILINK_
  16. #define _PTILINK_
  17. #define NPORTS 3 // number of PTILINKx devices to make
  18. #define MAXLPTXNAME 99
  19. typedef struct _PTI_EXTENSION PTI_EXTENSION;
  20. //
  21. // This structure contains configuration data, much of which
  22. // is read from the registry.
  23. //
  24. typedef struct _PAR_REG_DATA {
  25. ULONG PollInterval;
  26. ULONG TraceLevel;
  27. ULONG TraceMask;
  28. ULONG IoWait;
  29. ULONG SyncWait;
  30. } PAR_REG_DATA,*PPAR_REG_DATA;
  31. //
  32. // Client callbacks from PtiLink
  33. //
  34. // Ptilink requests a read buffer from the upward client
  35. typedef
  36. PVOID
  37. (*GET_READ_BUFFER_ROUTINE)(
  38. IN PVOID ParentContext,
  39. OUT PULONG BufferSize,
  40. OUT PVOID* RequestContext
  41. );
  42. // Ptilink returns a completed read buffer to the upward client
  43. typedef
  44. VOID
  45. (*COMPLETE_READ_BUFFER_ROUTINE)(
  46. IN PVOID ParentContext,
  47. IN PVOID ReadBuffer,
  48. IN NTSTATUS Status,
  49. IN ULONG BytesTransfered,
  50. IN PVOID RequestContext
  51. );
  52. // PtiLink notifies upward client of a link event
  53. typedef
  54. VOID
  55. (*NOTIFY_LINK_EVENT)(
  56. IN PVOID ParentContext,
  57. IN ULONG PtiLinkEventId,
  58. IN ULONG PtiLinkEventData
  59. );
  60. // PtilinkEventIds
  61. #define PTILINK_LINK_UP 2 // link has been established
  62. // a LINK_OPEN or dataframe
  63. // was received on SHUT link
  64. // i.e., link is starting
  65. #define PTILINK_LINK_DOWN 4 // link has been terminated
  66. // peer has issued a LINK_SHUT
  67. // and is departing
  68. //
  69. // Device driver routines ... are of the form ParXXXXXX
  70. //
  71. BOOLEAN
  72. ParInterruptService(
  73. IN PKINTERRUPT Interrupt,
  74. IN OUT PVOID Extension
  75. );
  76. VOID
  77. ParDpcForIsr(
  78. IN PKDPC Dpc,
  79. IN PDEVICE_OBJECT DeviceObject,
  80. IN PIRP Irp,
  81. IN PVOID Extension
  82. );
  83. VOID
  84. ParDeferredPortCheck(
  85. IN PVOID Extension
  86. );
  87. VOID
  88. ParAllocTimerDpc(
  89. IN PKDPC Dpc,
  90. IN PVOID Extension,
  91. IN PVOID SystemArgument1,
  92. IN PVOID SystemArgument2
  93. );
  94. NTSTATUS
  95. ParCreate(
  96. IN PDEVICE_OBJECT DeviceObject,
  97. IN PIRP Irp
  98. );
  99. NTSTATUS
  100. ParClose(
  101. IN PDEVICE_OBJECT DeviceObject,
  102. IN PIRP Irp
  103. );
  104. NTSTATUS
  105. ParRead(
  106. IN PDEVICE_OBJECT DeviceObject,
  107. IN PIRP Irp
  108. );
  109. PVOID
  110. ParGetReadBuffer(
  111. IN PVOID ParentContext,
  112. OUT PULONG BufferSize,
  113. OUT PVOID* RequestContext
  114. );
  115. VOID
  116. ParCompleteReadBuffer(
  117. IN PVOID ParentContext,
  118. IN PVOID ReadBuffer,
  119. IN NTSTATUS Status,
  120. IN ULONG BytesTransfered,
  121. IN PVOID RequestContext
  122. );
  123. VOID
  124. ParLinkEventNotification(
  125. IN PVOID ParentContext,
  126. IN ULONG PtiLinkEventId,
  127. IN ULONG PtiLinkEventData
  128. );
  129. NTSTATUS
  130. ParWrite(
  131. IN PDEVICE_OBJECT DeviceObject,
  132. IN PIRP Irp
  133. );
  134. NTSTATUS
  135. ParCleanup(
  136. IN PDEVICE_OBJECT DeviceObject,
  137. IN PIRP Irp
  138. );
  139. VOID
  140. ParUnload(
  141. IN PDRIVER_OBJECT DriverObject
  142. );
  143. //
  144. // Link Level Routines ... are of the form PtiXXXXXX
  145. //
  146. NTSTATUS
  147. PtiInitialize(
  148. IN ULONG PortId,
  149. OUT PVOID pExtension,
  150. OUT PVOID pPtiExtension
  151. );
  152. //
  153. // a word about registering callbacks: Par (the device driver level)
  154. // registers callbacks to itself at ParCreate time. If you are using
  155. // the Ptilink service API in a non-irp fashion, you need to open the
  156. // Ptilink device, and then re-register your own callbacks, which
  157. // effectively disconnects the Par device driver level - it will be
  158. // reconnected, of course, at the next ParCreate.
  159. //
  160. // So the sequence to use the PtiLink API without IRP's is:
  161. //
  162. // ZwCreateFile("\\\\.\\PTILINKx", ...)
  163. // at this time, Ptilink attempts tp make a link on LPTx
  164. // the ParCreate hooks up interrupts, calls PtiInit, etc
  165. // the only Ptilink stuff exposed to you are the callbacks
  166. //
  167. // PtiRegisterCallbacks(...your handlers here...)
  168. // you are overriding the inherent callbacks of the Par level
  169. //
  170. // PtiWrite(...)
  171. // ...
  172. // ... etc, etc ...
  173. // ...
  174. //
  175. // ZwClose()
  176. //
  177. #ifndef PID_STANDARD
  178. #define PID_STANDARD 0x13
  179. #endif
  180. #ifndef PID_LINK
  181. #define PID_LINK 0x11
  182. #endif
  183. NTSTATUS
  184. PtiQueryDeviceStatus(
  185. IN ULONG PortId, // parallel port number (0..2)
  186. OUT WCHAR* szPortName // Buffer of at least LPTXMAXNAME + 1 bytes
  187. );
  188. NTSTATUS
  189. PtiRegisterCallbacks(
  190. IN PVOID Extension,
  191. IN GET_READ_BUFFER_ROUTINE GetReadBuffer,
  192. IN COMPLETE_READ_BUFFER_ROUTINE CompleteReadBuffer,
  193. IN NOTIFY_LINK_EVENT LinkEventNotification,
  194. IN PVOID ParentContext
  195. );
  196. VOID
  197. PtiCleanup(
  198. IN PVOID PtiExtension
  199. );
  200. NTSTATUS
  201. PtiWrite(
  202. IN PVOID PtiExtension,
  203. IN PVOID Buffer,
  204. IN ULONG BufferSize,
  205. IN UCHAR Pid
  206. );
  207. BOOLEAN
  208. PtiIsReadPending(
  209. IN PVOID PtiExtension
  210. );
  211. VOID
  212. PtiRead(
  213. IN PVOID PtiExtension
  214. );
  215. ULONG
  216. PtiQueryMaxReadSize(
  217. );
  218. VOID
  219. PtiPortNameFromPortId(
  220. IN ULONG PortId,
  221. OUT CHAR* szPortName
  222. );
  223. //************************************************************************
  224. //* Platform Id Codes *
  225. //************************************************************************
  226. #define PLAT_WIN9X 0 // Win95 and Win98
  227. #define PLAT_DOS 1 // Dos
  228. #define PLAT_NT 2 // WinNT v4 and v5
  229. //************************************************************************
  230. //* LinkInformation Structure *
  231. //************************************************************************
  232. //
  233. // LinkInformation - Link Management Information
  234. //
  235. // This structure contains information which is exchanged by the Nodes
  236. // within Link Management Packets
  237. //
  238. // This structure must be maintained in parallel with it's twin in PTI.INC
  239. //
  240. // All changes must be backward compatible with all previous driver versions
  241. #define LINKINFOSIZE 45*4 // explicitly define expected size
  242. typedef struct _LINK_INFORMATION {
  243. UCHAR LinkFunction; // 1] Current/Last Link Function
  244. UCHAR res1;
  245. UCHAR res2;
  246. UCHAR res3;
  247. UCHAR VerPlat; // 2] Platform ID byte (see PLAT_XXXX)
  248. UCHAR VerReserved; // reserved
  249. UCHAR VerMajor; // Link Major version
  250. UCHAR VerMinor; // Link Minor version
  251. UCHAR IOMode; // 3] Current IO transfer mode
  252. UCHAR CableType; // Detected cable type
  253. UCHAR PortType; // Physical parallel port type
  254. UCHAR Station; // Address of this station
  255. USHORT FIFOlen; // 4] ECP FIFO length, if ECP port
  256. USHORT FIFOwidth; // ECP FIFO width, if ECP port
  257. ULONG CPUType; // 5] CPU type
  258. ULONG CPUSpeed; // 6] CPU speed rating
  259. ULONG RxBufSize; // 7] Rx buffer size
  260. ULONG NominalSpd; // 8] Estimated speed rating
  261. ULONG ActualSpd; // 9] Actual performance to date
  262. ULONG PpIOWait; // 10] default IO wait time
  263. ULONG PpLongWait; // 11] default synchronization wait time
  264. ULONG PpShortWait; // 12] default synchronization wait time
  265. ULONG LastLinkTime; // 13] time of last link receive activity
  266. ULONG CableTestTime; // 14] time of last cable detect
  267. // These times are not used on NT because
  268. // NT times are 64 bits ... see NT time below
  269. // some basic counters
  270. ULONG RxAttempts; // 15] Number of Ints w/ real RATTNs
  271. ULONG RxPackets; // 16] Number of good received packets
  272. ULONG TxAttempts; // 17] Number of TxPackets attempted
  273. ULONG TxPackets; // 18] Number of successful TxPackets
  274. ULONG GoodPackets; // 19] Number of successful recent Txs / Rxs
  275. ULONG HwIRQs; // 20] Number of real hardware IRQs
  276. // Main Error Counter Group
  277. ULONG TxHdrDataErrors; // 21] data error during header
  278. ULONG RxHdrDataErrors; // 22] data error during header
  279. ULONG TxHdrSyncErrors; // 23] sync error during header
  280. ULONG RxHdrSyncErrors; // 24] sync error during header
  281. ULONG TxSyncErrors; // 25] sync error during packet
  282. ULONG RxSyncErrors; // 26] sync error during packet
  283. // Tx Details Group
  284. ULONG TxTimeoutErrors1; // 27] timeouts in Tx IO code
  285. ULONG TxTimeoutErrors2; // 28] timeouts in Tx IO code
  286. ULONG TxTimeoutErrors3; // 29] timeouts in Tx IO code
  287. ULONG TxTimeoutErrors4; // 30] timeouts in Tx IO code
  288. ULONG TxTimeoutErrors5; // 31] timeouts in Tx IO code
  289. ULONG TxCollision; // 32] Collision in Tx IO code
  290. // Rx Details Group
  291. ULONG RxTimeoutErrors1; // 33] timeouts in Rx IO code
  292. ULONG RxTimeoutErrors2; // 34] timeouts in Rx IO code
  293. ULONG RxTimeoutErrors3; // 35] timeouts in Rx IO code
  294. ULONG RxTimeoutErrors4; // 36] timeouts in Rx IO code
  295. ULONG RxTimeoutErrors5; // 37] timeouts in Rx IO code
  296. ULONG RxTooBigErrors; // 38] Rx packet too big or won't fit
  297. // Misc Error Details Group
  298. ULONG CableDetects; // 39] Attempts to detect type of cable
  299. ULONG TxRetries; // 40] Tx Retry attempts
  300. ULONG TxRxPreempts; // 41] Tx Receive preemptions
  301. ULONG InternalErrors; // 42] Internal screwups
  302. ULONG ReservedError; // 43]
  303. // NT Specific Group
  304. TIME LastPacketTime; // 45] time of last good TX or Rx
  305. } LINK_INFORMATION, *PLINK_INFORMATION;
  306. //
  307. // This structure is filled in by ECP detection at PtiInitialize time
  308. //
  309. typedef struct _PTI_ECP_INFORMATION {
  310. BOOLEAN IsEcpPort; // Is this an ECP port?
  311. ULONG FifoWidth; // Number of bytes in a PWord.
  312. ULONG FifoDepth; // Number of PWords in FIFO.
  313. } PTI_ECP_INFORMATION, *PPTI_ECP_INFORMATION;
  314. //
  315. // The internal structure for the 'PtiExtension'.
  316. //
  317. typedef struct _PTI_EXTENSION {
  318. //
  319. // Base I/O address for parallel port.
  320. //
  321. PUCHAR Port;
  322. PUCHAR wPortECR; // ECR register if obtained from ParPort
  323. PUCHAR wPortDFIFO; // Data FIFO register if obtained from ParPort
  324. //
  325. // The link state
  326. //
  327. ULONG LinkState;
  328. //
  329. // TRUE if we are polling
  330. //
  331. BOOLEAN Polling;
  332. // "mutex" on the line
  333. // InterlockedCompareExchange64 to TRUE when using wire, FALSE when done
  334. //
  335. ULONG Busy;
  336. //
  337. // This structure holds the PTI-derived ECP port information.
  338. //
  339. PTI_ECP_INFORMATION EcpInfo;
  340. // Time of last good packet Tx or Rx
  341. //
  342. TIME LastGoodPacket;
  343. // Time of last pass through WatchDog
  344. //
  345. TIME LastDogTime;
  346. //
  347. // Functions for getting and completing read buffers.
  348. //
  349. GET_READ_BUFFER_ROUTINE GetReadBuffer;
  350. COMPLETE_READ_BUFFER_ROUTINE CompleteReadBuffer;
  351. NOTIFY_LINK_EVENT LinkEventNotify;
  352. PVOID ParentContext;
  353. //
  354. // Our and His Link Information.
  355. //
  356. LINK_INFORMATION Our;
  357. LINK_INFORMATION His;
  358. } PTI_EXTENSION, *PPTI_EXTENSION;
  359. #endif // _PTILINK_