From nobody Mon Feb 9 18:39:58 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 ARC-Seal: i=1; a=rsa-sha256; t=1615120008; cv=none; d=zohomail.com; s=zohoarc; b=HCdyHwOfqZ1//i542+PWJvEELulYwngG4RU3AvvWMNTtgqnS5UAB9dzwcCFkSNsTe9LkZGBsOdNCQGhO/6Cp3j9FyVyl7xsCU8yqyZnVG2hZGOWBOJ+XKo7ozzNWJbE69fEEAvNN1ITHm47CckWE7cqvRgVtzBiTO+LqIJx+tvw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615120008; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iY0Px1SPXmKOlyCC8GjvBDuSHP92CFGrkCzKdKXEuKA=; b=R1U8mP42mSIKwEVyLYRM8QV/q9vpYwR52rbKAifhpf67IAKcXio96fnPcaD6rDKPxOh9waaGPMV9awqQUiVmhicC9EwawjegOA9o2bSJVIaZs2IBYj1reCKI0mCM5m4FGYB31pD0Cd4puK9y2WjFbBImGVF1r8FbMgJkNr+YTlY= ARC-Authentication-Results: i=1; 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 1615120008137263.5950695309018; Sun, 7 Mar 2021 04:26:48 -0800 (PST) Received: from localhost ([::1]:44748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lIsUh-0007nm-0a for importer@patchew.org; Sun, 07 Mar 2021 07:26:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41848) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lIsG1-0002Rp-Ue for qemu-devel@nongnu.org; Sun, 07 Mar 2021 07:11:38 -0500 Received: from mail.ilande.co.uk ([2001:41c9:1:41f::167]:43716 helo=mail.default.ilande.uk0.bigv.io) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lIsFy-00086u-8Z for qemu-devel@nongnu.org; Sun, 07 Mar 2021 07:11:37 -0500 Received: from host86-148-34-47.range86-148.btcentralplus.com ([86.148.34.47] helo=kentang.home) by mail.default.ilande.uk0.bigv.io with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lIsFj-0002V5-7H; Sun, 07 Mar 2021 12:11:23 +0000 From: Mark Cave-Ayland To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Sun, 7 Mar 2021 12:08:36 +0000 Message-Id: <20210307120850.10418-29-mark.cave-ayland@ilande.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210307120850.10418-1-mark.cave-ayland@ilande.co.uk> References: <20210307120850.10418-1-mark.cave-ayland@ilande.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 86.148.34.47 X-SA-Exim-Mail-From: mark.cave-ayland@ilande.co.uk Subject: [PULL 28/42] esp: use FIFO for PDMA transfers between initiator and device X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.default.ilande.uk0.bigv.io) 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:41c9:1:41f::167; envelope-from=mark.cave-ayland@ilande.co.uk; helo=mail.default.ilande.uk0.bigv.io 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" PDMA as implemented on the Quadra 800 uses DREQ to load data into the FIFO up to a maximum of 16 bytes at a time. The MacOS toolbox ROM requires this because it mixes FIFO and PDMA transfers whilst checking the FIFO status and counter registers to ensure success. Signed-off-by: Mark Cave-Ayland Reviewed-by: Laurent Vivier Message-Id: <20210304221103.6369-29-mark.cave-ayland@ilande.co.uk> --- hw/scsi/esp.c | 109 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 34 deletions(-) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 10e63d1f62..aa897a4ebd 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -134,13 +134,8 @@ static void set_pdma(ESPState *s, enum pdma_origin_id = origin) =20 static uint8_t esp_pdma_read(ESPState *s) { - uint32_t dmalen =3D esp_get_tc(s); uint8_t val; =20 - if (dmalen =3D=3D 0) { - return 0; - } - switch (s->pdma_origin) { case TI: if (s->do_cmd) { @@ -160,10 +155,6 @@ static uint8_t esp_pdma_read(ESPState *s) g_assert_not_reached(); } =20 - s->ti_size--; - dmalen--; - esp_set_tc(s, dmalen); - return val; } =20 @@ -194,7 +185,6 @@ static void esp_pdma_write(ESPState *s, uint8_t val) g_assert_not_reached(); } =20 - s->ti_size++; dmalen--; esp_set_tc(s, dmalen); } @@ -290,6 +280,7 @@ static void do_busid_cmd(ESPState *s, uint8_t *buf, uin= t8_t busid) s->rregs[ESP_RINTR] =3D INTR_BS | INTR_FC; s->rregs[ESP_RSEQ] =3D SEQ_CD; esp_raise_irq(s); + esp_lower_drq(s); } =20 static void do_cmd(ESPState *s) @@ -447,28 +438,71 @@ static void esp_dma_done(ESPState *s) static void do_dma_pdma_cb(ESPState *s) { int to_device =3D ((s->rregs[ESP_RSTAT] & 7) =3D=3D STAT_DO); + int len; =20 if (s->do_cmd) { s->ti_size =3D 0; s->cmdlen =3D 0; s->do_cmd =3D 0; do_cmd(s); + esp_lower_drq(s); return; } - if (s->async_len =3D=3D 0) { - scsi_req_continue(s->current_req); - /* - * If there is still data to be read from the device then - * complete the DMA operation immediately. Otherwise defer - * until the scsi layer has completed. - */ - if (to_device || esp_get_tc(s) !=3D 0 || s->ti_size =3D=3D 0) { + + if (to_device) { + /* Copy FIFO data to device */ + len =3D MIN(s->ti_wptr, TI_BUFSZ); + memcpy(s->async_buf, s->ti_buf, len); + s->ti_wptr =3D 0; + s->ti_rptr =3D 0; + s->async_buf +=3D len; + s->async_len -=3D len; + s->ti_size +=3D len; + if (s->async_len =3D=3D 0) { + scsi_req_continue(s->current_req); return; } - } =20 - /* Partially filled a scsi buffer. Complete immediately. */ - esp_dma_done(s); + if (esp_get_tc(s) =3D=3D 0) { + esp_lower_drq(s); + esp_dma_done(s); + } + + return; + } else { + if (s->async_len =3D=3D 0) { + if (s->current_req) { + scsi_req_continue(s->current_req); + } + + /* + * If there is still data to be read from the device then + * complete the DMA operation immediately. Otherwise defer + * until the scsi layer has completed. + */ + if (esp_get_tc(s) !=3D 0 || s->ti_size =3D=3D 0) { + return; + } + } + + if (esp_get_tc(s) !=3D 0) { + /* Copy device data to FIFO */ + s->ti_wptr =3D 0; + s->ti_rptr =3D 0; + len =3D MIN(s->async_len, TI_BUFSZ); + memcpy(s->ti_buf, s->async_buf, len); + s->ti_wptr +=3D len; + s->async_buf +=3D len; + s->async_len -=3D len; + s->ti_size -=3D len; + esp_set_tc(s, esp_get_tc(s) - len); + return; + } + + /* Partially filled a scsi buffer. Complete immediately. */ + esp_lower_drq(s); + esp_dma_done(s); + } } =20 static void esp_do_dma(ESPState *s) @@ -511,7 +545,7 @@ static void esp_do_dma(ESPState *s) if (s->dma_memory_read) { s->dma_memory_read(s->dma_opaque, s->async_buf, len); } else { - set_pdma(s, ASYNC); + set_pdma(s, TI); s->pdma_cb =3D do_dma_pdma_cb; esp_raise_drq(s); return; @@ -520,9 +554,20 @@ static void esp_do_dma(ESPState *s) if (s->dma_memory_write) { s->dma_memory_write(s->dma_opaque, s->async_buf, len); } else { - set_pdma(s, ASYNC); + /* Copy device data to FIFO */ + len =3D MIN(len, TI_BUFSZ - s->ti_wptr); + memcpy(&s->ti_buf[s->ti_wptr], s->async_buf, len); + s->ti_wptr +=3D len; + s->async_buf +=3D len; + s->async_len -=3D len; + s->ti_size -=3D len; + esp_set_tc(s, esp_get_tc(s) - len); + set_pdma(s, TI); s->pdma_cb =3D do_dma_pdma_cb; esp_raise_drq(s); + + /* Indicate transfer to FIFO is complete */ + s->rregs[ESP_RSTAT] |=3D STAT_TC; return; } } @@ -548,6 +593,7 @@ static void esp_do_dma(ESPState *s) =20 /* Partially filled a scsi buffer. Complete immediately. */ esp_dma_done(s); + esp_lower_drq(s); } =20 static void esp_report_command_complete(ESPState *s, uint32_t status) @@ -564,6 +610,7 @@ static void esp_report_command_complete(ESPState *s, ui= nt32_t status) s->status =3D status; s->rregs[ESP_RSTAT] =3D STAT_ST; esp_dma_done(s); + esp_lower_drq(s); if (s->current_req) { scsi_req_unref(s->current_req); s->current_req =3D NULL; @@ -605,6 +652,7 @@ void esp_transfer_data(SCSIRequest *req, uint32_t len) * completion interrupt is deferred to here. */ esp_dma_done(s); + esp_lower_drq(s); } } =20 @@ -976,10 +1024,8 @@ static void sysbus_esp_pdma_write(void *opaque, hwadd= r addr, break; } dmalen =3D esp_get_tc(s); - if (dmalen =3D=3D 0 && s->pdma_cb) { - esp_lower_drq(s); + if (dmalen =3D=3D 0 || (s->ti_wptr =3D=3D TI_BUFSZ)) { s->pdma_cb(s); - s->pdma_cb =3D NULL; } } =20 @@ -988,14 +1034,10 @@ static uint64_t sysbus_esp_pdma_read(void *opaque, h= waddr addr, { SysBusESPState *sysbus =3D opaque; ESPState *s =3D ESP(&sysbus->esp); - uint32_t dmalen =3D esp_get_tc(s); uint64_t val =3D 0; =20 trace_esp_pdma_read(size); =20 - if (dmalen =3D=3D 0) { - return 0; - } switch (size) { case 1: val =3D esp_pdma_read(s); @@ -1005,11 +1047,10 @@ static uint64_t sysbus_esp_pdma_read(void *opaque, = hwaddr addr, val =3D (val << 8) | esp_pdma_read(s); break; } - dmalen =3D esp_get_tc(s); - if (dmalen =3D=3D 0 && s->pdma_cb) { - esp_lower_drq(s); + if (s->ti_rptr =3D=3D s->ti_wptr) { + s->ti_wptr =3D 0; + s->ti_rptr =3D 0; s->pdma_cb(s); - s->pdma_cb =3D NULL; } return val; } --=20 2.20.1