1#ifndef _ASM_IA64_CHECKSUM_H
2#define _ASM_IA64_CHECKSUM_H
3
4/*
5 * Copyright (C) 1998, 1999 Hewlett-Packard Co
6 * Copyright (C) 1998, 1999 David Mosberger-Tang <davidm@hpl.hp.com>
7 */
8
9/*
10 * This is a version of ip_compute_csum() optimized for IP headers,
11 * which always checksum on 4 octet boundaries.
12 */
13extern unsigned short ip_fast_csum (unsigned char * iph, unsigned int ihl);
14
15/*
16 * Computes the checksum of the TCP/UDP pseudo-header returns a 16-bit
17 * checksum, already complemented
18 */
19extern unsigned short int csum_tcpudp_magic (unsigned long saddr,
20					     unsigned long daddr,
21					     unsigned short len,
22					     unsigned short proto,
23					     unsigned int sum);
24
25extern unsigned int csum_tcpudp_nofold (unsigned long saddr,
26					unsigned long daddr,
27					unsigned short len,
28					unsigned short proto,
29					unsigned int sum);
30
31/*
32 * Computes the checksum of a memory block at buff, length len,
33 * and adds in "sum" (32-bit)
34 *
35 * returns a 32-bit number suitable for feeding into itself
36 * or csum_tcpudp_magic
37 *
38 * this function must be called with even lengths, except
39 * for the last fragment, which may be odd
40 *
41 * it's best to have buff aligned on a 32-bit boundary
42 */
43extern unsigned int csum_partial (const unsigned char * buff, int len,
44				  unsigned int sum);
45
46/*
47 * Same as csum_partial, but copies from src while it checksums.
48 *
49 * Here it is even more important to align src and dst on a 32-bit (or
50 * even better 64-bit) boundary.
51 */
52extern unsigned int csum_partial_copy (const char *src, char *dst, int len,
53				       unsigned int sum);
54
55/*
56 * The same as csum_partial, but copies from user space (but on the
57 * ia-64 we have just one address space, so this is identical to the
58 * above).
59 *
60 * This is obsolete and will go away.
61 */
62#define csum_partial_copy_fromuser csum_partial_copy
63
64/*
65 * This is a new version of the above that records errors it finds in
66 * *errp, but continues and zeros the rest of the buffer.
67 */
68extern unsigned int csum_partial_copy_from_user (const char *src, char *dst,
69						 int len, unsigned int sum,
70						 int *errp);
71
72extern unsigned int csum_partial_copy_nocheck (const char *src, char *dst,
73					       int len, unsigned int sum);
74
75/*
76 * This routine is used for miscellaneous IP-like checksums, mainly in
77 * icmp.c
78 */
79extern unsigned short ip_compute_csum (unsigned char *buff, int len);
80
81/*
82 * Fold a partial checksum without adding pseudo headers.
83 */
84static inline unsigned short
85csum_fold (unsigned int sum)
86{
87	sum = (sum & 0xffff) + (sum >> 16);
88	sum = (sum & 0xffff) + (sum >> 16);
89	return ~sum;
90}
91
92#endif /* _ASM_IA64_CHECKSUM_H */
93