logo

Navigation:First_Community->Software->Windows Driver Goto:New TopicSettingSearch
Task Offload
Posted by: chlchen2000 Date: October 20, 2005 11:24PM

CopyRight owned by the original author.--(www.MegaEntry.com)

To increase its performance, the Microsoft TCP/IP transport can offload one or more of the following tasks to a NIC that has the appropriate task-offload capabilities:
  • Checksum tasks. The TCP/IP transport can offload the calculation and/or validation of IP and/or TCP checksums.

  • Internet Protocol Security tasks The TCP/IP transport can offload the calculation and validation of encrypted checksums for authentication headers (AH) and/or encapsulating security payloads (ESP). The TCP/IP transport can also offload the encryption and decryption of ESP payloads. In addition, the transport can offload the encryption and decryption of UDP-encapsulated ESP data packets.

  • Segmentation of large TCP packets The TCP/IP transport supports Large Send Offload (LSO). With LSO, the TCP/IP transport can offload the segmentation of large TCP packets.

The TCP/IP transport supports task offload only for IPv4 packets.

Offloading tasks from the TCP/IP transport to a NIC involves two major operations:

Re: Task Offload
Posted by: chlchen2000 Date: October 20, 2005 11:25PM

Querying Task-Offload Capabilities

MegaEntry - Social networking and discussion site!

The TCP/IP transport determines a NIC 's task-offload capabilities by querying OID_TCP_TASK_OFFLOAD. In this query, the TCP/IP transport supplies, in the InformationBuffer, an NDIS_TASK_OFFLOAD_HEADER, which is defined as:

typedef struct _NDIS_TASK_OFFLOAD_HEADER
{
    ULONG  Version;
    ULONG  Size;
    ULONG  Reserved;
    UCHAR  OffsetFirstTask;
    NDIS_ENCAPSULATION_FORMAT  EncapsulationFormat;
} NDIS_TASK_OFFLOAD_HEADER, *PNDIS_TASK_OFFLOAD_HEADER;
The NDIS_TASK_OFFLOAD_HEADER structure specifies the following:
  • The task-offload version supported by the TCP/IP transport
  • The size of the NDIS_TASK_OFFLOAD_HEADER structure (which is used to check the version of the structure).
  • The offset in bytes from the beginning of the InformationBuffer to the first NDIS_TASK_OFFLOAD structure.
  • The encapsulation format for send and receive packets that were passed between the TCP/IP transport and the miniport driver.
By using the information supplied by the NDIS_TASK_OFFLOAD_HEADER, the miniport driver or its NIC can locate the beginning of the first IP header in a send or receive packet. This is a prerequisite for performing offload tasks.

In response to a query of OID_TCP_TASK_OFFLOAD, a miniport driver returns, in the InformationBuffer, the NDIS_TASK_OFFLOAD_HEADER followed by one or more NDIS_TASK_OFFLOAD structures. The NDIS_TASK_OFFLOAD structure is defined as:

typedef struct _NDIS_TASK_OFFLOAD
{
    ULONG      Version;
    ULONG      Size;
    NDIS_TASK  Task;
    ULONG      OffsetNextTask;
    ULONG      TaskBufferLength;
    UCHAR      TaskBuffer[1];
} NDIS_TASK_OFFLOAD, *PNDIS_TASK_OFFLOAD;
The NDIS_TASK_OFFLOAD structure specifies the following:
  • The version of the specified offload task.
  • The size of the NDIS_TASK_OFFLOAD structure (which is used to check the version of the structure).
  • The offload task.
  • The offset from the beginning of the InformationBuffer to the next NDIS_TASK_OFFLOAD structure.
  • The length of the TaskBuffer.
  • A variable-length array that contains task-specific information.
Each NDIS_TASK_OFFLOAD structure specifies a task-offload capability supported by the miniport driver 's NIC. If the miniport driver 's NIC supports multiple versions of a particular task-offload capability, it returns one NDIS_TASK_OFFLOAD structure for each version.


