1 /******************************************************************************
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.
9 ******************************************************************************/
11 /******************************************************************************
13 * (C)Copyright 1998-2001 SysKonnect GmbH.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * The information in this file is provided "AS IS" without warranty.
22 ******************************************************************************/
24 /******************************************************************************
29 * Revision 1.9 2001/02/06 11:21:39 rassmann
32 * Revision 1.8 2001/02/06 11:15:36 rassmann
33 * Supporting two nets on dual-port adapters.
35 * Revision 1.7 2000/06/29 13:17:05 rassmann
36 * Corrected reception of a packet with UDP checksum == 0 (which means there
37 * is no UDP checksum).
39 * Revision 1.6 2000/02/28 12:33:44 cgoos
40 * Changed C++ style comments to C style.
42 * Revision 1.5 2000/02/21 12:10:05 cgoos
43 * Fixed license comment.
45 * Revision 1.4 2000/02/21 11:08:37 cgoos
46 * Merged changes back into common source.
48 * Revision 1.1 1999/07/26 14:47:49 mkarl
49 * changed from common source to windows specific source
50 * added return SKCS_STATUS_IP_CSUM_ERROR_UDP and
51 * SKCS_STATUS_IP_CSUM_ERROR_TCP to pass the NidsTester
52 * changes for Tx csum offload
54 * Revision 1.2 1998/09/04 12:16:34 mhaveman
55 * Checked in for Stephan to allow compilation.
56 * -Added definition SK_CSUM_EVENT_CLEAR_PROTO_STATS to clear statistic
57 * -Added prototype for SkCsEvent()
59 * Revision 1.1 1998/09/01 15:36:53 swolf
62 * 01-Sep-1998 sw Created.
64 ******************************************************************************/
66 /******************************************************************************
70 * Public header file for the "GEnesis" common module "CSUM".
72 * "GEnesis" is an abbreviation of "Gigabit Ethernet Network System in Silicon"
73 * and is the code name of this SysKonnect project.
75 * Compilation Options:
77 * SK_USE_CSUM - Define if CSUM is to be used. Otherwise, CSUM will be an
80 * SKCS_OVERWRITE_PROTO - Define to overwrite the default protocol id
81 * definitions. In this case, all SKCS_PROTO_xxx definitions must be made
84 * SKCS_OVERWRITE_STATUS - Define to overwrite the default return status
85 * definitions. In this case, all SKCS_STATUS_xxx definitions must be made
88 * Include File Hierarchy:
94 ******************************************************************************/
96 #ifndef __INC_SKCSUM_H
97 #define __INC_SKCSUM_H
99 #include "h/sktypes.h"
100 #include "h/skqueue.h"
102 /* defines ********************************************************************/
105 * Define the default bit flags for 'SKCS_PACKET_INFO.ProtocolFlags' if no user
108 #ifndef SKCS_OVERWRITE_PROTO /* User overwrite? */
109 #define SKCS_PROTO_IP 0x1 /* IP (Internet Protocol version 4) */
110 #define SKCS_PROTO_TCP 0x2 /* TCP (Transmission Control Protocol) */
111 #define SKCS_PROTO_UDP 0x4 /* UDP (User Datagram Protocol) */
113 /* Indices for protocol statistics. */
114 #define SKCS_PROTO_STATS_IP 0
115 #define SKCS_PROTO_STATS_UDP 1
116 #define SKCS_PROTO_STATS_TCP 2
117 #define SKCS_NUM_PROTOCOLS 3 /* Number of supported protocols. */
118 #endif /* !SKCS_OVERWRITE_PROTO */
121 * Define the default SKCS_STATUS type and values if no user overwrite.
123 * SKCS_STATUS_UNKNOWN_IP_VERSION - Not an IP v4 frame.
124 * SKCS_STATUS_IP_CSUM_ERROR - IP checksum error.
125 * SKCS_STATUS_IP_CSUM_ERROR_TCP - IP checksum error in TCP frame.
126 * SKCS_STATUS_IP_CSUM_ERROR_UDP - IP checksum error in UDP frame
127 * SKCS_STATUS_IP_FRAGMENT - IP fragment (IP checksum ok).
128 * SKCS_STATUS_IP_CSUM_OK - IP checksum ok (not a TCP or UDP frame).
129 * SKCS_STATUS_TCP_CSUM_ERROR - TCP checksum error (IP checksum ok).
130 * SKCS_STATUS_UDP_CSUM_ERROR - UDP checksum error (IP checksum ok).
131 * SKCS_STATUS_TCP_CSUM_OK - IP and TCP checksum ok.
132 * SKCS_STATUS_UDP_CSUM_OK - IP and UDP checksum ok.
133 * SKCS_STATUS_IP_CSUM_OK_NO_UDP - IP checksum OK and no UDP checksum.
135 #ifndef SKCS_OVERWRITE_STATUS /* User overwrite? */
136 #define SKCS_STATUS int /* Define status type. */
138 #define SKCS_STATUS_UNKNOWN_IP_VERSION 1
139 #define SKCS_STATUS_IP_CSUM_ERROR 2
140 #define SKCS_STATUS_IP_FRAGMENT 3
141 #define SKCS_STATUS_IP_CSUM_OK 4
142 #define SKCS_STATUS_TCP_CSUM_ERROR 5
143 #define SKCS_STATUS_UDP_CSUM_ERROR 6
144 #define SKCS_STATUS_TCP_CSUM_OK 7
145 #define SKCS_STATUS_UDP_CSUM_OK 8
146 /* needed for Microsoft */
147 #define SKCS_STATUS_IP_CSUM_ERROR_UDP 9
148 #define SKCS_STATUS_IP_CSUM_ERROR_TCP 10
149 /* UDP checksum may be omitted */
150 #define SKCS_STATUS_IP_CSUM_OK_NO_UDP 11
151 #endif /* !SKCS_OVERWRITE_STATUS */
153 /* Clear protocol statistics event. */
154 #define SK_CSUM_EVENT_CLEAR_PROTO_STATS 1
157 * Add two values in one's complement.
159 * Note: One of the two input values may be "longer" than 16-bit, but then the
160 * resulting sum may be 17 bits long. In this case, add zero to the result using
161 * SKCS_OC_ADD() again.
163 * Result = Value1 + Value2
165 #define SKCS_OC_ADD(Result, Value1, Value2) { \
168 Sum = (unsigned long) (Value1) + (unsigned long) (Value2); \
169 /* Add-in any carry. */ \
170 (Result) = (Sum & 0xffff) + (Sum >> 16); \
174 * Subtract two values in one's complement.
176 * Result = Value1 - Value2
178 #define SKCS_OC_SUB(Result, Value1, Value2) \
179 SKCS_OC_ADD((Result), (Value1), ~(Value2) & 0xffff)
181 /* typedefs *******************************************************************/
184 * SKCS_PROTO_STATS - The CSUM protocol statistics structure.
186 * There is one instance of this structure for each protocol supported.
188 typedef struct s_CsProtocolStatistics {
189 SK_U64 RxOkCts; /* Receive checksum ok. */
190 SK_U64 RxUnableCts; /* Unable to verify receive checksum. */
191 SK_U64 RxErrCts; /* Receive checksum error. */
192 SK_U64 TxOkCts; /* Transmit checksum ok. */
193 SK_U64 TxUnableCts; /* Unable to calculate checksum in hw. */
197 * s_Csum - The CSUM module context structure.
199 typedef struct s_Csum {
200 /* Enabled receive SK_PROTO_XXX bit flags. */
201 unsigned ReceiveFlags[SK_MAX_NETS];
203 unsigned TransmitFlags[SK_MAX_NETS];
206 /* The protocol statistics structure; one per supported protocol. */
207 SKCS_PROTO_STATS ProtoStats[SK_MAX_NETS][SKCS_NUM_PROTOCOLS];
211 * SKCS_PACKET_INFO - The packet information structure.
213 typedef struct s_CsPacketInfo {
214 /* Bit field specifiying the desired/found protocols. */
215 unsigned ProtocolFlags;
217 /* Length of complete IP header, including any option fields. */
218 unsigned IpHeaderLength;
220 /* IP header checksum. */
221 unsigned IpHeaderChecksum;
223 /* TCP/UDP pseudo header checksum. */
224 unsigned PseudoHeaderChecksum;
227 /* function prototypes ********************************************************/
229 #ifndef SkCsCalculateChecksum
230 extern unsigned SkCsCalculateChecksum(
235 extern int SkCsEvent(
241 extern SKCS_STATUS SkCsGetReceiveInfo(
248 extern void SkCsGetSendInfo(
251 SKCS_PACKET_INFO *pPacketInfo,
254 extern void SkCsSetReceiveFlags(
256 unsigned ReceiveFlags,
257 unsigned *pChecksum1Offset,
258 unsigned *pChecksum2Offset,
261 #endif /* __INC_SKCSUM_H */