From nobody Fri May 3 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150306601615090.67976103808212; Fri, 18 Aug 2017 07:20:16 -0700 (PDT) Received: from localhost ([::1]:57082 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dii8E-0001mm-Mq for importer@patchew.org; Fri, 18 Aug 2017 10:20:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dii3p-0006Pq-AW for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:15:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dii3m-0006OM-Ju for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:15:41 -0400 Received: from chuckie.co.uk ([82.165.15.123]:57476 helo=s16892447.onlinehome-server.info) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dii3m-0006Dx-Bk for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:15:38 -0400 Received: from host86-189-213-185.range86-189.btcentralplus.com ([86.189.213.185] helo=kentang.home) by s16892447.onlinehome-server.info with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1dii3b-0000ac-FW; Fri, 18 Aug 2017 15:15:28 +0100 From: Mark Cave-Ayland To: qemu-devel@nongnu.org, jasowang@redhat.com Date: Fri, 18 Aug 2017 15:15:05 +0100 Message-Id: <1503065708-28277-2-git-send-email-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1503065708-28277-1-git-send-email-mark.cave-ayland@ilande.co.uk> References: <1503065708-28277-1-git-send-email-mark.cave-ayland@ilande.co.uk> X-SA-Exim-Connect-IP: 86.189.213.185 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk X-SA-Exim-Version: 4.2.1 (built Sun, 08 Jan 2012 02:45:44 +0000) X-SA-Exim-Scanned: Yes (on s16892447.onlinehome-server.info) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 82.165.15.123 Subject: [Qemu-devel] [PATCH 1/4] net: move CRC32 calculation from compute_mcast_idx() into its own net_crc32() function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Separate out the standard ethernet CRC32 calculation into a new net_crc32() function, renaming the constant POLYNOMIAL to POLYNOMIAL_BE to make it clear that this is a big-endian CRC32 calculation. Then remove the existing implementation from compute_mcast_idx() and call t= he new function in its place. Signed-off-by: Mark Cave-Ayland Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/net/net.h | 3 ++- net/net.c | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 1c55a93..586098c 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -227,7 +227,8 @@ NetClientState *net_hub_port_find(int hub_id); =20 void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd); =20 -#define POLYNOMIAL 0x04c11db6 +#define POLYNOMIAL_BE 0x04c11db6 +uint32_t net_crc32(const uint8_t *p, int len); unsigned compute_mcast_idx(const uint8_t *ep); =20 #define vmstate_offset_macaddr(_state, _field) \ diff --git a/net/net.c b/net/net.c index 0e28099..a856907 100644 --- a/net/net.c +++ b/net/net.c @@ -1568,25 +1568,31 @@ int net_client_parse(QemuOptsList *opts_list, const= char *optarg) =20 /* From FreeBSD */ /* XXX: optimize */ -unsigned compute_mcast_idx(const uint8_t *ep) +uint32_t net_crc32(const uint8_t *p, int len) { uint32_t crc; int carry, i, j; uint8_t b; =20 crc =3D 0xffffffff; - for (i =3D 0; i < 6; i++) { - b =3D *ep++; + for (i =3D 0; i < len; i++) { + b =3D *p++; for (j =3D 0; j < 8; j++) { carry =3D ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01); crc <<=3D 1; b >>=3D 1; if (carry) { - crc =3D ((crc ^ POLYNOMIAL) | carry); + crc =3D ((crc ^ POLYNOMIAL_BE) | carry); } } } - return crc >> 26; + + return crc; +} + +unsigned compute_mcast_idx(const uint8_t *ep) +{ + return net_crc32(ep, 6) >> 26; } =20 QemuOptsList qemu_netdev_opts =3D { --=20 1.7.10.4 From nobody Fri May 3 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503066173481700.6604650575766; Fri, 18 Aug 2017 07:22:53 -0700 (PDT) Received: from localhost ([::1]:57278 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiAm-0004iQ-Bi for importer@patchew.org; Fri, 18 Aug 2017 10:22:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54957) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dii3p-0006Pi-9R for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:15:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dii3l-0006N5-95 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:15:41 -0400 Received: from chuckie.co.uk ([82.165.15.123]:57467 helo=s16892447.onlinehome-server.info) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dii3l-00068E-1h for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:15:37 -0400 Received: from host86-189-213-185.range86-189.btcentralplus.com ([86.189.213.185] helo=kentang.home) by s16892447.onlinehome-server.info with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1dii3c-0000ac-LN; Fri, 18 Aug 2017 15:15:29 +0100 From: Mark Cave-Ayland To: qemu-devel@nongnu.org, jasowang@redhat.com Date: Fri, 18 Aug 2017 15:15:06 +0100 Message-Id: <1503065708-28277-3-git-send-email-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1503065708-28277-1-git-send-email-mark.cave-ayland@ilande.co.uk> References: <1503065708-28277-1-git-send-email-mark.cave-ayland@ilande.co.uk> X-SA-Exim-Connect-IP: 86.189.213.185 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk X-SA-Exim-Version: 4.2.1 (built Sun, 08 Jan 2012 02:45:44 +0000) X-SA-Exim-Scanned: Yes (on s16892447.onlinehome-server.info) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 82.165.15.123 Subject: [Qemu-devel] [PATCH 2/4] net: introduce net_crc32_le() function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This provides a standard ethernet CRC32 little-endian implementation. Signed-off-by: Mark Cave-Ayland Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/net/net.h | 2 ++ net/net.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 586098c..4afac1a 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -228,7 +228,9 @@ NetClientState *net_hub_port_find(int hub_id); void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd); =20 #define POLYNOMIAL_BE 0x04c11db6 +#define POLYNOMIAL_LE 0xedb88320 uint32_t net_crc32(const uint8_t *p, int len); +uint32_t net_crc32_le(const uint8_t *p, int len); unsigned compute_mcast_idx(const uint8_t *ep); =20 #define vmstate_offset_macaddr(_state, _field) \ diff --git a/net/net.c b/net/net.c index a856907..c99e705 100644 --- a/net/net.c +++ b/net/net.c @@ -1590,6 +1590,28 @@ uint32_t net_crc32(const uint8_t *p, int len) return crc; } =20 +uint32_t net_crc32_le(const uint8_t *p, int len) +{ + uint32_t crc; + int carry, i, j; + uint8_t b; + + crc =3D 0xffffffff; + for (i =3D 0; i < len; i++) { + b =3D *p++; + for (j =3D 0; j < 8; j++) { + carry =3D (crc & 0x1) ^ (b & 0x01); + crc >>=3D 1; + b >>=3D 1; + if (carry) { + crc =3D crc ^ POLYNOMIAL_LE; + } + } + } + + return crc; +} + unsigned compute_mcast_idx(const uint8_t *ep) { return net_crc32(ep, 6) >> 26; --=20 1.7.10.4 From nobody Fri May 3 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503066012895914.0224701551781; Fri, 18 Aug 2017 07:20:12 -0700 (PDT) Received: from localhost ([::1]:57081 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dii8B-0001gD-Ae for importer@patchew.org; Fri, 18 Aug 2017 10:20:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dii3p-0006Pj-9x for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:15:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dii3l-0006NX-Vp for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:15:41 -0400 Received: from chuckie.co.uk ([82.165.15.123]:57470 helo=s16892447.onlinehome-server.info) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dii3l-0006Am-DY for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:15:37 -0400 Received: from host86-189-213-185.range86-189.btcentralplus.com ([86.189.213.185] helo=kentang.home) by s16892447.onlinehome-server.info with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1dii3d-0000ac-Mq; Fri, 18 Aug 2017 15:15:30 +0100 From: Mark Cave-Ayland To: qemu-devel@nongnu.org, jasowang@redhat.com Date: Fri, 18 Aug 2017 15:15:07 +0100 Message-Id: <1503065708-28277-4-git-send-email-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1503065708-28277-1-git-send-email-mark.cave-ayland@ilande.co.uk> References: <1503065708-28277-1-git-send-email-mark.cave-ayland@ilande.co.uk> X-SA-Exim-Connect-IP: 86.189.213.185 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk X-SA-Exim-Version: 4.2.1 (built Sun, 08 Jan 2012 02:45:44 +0000) X-SA-Exim-Scanned: Yes (on s16892447.onlinehome-server.info) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 82.165.15.123 Subject: [Qemu-devel] [PATCH 3/4] pcnet: switch lnc_mchash() over to use net_crc32_le() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Mark Cave-Ayland Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/net/pcnet.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c index 6544553..c050993 100644 --- a/hw/net/pcnet.c +++ b/hw/net/pcnet.c @@ -522,23 +522,9 @@ static inline void pcnet_rmd_store(PCNetState *s, stru= ct pcnet_RMD *rmd, be16_to_cpu(hdr->ether_type)); \ } while (0) =20 -#define MULTICAST_FILTER_LEN 8 - static inline uint32_t lnc_mchash(const uint8_t *ether_addr) { -#define LNC_POLYNOMIAL 0xEDB88320UL - uint32_t crc =3D 0xFFFFFFFF; - int idx, bit; - uint8_t data; - - for (idx =3D 0; idx < 6; idx++) { - for (data =3D *ether_addr++, bit =3D 0; bit < MULTICAST_FILTER_LEN= ; bit++) { - crc =3D (crc >> 1) ^ (((crc ^ data) & 1) ? LNC_POLYNOMIAL : 0); - data >>=3D 1; - } - } - return crc; -#undef LNC_POLYNOMIAL + return net_crc32_le(ether_addr, 6); } =20 #define CRC(crc, ch) (crc =3D (crc >> 8) ^ crctab[(crc ^ (ch)) & 0xff]) --=20 1.7.10.4 From nobody Fri May 3 17:52:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503066315509741.9836500229488; Fri, 18 Aug 2017 07:25:15 -0700 (PDT) Received: from localhost ([::1]:57421 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiD4-0006ZF-5s for importer@patchew.org; Fri, 18 Aug 2017 10:25:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54959) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dii3p-0006Pk-9z for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:15:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dii3m-0006OF-It for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:15:41 -0400 Received: from chuckie.co.uk ([82.165.15.123]:57474 helo=s16892447.onlinehome-server.info) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dii3m-0006DO-6Q for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:15:38 -0400 Received: from host86-189-213-185.range86-189.btcentralplus.com ([86.189.213.185] helo=kentang.home) by s16892447.onlinehome-server.info with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1dii3e-0000ac-OJ; Fri, 18 Aug 2017 15:15:31 +0100 From: Mark Cave-Ayland To: qemu-devel@nongnu.org, jasowang@redhat.com Date: Fri, 18 Aug 2017 15:15:08 +0100 Message-Id: <1503065708-28277-5-git-send-email-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1503065708-28277-1-git-send-email-mark.cave-ayland@ilande.co.uk> References: <1503065708-28277-1-git-send-email-mark.cave-ayland@ilande.co.uk> X-SA-Exim-Connect-IP: 86.189.213.185 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk X-SA-Exim-Version: 4.2.1 (built Sun, 08 Jan 2012 02:45:44 +0000) X-SA-Exim-Scanned: Yes (on s16892447.onlinehome-server.info) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 82.165.15.123 Subject: [Qemu-devel] [PATCH 4/4] eepro100: switch e100_compute_mcast_idx() over to use net_crc32() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Mark Cave-Ayland Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/net/eepro100.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c index 5a4774a..4226572 100644 --- a/hw/net/eepro100.c +++ b/hw/net/eepro100.c @@ -327,26 +327,9 @@ static const uint16_t eepro100_mdi_mask[] =3D { =20 static E100PCIDeviceInfo *eepro100_get_class(EEPRO100State *s); =20 -/* From FreeBSD (locally modified). */ static unsigned e100_compute_mcast_idx(const uint8_t *ep) { - uint32_t crc; - int carry, i, j; - uint8_t b; - - crc =3D 0xffffffff; - for (i =3D 0; i < 6; i++) { - b =3D *ep++; - for (j =3D 0; j < 8; j++) { - carry =3D ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01); - crc <<=3D 1; - b >>=3D 1; - if (carry) { - crc =3D ((crc ^ POLYNOMIAL) | carry); - } - } - } - return (crc & BITS(7, 2)) >> 2; + return (net_crc32(ep, 6) & BITS(7, 2)) >> 2; } =20 /* Read a 16 bit control/status (CSR) register. */ --=20 1.7.10.4