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.

177 lines
4.5 KiB

  1. // Copyright (c) 1997, Microsoft Corporation, all rights reserved
  2. //
  3. // ppool.h
  4. // RAS L2TP WAN mini-port/call-manager driver
  5. // Packet pool management header
  6. //
  7. // 01/07/97 Steve Cobb, adapted from Gurdeep's WANARP code.
  8. #ifndef _PPOOL_H_
  9. #define _PPOOL_H_
  10. //-----------------------------------------------------------------------------
  11. // Data structures
  12. //-----------------------------------------------------------------------------
  13. // Packet pool control block. A packet pool encapsulates an NDIS packet pool
  14. // handling all pool growth and shrinkage internally.
  15. //
  16. typedef struct
  17. _PACKETPOOL
  18. {
  19. // Size in bytes of the ProtocolReserved array for each packet in the
  20. // pool.
  21. //
  22. ULONG ulProtocolReservedLength;
  23. // The optimal number of packets to allocate in each packet block.
  24. //
  25. ULONG ulPacketsPerBlock;
  26. // Maximum number of individual packets that may be allocated in the
  27. // entire pool, or 0 for unlimited.
  28. //
  29. ULONG ulMaxPackets;
  30. // Current number of individual packets allocated in the entire pool.
  31. //
  32. ULONG ulCurPackets;
  33. // Garbage collection occurs after this many calls to FreePacketToPool.
  34. //
  35. ULONG ulFreesPerCollection;
  36. // Number of calls to FreeBufferToPool since a garbage collection.
  37. //
  38. ULONG ulFreesSinceCollection;
  39. // Memory identification tag for allocated blocks.
  40. //
  41. ULONG ulTag;
  42. // Head of the double linked list of PACKETBLOCKHEADs. Access to the list
  43. // is protected with 'lock' in this structure.
  44. //
  45. LIST_ENTRY listBlocks;
  46. // Head of the double linked list of free PACKETHEADs. Each PACKETHEAD in
  47. // the list is ready to go, i.e. it already has an NDIS_PACKET associated
  48. // with it. Access to the list is prototected by 'lock' in this
  49. // structure. Interlocked push/pop is not used because (a) the list of
  50. // blocks and this list must lock each other and (b) double links are
  51. // necessary for garbage collection.
  52. //
  53. LIST_ENTRY listFreePackets;
  54. // This lock protects this structure and both the list of blocks and the
  55. // list of packets.
  56. //
  57. NDIS_SPIN_LOCK lock;
  58. }
  59. PACKETPOOL;
  60. // Header of a single block of packets from a packet pool. The PACKETHEAD of
  61. // the first buffer immediately follows.
  62. //
  63. typedef struct
  64. _PACKETBLOCKHEAD
  65. {
  66. // Links to the prev/next packet block header in the packet pool's list.
  67. //
  68. LIST_ENTRY linkBlocks;
  69. // NDIS's handle of the pool of NDIS_PACKET descriptors associated with
  70. // this block, or NULL if none.
  71. //
  72. NDIS_HANDLE hNdisPool;
  73. // Back pointer to the packet pool.
  74. //
  75. PACKETPOOL* pPool;
  76. // Number of individual packets in this block.
  77. //
  78. ULONG ulPackets;
  79. // Number of individual packets in this block on the free list.
  80. //
  81. ULONG ulFreePackets;
  82. }
  83. PACKETBLOCKHEAD;
  84. // Control information for an individual packet. For the packet pool, this
  85. // "header" does not actually preceed anything, but this keeps the terminology
  86. // consistent with the very similar buffer pool routines.
  87. //
  88. typedef struct
  89. _PACKETHEAD
  90. {
  91. // Link to next packet header in the packet pool's free list.
  92. //
  93. LIST_ENTRY linkFreePackets;
  94. // Back link to owning packet block header.
  95. //
  96. PACKETBLOCKHEAD* pBlock;
  97. // NDIS packet descriptor of this buffer.
  98. //
  99. NDIS_PACKET* pNdisPacket;
  100. }
  101. PACKETHEAD;
  102. //-----------------------------------------------------------------------------
  103. // Interface prototypes and inline definitions
  104. //-----------------------------------------------------------------------------
  105. VOID
  106. InitPacketPool(
  107. OUT PACKETPOOL* pPool,
  108. IN ULONG ulProtocolReservedLength,
  109. IN ULONG ulMaxPackets,
  110. IN ULONG ulPacketsPerBlock,
  111. IN ULONG ulFreesPerCollection,
  112. IN ULONG ulTag );
  113. BOOLEAN
  114. FreePacketPool(
  115. IN PACKETPOOL* pPool );
  116. NDIS_PACKET*
  117. GetPacketFromPool(
  118. IN PACKETPOOL* pPool,
  119. OUT PACKETHEAD** ppHead );
  120. VOID
  121. FreePacketToPool(
  122. IN PACKETPOOL* pPool,
  123. IN PACKETHEAD* pHead,
  124. IN BOOLEAN fGarbageCollection );
  125. PACKETPOOL*
  126. PacketPoolFromPacketHead(
  127. IN PACKETHEAD* pHead );
  128. VOID
  129. CollectPacketPoolGarbage(
  130. PACKETPOOL* pPool );
  131. __inline
  132. PACKETPOOL*
  133. PacketPoolFromPacketHead(
  134. IN PACKETHEAD* pHead )
  135. // Returns the address of the pool, given 'pHead', the address of a
  136. // PACKETHEAD like the one returned from GetPacketFromPool.
  137. //
  138. {
  139. return pHead->pBlock->pPool;
  140. }
  141. #endif // PPOOL_H_