Skip to contentSkip to conversation

lsi: use ldn_le_p()/stn_le_p()

PATCH Superseded Sven Schnelle 3 participants 15 messages Mar 4, 2019 – Mar 5, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 lsi: use ldn_le_p()/stn_le_p()

---
 hw/scsi/lsi53c895a.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)
hw/scsi/lsi53c895a.c +4 -20
index 25c6926039..6d280f8b77 100644
@@ -289,8 +289,7 @@ typedef struct {
     uint8_t sbr;
     uint32_t adder;
 
-    /* Script ram is stored as 32-bit words in host byteorder.  */
-    uint32_t script_ram[2048];
+    uint8_t script_ram[8192];
 } LSIState;
 
 #define TYPE_LSI53C810  "lsi53c810"
@@ -2077,29 +2076,14 @@ static void lsi_ram_write(void *opaque, hwaddr addr,
                           uint64_t val, unsigned size)
 {
     LSIState *s = opaque;
-    uint32_t newval;
-    uint32_t mask;
-    int shift;
-
-    newval = s->script_ram[addr >> 2];
-    shift = (addr & 3) * 8;
-    mask = ((uint64_t)1 << (size * 8)) - 1;
-    newval &= ~(mask << shift);
-    newval |= val << shift;
-    s->script_ram[addr >> 2] = newval;
+    stn_le_p(s->script_ram + addr, size, val);
 }
 
 static uint64_t lsi_ram_read(void *opaque, hwaddr addr,
                              unsigned size)
 {
     LSIState *s = opaque;
-    uint32_t val;
-    uint32_t mask;
-
-    val = s->script_ram[addr >> 2];
-    mask = ((uint64_t)1 << (size * 8)) - 1;
-    val >>= (addr & 3) * 8;
-    return val & mask;
+    return ldn_le_p(s->script_ram + addr, size);
 }
 
 static const MemoryRegionOps lsi_ram_ops = {
@@ -2242,7 +2226,7 @@ static const VMStateDescription vmstate_lsi_scsi = {
         VMSTATE_BUFFER_UNSAFE(scratch, LSIState, 0, 18 * sizeof(uint32_t)),
         VMSTATE_UINT8(sbr, LSIState),
 
-        VMSTATE_BUFFER_UNSAFE(script_ram, LSIState, 0, 2048 * sizeof(uint32_t)),
+        VMSTATE_BUFFER_UNSAFE(script_ram, LSIState, 0, 8192),
         VMSTATE_END_OF_LIST()
     }
 };
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/5 lsi: use enum type for s->waiting

This makes the code easier to read - no functional change.

---
 hw/scsi/lsi53c895a.c | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)
hw/scsi/lsi53c895a.c +23 -19
index 6d280f8b77..fb9c6db4b2 100644
@@ -194,6 +194,13 @@ typedef struct lsi_request {
     QTAILQ_ENTRY(lsi_request) next;
 } lsi_request;
 
