From nobody Sun Nov 2 03:14:20 2025 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 1527575671566715.292290475937; Mon, 28 May 2018 23:34:31 -0700 (PDT) Received: from localhost ([::1]:59226 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNYDG-0004p0-RX for importer@patchew.org; Tue, 29 May 2018 02:34:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNY81-0001KG-9a for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNY7z-0001WE-FC for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:05 -0400 Received: from 7.mo177.mail-out.ovh.net ([46.105.61.149]:34645) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fNY7z-0001N5-8E for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:03 -0400 Received: from player718.ha.ovh.net (unknown [10.109.120.93]) by mo177.mail-out.ovh.net (Postfix) with ESMTP id 0BCECB2528 for ; Tue, 29 May 2018 08:28:52 +0200 (CEST) Received: from zorba.kaod.org.com (LFbn-TOU-1-49-10.w86-201.abo.wanadoo.fr [86.201.141.10]) (Authenticated sender: clg@kaod.org) by player718.ha.ovh.net (Postfix) with ESMTPSA id 479C54E008A; Tue, 29 May 2018 08:28:47 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-arm@nongnu.org Date: Tue, 29 May 2018 08:28:33 +0200 Message-Id: <20180529062838.20556-2-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180529062838.20556-1-clg@kaod.org> References: <20180529062838.20556-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 17520128450964327344 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrheejgddutdelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.61.149 Subject: [Qemu-devel] [PATCH 1/6] ftgmac100: compute maximum frame size depending on the protocol 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: , Cc: Samuel Thibault , Jason Wang , qemu-devel@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The maximum frame size includes the CRC and depends if a VLAN tag is inserted or not. Adjust the frame size limit in the transmit handler using on the FTGMAC100State buffer size and in the receive handler use the packet protocol. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Joel Stanley --- include/hw/net/ftgmac100.h | 7 ++++++- hw/net/ftgmac100.c | 23 ++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/hw/net/ftgmac100.h b/include/hw/net/ftgmac100.h index d9bc589fbf72..94cfe0533297 100644 --- a/include/hw/net/ftgmac100.h +++ b/include/hw/net/ftgmac100.h @@ -16,6 +16,11 @@ #include "hw/sysbus.h" #include "net/net.h" =20 +/* + * Max frame size for the receiving buffer + */ +#define FTGMAC100_MAX_FRAME_SIZE 9220 + typedef struct FTGMAC100State { /*< private >*/ SysBusDevice parent_obj; @@ -26,7 +31,7 @@ typedef struct FTGMAC100State { qemu_irq irq; MemoryRegion iomem; =20 - uint8_t *frame; + uint8_t frame[FTGMAC100_MAX_FRAME_SIZE]; =20 uint32_t irq_state; uint32_t isr; diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c index a6d27a7b01df..7598d08c9cb9 100644 --- a/hw/net/ftgmac100.c +++ b/hw/net/ftgmac100.c @@ -207,16 +207,18 @@ typedef struct { /* * Max frame size for the receiving buffer */ -#define FTGMAC100_MAX_FRAME_SIZE 10240 +#define FTGMAC100_MAX_FRAME_SIZE 9220 =20 /* Limits depending on the type of the frame * * 9216 for Jumbo frames (+ 4 for VLAN) * 1518 for other frames (+ 4 for VLAN) */ -static int ftgmac100_max_frame_size(FTGMAC100State *s) +static int ftgmac100_max_frame_size(FTGMAC100State *s, uint16_t proto) { - return (s->maccr & FTGMAC100_MACCR_JUMBO_LF ? 9216 : 1518) + 4; + int max =3D (s->maccr & FTGMAC100_MACCR_JUMBO_LF ? 9216 : 1518); + + return max + (proto =3D=3D ETH_P_VLAN ? 4 : 0); } =20 static void ftgmac100_update_irq(FTGMAC100State *s) @@ -408,7 +410,6 @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t= tx_ring, uint8_t *ptr =3D s->frame; uint32_t addr =3D tx_descriptor; uint32_t flags =3D 0; - int max_frame_size =3D ftgmac100_max_frame_size(s); =20 while (1) { FTGMAC100Desc bd; @@ -427,11 +428,12 @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint32= _t tx_ring, flags =3D bd.des1; } =20 - len =3D bd.des0 & 0x3FFF; - if (frame_size + len > max_frame_size) { + len =3D FTGMAC100_TXDES0_TXBUF_SIZE(bd.des0); + if (frame_size + len > sizeof(s->frame)) { qemu_log_mask(LOG_GUEST_ERROR, "%s: frame too big : %d bytes\n= ", __func__, len); - len =3D max_frame_size - frame_size; + s->isr |=3D FTGMAC100_INT_XPKT_LOST; + len =3D sizeof(s->frame) - frame_size; } =20 if (dma_memory_read(&address_space_memory, bd.des3, ptr, len)) { @@ -788,7 +790,8 @@ static ssize_t ftgmac100_receive(NetClientState *nc, co= nst uint8_t *buf, uint32_t buf_len; size_t size =3D len; uint32_t first =3D FTGMAC100_RXDES0_FRS; - int max_frame_size =3D ftgmac100_max_frame_size(s); + uint16_t proto =3D be16_to_cpu(PKT_GET_ETH_HDR(buf)->h_proto); + int max_frame_size =3D ftgmac100_max_frame_size(s, proto); =20 if ((s->maccr & (FTGMAC100_MACCR_RXDMA_EN | FTGMAC100_MACCR_RXMAC_EN)) !=3D (FTGMAC100_MACCR_RXDMA_EN | FTGMAC100_MACCR_RXMAC_EN)) { @@ -814,9 +817,9 @@ static ssize_t ftgmac100_receive(NetClientState *nc, co= nst uint8_t *buf, =20 /* Huge frames are truncated. */ if (size > max_frame_size) { - size =3D max_frame_size; qemu_log_mask(LOG_GUEST_ERROR, "%s: frame too big : %zd bytes\n", __func__, size); + size =3D max_frame_size; flags |=3D FTGMAC100_RXDES0_FTL; } =20 @@ -934,8 +937,6 @@ static void ftgmac100_realize(DeviceState *dev, Error *= *errp) object_get_typename(OBJECT(dev)), DEVICE(dev)->i= d, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); - - s->frame =3D g_malloc(FTGMAC100_MAX_FRAME_SIZE); } =20 static const VMStateDescription vmstate_ftgmac100 =3D { --=20 2.13.6 From nobody Sun Nov 2 03:14:20 2025 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527575502880794.5350373070105; Mon, 28 May 2018 23:31:42 -0700 (PDT) Received: from localhost ([::1]:59208 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNYAS-0002lv-Oh for importer@patchew.org; Tue, 29 May 2018 02:31:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNY7z-0001Im-D9 for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNY7w-0001Ty-AP for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:03 -0400 Received: from 5.mo7.mail-out.ovh.net ([178.32.120.239]:49813) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fNY7w-0001SD-3S for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:00 -0400 Received: from player718.ha.ovh.net (unknown [10.109.108.4]) by mo7.mail-out.ovh.net (Postfix) with ESMTP id 2262BACACD for ; Tue, 29 May 2018 08:28:57 +0200 (CEST) Received: from zorba.kaod.org.com (LFbn-TOU-1-49-10.w86-201.abo.wanadoo.fr [86.201.141.10]) (Authenticated sender: clg@kaod.org) by player718.ha.ovh.net (Postfix) with ESMTPSA id 7B9FD4E00AE; Tue, 29 May 2018 08:28:52 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-arm@nongnu.org Date: Tue, 29 May 2018 08:28:34 +0200 Message-Id: <20180529062838.20556-3-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180529062838.20556-1-clg@kaod.org> References: <20180529062838.20556-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 17521535827166137264 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrheejgddutdelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.32.120.239 Subject: [Qemu-devel] [PATCH 2/6] ftgmac100: add IEEE 802.1Q VLAN support 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: , Cc: Samuel Thibault , Jason Wang , qemu-devel@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The ftgmac100 NIC supports VLAN tag insertion and the MAC engine also has a control to remove VLAN tags from received packets. The VLAN control bits and VLAN tag information are contained in the second word of the transmit and receive descriptors. The Insert VLAN bit and the VLAN Tag available bit are only valid in the first segment of the packet. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Joel Stanley --- hw/net/ftgmac100.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c index 7598d08c9cb9..50af1222464a 100644 --- a/hw/net/ftgmac100.c +++ b/hw/net/ftgmac100.c @@ -443,6 +443,24 @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint32_= t tx_ring, break; } =20 + /* Check for VLAN */ + if (bd.des0 & FTGMAC100_TXDES0_FTS && + bd.des1 & FTGMAC100_TXDES1_INS_VLANTAG && + be16_to_cpu(PKT_GET_ETH_HDR(ptr)->h_proto) !=3D ETH_P_VLAN) { + if (frame_size + len + 4 > sizeof(s->frame)) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: frame too big : %d byt= es\n", + __func__, len); + s->isr |=3D FTGMAC100_INT_XPKT_LOST; + len =3D sizeof(s->frame) - frame_size - 4; + } + memmove(ptr + 16, ptr + 12, len - 12); + ptr[12] =3D 0x81; + ptr[13] =3D 0x00; + ptr[14] =3D (uint8_t) bd.des1 >> 8; + ptr[15] =3D (uint8_t) bd.des1; + len +=3D 4; + } + ptr +=3D len; frame_size +=3D len; if (bd.des0 & FTGMAC100_TXDES0_LTS) { @@ -858,7 +876,19 @@ static ssize_t ftgmac100_receive(NetClientState *nc, c= onst uint8_t *buf, buf_len +=3D size - 4; } buf_addr =3D bd.des3; - dma_memory_write(&address_space_memory, buf_addr, buf, buf_len); + if (first && proto =3D=3D ETH_P_VLAN && buf_len >=3D 18) { + bd.des1 =3D (buf[14] << 8) | buf[15] | FTGMAC100_RXDES1_VLANTA= G_AVAIL; + if (s->maccr & FTGMAC100_MACCR_RM_VLAN) { + dma_memory_write(&address_space_memory, buf_addr, buf, 12); + dma_memory_write(&address_space_memory, buf_addr + 12, buf= + 16, + buf_len - 16); + } else { + dma_memory_write(&address_space_memory, buf_addr, buf, buf= _len); + } + } else { + bd.des1 =3D 0; + dma_memory_write(&address_space_memory, buf_addr, buf, buf_len= ); + } buf +=3D buf_len; if (size < 4) { dma_memory_write(&address_space_memory, buf_addr + buf_len, --=20 2.13.6 From nobody Sun Nov 2 03:14:20 2025 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 1527575502828363.3454700126879; Mon, 28 May 2018 23:31:42 -0700 (PDT) Received: from localhost ([::1]:59206 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNYAQ-0002kA-Ci for importer@patchew.org; Tue, 29 May 2018 02:31:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36577) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNY83-0001Mh-TA for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNY80-0001Wv-Kc for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:07 -0400 Received: from 7.mo2.mail-out.ovh.net ([188.165.48.182]:38675) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fNY80-0001WB-EM for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:04 -0400 Received: from player718.ha.ovh.net (unknown [10.109.108.63]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id 08BE7139F68 for ; Tue, 29 May 2018 08:29:02 +0200 (CEST) Received: from zorba.kaod.org.com (LFbn-TOU-1-49-10.w86-201.abo.wanadoo.fr [86.201.141.10]) (Authenticated sender: clg@kaod.org) by player718.ha.ovh.net (Postfix) with ESMTPSA id AF1B84E0087; Tue, 29 May 2018 08:28:57 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-arm@nongnu.org Date: Tue, 29 May 2018 08:28:35 +0200 Message-Id: <20180529062838.20556-4-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180529062838.20556-1-clg@kaod.org> References: <20180529062838.20556-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 17522943200272550832 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrheejgddutdelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 188.165.48.182 Subject: [Qemu-devel] [PATCH 3/6] net/ftgmac100: fix multicast hash routine 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: , Cc: Samuel Thibault , Jason Wang , qemu-devel@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Based on the multicast hash calculation of the FTGMAC100 Linux driver. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Joel Stanley --- hw/net/ftgmac100.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c index 50af1222464a..fd7699b1c05e 100644 --- a/hw/net/ftgmac100.c +++ b/hw/net/ftgmac100.c @@ -778,8 +778,8 @@ static int ftgmac100_filter(FTGMAC100State *s, const ui= nt8_t *buf, size_t len) return 0; } =20 - /* TODO: this does not seem to work for ftgmac100 */ - mcast_idx =3D net_crc32(buf, ETH_ALEN) >> 26; + mcast_idx =3D net_crc32_le(buf, ETH_ALEN); + mcast_idx =3D (~(mcast_idx >> 2)) & 0x3f; if (!(s->math[mcast_idx / 32] & (1 << (mcast_idx % 32)))) { return 0; } --=20 2.13.6 From nobody Sun Nov 2 03:14:20 2025 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 1527575504857628.449432476922; Mon, 28 May 2018 23:31:44 -0700 (PDT) Received: from localhost ([::1]:59209 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNYAX-0002qm-UT for importer@patchew.org; Tue, 29 May 2018 02:31:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36635) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNY89-0001SK-M2 for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNY86-0001c9-I2 for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:13 -0400 Received: from 4.mo5.mail-out.ovh.net ([178.33.111.247]:60617) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fNY86-0001bJ-Bw for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:10 -0400 Received: from player718.ha.ovh.net (unknown [10.109.120.118]) by mo5.mail-out.ovh.net (Postfix) with ESMTP id 2DC1C1B7377 for ; Tue, 29 May 2018 08:29:08 +0200 (CEST) Received: from zorba.kaod.org.com (LFbn-TOU-1-49-10.w86-201.abo.wanadoo.fr [86.201.141.10]) (Authenticated sender: clg@kaod.org) by player718.ha.ovh.net (Postfix) with ESMTPSA id E35094E0087; Tue, 29 May 2018 08:29:02 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-arm@nongnu.org Date: Tue, 29 May 2018 08:28:36 +0200 Message-Id: <20180529062838.20556-5-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180529062838.20556-1-clg@kaod.org> References: <20180529062838.20556-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 17524632052135857072 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrheejgddutdelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.33.111.247 Subject: [Qemu-devel] [PATCH 4/6] slirp/ncsi: fix "Get Version ID" payload length 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: , Cc: Samuel Thibault , Jason Wang , qemu-devel@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Joel Stanley --- slirp/ncsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slirp/ncsi.c b/slirp/ncsi.c index d12ba3e494b0..02d0e9def3e8 100644 --- a/slirp/ncsi.c +++ b/slirp/ncsi.c @@ -60,7 +60,7 @@ static const struct ncsi_rsp_handler { { NCSI_PKT_RSP_EGMF, 4, NULL }, { NCSI_PKT_RSP_DGMF, 4, NULL }, { NCSI_PKT_RSP_SNFC, 4, NULL }, - { NCSI_PKT_RSP_GVI, 36, NULL }, + { NCSI_PKT_RSP_GVI, 40, NULL }, { NCSI_PKT_RSP_GC, 32, ncsi_rsp_handler_gc }, { NCSI_PKT_RSP_GP, -1, NULL }, { NCSI_PKT_RSP_GCPS, 172, NULL }, --=20 2.13.6 From nobody Sun Nov 2 03:14:20 2025 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 152757569966368.63933090172816; Mon, 28 May 2018 23:34:59 -0700 (PDT) Received: from localhost ([::1]:59228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNYDi-00054V-Ua for importer@patchew.org; Tue, 29 May 2018 02:34:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNY8E-0001U9-AM for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNY8B-0001fA-7Y for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:18 -0400 Received: from 6.mo179.mail-out.ovh.net ([46.105.56.76]:40000) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fNY8B-0001eM-1O for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:15 -0400 Received: from player718.ha.ovh.net (unknown [10.109.108.14]) by mo179.mail-out.ovh.net (Postfix) with ESMTP id 6C2DFC8A6D for ; Tue, 29 May 2018 08:29:13 +0200 (CEST) Received: from zorba.kaod.org.com (LFbn-TOU-1-49-10.w86-201.abo.wanadoo.fr [86.201.141.10]) (Authenticated sender: clg@kaod.org) by player718.ha.ovh.net (Postfix) with ESMTPSA id 2AD5D4E008A; Tue, 29 May 2018 08:29:08 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-arm@nongnu.org Date: Tue, 29 May 2018 08:28:37 +0200 Message-Id: <20180529062838.20556-6-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180529062838.20556-1-clg@kaod.org> References: <20180529062838.20556-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 17526039427134753712 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrheejgddutdelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.56.76 Subject: [Qemu-devel] [PATCH 5/6] slirp/ncsi: add a "Get Parameter" response 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: , Cc: Samuel Thibault , Jason Wang , qemu-devel@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is a minimum response to exercise the kernel. Signed-off-by: C=C3=A9dric Le Goater Tested-by: Joel Stanley --- slirp/ncsi.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/slirp/ncsi.c b/slirp/ncsi.c index 02d0e9def3e8..f00253641ea4 100644 --- a/slirp/ncsi.c +++ b/slirp/ncsi.c @@ -35,6 +35,27 @@ static int ncsi_rsp_handler_gls(struct ncsi_rsp_pkt_hdr = *rnh) return 0; } =20 +/* Get Parameter */ +static int ncsi_rsp_handler_gp(struct ncsi_rsp_pkt_hdr *rnh) +{ + struct ncsi_rsp_gp_pkt *rsp =3D (struct ncsi_rsp_gp_pkt *) rnh; + + rsp->mac_cnt =3D 0x0; + rsp->mac_enable =3D 0x0; + + /* TODO: provide the guest configured MAC */ + rsp->mac[0] =3D 0xaa; + rsp->mac[1] =3D 0xbb; + rsp->mac[2] =3D 0xcc; + rsp->mac[3] =3D 0xdd; + rsp->mac[4] =3D 0xee; + rsp->mac[5] =3D 0xff; + + /* more data follows */ + + return 0; +} + static const struct ncsi_rsp_handler { unsigned char type; int payload; @@ -62,7 +83,7 @@ static const struct ncsi_rsp_handler { { NCSI_PKT_RSP_SNFC, 4, NULL }, { NCSI_PKT_RSP_GVI, 40, NULL }, { NCSI_PKT_RSP_GC, 32, ncsi_rsp_handler_gc }, - { NCSI_PKT_RSP_GP, -1, NULL }, + { NCSI_PKT_RSP_GP, 40, ncsi_rsp_handler_gp }, { NCSI_PKT_RSP_GCPS, 172, NULL }, { NCSI_PKT_RSP_GNS, 172, NULL }, { NCSI_PKT_RSP_GNPTS, 172, NULL }, --=20 2.13.6 From nobody Sun Nov 2 03:14:20 2025 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 152757569308382.55515736462644; Mon, 28 May 2018 23:34:53 -0700 (PDT) Received: from localhost ([::1]:59227 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNYDc-0004zM-7g for importer@patchew.org; Tue, 29 May 2018 02:34:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fNY8K-0001cF-57 for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fNY8H-0001it-1A for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:24 -0400 Received: from 17.mo6.mail-out.ovh.net ([46.105.36.150]:59573) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fNY8G-0001hw-RM for qemu-devel@nongnu.org; Tue, 29 May 2018 02:29:20 -0400 Received: from player718.ha.ovh.net (unknown [10.109.120.102]) by mo6.mail-out.ovh.net (Postfix) with ESMTP id EFC8215ED2C for ; Tue, 29 May 2018 08:29:18 +0200 (CEST) Received: from zorba.kaod.org.com (LFbn-TOU-1-49-10.w86-201.abo.wanadoo.fr [86.201.141.10]) (Authenticated sender: clg@kaod.org) by player718.ha.ovh.net (Postfix) with ESMTPSA id 5EC8F4E00A8; Tue, 29 May 2018 08:29:13 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-arm@nongnu.org Date: Tue, 29 May 2018 08:28:38 +0200 Message-Id: <20180529062838.20556-7-clg@kaod.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180529062838.20556-1-clg@kaod.org> References: <20180529062838.20556-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 17527446800400747440 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedthedrheejgddutdelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.36.150 Subject: [Qemu-devel] [PATCH 6/6] slirp/ncsi: add checksum support 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: , Cc: Samuel Thibault , Jason Wang , qemu-devel@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The checksum field of a NC-SI packet contains a value that may be included in each command and response. The verification is optional but the Linux driver does so when a non-zero value is provided. Let's extend the model to compute the checksum value and exercise a little more the Linux driver. See section "8.2.2.3 - 2's Complement Checksum Compensation" in the Network Controller Sideband Interface (NC-SI) Specification for more details. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Joel Stanley --- slirp/ncsi.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/slirp/ncsi.c b/slirp/ncsi.c index f00253641ea4..fbfb79713f23 100644 --- a/slirp/ncsi.c +++ b/slirp/ncsi.c @@ -8,9 +8,23 @@ */ #include "qemu/osdep.h" #include "slirp.h" +#include "net/checksum.h" =20 #include "ncsi-pkt.h" =20 +static uint32_t ncsi_calculate_checksum(unsigned char *data, int len) +{ + uint32_t checksum =3D 0; + int i; + + for (i =3D 0; i < len; i +=3D 2) { + checksum +=3D (((uint32_t)data[i] << 8) | data[i + 1]); + } + + checksum =3D (~checksum + 1); + return checksum; +} + /* Get Capabilities */ static int ncsi_rsp_handler_gc(struct ncsi_rsp_pkt_hdr *rnh) { @@ -108,6 +122,9 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int p= kt_len) (ncsi_reply + ETH_HLEN); const struct ncsi_rsp_handler *handler =3D NULL; int i; + int ncsi_rsp_len =3D sizeof(*nh); + uint32_t checksum; + uint32_t *pchecksum; =20 memset(ncsi_reply, 0, sizeof(ncsi_reply)); =20 @@ -137,15 +154,19 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int= pkt_len) /* TODO: handle errors */ handler->handler(rnh); } + ncsi_rsp_len +=3D handler->payload; } else { rnh->common.length =3D 0; rnh->code =3D htons(NCSI_PKT_RSP_C_UNAVAILABLE); rnh->reason =3D htons(NCSI_PKT_RSP_R_UNKNOWN); } =20 - /* TODO: add a checksum at the end of the frame but the specs - * allows it to be zero */ + /* add a checksum at the end of the frame (the specs allows it to + * be zero */ + checksum =3D ncsi_calculate_checksum((unsigned char *) rnh, ncsi_rsp_l= en); + pchecksum =3D (uint32_t *)((void *) rnh + ncsi_rsp_len); + *pchecksum =3D htonl(checksum); + ncsi_rsp_len +=3D 4; =20 - slirp_output(slirp->opaque, ncsi_reply, ETH_HLEN + sizeof(*nh) + - (handler ? handler->payload : 0) + 4); + slirp_output(slirp->opaque, ncsi_reply, ETH_HLEN + ncsi_rsp_len); } --=20 2.13.6