From: Simon Glass Date: Thu, 8 Jan 2015 20:30:47 -0700 Subject: [U-Boot] [PATCH v2 03/11] x86: Allow adding of IP checksums In-Reply-To: <1420774255-702-1-git-send-email-sjg@chromium.org> References: <1420774255-702-1-git-send-email-sjg@chromium.org> Message-ID: <1420774255-702-4-git-send-email-sjg@chromium.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Add a function to add IP checksums. Signed-off-by: Simon Glass --- Changes in v2: - Refactor IP checksum patches arch/x86/cpu/ip_checksum.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arch/x86/cpu/ip_checksum.c b/arch/x86/cpu/ip_checksum.c index 1b529da..ddfc0d7 100644 --- a/arch/x86/cpu/ip_checksum.c +++ b/arch/x86/cpu/ip_checksum.c @@ -32,3 +32,24 @@ unsigned short compute_ip_checksum(const void *vptr, unsigned long nbytes) sum += (sum >> 16); return ~sum; } + +unsigned long add_ip_checksums(unsigned long offset, unsigned long sum, + unsigned long new) +{ + unsigned long checksum; + + sum = ~sum & 0xffff; + new = ~new & 0xffff; + if (offset & 1) { + /* + * byte-swap the sum if it came from an odd offset; since the + * computation is endian independant this works. + */ + new = ((new >> 8) & 0xff) | ((new << 8) & 0xff00); + } + checksum = sum + new; + if (checksum > 0xffff) + checksum -= 0xffff; + + return (~checksum) & 0xffff; +} -- 2.2.0.rc0.207.ga3a616c