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.

293 lines
9.8 KiB

  1. /*****************************************************************************
  2. ** **
  3. ** COPYRIGHT (C) 2000, 2001 MKNET CORPORATION **
  4. ** DEVELOPED FOR THE MK7100-BASED VFIR PCI CONTROLLER. **
  5. ** **
  6. *****************************************************************************/
  7. /**********************************************************************
  8. Module Name:
  9. WINREG.C
  10. Routines:
  11. ParseRegistryParameters
  12. ProcessRegistry
  13. Comments:
  14. Parse Windows Registry.
  15. *****************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. //************************************************************
  19. // MK7RegTabType
  20. //
  21. // One instance of this structure will be used for every configuration
  22. // parameter that this driver supports. The table contains all of the
  23. // relavent information about each parameter: Name, whether or not it is
  24. // required, where it is located in the "Adapter" structure, the size of
  25. // the parameter in bytes, the default value for the parameter, and what
  26. // the minimum and maximum values are for the parameter. In the debug
  27. // version of the driver, this table also contains a field for the ascii
  28. // name of the parameter.
  29. //************************************************************
  30. typedef struct _MK7RegTabType {
  31. NDIS_STRING RegVarName; // variable name text
  32. char *RegAscName; // variable name text
  33. UINT Mandantory; // 1 -> manditory, 0 -> optional
  34. #define MK7OPTIONAL 0
  35. #define MK7MANDATORY 1
  36. UINT FieldOffset; // offset to MK7_ADAPTER field loaded
  37. UINT FieldSize; // size (in bytes) of the field
  38. UINT Default; // default value to use
  39. UINT Min; // minimum value allowed
  40. UINT Max; // maximum value allowed
  41. } MK7RegTabType;
  42. //************************************************************
  43. // Registry Parameters Table
  44. //
  45. // This table contains a list of all of the configuration parameters
  46. // that the driver supports. The driver will attempt to find these
  47. // parameters in the registry and use the registry value for these
  48. // parameters. If the parameter is not found in the registry, then the
  49. // default value is used. This is a way for us to set defaults for
  50. // certain parameters.
  51. //
  52. //************************************************************
  53. MK7RegTabType MK7RegTab[ ] = {
  54. //
  55. // REGISTRY NAME TEXT NAME MAN/OPT OFFSET
  56. // SIZE DEF VAL MIN MAX
  57. //
  58. //#if DBG
  59. // {NDIS_STRING_CONST("Debug"), "Debug", MK7OPTIONAL, MK7_OFFSET(Debug),
  60. // MK7_SIZE(Debug), DBG_NORMAL, 0, 0xffffffff},
  61. //#endif
  62. {NDIS_STRING_CONST("MaxConnectRate"), "MaxConnectRate", MK7OPTIONAL, MK7_OFFSET(MaxConnSpeed),
  63. MK7_SIZE(MaxConnSpeed), 16000000, 9600, 16000000},
  64. {NDIS_STRING_CONST("MinTurnAroundTime"), "MinTurnAroundTime", MK7OPTIONAL, MK7_OFFSET(turnAroundTime_usec),
  65. MK7_SIZE(turnAroundTime_usec), DEFAULT_TURNAROUND_usec, 0, DEFAULT_TURNAROUND_usec},
  66. //
  67. // All the ones from here down are not really necessary except for testing.
  68. //
  69. {NDIS_STRING_CONST("BusNumber"), "BusNumber", MK7OPTIONAL, MK7_OFFSET(BusNumber),
  70. MK7_SIZE(BusNumber), 0, 0, 16},
  71. {NDIS_STRING_CONST("SlotNumber"), "SlotNumber", MK7OPTIONAL, MK7_OFFSET(MKSlot),
  72. MK7_SIZE(MKSlot), 0, 0, 32},
  73. #if DBG
  74. {NDIS_STRING_CONST("Loopback"), "Loopback", MK7OPTIONAL, MK7_OFFSET(LB),
  75. MK7_SIZE(LB), 0, 0, 2},
  76. #endif
  77. {NDIS_STRING_CONST("RingSize"), "RingSize", MK7OPTIONAL, MK7_OFFSET(RingSize),
  78. MK7_SIZE(RingSize), DEF_RING_SIZE, MIN_RING_SIZE, MAX_RING_SIZE},
  79. {NDIS_STRING_CONST("RXRingSize"), "RXRingSize", MK7OPTIONAL, MK7_OFFSET(RegNumRcb),
  80. MK7_SIZE(RegNumRcb), DEF_RXRING_SIZE,MIN_RING_SIZE, DEF_RXRING_SIZE},
  81. {NDIS_STRING_CONST("TXRingSize"), "TXRingSize", MK7OPTIONAL, MK7_OFFSET(RegNumTcb),
  82. MK7_SIZE(RegNumTcb), DEF_TXRING_SIZE,MIN_RING_SIZE, DEF_TXRING_SIZE},
  83. {NDIS_STRING_CONST("ExtraBOFs"), "ExtraBOFs", MK7OPTIONAL, MK7_OFFSET(RegExtraBOFs),
  84. MK7_SIZE(RegExtraBOFs), DEF_EBOFS, MIN_EBOFS, MAX_EBOFS},
  85. {NDIS_STRING_CONST("Speed"), "Speed", MK7OPTIONAL, MK7_OFFSET(RegSpeed),
  86. MK7_SIZE(RegSpeed), 16000000, 4000000, 16000000},
  87. {NDIS_STRING_CONST("BusType"), "BusType", MK7OPTIONAL, MK7_OFFSET(MKBusType),
  88. MK7_SIZE(MKBusType), PCIBUS, PCIBUS, PCIBUS},
  89. {NDIS_STRING_CONST("IoSize"), "IoSize", MK7OPTIONAL, MK7_OFFSET(MKBaseSize),
  90. MK7_SIZE(MKBaseSize), MK7_IO_SIZE, MK7_IO_SIZE, MK7_IO_SIZE},
  91. {NDIS_STRING_CONST("Wireless"), "Wireless", MK7OPTIONAL, MK7_OFFSET(Wireless),
  92. MK7_SIZE(Wireless), 1, 0, 1},
  93. };
  94. #define NUM_REG_PARAM ( sizeof (MK7RegTab) / sizeof (MK7RegTabType) )
  95. //-----------------------------------------------------------------------------
  96. // Procedure: ParseRegistryParameters
  97. //
  98. // Description: This routine will parse all of the parameters out of the
  99. // registry/PROTOCOL.INI, and store the values in the "Adapter"
  100. // Structure. If the parameter is not present in the registry, then the
  101. // default value for the parameter will be placed into the "Adapter"
  102. // structure. This routine also checks the validity of the parameter
  103. // value, and if the value is out of range, the driver will the min/max
  104. // value allowed.
  105. //
  106. // Arguments:
  107. // Adapter - ptr to Adapter object instance
  108. // ConfigHandle - NDIS Configuration Registery handle
  109. //
  110. // Returns:
  111. // NDIS_STATUS_SUCCESS - All mandatory parameters were parsed
  112. // NDIS_STATUS_FAILED - A mandatory parameter was not present
  113. //-----------------------------------------------------------------------------
  114. NDIS_STATUS
  115. ParseRegistryParameters(IN PMK7_ADAPTER Adapter,
  116. IN NDIS_HANDLE ConfigHandle)
  117. {
  118. UINT i;
  119. NDIS_STATUS Status;
  120. MK7RegTabType *RegTab;
  121. UINT value;
  122. PUCHAR fieldPtr;
  123. PNDIS_CONFIGURATION_PARAMETER ReturnedValue;
  124. #if DBG
  125. char ansiRegName[32];
  126. ULONG paramval;
  127. #endif
  128. //****************************************
  129. // Grovel through the registry parameters and aquire all of the values
  130. // stored therein.
  131. //****************************************
  132. for (i=0, RegTab=MK7RegTab; i<NUM_REG_PARAM; i++, RegTab++) {
  133. fieldPtr = ((PUCHAR) Adapter) + RegTab->FieldOffset;
  134. #if DBG
  135. strcpy(ansiRegName, RegTab->RegAscName);
  136. #endif
  137. //****************************************
  138. // Get the configuration value for a specific parameter. Under NT the
  139. // parameters are all read in as DWORDs.
  140. //****************************************
  141. NdisReadConfiguration(&Status,
  142. &ReturnedValue,
  143. ConfigHandle,
  144. &RegTab->RegVarName,
  145. NdisParameterInteger);
  146. //****************************************
  147. // Param in Reg:
  148. // Check that it's w/i the min-max range. If not set it to
  149. // default, else just set to that in the Reg.
  150. //
  151. // Param not in Reg:
  152. // If it's a mandatory param, error out.
  153. // If it's optional (non-mandatory), again use default.
  154. //****************************************
  155. if (Status == NDIS_STATUS_SUCCESS) {
  156. #if DBG
  157. paramval = ReturnedValue->ParameterData.IntegerData;
  158. #endif
  159. if (ReturnedValue->ParameterData.IntegerData < RegTab->Min ||
  160. ReturnedValue->ParameterData.IntegerData > RegTab->Max) {
  161. value = RegTab->Default;
  162. }
  163. else {
  164. value = ReturnedValue->ParameterData.IntegerData;
  165. }
  166. }
  167. else if (RegTab->Mandantory) {
  168. DBGSTR(("Could not find mandantory in registry\n"));
  169. DBGLOG("<= ParseRegistryParameters (ERROR out)", 0);
  170. return (NDIS_STATUS_FAILURE);
  171. }
  172. else { // non-mandatory
  173. value = RegTab->Default;
  174. }
  175. //****************************************
  176. // Store the value in the adapter structure.
  177. //****************************************
  178. switch (RegTab->FieldSize) {
  179. case 1:
  180. *((PUCHAR) fieldPtr) = (UCHAR) value;
  181. break;
  182. case 2:
  183. *((PUSHORT) fieldPtr) = (USHORT) value;
  184. break;
  185. case 4:
  186. *((PULONG) fieldPtr) = (ULONG) value;
  187. break;
  188. default:
  189. DBGSTR(("Bogus field size %d\n", RegTab->FieldSize));
  190. break;
  191. }
  192. }
  193. return (NDIS_STATUS_SUCCESS);
  194. }
  195. //----------------------------------------------------------------------
  196. // Procedure: [ProcessRegistry]
  197. //
  198. // Description: Do all the one time Registry stuff.
  199. //
  200. // Return: NDIS_STATUS_SUCCESS
  201. // (!NDIS_STATUS_SUCCESS)
  202. //----------------------------------------------------------------------
  203. NDIS_STATUS ProcessRegistry(PMK7_ADAPTER Adapter,
  204. NDIS_HANDLE WrapperConfigurationContext)
  205. {
  206. NDIS_STATUS Status;
  207. NDIS_HANDLE ConfigHandle;
  208. PVOID OverrideNetAddress;
  209. ULONG i;
  210. NdisOpenConfiguration(&Status,
  211. &ConfigHandle,
  212. WrapperConfigurationContext);
  213. if (Status != NDIS_STATUS_SUCCESS) {
  214. return (NDIS_STATUS_FAILURE);
  215. }
  216. //****************************************
  217. // Parse all our configuration parameters. Error out if bad
  218. // status returned -- Required param not in Registry.
  219. //****************************************
  220. Status = ParseRegistryParameters(Adapter, ConfigHandle);
  221. if (Status != NDIS_STATUS_SUCCESS) {
  222. NdisCloseConfiguration(ConfigHandle);
  223. return (Status);
  224. }
  225. NdisCloseConfiguration(ConfigHandle);
  226. // Adapter->NumRcb = Adapter->RegNumRcb;
  227. // Adapter->NumTcb = Adapter->RegNumTcb;
  228. Adapter->NumRcb = DEF_RXRING_SIZE;
  229. Adapter->NumTcb = DEF_TXRING_SIZE;
  230. Adapter->NumRpd = CalRpdSize(Adapter->NumRcb);
  231. Adapter->extraBOFsRequired = Adapter->RegExtraBOFs;
  232. return(Status);
  233. }