@@ -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;
+}
Add a function to add IP checksums. Signed-off-by: Simon Glass <sjg@chromium.org> --- Changes in v2: - Refactor IP checksum patches arch/x86/cpu/ip_checksum.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)