Re: Task Offload
Posted by: chlchen2000 Date: October 20, 2005 11:26PM

Offloading TCP/IP Checksum Tasks

CopyRight owned by the original author.--(www.MegaEntry.com)

TCP/IP checksum tasks cannot be offloaded to a load-balancing miniport driver. For more information on load balancing, see Load Balancing and Fail Over.

Before passing to the miniport driver a packet descriptor for a packet on which the miniport driver will perform one or more checksum tasks, the TCP/IP transport specifies the checksum information associated with the packet descriptor. This information is specified by an NDIS_TCP_IP_CHECKSUM_PACKET_INFO structure, which is part of the per-packet information (extended out-of-band data) that is associated with the packet descriptor.

The NDIS_TCP_IP_CHECKSUM_PACKET_INFO structure is defined as:

typedef struct _NDIS_TCP_IP_CHECKSUM_PACKET_INFO
{
  union
  {
    struct
    {
      ULONG    NdisPacketChecksumV4:1;
      ULONG    NdisPacketChecksumV6:1;
      ULONG    NdisPacketTcpChecksum:1;
      ULONG    NdisPacketUdpChecksum:1;
      ULONG    NdisPacketIpChecksum:1;
    } Transmit;
 
    struct
    {
      ULONG   NdisPacketTcpChecksumFailed:1;
      ULONG   NdisPacketUdpChecksumFailed:1;
      ULONG   NdisPacketIpChecksumFailed:1;
      ULONG   NdisPacketTcpChecksumSucceeded:1;
      ULONG   NdisPacketUdpChecksumSucceeded:1;
      ULONG   NdisPacketIpChecksumSucceeded:1;
      ULONG   NdisPacketLoopback:1;
    } Receive;
 
  ULONG    Value;
  };
} NDIS_TCP_IP_CHECKSUM_PACKET_INFO, *PNDIS_TCP_IP_CHECKSUM_PACKET_INFO;
Before offloading the checksum calculation for a TCP packet, the TCP/IP transport calculates the one 's complement sum for the TCP pseudoheader. The TCP/IP transport calculates the one 's complement sum across all fields in the pseudoheader, including Source IP Address, Destination IP Address, Protocol, and the TCP length for TCP packets. The TCP/IP transport enters the one 's complement sum for the pseudoheader in the Checksum field of the TCP header.

The one 's complement sum for the pseudoheader provided by the TCP/IP transport gives the NIC an early start in calculating the real TCP checksum for the send packet. To calculate the actual TCP checksum, the NIC calculates the variable part of the TCP checksum (for the TCP header and payload), adds this checksum to the one 's complement sum for the pseudoheader calculated by the TCP/IP transport, and calculates the 16-bit one 's complement for the checksum. For more information on calculating such checksums, see RFC 793 and RFC 1122.

After it receives the packet descriptor in its MiniportSend, MiniportSendPackets, or MiniportCoSendPackets function, a miniport driver typically does the following checksum processing:
  1. To determine the packet 's protocol, the miniport driver calls the NDIS_GET_PACKET_PROTOCOL_TYPE macro.
  2. If the protocol ID that the macro returns is not NDIS_PROTOCOL_ID_TCP_IP, the miniport driver 's NIC should not perform any checksum operations on the packet.
  3. If the returned protocol ID is NDIS_PROTOCOL_ID_TCP_IP, the miniport driver calls the NDIS_PER_PACKET_INFO_FROM_PACKET macro with an InfoType of TcpIpCheckSumPacketInfo to obtain a NDIS_TCP_IP_CHECKSUM_PACKET_INFO structure. Alternatively, the miniport driver can call the NDIS_PACKET_EXTENSION_FROM_PACKET macro to obtain a pointer to the NDIS_PACKET_EXTENSION structure. The miniport driver can then use the TcpIpCheckSumPacketInfo array index to obtain the NDIS_TCP_IP_CHECKSUM_PACKET_INFO structure.
  4. The miniport driver tests the NdisPacketChecksumV4 flag in the NDIS_TCP_IP_CHECKSUM_PACKET_INFO structure. If the NdisPacketChecksumV4 flag is not set, the miniport driver 's NIC should not perform any checksum operations on the packet.
  5. If the NdisPacketChecksumV4 flag is set, the miniport driver tests the NdisPacketTcpChecksum, NdisPacketUdpChecksum, and NdisPacketIpChecksum flags to determine which checksums its NIC should calculate for the packet.
  6. The miniport driver passes the packet to its NIC, which calculates the appropriate checksums for the packet. If a packet has both a tunnel IP header and a transport IP header, a NIC that supports IP checksum offloads performs IP checksum tasks only on the tunnel header. The TCP/IP transport performs IP checksum tasks on the transport IP header.
