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.

317 lines
10 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Copyright (c) 1991 Nokia Data Systems AB
  4. Module Name:
  5. dlcdef.h
  6. Abstract:
  7. This module includes all defines and constants of DLC API driver.
  8. Author:
  9. Antti Saarenheimo 22-Jul-1991
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. --*/
  14. #include <ntddk.h> // required for PAGE_SIZE
  15. //
  16. // minima, maxima and defaults for registry parameters
  17. //
  18. #define MIN_TIMER_TICK_VALUE 1
  19. #define MAX_TIMER_TICK_VALUE 255
  20. #define MIN_AUTO_FRAMING_CACHE_SIZE 0 // means NO CACHING!
  21. #define MAX_AUTO_FRAMING_CACHE_SIZE 256 // arbitrary maximum
  22. //
  23. // if non-TR cards && using max ethernet frame length then 1514 is the value
  24. // we use (came from ELNKII, EE16, LANCE, et al)
  25. //
  26. #define MAX_ETHERNET_FRAME_LENGTH 1514
  27. //
  28. // default values for parameters retrieved from registry
  29. //
  30. #define DEFAULT_SWAP_ADDRESS_BITS 1
  31. #define DEFAULT_DIX_FORMAT 0
  32. #define DEFAULT_T1_TICK_ONE 5
  33. #define DEFAULT_T1_TICK_TWO 25
  34. #define DEFAULT_T2_TICK_ONE 1
  35. #define DEFAULT_T2_TICK_TWO 10
  36. #define DEFAULT_Ti_TICK_ONE 25
  37. #define DEFAULT_Ti_TICK_TWO 125
  38. #define DEFAULT_USE_ETHERNET_FRAME_SIZE 1
  39. #define DEFAULT_AUTO_FRAMING_CACHE_SIZE 16
  40. //
  41. // The event and command queue structures overlaps => we cane save the
  42. // duplicate code. The defined name makes code more readable.
  43. //
  44. #define SearchAndRemoveEvent( a, b, c, d ) \
  45. (PDLC_EVENT)SearchAndRemoveCommand( a, b, c, d )
  46. #define MAX_SAP_STATIONS 128
  47. #define MAX_LINK_STATIONS 255
  48. #define GROUP_SAP_BIT 0x0100
  49. #define DLC_INDIVIDUAL_SAP 0x04
  50. #define XID_HANDLING_BIT 0x08
  51. #define MIN_DLC_BUFFER_SIZE PAGE_SIZE
  52. #define MAX_FREE_SIZE_THRESHOLD 0x2000
  53. #define INVALID_RCV_READ_OPTION 3
  54. #define DLC_INVALID_OPTION_INDICATOR 3
  55. #define DLC_NO_RECEIVE_COMMAND 4
  56. #define DLC_CONTIGUOUS_MAC 0x80
  57. #define DLC_CONTIGUOUS_DATA 0x40
  58. #define DLC_BREAK 0x20
  59. #if defined(ALPHA)
  60. #define DLC_BUFFER_SEGMENTS 6 // 256, 512, 1024, 2048, 4096, 8192 => 6
  61. #else
  62. #define DLC_BUFFER_SEGMENTS 5 // 256, 512, 1024, 2048, 4096 => 5
  63. #endif
  64. #define MAX_USER_DATA_LENGTH 128 // anything less than 256
  65. //
  66. // Transmit timeout = 20 * 250 ms = 5 seconds
  67. //
  68. #define MAX_TRANSMIT_RETRY 20
  69. #define TRANSMIT_RETRY_WAIT 2500000L
  70. #define LLC_RECEIVE_COMMAND_FLAG 0x80
  71. #define DLC_IGNORE_SEARCH_HANDLE NULL
  72. #define DLC_MATCH_ANY_COMMAND (PVOID)-1
  73. #define DLC_IGNORE_STATION_ID 0x00ff
  74. #define DLC_STATION_MASK_SPECIFIC 0xffff
  75. #define DLC_STATION_MASK_SAP 0xff00
  76. #define DLC_STATION_MASK_ALL 0
  77. #define IOCTL_DLC_READ_INDEX ((IOCTL_DLC_READ >> 2) & 0x0fff)
  78. #define IOCTL_DLC_RECEIVE_INDEX ((IOCTL_DLC_RECEIVE >> 2) & 0x0fff)
  79. #define IOCTL_DLC_TRANSMIT_INDEX ((IOCTL_DLC_TRANSMIT >> 2) & 0x0fff)
  80. #define IOCTL_DLC_OPEN_ADAPTER_INDEX ((IOCTL_DLC_OPEN_ADAPTER >> 2) & 0x0fff)
  81. enum _DLC_OBJECT_STATES {
  82. DLC_OBJECT_OPEN,
  83. DLC_OBJECT_CLOSING,
  84. DLC_OBJECT_CLOSED,
  85. DLC_OBJECT_INVALID_TYPE
  86. };
  87. //
  88. // The Token-Ring status codes documented in Appendix B of the IBM LAN
  89. // Tech Reference are shifted right one bit from the NDIS values
  90. // documented in "ntddndis.h."
  91. //
  92. // In versions 3.xx of Windows NT, DLC returns a Network Status that
  93. // agrees with the NDIS values. In version 4.xx and newer, IBM
  94. // compatible values are used.
  95. //
  96. // These macros may be used to convert between the two conventions.
  97. //
  98. #define NDIS_RING_STATUS_TO_DLC_RING_STATUS(status) ((status)>>1)
  99. #define DLC_RING_STATUS_TO_NDIS_RING_STATUS(status) ((status)<<1)
  100. #define NDIS_RING_STATUS_MASK \
  101. NDIS_RING_SIGNAL_LOSS\
  102. |NDIS_RING_HARD_ERROR\
  103. |NDIS_RING_SOFT_ERROR\
  104. |NDIS_RING_TRANSMIT_BEACON\
  105. |NDIS_RING_LOBE_WIRE_FAULT\
  106. |NDIS_RING_AUTO_REMOVAL_ERROR\
  107. |NDIS_RING_REMOVE_RECEIVED\
  108. |NDIS_RING_COUNTER_OVERFLOW\
  109. |NDIS_RING_SINGLE_STATION\
  110. |NDIS_RING_RING_RECOVERY
  111. #define DLC_RING_STATUS_MASK NDIS_RING_STATUS_TO_DLC_RING_STATUS(NDIS_RING_STATUS_MASK)
  112. #define IS_NDIS_RING_STATUS(status) (((status)&NDIS_RING_STATUS_MASK)!=0)
  113. #define IS_DLC_RING_STATUS(status) (((status)&DLC_RING_STATUS_MASK)!=0)
  114. //
  115. // ENTER/LEAVE_DLC - acquires or releases the per-file context spin lock. Use
  116. // Ndis spin locking calls
  117. //
  118. #define ENTER_DLC(p) ACQUIRE_SPIN_LOCK(&p->SpinLock)
  119. #define LEAVE_DLC(p) RELEASE_SPIN_LOCK(&p->SpinLock)
  120. //
  121. // ACQUIRE/RELEASE_DLC_LOCK - acquires or releases global DLC spin lock. Use
  122. // kernel spin locking calls
  123. //
  124. #define ACQUIRE_DLC_LOCK(i) KeAcquireSpinLock(&DlcSpinLock, &(i))
  125. #define RELEASE_DLC_LOCK(i) KeReleaseSpinLock(&DlcSpinLock, (i))
  126. #define ADAPTER_ERROR_COUNTERS 11 // # adapter error log counters
  127. #define ReferenceFileContextByTwo(pFileContext) (pFileContext)->ReferenceCount += 2
  128. #define ReferenceFileContext(pFileContext) (pFileContext)->ReferenceCount++
  129. #if DBG
  130. #define DereferenceFileContext(pFileContext) \
  131. if (pFileContext->ReferenceCount <= 0) { \
  132. DbgPrint("DLC.DereferenceFileContext: Error: file context %08x: reference count %x\n",\
  133. pFileContext, \
  134. pFileContext->ReferenceCount \
  135. ); \
  136. DbgBreakPoint(); \
  137. } \
  138. (pFileContext)->ReferenceCount--; \
  139. if ((pFileContext)->ReferenceCount <= 0) { \
  140. DlcKillFileContext(pFileContext); \
  141. }
  142. #define DereferenceFileContextByTwo(pFileContext) \
  143. if (pFileContext->ReferenceCount <= 1) { \
  144. DbgPrint("DLC.DereferenceFileContextByTwo: Error: file context %08x: reference count %x\n",\
  145. pFileContext, \
  146. pFileContext->ReferenceCount \
  147. ); \
  148. DbgBreakPoint(); \
  149. } \
  150. (pFileContext)->ReferenceCount -= 2; \
  151. if ((pFileContext)->ReferenceCount <= 0) { \
  152. DlcKillFileContext(pFileContext); \
  153. }
  154. #else
  155. #define DereferenceFileContext(pFileContext) \
  156. (pFileContext)->ReferenceCount--; \
  157. if ((pFileContext)->ReferenceCount <= 0) { \
  158. DlcKillFileContext(pFileContext); \
  159. }
  160. #define DereferenceFileContextByTwo(pFileContext) \
  161. (pFileContext)->ReferenceCount -= 2; \
  162. if ((pFileContext)->ReferenceCount <= 0) { \
  163. DlcKillFileContext(pFileContext); \
  164. }
  165. #endif // DBG
  166. #define BufferPoolCount(hBufferPool) \
  167. (((PDLC_BUFFER_POOL)hBufferPool)->FreeSpace >= (256L * 0x0000ffffL) ? \
  168. 0xffff : \
  169. (((PDLC_BUFFER_POOL)hBufferPool)->FreeSpace / 256))
  170. #define BufGetUncommittedSpace(handle) \
  171. ((PDLC_BUFFER_POOL)(handle))->UncommittedSpace
  172. #define BufCommitBuffers(handle, BufferSize) \
  173. ExInterlockedAddUlong( \
  174. (PULONG)&((PDLC_BUFFER_POOL)(handle))->UncommittedSpace, \
  175. (ULONG)(-((LONG)BufferSize)), \
  176. &(((PDLC_BUFFER_POOL)(handle))->SpinLock))
  177. #define BufUncommitBuffers(handle, BufferSize) \
  178. ExInterlockedAddUlong(\
  179. (PULONG)&((PDLC_BUFFER_POOL)(handle))->UncommittedSpace,\
  180. (ULONG)(BufferSize),\
  181. &(((PDLC_BUFFER_POOL)(handle))->SpinLock))
  182. /*++
  183. BOOLEAN
  184. BufferPoolCheckThresholds(
  185. IN PDLC_BUFFER_POOL pBufferPool
  186. )
  187. Routine Description:
  188. The function checks the minimum and maximum size Thresholds and
  189. returns TRUE, if buffer pool needs reallocation.
  190. We do this check outside the spinlocks to avoid
  191. unnecessary locking in 99 % of the cases.
  192. Arguments:
  193. pBufferPool - handle of buffer pool data structure.
  194. Return Value:
  195. Returns TRUE => Buffer pool needs extending
  196. FALSE => no need for it
  197. --*/
  198. #define BufferPoolCheckThresholds( pBufferPool ) \
  199. (((pBufferPool) != NULL && \
  200. (((PDLC_BUFFER_POOL)(pBufferPool))->UncommittedSpace < 0 || \
  201. ((PDLC_BUFFER_POOL)(pBufferPool))->MissingSize > 0) && \
  202. ((PDLC_BUFFER_POOL)(pBufferPool))->BufferPoolSize < \
  203. ((PDLC_BUFFER_POOL)(pBufferPool))->MaxBufferSize && \
  204. MemoryLockFailed == FALSE) ? TRUE : FALSE)
  205. //
  206. // These routines closes a llc object, when there are no
  207. // more references to it
  208. //
  209. #define ReferenceLlcObject( pDlcObject ) (pDlcObject)->LlcReferenceCount++
  210. #define DereferenceLlcObject( pDlcObject ) { \
  211. (pDlcObject)->LlcReferenceCount--; \
  212. if ((pDlcObject)->LlcReferenceCount == 0) {\
  213. CompleteLlcObjectClose( pDlcObject ); \
  214. } \
  215. DLC_TRACE('O'); \
  216. DLC_TRACE( (UCHAR)(pDlcObject)->LlcReferenceCount ); \
  217. }
  218. //
  219. // We need the same kind of routines to reference the buffer pool.
  220. // The adapter closing have quite many times deleted the buffer pool
  221. // just before it was called (after LEAVE_DLC).
  222. //
  223. #define ReferenceBufferPool(pFileContext) (pFileContext)->BufferPoolReferenceCount++
  224. #if DBG
  225. #define DereferenceBufferPool(pFileContext) {\
  226. (pFileContext)->BufferPoolReferenceCount--; \
  227. if ((pFileContext)->BufferPoolReferenceCount == 0) {\
  228. BufferPoolDereference( \
  229. pFileContext, \
  230. (PDLC_BUFFER_POOL*)&(pFileContext)->hBufferPool); \
  231. } \
  232. }
  233. #else
  234. #define DereferenceBufferPool(pFileContext) {\
  235. (pFileContext)->BufferPoolReferenceCount--; \
  236. if ((pFileContext)->BufferPoolReferenceCount == 0) {\
  237. BufferPoolDereference((PDLC_BUFFER_POOL*)&(pFileContext)->hBufferPool); \
  238. } \
  239. }
  240. #endif