Muokkaa

Jaa


Asynchronous I/O and Completion Functions in Network Drivers

Latency is inherent in some network operations. Because of this latency, many of the upper-edge functions provided by a miniport 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 that are performed by a protocol or miniport driver.

When a protocol driver calls NDIS to send a packet, resulting in a call to the miniport driver's MiniportSendNetBufferLists function, the miniport 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 miniport driver (or NDIS) queues the packet and waits for the NIC to indicate the result of the send operation. The miniport driver MiniportSendNetBufferLists function can handle this operation asynchronously by returning a status value of NDIS_STATUS_PENDING. When the miniport driver completes the send operation, it calls the completion function, NdisMSendNetBufferListsComplete, 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 to:

  • Set and querying configuration.

  • Reset hardware.

  • Indicate status.

  • Indicate received data.

  • Transfer received data.