Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. offload.h
  5. Abstract:
  6. Task offloading header file
  7. Revision History:
  8. Who When What
  9. -------- -------- ----------------------------------------------
  10. created
  11. Notes:
  12. --*/
  13. #if OFFLOAD
  14. //
  15. // Define the maximum size of large TCP packets the driver can offload.
  16. // This sample driver uses shared memory to map the large packets,
  17. // LARGE_SEND_OFFLOAD_SIZE is useless in this case, so we just define
  18. // it as NIC_MAX_PACKET_SIZE. But shipping drivers should define
  19. // LARGE_SEND_OFFLOAD_SIZE if they support LSO, and use it as
  20. // MaximumPhysicalMapping when they call NdisMInitializeScatterGatherDma
  21. // if they use ScatterGather method. If the drivers don't support
  22. // LSO, then MaximumPhysicalMapping is NIC_MAX_PACKET_SIZE.
  23. //
  24. #define LARGE_SEND_OFFLOAD_SIZE NIC_MAX_PACKET_SIZE
  25. //
  26. // Definitions for header flags.
  27. //
  28. #define TCP_FLAG_FIN 0x00000100
  29. #define TCP_FLAG_SYN 0x00000200
  30. #define TCP_FLAG_RST 0x00000400
  31. #define TCP_FLAG_PUSH 0x00000800
  32. #define TCP_FLAG_ACK 0x00001000
  33. #define TCP_FLAG_URG 0x00002000
  34. //
  35. // These are the maximum size of TCP and IP options
  36. //
  37. #define TCP_MAX_OPTION_SIZE 40
  38. #define IP_MAX_OPTION_SIZE 40
  39. //
  40. // Structure of a TCP packet header.
  41. //
  42. struct TCPHeader {
  43. USHORT tcp_src; // Source port.
  44. USHORT tcp_dest; // Destination port.
  45. int tcp_seq; // Sequence number.
  46. int tcp_ack; // Ack number.
  47. USHORT tcp_flags; // Flags and data offset.
  48. USHORT tcp_window; // Window offered.
  49. USHORT tcp_xsum; // Checksum.
  50. USHORT tcp_urgent; // Urgent pointer.
  51. };
  52. typedef struct TCPHeader TCPHeader;
  53. //
  54. // IP Header format.
  55. //
  56. typedef struct IPHeader {
  57. UCHAR iph_verlen; // Version and length.
  58. UCHAR iph_tos; // Type of service.
  59. USHORT iph_length; // Total length of datagram.
  60. USHORT iph_id; // Identification.
  61. USHORT iph_offset; // Flags and fragment offset.
  62. UCHAR iph_ttl; // Time to live.
  63. UCHAR iph_protocol; // Protocol.
  64. USHORT iph_xsum; // Header checksum.
  65. UINT iph_src; // Source address.
  66. UINT iph_dest; // Destination address.
  67. } IPHeader;
  68. #define TCP_IP_MAX_HEADER_SIZE TCP_MAX_OPTION_SIZE+IP_MAX_OPTION_SIZE \
  69. +sizeof(TCPHeader)+sizeof(IPHeader)
  70. #define LARGE_SEND_MEM_SIZE_OPTION 3
  71. //
  72. // Try different size of shared memory to use
  73. //
  74. extern ULONG LargeSendSharedMemArray[];
  75. //
  76. // Compute the checksum
  77. //
  78. #define XSUM(_TmpXsum, _StartVa, _PacketLength, _Offset) \
  79. { \
  80. PUSHORT WordPtr = (PUSHORT)((PUCHAR)_StartVa + _Offset); \
  81. ULONG WordCount = (_PacketLength) >> 1; \
  82. BOOLEAN fOddLen = (BOOLEAN)((_PacketLength) & 1); \
  83. while (WordCount--) \
  84. { \
  85. _TmpXsum += *WordPtr; \
  86. WordPtr++; \
  87. } \
  88. if (fOddLen) \
  89. { \
  90. _TmpXsum += (USHORT)*((PUCHAR)WordPtr); \
  91. } \
  92. _TmpXsum = (((_TmpXsum >> 16) | (_TmpXsum << 16)) + _TmpXsum) >> 16; \
  93. }
  94. //
  95. // Function prototypes
  96. //
  97. VOID
  98. e100DumpPkt(
  99. PNDIS_PACKET Packet
  100. );
  101. VOID
  102. CalculateChecksum(
  103. PVOID StartVa,
  104. ULONG PacketLength,
  105. PNDIS_PACKET pPacket,
  106. ULONG IpHdrOffset
  107. );
  108. VOID
  109. CalculateTcpChecksum(
  110. PVOID StartVa,
  111. ULONG PacketLength,
  112. ULONG IpHdrOffset
  113. );
  114. VOID
  115. CalculateIpChecksum(
  116. PUCHAR StartVa,
  117. ULONG IpHdrOffset
  118. );
  119. VOID
  120. CalculateUdpChecksum(
  121. PNDIS_PACKET Packet,
  122. ULONG IpHdrOffset
  123. );
  124. VOID
  125. MPOffloadSendPackets(
  126. IN NDIS_HANDLE MiniportAdapterContext,
  127. IN PPNDIS_PACKET PacketArray,
  128. IN UINT NumberOfPackets
  129. );
  130. NDIS_STATUS
  131. MpOffloadSendPacket(
  132. IN PMP_ADAPTER Adapter,
  133. IN PNDIS_PACKET Packet,
  134. IN BOOLEAN bFromQueue
  135. );
  136. VOID
  137. MP_OFFLOAD_FREE_SEND_PACKET(
  138. IN PMP_ADAPTER Adapter,
  139. IN PMP_TCB pMpTcb
  140. );
  141. VOID
  142. DisableOffload(
  143. IN PMP_ADAPTER Adapter
  144. );
  145. #endif // OFFLOAD