From nobody Fri May 17 00:24:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1662489273785197.0266560731119; Tue, 6 Sep 2022 11:34:33 -0700 (PDT) Received: from localhost ([::1]:59966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVdP4-0005bN-QX for importer@patchew.org; Tue, 06 Sep 2022 14:34:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVdMH-0003Ej-N5 for qemu-devel@nongnu.org; Tue, 06 Sep 2022 14:31:37 -0400 Received: from blyat.fensystems.co.uk ([2a05:d018:a4d:6403:2dda:8093:274f:d185]:55672) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVdMG-0004sX-6l for qemu-devel@nongnu.org; Tue, 06 Sep 2022 14:31:37 -0400 Received: from dolphin.home (unknown [IPv6:2a00:23c6:5486:8700:72b3:d5ff:feb1:e101]) by blyat.fensystems.co.uk (Postfix) with ESMTPSA id C80104425E; Tue, 6 Sep 2022 18:31:32 +0000 (UTC) From: Michael Brown To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Michael Brown Subject: [PATCH 1/4] usbnet: Add missing usb_wakeup() call in usbnet_receive() Date: Tue, 6 Sep 2022 19:30:50 +0100 Message-Id: <20220906183053.3625472-2-mcb30@ipxe.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220906183053.3625472-1-mcb30@ipxe.org> References: <20220906183053.3625472-1-mcb30@ipxe.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a05:d018:a4d:6403:2dda:8093:274f:d185; envelope-from=mcb30@ipxe.org; helo=blyat.fensystems.co.uk X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-ZM-MESSAGEID: 1662489275195100001 Content-Type: text/plain; charset="utf-8" usbnet_receive() does not currently wake up the USB endpoint, leading to a dead RX datapath when used with a host controller such as xHCI that relies on being woken up. Fix by adding a call to usb_wakeup() at the end of usbnet_receive(). Signed-off-by: Michael Brown --- hw/usb/dev-network.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c index 6c49c16015..61bf598870 100644 --- a/hw/usb/dev-network.c +++ b/hw/usb/dev-network.c @@ -647,6 +647,7 @@ struct USBNetState { uint8_t in_buf[2048]; =20 USBEndpoint *intr; + USBEndpoint *bulk_in; =20 char usbstring_mac[13]; NICState *nic; @@ -1317,6 +1318,7 @@ static ssize_t usbnet_receive(NetClientState *nc, con= st uint8_t *buf, size_t siz memcpy(in_buf, buf, size); s->in_len =3D total_size; s->in_ptr =3D 0; + usb_wakeup(s->bulk_in, 0); return size; } =20 @@ -1359,6 +1361,7 @@ static void usb_net_realize(USBDevice *dev, Error **e= rrp) s->filter =3D 0; s->vendorid =3D 0x1234; s->intr =3D usb_ep_get(dev, USB_TOKEN_IN, 1); + s->bulk_in =3D usb_ep_get(dev, USB_TOKEN_IN, 2); =20 qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic =3D qemu_new_nic(&net_usbnet_info, &s->conf, --=20 2.35.1 From nobody Fri May 17 00:24:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1662489431600512.1392368962111; Tue, 6 Sep 2022 11:37:11 -0700 (PDT) Received: from localhost ([::1]:52406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVdRe-0001C4-Az for importer@patchew.org; Tue, 06 Sep 2022 14:37:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVdMJ-0003HC-3F for qemu-devel@nongnu.org; Tue, 06 Sep 2022 14:31:39 -0400 Received: from blyat.fensystems.co.uk ([54.246.183.96]:56010) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVdMH-0004sk-In for qemu-devel@nongnu.org; Tue, 06 Sep 2022 14:31:38 -0400 Received: from dolphin.home (unknown [IPv6:2a00:23c6:5486:8700:72b3:d5ff:feb1:e101]) by blyat.fensystems.co.uk (Postfix) with ESMTPSA id 9EE8D44271; Tue, 6 Sep 2022 18:31:34 +0000 (UTC) From: Michael Brown To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Michael Brown Subject: [PATCH 2/4] usbnet: Accept mandatory USB_CDC_SET_ETHERNET_PACKET_FILTER request Date: Tue, 6 Sep 2022 19:30:51 +0100 Message-Id: <20220906183053.3625472-3-mcb30@ipxe.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220906183053.3625472-1-mcb30@ipxe.org> References: <20220906183053.3625472-1-mcb30@ipxe.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=54.246.183.96; envelope-from=mcb30@ipxe.org; helo=blyat.fensystems.co.uk X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-ZM-MESSAGEID: 1662489432041100001 Content-Type: text/plain; charset="utf-8" The USB_CDC_SET_ETHERNET_PACKET_FILTER request is mandatory for CDC-ECM devices. Accept this request, ignoring the actual filter value (to match the existing behaviour for RNDIS). Signed-off-by: Michael Brown --- hw/usb/dev-network.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c index 61bf598870..155df935cd 100644 --- a/hw/usb/dev-network.c +++ b/hw/usb/dev-network.c @@ -1122,6 +1122,12 @@ static void usb_net_handle_control(USBDevice *dev, U= SBPacket *p, #endif break; =20 + case ClassInterfaceOutRequest | USB_CDC_SET_ETHERNET_PACKET_FILTER: + if (is_rndis(s)) { + goto fail; + } + break; + default: fail: fprintf(stderr, "usbnet: failed control transaction: " --=20 2.35.1 From nobody Fri May 17 00:24:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1662489273382354.7752554044308; Tue, 6 Sep 2022 11:34:33 -0700 (PDT) Received: from localhost ([::1]:59968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVdP5-0005d7-Bd for importer@patchew.org; Tue, 06 Sep 2022 14:34:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48942) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVdML-0003M3-5x for qemu-devel@nongnu.org; Tue, 06 Sep 2022 14:31:41 -0400 Received: from blyat.fensystems.co.uk ([54.246.183.96]:56036) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVdMJ-0004sw-IF for qemu-devel@nongnu.org; Tue, 06 Sep 2022 14:31:40 -0400 Received: from dolphin.home (unknown [IPv6:2a00:23c6:5486:8700:72b3:d5ff:feb1:e101]) by blyat.fensystems.co.uk (Postfix) with ESMTPSA id 7F386442B3; Tue, 6 Sep 2022 18:31:36 +0000 (UTC) From: Michael Brown To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Michael Brown Subject: [PATCH 3/4] usbnet: Detect short packets as sent by the xHCI controller Date: Tue, 6 Sep 2022 19:30:52 +0100 Message-Id: <20220906183053.3625472-4-mcb30@ipxe.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220906183053.3625472-1-mcb30@ipxe.org> References: <20220906183053.3625472-1-mcb30@ipxe.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=54.246.183.96; envelope-from=mcb30@ipxe.org; helo=blyat.fensystems.co.uk X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-ZM-MESSAGEID: 1662489275362100003 Content-Type: text/plain; charset="utf-8" The xHCI controller will ignore the endpoint MTU and so may deliver packets of any length. Detect short packets as being any packet that has a length of zero or a length that is not a multiple of the MTU. Signed-off-by: Michael Brown --- hw/usb/dev-network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c index 155df935cd..9d83974ec9 100644 --- a/hw/usb/dev-network.c +++ b/hw/usb/dev-network.c @@ -1211,7 +1211,7 @@ static void usb_net_handle_dataout(USBNetState *s, US= BPacket *p) s->out_ptr +=3D sz; =20 if (!is_rndis(s)) { - if (p->iov.size < 64) { + if (p->iov.size % 64 || p->iov.size =3D=3D 0) { qemu_send_packet(qemu_get_queue(s->nic), s->out_buf, s->out_pt= r); s->out_ptr =3D 0; } --=20 2.35.1 From nobody Fri May 17 00:24:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1662489436090416.07065605683385; Tue, 6 Sep 2022 11:37:16 -0700 (PDT) Received: from localhost ([::1]:47236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVdRj-0001Fs-29 for importer@patchew.org; Tue, 06 Sep 2022 14:37:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVdMN-0003S5-Lo for qemu-devel@nongnu.org; Tue, 06 Sep 2022 14:31:43 -0400 Received: from blyat.fensystems.co.uk ([54.246.183.96]:56052) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVdML-0004t9-4O for qemu-devel@nongnu.org; Tue, 06 Sep 2022 14:31:43 -0400 Received: from dolphin.home (unknown [IPv6:2a00:23c6:5486:8700:72b3:d5ff:feb1:e101]) by blyat.fensystems.co.uk (Postfix) with ESMTPSA id 4DA09442B8; Tue, 6 Sep 2022 18:31:38 +0000 (UTC) From: Michael Brown To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Michael Brown Subject: [PATCH 4/4] usbnet: Report link-up via interrupt endpoint in CDC-ECM mode Date: Tue, 6 Sep 2022 19:30:53 +0100 Message-Id: <20220906183053.3625472-5-mcb30@ipxe.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220906183053.3625472-1-mcb30@ipxe.org> References: <20220906183053.3625472-1-mcb30@ipxe.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=54.246.183.96; envelope-from=mcb30@ipxe.org; helo=blyat.fensystems.co.uk X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-ZM-MESSAGEID: 1662489438135100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michael Brown --- hw/usb/dev-network.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c index 9d83974ec9..ac1adca543 100644 --- a/hw/usb/dev-network.c +++ b/hw/usb/dev-network.c @@ -91,6 +91,8 @@ enum usbstring_idx { #define USB_CDC_SET_ETHERNET_PACKET_FILTER 0x43 #define USB_CDC_GET_ETHERNET_STATISTIC 0x44 =20 +#define USB_CDC_NETWORK_CONNECTION 0x00 + #define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 =3D=3D 32 msec */ #define STATUS_BYTECOUNT 16 /* 8 byte header + data */ =20 @@ -640,6 +642,8 @@ struct USBNetState { uint16_t filter; uint32_t vendorid; =20 + uint16_t connection; + unsigned int out_ptr; uint8_t out_buf[2048]; =20 @@ -1140,18 +1144,28 @@ static void usb_net_handle_control(USBDevice *dev, = USBPacket *p, =20 static void usb_net_handle_statusin(USBNetState *s, USBPacket *p) { - le32 buf[2]; + le32 rbuf[2]; + uint16_t ebuf[4]; =20 if (p->iov.size < 8) { p->status =3D USB_RET_STALL; return; } =20 - buf[0] =3D cpu_to_le32(1); - buf[1] =3D cpu_to_le32(0); - usb_packet_copy(p, buf, 8); - if (!s->rndis_resp.tqh_first) { - p->status =3D USB_RET_NAK; + if (is_rndis(s)) { + rbuf[0] =3D cpu_to_le32(1); + rbuf[1] =3D cpu_to_le32(0); + usb_packet_copy(p, rbuf, 8); + if (!s->rndis_resp.tqh_first) { + p->status =3D USB_RET_NAK; + } + } else { + ebuf[0] =3D + cpu_to_be16(ClassInterfaceRequest | USB_CDC_NETWORK_CONNECTION= ); + ebuf[1] =3D cpu_to_le16(s->connection); + ebuf[2] =3D cpu_to_le16(1); + ebuf[3] =3D cpu_to_le16(0); + usb_packet_copy(p, ebuf, 8); } =20 #ifdef TRAFFIC_DEBUG @@ -1366,6 +1380,7 @@ static void usb_net_realize(USBDevice *dev, Error **e= rrp) s->media_state =3D 0; /* NDIS_MEDIA_STATE_CONNECTED */; s->filter =3D 0; s->vendorid =3D 0x1234; + s->connection =3D 1; /* Connected */ s->intr =3D usb_ep_get(dev, USB_TOKEN_IN, 1); s->bulk_in =3D usb_ep_get(dev, USB_TOKEN_IN, 2); =20 --=20 2.35.1