16fc729afSOlivier Houchard /*-
251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni *
46fc729afSOlivier Houchard * Copyright (c) 1990 The Regents of the University of California.
56fc729afSOlivier Houchard * All rights reserved.
66fc729afSOlivier Houchard *
76fc729afSOlivier Houchard * Redistribution and use in source and binary forms, with or without
86fc729afSOlivier Houchard * modification, are permitted provided that the following conditions
96fc729afSOlivier Houchard * are met:
106fc729afSOlivier Houchard * 1. Redistributions of source code must retain the above copyright
116fc729afSOlivier Houchard * notice, this list of conditions and the following disclaimer.
126fc729afSOlivier Houchard * 2. Redistributions in binary form must reproduce the above copyright
136fc729afSOlivier Houchard * notice, this list of conditions and the following disclaimer in the
146fc729afSOlivier Houchard * documentation and/or other materials provided with the distribution.
15371f621aSEd Maste * 3. Neither the name of the University nor the names of its contributors
166fc729afSOlivier Houchard * may be used to endorse or promote products derived from this software
176fc729afSOlivier Houchard * without specific prior written permission.
186fc729afSOlivier Houchard *
196fc729afSOlivier Houchard * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
206fc729afSOlivier Houchard * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
216fc729afSOlivier Houchard * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
226fc729afSOlivier Houchard * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
236fc729afSOlivier Houchard * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
246fc729afSOlivier Houchard * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
256fc729afSOlivier Houchard * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
266fc729afSOlivier Houchard * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
276fc729afSOlivier Houchard * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
286fc729afSOlivier Houchard * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
296fc729afSOlivier Houchard * SUCH DAMAGE.
306fc729afSOlivier Houchard *
316fc729afSOlivier Houchard * from tahoe: in_cksum.c 1.2 86/01/05
326fc729afSOlivier Houchard * from: Id: in_cksum.c,v 1.8 1995/12/03 18:35:19 bde Exp
336fc729afSOlivier Houchard */
346fc729afSOlivier Houchard
356fc729afSOlivier Houchard #ifndef _MACHINE_IN_CKSUM_H_
366fc729afSOlivier Houchard #define _MACHINE_IN_CKSUM_H_ 1
376fc729afSOlivier Houchard
386fc729afSOlivier Houchard #ifdef _KERNEL
39*ecbbe831SMark Johnston
40*ecbbe831SMark Johnston #define HAVE_MD_IN_CKSUM
41*ecbbe831SMark Johnston
426fc729afSOlivier Houchard u_short in_cksum(struct mbuf *m, int len);
436fc729afSOlivier Houchard u_short in_addword(u_short sum, u_short b);
446fc729afSOlivier Houchard u_short in_cksum_skip(struct mbuf *m, int len, int skip);
450f18d325SOlivier Houchard u_int do_cksum(const void *, int);
46920b9658SBjoern A. Zeeb #if defined(IPVERSION) && (IPVERSION == 4)
47c0e239deSOlivier Houchard u_int in_cksum_hdr(const struct ip *);
48920b9658SBjoern A. Zeeb #endif
4993d18f47SOlivier Houchard
5093d18f47SOlivier Houchard static __inline u_short
in_pseudo(u_int sum,u_int b,u_int c)5193d18f47SOlivier Houchard in_pseudo(u_int sum, u_int b, u_int c)
5293d18f47SOlivier Houchard {
5393d18f47SOlivier Houchard __asm __volatile("adds %0, %0, %1\n"
5493d18f47SOlivier Houchard "adcs %0, %0, %2\n"
5593d18f47SOlivier Houchard "adc %0, %0, #0\n"
5693d18f47SOlivier Houchard : "+r" (sum)
5793d18f47SOlivier Houchard : "r" (b), "r" (c));
5893d18f47SOlivier Houchard sum = (sum & 0xffff) + (sum >> 16);
5993d18f47SOlivier Houchard if (sum > 0xffff)
6093d18f47SOlivier Houchard sum -= 0xffff;
6193d18f47SOlivier Houchard return (sum);
6293d18f47SOlivier Houchard }
6393d18f47SOlivier Houchard
646fc729afSOlivier Houchard #endif /* _KERNEL */
656fc729afSOlivier Houchard #endif /* _MACHINE_IN_CKSUM_H_ */
66