NDIS Driver Tips and GuidelinesUpdated: December 4, 2001
NOTE: NDIS 5.0 is deprecated and will be removed in future versions of Windows. Refer to NDIS 6.x. On This Page
Driver InitializationDriver initialization times can have significant impact when a system is starting up or waking up, affecting the end-user experience of how fast the system is and how it looks and feels. Microsoft testers discovered that, in many cases, the initialization time can be reduced several seconds by optimizing the NDIS miniport drivers. Driver Initialization. The time spent in driver initialization can have a significant impact on the time it takes for Microsoft Windows to boot. Reducing this time is particularly important for laptops when they are not connected to a network, as well as for desktop systems that are suspended and restored. Driver initialization time should always be on the order of 10s of milliseconds. To optimize driver initialization:
Driver Shutdown. When the driver is asked to shut down, nothing else should be done except setting the hardware into an idle state. Driver Halt. In addition to the processing done for shut down, the Halt routine must also free all resources. Please note the following additional requirements:
Driver Interrupt Handling. Determine whether an interrupt is yours from the hardware state when the driver interrupt service routine (ISR) is called. If it is, request that a deferred procedure call (DPC) be queued, and disable the interrupt. Re-enable the interrupt when the DPC completes. Make sure the hardware will not raise an interrupt until the driver is ready to handle it--that is, after NdisMRegisterInterrupt() completes. General Guidelines for Writing NDIS Miniport DriversThe miniport driver should make only NDIS library calls. Avoiding the use of operating system-specific kernel calls increases the portability of the code between Windows platforms. Also, to make the NDIS miniport drivers binary compatible between Windows 98/Windows Me and Windows 2000/Windows XP, the BINARY_COMPATIBLE flag must be used. If you have to call interfaces outside the NDIS library, use only the calls defined in the Wdm.h file, which can be found in the Windows DDK. Important: The development of full MAC drivers is no longer supported or documented in the DDKs. Support for full MAC drivers will be removed from future releases of Windows operating systems. Recommended Solutions for NDIS Driver ProblemsBoth hardware and software vendors can use the information here to avoid repeating these same problems during their own testing processes. Problem: NDIS Driver Timers Fail during Driver Unload. Drivers can be loaded and unloaded multiple times under Windows 2000/Windows XP through calls to the MiniportHalt routine. All operations necessary to unload the driver must be completed when this routine is called, including freeing memory, deregistering interrupts and shutdown handlers, and canceling timers. Timers are cancelled by a call to NdisMCancelTimer; however, in some cases, a call to NdisMCancelTimer may fail. If NdisMCancelTimer fails, this means that the timer has already fired. If the timer has fired, the driver cannot unload until the timer routine has been called and completed. The following options can help avoid this problem:
The miniport's shutdown handler should only stop generating interrupts, DMA transfers, and so on. It should not cancel timers or de-allocate resources. Problem: NDIS Driver Doesn't Start during Initialization. Most PCI card drivers should set the Dma32BitAddresses parameter to TRUE. The only reason for setting this flag to FALSE is if the card cannot address memory above 16 MB. If the flag is set to FALSE, the driver may not start during initialization, as memory below 16 MB can be a scarce resource. This can also cause problems with cards that are not power managed. In this case, the drivers are halted on Suspend and re-initialized on Resume. In addition, the network adapter may fail to initialize on Resume. The NE3200 sample driver in the Windows DDK is for a PCI card that cannot address physical memory that exceeds 16 MB. Therefore, when allocating resources for DMA transfers, this sample driver calls NdisMAllocateMapRegisters with the Dma32BitAddresses parameter set to FALSE. Tips for Driver Initialization and PerformanceFollow these tips for driver initialization, send requests, and buffer allocation. NDIS Driver Initialization Routine Process. A miniport driver should only call NdisMIndicateStatus after its initialize routine. Until an NDIS miniport's MiniportInitialize routine completes, NDIS is not prepared to receive and process status indications from these drivers. NDIS Drivers Must Not Complete Requests at Device IRQL. NDIS Miniports complete send request by calling NdisMSendComplete. This should never be done at the device interrupt request level (DIRQL). Some drivers incorrectly complete send requests in a function called through NdisMSynchronizeWithInterrupt. Doing this causes the called function to execute at DIRQL. Sends should never be completed at this IRQL. (Note that an earlier version of this article stated this incorrectly; this text represents the correct information.) Reduce Free Buffers for Drivers to Increase System Performance. Memory should be allocated dynamically where possible on an as-needed basis. When large amounts of memory are allocated for driver use, system performance can degrade. Large amounts of memory consumption in low-memory environments can also affect system performance. The initial number of buffers typically starts at 32 to 64 and should be increased in increments of 32. The highest number of buffers allowed should be 256. In an NDIS 3.0 model driver where the network adapter driver always owns received packets, a fixed number of buffers (scaled to the bandwidth) are all that is needed. For a 100 Mb/s system, 32 to 64 buffers are sufficient. For Gigabit Ethernet, the number of buffers could be double that of a 100 Mb/s system. In a driver that uses the Receive Packet model, the network adapter relinquishes control of the receive buffer to the network stack. The network adapter driver is then required to manage this pool. A potential way to do this is as follows:
Testing Network Adapter Drivers with Driver VerifierTo better ensure driver quality, the Windows test teams have extended the testing done to include the use of the Driver Verifier. Drivers are required to pass this testing to be included with Windows 2000/Windows XP, and the test tools are being modified to automatically turn on driver verification at Level 3 for all network interface card (NIC) drivers tested with these tools. The Driver Verifier is documented in the Windows DDK. One of the best ways to ensure creation of high quality drivers is to run the Driver Verifier before submitting your driver to Microsoft for testing. The Driver Verifier should be run at Level 3 through the entire suite of NDIS tests before submission. All drivers that are submitted for inclusion with Windows products are tested extensively by the Windows networking team. Drivers that pass this testing are verified on an ongoing basis with current builds of the operating system. A subset of the tests and tools used to verify these drivers are also part of the Microsoft Windows Hardware Compatibility Tests (HCTs) required for the Windows Logo for hardware. Call to action for NDIS 5.0 driver writers:
|
|
