diff mbox series

[v15,02/11] esp: move get_cmd() post-DMA code to get_cmd_cb()

Message ID 20191026164546.30020-3-laurent@vivier.eu (mailing list archive)
State New, archived
Headers show
Series hw/m68k: add Apple Machintosh Quadra 800 machine | expand

Commit Message

Laurent Vivier Oct. 26, 2019, 4:45 p.m. UTC
This will be needed to implement pseudo-DMA

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 hw/scsi/esp.c | 46 +++++++++++++++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 17 deletions(-)

Comments

Philippe Mathieu-Daudé Oct. 26, 2019, 5:21 p.m. UTC | #1
On 10/26/19 6:45 PM, Laurent Vivier wrote:
> This will be needed to implement pseudo-DMA
> 
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>

:)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>   hw/scsi/esp.c | 46 +++++++++++++++++++++++++++++-----------------
>   1 file changed, 29 insertions(+), 17 deletions(-)
> 
> diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
> index 09b28cba17..0230ede21d 100644
> --- a/hw/scsi/esp.c
> +++ b/hw/scsi/esp.c
> @@ -84,6 +84,34 @@ void esp_request_cancelled(SCSIRequest *req)
>       }
>   }
>   
> +static int get_cmd_cb(ESPState *s)
> +{
> +    int target;
> +
> +    target = s->wregs[ESP_WBUSID] & BUSID_DID;
> +
> +    s->ti_size = 0;
> +    s->ti_rptr = 0;
> +    s->ti_wptr = 0;
> +
> +    if (s->current_req) {
> +        /* Started a new command before the old one finished.  Cancel it.  */
> +        scsi_req_cancel(s->current_req);
> +        s->async_len = 0;
> +    }
> +
> +    s->current_dev = scsi_device_find(&s->bus, 0, target, 0);
> +    if (!s->current_dev) {
> +        /* No such drive */
> +        s->rregs[ESP_RSTAT] = 0;
> +        s->rregs[ESP_RINTR] = INTR_DC;
> +        s->rregs[ESP_RSEQ] = SEQ_0;
> +        esp_raise_irq(s);
> +        return -1;
> +    }
> +    return 0;
> +}
> +
>   static uint32_t get_cmd(ESPState *s, uint8_t *buf, uint8_t buflen)
>   {
>       uint32_t dmalen;
> @@ -108,23 +136,7 @@ static uint32_t get_cmd(ESPState *s, uint8_t *buf, uint8_t buflen)
>       }
>       trace_esp_get_cmd(dmalen, target);
>   
> -    s->ti_size = 0;
> -    s->ti_rptr = 0;
> -    s->ti_wptr = 0;
> -
> -    if (s->current_req) {
> -        /* Started a new command before the old one finished.  Cancel it.  */
> -        scsi_req_cancel(s->current_req);
> -        s->async_len = 0;
> -    }
> -
> -    s->current_dev = scsi_device_find(&s->bus, 0, target, 0);
> -    if (!s->current_dev) {
> -        // No such drive
> -        s->rregs[ESP_RSTAT] = 0;
> -        s->rregs[ESP_RINTR] = INTR_DC;
> -        s->rregs[ESP_RSEQ] = SEQ_0;
> -        esp_raise_irq(s);
> +    if (get_cmd_cb(s) < 0) {
>           return 0;
>       }
>       return dmalen;
>
Paolo Bonzini Oct. 27, 2019, 5:02 p.m. UTC | #2
On 26/10/19 18:45, Laurent Vivier wrote:
> This will be needed to implement pseudo-DMA
> 
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
>  hw/scsi/esp.c | 46 +++++++++++++++++++++++++++++-----------------
>  1 file changed, 29 insertions(+), 17 deletions(-)
> 
> diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
> index 09b28cba17..0230ede21d 100644
> --- a/hw/scsi/esp.c
> +++ b/hw/scsi/esp.c
> @@ -84,6 +84,34 @@ void esp_request_cancelled(SCSIRequest *req)
>      }
>  }
>  
> +static int get_cmd_cb(ESPState *s)
> +{
> +    int target;
> +
> +    target = s->wregs[ESP_WBUSID] & BUSID_DID;
> +
> +    s->ti_size = 0;
> +    s->ti_rptr = 0;
> +    s->ti_wptr = 0;
> +
> +    if (s->current_req) {
> +        /* Started a new command before the old one finished.  Cancel it.  */
> +        scsi_req_cancel(s->current_req);
> +        s->async_len = 0;
> +    }
> +
> +    s->current_dev = scsi_device_find(&s->bus, 0, target, 0);
> +    if (!s->current_dev) {
> +        /* No such drive */
> +        s->rregs[ESP_RSTAT] = 0;
> +        s->rregs[ESP_RINTR] = INTR_DC;
> +        s->rregs[ESP_RSEQ] = SEQ_0;
> +        esp_raise_irq(s);
> +        return -1;
> +    }
> +    return 0;
> +}
> +
>  static uint32_t get_cmd(ESPState *s, uint8_t *buf, uint8_t buflen)
>  {
>      uint32_t dmalen;
> @@ -108,23 +136,7 @@ static uint32_t get_cmd(ESPState *s, uint8_t *buf, uint8_t buflen)
>      }
>      trace_esp_get_cmd(dmalen, target);
>  
> -    s->ti_size = 0;
> -    s->ti_rptr = 0;
> -    s->ti_wptr = 0;
> -
> -    if (s->current_req) {
> -        /* Started a new command before the old one finished.  Cancel it.  */
> -        scsi_req_cancel(s->current_req);
> -        s->async_len = 0;
> -    }
> -
> -    s->current_dev = scsi_device_find(&s->bus, 0, target, 0);
> -    if (!s->current_dev) {
> -        // No such drive
> -        s->rregs[ESP_RSTAT] = 0;
> -        s->rregs[ESP_RINTR] = INTR_DC;
> -        s->rregs[ESP_RSEQ] = SEQ_0;
> -        esp_raise_irq(s);
> +    if (get_cmd_cb(s) < 0) {
>          return 0;
>      }
>      return dmalen;
> 

Acked-by: Paolo Bonzini <pbonzini@redhat.com>
diff mbox series

Patch

diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index 09b28cba17..0230ede21d 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -84,6 +84,34 @@  void esp_request_cancelled(SCSIRequest *req)
     }
 }
 