+enum {
+    LSI_NOWAIT,
+    LSI_WAIT_RESELECT, /* Wait Reselect instruction has been issued */
+    LSI_DMA_SCRIPTS, /* processing DMA from lsi_execute_script */
+    LSI_DMA_IN_PROGRESS, /* DMA operation is in progress */
+};
+
 typedef struct {
     /*< private >*/
     PCIDevice parent_obj;
@@ -212,10 +219,6 @@ typedef struct {
     int msg_action;
     int msg_len;
     uint8_t msg[LSI_MAX_MSGIN_LEN];
-    /* 0 if SCRIPTS are running or stopped.
-     * 1 if a Wait Reselect instruction has been issued.
-     * 2 if processing DMA from lsi_execute_script.
-     * 3 if a DMA operation is in progress.  */
     int waiting;
     SCSIBus bus;
     int current_lun;
@@ -322,7 +325,7 @@ static void lsi_soft_reset(LSIState *s)
 
     s->msg_action = 0;
     s->msg_len = 0;
-    s->waiting = 0;
+    s->waiting = LSI_NOWAIT;
     s->dsa = 0;
     s->dnad = 0;
     s->dbc = 0;
@@ -564,10 +567,10 @@ static void lsi_bad_phase(LSIState *s, int out, int new_phase)
 static void lsi_resume_script(LSIState *s)
 {
     if (s->waiting != 2) {
-        s->waiting = 0;
+        s->waiting = LSI_NOWAIT;
         lsi_execute_script(s);
     } else {
-        s->waiting = 0;
+        s->waiting = LSI_NOWAIT;
     }
 }
 
@@ -744,7 +747,7 @@ static int lsi_queue_req(LSIState *s, SCSIRequest *req, uint32_t len)
        Since no interrupt stacking is implemented in the emulation, it
        is also required that there are no pending interrupts waiting
        for service from the device driver. */
-    if (s->waiting == 1 ||
+    if (s->waiting == LSI_WAIT_RESELECT ||
         (lsi_irq_on_rsl(s) && !(s->scntl1 & LSI_SCNTL1_CON) &&
          !(s->istat0 & (LSI_ISTAT0_SIP | LSI_ISTAT0_DIP)))) {
         /* Reselect device.  */
@@ -789,7 +792,7 @@ static void lsi_transfer_data(SCSIRequest *req, uint32_t len)
     int out;
 
     assert(req->hba_private);
-    if (s->waiting == 1 || req->hba_private != s->current ||
+    if (s->waiting == LSI_WAIT_RESELECT || req->hba_private != s->current ||
         (lsi_irq_on_rsl(s) && !(s->scntl1 & LSI_SCNTL1_CON))) {
         if (lsi_queue_req(s, req, len)) {
             return;
@@ -803,7 +806,7 @@ static void lsi_transfer_data(SCSIRequest *req, uint32_t len)
     s->current->dma_len = len;
     s->command_complete = 1;
     if (s->waiting) {
-        if (s->waiting == 1 || s->dbc == 0) {
+        if (s->waiting == LSI_WAIT_RESELECT || s->dbc == 0) {
             lsi_resume_script(s);
         } else {
             lsi_do_dma(s, out);
@@ -1093,7 +1096,7 @@ static void lsi_wait_reselect(LSIState *s)
         lsi_reselect(s, p);
     }
     if (s->current == NULL) {
-        s->waiting = 1;
+        s->waiting = LSI_WAIT_RESELECT;
     }
 }
 
@@ -1202,16 +1205,16 @@ again:
         s->dnad64 = addr_high;
         switch (s->sstat1 & 0x7) {
         case PHASE_DO:
-            s->waiting = 2;
+            s->waiting = LSI_DMA_SCRIPTS;
             lsi_do_dma(s, 1);
             if (s->waiting)
-                s->waiting = 3;
+                s->waiting = LSI_DMA_IN_PROGRESS;
             break;
         case PHASE_DI:
-            s->waiting = 2;
+            s->waiting = LSI_DMA_SCRIPTS;
             lsi_do_dma(s, 0);
             if (s->waiting)
-                s->waiting = 3;
+                s->waiting = LSI_DMA_IN_PROGRESS;
             break;
         case PHASE_CMD:
             lsi_do_command(s);
@@ -1278,6 +1281,7 @@ again:
                 }
                 s->sbcl |= LSI_SBCL_BSY;
                 lsi_set_phase(s, PHASE_MO);
+                s->waiting = LSI_NOWAIT;
                 break;
             case 1: /* Disconnect */
                 trace_lsi_execute_script_io_disconnect();
@@ -1542,7 +1546,7 @@ again:
             }
         }
     }
-    if (insn_processed > 10000 && !s->waiting) {
+    if (insn_processed > 10000 && s->waiting == LSI_NOWAIT) {
         /* Some windows drivers make the device spin waiting for a memory
            location to change.  If we have been executed a lot of code then
            assume this is the case and force an unexpected device disconnect.
@@ -1554,7 +1558,7 @@ again:
         }
         lsi_script_scsi_interrupt(s, LSI_SIST0_UDC, 0);
         lsi_disconnect(s);
-    } else if (s->istat1 & LSI_ISTAT1_SRUN && !s->waiting) {
+    } else if (s->istat1 & LSI_ISTAT1_SRUN && s->waiting == LSI_NOWAIT) {
         if (s->dcntl & LSI_DCNTL_SSM) {
             lsi_script_dma_interrupt(s, LSI_DSTAT_SSI);
         } else {
@@ -1885,9 +1889,9 @@ static void lsi_reg_writeb(LSIState *s, int offset, uint8_t val)
             s->istat0 &= ~LSI_ISTAT0_INTF;
             lsi_update_irq(s);
         }
-        if (s->waiting == 1 && val & LSI_ISTAT0_SIGP) {
+        if (s->waiting == LSI_WAIT_RESELECT && val & LSI_ISTAT0_SIGP) {
             trace_lsi_awoken();
-            s->waiting = 0;
+            s->waiting = LSI_NOWAIT;
             s->dsp = s->dnad;
             lsi_execute_script(s);
         }
Signature · 1 line
2.20.1
#2 lore raw

Re: [Qemu-devel] [PATCH 2/5] lsi: use enum type for s->waiting

Quoted 12 lines · Sven Schnelle

This makes the code easier to read - no functional change.

---
 hw/scsi/lsi53c895a.c | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)
hw/scsi/lsi53c895a.c +0 -0
index 6d280f8b77..fb9c6db4b2 100644

hw/scsi/lsi53c895a.c typedef struct lsi_request { · line 198

Quoted 5 lines
hw/scsi/lsi53c895a.c +2 -0
@@ -194,6 +194,13 @@ typedef struct lsi_request {
     QTAILQ_ENTRY(lsi_request) next;
 } lsi_request;
 
+enum {
+    LSI_NOWAIT,

You forgot the comment for NOWAIT.

Quoted 9 lines
hw/scsi/lsi53c895a.c +5 -0
+    LSI_WAIT_RESELECT, /* Wait Reselect instruction has been issued */
+    LSI_DMA_SCRIPTS, /* processing DMA from lsi_execute_script */
+    LSI_DMA_IN_PROGRESS, /* DMA operation is in progress */
+};
+
 typedef struct {
     /*< private >*/
     PCIDevice parent_obj;

hw/scsi/lsi53c895a.c typedef struct { · line 222

Quoted 8 lines
hw/scsi/lsi53c895a.c +0 -4
@@ -212,10 +219,6 @@ typedef struct {
     int msg_action;
     int msg_len;
     uint8_t msg[LSI_MAX_MSGIN_LEN];
-    /* 0 if SCRIPTS are running or stopped.
-     * 1 if a Wait Reselect instruction has been issued.
-     * 2 if processing DMA from lsi_execute_script.
-     * 3 if a DMA operation is in progress.  */
     int waiting;

When a field is not used by migration, you can declare it as enum:

enum {
LSI_NOWAIT = 0, /* SCRIPTS are running or stopped */ LSI_WAIT_RESELECT = 1, /* Wait Reselect instruction has been
issued */
LSI_DMA_SCRIPTS = 2, /* processing DMA from lsi_execute_script */ LSI_DMA_IN_PROGRESS = 3, /* DMA operation is in progress */
} waiting;

This gives hints to the compiler about values to check.

Quoted 120 lines
hw/scsi/lsi53c895a.c +16 -15
     SCSIBus bus;
     int current_lun;
@@ -322,7 +325,7 @@ static void lsi_soft_reset(LSIState *s)
 
     s->msg_action = 0;
     s->msg_len = 0;
-    s->waiting = 0;
+    s->waiting = LSI_NOWAIT;
     s->dsa = 0;
     s->dnad = 0;
     s->dbc = 0;
@@ -564,10 +567,10 @@ static void lsi_bad_phase(LSIState *s, int out, int new_phase)
 static void lsi_resume_script(LSIState *s)
 {
     if (s->waiting != 2) {
-        s->waiting = 0;
+        s->waiting = LSI_NOWAIT;
         lsi_execute_script(s);
     } else {
-        s->waiting = 0;
+        s->waiting = LSI_NOWAIT;
     }
 }
 
@@ -744,7 +747,7 @@ static int lsi_queue_req(LSIState *s, SCSIRequest *req, uint32_t len)
        Since no interrupt stacking is implemented in the emulation, it
        is also required that there are no pending interrupts waiting
        for service from the device driver. */
-    if (s->waiting == 1 ||
+    if (s->waiting == LSI_WAIT_RESELECT ||
         (lsi_irq_on_rsl(s) && !(s->scntl1 & LSI_SCNTL1_CON) &&
          !(s->istat0 & (LSI_ISTAT0_SIP | LSI_ISTAT0_DIP)))) {
         /* Reselect device.  */
@@ -789,7 +792,7 @@ static void lsi_transfer_data(SCSIRequest *req, uint32_t len)
     int out;
 
     assert(req->hba_private);
-    if (s->waiting == 1 || req->hba_private != s->current ||
+    if (s->waiting == LSI_WAIT_RESELECT || req->hba_private != s->current ||
         (lsi_irq_on_rsl(s) && !(s->scntl1 & LSI_SCNTL1_CON))) {
         if (lsi_queue_req(s, req, len)) {
             return;
@@ -803,7 +806,7 @@ static void lsi_transfer_data(SCSIRequest *req, uint32_t len)
     s->current->dma_len = len;
     s->command_complete = 1;
     if (s->waiting) {
-        if (s->waiting == 1 || s->dbc == 0) {
+        if (s->waiting == LSI_WAIT_RESELECT || s->dbc == 0) {
             lsi_resume_script(s);
         } else {
             lsi_do_dma(s, out);
@@ -1093,7 +1096,7 @@ static void lsi_wait_reselect(LSIState *s)
         lsi_reselect(s, p);
     }
     if (s->current == NULL) {
-        s->waiting = 1;
+        s->waiting = LSI_WAIT_RESELECT;
     }
 }
 
@@ -1202,16 +1205,16 @@ again:
         s->dnad64 = addr_high;
         switch (s->sstat1 & 0x7) {
         case PHASE_DO:
-            s->waiting = 2;
+            s->waiting = LSI_DMA_SCRIPTS;
             lsi_do_dma(s, 1);
             if (s->waiting)
-                s->waiting = 3;
+                s->waiting = LSI_DMA_IN_PROGRESS;
             break;
         case PHASE_DI:
-            s->waiting = 2;
+            s->waiting = LSI_DMA_SCRIPTS;
             lsi_do_dma(s, 0);
             if (s->waiting)
-                s->waiting = 3;
+                s->waiting = LSI_DMA_IN_PROGRESS;
             break;
         case PHASE_CMD:
             lsi_do_command(s);
@@ -1278,6 +1281,7 @@ again:
                 }
                 s->sbcl |= LSI_SBCL_BSY;
                 lsi_set_phase(s, PHASE_MO);
+                s->waiting = LSI_NOWAIT;
                 break;
             case 1: /* Disconnect */
                 trace_lsi_execute_script_io_disconnect();
@@ -1542,7 +1546,7 @@ again:
             }
         }
     }
-    if (insn_processed > 10000 && !s->waiting) {
+    if (insn_processed > 10000 && s->waiting == LSI_NOWAIT) {
         /* Some windows drivers make the device spin waiting for a memory
            location to change.  If we have been executed a lot of code then
            assume this is the case and force an unexpected device disconnect.
@@ -1554,7 +1558,7 @@ again:
         }
         lsi_script_scsi_interrupt(s, LSI_SIST0_UDC, 0);
         lsi_disconnect(s);
-    } else if (s->istat1 & LSI_ISTAT1_SRUN && !s->waiting) {
+    } else if (s->istat1 & LSI_ISTAT1_SRUN && s->waiting == LSI_NOWAIT) {
         if (s->dcntl & LSI_DCNTL_SSM) {
             lsi_script_dma_interrupt(s, LSI_DSTAT_SSI);
         } else {
@@ -1885,9 +1889,9 @@ static void lsi_reg_writeb(LSIState *s, int offset, uint8_t val)
             s->istat0 &= ~LSI_ISTAT0_INTF;
             lsi_update_irq(s);
         }
-        if (s->waiting == 1 && val & LSI_ISTAT0_SIGP) {
+        if (s->waiting == LSI_WAIT_RESELECT && val & LSI_ISTAT0_SIGP) {
             trace_lsi_awoken();
-            s->waiting = 0;
+            s->waiting = LSI_NOWAIT;
             s->dsp = s->dnad;
             lsi_execute_script(s);
         }
#3 lore raw

Re: [Qemu-devel] [PATCH 2/5] lsi: use enum type for s->waiting

Hi Philippe,

Quoted 5 lines · Philippe Mathieu-Daudé

hw/scsi/lsi53c895a.c typedef struct lsi_request { · line 198

Quoted 3 lines
hw/scsi/lsi53c895a.c +2 -0
+enum {
+    LSI_NOWAIT,

You forgot the comment for NOWAIT.

I thought LSI_NOWAIT is self-explaining, but will add that.

Quoted 12 lines
Quoted 1 line
     int waiting;

When a field is not used by migration, you can declare it as enum:

enum {
LSI_NOWAIT = 0, /* SCRIPTS are running or stopped */ LSI_WAIT_RESELECT = 1, /* Wait Reselect instruction has been
issued */
LSI_DMA_SCRIPTS = 2, /* processing DMA from lsi_execute_script */ LSI_DMA_IN_PROGRESS = 3, /* DMA operation is in progress */
} waiting;

Quoted 1 line

This gives hints to the compiler about values to check.

But it is used by migration, so this doesn't apply here? I had a typedef enum before, but this doesn't compile.

Otherwise thanks for reviewing.

Regards
Sven

#4 lore raw

Re: [Qemu-devel] [PATCH 2/5] lsi: use enum type for s->waiting

Quoted 23 lines · Sven Schnelle

Hi Philippe,

Quoted 5 lines · Philippe Mathieu-Daudé

hw/scsi/lsi53c895a.c typedef struct lsi_request { · line 198

Quoted 3 lines
hw/scsi/lsi53c895a.c +2 -0
+enum {
+    LSI_NOWAIT,

You forgot the comment for NOWAIT.

I thought LSI_NOWAIT is self-explaining, but will add that.

Quoted 12 lines
Quoted 1 line
     int waiting;

When a field is not used by migration, you can declare it as enum:

enum {
LSI_NOWAIT = 0, /* SCRIPTS are running or stopped */ LSI_WAIT_RESELECT = 1, /* Wait Reselect instruction has been
issued */
LSI_DMA_SCRIPTS = 2, /* processing DMA from lsi_execute_script */ LSI_DMA_IN_PROGRESS = 3, /* DMA operation is in progress */
} waiting;

Quoted 4 lines
Quoted 1 line

This gives hints to the compiler about values to check.

But it is used by migration, so this doesn't apply here? I had a typedef enum before, but this doesn't compile.

Oh you are right, I didn't check... So with the updated comment:

Quoted 7 lines

Otherwise thanks for reviewing.

Regards
Sven

#5 lore raw

PATCH 3/5 lsi: use enum type for s->msg_action

In reply to Sven Schnelle

This makes the code easier to read - no functional change.

---
 hw/scsi/lsi53c895a.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)
hw/scsi/lsi53c895a.c +16 -11
index fb9c6db4b2..d1eb2cf074 100644
@@ -201,6 +201,13 @@ enum {
     LSI_DMA_IN_PROGRESS, /* DMA operation is in progress */
 };
 
+enum {
+    LSI_MSG_ACTION_COMMAND,
+    LSI_MSG_ACTION_DISCONNECT,
+    LSI_MSG_ACTION_DOUT,
+    LSI_MSG_ACTION_DIN,
+};
+
 typedef struct {
     /*< private >*/
     PCIDevice parent_obj;
@@ -214,8 +221,6 @@ typedef struct {
 
     int carry; /* ??? Should this be an a visible register somewhere?  */
     int status;
-    /* Action to take at the end of a MSG IN phase.
-       0 = COMMAND, 1 = disconnect, 2 = DATA OUT, 3 = DATA IN.  */
     int msg_action;
     int msg_len;
     uint8_t msg[LSI_MAX_MSGIN_LEN];
@@ -323,7 +328,7 @@ static void lsi_soft_reset(LSIState *s)
     trace_lsi_reset();
     s->carry = 0;
 
-    s->msg_action = 0;
+    s->msg_action = LSI_MSG_ACTION_COMMAND;
     s->msg_len = 0;
     s->waiting = LSI_NOWAIT;
     s->dsa = 0;
@@ -686,7 +691,7 @@ static void lsi_reselect(LSIState *s, lsi_request *p)
     trace_lsi_reselect(id);
     s->scntl1 |= LSI_SCNTL1_CON;
     lsi_set_phase(s, PHASE_MI);
-    s->msg_action = p->out ? 2 : 3;
+    s->msg_action = p->out ? LSI_MSG_ACTION_DOUT : LSI_MSG_ACTION_DIN;
     s->current->dma_len = p->pending;
     lsi_add_msg_byte(s, 0x80);
     if (s->current->tag & LSI_TAG_VALID) {
@@ -857,7 +862,7 @@ static void lsi_do_command(LSIState *s)
             lsi_add_msg_byte(s, 4); /* DISCONNECT */
             /* wait data */
             lsi_set_phase(s, PHASE_MI);
-            s->msg_action = 1;
+            s->msg_action = LSI_MSG_ACTION_DISCONNECT;
             lsi_queue_command(s);
         } else {
             /* wait command complete */
@@ -878,7 +883,7 @@ static void lsi_do_status(LSIState *s)
     s->sfbr = status;
     pci_dma_write(PCI_DEVICE(s), s->dnad, &status, 1);
     lsi_set_phase(s, PHASE_MI);
-    s->msg_action = 1;
+    s->msg_action = LSI_MSG_ACTION_DISCONNECT;
     lsi_add_msg_byte(s, 0); /* COMMAND COMPLETE */
 }
 
@@ -901,16 +906,16 @@ static void lsi_do_msgin(LSIState *s)
         /* ??? Check if ATN (not yet implemented) is asserted and maybe
            switch to PHASE_MO.  */
         switch (s->msg_action) {
-        case 0:
+        case LSI_MSG_ACTION_COMMAND:
             lsi_set_phase(s, PHASE_CMD);
             break;
-        case 1:
+        case LSI_MSG_ACTION_DISCONNECT:
             lsi_disconnect(s);
             break;
-        case 2:
+        case LSI_MSG_ACTION_DOUT:
             lsi_set_phase(s, PHASE_DO);
             break;
-        case 3:
+        case LSI_MSG_ACTION_DIN:
             lsi_set_phase(s, PHASE_DI);
             break;
         default:
@@ -1062,7 +1067,7 @@ bad:
     qemu_log_mask(LOG_UNIMP, "Unimplemented message 0x%02x\n", msg);
     lsi_set_phase(s, PHASE_MI);
     lsi_add_msg_byte(s, 7); /* MESSAGE REJECT */
-    s->msg_action = 0;
+    s->msg_action = LSI_MSG_ACTION_COMMAND;
 }
 
 #define LSI_BUF_SIZE 4096
Signature · 1 line
2.20.1
Reviewed-by on v1 3/5
#6 lore raw

Re: [Qemu-devel] [PATCH 3/5] lsi: use enum type for s->msg_action

Quoted 12 lines · Sven Schnelle

This makes the code easier to read - no functional change.

---
 hw/scsi/lsi53c895a.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)
hw/scsi/lsi53c895a.c +0 -0
index fb9c6db4b2..d1eb2cf074 100644

hw/scsi/lsi53c895a.c enum { · line 204

Quoted 4 lines
hw/scsi/lsi53c895a.c +1 -0
@@ -201,6 +201,13 @@ enum {
     LSI_DMA_IN_PROGRESS, /* DMA operation is in progress */
 };
 
+enum {

Since someone unfamiliar with the device could add:

LSI_MSG_ACTION_DEBUG,

hw/scsi/lsi53c895a.c enum { · line 208

Quoted 4 lines
hw/scsi/lsi53c895a.c +4 -0
+    LSI_MSG_ACTION_COMMAND,
+    LSI_MSG_ACTION_DISCONNECT,
+    LSI_MSG_ACTION_DOUT,
+    LSI_MSG_ACTION_DIN,

... it is safer to assign values when enum are not expected to change:

LSI_MSG_ACTION_COMMAND = 0,
LSI_MSG_ACTION_DISCONNECT = 1,
LSI_MSG_ACTION_DOUT = 2,
LSI_MSG_ACTION_DIN = 3,

With that change:

Quoted 81 lines
hw/scsi/lsi53c895a.c +11 -11
+};
+
 typedef struct {
     /*< private >*/
     PCIDevice parent_obj;
@@ -214,8 +221,6 @@ typedef struct {
 
     int carry; /* ??? Should this be an a visible register somewhere?  */
     int status;
-    /* Action to take at the end of a MSG IN phase.
-       0 = COMMAND, 1 = disconnect, 2 = DATA OUT, 3 = DATA IN.  */
     int msg_action;
     int msg_len;
     uint8_t msg[LSI_MAX_MSGIN_LEN];
@@ -323,7 +328,7 @@ static void lsi_soft_reset(LSIState *s)
     trace_lsi_reset();
     s->carry = 0;
 
-    s->msg_action = 0;
+    s->msg_action = LSI_MSG_ACTION_COMMAND;
     s->msg_len = 0;
     s->waiting = LSI_NOWAIT;
     s->dsa = 0;
@@ -686,7 +691,7 @@ static void lsi_reselect(LSIState *s, lsi_request *p)
     trace_lsi_reselect(id);
     s->scntl1 |= LSI_SCNTL1_CON;
     lsi_set_phase(s, PHASE_MI);
-    s->msg_action = p->out ? 2 : 3;
+    s->msg_action = p->out ? LSI_MSG_ACTION_DOUT : LSI_MSG_ACTION_DIN;
     s->current->dma_len = p->pending;
     lsi_add_msg_byte(s, 0x80);
     if (s->current->tag & LSI_TAG_VALID) {
@@ -857,7 +862,7 @@ static void lsi_do_command(LSIState *s)
             lsi_add_msg_byte(s, 4); /* DISCONNECT */
             /* wait data */
             lsi_set_phase(s, PHASE_MI);
-            s->msg_action = 1;
+            s->msg_action = LSI_MSG_ACTION_DISCONNECT;
             lsi_queue_command(s);
         } else {
             /* wait command complete */
@@ -878,7 +883,7 @@ static void lsi_do_status(LSIState *s)
     s->sfbr = status;
     pci_dma_write(PCI_DEVICE(s), s->dnad, &status, 1);
     lsi_set_phase(s, PHASE_MI);
-    s->msg_action = 1;
+    s->msg_action = LSI_MSG_ACTION_DISCONNECT;
     lsi_add_msg_byte(s, 0); /* COMMAND COMPLETE */
 }
 
@@ -901,16 +906,16 @@ static void lsi_do_msgin(LSIState *s)
         /* ??? Check if ATN (not yet implemented) is asserted and maybe
            switch to PHASE_MO.  */
         switch (s->msg_action) {
-        case 0:
+        case LSI_MSG_ACTION_COMMAND:
             lsi_set_phase(s, PHASE_CMD);
             break;
-        case 1:
+        case LSI_MSG_ACTION_DISCONNECT:
             lsi_disconnect(s);
             break;
-        case 2:
+        case LSI_MSG_ACTION_DOUT:
             lsi_set_phase(s, PHASE_DO);
             break;
-        case 3:
+        case LSI_MSG_ACTION_DIN:
             lsi_set_phase(s, PHASE_DI);
             break;
         default:
@@ -1062,7 +1067,7 @@ bad:
     qemu_log_mask(LOG_UNIMP, "Unimplemented message 0x%02x\n", msg);
     lsi_set_phase(s, PHASE_MI);
     lsi_add_msg_byte(s, 7); /* MESSAGE REJECT */
-    s->msg_action = 0;
+    s->msg_action = LSI_MSG_ACTION_COMMAND;
 }
 
 #define LSI_BUF_SIZE 4096
#7 lore raw

Re: [Qemu-devel] [PATCH 3/5] lsi: use enum type for s->msg_action

Quoted 43 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Sven Schnelle

This makes the code easier to read - no functional change.

---
 hw/scsi/lsi53c895a.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)
hw/scsi/lsi53c895a.c +0 -0
index fb9c6db4b2..d1eb2cf074 100644

hw/scsi/lsi53c895a.c enum { · line 204

Quoted 4 lines
hw/scsi/lsi53c895a.c +1 -0
@@ -201,6 +201,13 @@ enum {
     LSI_DMA_IN_PROGRESS, /* DMA operation is in progress */
 };
 
+enum {

Since someone unfamiliar with the device could add:

LSI_MSG_ACTION_DEBUG,

hw/scsi/lsi53c895a.c enum { · line 208

Quoted 4 lines
hw/scsi/lsi53c895a.c +4 -0
+    LSI_MSG_ACTION_COMMAND,
+    LSI_MSG_ACTION_DISCONNECT,
+    LSI_MSG_ACTION_DOUT,
+    LSI_MSG_ACTION_DIN,

... it is safer to assign values when enum are not expected to change:

LSI_MSG_ACTION_COMMAND = 0,
LSI_MSG_ACTION_DISCONNECT = 1,
LSI_MSG_ACTION_DOUT = 2,
LSI_MSG_ACTION_DIN = 3,

With that change:

Quoted 7 lines
hw/scsi/lsi53c895a.c +2 -0
+};
+
 typedef struct {
     /*< private >*/
     PCIDevice parent_obj;
@@ -214,8 +221,6 @@ typedef struct {
 
Quoted 5 lines

hw/scsi/lsi53c895a.c typedef struct { · line 224

Quoted 5 lines
hw/scsi/lsi53c895a.c +0 -2
     int carry; /* ??? Should this be an a visible register somewhere?  */
     int status;
-    /* Action to take at the end of a MSG IN phase.
-       0 = COMMAND, 1 = disconnect, 2 = DATA OUT, 3 = DATA IN.  */
     int msg_action;

I'd also declare 'enum msg_action' here (same comments as patch 2 of this series).
Regardless the Reviewed-by tag stands.

Quoted 69 lines
Quoted 69 lines
hw/scsi/lsi53c895a.c +9 -9
     int msg_len;
     uint8_t msg[LSI_MAX_MSGIN_LEN];
@@ -323,7 +328,7 @@ static void lsi_soft_reset(LSIState *s)
     trace_lsi_reset();
     s->carry = 0;
 
-    s->msg_action = 0;
+    s->msg_action = LSI_MSG_ACTION_COMMAND;
     s->msg_len = 0;
     s->waiting = LSI_NOWAIT;
     s->dsa = 0;
@@ -686,7 +691,7 @@ static void lsi_reselect(LSIState *s, lsi_request *p)
     trace_lsi_reselect(id);
     s->scntl1 |= LSI_SCNTL1_CON;
     lsi_set_phase(s, PHASE_MI);
-    s->msg_action = p->out ? 2 : 3;
+    s->msg_action = p->out ? LSI_MSG_ACTION_DOUT : LSI_MSG_ACTION_DIN;
     s->current->dma_len = p->pending;
     lsi_add_msg_byte(s, 0x80);
     if (s->current->tag & LSI_TAG_VALID) {
@@ -857,7 +862,7 @@ static void lsi_do_command(LSIState *s)
             lsi_add_msg_byte(s, 4); /* DISCONNECT */
             /* wait data */
             lsi_set_phase(s, PHASE_MI);
-            s->msg_action = 1;
+            s->msg_action = LSI_MSG_ACTION_DISCONNECT;
             lsi_queue_command(s);
         } else {
             /* wait command complete */
@@ -878,7 +883,7 @@ static void lsi_do_status(LSIState *s)
     s->sfbr = status;
     pci_dma_write(PCI_DEVICE(s), s->dnad, &status, 1);
     lsi_set_phase(s, PHASE_MI);
-    s->msg_action = 1;
+    s->msg_action = LSI_MSG_ACTION_DISCONNECT;
     lsi_add_msg_byte(s, 0); /* COMMAND COMPLETE */
 }
 
@@ -901,16 +906,16 @@ static void lsi_do_msgin(LSIState *s)
         /* ??? Check if ATN (not yet implemented) is asserted and maybe
            switch to PHASE_MO.  */
         switch (s->msg_action) {
-        case 0:
+        case LSI_MSG_ACTION_COMMAND:
             lsi_set_phase(s, PHASE_CMD);
             break;
-        case 1:
+        case LSI_MSG_ACTION_DISCONNECT:
             lsi_disconnect(s);
             break;
-        case 2:
+        case LSI_MSG_ACTION_DOUT:
             lsi_set_phase(s, PHASE_DO);
             break;
-        case 3:
+        case LSI_MSG_ACTION_DIN:
             lsi_set_phase(s, PHASE_DI);
             break;
         default:
@@ -1062,7 +1067,7 @@ bad:
     qemu_log_mask(LOG_UNIMP, "Unimplemented message 0x%02x\n", msg);
     lsi_set_phase(s, PHASE_MI);
     lsi_add_msg_byte(s, 7); /* MESSAGE REJECT */
-    s->msg_action = 0;
+    s->msg_action = LSI_MSG_ACTION_COMMAND;
 }
 
 #define LSI_BUF_SIZE 4096
#8 lore raw

PATCH 4/5 lsi: use SCSI phase names instead of numbers in trace

In reply to Sven Schnelle
---
 hw/scsi/lsi53c895a.c | 24 ++++++++++++++++++------
 hw/scsi/trace-events |  4 ++--
 2 files changed, 20 insertions(+), 8 deletions(-)
hw/scsi/lsi53c895a.c +18 -6
index d1eb2cf074..f635d56e0f 100644
@@ -184,6 +184,17 @@ static const char *names[] = {
 /* Flag set if this is a tagged command.  */
 #define LSI_TAG_VALID     (1 << 16)
 
+static const char *scsi_phases[] = {
+    "DOUT",
+    "DIN",
+    "CMD",
+    "STATUS",
+    "RSVIN",
+    "RSVOUT",
+    "MSGOUT",
+    "MSGIN"
+};
+
 typedef struct lsi_request {
     SCSIRequest *req;
     uint32_t tag;
@@ -1201,8 +1212,9 @@ again:
             s->ia = s->dsp - 12;
         }
         if ((s->sstat1 & PHASE_MASK) != ((insn >> 24) & 7)) {
-            trace_lsi_execute_script_blockmove_badphase(s->sstat1 & PHASE_MASK,
-                                                        (insn >> 24) & 7);
+            trace_lsi_execute_script_blockmove_badphase(
+                    scsi_phases[s->sstat1 & PHASE_MASK],
+                    scsi_phases[(insn >> 24) & 7]);
             lsi_script_scsi_interrupt(s, LSI_SIST0_MA, 0);
             break;
         }
@@ -1234,8 +1246,8 @@ again:
             lsi_do_msgin(s);
             break;
         default:
-            qemu_log_mask(LOG_UNIMP, "lsi_scsi: Unimplemented phase %d\n",
-                          s->sstat1 & PHASE_MASK);
+            qemu_log_mask(LOG_UNIMP, "lsi_scsi: Unimplemented phase %s\n",
+                          scsi_phases[s->sstat1 & PHASE_MASK]);
         }
         s->dfifo = s->dbc & 0xff;
         s->ctest5 = (s->ctest5 & 0xfc) | ((s->dbc >> 8) & 3);
@@ -1462,9 +1474,9 @@ again:
             }
             if (cond == jmp && (insn & (1 << 17))) {
                 trace_lsi_execute_script_tc_compp(
-                        (s->sstat1 & PHASE_MASK),
+                        scsi_phases[(s->sstat1 & PHASE_MASK)],
                         jmp ? '=' : '!',
-                        ((insn >> 24) & 7));
+                        scsi_phases[((insn >> 24) & 7)]);
                 cond = (s->sstat1 & PHASE_MASK) == ((insn >> 24) & 7);
             }
             if (cond == jmp && (insn & (1 << 18))) {
hw/scsi/trace-events +2 -2
index 29aaa752d1..34feb6f42d 100644
@@ -268,7 +268,7 @@ lsi_memcpy(uint32_t dest, uint32_t src, int count) "memcpy dest 0x%"PRIx32" src
 lsi_wait_reselect(void) "Wait Reselect"
 lsi_execute_script(uint32_t dsp, uint32_t insn, uint32_t addr) "SCRIPTS dsp=0x%"PRIx32" opcode 0x%"PRIx32" arg 0x%"PRIx32
 lsi_execute_script_blockmove_delayed(void) "Delayed select timeout"
-lsi_execute_script_blockmove_badphase(uint8_t phase, uint8_t expected) "Wrong phase got %d expected %d"
+lsi_execute_script_blockmove_badphase(const char *phase, const char *expected) "Wrong phase got %s expected %s"
 lsi_execute_script_io_alreadyreselected(void) "Already reselected, jumping to alternative address"
 lsi_execute_script_io_selected(uint8_t id, const char *atn) "Selected target %d%s"
 lsi_execute_script_io_disconnect(void) "Wait Disconnect"
@@ -278,7 +278,7 @@ lsi_execute_script_io_opcode(const char *opcode, int reg, const char *opname, ui
 lsi_execute_script_tc_nop(void) "NOP"
 lsi_execute_script_tc_delayedselect_timeout(void) "Delayed select timeout"
 lsi_execute_script_tc_compc(int result) "Compare carry %d"
-lsi_execute_script_tc_compp(uint8_t phase, int op, uint8_t insn_phase) "Compare phase %d %c= %d"
+lsi_execute_script_tc_compp(const char *phase, int op, const char *insn_phase) "Compare phase %s %c= %s"
 lsi_execute_script_tc_compd(uint32_t sfbr, uint8_t mask, int op, int result) "Compare data 0x%"PRIx32" & 0x%x %c= 0x%x"
 lsi_execute_script_tc_jump(uint32_t addr) "Jump to 0x%"PRIx32
 lsi_execute_script_tc_call(uint32_t addr) "Call 0x%"PRIx32
Signature · 1 line
2.20.1
#9 lore raw

Re: [Qemu-devel] [PATCH 4/5] lsi: use SCSI phase names instead of numbers in trace

Hi Sven,

Quoted 14 lines · Sven Schnelle
---
 hw/scsi/lsi53c895a.c | 24 ++++++++++++++++++------
 hw/scsi/trace-events |  4 ++--
 2 files changed, 20 insertions(+), 8 deletions(-)
hw/scsi/lsi53c895a.c +0 -0
index d1eb2cf074..f635d56e0f 100644
@@ -184,6 +184,17 @@ static const char *names[] = {
 /* Flag set if this is a tagged command.  */
 #define LSI_TAG_VALID     (1 << 16)
 

hw/scsi/lsi53c895a.c static const char *names[] = { · line 196

Quoted 10 lines
hw/scsi/lsi53c895a.c +10 -0
+static const char *scsi_phases[] = {
+    "DOUT",
+    "DIN",
+    "CMD",
+    "STATUS",
+    "RSVIN",
+    "RSVOUT",
+    "MSGOUT",
+    "MSGIN"
+};

Some developper might use your code but forget to use value & PHASE_MASK, trying on small values, then another user uses bigger values and this array will return unexpected result.

static const char *scsi_phase_name(int phase)
{

  static const char *scsi_phases[8] = {
    [PHASE_DO] = "DOUT",
    [PHASE_DI] = "DIN",
    [PHASE_CMD] = "CMD",
    [PHASE_ST] = "STATUS",
    [PHASE_MO] = "MSGOUT",
    [PHASE_MI] = "MSGIN",

};
phase &= PHASE_MASK;
return scsi_phases[phase] ? scsi_phases[phase] : "RESERVED";
}

You can also keep your RSVIN/RSVOUT:

static const char *scsi_phase_name(int phase)
{

  static const char *scsi_phases[8] = {
    "DOUT",
    "DIN",
    "CMD",
    "STATUS",
    "RSVIN",
    "RSVOUT",
    "MSGOUT",
    "MSGIN"

};
return scsi_phases[phase & PHASE_MASK];
}

In both cases, calls are easier to read:

            trace_lsi_execute_script_blockmove_badphase(
                    scsi_phase_name(s->sstat1),
                    scsi_phase_name(insn >> 24));
Quoted 28 lines
hw/scsi/lsi53c895a.c +6 -4
+
 typedef struct lsi_request {
     SCSIRequest *req;
     uint32_t tag;
@@ -1201,8 +1212,9 @@ again:
             s->ia = s->dsp - 12;
         }
         if ((s->sstat1 & PHASE_MASK) != ((insn >> 24) & 7)) {
-            trace_lsi_execute_script_blockmove_badphase(s->sstat1 & PHASE_MASK,
-                                                        (insn >> 24) & 7);
+            trace_lsi_execute_script_blockmove_badphase(
+                    scsi_phases[s->sstat1 & PHASE_MASK],
+                    scsi_phases[(insn >> 24) & 7]);
             lsi_script_scsi_interrupt(s, LSI_SIST0_MA, 0);
             break;
         }
@@ -1234,8 +1246,8 @@ again:
             lsi_do_msgin(s);
             break;
         default:
-            qemu_log_mask(LOG_UNIMP, "lsi_scsi: Unimplemented phase %d\n",
-                          s->sstat1 & PHASE_MASK);
+            qemu_log_mask(LOG_UNIMP, "lsi_scsi: Unimplemented phase %s\n",
+                          scsi_phases[s->sstat1 & PHASE_MASK]);
         }
         s->dfifo = s->dbc & 0xff;
         s->ctest5 = (s->ctest5 & 0xfc) | ((s->dbc >> 8) & 3);

hw/scsi/lsi53c895a.c again: · line 1477

Quoted 5 lines
hw/scsi/lsi53c895a.c +1 -1
@@ -1462,9 +1474,9 @@ again:
             }
             if (cond == jmp && (insn & (1 << 17))) {
                 trace_lsi_execute_script_tc_compp(
-                        (s->sstat1 & PHASE_MASK),
+                        scsi_phases[(s->sstat1 & PHASE_MASK)],

No need for parenthesis here,

hw/scsi/lsi53c895a.c again: · line 1479

Quoted 3 lines
hw/scsi/lsi53c895a.c +1 -1
                         jmp ? '=' : '!',
-                        ((insn >> 24) & 7));
+                        scsi_phases[((insn >> 24) & 7)]);

Ditto.

Quoted 17 lines
hw/scsi/lsi53c895a.c +0 -0
                 cond = (s->sstat1 & PHASE_MASK) == ((insn >> 24) & 7);
             }
             if (cond == jmp && (insn & (1 << 18))) {
hw/scsi/trace-events +1 -1
index 29aaa752d1..34feb6f42d 100644
@@ -268,7 +268,7 @@ lsi_memcpy(uint32_t dest, uint32_t src, int count) "memcpy dest 0x%"PRIx32" src
 lsi_wait_reselect(void) "Wait Reselect"
 lsi_execute_script(uint32_t dsp, uint32_t insn, uint32_t addr) "SCRIPTS dsp=0x%"PRIx32" opcode 0x%"PRIx32" arg 0x%"PRIx32
 lsi_execute_script_blockmove_delayed(void) "Delayed select timeout"
-lsi_execute_script_blockmove_badphase(uint8_t phase, uint8_t expected) "Wrong phase got %d expected %d"
+lsi_execute_script_blockmove_badphase(const char *phase, const char *expected) "Wrong phase got %s expected %s"
 lsi_execute_script_io_alreadyreselected(void) "Already reselected, jumping to alternative address"
 lsi_execute_script_io_selected(uint8_t id, const char *atn) "Selected target %d%s"
 lsi_execute_script_io_disconnect(void) "Wait Disconnect"

hw/scsi/trace-events lsi_execute_script_io_opcode(const char *opcode, int reg, const char *opname, ui · line 281

Quoted 5 lines
hw/scsi/trace-events +1 -1
@@ -278,7 +278,7 @@ lsi_execute_script_io_opcode(const char *opcode, int reg, const char *opname, ui
 lsi_execute_script_tc_nop(void) "NOP"
 lsi_execute_script_tc_delayedselect_timeout(void) "Delayed select timeout"
 lsi_execute_script_tc_compc(int result) "Compare carry %d"
-lsi_execute_script_tc_compp(uint8_t phase, int op, uint8_t insn_phase) "Compare phase %d %c= %d"
+lsi_execute_script_tc_compp(const char *phase, int op, const char *insn_phase) "Compare phase %s %c= %s"

Since you change this line, can you fix 'int op' -> 'char op'? Or as a previous cleanup patch... There are other '%c' misused.

hw/scsi/trace-events lsi_execute_script_io_opcode(const char *opcode, int reg, const char *opname, ui · line 284

Quoted 4 lines
hw/scsi/trace-events +0 -0
 lsi_execute_script_tc_compd(uint32_t sfbr, uint8_t mask, int op, int result) "Compare data 0x%"PRIx32" & 0x%x %c= 0x%x"
 lsi_execute_script_tc_jump(uint32_t addr) "Jump to 0x%"PRIx32
 lsi_execute_script_tc_call(uint32_t addr) "Call 0x%"PRIx32

Regards,

Phil.

#10 lore raw

PATCH 5/5 lsi: return dfifo value

In reply to Sven Schnelle

Code was assigning DFIFO, but didn't return the value to users.

---
 hw/scsi/lsi53c895a.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/lsi53c895a.c +1 -1
index f635d56e0f..a0e0c57b9b 100644
@@ -1683,7 +1683,7 @@ static uint8_t lsi_reg_readb(LSIState *s, int offset)
         break;
     CASE_GET_REG32(temp, 0x1c)
     case 0x20: /* DFIFO */
-        ret = 0;
+        ret = s->dfifo;
         break;
     case 0x21: /* CTEST4 */
         ret = s->ctest4;
Signature · 1 line
2.20.1
#11 lore raw
In reply to Sven Schnelle
Quoted 1 line · Sven Schnelle

The commit header says "what" (good), but the commit body says nothing at all (generally, it should say "why"). If you give your reviewers a reason why it is good to use the new functions, it makes it easier to apply your patch.

Also, don't forget to send a 0/5 cover letter when sending a patch series; you can have git do this for you with 'git config format.coverletter auto'. https://wiki.qemu.org/Contribute/SubmitAPatch has more hints for improved patch handling.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#12 lore raw

Hi Eric,

Quoted 8 lines · Eric Blake
Quoted 1 line · Sven Schnelle

The commit header says "what" (good), but the commit body says nothing at all (generally, it should say "why"). If you give your reviewers a reason why it is good to use the new functions, it makes it easier to apply your patch.

Quoted 4 lines

Also, don't forget to send a 0/5 cover letter when sending a patch series; you can have git do this for you with 'git config format.coverletter auto'.
https://wiki.qemu.org/Contribute/SubmitAPatch has more hints for improved patch handling.

Thanks, will keep this in mind, sorry. Should i resend the series?

Regards
Sven

#13 lore raw
Quoted 11 lines · Sven Schnelle

Hi Eric,

Quoted 8 lines · Eric Blake
Quoted 1 line · Sven Schnelle

The commit header says "what" (good), but the commit body says nothing at all (generally, it should say "why"). If you give your reviewers a reason why it is good to use the new functions, it makes it easier to apply your patch.

Quoted 6 lines
Quoted 4 lines

Also, don't forget to send a 0/5 cover letter when sending a patch series; you can have git do this for you with 'git config format.coverletter auto'.
https://wiki.qemu.org/Contribute/SubmitAPatch has more hints for improved patch handling.

Thanks, will keep this in mind, sorry. Should i resend the series?

Up to you, but if it were me, I'd probably wait a day or two for any other review comments to address those at the same time, or for a definitive answer from the particular maintainer that will be including your patches.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v1 1/5
#14 lore raw
In reply to Sven Schnelle
Quoted 10 lines · Sven Schnelle
---
 hw/scsi/lsi53c895a.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)
hw/scsi/lsi53c895a.c +0 -0
index 25c6926039..6d280f8b77 100644

hw/scsi/lsi53c895a.c typedef struct { · line 292

Quoted 6 lines
hw/scsi/lsi53c895a.c +1 -2
@@ -289,8 +289,7 @@ typedef struct {
     uint8_t sbr;
     uint32_t adder;
 
-    /* Script ram is stored as 32-bit words in host byteorder.  */
-    uint32_t script_ram[2048];
+    uint8_t script_ram[8192];

I'm tempted to use here:

       uint8_t script_ram[2048 * sizeof(uint32_t)];
Quoted 17 lines
hw/scsi/lsi53c895a.c +0 -10
 } LSIState;
 
 #define TYPE_LSI53C810  "lsi53c810"
@@ -2077,29 +2076,14 @@ static void lsi_ram_write(void *opaque, hwaddr addr,
                           uint64_t val, unsigned size)
 {
     LSIState *s = opaque;
-    uint32_t newval;
-    uint32_t mask;
-    int shift;
-
-    newval = s->script_ram[addr >> 2];
-    shift = (addr & 3) * 8;
-    mask = ((uint64_t)1 << (size * 8)) - 1;
-    newval &= ~(mask << shift);
-    newval |= val << shift;
-    s->script_ram[addr >> 2] = newval;

hw/scsi/lsi53c895a.c static void lsi_ram_write(void *opaque, hwaddr addr, · line 2098

Quoted 10 lines
hw/scsi/lsi53c895a.c +1 -3
+    stn_le_p(s->script_ram + addr, size, val);
 }
 
 static uint64_t lsi_ram_read(void *opaque, hwaddr addr,
                              unsigned size)
 {
     LSIState *s = opaque;
-    uint32_t val;
-    uint32_t mask;
-
Quoted 18 lines
hw/scsi/lsi53c895a.c +2 -5
-    val = s->script_ram[addr >> 2];
-    mask = ((uint64_t)1 << (size * 8)) - 1;
-    val >>= (addr & 3) * 8;
-    return val & mask;
+    return ldn_le_p(s->script_ram + addr, size);
 }
 
 static const MemoryRegionOps lsi_ram_ops = {
@@ -2242,7 +2226,7 @@ static const VMStateDescription vmstate_lsi_scsi = {
         VMSTATE_BUFFER_UNSAFE(scratch, LSIState, 0, 18 * sizeof(uint32_t)),
         VMSTATE_UINT8(sbr, LSIState),
 
-        VMSTATE_BUFFER_UNSAFE(script_ram, LSIState, 0, 2048 * sizeof(uint32_t)),
+        VMSTATE_BUFFER_UNSAFE(script_ram, LSIState, 0, 8192),
         VMSTATE_END_OF_LIST()
     }
 };