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.

462 lines
13 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_STRING ExtendedXOnXOffStr= NDIS_STRING_CONST("ExtendedXonXoffEnabled");
  72. NDIS_STATUS Status;
  73. // assign some defaults if these strings are not found in the registry
  74. UCHAR irpStackSize = DEFAULT_IRP_STACK_SIZE;
  75. ULONG maxFrameSize = DEFAULT_MAX_FRAME_SIZE;
  76. USHORT framesPerPort = DEFAULT_FRAMES_PER_PORT;
  77. ULONG xonXoff = DEFAULT_XON_XOFF;
  78. ULONG timeoutBase = DEFAULT_TIMEOUT_BASE;
  79. ULONG timeoutBaud = DEFAULT_TIMEOUT_BAUD;
  80. ULONG timeoutReSync = DEFAULT_TIMEOUT_RESYNC;
  81. ULONG WriteBufferingEnabled = 1;
  82. ULONG NeededFrameSize;
  83. ULONG extendedXOnXOff = DEFAULT_EXTENDED_XONXOFF;
  84. UINT MaxMulticastList = 32;
  85. USHORT i; // counter
  86. //
  87. // We only support a single instance of AsyncMac
  88. //
  89. if (GlobalAdapterCount != 0) {
  90. return NDIS_STATUS_FAILURE;
  91. }
  92. for (i = 0; i < MediumArraySize; i++) {
  93. if (MediumArray[i] == NdisMediumWan) {
  94. break;
  95. }
  96. }
  97. if (i == MediumArraySize) {
  98. return (NDIS_STATUS_UNSUPPORTED_MEDIA);
  99. }
  100. *SelectedMediumIndex = i;
  101. //
  102. // Card specific information.
  103. //
  104. //
  105. // Allocate the Adapter block.
  106. //
  107. Adapter = (PASYNC_ADAPTER)
  108. ExAllocatePoolWithTag(NonPagedPool,
  109. sizeof(ASYNC_ADAPTER),
  110. ASYNC_ADAPTER_TAG);
  111. if (Adapter == NULL){
  112. DbgTracef(-1,("AsyncMac: Could not allocate physical memory!!!\n"));
  113. return NDIS_STATUS_RESOURCES;
  114. }
  115. ASYNC_ZERO_MEMORY(Adapter, sizeof(ASYNC_ADAPTER));
  116. Adapter->MiniportHandle = MiniportAdapterHandle;
  117. NdisOpenConfiguration(
  118. &Status,
  119. &ConfigHandle,
  120. WrapperConfigurationContext);
  121. if (Status != NDIS_STATUS_SUCCESS) {
  122. return NDIS_STATUS_FAILURE;
  123. }
  124. //
  125. // Read if the default IrpStackSize is used for this adapter.
  126. //
  127. NdisReadConfiguration(
  128. &Status,
  129. &ReturnedValue,
  130. ConfigHandle,
  131. &IrpStackSizeStr,
  132. NdisParameterInteger);
  133. if ( Status == NDIS_STATUS_SUCCESS ) {
  134. irpStackSize=(UCHAR)ReturnedValue->ParameterData.IntegerData;
  135. DbgTracef(0,("This MAC Adapter has an irp stack size of %u.\n",irpStackSize));
  136. }
  137. //
  138. // Read if the default MaxFrameSize is used for this adapter.
  139. //
  140. NdisReadConfiguration(
  141. &Status,
  142. &ReturnedValue,
  143. ConfigHandle,
  144. &MaxFrameSizeStr,
  145. NdisParameterInteger);
  146. if ( Status == NDIS_STATUS_SUCCESS ) {
  147. maxFrameSize=ReturnedValue->ParameterData.IntegerData;
  148. DbgTracef(0,("This MAC Adapter has a max frame size of %u.\n",maxFrameSize));
  149. }
  150. //
  151. // Read if the default for frames per port is changed
  152. //
  153. NdisReadConfiguration(
  154. &Status,
  155. &ReturnedValue,
  156. ConfigHandle,
  157. &FramesPerPortStr,
  158. NdisParameterInteger);
  159. if ( Status == NDIS_STATUS_SUCCESS ) {
  160. framesPerPort=(USHORT)ReturnedValue->ParameterData.IntegerData;
  161. DbgTracef(0,("This MAC Adapter has frames per port set to: %u.\n",framesPerPort));
  162. }
  163. //
  164. // Read if the default for Xon Xoff is changed
  165. //
  166. NdisReadConfiguration(
  167. &Status,
  168. &ReturnedValue,
  169. ConfigHandle,
  170. &XonXoffStr,
  171. NdisParameterInteger);
  172. if (Status == NDIS_STATUS_SUCCESS) {
  173. xonXoff=(ULONG)ReturnedValue->ParameterData.IntegerData;
  174. DbgTracef(0,("This MAC Adapter has Xon/Xoff set to: %u.\n",xonXoff));
  175. }
  176. //
  177. // Read if the default for Timeout Base has changed
  178. //
  179. NdisReadConfiguration(
  180. &Status,
  181. &ReturnedValue,
  182. ConfigHandle,
  183. &TimeoutBaseStr,
  184. NdisParameterInteger);
  185. if ( Status == NDIS_STATUS_SUCCESS ) {
  186. timeoutBase = ReturnedValue->ParameterData.IntegerData;
  187. DbgTracef(0,("This MAC Adapter has TimeoutBase set to: %u.\n", timeoutBase));
  188. }
  189. //
  190. // Read if the default for Timeout Baud has changed
  191. //
  192. NdisReadConfiguration(
  193. &Status,
  194. &ReturnedValue,
  195. ConfigHandle,
  196. &TimeoutBaudStr,
  197. NdisParameterInteger);
  198. if ( Status == NDIS_STATUS_SUCCESS ) {
  199. timeoutBaud = ReturnedValue->ParameterData.IntegerData;
  200. DbgTracef(0,("This MAC Adapter has TimeoutBaud set to: %u.\n", timeoutBaud));
  201. }
  202. //
  203. // Read if the default for Timeout ReSync has changed
  204. //
  205. NdisReadConfiguration(
  206. &Status,
  207. &ReturnedValue,
  208. ConfigHandle,
  209. &TimeoutReSyncStr,
  210. NdisParameterInteger);
  211. if (Status == NDIS_STATUS_SUCCESS) {
  212. timeoutReSync=ReturnedValue->ParameterData.IntegerData;
  213. DbgTracef(0,("This MAC Adapter has TimeoutReSync set to: %u.\n",timeoutReSync));
  214. }
  215. NdisReadConfiguration(&Status,
  216. &ReturnedValue,
  217. ConfigHandle,
  218. &WriteBufferingStr,
  219. NdisParameterInteger);
  220. if (Status == NDIS_STATUS_SUCCESS) {
  221. WriteBufferingEnabled = ReturnedValue->ParameterData.IntegerData;
  222. DbgTracef(0,("This MAC Adapter has WriteBufferingEnabled set to: %u.\n", WriteBufferingEnabled));
  223. }
  224. //
  225. // Read if the default Extended Xon Xoff is changed
  226. //
  227. NdisReadConfiguration(
  228. &Status,
  229. &ReturnedValue,
  230. ConfigHandle,
  231. &ExtendedXOnXOffStr,
  232. NdisParameterInteger);
  233. if (Status == NDIS_STATUS_SUCCESS) {
  234. extendedXOnXOff=(ULONG)ReturnedValue->ParameterData.IntegerData;
  235. DbgTracef(0,("This MAC Adapter has Extended Xon/Xoff set to: %u.\n",extendedXOnXOff));
  236. }
  237. NdisCloseConfiguration(ConfigHandle);
  238. NdisMSetAttributesEx(MiniportAdapterHandle,
  239. Adapter,
  240. (UINT)-1,
  241. NDIS_ATTRIBUTE_IGNORE_REQUEST_TIMEOUT |
  242. NDIS_ATTRIBUTE_DESERIALIZE |
  243. NDIS_ATTRIBUTE_NO_HALT_ON_SUSPEND,
  244. NdisInterfaceInternal);
  245. //
  246. // Initialize the ADAPTER structure here!!!
  247. //
  248. NdisAllocateSpinLock(&Adapter->Lock);
  249. Adapter->IrpStackSize = irpStackSize;
  250. //
  251. // We double the max frame size for PPP byte stuffing.
  252. // We also tack on some PADDING just to be safe.
  253. //
  254. //
  255. // Changed by DigiBoard 10/06/1995
  256. //
  257. // Adapter->MaxFrameSize = maxFrameSize;
  258. Adapter->MaxFrameSize = (maxFrameSize * 2) + PPP_PADDING + 100;
  259. Adapter->FramesPerPort = (framesPerPort > 0) ?
  260. framesPerPort : DEFAULT_FRAMES_PER_PORT;
  261. Adapter->TimeoutBase = timeoutBase;
  262. Adapter->TimeoutBaud = timeoutBaud;
  263. Adapter->TimeoutReSync = timeoutReSync;
  264. Adapter->WriteBufferingEnabled = WriteBufferingEnabled;
  265. InitializeListHead(&Adapter->ActivePorts);
  266. Adapter->ExtendedXOnXOff = extendedXOnXOff;
  267. //
  268. // Init the frame lookaside list. DataSize is dependent
  269. // on compression compile option.
  270. //
  271. {
  272. ULONG DataSize;
  273. DataSize = Adapter->MaxFrameSize;
  274. if (DataSize < DEFAULT_EXPANDED_PPP_MAX_FRAME_SIZE)
  275. DataSize = DEFAULT_EXPANDED_PPP_MAX_FRAME_SIZE;
  276. ExInitializeNPagedLookasideList(&Adapter->AsyncFrameList,
  277. NULL,
  278. NULL,
  279. 0,
  280. sizeof(ASYNC_FRAME) +
  281. DataSize +
  282. sizeof(PVOID),
  283. ASYNC_FRAME_TAG,
  284. 0);
  285. }
  286. //
  287. // Insert this "new" adapter into our list of all Adapters.
  288. //
  289. NdisAcquireSpinLock(&GlobalLock);
  290. GlobalAdapter = Adapter;
  291. GlobalAdapterCount++;
  292. NdisReleaseSpinLock(&GlobalLock);
  293. #ifndef MY_DEVICE_OBJECT
  294. if (AsyncDeviceObject == NULL) {
  295. PDRIVER_DISPATCH DispatchTable[IRP_MJ_MAXIMUM_FUNCTION] = {NULL};
  296. NDIS_STRING SymbolicName = NDIS_STRING_CONST("\\DosDevices\\ASYNCMAC");
  297. NDIS_STRING Name = NDIS_STRING_CONST("\\Device\\ASYNCMAC");
  298. NTSTATUS retStatus;
  299. DispatchTable[IRP_MJ_CREATE] = AsyncDriverCreate;
  300. DispatchTable[IRP_MJ_DEVICE_CONTROL] = AsyncDriverDispatch;
  301. DispatchTable[IRP_MJ_CLEANUP] = AsyncDriverCleanup;
  302. retStatus =
  303. NdisMRegisterDevice(NdisWrapperHandle,
  304. &Name,
  305. &SymbolicName,
  306. DispatchTable,
  307. &AsyncDeviceObject,
  308. &AsyncDeviceHandle);
  309. if (retStatus == STATUS_SUCCESS) {
  310. AsyncDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
  311. } else {
  312. AsyncDeviceObject = NULL;
  313. }
  314. }
  315. #endif
  316. //
  317. // Initialize the WAN info here.
  318. //
  319. Adapter->WanInfo.MaxFrameSize = DEFAULT_PPP_MAX_FRAME_SIZE;
  320. Adapter->WanInfo.MaxTransmit = 2;
  321. Adapter->WanInfo.HeaderPadding = DEFAULT_PPP_MAX_FRAME_SIZE;
  322. Adapter->WanInfo.TailPadding = 4 + sizeof(IO_STATUS_BLOCK);
  323. Adapter->WanInfo.MemoryFlags = 0;
  324. Adapter->WanInfo.HighestAcceptableAddress = HighestAcceptableMax;
  325. Adapter->WanInfo.Endpoints = 1000;
  326. Adapter->WanInfo.FramingBits = PPP_ALL | SLIP_ALL;
  327. Adapter->WanInfo.DesiredACCM = xonXoff;
  328. return NDIS_STATUS_SUCCESS;
  329. }
  330. NDIS_STATUS
  331. MpReconfigure(
  332. OUT PNDIS_STATUS OpenErrorStatus,
  333. IN NDIS_HANDLE MiniportAdapterContext,
  334. IN NDIS_HANDLE WrapperConfigurationContext
  335. )
  336. {
  337. return (NDIS_STATUS_SUCCESS);
  338. }
  339. NDIS_STATUS
  340. MpReset(
  341. OUT PBOOLEAN AddressingReset,
  342. IN NDIS_HANDLE MiniportAdapterContext
  343. )
  344. {
  345. *AddressingReset = FALSE;
  346. return (NDIS_STATUS_SUCCESS);
  347. }