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.

411 lines
12 KiB

  1. #include "precomp.h" // Precompiled header
  2. /****************************************************************************************
  3. * *
  4. * Module: SPD_W2K.C *
  5. * *
  6. * Creation: 14th April 1999 *
  7. * *
  8. * Author: Paul Smith *
  9. * *
  10. * Version: 1.0.0 *
  11. * *
  12. * Description: Functions specific to SPEED and Windows 2000 *
  13. * *
  14. ****************************************************************************************/
  15. // Paging...
  16. #ifdef ALLOC_PRAGMA
  17. #pragma alloc_text (PAGE, SpxGetNtCardType)
  18. #endif
  19. #define FILE_ID SPD_W2K_C // File ID for Event Logging see SPD_DEFS.H for values.
  20. /*****************************************************************************
  21. **************************** ****************************
  22. **************************** SpxGetNtCardType ****************************
  23. **************************** ****************************
  24. ******************************************************************************
  25. prototype: ULONG SpxGetNtCardType(IN PDEVICE_OBJECT pDevObject)
  26. description: Return the NT defined card type for the specified card
  27. device object.
  28. parameters: pDevObject points to the NT device object for the card
  29. returns: NT defined card type,
  30. or -1 if not identified
  31. */
  32. ULONG SpxGetNtCardType(IN PDEVICE_OBJECT pDevObject)
  33. {
  34. PCARD_DEVICE_EXTENSION pCard = pDevObject->DeviceExtension;
  35. ULONG NtCardType = -1;
  36. PVOID pPropertyBuffer = NULL;
  37. ULONG ResultLength = 0;
  38. NTSTATUS status = STATUS_SUCCESS;
  39. ULONG BufferLength = 1; // Initial size.
  40. PAGED_CODE(); // Macro in checked build to assert if pagable code is run at or above dispatch IRQL
  41. pPropertyBuffer = SpxAllocateMem(PagedPool, BufferLength); // Allocate the buffer
  42. if(pPropertyBuffer == NULL) // SpxAllocateMem failed.
  43. return -1;
  44. // Try to get HardwareID
  45. status = IoGetDeviceProperty(pCard->PDO, DevicePropertyHardwareID , BufferLength,
  46. pPropertyBuffer, &ResultLength);
  47. if(!SPX_SUCCESS(status)) // IoGetDeviceProperty failed.
  48. {
  49. if(status == STATUS_BUFFER_TOO_SMALL) // Buffer was too small.
  50. {
  51. ExFreePool(pPropertyBuffer); // Free old buffer that was not big enough.
  52. BufferLength = ResultLength + 1; // Set BufferLength to size required.
  53. pPropertyBuffer = SpxAllocateMem(PagedPool, BufferLength); // Allocate a bigger buffer.
  54. if(pPropertyBuffer == NULL) // SpxAllocateMem failed.
  55. return -1;
  56. // Try again.
  57. status = IoGetDeviceProperty(pCard->PDO, DevicePropertyHardwareID , BufferLength,
  58. pPropertyBuffer, &ResultLength);
  59. if(!SPX_SUCCESS(status)) // IoGetDeviceProperty failed a second time.
  60. {
  61. ExFreePool(pPropertyBuffer); // Free buffer.
  62. return -1;
  63. }
  64. }
  65. else
  66. {
  67. ExFreePool(pPropertyBuffer); // Free buffer.
  68. return -1;
  69. }
  70. }
  71. // If we get to here then there is something in the PropertyBuffer.
  72. _wcsupr(pPropertyBuffer); // Convert HardwareID to uppercase
  73. // Speed 2 adapters
  74. if(wcsstr(pPropertyBuffer, SPD2_PCI_PCI954_HWID) != NULL) // SPEED 2 Port Adapter
  75. NtCardType = Speed2_Pci;
  76. if(wcsstr(pPropertyBuffer, SPD2AND4_PCI_NO_F1_HWID) != NULL) // SPEED 2/4 Port Adapter Local Bus (unused)
  77. NtCardType = Speed2and4_Pci_8BitBus;
  78. if(wcsstr(pPropertyBuffer, SPD2P_PCI_PCI954_HWID) != NULL) // SPEED+ 2 Port Adapter
  79. NtCardType = Speed2P_Pci;
  80. if(wcsstr(pPropertyBuffer, SPD2P_PCI_8BIT_LOCALBUS_HWID) != NULL) // SPEED+ 2 Port Adapter Local bus (not used)
  81. NtCardType = Speed2P_Pci_8BitBus;
  82. // SPEED 4 adapters
  83. if(wcsstr(pPropertyBuffer, SPD4_PCI_PCI954_HWID) != NULL) // SPEED 4 Port Adapter
  84. NtCardType = Speed4_Pci;
  85. if(wcsstr(pPropertyBuffer, SPD4P_PCI_PCI954_HWID) != NULL) // SPEED+ 4 Port Adapter
  86. NtCardType = Speed4P_Pci;
  87. if(wcsstr(pPropertyBuffer, SPD4P_PCI_8BIT_LOCALBUS_HWID) != NULL) // SPEED+ 4 Port Adapter Local bus (not used)
  88. NtCardType = Speed4P_Pci_8BitBus;
  89. // Chase Fast Cards
  90. if(wcsstr(pPropertyBuffer, FAST4_PCI_HWID) != NULL) // PCI-Fast 4 Port Adapter
  91. NtCardType = Fast4_Pci;
  92. if(wcsstr(pPropertyBuffer, FAST8_PCI_HWID) != NULL) // PCI-Fast 8 Port Adapter
  93. NtCardType = Fast8_Pci;
  94. if(wcsstr(pPropertyBuffer, FAST16_PCI_HWID) != NULL) // PCI-Fast 16 Port Adapter
  95. NtCardType = Fast16_Pci;
  96. if(wcsstr(pPropertyBuffer, FAST16FMC_PCI_HWID) != NULL) // PCI-Fast 16 FMC Port Adapter
  97. NtCardType = Fast16FMC_Pci;
  98. if(wcsstr(pPropertyBuffer, AT_FAST4_HWID) != NULL) // AT-Fast 4 Port Adapter
  99. NtCardType = Fast4_Isa;
  100. if(wcsstr(pPropertyBuffer, AT_FAST8_HWID) != NULL) // AT-Fast 8 Port Adapter
  101. NtCardType = Fast8_Isa;
  102. if(wcsstr(pPropertyBuffer, AT_FAST16_HWID) != NULL) // AT-Fast 16 Port Adapter
  103. NtCardType = Fast16_Isa;
  104. if(wcsstr(pPropertyBuffer, RAS4_PCI_HWID) != NULL) // PCI-RAS 4 Multi-modem Adapter
  105. NtCardType = RAS4_Pci;
  106. if(wcsstr(pPropertyBuffer, RAS8_PCI_HWID) != NULL) // PCI-RAS 8 Multi-modem Adapter
  107. NtCardType = RAS8_Pci;
  108. ExFreePool(pPropertyBuffer); // Free buffer.
  109. return(NtCardType);
  110. } // SpxGetNtCardType
  111. //////////////////////////////////////////////////////////////////////////////
  112. // SetPortFiFoSettings
  113. //
  114. BOOLEAN SetPortFiFoSettings(PPORT_DEVICE_EXTENSION pPort)
  115. {
  116. // Store current settings.
  117. ULONG TxFIFOSize = pPort->BufferSizes.TxFIFOSize;
  118. ULONG TxFIFOTrigLevel = pPort->BufferSizes.TxFIFOTrigLevel;
  119. ULONG RxFIFOTrigLevel = pPort->BufferSizes.RxFIFOTrigLevel;
  120. ULONG LoFlowCtrlThreshold = pPort->UartConfig.LoFlowCtrlThreshold;
  121. ULONG HiFlowCtrlThreshold = pPort->UartConfig.HiFlowCtrlThreshold;
  122. // Get Tx FIFO Limit.
  123. if((pPort->TxFIFOSize > 0) && (pPort->TxFIFOSize <= pPort->MaxTxFIFOSize)) // Check for good value.
  124. {
  125. pPort->BufferSizes.TxFIFOSize = pPort->TxFIFOSize;
  126. }
  127. else
  128. goto SetFailure;
  129. // Get Tx FIFO Trigger Level.
  130. if(pPort->TxFIFOSize <= pPort->MaxTxFIFOSize) // Check for good value.
  131. {
  132. pPort->BufferSizes.TxFIFOTrigLevel = (BYTE) pPort->TxFIFOTrigLevel;
  133. }
  134. else
  135. goto SetFailure;
  136. // Get Rx FIFO Trigger Level.
  137. if(pPort->RxFIFOTrigLevel <= pPort->MaxRxFIFOSize) // Check for good value.
  138. {
  139. pPort->BufferSizes.RxFIFOTrigLevel = (BYTE) pPort->RxFIFOTrigLevel;
  140. }
  141. else
  142. goto SetFailure;
  143. // Attempt to change FIFO settings.
  144. if(pPort->pUartLib->UL_BufferControl_XXXX(pPort->pUart, &pPort->BufferSizes, UL_BC_OP_SET, UL_BC_FIFO | UL_BC_IN | UL_BC_OUT) != UL_STATUS_SUCCESS)
  145. {
  146. goto SetFailure;
  147. }
  148. // Get Low Flow Control Threshold Level.
  149. if(pPort->LoFlowCtrlThreshold <= pPort->MaxRxFIFOSize) // Check for good value.
  150. {
  151. pPort->UartConfig.LoFlowCtrlThreshold = (BYTE) pPort->LoFlowCtrlThreshold;
  152. }
  153. else
  154. goto SetFailure;
  155. // Get High Flow Control Threshold Level.
  156. if(pPort->HiFlowCtrlThreshold <= pPort->MaxRxFIFOSize) // Check for good value.
  157. {
  158. pPort->UartConfig.HiFlowCtrlThreshold = (BYTE) pPort->HiFlowCtrlThreshold;
  159. }
  160. else
  161. goto SetFailure;
  162. // Attempt to set the configuration.
  163. if(pPort->pUartLib->UL_SetConfig_XXXX(pPort->pUart, &pPort->UartConfig, UC_FC_THRESHOLD_SETTING_MASK) != UL_STATUS_SUCCESS)
  164. {
  165. goto SetFailure;
  166. }
  167. // Just do a quick get config to see if flow threshold have
  168. // changed as a result of changing the FIFO triggers.
  169. pPort->pUartLib->UL_GetConfig_XXXX(pPort->pUart, &pPort->UartConfig);
  170. // Update FIFO Flow Control Levels
  171. pPort->LoFlowCtrlThreshold = pPort->UartConfig.LoFlowCtrlThreshold;
  172. pPort->HiFlowCtrlThreshold = pPort->UartConfig.HiFlowCtrlThreshold;
  173. return TRUE;
  174. // Restore all settings to the way they were.
  175. SetFailure:
  176. // Restore settings.
  177. pPort->TxFIFOSize = TxFIFOSize;
  178. pPort->TxFIFOTrigLevel = TxFIFOTrigLevel;
  179. pPort->RxFIFOTrigLevel = RxFIFOTrigLevel;
  180. pPort->BufferSizes.TxFIFOSize = TxFIFOSize;
  181. pPort->BufferSizes.TxFIFOTrigLevel = (BYTE) TxFIFOTrigLevel;
  182. pPort->BufferSizes.RxFIFOTrigLevel = (BYTE) RxFIFOTrigLevel;
  183. pPort->pUartLib->UL_BufferControl_XXXX(pPort->pUart, &pPort->BufferSizes, UL_BC_OP_SET, UL_BC_FIFO | UL_BC_IN | UL_BC_OUT);
  184. // Restore settings.
  185. pPort->LoFlowCtrlThreshold = LoFlowCtrlThreshold;
  186. pPort->HiFlowCtrlThreshold = HiFlowCtrlThreshold;
  187. pPort->UartConfig.LoFlowCtrlThreshold = LoFlowCtrlThreshold;
  188. pPort->UartConfig.HiFlowCtrlThreshold = HiFlowCtrlThreshold;
  189. pPort->pUartLib->UL_SetConfig_XXXX(pPort->pUart, &pPort->UartConfig, UC_FC_THRESHOLD_SETTING_MASK);
  190. return FALSE;
  191. }
  192. NTSTATUS GetPortSettings(PDEVICE_OBJECT pDevObject)
  193. {
  194. PPORT_DEVICE_EXTENSION pPort = (PPORT_DEVICE_EXTENSION)pDevObject->DeviceExtension;
  195. HANDLE PnPKeyHandle;
  196. ULONG Data = 0;
  197. // Open PnP Reg Key
  198. if(SPX_SUCCESS(IoOpenDeviceRegistryKey(pDevObject, PLUGPLAY_REGKEY_DEVICE, STANDARD_RIGHTS_READ, &PnPKeyHandle)))
  199. {
  200. if(SPX_SUCCESS(Spx_GetRegistryKeyValue(PnPKeyHandle, TX_FIFO_LIMIT, wcslen(TX_FIFO_LIMIT) * sizeof(WCHAR), &Data, sizeof(ULONG))))
  201. {
  202. if((Data > 0) && (Data <= pPort->MaxTxFIFOSize)) // Check for good value.
  203. pPort->TxFIFOSize = Data;
  204. }
  205. if(SPX_SUCCESS(Spx_GetRegistryKeyValue(PnPKeyHandle, TX_FIFO_TRIG_LEVEL, wcslen(TX_FIFO_TRIG_LEVEL) * sizeof(WCHAR), &Data, sizeof(ULONG))))
  206. {
  207. if(Data <= pPort->MaxTxFIFOSize) // Check for good value.
  208. pPort->TxFIFOTrigLevel = Data;
  209. }
  210. if(SPX_SUCCESS(Spx_GetRegistryKeyValue(PnPKeyHandle, RX_FIFO_TRIG_LEVEL, wcslen(RX_FIFO_TRIG_LEVEL) * sizeof(WCHAR), &Data, sizeof(ULONG))))
  211. {
  212. if(Data <= pPort->MaxRxFIFOSize) // Check for good value.
  213. pPort->RxFIFOTrigLevel = Data;
  214. }
  215. if(SPX_SUCCESS(Spx_GetRegistryKeyValue(PnPKeyHandle, LO_FLOW_CTRL_LEVEL, wcslen(LO_FLOW_CTRL_LEVEL) * sizeof(WCHAR), &Data, sizeof(ULONG))))
  216. {
  217. if(Data <= pPort->MaxRxFIFOSize) // Check for good value.
  218. pPort->LoFlowCtrlThreshold = Data;
  219. }
  220. if(SPX_SUCCESS(Spx_GetRegistryKeyValue(PnPKeyHandle, HI_FLOW_CTRL_LEVEL, wcslen(HI_FLOW_CTRL_LEVEL) * sizeof(WCHAR), &Data, sizeof(ULONG))))
  221. {
  222. if(Data <= pPort->MaxRxFIFOSize) // Check for good value.
  223. pPort->HiFlowCtrlThreshold = Data;
  224. }
  225. ZwClose(PnPKeyHandle);
  226. }
  227. return STATUS_SUCCESS;
  228. }
  229. NTSTATUS GetCardSettings(PDEVICE_OBJECT pDevObject)
  230. {
  231. PCARD_DEVICE_EXTENSION pCard = (PCARD_DEVICE_EXTENSION)pDevObject->DeviceExtension;
  232. HANDLE PnPKeyHandle;
  233. ULONG Data = 0;
  234. // Open PnP Reg Key
  235. if(SPX_SUCCESS(IoOpenDeviceRegistryKey(pCard->PDO, PLUGPLAY_REGKEY_DEVICE, STANDARD_RIGHTS_READ, &PnPKeyHandle)))
  236. {
  237. if((pCard->CardType == Fast16_Pci) || (pCard->CardType == Fast16FMC_Pci))
  238. {
  239. if(SPX_SUCCESS(Spx_GetRegistryKeyValue(PnPKeyHandle, DELAY_INTERRUPT, wcslen(DELAY_INTERRUPT) * sizeof(WCHAR), &Data, sizeof(ULONG))))
  240. {
  241. if(Data)
  242. {
  243. if(!(pCard->CardOptions & DELAY_INTERRUPT_OPTION)) // If not already set then set the option
  244. {
  245. if(KeSynchronizeExecution(pCard->Interrupt, SetCardToDelayInterrupt, pCard))
  246. {
  247. pCard->CardOptions |= DELAY_INTERRUPT_OPTION;
  248. }
  249. }
  250. }
  251. else
  252. {
  253. if(pCard->CardOptions & DELAY_INTERRUPT_OPTION) // If set then unset the option.
  254. {
  255. if(KeSynchronizeExecution(pCard->Interrupt, SetCardNotToDelayInterrupt, pCard))
  256. {
  257. pCard->CardOptions &= ~DELAY_INTERRUPT_OPTION;
  258. }
  259. }
  260. }
  261. }
  262. }
  263. if(pCard->CardType == Fast16_Pci)
  264. {
  265. if(SPX_SUCCESS(Spx_GetRegistryKeyValue(PnPKeyHandle, SWAP_RTS_FOR_DTR, wcslen(SWAP_RTS_FOR_DTR) * sizeof(WCHAR), &Data, sizeof(ULONG))))
  266. {
  267. if(Data)
  268. {
  269. if(!(pCard->CardOptions & SWAP_RTS_FOR_DTR_OPTION)) // If not already set then set the option
  270. {
  271. if(KeSynchronizeExecution(pCard->Interrupt, SetCardToUseDTRInsteadOfRTS, pCard))
  272. {
  273. pCard->CardOptions |= SWAP_RTS_FOR_DTR_OPTION;
  274. }
  275. }
  276. }
  277. else
  278. {
  279. if(pCard->CardOptions & SWAP_RTS_FOR_DTR_OPTION) // If set then unset the option.
  280. {
  281. if(KeSynchronizeExecution(pCard->Interrupt, SetCardNotToUseDTRInsteadOfRTS, pCard))
  282. {
  283. pCard->CardOptions &= ~SWAP_RTS_FOR_DTR_OPTION;
  284. }
  285. }
  286. }
  287. }
  288. }
  289. if(SPX_SUCCESS(Spx_GetRegistryKeyValue(PnPKeyHandle, CLOCK_FREQ_OVERRIDE, wcslen(CLOCK_FREQ_OVERRIDE) * sizeof(WCHAR), &Data, sizeof(ULONG))))
  290. {
  291. if(Data > 0)
  292. pCard->ClockRate = Data; // Store new clock rate to use.
  293. }
  294. ZwClose(PnPKeyHandle);
  295. }
  296. return STATUS_SUCCESS;
  297. }