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.

351 lines
11 KiB

  1. /*-------------------------------------------------------------------
  2. | init.c - main module for RocketPort NT device driver. Contains
  3. mostly initialization code. Driver Entry is DriverEntry() routine.
  4. Copyright 1993-98 Comtrol Corporation. All rights reserved.
  5. |--------------------------------------------------------------------*/
  6. #include "precomp.h"
  7. //------ local routines, function prototypes -----------------------------
  8. NTSTATUS DriverEntry(
  9. IN PDRIVER_OBJECT DriverObject,
  10. IN PUNICODE_STRING RegistryPath);
  11. #ifndef NT50
  12. static NTSTATUS StartNT40(IN PDRIVER_OBJECT DriverObject);
  13. #endif
  14. //------------ global variables -----------------------------------
  15. #ifdef S_RK
  16. PCI_CONFIG PciConfig[MAX_NUM_BOXES+1]; // array of all our pci-boards in sys
  17. #endif
  18. DRIVER_CONTROL Driver; // all Driver control information eg ISR
  19. ULONG RocketDebugLevel = 0;
  20. #ifdef S_RK
  21. //char *szClassName = {"Resources RocketPort#"};
  22. #endif
  23. #if DBG
  24. static TCHAR *dbg_label = TEXT("DBG_VERSION");
  25. #endif
  26. /*----------------------------------------------------------------------
  27. DriverEntry -
  28. The entry point that the system point calls to initialize
  29. any driver.
  30. This routine will gather the configuration information,
  31. report resource usage, attempt to initialize all serial
  32. devices, connect to interrupts for ports. If the above
  33. goes reasonably well it will fill in the dispatch points,
  34. reset the serial devices and then return to the system.
  35. Arguments:
  36. DriverObject - Just what it says, really of little use
  37. to the driver itself, it is something that the IO system
  38. cares more about.
  39. PathToRegistry - points to the entry for this driver
  40. in the current control set of the registry.
  41. typical: "REGISTRY\Machine\System\CurrentControlSet\Services\VSLinka"
  42. Return Value:
  43. STATUS_SUCCESS if we could initialize a single device,
  44. otherwise STATUS_SERIAL_NO_DEVICE_INITED.
  45. |----------------------------------------------------------------------*/
  46. NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,
  47. IN PUNICODE_STRING RegistryPath)
  48. {
  49. NTSTATUS status;
  50. int stat;
  51. char tmpstr[120];
  52. //---- zero out the Driver structure
  53. RtlZeroMemory(&Driver,sizeof(Driver));
  54. Driver.GlobalDriverObject = DriverObject; // used for EventLogging
  55. Driver.DebugQ.QBase = ExAllocatePool(NonPagedPool,10000+2);
  56. if ( Driver.DebugQ.QBase == NULL ) {
  57. return STATUS_INSUFFICIENT_RESOURCES;
  58. }
  59. Driver.DebugQ.QSize = 10000;
  60. Driver.TraceOptions = 0;
  61. #if DBG
  62. Driver.TraceOptions = 0xffffffffL;
  63. #endif
  64. KeInitializeSpinLock(&Driver.DebugLock);
  65. KeInitializeSpinLock(&Driver.TimerLock);
  66. #if DBG
  67. // RocketDebugLevel = D_Error | D_Test;
  68. // Driver.GTraceFlags = D_Error | D_Test;
  69. //RocketDebugLevel = D_Error | D_Nic | D_Hdlc | D_Port;
  70. //Driver.GTraceFlags = D_Error | D_Nic | D_Hdlc | D_Port;
  71. //RocketDebugLevel = D_Error | D_Pnp;
  72. //Driver.GTraceFlags = D_Error | D_Pnp;
  73. //RocketDebugLevel = D_Error | D_Test | D_Pnp | D_Init;
  74. //Driver.GTraceFlags = D_Error | D_Test | D_Pnp | D_Init;
  75. //RocketDebugLevel = D_All;
  76. //Driver.GTraceFlags = D_All;
  77. RocketDebugLevel = D_Error;
  78. Driver.GTraceFlags = D_Error;
  79. #endif
  80. #ifdef S_VS
  81. stat = LoadMicroCode(NULL);
  82. if (stat)
  83. {
  84. status = STATUS_SERIAL_NO_DEVICE_INITED;
  85. Eprintf("Err:No VSLINKA.BIN file!");
  86. return status;
  87. }
  88. MyKdPrint(D_Init, ("MicroCode Loaded\n"))
  89. //----- allocate an array of Nic card structs
  90. // allow up to VS1000_MAX_NICS nic cards to come and go
  91. Driver.nics = (Nic *)our_locked_alloc(sizeof(Nic) * VS1000_MAX_NICS, "Dnic");
  92. #endif
  93. //---- do some registry configuration reading, in options.c
  94. // Save off RegistryPath to Driver.RegPath
  95. stat = SaveRegPath(RegistryPath);
  96. if ( stat ) {
  97. status = STATUS_SERIAL_NO_DEVICE_INITED;
  98. return status;
  99. }
  100. UToCStr(tmpstr, RegistryPath, sizeof(tmpstr));
  101. MyKdPrint(D_Test, (" init RegPath=%s\n", tmpstr))
  102. // read in all the driver level options out of \Parameters
  103. // this fills out values in Driver struct
  104. read_driver_options();
  105. if (Driver.NumDevices == 0)
  106. Driver.NumDevices = 1;
  107. if (Driver.NumDevices > MAX_NUM_BOXES)
  108. Driver.NumDevices = MAX_NUM_BOXES;
  109. MyKdPrint(D_Init,("DriverEntry\n"))
  110. if ((Driver.ScanRate < 1) || (Driver.ScanRate > 50))
  111. Driver.ScanRate = 7; // default to 7ms operation(137Hz)
  112. //------ only setup io stuff here if prior to NT5.0
  113. #ifndef NT50
  114. status = StartNT40(DriverObject);
  115. if (status != STATUS_SUCCESS)
  116. {
  117. EventLog(DriverObject, STATUS_SUCCESS, SERIAL_RP_INIT_FAIL, 0, NULL);
  118. SerialUnload(DriverObject); // deallocate our things
  119. return status;
  120. }
  121. #endif // not pnp
  122. // Initialize the Driver Object with driver's entry points
  123. DriverObject->DriverUnload = SerialUnload;
  124. DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = SerialFlush;
  125. DriverObject->MajorFunction[IRP_MJ_WRITE] = SerialWrite;
  126. DriverObject->MajorFunction[IRP_MJ_READ] = SerialRead;
  127. DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = SerialIoControl;
  128. #ifdef NT50
  129. DriverObject->DriverExtension->AddDevice = SerialAddDevice;
  130. DriverObject->MajorFunction[IRP_MJ_PNP] = SerialPnpDispatch;
  131. DriverObject->MajorFunction[IRP_MJ_POWER] = SerialPowerDispatch;
  132. DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] =
  133. SerialInternalIoControl;
  134. #endif
  135. // these appear to change in 5.0, but not working yet(see serial.sys)....
  136. DriverObject->MajorFunction[IRP_MJ_CREATE] = SerialCreateOpen;
  137. DriverObject->MajorFunction[IRP_MJ_CLOSE] = SerialClose;
  138. DriverObject->MajorFunction[IRP_MJ_CLEANUP] = SerialCleanup;
  139. DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
  140. SerialQueryInformationFile;
  141. DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
  142. SerialSetInformationFile;
  143. #ifdef NT50
  144. // pnp
  145. //---- Log the fact that the driver loaded
  146. EventLog(DriverObject, STATUS_SUCCESS, SERIAL_NT50_INIT_PASS, 0, NULL);
  147. return STATUS_SUCCESS;
  148. #endif
  149. #ifndef NT50
  150. # ifdef S_RK
  151. //--------------- Connect to IRQ, or start Timer.
  152. StartRocketIRQorTimer();
  153. # else
  154. RcktInitPollTimer();
  155. KeSetTimer(&Driver.PollTimer,
  156. Driver.PollIntervalTime,
  157. &Driver.TimerDpc);
  158. # endif
  159. //---- Log the fact that the driver loaded and found some hardware.
  160. EventLog(DriverObject, STATUS_SUCCESS, SERIAL_RP_INIT_PASS, 0, NULL);
  161. return STATUS_SUCCESS;
  162. #endif
  163. }
  164. #ifndef NT50
  165. /*----------------------------------------------------------------------
  166. StartNT40 - Fire up our boards and ports.
  167. |----------------------------------------------------------------------*/
  168. static NTSTATUS StartNT40(IN PDRIVER_OBJECT DriverObject)
  169. {
  170. NTSTATUS status = STATUS_SUCCESS;
  171. int i, dstat;
  172. PSERIAL_DEVICE_EXTENSION ext;
  173. PSERIAL_DEVICE_EXTENSION board_ext;
  174. if (Driver.NumDevices == 0) // no rocketports setup.
  175. {
  176. Eprintf("No boards configured, run setup.");
  177. EventLog(DriverObject, STATUS_SUCCESS, SERIAL_RP_INIT_FAIL, 0, NULL);
  178. return STATUS_SERIAL_NO_DEVICE_INITED;
  179. }
  180. //--------Create the driver device object which serves as
  181. // extensions to link and structure the boards together, and
  182. // also serve as a special public object for debug and monitor Ioctls.
  183. if (Driver.driver_ext == NULL)
  184. {
  185. status = CreateDriverDevice(Driver.GlobalDriverObject,
  186. NULL); //
  187. if (status)
  188. {
  189. if (Driver.VerboseLog)
  190. Eprintf("Err D1.");
  191. return status;
  192. }
  193. }
  194. #ifdef S_VS
  195. // get our Ethernet running
  196. i = init_eth_start();
  197. if (i != STATUS_SUCCESS)
  198. {
  199. if (Driver.VerboseLog)
  200. Eprintf("Err, E1.");
  201. return i;
  202. }
  203. #endif
  204. //--------Create the board device objects which serve as
  205. // extensions to link and structure the ports together.
  206. for (i=0; i<Driver.NumDevices; i++)
  207. {
  208. status = CreateBoardDevice(DriverObject, NULL);
  209. if (status)
  210. {
  211. if (Driver.VerboseLog)
  212. Eprintf("Err B1.");
  213. return status;
  214. }
  215. }
  216. board_ext = Driver.board_ext;
  217. while (board_ext != NULL)
  218. {
  219. read_device_options(board_ext);
  220. if (board_ext->config->NumPorts == 0)
  221. board_ext->config->NumPorts = 8;
  222. board_ext = board_ext->board_ext;
  223. }
  224. #ifdef S_RK
  225. // rocketport specific startup code. Setup some of
  226. // the config structs, look for PCI boards in system, match them up.
  227. status = init_cfg_rocket(DriverObject);
  228. if (status != STATUS_SUCCESS)
  229. {
  230. if (Driver.VerboseLog)
  231. Eprintf("Err C1.");
  232. return STATUS_SERIAL_NO_DEVICE_INITED;
  233. }
  234. //------ setup moree rocket hardware specific information
  235. if (SetupRocketCfg(0) != 0)
  236. {
  237. VerboseLogBoards("B -");
  238. return STATUS_SERIAL_NO_DEVICE_INITED;
  239. }
  240. //SetupRocketIRQ();
  241. //------ Report our RocketPort resource usage to NT, and get IO permissions
  242. ext = Driver.board_ext;
  243. while(ext)
  244. {
  245. if (RocketReportResources(ext) != 0)
  246. {
  247. VerboseLogBoards("C -");
  248. EventLog(DriverObject, STATUS_SUCCESS, SERIAL_RP_RESOURCE_CONFLICT,0, NULL);
  249. return STATUS_SERIAL_NO_DEVICE_INITED;
  250. }
  251. ext = ext->board_ext; // next
  252. }
  253. #endif
  254. //------ Fire up the boards.
  255. ext = Driver.board_ext;
  256. while(ext)
  257. {
  258. # ifdef S_RK
  259. dstat = InitController(ext);
  260. if (dstat != 0)
  261. {
  262. VerboseLogBoards("D -");
  263. return STATUS_SERIAL_NO_DEVICE_INITED;
  264. }
  265. # else
  266. status = VSSpecialStartup(ext);
  267. if (status != STATUS_SUCCESS)
  268. {
  269. if (Driver.VerboseLog)
  270. Eprintf("Hdlc open fail\n");
  271. status = STATUS_SERIAL_NO_DEVICE_INITED;
  272. return status;
  273. }
  274. # endif
  275. ext->FdoStarted = 1; // tell ISR that its on.
  276. ext->config->HardwareStarted = TRUE; // tell ISR its ready to go
  277. ext = ext->board_ext; // next
  278. }
  279. //----- make the port devices
  280. MyKdPrint(D_Init,("CreatePortDevices\n"))
  281. status = CreatePortDevices(DriverObject);
  282. if (status != STATUS_SUCCESS)
  283. {
  284. # ifdef S_RK
  285. VerboseLogBoards("E -");
  286. # else
  287. if (Driver.VerboseLog)
  288. Eprintf("Err, P1.");
  289. # endif
  290. EventLog(DriverObject, STATUS_SUCCESS, SERIAL_DEVICEOBJECT_FAILED, 0, NULL);
  291. return STATUS_SERIAL_NO_DEVICE_INITED;
  292. }
  293. #ifdef S_RK
  294. //------ If modem boards, initialize modems..
  295. ext = Driver.board_ext;
  296. while (ext)
  297. {
  298. // pull SocketModem devices out of reset state
  299. InitSocketModems(ext);
  300. // load RocketModemII devices...
  301. InitRocketModemII(ext);
  302. ext = ext->board_ext; // next
  303. }
  304. #endif
  305. return STATUS_SUCCESS;
  306. }
  307. #endif