]> git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/net/sk98lin/h/skcsum.h
85xx: Drop FIT support to allow u-boot image to fit in 512k
[people/ms/u-boot.git] / drivers / net / sk98lin / h / skcsum.h
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 *
13 * (C)Copyright 1998-2001 SysKonnect GmbH.
14 *
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.
19 *
20 * The information in this file is provided "AS IS" without warranty.
21 *
22 ******************************************************************************/
23
24 /******************************************************************************
25 *
26 * History:
27 *
28 * $Log: skcsum.h,v $
29 * Revision 1.9 2001/02/06 11:21:39 rassmann
30 * Editorial changes.
31 *
32 * Revision 1.8 2001/02/06 11:15:36 rassmann
33 * Supporting two nets on dual-port adapters.
34 *
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).
38 *
39 * Revision 1.6 2000/02/28 12:33:44 cgoos
40 * Changed C++ style comments to C style.
41 *
42 * Revision 1.5 2000/02/21 12:10:05 cgoos
43 * Fixed license comment.
44 *
45 * Revision 1.4 2000/02/21 11:08:37 cgoos
46 * Merged changes back into common source.
47 *
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
53 *
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()
58 *
59 * Revision 1.1 1998/09/01 15:36:53 swolf
60 * initial revision
61 *
62 * 01-Sep-1998 sw Created.
63 *
64 ******************************************************************************/
65
66 /******************************************************************************
67 *
68 * Description:
69 *
70 * Public header file for the "GEnesis" common module "CSUM".
71 *
72 * "GEnesis" is an abbreviation of "Gigabit Ethernet Network System in Silicon"
73 * and is the code name of this SysKonnect project.
74 *
75 * Compilation Options:
76 *
77 * SK_USE_CSUM - Define if CSUM is to be used. Otherwise, CSUM will be an
78 * empty module.
79 *
80 * SKCS_OVERWRITE_PROTO - Define to overwrite the default protocol id
81 * definitions. In this case, all SKCS_PROTO_xxx definitions must be made
82 * external.
83 *
84 * SKCS_OVERWRITE_STATUS - Define to overwrite the default return status
85 * definitions. In this case, all SKCS_STATUS_xxx definitions must be made
86 * external.
87 *
88 * Include File Hierarchy:
89 *
90 * "h/skcsum.h"
91 * "h/sktypes.h"
92 * "h/skqueue.h"
93 *
94 ******************************************************************************/
95
96 #ifndef __INC_SKCSUM_H
97 #define __INC_SKCSUM_H
98
99 #include "h/sktypes.h"
100 #include "h/skqueue.h"
101
102 /* defines ********************************************************************/
103
104 /*
105 * Define the default bit flags for 'SKCS_PACKET_INFO.ProtocolFlags' if no user
106 * overwrite.
107 */
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) */
112
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 */
119
120 /*
121 * Define the default SKCS_STATUS type and values if no user overwrite.
122 *
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.
134 */
135 #ifndef SKCS_OVERWRITE_STATUS /* User overwrite? */
136 #define SKCS_STATUS int /* Define status type. */
137
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 */
152
153 /* Clear protocol statistics event. */
154 #define SK_CSUM_EVENT_CLEAR_PROTO_STATS 1
155
156 /*
157 * Add two values in one's complement.
158 *
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.
162 *
163 * Result = Value1 + Value2
164 */
165 #define SKCS_OC_ADD(Result, Value1, Value2) { \
166 unsigned long Sum; \
167 \
168 Sum = (unsigned long) (Value1) + (unsigned long) (Value2); \
169 /* Add-in any carry. */ \
170 (Result) = (Sum & 0xffff) + (Sum >> 16); \
171 }
172
173 /*
174 * Subtract two values in one's complement.
175 *
176 * Result = Value1 - Value2
177 */
178 #define SKCS_OC_SUB(Result, Value1, Value2) \
179 SKCS_OC_ADD((Result), (Value1), ~(Value2) & 0xffff)
180
181 /* typedefs *******************************************************************/
182
183 /*
184 * SKCS_PROTO_STATS - The CSUM protocol statistics structure.
185 *
186 * There is one instance of this structure for each protocol supported.
187 */
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. */
194 } SKCS_PROTO_STATS;
195
196 /*
197 * s_Csum - The CSUM module context structure.
198 */
199 typedef struct s_Csum {
200 /* Enabled receive SK_PROTO_XXX bit flags. */
201 unsigned ReceiveFlags[SK_MAX_NETS];
202 #ifdef TX_CSUM
203 unsigned TransmitFlags[SK_MAX_NETS];
204 #endif /* TX_CSUM */
205
206 /* The protocol statistics structure; one per supported protocol. */
207 SKCS_PROTO_STATS ProtoStats[SK_MAX_NETS][SKCS_NUM_PROTOCOLS];
208 } SK_CSUM;
209
210 /*
211 * SKCS_PACKET_INFO - The packet information structure.
212 */
213 typedef struct s_CsPacketInfo {
214 /* Bit field specifiying the desired/found protocols. */
215 unsigned ProtocolFlags;
216
217 /* Length of complete IP header, including any option fields. */
218 unsigned IpHeaderLength;
219
220 /* IP header checksum. */
221 unsigned IpHeaderChecksum;
222
223 /* TCP/UDP pseudo header checksum. */
224 unsigned PseudoHeaderChecksum;
225 } SKCS_PACKET_INFO;
226
227 /* function prototypes ********************************************************/
228
229 #ifndef SkCsCalculateChecksum
230 extern unsigned SkCsCalculateChecksum(
231 void *pData,
232 unsigned Length);
233 #endif
234
235 extern int SkCsEvent(
236 SK_AC *pAc,
237 SK_IOC Ioc,
238 SK_U32 Event,
239 SK_EVPARA Param);
240
241 extern SKCS_STATUS SkCsGetReceiveInfo(
242 SK_AC *pAc,
243 void *pIpHeader,
244 unsigned Checksum1,
245 unsigned Checksum2,
246 int NetNumber);
247
248 extern void SkCsGetSendInfo(
249 SK_AC *pAc,
250 void *pIpHeader,
251 SKCS_PACKET_INFO *pPacketInfo,
252 int NetNumber);
253
254 extern void SkCsSetReceiveFlags(
255 SK_AC *pAc,
256 unsigned ReceiveFlags,
257 unsigned *pChecksum1Offset,
258 unsigned *pChecksum2Offset,
259 int NetNumber);
260
261 #endif /* __INC_SKCSUM_H */