diff mbox series

[v2,25/42] esp: remove CMD pdma_origin

Message ID 20210209193018.31339-26-mark.cave-ayland@ilande.co.uk
State New
Headers show
Series esp: consolidate PDMA transfer buffers and other fixes | expand

Commit Message

Mark Cave-Ayland Feb. 9, 2021, 7:30 p.m. UTC
The cmdbuf is really just a copy of FIFO data (including extra message phase
bytes) so its pdma_origin is effectively TI. Fortunately we already know when
we are receiving a SCSI command since do_cmd == 1 which enables us to
distinguish between the two cases in esp_pdma_read()/esp_pdma_write().

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

Comments

Philippe Mathieu-Daudé Feb. 23, 2021, 6:34 p.m. UTC | #1
On 2/9/21 8:30 PM, Mark Cave-Ayland wrote:
> The cmdbuf is really just a copy of FIFO data (including extra message phase
> bytes) so its pdma_origin is effectively TI. Fortunately we already know when
> we are receiving a SCSI command since do_cmd == 1 which enables us to
> distinguish between the two cases in esp_pdma_read()/esp_pdma_write().
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/scsi/esp.c         | 22 ++++++++++++----------
>  include/hw/scsi/esp.h |  1 -
>  2 files changed, 12 insertions(+), 11 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Laurent Vivier March 2, 2021, 9:49 p.m. UTC | #2
Le 09/02/2021 à 20:30, Mark Cave-Ayland a écrit :
> The cmdbuf is really just a copy of FIFO data (including extra message phase
> bytes) so its pdma_origin is effectively TI. Fortunately we already know when
> we are receiving a SCSI command since do_cmd == 1 which enables us to
> distinguish between the two cases in esp_pdma_read()/esp_pdma_write().
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/scsi/esp.c         | 22 ++++++++++++----------
>  include/hw/scsi/esp.h |  1 -
>  2 files changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
> index bff330733f..921f79ae89 100644
> --- a/hw/scsi/esp.c
> +++ b/hw/scsi/esp.c
> @@ -143,10 +143,11 @@ static uint8_t esp_pdma_read(ESPState *s)
>  
>      switch (s->pdma_origin) {
>      case TI:
> -        val = s->ti_buf[s->ti_rptr++];
> -        break;
> -    case CMD:
> -        val = s->cmdbuf[s->cmdlen++];
> +        if (s->do_cmd) {
> +            val = s->cmdbuf[s->cmdlen++];
> +        } else {
> +            val = s->ti_buf[s->ti_rptr++];
> +        }
>          break;
>      case ASYNC:
>          val = s->async_buf[0];
> @@ -176,10 +177,11 @@ static void esp_pdma_write(ESPState *s, uint8_t val)
>  
>      switch (s->pdma_origin) {
>      case TI:
> -        s->ti_buf[s->ti_wptr++] = val;
> -        break;
> -    case CMD:
> -        s->cmdbuf[s->cmdlen++] = val;
> +        if (s->do_cmd) {
> +            s->cmdbuf[s->cmdlen++] = val;
> +        } else {
> +            s->ti_buf[s->ti_wptr++] = val;
> +        }
>          break;
>      case ASYNC:
>          s->async_buf[0] = val;
> @@ -240,7 +242,7 @@ static uint32_t get_cmd(ESPState *s)
>          if (s->dma_memory_read) {
>              s->dma_memory_read(s->dma_opaque, buf, dmalen);
>          } else {
> -            set_pdma(s, CMD);
> +            set_pdma(s, TI);
>              esp_raise_drq(s);
>              return 0;
>          }
> @@ -471,7 +473,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);
> +            set_pdma(s, TI);
>              s->pdma_cb = do_dma_pdma_cb;
>              esp_raise_drq(s);
>              return;
> diff --git a/include/hw/scsi/esp.h b/include/hw/scsi/esp.h
> index 1e84b7bfb0..a8d5bf8a63 100644
> --- a/include/hw/scsi/esp.h
> +++ b/include/hw/scsi/esp.h
> @@ -17,7 +17,6 @@ typedef struct ESPState ESPState;
>  
>  enum pdma_origin_id {
>      TI,
> -    CMD,
>      ASYNC,
>  };
>  
> 

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

Patch

diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index bff330733f..921f79ae89 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -143,10 +143,11 @@  static uint8_t esp_pdma_read(ESPState *s)
 
     switch (s->pdma_origin) {
     case TI:
-        val = s->ti_buf[s->ti_rptr++];
-        break;
-    case CMD:
-        val = s->cmdbuf[s->cmdlen++];
+        if (s->do_cmd) {
+            val = s->cmdbuf[s->cmdlen++];
+        } else {
+            val = s->ti_buf[s->ti_rptr++];
+        }
         break;
     case ASYNC:
         val = s->async_buf[0];
@@ -176,10 +177,11 @@  static void esp_pdma_write(ESPState *s, uint8_t val)
 
     switch (s->pdma_origin) {
     case TI:
-        s->ti_buf[s->ti_wptr++] = val;
-        break;
-    case CMD:
-        s->cmdbuf[s->cmdlen++] = val;
+        if (s->do_cmd) {
+            s->cmdbuf[s->cmdlen++] = val;
+        } else {
+            s->ti_buf[s->ti_wptr++] = val;
+        }
         break;
     case ASYNC:
         s->async_buf[0] = val;
@@ -240,7 +242,7 @@  static uint32_t get_cmd(ESPState *s)
         if (s->dma_memory_read) {
             s->dma_memory_read(s->dma_opaque, buf, dmalen);
         } else {
-            set_pdma(s, CMD);
+            set_pdma(s, TI);
             esp_raise_drq(s);
             return 0;
         }
@@ -471,7 +473,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);
+            set_pdma(s, TI);
             s->pdma_cb = do_dma_pdma_cb;
             esp_raise_drq(s);
             return;
diff --git a/include/hw/scsi/esp.h b/include/hw/scsi/esp.h
index 1e84b7bfb0..a8d5bf8a63 100644
--- a/include/hw/scsi/esp.h
+++ b/include/hw/scsi/esp.h
@@ -17,7 +17,6 @@  typedef struct ESPState ESPState;
 
 enum pdma_origin_id {
     TI,
-    CMD,
     ASYNC,
 };