qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
To: qemu-devel@nongnu.org, pbonzini@redhat.com, fam@euphon.net,
	laurent@vivier.eu
Subject: [PATCH 19/25] esp: use in-built TC to determine PDMA transfer length
Date: Wed, 30 Dec 2020 15:37:39 +0000	[thread overview]
Message-ID: <20201230153745.30241-20-mark.cave-ayland@ilande.co.uk> (raw)
In-Reply-To: <20201230153745.30241-1-mark.cave-ayland@ilande.co.uk>

Real hardware simply counts down using the in-built TC to determine when the
the PDMA request is complete. Use the TC to determine the PDMA transfer length
which then enables us to remove the redundant pdma_len variable.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/scsi/esp.c         | 28 +++++++++++++---------------
 include/hw/scsi/esp.h |  1 -
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index b43d0941f0..35cc274747 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -127,10 +127,9 @@ static uint32_t esp_get_stc(ESPState *s)
     return dmalen;
 }
 
-static void set_pdma(ESPState *s, enum pdma_origin_id origin, uint32_t len)
+static void set_pdma(ESPState *s, enum pdma_origin_id origin)
 {
     s->pdma_origin = origin;
-    s->pdma_len = len;
 }
 
 static uint8_t esp_pdma_read(ESPState *s)
@@ -138,7 +137,7 @@ static uint8_t esp_pdma_read(ESPState *s)
     uint32_t dmalen = esp_get_tc(s);
     uint8_t val;
 
-    if (dmalen == 0 || s->pdma_len == 0) {
+    if (dmalen == 0) {
         return 0;
     }
 
@@ -161,7 +160,6 @@ static uint8_t esp_pdma_read(ESPState *s)
     }
 
     s->ti_size--;
-    s->pdma_len--;
     dmalen--;
     esp_set_tc(s, dmalen);
 
@@ -172,7 +170,7 @@ static void esp_pdma_write(ESPState *s, uint8_t val)
 {
     uint32_t dmalen = esp_get_tc(s);
 
-    if (dmalen == 0 || s->pdma_len == 0) {
+    if (dmalen == 0) {
         return;
     }
 
@@ -195,7 +193,6 @@ static void esp_pdma_write(ESPState *s, uint8_t val)
     }
 
     s->ti_size++;
-    s->pdma_len--;
     dmalen--;
     esp_set_tc(s, dmalen);
 }
@@ -242,7 +239,7 @@ static uint32_t get_cmd(ESPState *s, uint8_t *buf, uint8_t buflen)
         if (s->dma_memory_read) {
             s->dma_memory_read(s->dma_opaque, buf, dmalen);
         } else {
-            set_pdma(s, CMD, dmalen);
+            set_pdma(s, CMD);
             esp_raise_drq(s);
             return 0;
         }
@@ -404,7 +401,7 @@ static void write_response(ESPState *s)
             s->rregs[ESP_RINTR] = INTR_BS | INTR_FC;
             s->rregs[ESP_RSEQ] = SEQ_CD;
         } else {
-            set_pdma(s, TI, 2);
+            set_pdma(s, TI);
             s->pdma_cb = write_response_pdma_cb;
             esp_raise_drq(s);
             return;
@@ -474,7 +471,7 @@ static void esp_do_dma(ESPState *s)
         if (s->dma_memory_read) {
             s->dma_memory_read(s->dma_opaque, &s->cmdbuf[s->cmdlen], len);
         } else {
-            set_pdma(s, CMD, len);
+            set_pdma(s, CMD);
             s->pdma_cb = do_dma_pdma_cb;
             esp_raise_drq(s);
             return;
@@ -497,7 +494,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, len);
+            set_pdma(s, ASYNC);
             s->pdma_cb = do_dma_pdma_cb;
             esp_raise_drq(s);
             return;
@@ -506,7 +503,7 @@ 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, len);
+            set_pdma(s, ASYNC);
             s->pdma_cb = do_dma_pdma_cb;
             esp_raise_drq(s);
             return;
