[PATCH 06/16] ncr710, lsi: use same enums for command_complete

Paolo Bonzini posted 16 patches 5 days, 16 hours ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>, Richard Henderson <richard.henderson@linaro.org>, Helge Deller <deller@gmx.de>
[PATCH 06/16] ncr710, lsi: use same enums for command_complete
Posted by Paolo Bonzini 5 days, 16 hours ago
The ncr710 and lsi53c895a HBAs share some of the logic, also make
them use the same enum for the command_complete variable.  Change
the names for ncr710 to something that is more representative,
for example NCR710_CMD_DATA_READY might also indicate that the
device is ready to *receive* data, not just that it has data
ready to send.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/scsi/ncr53c710.h  |  4 ++--
 hw/scsi/lsi53c895a.c | 16 +++++++++++-----
 hw/scsi/ncr53c710.c  | 10 +++++-----
 3 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/hw/scsi/ncr53c710.h b/hw/scsi/ncr53c710.h
index 00b6a01577c..97f1bf5fe22 100644
--- a/hw/scsi/ncr53c710.h
+++ b/hw/scsi/ncr53c710.h
@@ -100,8 +100,8 @@ typedef enum {
 } NCR710WaitState;
 
 typedef enum {
-    NCR710_CMD_PENDING = 0,
-    NCR710_CMD_DATA_READY = 1,
+    NCR710_CMD_SENT = 0,
+    NCR710_CMD_READY = 1,
     NCR710_CMD_COMPLETE = 2
 } NCR710CommandState;
 
diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c
index 54123f77579..6b0c97d98e3 100644
--- a/hw/scsi/lsi53c895a.c
+++ b/hw/scsi/lsi53c895a.c
@@ -209,6 +209,12 @@ enum {
     LSI_WAIT_SCRIPTS, /* SCRIPTS stopped because of instruction count limit */
 };
 
