From nobody Sat Feb 7 11:05:05 2026 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; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633123207394415.3585566682664; Fri, 1 Oct 2021 14:20:07 -0700 (PDT) Received: from localhost ([::1]:35182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWPws-0004fl-5k for importer@patchew.org; Fri, 01 Oct 2021 17:20:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48798) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWPti-0001dc-6O for qemu-devel@nongnu.org; Fri, 01 Oct 2021 17:16:50 -0400 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:46257) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWPte-0007v5-7o for qemu-devel@nongnu.org; Fri, 01 Oct 2021 17:16:49 -0400 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 02F09748F5D; Fri, 1 Oct 2021 23:16:43 +0200 (CEST) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 84A71748F4E; Fri, 1 Oct 2021 23:16:42 +0200 (CEST) Message-Id: <457b7ce06f15f982441572ac7c0576432ee227dc.1633122670.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [RFC PATCH 1/4] usb/ohci: Move cancelling async packet to ohci_stop_endpoints() Date: Fri, 01 Oct 2021 23:11:10 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% 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=2001:738:2001:2001::2001; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu 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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland , Gerd Hoffmann , Howard Spoelstra Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1633123209358100003 Content-Type: text/plain; charset="utf-8" This is always done before calling this function so remove duplicated code and do it within the function at one place. Signed-off-by: BALATON Zoltan --- hw/usb/hcd-ohci.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index 1cf2816772..405abbb62d 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -369,6 +369,10 @@ void ohci_stop_endpoints(OHCIState *ohci) USBDevice *dev; int i, j; =20 + if (ohci->async_td) { + usb_cancel_packet(&ohci->usb_packet); + ohci->async_td =3D 0; + } for (i =3D 0; i < ohci->num_ports; i++) { dev =3D ohci->rhport[i].port.dev; if (dev && dev->attached) { @@ -398,10 +402,6 @@ static void ohci_roothub_reset(OHCIState *ohci) usb_port_reset(&port->port); } } - if (ohci->async_td) { - usb_cancel_packet(&ohci->usb_packet); - ohci->async_td =3D 0; - } ohci_stop_endpoints(ohci); } =20 @@ -1271,10 +1271,6 @@ static void ohci_frame_boundary(void *opaque) =20 /* Cancel all pending packets if either of the lists has been disabled= . */ if (ohci->old_ctl & (~ohci->ctl) & (OHCI_CTL_BLE | OHCI_CTL_CLE)) { - if (ohci->async_td) { - usb_cancel_packet(&ohci->usb_packet); - ohci->async_td =3D 0; - } ohci_stop_endpoints(ohci); } ohci->old_ctl =3D ohci->ctl; --=20 2.21.4 From nobody Sat Feb 7 11:05:05 2026 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; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633123206237697.4095174004447; Fri, 1 Oct 2021 14:20:06 -0700 (PDT) Received: from localhost ([::1]:35072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWPwq-0004bN-Mw for importer@patchew.org; Fri, 01 Oct 2021 17:20:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48880) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWPtq-0001mB-Ly for qemu-devel@nongnu.org; Fri, 01 Oct 2021 17:16:58 -0400 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:46263) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWPti-000844-Kj for qemu-devel@nongnu.org; Fri, 01 Oct 2021 17:16:58 -0400 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 77CB0748F5E; Fri, 1 Oct 2021 23:16:49 +0200 (CEST) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 8B17A748F56; Fri, 1 Oct 2021 23:16:42 +0200 (CEST) Message-Id: In-Reply-To: References: From: BALATON Zoltan Subject: [RFC PATCH 2/4] usb/ohci: Move USBPortOps related functions together Date: Fri, 01 Oct 2021 23:11:10 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% 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=2001:738:2001:2001::2001; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu 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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland , Gerd Hoffmann , Howard Spoelstra Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1633123208483100001 Content-Type: text/plain; charset="utf-8" This also allows removing two forward declarations Signed-off-by: BALATON Zoltan --- hw/usb/hcd-ohci.c | 204 +++++++++++++++++++++++----------------------- 1 file changed, 100 insertions(+), 104 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index 405abbb62d..f8761370e3 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -58,8 +58,6 @@ struct ohci_hcca { #define ED_WBACK_OFFSET offsetof(struct ohci_ed, head) #define ED_WBACK_SIZE 4 =20 -static void ohci_async_cancel_device(OHCIState *ohci, USBDevice *dev); - /* Bitfields for the first word of an Endpoint Desciptor. */ #define OHCI_ED_FA_SHIFT 0 #define OHCI_ED_FA_MASK (0x7f<opaque; - OHCIPort *port =3D &s->rhport[port1->index]; - uint32_t old_state =3D port->ctrl; - - /* set connect status */ - port->ctrl |=3D OHCI_PORT_CCS | OHCI_PORT_CSC; - - /* update speed */ - if (port->port.dev->speed =3D=3D USB_SPEED_LOW) { - port->ctrl |=3D OHCI_PORT_LSDA; - } else { - port->ctrl &=3D ~OHCI_PORT_LSDA; - } - - /* notify of remote-wakeup */ - if ((s->ctl & OHCI_CTL_HCFS) =3D=3D OHCI_USB_SUSPEND) { - ohci_set_interrupt(s, OHCI_INTR_RD); - } - - trace_usb_ohci_port_attach(port1->index); - - if (old_state !=3D port->ctrl) { - ohci_set_interrupt(s, OHCI_INTR_RHSC); - } -} - -static void ohci_detach(USBPort *port1) -{ - OHCIState *s =3D port1->opaque; - OHCIPort *port =3D &s->rhport[port1->index]; - uint32_t old_state =3D port->ctrl; - - ohci_async_cancel_device(s, port1->dev); - - /* set connect status */ - if (port->ctrl & OHCI_PORT_CCS) { - port->ctrl &=3D ~OHCI_PORT_CCS; - port->ctrl |=3D OHCI_PORT_CSC; - } - /* disable port */ - if (port->ctrl & OHCI_PORT_PES) { - port->ctrl &=3D ~OHCI_PORT_PES; - port->ctrl |=3D OHCI_PORT_PESC; - } - trace_usb_ohci_port_detach(port1->index); - - if (old_state !=3D port->ctrl) { - ohci_set_interrupt(s, OHCI_INTR_RHSC); - } -} - -static void ohci_wakeup(USBPort *port1) -{ - OHCIState *s =3D port1->opaque; - OHCIPort *port =3D &s->rhport[port1->index]; - uint32_t intr =3D 0; - if (port->ctrl & OHCI_PORT_PSS) { - trace_usb_ohci_port_wakeup(port1->index); - port->ctrl |=3D OHCI_PORT_PSSC; - port->ctrl &=3D ~OHCI_PORT_PSS; - intr =3D OHCI_INTR_RHSC; - } - /* Note that the controller can be suspended even if this port is not = */ - if ((s->ctl & OHCI_CTL_HCFS) =3D=3D OHCI_USB_SUSPEND) { - trace_usb_ohci_remote_wakeup(s->name); - /* This is the one state transition the controller can do by itsel= f */ - s->ctl &=3D ~OHCI_CTL_HCFS; - s->ctl |=3D OHCI_USB_RESUME; - /* In suspend mode only ResumeDetected is possible, not RHSC: - * see the OHCI spec 5.1.2.3. - */ - intr =3D OHCI_INTR_RD; - } - ohci_set_interrupt(s, intr); -} - -static void ohci_child_detach(USBPort *port1, USBDevice *child) -{ - OHCIState *s =3D port1->opaque; - - ohci_async_cancel_device(s, child); -} - static USBDevice *ohci_find_device(OHCIState *ohci, uint8_t addr) { USBDevice *dev; @@ -628,17 +540,6 @@ static int ohci_copy_iso_td(OHCIState *ohci, return 0; } =20 -static void ohci_process_lists(OHCIState *ohci, int completion); - -static void ohci_async_complete_packet(USBPort *port, USBPacket *packet) -{ - OHCIState *ohci =3D container_of(packet, OHCIState, usb_packet); - - trace_usb_ohci_async_complete(); - ohci->async_complete =3D true; - ohci_process_lists(ohci, 1); -} - #define USUB(a, b) ((int16_t)((uint16_t)(a) - (uint16_t)(b))) =20 static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed, @@ -1783,6 +1684,41 @@ static void ohci_mem_write(void *opaque, } } =20 +static const MemoryRegionOps ohci_mem_ops =3D { + .read =3D ohci_mem_read, + .write =3D ohci_mem_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, +}; + +/* USBPortOps */ +static void ohci_attach(USBPort *port1) +{ + OHCIState *s =3D port1->opaque; + OHCIPort *port =3D &s->rhport[port1->index]; + uint32_t old_state =3D port->ctrl; + + /* set connect status */ + port->ctrl |=3D OHCI_PORT_CCS | OHCI_PORT_CSC; + + /* update speed */ + if (port->port.dev->speed =3D=3D USB_SPEED_LOW) { + port->ctrl |=3D OHCI_PORT_LSDA; + } else { + port->ctrl &=3D ~OHCI_PORT_LSDA; + } + + /* notify of remote-wakeup */ + if ((s->ctl & OHCI_CTL_HCFS) =3D=3D OHCI_USB_SUSPEND) { + ohci_set_interrupt(s, OHCI_INTR_RD); + } + + trace_usb_ohci_port_attach(port1->index); + + if (old_state !=3D port->ctrl) { + ohci_set_interrupt(s, OHCI_INTR_RHSC); + } +} + static void ohci_async_cancel_device(OHCIState *ohci, USBDevice *dev) { if (ohci->async_td && @@ -1793,11 +1729,71 @@ static void ohci_async_cancel_device(OHCIState *ohc= i, USBDevice *dev) } } =20 -static const MemoryRegionOps ohci_mem_ops =3D { - .read =3D ohci_mem_read, - .write =3D ohci_mem_write, - .endianness =3D DEVICE_LITTLE_ENDIAN, -}; +static void ohci_child_detach(USBPort *port1, USBDevice *child) +{ + OHCIState *s =3D port1->opaque; + + ohci_async_cancel_device(s, child); +} + +static void ohci_detach(USBPort *port1) +{ + OHCIState *s =3D port1->opaque; + OHCIPort *port =3D &s->rhport[port1->index]; + uint32_t old_state =3D port->ctrl; + + ohci_async_cancel_device(s, port1->dev); + + /* set connect status */ + if (port->ctrl & OHCI_PORT_CCS) { + port->ctrl &=3D ~OHCI_PORT_CCS; + port->ctrl |=3D OHCI_PORT_CSC; + } + /* disable port */ + if (port->ctrl & OHCI_PORT_PES) { + port->ctrl &=3D ~OHCI_PORT_PES; + port->ctrl |=3D OHCI_PORT_PESC; + } + trace_usb_ohci_port_detach(port1->index); + + if (old_state !=3D port->ctrl) { + ohci_set_interrupt(s, OHCI_INTR_RHSC); + } +} + +static void ohci_wakeup(USBPort *port1) +{ + OHCIState *s =3D port1->opaque; + OHCIPort *port =3D &s->rhport[port1->index]; + uint32_t intr =3D 0; + if (port->ctrl & OHCI_PORT_PSS) { + trace_usb_ohci_port_wakeup(port1->index); + port->ctrl |=3D OHCI_PORT_PSSC; + port->ctrl &=3D ~OHCI_PORT_PSS; + intr =3D OHCI_INTR_RHSC; + } + /* Note that the controller can be suspended even if this port is not = */ + if ((s->ctl & OHCI_CTL_HCFS) =3D=3D OHCI_USB_SUSPEND) { + trace_usb_ohci_remote_wakeup(s->name); + /* This is the one state transition the controller can do by itsel= f */ + s->ctl &=3D ~OHCI_CTL_HCFS; + s->ctl |=3D OHCI_USB_RESUME; + /* In suspend mode only ResumeDetected is possible, not RHSC: + * see the OHCI spec 5.1.2.3. + */ + intr =3D OHCI_INTR_RD; + } + ohci_set_interrupt(s, intr); +} + +static void ohci_async_complete_packet(USBPort *port, USBPacket *packet) +{ + OHCIState *ohci =3D container_of(packet, OHCIState, usb_packet); + + trace_usb_ohci_async_complete(); + ohci->async_complete =3D true; + ohci_process_lists(ohci, 1); +} =20 static USBPortOps ohci_port_ops =3D { .attach =3D ohci_attach, --=20 2.21.4 From nobody Sat Feb 7 11:05:05 2026 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; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633123207815335.73228601669246; Fri, 1 Oct 2021 14:20:07 -0700 (PDT) Received: from localhost ([::1]:35206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWPws-0004gL-Mb for importer@patchew.org; Fri, 01 Oct 2021 17:20:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48886) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWPtw-0001yl-6f for qemu-devel@nongnu.org; Fri, 01 Oct 2021 17:17:04 -0400 Received: from zero.eik.bme.hu ([152.66.115.2]:46268) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWPti-00084D-Q1 for qemu-devel@nongnu.org; Fri, 01 Oct 2021 17:17:03 -0400 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 86B9D748F4E; Fri, 1 Oct 2021 23:16:49 +0200 (CEST) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 910BF748F5A; Fri, 1 Oct 2021 23:16:42 +0200 (CEST) Message-Id: <3b131f4b448feed92422602a2b1cfe9a2d302810.1633122670.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [RFC PATCH 3/4] usb/ohci: Merge ohci_async_cancel_device() into ohci_child_detach() Date: Fri, 01 Oct 2021 23:11:10 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% 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=152.66.115.2; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu 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, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland , Gerd Hoffmann , Howard Spoelstra Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1633123209654100005 Content-Type: text/plain; charset="utf-8" These two do the same and only used once so no need to have two functions, simplify by merging them. Signed-off-by: BALATON Zoltan --- hw/usb/hcd-ohci.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index f8761370e3..212d0aabbe 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -1719,8 +1719,10 @@ static void ohci_attach(USBPort *port1) } } =20 -static void ohci_async_cancel_device(OHCIState *ohci, USBDevice *dev) +static void ohci_child_detach(USBPort *port1, USBDevice *dev) { + OHCIState *ohci =3D port1->opaque; + if (ohci->async_td && usb_packet_is_inflight(&ohci->usb_packet) && ohci->usb_packet.ep->dev =3D=3D dev) { @@ -1729,20 +1731,13 @@ static void ohci_async_cancel_device(OHCIState *ohc= i, USBDevice *dev) } } =20 -static void ohci_child_detach(USBPort *port1, USBDevice *child) -{ - OHCIState *s =3D port1->opaque; - - ohci_async_cancel_device(s, child); -} - static void ohci_detach(USBPort *port1) { OHCIState *s =3D port1->opaque; OHCIPort *port =3D &s->rhport[port1->index]; uint32_t old_state =3D port->ctrl; =20 - ohci_async_cancel_device(s, port1->dev); + ohci_child_detach(port1, port1->dev); =20 /* set connect status */ if (port->ctrl & OHCI_PORT_CCS) { --=20 2.21.4 From nobody Sat Feb 7 11:05:05 2026 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; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633123371408533.8438001144021; Fri, 1 Oct 2021 14:22:51 -0700 (PDT) Received: from localhost ([::1]:41438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWPzV-0000e0-46 for importer@patchew.org; Fri, 01 Oct 2021 17:22:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWPti-0001e2-AJ for qemu-devel@nongnu.org; Fri, 01 Oct 2021 17:16:50 -0400 Received: from zero.eik.bme.hu ([152.66.115.2]:46259) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWPte-0007v8-Ig for qemu-devel@nongnu.org; Fri, 01 Oct 2021 17:16:50 -0400 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id E26A7748F58; Fri, 1 Oct 2021 23:16:42 +0200 (CEST) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 976D7748F4F; Fri, 1 Oct 2021 23:16:42 +0200 (CEST) Message-Id: In-Reply-To: References: From: BALATON Zoltan Subject: [RFC PATCH 4/4] usb/ohci: Don't use packet from OHCIState for isochronous transfers Date: Fri, 01 Oct 2021 23:11:10 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% 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=152.66.115.2; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland , Gerd Hoffmann , Howard Spoelstra Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1633123373313100001 Content-Type: text/plain; charset="utf-8" Since isochronous transfers cannot be handled async (the function returns error in that case) we don't need to remember the packet. Avoid using the usb_pkt in OHCIState (as that can be a waiting async packet on another endpoint) and allocate and use a local USBPacket for the iso transfer instead. After this we don't have to care if we're called from a completion callback or not so we can drop that parameter as well. Signed-off-by: BALATON Zoltan --- hw/usb/hcd-ohci.c | 70 +++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index 212d0aabbe..18170e7256 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -542,8 +542,7 @@ static int ohci_copy_iso_td(OHCIState *ohci, =20 #define USUB(a, b) ((int16_t)((uint16_t)(a) - (uint16_t)(b))) =20 -static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed, - int completion) +static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed) { int dir; size_t len =3D 0; @@ -553,6 +552,9 @@ static int ohci_service_iso_td(OHCIState *ohci, struct = ohci_ed *ed, int i; USBDevice *dev; USBEndpoint *ep; + USBPacket *pkt; + uint8_t buf[8192]; + bool int_req; struct ohci_iso_td iso_td; uint32_t addr; uint16_t starting_frame; @@ -687,40 +689,42 @@ static int ohci_service_iso_td(OHCIState *ohci, struc= t ohci_ed *ed, } else { len =3D end_addr - start_addr + 1; } - if (len > sizeof(ohci->usb_buf)) { - len =3D sizeof(ohci->usb_buf); + if (len > sizeof(buf)) { + len =3D sizeof(buf); } =20 if (len && dir !=3D OHCI_TD_DIR_IN) { - if (ohci_copy_iso_td(ohci, start_addr, end_addr, ohci->usb_buf, le= n, + if (ohci_copy_iso_td(ohci, start_addr, end_addr, buf, len, DMA_DIRECTION_TO_DEVICE)) { ohci_die(ohci); return 1; } } =20 - if (!completion) { - bool int_req =3D relative_frame_number =3D=3D frame_count && - OHCI_BM(iso_td.flags, TD_DI) =3D=3D 0; - dev =3D ohci_find_device(ohci, OHCI_BM(ed->flags, ED_FA)); - if (dev =3D=3D NULL) { - trace_usb_ohci_td_dev_error(); - return 1; - } - ep =3D usb_ep_get(dev, pid, OHCI_BM(ed->flags, ED_EN)); - usb_packet_setup(&ohci->usb_packet, pid, ep, 0, addr, false, int_r= eq); - usb_packet_addbuf(&ohci->usb_packet, ohci->usb_buf, len); - usb_handle_packet(dev, &ohci->usb_packet); - if (ohci->usb_packet.status =3D=3D USB_RET_ASYNC) { - usb_device_flush_ep_queue(dev, ep); - return 1; - } + dev =3D ohci_find_device(ohci, OHCI_BM(ed->flags, ED_FA)); + if (dev =3D=3D NULL) { + trace_usb_ohci_td_dev_error(); + return 1; } - if (ohci->usb_packet.status =3D=3D USB_RET_SUCCESS) { - ret =3D ohci->usb_packet.actual_length; + ep =3D usb_ep_get(dev, pid, OHCI_BM(ed->flags, ED_EN)); + pkt =3D g_new0(USBPacket, 1); + usb_packet_init(pkt); + int_req =3D relative_frame_number =3D=3D frame_count && + OHCI_BM(iso_td.flags, TD_DI) =3D=3D 0; + usb_packet_setup(pkt, pid, ep, 0, addr, false, int_req); + usb_packet_addbuf(pkt, buf, len); + usb_handle_packet(dev, pkt); + if (pkt->status =3D=3D USB_RET_ASYNC) { + usb_device_flush_ep_queue(dev, ep); + g_free(pkt); + return 1; + } + if (pkt->status =3D=3D USB_RET_SUCCESS) { + ret =3D pkt->actual_length; } else { - ret =3D ohci->usb_packet.status; + ret =3D pkt->status; } + g_free(pkt); =20 trace_usb_ohci_iso_td_so(start_offset, end_offset, start_addr, end_add= r, str, len, ret); @@ -728,7 +732,7 @@ static int ohci_service_iso_td(OHCIState *ohci, struct = ohci_ed *ed, /* Writeback */ if (dir =3D=3D OHCI_TD_DIR_IN && ret >=3D 0 && ret <=3D len) { /* IN transfer succeeded */ - if (ohci_copy_iso_td(ohci, start_addr, end_addr, ohci->usb_buf, re= t, + if (ohci_copy_iso_td(ohci, start_addr, end_addr, buf, ret, DMA_DIRECTION_FROM_DEVICE)) { ohci_die(ohci); return 1; @@ -1051,7 +1055,7 @@ exit_no_retire: } =20 /* Service an endpoint list. Returns nonzero if active TD were found. */ -static int ohci_service_ed_list(OHCIState *ohci, uint32_t head, int comple= tion) +static int ohci_service_ed_list(OHCIState *ohci, uint32_t head) { struct ohci_ed ed; uint32_t next_ed; @@ -1102,7 +1106,7 @@ static int ohci_service_ed_list(OHCIState *ohci, uint= 32_t head, int completion) break; } else { /* Handle isochronous endpoints */ - if (ohci_service_iso_td(ohci, &ed, completion)) + if (ohci_service_iso_td(ohci, &ed)) break; } } @@ -1130,20 +1134,20 @@ static void ohci_sof(OHCIState *ohci) } =20 /* Process Control and Bulk lists. */ -static void ohci_process_lists(OHCIState *ohci, int completion) +static void ohci_process_lists(OHCIState *ohci) { if ((ohci->ctl & OHCI_CTL_CLE) && (ohci->status & OHCI_STATUS_CLF)) { if (ohci->ctrl_cur && ohci->ctrl_cur !=3D ohci->ctrl_head) { trace_usb_ohci_process_lists(ohci->ctrl_head, ohci->ctrl_cur); } - if (!ohci_service_ed_list(ohci, ohci->ctrl_head, completion)) { + if (!ohci_service_ed_list(ohci, ohci->ctrl_head)) { ohci->ctrl_cur =3D 0; ohci->status &=3D ~OHCI_STATUS_CLF; } } =20 if ((ohci->ctl & OHCI_CTL_BLE) && (ohci->status & OHCI_STATUS_BLF)) { - if (!ohci_service_ed_list(ohci, ohci->bulk_head, completion)) { + if (!ohci_service_ed_list(ohci, ohci->bulk_head)) { ohci->bulk_cur =3D 0; ohci->status &=3D ~OHCI_STATUS_BLF; } @@ -1167,7 +1171,7 @@ static void ohci_frame_boundary(void *opaque) int n; =20 n =3D ohci->frame_number & 0x1f; - ohci_service_ed_list(ohci, le32_to_cpu(hcca.intr[n]), 0); + ohci_service_ed_list(ohci, le32_to_cpu(hcca.intr[n])); } =20 /* Cancel all pending packets if either of the lists has been disabled= . */ @@ -1175,7 +1179,7 @@ static void ohci_frame_boundary(void *opaque) ohci_stop_endpoints(ohci); } ohci->old_ctl =3D ohci->ctl; - ohci_process_lists(ohci, 0); + ohci_process_lists(ohci); =20 /* Stop if UnrecoverableError happened or ohci_sof will crash */ if (ohci->intr_status & OHCI_INTR_UE) { @@ -1787,7 +1791,7 @@ static void ohci_async_complete_packet(USBPort *port,= USBPacket *packet) =20 trace_usb_ohci_async_complete(); ohci->async_complete =3D true; - ohci_process_lists(ohci, 1); + ohci_process_lists(ohci); } =20 static USBPortOps ohci_port_ops =3D { --=20 2.21.4