发信人: wenbobo(灌了拂衣去)
整理人: wenbobo(2002-09-22 17:48:52), 站内信件
|
Using Shared Memory
Miniport drivers for bus-master DMA devices must allocate shared memory for use by the NIC and the NIC driver. Special precautions are necessary when sharing cached memory between such a driver and its NIC. On certain architectures, specific steps must be taken to ensure that the memory is coherent because the NIC can access the shared physical memory directly, while the NIC driver accesses memory through the cache. This can cause differences in what the driver and the NIC detect in memory, even if they look at the same location.
The use of noncached shared memory avoids most of the problems associated with cached shared memory. However, noncached memory is a scarce system resource and allocation of such memory can be limited. When data written to physical memory must use a small write queue, even noncached data might not appear in physical memory immediately. Additionally, there are cases when using noncached memory is neither recommended nor possible. For example, data that the NIC driver reads repeatedly should always be cached to improve performance. Or, as another example, a NIC driver might be required to pass a received data packet to a number of different protocol drivers. Cached memory would be highly recommended in these cases. The NIC driver should also use cached memory for any data passed in by a protocol driver.
NdisMAllocateSharedMemory can be called by a bus-master NIC driver to allocate memory for permanent sharing between the network adapter and the NIC driver. This function returns a virtual address and a physical address for the shared memory. The addresses are valid until a call to NdisMFreeSharedMemory frees the memory.
When shared cached memory is used, NDIS provides a function that must be called by the NIC driver to ensure coherency between what the NIC sees and what the NIC driver sees. Before accessing the shared memory on a send or on a receive, the NIC driver must call NdisFlushBuffer and also NdisMUpdateSharedMemory to ensure cache coherence.
Asynchronous I/O and Completion Functions
Latency is inherent in some network operations. Because of this, many of the upper-edge functions provided by a NIC driver and the lower-edge functions of a protocol driver are designed to support asynchronous operation. Rather than wasting CPU cycles waiting in a loop for some time-consuming task to finish or a hardware event to signal, network drivers rely on the ability to handle most operations asynchronously.
Asynchronous network I/O is supported by using a completion function. The following example illustrates using a completion function for a network send operation, but this same mechanism exists for many other operations performed by a protocol or NIC driver.
When a protocol driver calls NDIS to send a packet, resulting in a call to the NIC driver's MiniportSend function, the NIC driver can try to complete this request immediately and return an appropriate status value as a result. For synchronous operation, the possible responses are NDIS_STATUS_SUCCESS for successful completion of the send, NDIS_STATUS_RESOURCES, and NDIS_STATUS_FAILURE indicating a failure of some kind.
But a send operation can take some time to complete while the NIC driver (or NDIS) queues the packet and waits for the NIC to indicate the result of the send operation. The NIC driver MiniportSend function can handle this operation asynchronously by returning a status value of NDIS_STATUS_PENDING. When the NIC driver completes the send operation, it calls the completion function, NdisMSendComplete, passing a pointer to the packet descriptor that was sent. This information is passed to the protocol driver, signaling completion.
Most driver operations that can require an extended time to complete support asynchronous operation with a similar completion function. Such functions have names of the form NdisMXxxComplete.
Completion functions are also provided for:
* setting and querying configuration.
* resetting hardware.
* indicating status.
* indicating received data.
* transferring received data.
---- 掬水月在手
弄花香满身
|
|