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.

441 lines
12 KiB

  1. /*++
  2. Copyright (c) 1990-1997 Microsoft Corporation
  3. Module Name:
  4. mp.c
  5. Abstract:
  6. This file contains the routines that asyncmac uses to present
  7. the NDIS 5.0 miniport interface
  8. Author:
  9. Tony Bell (TonyBe) May 20, 1997
  10. Environment:
  11. Kernel Mode
  12. Revision History:
  13. TonyBe 05/20/97 Created
  14. --*/
  15. #include "asyncall.h"
  16. extern NDIS_HANDLE NdisWrapperHandle;
  17. VOID
  18. MpHalt(
  19. IN NDIS_HANDLE MiniportAdapterContext
  20. )
  21. {
  22. PASYNC_ADAPTER Adapter = (PASYNC_ADAPTER)MiniportAdapterContext;
  23. DbgTracef(0,("AsyncMac: In MpHalt\n"));
  24. NdisAcquireSpinLock(&GlobalLock);
  25. ASSERT(Adapter == GlobalAdapter);
  26. #if DBG
  27. if (InterlockedCompareExchange(&glConnectionCount, 0, 0) != 0) {
  28. DbgPrint("MpHalt with outstanding connections!\n");
  29. DbgBreakPoint();
  30. }
  31. #endif
  32. GlobalAdapterCount--;
  33. GlobalAdapter = NULL;
  34. NdisReleaseSpinLock(&GlobalLock);
  35. ExDeleteNPagedLookasideList(&Adapter->AsyncFrameList);
  36. #ifndef MY_DEVICE_OBJECT
  37. if (AsyncDeviceHandle != NULL) {
  38. NdisMDeregisterDevice(AsyncDeviceHandle);
  39. AsyncDeviceHandle = NULL;
  40. AsyncDeviceObject = NULL;
  41. }
  42. #endif
  43. ExFreePool(Adapter);
  44. return;
  45. }
  46. NDIS_STATUS
  47. MpInit(
  48. OUT PNDIS_STATUS OpenErrorStatus,
  49. OUT PUINT SelectedMediumIndex,
  50. IN PNDIS_MEDIUM MediumArray,
  51. IN UINT MediumArraySize,
  52. IN NDIS_HANDLE MiniportAdapterHandle,
  53. IN NDIS_HANDLE WrapperConfigurationContext
  54. )
  55. {
  56. //
  57. // Pointer for the adapter root.
  58. //
  59. PASYNC_ADAPTER Adapter;
  60. NDIS_HANDLE ConfigHandle;
  61. PNDIS_CONFIGURATION_PARAMETER ReturnedValue;
  62. NDIS_STRING PortsStr = NDIS_STRING_CONST("Ports");
  63. NDIS_STRING IrpStackSizeStr = NDIS_STRING_CONST("IrpStackSize");
  64. NDIS_STRING MaxFrameSizeStr = NDIS_STRING_CONST("MaxFrameSize");
  65. NDIS_STRING FramesPerPortStr= NDIS_STRING_CONST("FramesPerPort");
  66. NDIS_STRING XonXoffStr = NDIS_STRING_CONST("XonXoff");
  67. NDIS_STRING TimeoutBaseStr= NDIS_STRING_CONST("TimeoutBase");
  68. NDIS_STRING TimeoutBaudStr= NDIS_STRING_CONST("TimeoutBaud");
  69. NDIS_STRING TimeoutReSyncStr= NDIS_STRING_CONST("TimeoutReSync");
  70. NDIS_STRING WriteBufferingStr= NDIS_STRING_CONST("WriteBufferingEnabled");
  71. NDIS_STATUS Status;
  72. // assign some defaults if these strings are not found in the registry
  73. UCHAR irpStackSize = DEFAULT_IRP_STACK_SIZE;
  74. ULONG maxFrameSize = DEFAULT_MAX_FRAME_SIZE;
  75. USHORT framesPerPort = DEFAULT_FRAMES_PER_PORT;
  76. ULONG xonXoff = DEFAULT_XON_XOFF;
  77. ULONG timeoutBase = DEFAULT_TIMEOUT_BASE;
  78. ULONG timeoutBaud = DEFAULT_TIMEOUT_BAUD;
  79. ULONG timeoutReSync = DEFAULT_TIMEOUT_RESYNC;
  80. ULONG WriteBufferingEnabled = 1;
  81. ULONG NeededFrameSize;
  82. UINT MaxMulticastList = 32;
  83. USHORT i; // counter
  84. //
  85. // We only support a single instance of AsyncMac
  86. //
  87. if (GlobalAdapterCount != 0) {
  88. return NDIS_STATUS_FAILURE;
  89. }
  90. for (i = 0; i < MediumArraySize; i++) {
  91. if (MediumArray[i] == NdisMediumWan) {
  92. break;
  93. }
  94. }
  95. if (i == MediumArraySize) {
  96. return (NDIS_STATUS_UNSUPPORTED_MEDIA);
  97. }
  98. *SelectedMediumIndex = i;
  99. //
  100. // Card specific information.
  101. //
  102. //
  103. // Allocate the Adapter block.
  104. //
  105. Adapter = (PASYNC_ADAPTER)
  106. ExAllocatePoolWithTag(NonPagedPool,
  107. sizeof(ASYNC_ADAPTER),
  108. ASYNC_ADAPTER_TAG);
  109. if (Adapter == NULL){
  110. DbgTracef(-1,("AsyncMac: Could not allocate physical memory!!!\n"));
  111. return NDIS_STATUS_RESOURCES;
  112. }
  113. ASYNC_ZERO_MEMORY(Adapter, sizeof(ASYNC_ADAPTER));
  114. Adapter->MiniportHandle = MiniportAdapterHandle;
  115. NdisOpenConfiguration(
  116. &Status,
  117. &ConfigHandle,
  118. WrapperConfigurationContext);
  119. if (Status != NDIS_STATUS_SUCCESS) {
  120. return NDIS_STATUS_FAILURE;
  121. }
  122. //
  123. // Read if the default IrpStackSize is used for this adapter.
  124. //
  125. NdisReadConfiguration(
  126. &Status,
  127. &ReturnedValue,
  128. ConfigHandle,
  129. &IrpStackSizeStr,
  130. NdisParameterInteger);
  131. if ( Status == NDIS_STATUS_SUCCESS ) {
  132. irpStackSize=(UCHAR)ReturnedValue->ParameterData.IntegerData;
  133. DbgTracef(0,("This MAC Adapter has an irp stack size of %u.\n",irpStackSize));
  134. }
  135. //
  136. // Read if the default MaxFrameSize is used for this adapter.
  137. //
  138. NdisReadConfiguration(
  139. &Status,
  140. &ReturnedValue,
  141. ConfigHandle,
  142. &MaxFrameSizeStr,
  143. NdisParameterInteger);
  144. if ( Status == NDIS_STATUS_SUCCESS ) {
  145. maxFrameSize=ReturnedValue->ParameterData.IntegerData;
  146. DbgTracef(0,("This MAC Adapter has a max frame size of %u.\n",maxFrameSize));
  147. }
  148. //
  149. // Read if the default for frames per port is changed
  150. //
  151. NdisReadConfiguration(
  152. &Status,
  153. &ReturnedValue,
  154. ConfigHandle,
  155. &FramesPerPortStr,
  156. NdisParameterInteger);
  157. if ( Status == NDIS_STATUS_SUCCESS ) {
  158. framesPerPort=(USHORT)ReturnedValue->ParameterData.IntegerData;
  159. DbgTracef(0,("This MAC Adapter has frames per port set to: %u.\n",framesPerPort));
  160. }
  161. //
  162. // Read if the default for Xon Xoff is changed
  163. //
  164. NdisReadConfiguration(
  165. &Status,
  166. &ReturnedValue,
  167. ConfigHandle,
  168. &XonXoffStr,
  169. NdisParameterInteger);
  170. if (Status == NDIS_STATUS_SUCCESS) {
  171. xonXoff=(ULONG)ReturnedValue->ParameterData.IntegerData;
  172. DbgTracef(0,("This MAC Adapter has Xon/Xoff set to: %u.\n",xonXoff));
  173. }
  174. //
  175. // Read if the default for Timeout Base has changed
  176. //
  177. NdisReadConfiguration(
  178. &Status,
  179. &ReturnedValue,
  180. ConfigHandle,
  181. &TimeoutBaseStr,
  182. NdisParameterInteger);
  183. if ( Status == NDIS_STATUS_SUCCESS ) {
  184. timeoutBase = ReturnedValue->ParameterData.IntegerData;
  185. DbgTracef(0,("This MAC Adapter has TimeoutBase set to: %u.\n", timeoutBase));
  186. }
  187. //
  188. // Read if the default for Timeout Baud has changed
  189. //
  190. NdisReadConfiguration(
  191. &Status,
  192. &ReturnedValue,
  193. ConfigHandle,
  194. &TimeoutBaudStr,
  195. NdisParameterInteger);
  196. if ( Status == NDIS_STATUS_SUCCESS ) {
  197. timeoutBaud = ReturnedValue->ParameterData.IntegerData;
  198. DbgTracef(0,("This MAC Adapter has TimeoutBaud set to: %u.\n", timeoutBaud));
  199. }
  200. //
  201. // Read if the default for Timeout ReSync has changed
  202. //
  203. NdisReadConfiguration(
  204. &Status,
  205. &ReturnedValue,
  206. ConfigHandle,
  207. &TimeoutReSyncStr,
  208. NdisParameterInteger);
  209. if (Status == NDIS_STATUS_SUCCESS) {
  210. timeoutReSync=ReturnedValue->ParameterData.IntegerData;
  211. DbgTracef(0,("This MAC Adapter has TimeoutReSync set to: %u.\n",timeoutReSync));
  212. }
  213. NdisReadConfiguration(&Status,
  214. &ReturnedValue,
  215. ConfigHandle,
  216. &WriteBufferingStr,
  217. NdisParameterInteger);
  218. if (Status == NDIS_STATUS_SUCCESS) {
  219. WriteBufferingEnabled = ReturnedValue->ParameterData.IntegerData;
  220. DbgTracef(0,("This MAC Adapter has WriteBufferingEnabled set to: %u.\n", WriteBufferingEnabled));
  221. }
  222. NdisCloseConfiguration(ConfigHandle);
  223. NdisMSetAttributesEx(MiniportAdapterHandle,
  224. Adapter,
  225. (UINT)-1,
  226. NDIS_ATTRIBUTE_IGNORE_REQUEST_TIMEOUT |
  227. NDIS_ATTRIBUTE_DESERIALIZE |
  228. NDIS_ATTRIBUTE_NO_HALT_ON_SUSPEND,
  229. NdisInterfaceInternal);
  230. //
  231. // Initialize the ADAPTER structure here!!!
  232. //
  233. NdisAllocateSpinLock(&Adapter->Lock);
  234. Adapter->IrpStackSize = irpStackSize;
  235. //
  236. // We double the max frame size for PPP byte stuffing.
  237. // We also tack on some PADDING just to be safe.
  238. //
  239. //
  240. // Changed by DigiBoard 10/06/1995
  241. //
  242. // Adapter->MaxFrameSize = maxFrameSize;
  243. Adapter->MaxFrameSize = (maxFrameSize * 2) + PPP_PADDING + 100;
  244. Adapter->FramesPerPort = (framesPerPort > 0) ?
  245. framesPerPort : DEFAULT_FRAMES_PER_PORT;
  246. Adapter->TimeoutBase = timeoutBase;
  247. Adapter->TimeoutBaud = timeoutBaud;
  248. Adapter->TimeoutReSync = timeoutReSync;
  249. Adapter->WriteBufferingEnabled = WriteBufferingEnabled;
  250. InitializeListHead(&Adapter->ActivePorts);
  251. //
  252. // Init the frame lookaside list. DataSize is dependent
  253. // on compression compile option.
  254. //
  255. {
  256. ULONG DataSize;
  257. DataSize = Adapter->MaxFrameSize;
  258. if (DataSize < DEFAULT_EXPANDED_PPP_MAX_FRAME_SIZE)
  259. DataSize = DEFAULT_EXPANDED_PPP_MAX_FRAME_SIZE;
  260. ExInitializeNPagedLookasideList(&Adapter->AsyncFrameList,
  261. NULL,
  262. NULL,
  263. 0,
  264. sizeof(ASYNC_FRAME) +
  265. DataSize +
  266. sizeof(PVOID),
  267. ASYNC_FRAME_TAG,
  268. 0);
  269. }
  270. //
  271. // Insert this "new" adapter into our list of all Adapters.
  272. //
  273. NdisAcquireSpinLock(&GlobalLock);
  274. GlobalAdapter = Adapter;
  275. GlobalAdapterCount++;
  276. NdisReleaseSpinLock(&GlobalLock);
  277. #ifndef MY_DEVICE_OBJECT
  278. if (AsyncDeviceObject == NULL) {
  279. PDRIVER_DISPATCH DispatchTable[IRP_MJ_MAXIMUM_FUNCTION] = {NULL};
  280. NDIS_STRING SymbolicName = NDIS_STRING_CONST("\\DosDevices\\ASYNCMAC");
  281. NDIS_STRING Name = NDIS_STRING_CONST("\\Device\\ASYNCMAC");
  282. NTSTATUS Status;
  283. DispatchTable[IRP_MJ_CREATE] = AsyncDriverCreate;
  284. DispatchTable[IRP_MJ_DEVICE_CONTROL] = AsyncDriverDispatch;
  285. DispatchTable[IRP_MJ_CLEANUP] = AsyncDriverCleanup;
  286. Status =
  287. NdisMRegisterDevice(NdisWrapperHandle,
  288. &Name,
  289. &SymbolicName,
  290. DispatchTable,
  291. &AsyncDeviceObject,
  292. &AsyncDeviceHandle);
  293. if (Status == STATUS_SUCCESS) {
  294. AsyncDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
  295. } else {
  296. AsyncDeviceObject = NULL;
  297. }
  298. }
  299. #endif
  300. //
  301. // Initialize the WAN info here.
  302. //
  303. Adapter->WanInfo.MaxFrameSize = DEFAULT_PPP_MAX_FRAME_SIZE;
  304. Adapter->WanInfo.MaxTransmit = 2;
  305. Adapter->WanInfo.HeaderPadding = DEFAULT_PPP_MAX_FRAME_SIZE;
  306. Adapter->WanInfo.TailPadding = 4 + sizeof(IO_STATUS_BLOCK);
  307. Adapter->WanInfo.MemoryFlags = 0;
  308. Adapter->WanInfo.HighestAcceptableAddress = HighestAcceptableMax;
  309. Adapter->WanInfo.Endpoints = 1000;
  310. Adapter->WanInfo.FramingBits = PPP_ALL | SLIP_ALL;
  311. Adapter->WanInfo.DesiredACCM = xonXoff;
  312. return NDIS_STATUS_SUCCESS;
  313. }
  314. NDIS_STATUS
  315. MpReconfigure(
  316. OUT PNDIS_STATUS OpenErrorStatus,
  317. IN NDIS_HANDLE MiniportAdapterContext,
  318. IN NDIS_HANDLE WrapperConfigurationContext
  319. )
  320. {
  321. return (NDIS_STATUS_SUCCESS);
  322. }
  323. NDIS_STATUS
  324. MpReset(
  325. OUT PBOOLEAN AddressingReset,
  326. IN NDIS_HANDLE MiniportAdapterContext
  327. )
  328. {
  329. *AddressingReset = FALSE;
  330. return (NDIS_STATUS_SUCCESS);
  331. }