From nobody Mon Feb 9 14:34:32 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 1642340733029895.2965960635572; Sun, 16 Jan 2022 05:45:33 -0800 (PST) Received: from localhost ([::1]:34026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n95qe-0007pq-3d for importer@patchew.org; Sun, 16 Jan 2022 08:45:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n95in-0000lA-Lp for qemu-devel@nongnu.org; Sun, 16 Jan 2022 08:37:27 -0500 Received: from zero.eik.bme.hu ([152.66.115.2]:53163) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n95ik-0001h4-3e for qemu-devel@nongnu.org; Sun, 16 Jan 2022 08:37:25 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id AACA47470C8; Sun, 16 Jan 2022 14:37:19 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 4A8FF7470BD; Sun, 16 Jan 2022 14:37:19 +0100 (CET) Message-Id: <58b79c2f74864af713a575c3011cc77dfc6ea0f8.1642339238.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH 5/5] usb/ohci: Don't use packet from OHCIState for isochronous transfers Date: Sun, 16 Jan 2022 14:20:43 +0100 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1642340733915100003 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_packet field 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 e87f5bd813..5e5a93e54f 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -548,8 +548,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; @@ -559,6 +558,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; @@ -693,40 +695,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); @@ -734,7 +738,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; @@ -1057,7 +1061,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; @@ -1108,7 +1112,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; } } @@ -1136,20 +1140,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; } @@ -1173,7 +1177,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= . */ @@ -1181,7 +1185,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) { @@ -1793,7 +1797,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.30.2