Source code of Windows XP (NT5)
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.

263 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. macros.h
  5. Abstract:
  6. Macros used in ATMEPVC
  7. Author:
  8. Revision History:
  9. Who When What
  10. -------- -------- ----
  11. ADube 03-23-00 created, .
  12. --*/
  13. #ifndef _MACROS_H
  14. #define _MACROS_H
  15. #define FALL_THROUGH // For informational purpose in a switch statement
  16. // Warning -- FAIL(NDIS_STATUS_PENDING) == TRUE
  17. //
  18. #define FAIL(_Status) ((_Status) != NDIS_STATUS_SUCCESS)
  19. #define PEND(_Status) ((_Status) == NDIS_STATUS_PENDING)
  20. #if RM_EXTRA_CHECKING
  21. #define LOCKHDR(_pHdr, _psr) \
  22. RmWriteLockObject((_pHdr), dbg_func_locid, (_psr))
  23. #else // !RM_EXTRA_CHECKING
  24. #define LOCKHDR(_pHdr, _psr) \
  25. RmWriteLockObject((_pHdr), (_psr))
  26. #endif // !RM_EXTRA_CHECKING
  27. #define LOCKOBJ(_pObj, _psr) \
  28. LOCKHDR(&(_pObj)->Hdr, (_psr))
  29. #define UNLOCKHDR(_pHdr, _psr) \
  30. RmUnlockObject((_pHdr), (_psr))
  31. #define UNLOCKOBJ(_pObj, _psr) \
  32. UNLOCKHDR(&(_pObj)->Hdr, (_psr))
  33. #define EPVC_ALLOCSTRUCT(_p, _tag) \
  34. NdisAllocateMemoryWithTag(&(_p), sizeof(*(_p)), (_tag))
  35. #define EPVC_FREE(_p) NdisFreeMemory((_p), 0, 0)
  36. #define EPVC_ZEROSTRUCT(_p) \
  37. NdisZeroMemory((_p), sizeof(*(_p)))
  38. #define ARRAY_LENGTH(_array) (sizeof(_array)/sizeof((_array)[0]))
  39. #if RM_EXTRA_CHECKING
  40. #define DBG_ADDASSOC(_phdr, _e1, _e2, _assoc, _fmt, _psr)\
  41. RmDbgAddAssociation( \
  42. dbg_func_locid, \
  43. (_phdr), \
  44. (UINT_PTR) (_e1), \
  45. (UINT_PTR) (_e2), \
  46. (_assoc), \
  47. (_fmt), \
  48. (_psr) \
  49. )
  50. #define DBG_DELASSOC(_phdr, _e1, _e2, _assoc, _psr) \
  51. RmDbgDeleteAssociation( \
  52. dbg_func_locid, \
  53. (_phdr), \
  54. (UINT_PTR) (_e1), \
  55. (UINT_PTR) (_e2), \
  56. (_assoc), \
  57. (_psr) \
  58. )
  59. // (debug only) Enumeration of types of associations.
  60. //
  61. #else // !RM_EXTRA_CHECKING
  62. #define DBG_ADDASSOC(_phdr, _e1, _e2, _assoc, _fmt, _psr) (0)
  63. #define DBG_DELASSOC(_phdr, _e1, _e2, _assoc, _psr) (0)
  64. #endif // !RM_EXTRA_CHECKING
  65. #define EPVC_ATPASSIVE() (KeGetCurrentIrql()==PASSIVE_LEVEL)
  66. #if DO_TIMESTAMPS
  67. void
  68. epvcTimeStamp(
  69. char *szFormatString,
  70. UINT Val
  71. );
  72. #define TIMESTAMP(_FormatString) \
  73. epvcTimeStamp( "TIMESTAMP %lu:%lu.%lu ATMEPVC " _FormatString "\n", 0)
  74. #define TIMESTAMP1(_FormatString, _Val) \
  75. epvcTimeStamp( "TIMESTAMP %lu:%lu.%lu ATMEPVC " _FormatString "\n", (_Val))
  76. #else // !DO_TIMESTAMPS
  77. #define TIMESTAMP(_FormatString)
  78. #define TIMESTAMP1(_FormatString, _Val)
  79. #endif // !DO_TIMESTAMPS
  80. #define TRACE_BREAK(_Mod, Str) \
  81. TRACE (TL_A, _Mod, Str); \
  82. ASSERT (NdisStatus == NDIS_STATUS_SUCCESS); \
  83. break;
  84. #define GET_ADAPTER_FROM_MINIPORT(_pM) _pM->pAdapter
  85. //
  86. // Miniport Flag access routines
  87. //
  88. #define MiniportTestFlag(_A, _F) ((epvcReadFlags(&(_A)->Hdr.State) & (_F))!= 0)
  89. #define MiniportSetFlag(_A, _F) (epvcSetFlags(&(_A)->Hdr.State, (_F)))
  90. #define MiniportClearFlag(_A, _F) (epvcClearFlags(&(_A)->Hdr.State, (_F)))
  91. #define MiniportTestFlags(_A, _F) ((epvcReadFlags(&(_A)->Hdr.State) & (_F)) == (_F))
  92. //
  93. // Adapter Flag access routines
  94. //
  95. #define AdapterTestFlag(_A, _F) ((epvcReadFlags(&(_A)->Hdr.State) & (_F))!= 0)
  96. #define AdapterSetFlag(_A, _F) (epvcSetFlags(&(_A)->Hdr.State, (_F)))
  97. #define AdapterClearFlag(_A, _F) (epvcClearFlags(&(_A)->Hdr.State, (_F)))
  98. #define AdapterTestFlags(_A, _F) ((epvcReadFlags(&(_A)->Hdr.State) & (_F)) == (_F))
  99. #define epvcLinkToExternal(_Hdr, _Luid, _Ext, _Num, _Str, _sr) \
  100. RmLinkToExternalEx (_Hdr,_Luid,_Ext,_Num,_Str,_sr);
  101. #define epvcUnlinkFromExternal(_Hdr, _Luid, _Ext, _Assoc, _sr) \
  102. RmUnlinkFromExternalEx( \
  103. _Hdr, \
  104. _Luid, \
  105. _Ext, \
  106. _Assoc, \
  107. _sr \
  108. );
  109. /*++
  110. ULONG
  111. LINKSPEED_TO_CPS(
  112. IN ULONG LinkSpeed
  113. )
  114. Convert from NDIS "Link Speed" to cells per second
  115. --*/
  116. #define LINKSPEED_TO_CPS(_LinkSpeed) (((_LinkSpeed)*100)/(48*8))
  117. #define CALL_PARAMETER_SIZE sizeof(CO_CALL_PARAMETERS) + \
  118. sizeof(CO_CALL_MANAGER_PARAMETERS) + \
  119. sizeof(CO_MEDIA_PARAMETERS) + \
  120. sizeof(ATM_MEDIA_PARAMETERS)
  121. #define MP_OFFSET(field) ((UINT)FIELD_OFFSET(EPVC_I_MINIPORT,field))
  122. #define MP_SIZE(field) sizeof(((PEPVC_I_MINIPORT)0)->field)
  123. // All memory allocations and frees are done with these ALLOC_*/FREE_*
  124. // macros/inlines to allow memory management scheme changes without global
  125. // editing. For example, might choose to lump several lookaside lists of
  126. // nearly equal sized items into a single list for efficiency.
  127. //
  128. // NdisFreeMemory requires the length of the allocation as an argument. NT
  129. // currently doesn't use this for non-paged memory, but according to JameelH,
  130. // Windows95 does. These inlines stash the length at the beginning of the
  131. // allocation, providing the traditional malloc/free interface. The
  132. // stash-area is a ULONGLONG so that all allocated blocks remain ULONGLONG
  133. // aligned as they would be otherwise, preventing problems on Alphas.
  134. //
  135. __inline
  136. VOID*
  137. ALLOC_NONPAGED(
  138. IN ULONG ulBufLength,
  139. IN ULONG ulTag )
  140. {
  141. CHAR* pBuf;
  142. NdisAllocateMemoryWithTag(
  143. &pBuf, (UINT )(ulBufLength + MEMORY_ALLOCATION_ALIGNMENT), ulTag );
  144. if (!pBuf)
  145. {
  146. return NULL;
  147. }
  148. ((ULONG* )pBuf)[ 0 ] = ulBufLength;
  149. ((ULONG* )pBuf)[ 1 ] = ulTag;
  150. return (pBuf + MEMORY_ALLOCATION_ALIGNMENT);
  151. }
  152. __inline
  153. VOID
  154. FREE_NONPAGED(
  155. IN VOID* pBuf )
  156. {
  157. ULONG ulBufLen;
  158. ulBufLen = *((ULONG* )(((CHAR* )pBuf) - MEMORY_ALLOCATION_ALIGNMENT));
  159. NdisFreeMemory(
  160. ((CHAR* )pBuf) - MEMORY_ALLOCATION_ALIGNMENT,
  161. (UINT )(ulBufLen + MEMORY_ALLOCATION_ALIGNMENT),
  162. 0 );
  163. }
  164. #define CanMiniportIndicate(_M) (MiniportTestFlag(_M, fMP_MiniportInitialized)== TRUE)
  165. #define epvcIncrementMallocFailure()
  166. #define ASSERTAndBreak(_condition) ASSERT(_condition); break;
  167. #define epvcSetSendPktStats()
  168. #define epvcSendCompleteStats()
  169. #endif