[U-Boot] [PATCH v2 03/11] x86: Allow adding of IP checksums
Simon Glass
sjg at chromium.org
Fri Jan 9 04:30:47 CET 2015
Add a function to add IP checksums.
Signed-off-by: Simon Glass <sjg at 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
More information about the U-Boot
mailing list