]>
git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - arch/s390/include/asm/checksum.h
6d01c96aeb5c4e0eb47e8edd4b950e37770ece08
1 /* SPDX-License-Identifier: GPL-2.0 */
3 * S390 fast network checksum routines
6 * Copyright IBM Corp. 1999
7 * Author(s): Ulrich Hild (first version)
8 * Martin Schwidefsky (heavily optimized CKSM version)
9 * D.J. Barrow (third attempt)
12 #ifndef _S390_CHECKSUM_H
13 #define _S390_CHECKSUM_H
15 #include <linux/uaccess.h>
18 * computes the checksum of a memory block at buff, length len,
19 * and adds in "sum" (32-bit)
21 * returns a 32-bit number suitable for feeding into itself
22 * or csum_tcpudp_magic
24 * this function must be called with even lengths, except
25 * for the last fragment, which may be odd
27 * it's best to have buff aligned on a 32-bit boundary
30 csum_partial(const void *buff
, int len
, __wsum sum
)
32 register unsigned long reg2
asm("2") = (unsigned long) buff
;
33 register unsigned long reg3
asm("3") = (unsigned long) len
;
36 "0: cksm %0,%1\n" /* do checksum on longs */
38 : "+d" (sum
), "+d" (reg2
), "+d" (reg3
) : : "cc", "memory");
43 csum_partial_copy_nocheck (const void *src
, void *dst
, int len
, __wsum sum
)
46 return csum_partial(dst
, len
, sum
);
50 * Fold a partial checksum without adding pseudo headers
52 static inline __sum16
csum_fold(__wsum sum
)
54 u32 csum
= (__force u32
) sum
;
56 csum
+= (csum
>> 16) + (csum
<< 16);
58 return (__force __sum16
) ~csum
;
62 * This is a version of ip_compute_csum() optimized for IP headers,
63 * which always checksum on 4 octet boundaries.
66 static inline __sum16
ip_fast_csum(const void *iph
, unsigned int ihl
)
68 return csum_fold(csum_partial(iph
, ihl
*4, 0));
72 * computes the checksum of the TCP/UDP pseudo-header
73 * returns a 32-bit checksum
76 csum_tcpudp_nofold(__be32 saddr
, __be32 daddr
, __u32 len
, __u8 proto
,
79 __u32 csum
= (__force __u32
)sum
;
81 csum
+= (__force __u32
)saddr
;
82 if (csum
< (__force __u32
)saddr
)
85 csum
+= (__force __u32
)daddr
;
86 if (csum
< (__force __u32
)daddr
)
90 if (csum
< len
+ proto
)
93 return (__force __wsum
)csum
;
97 * computes the checksum of the TCP/UDP pseudo-header
98 * returns a 16-bit checksum, already complemented
101 static inline __sum16
102 csum_tcpudp_magic(__be32 saddr
, __be32 daddr
, __u32 len
, __u8 proto
,
105 return csum_fold(csum_tcpudp_nofold(saddr
,daddr
,len
,proto
,sum
));
109 * this routine is used for miscellaneous IP-like checksums, mainly
113 static inline __sum16
ip_compute_csum(const void *buff
, int len
)
115 return csum_fold(csum_partial(buff
, len
, 0));
118 #endif /* _S390_CHECKSUM_H */