Special precautions are necessary when sharing cached memory between a NIC driver and its network interface card. Windows NT does not ensure execution of the NDIS interface library with an I/O-coherent cache, because the hardware on the network interface card can access shared physical memory on the card directly while the NIC driver accesses memory through the cache. This can cause differences in what the driver and the network interface card detect in memory, even if they look at the same location.
The use of noncached shared memory avoids most of the problems mentioned for cached shared memory. However, when data written to physical memory must use a small write queue, even noncached data may not appear in physical memory immediately. Additionally, there are cases when using noncached memory is not recommended or is not possible. For example, data that the NIC driver reads repeatedly should always be cached to improve performance. For example, a NIC driver may be required to pass a received data packet to a number of different transport 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 transport driver.
To help eliminate shared memory problems, several functions in the NDIS library should be used:
NdisMAllocateSharedMemory can be called by a miniport NIC driver to allocate memory for permanent sharing between the network interface card and the NIC driver. This function writes a virtual address and a physical address for the shared memory. The physical address is valid until a call to NdisMFreeSharedMemory frees the memory. To access the shared memory, your driver must call NdisMUpdateSharedMemory.
For full NIC drivers, the NDIS interface library offers similar functions: NdisAllocateSharedMemory, NdisFreeSharedMemory, and NdisUpdateSharedMemory.