From de37109767b6b415778f34cbac196c8418f7e371 Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Tue, 30 Jan 2024 16:51:05 -0800 Subject: lib: Move IP checksum to commonlib This patch moves the IP checksum algorithm into commonlib to prepare for it being shared with libpayload. The current implementation is ancient and pretty hard to read (and does some unnecessary questionable things like the type-punning stuff which leads to suboptimal code generation), so this reimplements it from scratch (that also helps with the licensing). This algorithm is prepared to take in a pre-calculated "wide" checksum in a machine-register-sized data type which is then narrowed down to 16 bits (see RFC 1071 for why that's valid). This isn't used yet (and the code will get optimized out), but will be used later in this patch series for architecture-specific optimization. Change-Id: Ic04c714c00439a17fc04a8a6e730cc2aa19b8e68 Signed-off-by: Julius Werner Reviewed-on: https://review.coreboot.org/c/coreboot/+/80251 Reviewed-by: Yidi Lin Tested-by: build bot (Jenkins) Reviewed-by: Jakub Czapiga --- src/drivers/net/ne2k.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/drivers/net') diff --git a/src/drivers/net/ne2k.c b/src/drivers/net/ne2k.c index 4479a76742..70ef0efc39 100644 --- a/src/drivers/net/ne2k.c +++ b/src/drivers/net/ne2k.c @@ -28,11 +28,11 @@ SMC8416 PIO support added by Andrew Bettison (andrewb@zip.com.au) on 4/3/02 */ #include +#include #include #include #include #include -#include #include "ns8390.h" @@ -184,7 +184,7 @@ static void ns8390_tx_header(unsigned int eth_nic_base, int pktlen) hdr[38] = (8 + pktlen) >> 8; hdr[39] = 8 + pktlen; - chksum = compute_ip_checksum(&hdr[14], 20); + chksum = ipchksum(&hdr[14], 20); hdr[25] = chksum >> 8; hdr[24] = chksum; -- cgit v1.2.3