skcsum.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /******************************************************************************
  2. *
  3. * Name: skcsum.h
  4. * Project: GEnesis - SysKonnect SK-NET Gigabit Ethernet (SK-98xx)
  5. * Version: $Revision: 1.10 $
  6. * Date: $Date: 2003/08/20 13:59:57 $
  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. * Description:
  25. *
  26. * Public header file for the "GEnesis" common module "CSUM".
  27. *
  28. * "GEnesis" is an abbreviation of "Gigabit Ethernet Network System in Silicon"
  29. * and is the code name of this SysKonnect project.
  30. *
  31. * Compilation Options:
  32. *
  33. * SK_USE_CSUM - Define if CSUM is to be used. Otherwise, CSUM will be an
  34. * empty module.
  35. *
  36. * SKCS_OVERWRITE_PROTO - Define to overwrite the default protocol id
  37. * definitions. In this case, all SKCS_PROTO_xxx definitions must be made
  38. * external.
  39. *
  40. * SKCS_OVERWRITE_STATUS - Define to overwrite the default return status
  41. * definitions. In this case, all SKCS_STATUS_xxx definitions must be made
  42. * external.
  43. *
  44. * Include File Hierarchy:
  45. *
  46. * "h/skcsum.h"
  47. * "h/sktypes.h"
  48. * "h/skqueue.h"
  49. *
  50. ******************************************************************************/
  51. #ifndef __INC_SKCSUM_H
  52. #define __INC_SKCSUM_H
  53. #include "h/sktypes.h"
  54. #include "h/skqueue.h"
  55. /* defines ********************************************************************/
  56. /*
  57. * Define the default bit flags for 'SKCS_PACKET_INFO.ProtocolFlags' if no user
  58. * overwrite.
  59. */
  60. #ifndef SKCS_OVERWRITE_PROTO /* User overwrite? */
  61. #define SKCS_PROTO_IP 0x1 /* IP (Internet Protocol version 4) */
  62. #define SKCS_PROTO_TCP 0x2 /* TCP (Transmission Control Protocol) */
  63. #define SKCS_PROTO_UDP 0x4 /* UDP (User Datagram Protocol) */
  64. /* Indices for protocol statistics. */
  65. #define SKCS_PROTO_STATS_IP 0
  66. #define SKCS_PROTO_STATS_UDP 1
  67. #define SKCS_PROTO_STATS_TCP 2
  68. #define SKCS_NUM_PROTOCOLS 3 /* Number of supported protocols. */
  69. #endif /* !SKCS_OVERWRITE_PROTO */
  70. /*
  71. * Define the default SKCS_STATUS type and values if no user overwrite.
  72. *
  73. * SKCS_STATUS_UNKNOWN_IP_VERSION - Not an IP v4 frame.
  74. * SKCS_STATUS_IP_CSUM_ERROR - IP checksum error.
  75. * SKCS_STATUS_IP_CSUM_ERROR_TCP - IP checksum error in TCP frame.
  76. * SKCS_STATUS_IP_CSUM_ERROR_UDP - IP checksum error in UDP frame
  77. * SKCS_STATUS_IP_FRAGMENT - IP fragment (IP checksum ok).
  78. * SKCS_STATUS_IP_CSUM_OK - IP checksum ok (not a TCP or UDP frame).
  79. * SKCS_STATUS_TCP_CSUM_ERROR - TCP checksum error (IP checksum ok).
  80. * SKCS_STATUS_UDP_CSUM_ERROR - UDP checksum error (IP checksum ok).
  81. * SKCS_STATUS_TCP_CSUM_OK - IP and TCP checksum ok.
  82. * SKCS_STATUS_UDP_CSUM_OK - IP and UDP checksum ok.
  83. * SKCS_STATUS_IP_CSUM_OK_NO_UDP - IP checksum OK and no UDP checksum.
  84. */
  85. #ifndef SKCS_OVERWRITE_STATUS /* User overwrite? */
  86. #define SKCS_STATUS int /* Define status type. */
  87. #define SKCS_STATUS_UNKNOWN_IP_VERSION 1
  88. #define SKCS_STATUS_IP_CSUM_ERROR 2
  89. #define SKCS_STATUS_IP_FRAGMENT 3
  90. #define SKCS_STATUS_IP_CSUM_OK 4
  91. #define SKCS_STATUS_TCP_CSUM_ERROR 5
  92. #define SKCS_STATUS_UDP_CSUM_ERROR 6
  93. #define SKCS_STATUS_TCP_CSUM_OK 7
  94. #define SKCS_STATUS_UDP_CSUM_OK 8
  95. /* needed for Microsoft */
  96. #define SKCS_STATUS_IP_CSUM_ERROR_UDP 9
  97. #define SKCS_STATUS_IP_CSUM_ERROR_TCP 10
  98. /* UDP checksum may be omitted */
  99. #define SKCS_STATUS_IP_CSUM_OK_NO_UDP 11
  100. #endif /* !SKCS_OVERWRITE_STATUS */
  101. /* Clear protocol statistics event. */
  102. #define SK_CSUM_EVENT_CLEAR_PROTO_STATS 1
  103. /*
  104. * Add two values in one's complement.
  105. *
  106. * Note: One of the two input values may be "longer" than 16-bit, but then the
  107. * resulting sum may be 17 bits long. In this case, add zero to the result using
  108. * SKCS_OC_ADD() again.
  109. *
  110. * Result = Value1 + Value2
  111. */
  112. #define SKCS_OC_ADD(Result, Value1, Value2) { \
  113. unsigned long Sum; \
  114. \
  115. Sum = (unsigned long) (Value1) + (unsigned long) (Value2); \
  116. /* Add-in any carry. */ \
  117. (Result) = (Sum & 0xffff) + (Sum >> 16); \
  118. }
  119. /*
  120. * Subtract two values in one's complement.
  121. *
  122. * Result = Value1 - Value2
  123. */
  124. #define SKCS_OC_SUB(Result, Value1, Value2) \
  125. SKCS_OC_ADD((Result), (Value1), ~(Value2) & 0xffff)
  126. /* typedefs *******************************************************************/
  127. /*
  128. * SKCS_PROTO_STATS - The CSUM protocol statistics structure.
  129. *
  130. * There is one instance of this structure for each protocol supported.
  131. */
  132. typedef struct s_CsProtocolStatistics {
  133. SK_U64 RxOkCts; /* Receive checksum ok. */
  134. SK_U64 RxUnableCts; /* Unable to verify receive checksum. */
  135. SK_U64 RxErrCts; /* Receive checksum error. */
  136. SK_U64 TxOkCts; /* Transmit checksum ok. */
  137. SK_U64 TxUnableCts; /* Unable to calculate checksum in hw. */
  138. } SKCS_PROTO_STATS;
  139. /*
  140. * s_Csum - The CSUM module context structure.
  141. */
  142. typedef struct s_Csum {
  143. /* Enabled receive SK_PROTO_XXX bit flags. */
  144. unsigned ReceiveFlags[SK_MAX_NETS];
  145. #ifdef TX_CSUM
  146. unsigned TransmitFlags[SK_MAX_NETS];
  147. #endif /* TX_CSUM */
  148. /* The protocol statistics structure; one per supported protocol. */
  149. SKCS_PROTO_STATS ProtoStats[SK_MAX_NETS][SKCS_NUM_PROTOCOLS];
  150. } SK_CSUM;
  151. /*
  152. * SKCS_PACKET_INFO - The packet information structure.
  153. */
  154. typedef struct s_CsPacketInfo {
  155. /* Bit field specifiying the desired/found protocols. */
  156. unsigned ProtocolFlags;
  157. /* Length of complete IP header, including any option fields. */
  158. unsigned IpHeaderLength;
  159. /* IP header checksum. */
  160. unsigned IpHeaderChecksum;
  161. /* TCP/UDP pseudo header checksum. */
  162. unsigned PseudoHeaderChecksum;
  163. } SKCS_PACKET_INFO;
  164. /* function prototypes ********************************************************/
  165. #ifndef SK_CS_CALCULATE_CHECKSUM
  166. extern unsigned SkCsCalculateChecksum(
  167. void *pData,
  168. unsigned Length);
  169. #endif /* SK_CS_CALCULATE_CHECKSUM */
  170. extern int SkCsEvent(
  171. SK_AC *pAc,
  172. SK_IOC Ioc,
  173. SK_U32 Event,
  174. SK_EVPARA Param);
  175. extern SKCS_STATUS SkCsGetReceiveInfo(
  176. SK_AC *pAc,
  177. void *pIpHeader,
  178. unsigned Checksum1,
  179. unsigned Checksum2,
  180. int NetNumber);
  181. extern void SkCsSetReceiveFlags(
  182. SK_AC *pAc,
  183. unsigned ReceiveFlags,
  184. unsigned *pChecksum1Offset,
  185. unsigned *pChecksum2Offset,
  186. int NetNumber);
  187. #endif /* __INC_SKCSUM_H */