1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Optmized version of the ip_fast_csum() function
4 * Used for calculating IP header checksum
6 * Return: 16bit checksum, complemented
9 * in0: address of buffer to checksum (char *)
10 * in1: length of the buffer (int)
12 * Copyright (C) 2002, 2006 Intel Corp.
13 * Copyright (C) 2002, 2006 Ken Chen <kenneth.w.chen@intel.com>
16 #include <asm/asmmacro.h>
17 #include <asm/export.h>
20 * Since we know that most likely this function is called with buf aligned
21 * on 4-byte boundary and 20 bytes in length, we can execution rather quickly
22 * versus calling generic version of do_csum, which has lots of overhead in
23 * handling various alignments and sizes. However, due to lack of constrains
24 * put on the function input argument, cases with alignment not on 4-byte or
25 * size not equal to 20 bytes will be handled by the generic do_csum function.
35 GLOBAL_ENTRY(ip_fast_csum)
38 cmp.ne p6,p7=5,in1 // size other than 20 byte?
39 and r14=3,in0 // is it aligned on 4-byte?
40 add r15=4,in0 // second source pointer
42 cmp.ne.or.andcm p6,p7=r14,r0
59 shr.u ret0=r20,16 // now need to add the carry
64 shr.u ret0=r20,16 // add carry again
76 .restore sp // reset frame state
83 alloc r35=ar.pfs,2,2,2,0
90 br.call.sptk.many b0=do_csum
97 EXPORT_SYMBOL(ip_fast_csum)
99 GLOBAL_ENTRY(csum_ipv6_magic)
106 dep r15=in3,in2,32,16
129 shr.u r10=r8,32 // now fold sum into short
134 shr.u r10=r8,16 // yeah, keep it rolling
139 shr.u r10=r8,16 // three times lucky
148 EXPORT_SYMBOL(csum_ipv6_magic)