Before indicating up a receive packet on which it performs checksum tasks, the miniport driver validates the appropriate checksum(s) and sets the appropriate NdisPackeXxxChecksumFailed and/or NdisPacketXxxChecksumSucceeded flags in the NDIS_TCP_IP_CHECKSUM_PACKET_INFO structure.


Re: Task Offload
Posted by: chlchen2000 Date: October 20, 2005 11:26PM

Offloading the Segmentation of Large TCP Packets

CopyRight owned by the original author.--(www.MegaEntry.com)

A NIC that supports the segmentation of large TCP packets (TCP packets that are larger than the maximum transmission unit of the network medium), must also be able to:
  • Calculate IP checksums for send packets that contain IP options.
  • Calculate TCP checksums for send packets that contain TCP options.
If a miniport driver indicates that its NIC supports large-TCP-packet segmentation, the TCP/IP stack assumes that the NIC can perform this segmentation on large TCP packets that contain IP options and/or TCP options.

The TCP/IP transport offloads only those large TCP packets that meet the following criteria:
  • The packet is a TCP packet. The TCP/IP transport does not offload large UDP packets for segmentation.
  • The packet must be divisible by at least the minimum number of segments specified by the miniport driver. For more information, see Reporting a NIC 's TCP Packet Segmentation Capabilities.
  • The packet is not a loopback packet.
  • The packet will not be sent through a tunnel.
  • The packet will not be sent to a load-balancing miniport driver. For more information on load balancing, see Load Balancing and Fail Over.
Before offloading a large TCP packet for segmentation, the TCP/IP transport:
  • Updates the large-packet segmentation information that is associated with the packet descriptor. This information is a ULONG value that is part of the per-packet information that is associated with the packet descriptor. For more information on per-packet information, see NDIS_PACKET_EXTENSION. The TCP/IP transport sets this ULONG value to the maximum segment size (MSS), which is equivalent to the current maximum transmission unit (MTU). The MTU is the maximum number of user data bytes that the miniport driver can currently include in a single packet.
  • Writes the total length of the large TCP packet to the Total Length field of the packet 's IP header. The total length includes the length of the IP header, the length of the IP options if they are present, the length of the TCP header, the length of the TCP options if they are present, and the length of the TCP payload.
  • Calculates a one 's complement sum for the TCP pseudoheader and writes this sum to the Checksum field of the TCP header. The TCP/IP transport calculates the one 's complement sum over the following fields in the pseudoheader: Source IP Address, Destination IP Address, and Protocol. The one 's complement sum for the pseudoheader provided by the TCP/IP transport gives the NIC an early start in calculating the real TCP checksum for each packet that the NIC derives from the large TCP packet without having to examine the IP header.
  • Writes the correct sequence number to the Sequence Number field of the TCP header. The sequence number identifies the first byte of the TCP payload.
After the miniport driver obtains the packet descriptor in its MiniportSend, MiniportSendPackets, or MiniportCoSendPackets function, it can call the NDIS_PER_PACKET_INFO_FROM_PACKET macro with an InfoType of TcpLargeSendPacketInfo to obtain the MSS value written by the TCP/IP transport. Alternatively, the miniport driver can call the NDIS_PACKET_EXTENSION_FROM_PACKET macro to obtain a pointer to the NDIS_PACKET_EXTENSION structure. The miniport driver can then use the TcpLargeSendPacketInfo array index to obtain the MSS value.

