skcsum.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /******************************************************************************
  2. *
  3. * Name: skcsum.h
  4. * Project: GEnesis - SysKonnect SK-NET Gigabit Ethernet (SK-98xx)
  5. * Version: $Revision: 1.9 $
  6. * Date: $Date: 2001/02/06 11:21:39 $
  7. * Purpose: Store/verify Internet checksum in send/receive packets.
  8. *
  9. ******************************************************************************/
  10. /******************************************************************************
  11. *
  12. * (C)Copyright 1998-2001 SysKonnect GmbH.
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * The information in this file is provided "AS IS" without warranty.
  20. *
  21. ******************************************************************************/
  22. /******************************************************************************
  23. *
  24. * History:
  25. *
  26. * $Log: skcsum.h,v $
  27. * Revision 1.9 2001/02/06 11:21:39 rassmann
  28. * Editorial changes.
  29. *
  30. * Revision 1.8 2001/02/06 11:15:36 rassmann
  31. * Supporting two nets on dual-port adapters.
  32. *
  33. * Revision 1.7 2000/06/29 13:17:05 rassmann
  34. * Corrected reception of a packet with UDP checksum == 0 (which means there
  35. * is no UDP checksum).
  36. *
  37. * Revision 1.6 2000/02/28 12:33:44 cgoos
  38. * Changed C++ style comments to C style.
  39. *
  40. * Revision 1.5 2000/02/21 12:10:05 cgoos
  41. * Fixed license comment.
  42. *
  43. * Revision 1.4 2000/02/21 11:08:37 cgoos
  44. * Merged changes back into common source.
  45. *
  46. * Revision 1.1 1999/07/26 14:47:49 mkarl
  47. * changed from common source to windows specific source
  48. * added return SKCS_STATUS_IP_CSUM_ERROR_UDP and
  49. * SKCS_STATUS_IP_CSUM_ERROR_TCP to pass the NidsTester
  50. * changes for Tx csum offload
  51. *
  52. * Revision 1.2 1998/09/04 12:16:34 mhaveman
  53. * Checked in for Stephan to allow compilation.
  54. * -Added definition SK_CSUM_EVENT_CLEAR_PROTO_STATS to clear statistic
  55. * -Added prototype for SkCsEvent()
  56. *
  57. * Revision 1.1 1998/09/01 15:36:53 swolf
  58. * initial revision
  59. *
  60. * 01-Sep-1998 sw Created.
  61. *
  62. ******************************************************************************/
  63. /******************************************************************************
  64. *
  65. * Description:
  66. *
  67. * Public header file for the "GEnesis" common module "CSUM".
  68. *
  69. * "GEnesis" is an abbreviation of "Gigabit Ethernet Network System in Silicon"
  70. * and is the code name of this SysKonnect project.
  71. *
  72. * Compilation Options:
  73. *
  74. * SK_USE_CSUM - Define if CSUM is to be used. Otherwise, CSUM will be an
  75. * empty module.
  76. *
  77. * SKCS_OVERWRITE_PROTO - Define to overwrite the default protocol id
  78. * definitions. In this case, all SKCS_PROTO_xxx definitions must be made
  79. * external.
  80. *
  81. * SKCS_OVERWRITE_STATUS - Define to overwrite the default return status
  82. * definitions. In this case, all SKCS_STATUS_xxx definitions must be made
  83. * external.
  84. *
  85. * Include File Hierarchy:
  86. *
  87. * "h/skcsum.h"
  88. * "h/sktypes.h"
  89. * "h/skqueue.h"
  90. *
  91. ******************************************************************************/
  92. #ifndef __INC_SKCSUM_H
  93. #define __INC_SKCSUM_H
  94. #include "h/sktypes.h"
  95. #include "h/skqueue.h"
  96. /* defines ********************************************************************/
  97. /*
  98. * Define the default bit flags for 'SKCS_PACKET_INFO.ProtocolFlags' if no user
  99. * overwrite.
  100. */
  101. #ifndef SKCS_OVERWRITE_PROTO /* User overwrite? */
  102. #define SKCS_PROTO_IP 0x1 /* IP (Internet Protocol version 4) */
  103. #define SKCS_PROTO_TCP 0x2 /* TCP (Transmission Control Protocol) */
  104. #define SKCS_PROTO_UDP 0x4 /* UDP (User Datagram Protocol) */
  105. /* Indices for protocol statistics. */
  106. #define SKCS_PROTO_STATS_IP 0
  107. #define SKCS_PROTO_STATS_UDP 1
  108. #define SKCS_PROTO_STATS_TCP 2
  109. #define SKCS_NUM_PROTOCOLS 3 /* Number of supported protocols. */
  110. #endif /* !SKCS_OVERWRITE_PROTO */
  111. /*
  112. * Define the default SKCS_STATUS type and values if no user overwrite.
  113. *
  114. * SKCS_STATUS_UNKNOWN_IP_VERSION - Not an IP v4 frame.
  115. * SKCS_STATUS_IP_CSUM_ERROR - IP checksum error.
  116. * SKCS_STATUS_IP_CSUM_ERROR_TCP - IP checksum error in TCP frame.
  117. * SKCS_STATUS_IP_CSUM_ERROR_UDP - IP checksum error in UDP frame
  118. * SKCS_STATUS_IP_FRAGMENT - IP fragment (IP checksum ok).
  119. * SKCS_STATUS_IP_CSUM_OK - IP checksum ok (not a TCP or UDP frame).
  120. * SKCS_STATUS_TCP_CSUM_ERROR - TCP checksum error (IP checksum ok).
  121. * SKCS_STATUS_UDP_CSUM_ERROR - UDP checksum error (IP checksum ok).
  122. * SKCS_STATUS_TCP_CSUM_OK - IP and TCP checksum ok.
  123. * SKCS_STATUS_UDP_CSUM_OK - IP and UDP checksum ok.
  124. * SKCS_STATUS_IP_CSUM_OK_NO_UDP - IP checksum OK and no UDP checksum.
  125. */
  126. #ifndef SKCS_OVERWRITE_STATUS /* User overwrite? */
  127. #define SKCS_STATUS int /* Define status type. */
  128. #define SKCS_STATUS_UNKNOWN_IP_VERSION 1
  129. #define SKCS_STATUS_IP_CSUM_ERROR 2
  130. #define SKCS_STATUS_IP_FRAGMENT 3
  131. #define SKCS_STATUS_IP_CSUM_OK 4
  132. #define SKCS_STATUS_TCP_CSUM_ERROR 5
  133. #define SKCS_STATUS_UDP_CSUM_ERROR 6
  134. #define SKCS_STATUS_TCP_CSUM_OK 7
  135. #define SKCS_STATUS_UDP_CSUM_OK 8
  136. /* needed for Microsoft */
  137. #define SKCS_STATUS_IP_CSUM_ERROR_UDP 9
  138. #define SKCS_STATUS_IP_CSUM_ERROR_TCP 10
  139. /* UDP checksum may be omitted */
  140. #define SKCS_STATUS_IP_CSUM_OK_NO_UDP 11
  141. #endif /* !SKCS_OVERWRITE_STATUS */
  142. /* Clear protocol statistics event. */
  143. #define SK_CSUM_EVENT_CLEAR_PROTO_STATS 1
  144. /*
  145. * Add two values in one's complement.
  146. *
  147. * Note: One of the two input values may be "longer" than 16-bit, but then the
  148. * resulting sum may be 17 bits long. In this case, add zero to the result using
  149. * SKCS_OC_ADD() again.
  150. *
  151. * Result = Value1 + Value2
  152. */
  153. #define SKCS_OC_ADD(Result, Value1, Value2) { \
  154. unsigned long Sum; \
  155. \
  156. Sum = (unsigned long) (Value1) + (unsigned long) (Value2); \
  157. /* Add-in any carry. */ \
  158. (Result) = (Sum & 0xffff) + (Sum >> 16); \
  159. }
  160. /*
  161. * Subtract two values in one's complement.
  162. *
  163. * Result = Value1 - Value2
  164. */
  165. #define SKCS_OC_SUB(Result, Value1, Value2) \
  166. SKCS_OC_ADD((Result), (Value1), ~(Value2) & 0xffff)
  167. /* typedefs *******************************************************************/
  168. /*
  169. * SKCS_PROTO_STATS - The CSUM protocol statistics structure.
  170. *
  171. * There is one instance of this structure for each protocol supported.
  172. */
  173. typedef struct s_CsProtocolStatistics {
  174. SK_U64 RxOkCts; /* Receive checksum ok. */
  175. SK_U64 RxUnableCts; /* Unable to verify receive checksum. */
  176. SK_U64 RxErrCts; /* Receive checksum error. */
  177. SK_U64 TxOkCts; /* Transmit checksum ok. */
  178. SK_U64 TxUnableCts; /* Unable to calculate checksum in hw. */
  179. } SKCS_PROTO_STATS;
  180. /*
  181. * s_Csum - The CSUM module context structure.
  182. */
  183. typedef struct s_Csum {
  184. /* Enabled receive SK_PROTO_XXX bit flags. */
  185. unsigned ReceiveFlags[SK_MAX_NETS];
  186. #ifdef TX_CSUM
  187. unsigned TransmitFlags[SK_MAX_NETS];
  188. #endif /* TX_CSUM */
  189. /* The protocol statistics structure; one per supported protocol. */
  190. SKCS_PROTO_STATS ProtoStats[SK_MAX_NETS][SKCS_NUM_PROTOCOLS];
  191. } SK_CSUM;
  192. /*
  193. * SKCS_PACKET_INFO - The packet information structure.
  194. */
  195. typedef struct s_CsPacketInfo {
  196. /* Bit field specifiying the desired/found protocols. */
  197. unsigned ProtocolFlags;
  198. /* Length of complete IP header, including any option fields. */
  199. unsigned IpHeaderLength;
  200. /* IP header checksum. */
  201. unsigned IpHeaderChecksum;
  202. /* TCP/UDP pseudo header checksum. */
  203. unsigned PseudoHeaderChecksum;
  204. } SKCS_PACKET_INFO;
  205. /* function prototypes ********************************************************/
  206. #ifndef SkCsCalculateChecksum
  207. extern unsigned SkCsCalculateChecksum(
  208. void *pData,
  209. unsigned Length);
  210. #endif
  211. extern int SkCsEvent(
  212. SK_AC *pAc,
  213. SK_IOC Ioc,
  214. SK_U32 Event,
  215. SK_EVPARA Param);
  216. extern SKCS_STATUS SkCsGetReceiveInfo(
  217. SK_AC *pAc,
  218. void *pIpHeader,
  219. unsigned Checksum1,
  220. unsigned Checksum2,
  221. int NetNumber);
  222. extern void SkCsGetSendInfo(
  223. SK_AC *pAc,
  224. void *pIpHeader,
  225. SKCS_PACKET_INFO *pPacketInfo,
  226. int NetNumber);
  227. extern void SkCsSetReceiveFlags(
  228. SK_AC *pAc,
  229. unsigned ReceiveFlags,
  230. unsigned *pChecksum1Offset,
  231. unsigned *pChecksum2Offset,
  232. int NetNumber);
  233. #endif /* __INC_SKCSUM_H */