+typedef enum {
+    LSI_CMD_SENT, /* command is running */
+    LSI_CMD_READY, /* one round of data transfer completed */
+    LSI_CMD_COMPLETE, /* command completed */
+} LSICommandState;
+
 enum {
     LSI_MSG_ACTION_COMMAND = 0,
     LSI_MSG_ACTION_DISCONNECT = 1,
@@ -238,7 +244,7 @@ struct LSIState {
     int current_lun;
     /* The tag is a combination of the device ID and the SCSI tag.  */
     uint32_t select_tag;
-    int command_complete;
+    LSICommandState command_complete;
     QTAILQ_HEAD(, lsi_request) queue;
     lsi_request *current;
 
@@ -815,7 +821,7 @@ static void lsi_command_complete(SCSIRequest *req, size_t resid)
     out = (s->sstat1 & PHASE_MASK) == PHASE_DO;
     trace_lsi_command_complete(req->status);
     s->status = req->status;
-    s->command_complete = 2;
+    s->command_complete = LSI_CMD_COMPLETE;
     if (s->waiting && s->dbc != 0) {
         /* Raise phase mismatch for short transfers.  */
         stop = lsi_bad_phase(s, out, PHASE_ST);
@@ -854,7 +860,7 @@ static void lsi_transfer_data(SCSIRequest *req, uint32_t len)
     /* host adapter (re)connected */
     trace_lsi_transfer_data(req->tag, len);
     s->current->dma_len = len;
-    s->command_complete = 1;
+    s->command_complete = LSI_CMD_READY;
     if (s->waiting) {
         if (s->waiting == LSI_WAIT_RESELECT || s->dbc == 0) {
             lsi_resume_script(s);
@@ -876,7 +882,7 @@ static void lsi_do_command(LSIState *s)
         s->dbc = 16;
     pci_dma_read(PCI_DEVICE(s), s->dnad, buf, s->dbc);
     s->sfbr = buf[0];
-    s->command_complete = 0;
+    s->command_complete = LSI_CMD_PENDING;
 
     id = (s->select_tag >> 8) & 0xf;
     dev = scsi_device_find(&s->bus, 0, id, s->current_lun);
@@ -900,7 +906,7 @@ static void lsi_do_command(LSIState *s)
         }
         scsi_req_continue(s->current->req);
     }
-    if (!s->command_complete) {
+    if (s->command_complete == LSI_CMD_PENDING) {
         if (n) {
             /* Command did not complete immediately so disconnect.  */
             lsi_add_msg_byte(s, 2); /* SAVE DATA POINTER */
diff --git a/hw/scsi/ncr53c710.c b/hw/scsi/ncr53c710.c
index 57967e7a84f..7113ce2d8a9 100644
--- a/hw/scsi/ncr53c710.c
+++ b/hw/scsi/ncr53c710.c
@@ -849,7 +849,7 @@ void ncr710_transfer_data(SCSIRequest *req, uint32_t len)
     }
 
     /* Host adapter (re)connected */
-    s->command_complete = NCR710_CMD_DATA_READY;
+    s->command_complete = NCR710_CMD_READY;
     if (!s->current) {
         return;
     }
@@ -924,7 +924,7 @@ static void ncr710_do_command(NCR710State *s)
     s->dbc -= bytes_read;
     s->sfbr = buf[0];
 
-    s->command_complete = NCR710_CMD_PENDING;
+    s->command_complete = NCR710_CMD_SENT;
     id = (s->select_tag >> 8) & 0xff;
     s->lcrc = id;
 
@@ -1279,7 +1279,7 @@ void ncr710_reselection_retry_callback(void *opaque)
     p->pending = 0;
 
     SCSIRequest *req = p->req;
-    s->command_complete = NCR710_CMD_PENDING;
+    s->command_complete = NCR710_CMD_SENT;
     p->dma_len = len;
 
     s->scntl1 |= NCR710_SCNTL1_CON;
@@ -1466,7 +1466,7 @@ again:
                 break;
             case 1: /* Disconnect */
 
-                if (s->command_complete != NCR710_CMD_PENDING) {
+                if (s->command_complete != NCR710_CMD_SENT) {
                     s->scntl1 &= ~NCR710_SCNTL1_CON;
                     s->istat &= ~NCR710_ISTAT_CON;
                     s->waiting = NCR710_WAIT_NONE;
@@ -1640,7 +1640,7 @@ again:
                                            "preserved for driver processing\n");
                             ncr710_script_dma_interrupt(s,
                                                         NCR710_DSTAT_SIR);
-                            s->command_complete = NCR710_CMD_PENDING;
+                            s->command_complete = NCR710_CMD_SENT;
                         } else {
                             ncr710_script_dma_interrupt(s, NCR710_DSTAT_SIR);
                         }
-- 
2.53.0
Re: [PATCH 06/16] ncr710, lsi: use same enums for command_complete
Posted by Philippe Mathieu-Daudé 5 days, 14 hours ago
On 27/3/26 22:25, Paolo Bonzini wrote:
> The ncr710 and lsi53c895a HBAs share some of the logic, also make
> them use the same enum for the command_complete variable.  Change
> the names for ncr710 to something that is more representative,
> for example NCR710_CMD_DATA_READY might also indicate that the
> device is ready to *receive* data, not just that it has data
> ready to send.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   hw/scsi/ncr53c710.h  |  4 ++--
>   hw/scsi/lsi53c895a.c | 16 +++++++++++-----
>   hw/scsi/ncr53c710.c  | 10 +++++-----
>   3 files changed, 18 insertions(+), 12 deletions(-)


> diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c
> index 54123f77579..6b0c97d98e3 100644
> --- a/hw/scsi/lsi53c895a.c
> +++ b/hw/scsi/lsi53c895a.c
> @@ -209,6 +209,12 @@ enum {
>       LSI_WAIT_SCRIPTS, /* SCRIPTS stopped because of instruction count limit */
>   };
>   
> +typedef enum {
> +    LSI_CMD_SENT, /* command is running */
> +    LSI_CMD_READY, /* one round of data transfer completed */
> +    LSI_CMD_COMPLETE, /* command completed */
> +} LSICommandState;
> +
>   enum {
>       LSI_MSG_ACTION_COMMAND = 0,
>       LSI_MSG_ACTION_DISCONNECT = 1,
> @@ -238,7 +244,7 @@ struct LSIState {
>       int current_lun;
>       /* The tag is a combination of the device ID and the SCSI tag.  */
>       uint32_t select_tag;
> -    int command_complete;
> +    LSICommandState command_complete;
>       QTAILQ_HEAD(, lsi_request) queue;
>       lsi_request *current;
>   
> @@ -815,7 +821,7 @@ static void lsi_command_complete(SCSIRequest *req, size_t resid)
>       out = (s->sstat1 & PHASE_MASK) == PHASE_DO;
>       trace_lsi_command_complete(req->status);
>       s->status = req->status;
> -    s->command_complete = 2;
> +    s->command_complete = LSI_CMD_COMPLETE;
>       if (s->waiting && s->dbc != 0) {
>           /* Raise phase mismatch for short transfers.  */
>           stop = lsi_bad_phase(s, out, PHASE_ST);
> @@ -854,7 +860,7 @@ static void lsi_transfer_data(SCSIRequest *req, uint32_t len)
>       /* host adapter (re)connected */
>       trace_lsi_transfer_data(req->tag, len);
>       s->current->dma_len = len;
> -    s->command_complete = 1;
> +    s->command_complete = LSI_CMD_READY;
>       if (s->waiting) {
>           if (s->waiting == LSI_WAIT_RESELECT || s->dbc == 0) {
>               lsi_resume_script(s);
> @@ -876,7 +882,7 @@ static void lsi_do_command(LSIState *s)
>           s->dbc = 16;
>       pci_dma_read(PCI_DEVICE(s), s->dnad, buf, s->dbc);
>       s->sfbr = buf[0];
> -    s->command_complete = 0;
> +    s->command_complete = LSI_CMD_PENDING;

Where is LSI_CMD_PENDING defined?

../../hw/scsi/lsi53c895a.c:885:27: error: use of undeclared identifier 
'LSI_CMD_PENDING'
   885 |     s->command_complete = LSI_CMD_PENDING;
       |                           ^
../../hw/scsi/lsi53c895a.c:909:32: error: use of undeclared identifier 
'LSI_CMD_PENDING'
   909 |     if (s->command_complete == LSI_CMD_PENDING) {
       |                                ^

>   
>       id = (s->select_tag >> 8) & 0xf;
>       dev = scsi_device_find(&s->bus, 0, id, s->current_lun);
> @@ -900,7 +906,7 @@ static void lsi_do_command(LSIState *s)
>           }
>           scsi_req_continue(s->current->req);
>       }
> -    if (!s->command_complete) {
> +    if (s->command_complete == LSI_CMD_PENDING) {
>           if (n) {
>               /* Command did not complete immediately so disconnect.  */
>               lsi_add_msg_byte(s, 2); /* SAVE DATA POINTER */