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.

306 lines
13 KiB

  1. /***************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. INIT.C
  5. Abstract:
  6. Remote NDIS Miniport driver initialization code
  7. Environment:
  8. kernel mode only
  9. Notes:
  10. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  11. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  12. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  13. PURPOSE.
  14. Copyright (c) 1999 Microsoft Corporation. All Rights Reserved.
  15. Revision History:
  16. 5/13/99 : created
  17. Author:
  18. Tom Green
  19. ****************************************************************************/
  20. #include "precomp.h"
  21. extern ULONG MsgFrameAllocs;
  22. /****************************************************************************/
  23. /* SetupSendQueues */
  24. /****************************************************************************/
  25. /* */
  26. /* Routine Description: */
  27. /* */
  28. /* Set up queues for sending packets to microport */
  29. /* */
  30. /* Arguments: */
  31. /* */
  32. /* Adapter - adapter object */
  33. /* */
  34. /* Return: */
  35. /* */
  36. /* NDIS_STATUS */
  37. /* */
  38. /****************************************************************************/
  39. NDIS_STATUS
  40. SetupSendQueues(IN PRNDISMP_ADAPTER Adapter)
  41. {
  42. NdisInitializeNPagedLookasideList(
  43. &Adapter->MsgFramePool,
  44. NULL,
  45. NULL,
  46. 0,
  47. sizeof(RNDISMP_MESSAGE_FRAME),
  48. RNDISMP_TAG_SEND_FRAME,
  49. 0);
  50. Adapter->MsgFramePoolAlloced = TRUE;
  51. return NDIS_STATUS_SUCCESS;
  52. } // SetupSendQueues
  53. /****************************************************************************/
  54. /* SetupReceiveQueues */
  55. /****************************************************************************/
  56. /* */
  57. /* Routine Description: */
  58. /* */
  59. /* Allocate resources for receiving packets from the microport */
  60. /* */
  61. /* Arguments: */
  62. /* */
  63. /* Adapter - adapter object */
  64. /* */
  65. /* Return: */
  66. /* */
  67. /* NDIS_STATUS */
  68. /* */
  69. /****************************************************************************/
  70. NDIS_STATUS
  71. SetupReceiveQueues(IN PRNDISMP_ADAPTER Adapter)
  72. {
  73. NDIS_STATUS AllocationStatus;
  74. UINT Index;
  75. TRACE2(("SetupReceiveQueues\n"));
  76. do
  77. {
  78. Adapter->InitialReceiveFrames = INITIAL_RECEIVE_FRAMES;
  79. Adapter->MaxReceiveFrames = MAX_RECEIVE_FRAMES;
  80. // Set up a pool of receive data frame structures
  81. NdisInitializeNPagedLookasideList(
  82. &Adapter->RcvFramePool,
  83. NULL,
  84. NULL,
  85. 0,
  86. sizeof(RNDISMP_RECV_DATA_FRAME),
  87. RNDISMP_TAG_RECV_DATA_FRAME,
  88. 0);
  89. Adapter->RcvFramePoolAlloced = TRUE;
  90. // Set up a pool of packets for indicating groups of packets to NDIS
  91. NdisAllocatePacketPoolEx(&AllocationStatus,
  92. &Adapter->ReceivePacketPool,
  93. Adapter->InitialReceiveFrames,
  94. Adapter->MaxReceiveFrames,
  95. NUM_BYTES_PROTOCOL_RESERVED_SECTION);
  96. if (AllocationStatus != NDIS_STATUS_SUCCESS)
  97. {
  98. TRACE2(("NdisAllocatePacketPool failed (%08X)\n", AllocationStatus));
  99. break;
  100. }
  101. // Set up our pool of buffer descriptors one per packet
  102. NdisAllocateBufferPool(&AllocationStatus,
  103. &Adapter->ReceiveBufferPool,
  104. Adapter->MaxReceiveFrames);
  105. if (AllocationStatus != NDIS_STATUS_SUCCESS)
  106. {
  107. TRACE2(("NdisAllocateBufferPool failed (%08X)\n", AllocationStatus));
  108. break;
  109. }
  110. }
  111. while (FALSE);
  112. if (AllocationStatus != NDIS_STATUS_SUCCESS)
  113. {
  114. FreeReceiveResources(Adapter);
  115. }
  116. return AllocationStatus;
  117. } // SetupReceiveQueues
  118. /****************************************************************************/
  119. /* AllocateTransportResources */
  120. /****************************************************************************/
  121. /* */
  122. /* Routine Description: */
  123. /* */
  124. /* Allocate resources for transmit, receive, and requests */
  125. /* */
  126. /* Arguments: */
  127. /* */
  128. /* Adapter - adapter object */
  129. /* */
  130. /* Return: */
  131. /* */
  132. /* NDIS_STATUS */
  133. /* */
  134. /****************************************************************************/
  135. NDIS_STATUS
  136. AllocateTransportResources(IN PRNDISMP_ADAPTER Adapter)
  137. {
  138. NDIS_STATUS Status;
  139. TRACE2(("AllocateTransportResources\n"));
  140. Status = SetupSendQueues(Adapter);
  141. if(Status != NDIS_STATUS_SUCCESS)
  142. {
  143. goto AllocateDone;
  144. }
  145. Status = SetupReceiveQueues(Adapter);
  146. if(Status != NDIS_STATUS_SUCCESS)
  147. {
  148. FreeSendResources(Adapter);
  149. goto AllocateDone;
  150. }
  151. AllocateDone:
  152. return Status;
  153. } // AllocateTransportResources
  154. /****************************************************************************/
  155. /* FreeTransportResources */
  156. /****************************************************************************/
  157. /* */
  158. /* Routine Description: */
  159. /* */
  160. /* Free up resources for transmit, receive, and requests */
  161. /* */
  162. /* Arguments: */
  163. /* */
  164. /* Adapter - adapter object */
  165. /* */
  166. /* Return: */
  167. /* */
  168. /* VOID */
  169. /* */
  170. /****************************************************************************/
  171. VOID
  172. FreeTransportResources(IN PRNDISMP_ADAPTER Adapter)
  173. {
  174. TRACE2(("FreeTransportResources\n"));
  175. FreeSendResources(Adapter);
  176. FreeReceiveResources(Adapter);
  177. } // FreeTransportResources
  178. /****************************************************************************/
  179. /* FreeSendResources */
  180. /****************************************************************************/
  181. /* */
  182. /* Routine Description: */
  183. /* */
  184. /* Free up resources for sending packets */
  185. /* */
  186. /* Arguments: */
  187. /* */
  188. /* Adapter - adapter object */
  189. /* */
  190. /* Return: */
  191. /* */
  192. /* VOID */
  193. /* */
  194. /****************************************************************************/
  195. VOID
  196. FreeSendResources(IN PRNDISMP_ADAPTER Adapter)
  197. {
  198. TRACE3(("FreeSendResources\n"));
  199. if (Adapter->MsgFramePoolAlloced)
  200. {
  201. NdisDeleteNPagedLookasideList(&Adapter->MsgFramePool);
  202. Adapter->MsgFramePoolAlloced = FALSE;
  203. }
  204. } // FreeSendResources
  205. /****************************************************************************/
  206. /* FreeReceiveResources */
  207. /****************************************************************************/
  208. /* */
  209. /* Routine Description: */
  210. /* */
  211. /* Free up resources allocated for receiving packets */
  212. /* */
  213. /* Arguments: */
  214. /* */
  215. /* Adapter - adapter object */
  216. /* */
  217. /* Return: */
  218. /* */
  219. /* VOID */
  220. /* */
  221. /****************************************************************************/
  222. VOID
  223. FreeReceiveResources(IN PRNDISMP_ADAPTER Adapter)
  224. {
  225. UINT Index;
  226. UINT Size;
  227. PUCHAR Buffer;
  228. TRACE3(("FreeReceiveResources\n"));
  229. // free up buffer pool
  230. if (Adapter->ReceiveBufferPool)
  231. {
  232. NdisFreeBufferPool(Adapter->ReceiveBufferPool);
  233. Adapter->ReceiveBufferPool = NULL;
  234. }
  235. // free up packet pool
  236. if (Adapter->ReceivePacketPool)
  237. {
  238. NdisFreePacketPool(Adapter->ReceivePacketPool);
  239. Adapter->ReceivePacketPool = NULL;
  240. }
  241. // delete receive data frame pool.
  242. if (Adapter->RcvFramePoolAlloced)
  243. {
  244. NdisDeleteNPagedLookasideList(&Adapter->RcvFramePool);
  245. Adapter->RcvFramePoolAlloced = FALSE;
  246. }
  247. } // FreeReceiveResources