The miniport driver obtains the total length of the large packet from the packet 's IP header and uses the MSS value to divide the large TCP packet into smaller packets. Each of the smaller packets contains MSS or less user data bytes. Note that only the last packet that was created from the segmented large packet should contain less than MSS user data bytes. All other packets that were created from the segmented packet should contain MSS user data bytes. If you do not follow this rule, the creation and transmission of unnecessary extra packets could degrade performance.

The miniport driver affixes MAC, IP, and TCP headers to each segment that is derived from the large packet. The miniport driver must calculate the IP and TCP checksums for these derived packets. To calculate the TCP checksum for each packet that was derived from the large TCP packet, the NIC calculates the variable part of the TCP checksum (for the TCP header and TCP payload), adds this checksum to the one 's complement sum for the pseudoheader calculated by the TCP/IP transport, and then calculates the 16-bit one 's complement for the checksum. For more information on calculating such checksums, see RFC 793 and RFC 1122.

The following figure shows the segmentation of a large packet.

Segmentation of a Large TCP Packet

The length of the TCP user data in the large TCP packet should be equal to or less than the value that the miniport driver assigns to the MaxOffloadSize. For more information, see Reporting a NIC 's TCP Packet Segmentation Capabilities.

The length of the TCP user data in a segment packet must be less than or equal to the MSS. The MSS is the ULONG value that the TCP transport passes down by using the per-packet information that is associated with the large TCP packet descriptor. Note that only the last packet that was created from the segmented large packet should contain less than MSS user data bytes. All other packets that were created from the segmented packet should contain MSS user data bytes. If you do not follow this rule, the creation and transmission of unnecessary extra packets could degrade performance.

The number of segment packets that were derived from the large TCP packet must be equal to or greater than the MinSegmentCount specified by the miniport driver. For more information, see Reporting a NIC 's TCP Packet Segmentation Capabilities.

The following assumptions and restrictions apply to processing IP and TCP headers:
  • The MF bit in the IP header of the large TCP packet that the TCP/IP transport offloaded will not be set, and the Fragment Offset in the IP header will be zero.
  • The URG, RST, and SYN flags in the TCP header of the large TCP packet will not be set, and the urgent offset (pointer) in the TCP header will be zero.
  • If the FIN bit in the TCP header of the large packet is set, the miniport driver must set this bit in the TCP header of the last packet that it creates from the large TCP packet.
  • If the PSH bit in the TCP header of the large TCP packet is set, the miniport driver must set this bit in the TCP header of the last packet that it creates from the large TCP packet.
  • If the large TCP packet contains IP options and/or TCP options, the miniport driver copies these options, unaltered, to each packet that it derived from the large TCP packet. Specifically, the NIC will not increment the Time Stamp option.
The miniport driver must send packets in the order that it receives them from the TCP/IP transport. However, the miniport driver can interleave packets that were created from a large TCP packet with other packets.

The miniport driver must also preserve the order of the ACKs that it receives in response to the transmission of packets that were derived from the large TCP packet. The miniport driver must indicate up packets that contain such ACKs in the order that it receives them so that the fast retransmit algorithms, fast recovery algorithms, and selective ACK algorithms performed by the TCP/IP transport work correctly.

CopyRight owned by the original author.--(www.MegaEntry.com)

When processing a large TCP packet, the miniport driver is responsible only for segmenting the packet and affixing MAC, IP, and TCP headers to the packets that are derived from the large TCP packet. The TCP/IP transport performs all other tasks (such as adjusting the send window size based on the remote host 's receive window size).

Before completing the send operation for the large packet (such as with NdisMSendComplete or NdisMCoSendComplete), the miniport driver writes the ULONG value (the per-packet information for large-TCP-packet offloads) with the total number of TCP user data bytes sent successfully in all packets that were created from the large TCP packet.


Next:PCI, PCI-X, and PCI Express: Frequ...

Reply To This Message
Subject: 

IE 6.0 or above is perfect