Windows NT 4.0 source code leak
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.

344 lines
7.8 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. ltreset.c
  5. Abstract:
  6. This module contains
  7. Author:
  8. Nikhil Kamkolkar (nikhilk@microsoft.com)
  9. Stephen Hou (stephh@microsoft.com)
  10. Revision History:
  11. 19 Jun 1992 Initial Version (dch@pacvax.pacersoft.com)
  12. Notes: Tab stop: 4
  13. --*/
  14. #define LTRESET_H_LOCALS
  15. #include "ltmain.h"
  16. #include "ltreset.h"
  17. #include "ltfirm.h"
  18. #include "lttimer.h"
  19. // Define file id for errorlogging
  20. #define FILENUM LTRESET
  21. NDIS_STATUS
  22. LtReset(
  23. IN NDIS_HANDLE MacBindingHandle
  24. )
  25. /*++
  26. Routine Description:
  27. called by NDIS to reset the adapter
  28. Arguments:
  29. MacBindingHandle : context passed back in OpenAdapter
  30. Return Value:
  31. NDIS_STATUS_PENDING : if the reset successfully pended
  32. and waiting to be completed
  33. NDIS_STATUS_RESET_IN_PROGRESS : if the adapter is current being reset
  34. NDIS_STATUS_ADAPTER_REMOVED : if the adapter has been closed
  35. NDIS_STATUS_CLOSING : if the binding request the reset is closing
  36. --*/
  37. {
  38. NDIS_STATUS Status;
  39. BOOLEAN TimerCancelled = FALSE;
  40. PLT_ADAPTER Adapter = ((PLT_OPEN)MacBindingHandle)->LtAdapter;
  41. PLT_OPEN Open = (PLT_OPEN)MacBindingHandle;
  42. LtReferenceBinding(Open,&Status);
  43. if (Status == NDIS_STATUS_SUCCESS)
  44. {
  45. if (Adapter->Flags & ADAPTER_RESET_IN_PROGRESS)
  46. {
  47. Status = NDIS_STATUS_RESET_IN_PROGRESS;
  48. }
  49. if (Adapter->Flags & ADAPTER_CLOSING)
  50. {
  51. Status = NDIS_STATUS_ADAPTER_REMOVED;
  52. }
  53. if (Open->Flags & BINDING_CLOSING)
  54. {
  55. Status = NDIS_STATUS_CLOSING;
  56. }
  57. }
  58. if (Status != NDIS_STATUS_SUCCESS)
  59. {
  60. LtDeReferenceBinding(Open);
  61. return(Status);
  62. }
  63. // kill the timer so we don't get any conflicts when trying to reset the card
  64. NdisCancelTimer(&Adapter->PollingTimer, &TimerCancelled);
  65. if (TimerCancelled)
  66. {
  67. LtDeReferenceAdapter(Adapter);
  68. }
  69. // indicate the start of the reset to all bindings
  70. LtResetSignalBindings(
  71. Adapter,
  72. NDIS_STATUS_RESET_START);
  73. NdisAcquireSpinLock(&Adapter->Lock);
  74. // set the reset in progress flag
  75. Adapter->Flags ^= ADAPTER_RESET_IN_PROGRESS;
  76. Adapter->ResetOwner = Open;
  77. NdisReleaseSpinLock(&Adapter->Lock);
  78. LtResetSetupForReset(Adapter);
  79. // intstantiate the reference for the timer
  80. // too late to do anything other than return
  81. // success since the reset's done. no problem
  82. // as long as the adapter can't close while the
  83. // reset is in progress.
  84. LtReferenceAdapter(Adapter,&Status);
  85. // card's essentially reset, restart the timer
  86. NdisSetTimer(&Adapter->PollingTimer, LT_POLLING_TIME);
  87. return(NDIS_STATUS_PENDING);
  88. }
  89. VOID
  90. LtResetComplete(
  91. PLT_ADAPTER Adapter
  92. )
  93. /*++
  94. Routine Description:
  95. completes the pending reset
  96. Arguments:
  97. Adapter : pointer to the logical adapter
  98. Return Value:
  99. none
  100. --*/
  101. {
  102. NdisAcquireSpinLock(&Adapter->Lock);
  103. // flip the reset in progress flags
  104. Adapter->Flags ^= ADAPTER_RESET_IN_PROGRESS;
  105. NdisReleaseSpinLock(&Adapter->Lock);
  106. LtResetSignalBindings(
  107. Adapter,
  108. NDIS_STATUS_RESET_END);
  109. NdisCompleteReset(
  110. (Adapter->ResetOwner)->NdisBindingContext,
  111. NDIS_STATUS_SUCCESS);
  112. LtDeReferenceBinding(Adapter->ResetOwner);
  113. }
  114. STATIC
  115. VOID
  116. LtResetSetupForReset(
  117. IN PLT_ADAPTER Adapter
  118. )
  119. /*++
  120. Routine Description:
  121. Kills off anything in the transmit, receive and loopback queues and
  122. returns the appropriate status. It then resets the card and acquires
  123. a new NodeId
  124. Arguments:
  125. Adapter : pointer to the logical adapter
  126. Return Value:
  127. none
  128. --*/
  129. {
  130. PLIST_ENTRY CurrentPacketLink;
  131. PLT_PACKET_RESERVED PacketReserved;
  132. PRECV_DESC RecvDesc;
  133. UINT PacketLength;
  134. PNDIS_PACKET Packet;
  135. PLT_OPEN Open;
  136. NdisAcquireSpinLock(&Adapter->Lock);
  137. // remove everything from the receive list and return it to the free list
  138. while(!IsListEmpty(&Adapter->Receive)){
  139. CurrentPacketLink = RemoveHeadList(&Adapter->Receive);
  140. RecvDesc = CONTAINING_RECORD(
  141. CurrentPacketLink,
  142. RECV_DESC,
  143. Linkage);
  144. PacketLength = RecvDesc->BufferLength;
  145. NdisFreeMemory(
  146. RecvDesc,
  147. sizeof(RecvDesc)+PacketLength,
  148. 0);
  149. }
  150. // complete any pending transmits
  151. while(!IsListEmpty(&Adapter->Transmit))
  152. {
  153. CurrentPacketLink = RemoveHeadList(&Adapter->Transmit);
  154. PacketReserved = CONTAINING_RECORD(
  155. CurrentPacketLink,
  156. LT_PACKET_RESERVED,
  157. Linkage);
  158. Packet = CONTAINING_RECORD(
  159. PacketReserved,
  160. NDIS_PACKET,
  161. MacReserved);
  162. Open = PacketReserved->MacBindingHandle;
  163. NdisReleaseSpinLock(&Adapter->Lock);
  164. NdisCompleteSend(
  165. Open->NdisBindingContext,
  166. Packet,
  167. NDIS_STATUS_REQUEST_ABORTED);
  168. // decrement the count instantiated by the send
  169. LtDeReferenceBinding(Open);
  170. LtDeReferenceAdapter(Adapter);
  171. NdisAcquireSpinLock(&Adapter->Lock);
  172. }
  173. // complete anything on the loopback queue
  174. while(!IsListEmpty(&Adapter->LoopBack))
  175. {
  176. CurrentPacketLink = RemoveHeadList(&Adapter->LoopBack);
  177. PacketReserved = CONTAINING_RECORD(
  178. CurrentPacketLink,
  179. LT_PACKET_RESERVED,
  180. Linkage);
  181. Packet = CONTAINING_RECORD(
  182. PacketReserved,
  183. NDIS_PACKET,
  184. MacReserved);
  185. Open = PacketReserved->MacBindingHandle;
  186. NdisReleaseSpinLock(&Adapter->Lock);
  187. NdisCompleteSend(
  188. Open->NdisBindingContext,
  189. Packet,
  190. NDIS_STATUS_REQUEST_ABORTED);
  191. // decrement the count instantiated by the send
  192. LtDeReferenceBinding(Open);
  193. LtDeReferenceAdapter(Adapter);
  194. NdisAcquireSpinLock(&Adapter->Lock);
  195. }
  196. NdisReleaseSpinLock(&Adapter->Lock);
  197. LtFirmInitialize(Adapter, Adapter->NodeId);
  198. }
  199. STATIC
  200. VOID
  201. LtResetSignalBindings(
  202. PLT_ADAPTER Adapter,
  203. NDIS_STATUS StatusToSignal
  204. )
  205. /*++
  206. Routine Description:
  207. Loops through all bindings and indicates the status passed
  208. Arguments:
  209. Adapter : pointer to the logical adapter
  210. StatusToSignal : status to indicate to all bindings associated with the adapter
  211. Return Value:
  212. none
  213. --*/
  214. {
  215. PLT_OPEN Open;
  216. PLIST_ENTRY CurrentLink;
  217. NDIS_STATUS Status;
  218. CurrentLink = Adapter->OpenBindings.Flink;
  219. while (CurrentLink != &Adapter->OpenBindings)
  220. {
  221. Open = CONTAINING_RECORD(
  222. CurrentLink,
  223. LT_OPEN,
  224. Linkage
  225. );
  226. // skip the binding if it's closing
  227. if (Open->Flags & BINDING_CLOSING)
  228. {
  229. CurrentLink = CurrentLink->Flink;
  230. continue;
  231. }
  232. // increment the reference count while in the binding
  233. // only return we can get back is that the binding is
  234. // closing down, but this isn't a problem since we won't
  235. // reach this statement if that's true because of the prior
  236. // statements
  237. LtReferenceBinding(Open,&Status);
  238. NdisIndicateStatus(
  239. Open->NdisBindingContext,
  240. StatusToSignal,
  241. 0,
  242. 0);
  243. // decrement refcount now that we've finished with that binding
  244. LtDeReferenceBinding(Open);
  245. CurrentLink = CurrentLink->Flink;
  246. }
  247. }