diff mbox series

[v2,22/42] esp: move PDMA length adjustments into esp_pdma_read()/esp_pdma_write()

Message ID 20210209193018.31339-23-mark.cave-ayland@ilande.co.uk (mailing list archive)
State New, archived
Headers show
Series esp: consolidate PDMA transfer buffers and other fixes | expand

Commit Message

Mark Cave-Ayland Feb. 9, 2021, 7:29 p.m. UTC
Here the updates to async_len and ti_size are moved into the corresponding
esp_pdma_read()/esp_pdma_write() function to eliminate the reference to
pdma_cur in do_dma_pdma_cb().

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/scsi/esp.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

Comments

Laurent Vivier March 2, 2021, 9:44 p.m. UTC | #1
Le 09/02/2021 à 20:29, Mark Cave-Ayland a écrit :
> Here the updates to async_len and ti_size are moved into the corresponding
> esp_pdma_read()/esp_pdma_write() function to eliminate the reference to
> pdma_cur in do_dma_pdma_cb().
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/scsi/esp.c | 24 ++++++++++++++----------
>  1 file changed, 14 insertions(+), 10 deletions(-)
> 
> diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
> index 91f65a5d9b..691a2f4bdc 100644
> --- a/hw/scsi/esp.c
> +++ b/hw/scsi/esp.c
> @@ -153,12 +153,18 @@ static uint8_t esp_pdma_read(ESPState *s)
>          s->pdma_cur++;
>          break;
>      case ASYNC:
> -        val = s->async_buf[s->pdma_cur++];
> +        val = s->async_buf[0];
> +        if (s->async_len > 0) {
> +            s->async_len--;
> +            s->async_buf++;
> +        }
> +        s->pdma_cur++;
>          break;
>      default:
>          g_assert_not_reached();
>      }
>  
> +    s->ti_size--;
>      s->pdma_len--;
>      dmalen--;
>      esp_set_tc(s, dmalen);
> @@ -183,12 +189,18 @@ static void esp_pdma_write(ESPState *s, uint8_t val)
>          s->pdma_cur++;
>          break;
>      case ASYNC:
> -        s->async_buf[s->pdma_cur++] = val;
> +        s->async_buf[0] = val;
> +        if (s->async_len > 0) {
> +            s->async_len--;
> +            s->async_buf++;
> +        }
> +        s->pdma_cur++;
>          break;
>      default:
>          g_assert_not_reached();
>      }
>  
> +    s->ti_size++;
>      s->pdma_len--;
>      dmalen--;
>      esp_set_tc(s, dmalen);
> @@ -427,7 +439,6 @@ static void esp_dma_done(ESPState *s)
>  static void do_dma_pdma_cb(ESPState *s)
>  {
>      int to_device = ((s->rregs[ESP_RSTAT] & 7) == STAT_DO);
> -    int len = s->pdma_cur;
>  
>      if (s->do_cmd) {
>          s->ti_size = 0;
> @@ -436,13 +447,6 @@ static void do_dma_pdma_cb(ESPState *s)
>          do_cmd(s);
>          return;
>      }
> -    s->async_buf += len;
> -    s->async_len -= len;
> -    if (to_device) {
> -        s->ti_size += len;
> -    } else {
> -        s->ti_size -= len;
> -    }
>      if (s->async_len == 0) {
>          scsi_req_continue(s->current_req);
>          /*
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>
diff mbox series

Patch

diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index 91f65a5d9b..691a2f4bdc 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -153,12 +153,18 @@  static uint8_t esp_pdma_read(ESPState *s)
         s->pdma_cur++;
         break;
     case ASYNC:
-        val = s->async_buf[s->pdma_cur++];
+        val = s->async_buf[0];
+        if (s->async_len > 0) {
+            s->async_len--;
+            s->async_buf++;
+        }
+        s->pdma_cur++;
         break;
     default:
         g_assert_not_reached();
     }
 
+    s->ti_size--;
     s->pdma_len--;
     dmalen--;
     esp_set_tc(s, dmalen);
@@ -183,12 +189,18 @@  static void esp_pdma_write(ESPState *s, uint8_t val)
         s->pdma_cur++;
         break;
     case ASYNC:
-        s->async_buf[s->pdma_cur++] = val;
+        s->async_buf[0] = val;
+        if (s->async_len > 0) {
+            s->async_len--;
+            s->async_buf++;
+        }
+        s->pdma_cur++;
         break;
     default:
         g_assert_not_reached();
     }
 
+    s->ti_size++;
     s->pdma_len--;
     dmalen--;
     esp_set_tc(s, dmalen);
@@ -427,7 +439,6 @@  static void esp_dma_done(ESPState *s)
 static void do_dma_pdma_cb(ESPState *s)
 {
     int to_device = ((s->rregs[ESP_RSTAT] & 7) == STAT_DO);
-    int len = s->pdma_cur;
 
     if (s->do_cmd) {
         s->ti_size = 0;
@@ -436,13 +447,6 @@  static void do_dma_pdma_cb(ESPState *s)
         do_cmd(s);
         return;
     }
-    s->async_buf += len;
-    s->async_len -= len;
-    if (to_device) {
-        s->ti_size += len;
-    } else {
-        s->ti_size -= len;
-    }
     if (s->async_len == 0) {
         scsi_req_continue(s->current_req);
         /*