]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sparc64/include/in_cksum.h
MFC r316910: 7812 Remove gender specific language
[FreeBSD/FreeBSD.git] / sys / sparc64 / include / in_cksum.h
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1990 The Regents of the University of California.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 /*-
32  * Copyright (c) 2001 by Thomas Moestl <tmm@FreeBSD.org>.
33  * All rights reserved.
34  *
35  * Redistribution and use in source and binary forms, with or without
36  * modification, are permitted provided that the following conditions
37  * are met:
38  * 1. Redistributions of source code must retain the above copyright
39  *    notice, this list of conditions and the following disclaimer.
40  * 2. Redistributions in binary form must reproduce the above copyright
41  *    notice, this list of conditions and the following disclaimer in the
42  *    documentation and/or other materials provided with the distribution.
43  *
44  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
45  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
46  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
47  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
48  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
49  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
50  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
51  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
52  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
53  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54  *
55  *      from tahoe:     in_cksum.c      1.2     86/01/05
56  *      from:           @(#)in_cksum.c  1.3 (Berkeley) 1/19/91
57  *      from: Id: in_cksum.c,v 1.8 1995/12/03 18:35:19 bde Exp
58  *      from: FreeBSD: src/sys/alpha/include/in_cksum.h,v 1.5 2000/05/06
59  *
60  * $FreeBSD$
61  */
62
63 #ifndef _MACHINE_IN_CKSUM_H_
64 #define _MACHINE_IN_CKSUM_H_    1
65
66 #include <sys/cdefs.h>
67
68 #define in_cksum(m, len)        in_cksum_skip(m, len, 0)
69
70 #if defined(IPVERSION) && (IPVERSION == 4)
71 static __inline void
72 in_cksum_update(struct ip *ip)
73 {
74         int __tmp;
75
76         __tmp = (int)ip->ip_sum + 1;
77         ip->ip_sum = __tmp + (__tmp >> 16);
78 }
79 #endif
80
81 static __inline u_short
82 in_addword(u_short sum, u_short b)
83 {
84         u_long __ret, __tmp;
85
86         __asm(
87             "sll %2, 16, %0\n"
88             "sll %3, 16, %1\n"
89             "addcc %0, %1, %0\n"
90             "srl %0, 16, %0\n"
91             "addc %0, 0, %0\n"
92             : "=&r" (__ret), "=&r" (__tmp) : "r" (sum), "r" (b) : "cc");
93         return (__ret);
94 }
95
96 static __inline u_short
97 in_pseudo(u_int sum, u_int b, u_int c)
98 {
99         u_long __tmp;
100
101         __asm(
102             "addcc %0, %3, %0\n"
103             "addccc %0, %4, %0\n"
104             "addc %0, 0, %0\n"
105             "sll %0, 16, %1\n"
106             "addcc %0, %1, %0\n"
107             "srl %0, 16, %0\n"
108             "addc %0, 0, %0\n"
109             : "=r" (sum), "=&r" (__tmp) : "0" (sum), "r" (b), "r" (c) : "cc");
110         return (sum);
111 }
112
113 #if defined(IPVERSION) && (IPVERSION == 4)
114 static __inline u_int
115 in_cksum_hdr(struct ip *ip)
116 {
117         u_long __ret, __tmp1, __tmp2, __tmp3, __tmp4;
118
119         /*
120          * Use 32-bit memory accesses and additions - addition with carry only
121          * works for 32 bits, and fixing up alignment issues for 64 is probably
122          * more trouble than it's worth.
123          * This may read outside of the ip header, but does not cross a page
124          * boundary in doing so, so that should be OK.
125          * Actually, this specialized implementation might be overkill - using
126          * a generic implementation for both in_cksum_skip and in_cksum_hdr
127          * should not be too much more expensive.
128          */
129 #define __LD_ADD(addr, tmp, sum, offs, mod)                             \
130     "lduw [" #addr " + " #offs "], " #tmp "\n"                          \
131     "add" # mod " " #sum ", " #tmp ", " #sum "\n"
132
133         __asm(
134             "and %5, 3, %3\n"
135             "andn %5, 3, %1\n"
136             "brz,pt %3, 0f\n"
137             " lduw [%1], %0\n"
138             "mov 4, %4\n"
139             "sub %4, %3, %4\n"
140             "sll %4, 3, %4\n"           /* fix up unaligned buffers */
141             "mov 1, %2\n"
142             "sll %2, %4, %4\n"
143             "sub %4, 1, %4\n"
144             "lduw [%1 + 20], %2\n"
145             "andn %2, %4, %2\n"
146             "and %0, %4, %0\n"
147             "or %0, %2, %0\n"
148             "0:\n"
149             __LD_ADD(%1, %2, %0, 4, cc)
150             __LD_ADD(%1, %2, %0, 8, ccc)
151             __LD_ADD(%1, %2, %0, 12, ccc)
152             __LD_ADD(%1, %2, %0, 16, ccc)
153             "addc %0, 0, %0\n"          /* reduce */
154             "1:\n"
155             "sll %0, 16, %2\n"
156             "addcc %0, %2, %0\n"
157             "srl %0, 16, %0\n"
158             "addc %0, 0, %0\n"
159             "andcc %3, 1, %3\n"         /* need to byte-swap? */
160             "clr %3\n"
161             "bne,a,pn %%xcc, 1b\n"
162             " sll %0, 8, %0\n"
163             "not %0\n"
164             "sll %0, 16, %0\n"
165             "srl %0, 16, %0\n"
166             : "=&r" (__ret), "=r" (__tmp1), "=&r" (__tmp2), "=&r" (__tmp3),
167             "=&r" (__tmp4) : "1" (ip) : "cc");
168 #undef __LD_ADD
169         return (__ret);
170 }
171 #endif
172
173 #ifdef _KERNEL
174 u_short in_cksum_skip(struct mbuf *m, int len, int skip);
175 #endif
176
177 #endif /* _MACHINE_IN_CKSUM_H_ */