+static int get_cmd_cb(ESPState *s)
+{
+    int target;
+
+    target = s->wregs[ESP_WBUSID] & BUSID_DID;
+
+    s->ti_size = 0;
+    s->ti_rptr = 0;
+    s->ti_wptr = 0;
+
+    if (s->current_req) {
+        /* Started a new command before the old one finished.  Cancel it.  */
+        scsi_req_cancel(s->current_req);
+        s->async_len = 0;
+    }
+
+    s->current_dev = scsi_device_find(&s->bus, 0, target, 0);
+    if (!s->current_dev) {
+        /* No such drive */
+        s->rregs[ESP_RSTAT] = 0;
+        s->rregs[ESP_RINTR] = INTR_DC;
+        s->rregs[ESP_RSEQ] = SEQ_0;
+        esp_raise_irq(s);
+        return -1;
+    }
+    return 0;
+}
+
 static uint32_t get_cmd(ESPState *s, uint8_t *buf, uint8_t buflen)
 {
     uint32_t dmalen;
@@ -108,23 +136,7 @@  static uint32_t get_cmd(ESPState *s, uint8_t *buf, uint8_t buflen)
     }
     trace_esp_get_cmd(dmalen, target);
 
-    s->ti_size = 0;
-    s->ti_rptr = 0;
-    s->ti_wptr = 0;
-
-    if (s->current_req) {
-        /* Started a new command before the old one finished.  Cancel it.  */
-        scsi_req_cancel(s->current_req);
-        s->async_len = 0;
-    }
-
-    s->current_dev = scsi_device_find(&s->bus, 0, target, 0);
-    if (!s->current_dev) {
-        // No such drive
-        s->rregs[ESP_RSTAT] = 0;
-        s->rregs[ESP_RINTR] = INTR_DC;
-        s->rregs[ESP_RSEQ] = SEQ_0;
-        esp_raise_irq(s);
+    if (get_cmd_cb(s) < 0) {
         return 0;
     }
     return dmalen;