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.

220 lines
4.6 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. ppool.h
  5. Abstract:
  6. Structures and #defines for managing NDIS_PACKET pools. This is
  7. merely a reformatted version of SteveC's l2tp\ppool.h
  8. Revision History:
  9. --*/
  10. #ifndef __IPINIP_PPOOL_H__
  11. #define __IPINIP_PPOOL_H___
  12. //
  13. // Data structures
  14. //
  15. //
  16. // Packet pool control block. A packet pool encapsulates an NDIS packet pool
  17. // handling all pool growth and shrinkage internally.
  18. //
  19. typedef struct _PACKET_POOL
  20. {
  21. //
  22. // Size in bytes of the ProtocolReserved array for each packet in the
  23. // pool.
  24. //
  25. ULONG ulProtocolReservedLength;
  26. //
  27. // The optimal number of packets to allocate in each packet block.
  28. //
  29. ULONG ulPacketsPerBlock;
  30. //
  31. // Maximum number of individual packets that may be allocated in the
  32. // entire pool, or 0 for unlimited.
  33. //
  34. ULONG ulMaxPackets;
  35. //
  36. // Current number of individual packets allocated in the entire pool.
  37. //
  38. ULONG ulCurPackets;
  39. //
  40. // Garbage collection occurs after this many calls to FreePacketToPool.
  41. //
  42. ULONG ulFreesPerCollection;
  43. //
  44. // Number of calls to FreeBufferToPool since a garbage collection.
  45. //
  46. ULONG ulFreesSinceCollection;
  47. //
  48. // Memory identification tag for allocated blocks.
  49. //
  50. ULONG ulTag;
  51. //
  52. // Head of the double linked list of PACKET_BLOCKs. Access to the
  53. // list is protected with 'lock' in this structure.
  54. //
  55. LIST_ENTRY leBlockHead;
  56. //
  57. // Head of the double linked list of free PACKET_HEADs. Each
  58. // PACKET_HEAD in the list is ready to go, i.e. it already has an
  59. // NDIS_PACKET associated with it.
  60. // Access to the list is prototected by 'lock' in this structure.
  61. // Interlocked push/pop is not used because (a) the list of
  62. // blocks and this list must lock each other and (b) double links are
  63. // necessary for garbage collection.
  64. //
  65. LIST_ENTRY leFreePktHead;
  66. //
  67. // This lock protects this structure and both the list of blocks and the
  68. // list of packets.
  69. //
  70. RT_LOCK rlLock;
  71. }PACKET_POOL, *PPACKET_POOL;
  72. //
  73. // Header of a single block of packets from a packet pool. The PACKET_HEAD of
  74. // the first buffer immediately follows.
  75. //
  76. typedef struct _PACKET_BLOCK
  77. {
  78. //
  79. // Links to the prev/next packet block header in the packet pool's list.
  80. //
  81. LIST_ENTRY leBlockLink;
  82. //
  83. // NDIS's handle of the pool of NDIS_PACKET descriptors associated with
  84. // this block, or NULL if none.
  85. //
  86. NDIS_HANDLE nhNdisPool;
  87. //
  88. // Back pointer to the packet pool.
  89. //
  90. PPACKET_POOL pPool;
  91. //
  92. // Number of individual packets in this block.
  93. //
  94. ULONG ulPackets;
  95. //
  96. // Number of individual packets in this block on the free list.
  97. //
  98. ULONG ulFreePackets;
  99. }PACKET_BLOCK ,*PPACKET_BLOCK;
  100. //
  101. // Control information for an individual packet. For the packet pool, this
  102. // "header" does not actually preceed anything, but this keeps the terminology
  103. // consistent with the very similar buffer pool routines.
  104. //
  105. typedef struct _PACKET_HEAD
  106. {
  107. //
  108. // Link to next packet header in the packet pool's free list.
  109. //
  110. LIST_ENTRY leFreePktLink;
  111. //
  112. // Back link to owning packet block header.
  113. //
  114. PPACKET_BLOCK pBlock;
  115. //
  116. // NDIS packet descriptor of this buffer.
  117. //
  118. PNDIS_PACKET pNdisPacket;
  119. }PACKET_HEAD, *PPACKET_HEAD;
  120. //-----------------------------------------------------------------------------
  121. // Interface prototypes and inline definitions
  122. //-----------------------------------------------------------------------------
  123. VOID
  124. InitPacketPool(
  125. OUT PPACKET_POOL pPool,
  126. IN ULONG ulProtocolReservedLength,
  127. IN ULONG ulMaxPackets,
  128. IN ULONG ulPacketsPerBlock,
  129. IN ULONG ulFreesPerCollection,
  130. IN ULONG ulTag
  131. );
  132. BOOLEAN
  133. FreePacketPool(
  134. IN PPACKET_POOL pPool
  135. );
  136. PNDIS_PACKET
  137. GetPacketFromPool(
  138. IN PPACKET_POOL pPool,
  139. OUT PACKET_HEAD **ppHead
  140. );
  141. VOID
  142. FreePacketToPool(
  143. IN PPACKET_POOL pPool,
  144. IN PPACKET_HEAD pHead,
  145. IN BOOLEAN fGarbageCollection
  146. );
  147. //
  148. // PPACKET_POOL
  149. // PacketPoolFromPacketHead(
  150. // IN PPACKET_HEAD pHead
  151. // );
  152. //
  153. #define PacketPoolFromPacketHead(pHead) \
  154. ((pHead)->pBlock->pPool)
  155. #endif // __IPINIP_PPOOL_H__