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.

307 lines
12 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. ASSERT(MsgFrameAllocs == 0);
  202. NdisDeleteNPagedLookasideList(&Adapter->MsgFramePool);
  203. Adapter->MsgFramePoolAlloced = FALSE;
  204. }
  205. } // FreeSendResources
  206. /****************************************************************************/
  207. /* FreeReceiveResources */
  208. /****************************************************************************/
  209. /* */
  210. /* Routine Description: */
  211. /* */
  212. /* Free up resources allocated for receiving packets */
  213. /* */
  214. /* Arguments: */
  215. /* */
  216. /* Adapter - adapter object */
  217. /* */
  218. /* Return: */
  219. /* */
  220. /* VOID */
  221. /* */
  222. /****************************************************************************/
  223. VOID
  224. FreeReceiveResources(IN PRNDISMP_ADAPTER Adapter)
  225. {
  226. UINT Index;
  227. UINT Size;
  228. PUCHAR Buffer;
  229. TRACE3(("FreeReceiveResources\n"));
  230. // free up buffer pool
  231. if (Adapter->ReceiveBufferPool)
  232. {
  233. NdisFreeBufferPool(Adapter->ReceiveBufferPool);
  234. Adapter->ReceiveBufferPool = NULL;
  235. }
  236. // free up packet pool
  237. if (Adapter->ReceivePacketPool)
  238. {
  239. NdisFreePacketPool(Adapter->ReceivePacketPool);
  240. Adapter->ReceivePacketPool = NULL;
  241. }
  242. // delete receive data frame pool.
  243. if (Adapter->RcvFramePoolAlloced)
  244. {
  245. NdisDeleteNPagedLookasideList(&Adapter->RcvFramePool);
  246. Adapter->RcvFramePoolAlloced = FALSE;
  247. }
  248. } // FreeReceiveResources