@@ -852,7 +849,6 @@ static const VMStateDescription vmstate_esp_pdma = {
     .needed = esp_pdma_needed,
     .fields = (VMStateField[]) {
         VMSTATE_INT32(pdma_origin, ESPState),
-        VMSTATE_UINT32(pdma_len, ESPState),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -917,6 +913,7 @@ static void sysbus_esp_pdma_write(void *opaque, hwaddr addr,
 {
     SysBusESPState *sysbus = opaque;
     ESPState *s = &sysbus->esp;
+    uint32_t dmalen;
 
     trace_esp_pdma_write(size);
 
@@ -929,7 +926,8 @@ static void sysbus_esp_pdma_write(void *opaque, hwaddr addr,
         esp_pdma_write(s, val);
         break;
     }
-    if (s->pdma_len == 0 && s->pdma_cb) {
+    dmalen = esp_get_tc(s);
+    if (dmalen == 0 && s->pdma_cb) {
         esp_lower_drq(s);
         s->pdma_cb(s);
         s->pdma_cb = NULL;
@@ -946,7 +944,7 @@ static uint64_t sysbus_esp_pdma_read(void *opaque, hwaddr addr,
 
     trace_esp_pdma_read(size);
 
-    if (dmalen == 0 || s->pdma_len == 0) {
+    if (dmalen == 0) {
         return 0;
     }
     switch (size) {
@@ -959,7 +957,7 @@ static uint64_t sysbus_esp_pdma_read(void *opaque, hwaddr addr,
         break;
     }
     dmalen = esp_get_tc(s);
-    if (dmalen == 0 || (s->pdma_len == 0 && s->pdma_cb)) {
+    if (dmalen == 0 && s->pdma_cb) {
         esp_lower_drq(s);
         s->pdma_cb(s);
         s->pdma_cb = NULL;
diff --git a/include/hw/scsi/esp.h b/include/hw/scsi/esp.h
index 292136344a..ecad5d8471 100644
--- a/include/hw/scsi/esp.h
+++ b/include/hw/scsi/esp.h
@@ -52,7 +52,6 @@ struct ESPState {
     void *dma_opaque;
     void (*dma_cb)(ESPState *s);
     int pdma_origin;
-    uint32_t pdma_len;
     void (*pdma_cb)(ESPState *s);
 
     /* Legacy field for vmstate_sysbus_esp_scsi version < 2 */
-- 
2.20.1



  parent reply	other threads:[~2020-12-30 15:53 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-30 15:37 [PATCH 00/25] esp: consolidate PDMA transfer buffers Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 01/25] esp: checkpatch fixes Mark Cave-Ayland
2021-01-01 16:53   ` Philippe Mathieu-Daudé
2020-12-30 15:37 ` [PATCH 02/25] esp: add trace event when receiving a TI command Mark Cave-Ayland
2021-01-01 16:54   ` Philippe Mathieu-Daudé
2020-12-30 15:37 ` [PATCH 03/25] esp: fix esp_reg_read() trace event Mark Cave-Ayland
2021-01-01 16:54   ` Philippe Mathieu-Daudé
2020-12-30 15:37 ` [PATCH 04/25] esp: add PDMA trace events Mark Cave-Ayland
2021-01-01 16:55   ` Philippe Mathieu-Daudé
2020-12-30 15:37 ` [PATCH 05/25] esp: determine transfer direction directly from SCSI phase Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 06/25] esp: introduce esp_get_tc() and esp_set_tc() Mark Cave-Ayland
2021-01-01 16:56   ` Philippe Mathieu-Daudé
2020-12-30 15:37 ` [PATCH 07/25] esp: introduce esp_get_stc() Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 08/25] esp: apply transfer length adjustment when STC is zero at TC load time Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 09/25] esp: remove dma_counter from ESPState Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 10/25] esp: remove dma_left " Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 11/25] esp: remove minlen restriction in handle_ti Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 12/25] esp: introduce esp_pdma_read() and esp_pdma_write() functions Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 13/25] esp: use pdma_origin directly in esp_pdma_read()/esp_pdma_write() Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 14/25] esp: move pdma_len and TC logic into esp_pdma_read()/esp_pdma_write() Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 15/25] esp: accumulate SCSI commands for PDMA transfers in cmdbuf instead of pdma_buf Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 16/25] esp: remove redundant pdma_start from ESPState Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 17/25] esp: move PDMA length adjustments into esp_pdma_read()/esp_pdma_write() Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 18/25] esp: use ti_wptr/ti_rptr to manage the current FIFO position for PDMA Mark Cave-Ayland
2020-12-30 15:37 ` Mark Cave-Ayland [this message]
2020-12-30 15:37 ` [PATCH 20/25] esp: remove CMD pdma_origin Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 21/25] esp: rename get_cmd_cb() to esp_select() Mark Cave-Ayland
2021-01-01 16:57   ` Philippe Mathieu-Daudé
2020-12-30 15:37 ` [PATCH 22/25] esp: fix PDMA target selection Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 23/25] esp: use FIFO for PDMA transfers between initiator and device Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 24/25] esp: remove pdma_origin from ESPState Mark Cave-Ayland
2020-12-30 15:37 ` [PATCH 25/25] esp: add 4 byte PDMA read and write transfers Mark Cave-Ayland
2021-01-06 15:18 ` [PATCH 00/25] esp: consolidate PDMA transfer buffers Mark Cave-Ayland
2021-01-13 14:39 ` Paolo Bonzini
2021-01-13 19:29   ` Mark Cave-Ayland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201230153745.30241-20-mark.cave-ayland@ilande.co.uk \
    --to=mark.cave-ayland@ilande.co.uk \
    --cc=fam@euphon.net \
    --cc=laurent@vivier.eu \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).