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