Add a function to add IP checksums. Signed-off-by: Simon Glass <s...@chromium.org> ---
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 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot