Skip to contentSkip to conversation

nc53c710 rewrite

RFC In review Philippe Mathieu-Daudé 4 participants 23 messages Nov 20 – Nov 21

lore
Share & tools
lore
#0 lore raw

v4 cover nc53c710 rewrite

Fourth attempt to replace the existing 53c710 driver by a new driver based on the code of the lsi53c895a.c :)

Used LLM to decompose v3 as logical / atomic changes when possible (didn't work well with the rewrite patch).

Fixes extracted first so could be merged for v11.2 (patches 1 to 5). The rest is the rewrite, so up to the maintainers (Helge, Mark) and is probably OK as hobbyist-only code.

Since v3:
- header split, Suggested-by tag (Zoltan)
- I couldn't figure the "hw/misc/lasi.c" change so dropped the comment about it.
- Dropped "move to COMMAND on CLEAR ACK after MESSAGE REJECT"
- Split rewrite patch as separated commits:
- base engine
- asynchronous completions
- synchronous drain
- HP-UX MESSAGE REJECT quirk
- reentrancy guard and reset-time request cancel

hw/scsi/ncr53c710.c is derived from hw/scsi/lsi53c895a.c which is LGPL, the rewrite is now declared GPL-2.0-or-later. hw/scsi/lsi_scsi.h, which is moved verbatim from lsi53c895a.c, keeps the original terms: its header says "This code is licensed under the LGPL." with SPDX-License-Identifier: LGPL-2.1-or-later.

Series reviewed against the NCR 53C710 data manual but totally untested (I don't have guest code to run), thus compile-checked only. I haven't tested whether the series is bisectable.

Keith Monahan (9):
hw/scsi/scsi-disk: Add quirk_mode_page_no_flexible_disk, use it on the

    715

hw/scsi: Move shared LSI/NCR definitions to lsi_scsi.h hw/scsi/ncr53c710: Rewrite the 53C710 SCRIPTS engine hw/scsi/ncr53c710: Deliver completions from bottom halves hw/scsi/ncr53c710: Drain asynchronous transfers in the register write hw/scsi/ncr53c710: Append SAVE DATA POINTERS after MESSAGE REJECT for
HP-UX
hw/scsi/ncr53c710: Guard SCRIPTS reentrancy and cancel requests on
soft reset
hw/scsi/lasi_ncr710: Map the full LASI SCSI module page hw/scsi/ncr53c710: Bump the migration version

Philippe Mathieu-Daudé (5):
hw/scsi/ncr53c710: Cancel the in-flight request on soft reset hw/scsi/ncr53c710: Do not load SBCL from DBC after a SCRIPTS phase
move
hw/scsi/lasi_ncr710: Limit max_target and max_lun to 7 hw/scsi/ncr53c710: Keep DCNTL.EA and DMODE.FC1 across an ISTAT.RST
reset
hw/scsi/ncr53c710: Document the SIGP latch deviation

 MAINTAINERS            |    1 +
 hw/scsi/lasi_ncr710.h  |   28 +-
 hw/scsi/lsi_scsi.h     |  104 ++
 hw/scsi/ncr53c710.h    |  279 ++--
 include/hw/scsi/scsi.h |    1 +
 hw/hppa/machine.c      |   10 +
 hw/scsi/lasi_ncr710.c  |  135 +-
 hw/scsi/lsi53c895a.c   |   79 +-
 hw/scsi/ncr53c710.c    | 2981 +++++++++++++++-------------------------
 hw/scsi/scsi-disk.c    |   13 +
 hw/scsi/trace-events   |   43 +-
 11 files changed, 1451 insertions(+), 2223 deletions(-)
 create mode 100644 hw/scsi/lsi_scsi.h
Signature · 1 line
2.55.0
#1 lore raw

RFC v4 1/14 hw/scsi/ncr53c710: Cancel the in-flight request on soft reset

ncr710_soft_reset() drops s->current and clears the request's hba_private without telling the SCSI layer. The request stays queued on the device and, once it completes or asks for data, the HBA callbacks find a NULL hba_private (ncr710_transfer_data() asserts on it).

Cancel the request first. scsi_req_cancel() invokes ncr710_request_cancelled(), which releases the NCR710Request and the HBA's reference on the request; ncr710_clear_pending_irq() then finds s->current already NULL and has nothing left to do. If the request is not enqueued, scsi_req_cancel() does nothing and the previous behaviour is kept.

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
 hw/scsi/ncr53c710.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/scsi/ncr53c710.c +4 -0
index 57967e7a84f0..10daa66e840d 100644
@@ -364,6 +364,10 @@ void ncr710_soft_reset(NCR710State *s)
     s->sidl = 0;
     s->sfbr = 0;
     qemu_set_irq(s->irq, 0);
+    if (s->current && s->current->req) {
+        /* Drops hba_private via ncr710_request_cancelled() */
+        scsi_req_cancel(s->current->req);
+    }
     ncr710_clear_pending_irq(s);
     ncr710_scsi_fifo_init(&s->scsi_fifo);
 }
Signature · 1 line
2.55.0
#2 lore raw

RFC v4 2/14 hw/scsi/ncr53c710: Do not load SBCL from DBC after a SCRIPTS phase move

In reply to Philippe Mathieu-Daudé

After a SCRIPTS Block Move, ncr710_execute_script() copies DBC, the transfer byte count, into SBCL. SBCL (SCSI Bus Control Lines) mirrors the state of the SCSI bus control signals, it is not a byte counter, so this overwrites it with unrelated data. The preceding line already updates CTEST5 from the DBC bits that the chip exposes there.

Remove the assignment. The effect on guests is inferred from the register definition; it has not been reproduced with a failing guest.

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
 hw/scsi/ncr53c710.c | 1 -
 1 file changed, 1 deletion(-)
hw/scsi/ncr53c710.c +0 -1
index 10daa66e840d..9ea2c47744e7 100644
@@ -1400,7 +1400,6 @@ again:
             BADF("Unimplemented phase %d\n", s->sstat2 & PHASE_MASK);
         }
         s->ctest5 = (s->ctest5 & 0xfc) | ((s->dbc >> 8) & 3);
-        s->sbcl = s->dbc;
         break;
 
     case 1: /* IO or Read/Write instruction.  */
Signature · 1 line
2.55.0
#3 lore raw

RFC v4 3/14 hw/scsi/scsi-disk: Add quirk_mode_page_no_flexible_disk, use it on the 715

In reply to Philippe Mathieu-Daudé

From: Keith Monahan <[email protected]>

scsi-disk answers MODE SENSE for page 05h (flexible disk geometry) for every disk. Per the commit author, real SCSI hard disks of that era reject this page with CHECK CONDITION, ILLEGAL REQUEST, INVALID FIELD IN CDB, as only floppy drives implement it. This has not been verified against real hardware or a datasheet here.

Per the commit author, HP-UX 9 on the HP 715 probes page 05h on the open root disk and, when the page is returned, treats the disk as a floppy and leaves it out of the ioscan listing, so SAM shows no hard disk. This guest behaviour has not been reproduced here.

Add the quirk_mode_page_no_flexible_disk property, which makes page 05h an invalid field in the CDB, and enable it for scsi-hd on the HP 715 machine through its compat properties. The property is also defined for scsi-cd, like the other mode page quirks, as both device types share mode_sense_page() and the same quirks bitmap; the 715 does not enable it there.

The array name hw_compat_715 suggested a versioned machine compat table, which it is not; call it hp_715_scsi_quirks.

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
 include/hw/scsi/scsi.h |  1 +
 hw/hppa/machine.c      | 10 ++++++++++
 hw/scsi/scsi-disk.c    | 13 +++++++++++++
 3 files changed, 24 insertions(+)
include/hw/scsi/scsi.h +1 -0
index a2f6f0be7fce..0efa62554d50 100644
@@ -264,5 +264,6 @@ bool scsi_generic_pr_state_cleanup(SCSIDevice *s, Error **errp);
 #define SCSI_DISK_QUIRK_MODE_PAGE_VENDOR_SPECIFIC_APPLE    2
 #define SCSI_DISK_QUIRK_MODE_PAGE_TRUNCATED                3
 #define SCSI_DISK_QUIRK_MODE_PAGE_SET_BLOCK_SIZE           4
+#define SCSI_DISK_QUIRK_MODE_PAGE_NO_FLEXIBLE_DISK         5
 
 #endif
hw/hppa/machine.c +10 -0
index 8a3f673daf75..2c9114995aad 100644
@@ -1024,6 +1024,14 @@ static void HP_A400_machine_init_class_init(ObjectClass *oc, const void *data)
     mc->default_ram_size = 1024 * MiB;
 }
 
+/*
+ * HP-UX 9 ioscan sends MODE SENSE page 5 to the open root disk and leaves
+ * the disk out of its listing if the page is returned.
+ */
+static GlobalProperty hp_715_scsi_quirks[] = {
+    { "scsi-hd", "quirk_mode_page_no_flexible_disk", "on" },
+};
+
 static void HP_715_machine_init_class_init(ObjectClass *oc, const void *data)
 {
     static const char * const valid_cpu_types[] = {
@@ -1045,6 +1053,8 @@ static void HP_715_machine_init_class_init(ObjectClass *oc, const void *data)
     mc->max_cpus = MIN_CONST(HPPA_MAX_CPUS, 8);
     mc->default_ram_size = 256 * MiB;
     mc->default_nic = TYPE_LASI_82596;
+    compat_props_add(mc->compat_props, hp_715_scsi_quirks,
+                     G_N_ELEMENTS(hp_715_scsi_quirks));
 }
 
 
hw/scsi/scsi-disk.c +13 -0
index a2df3a4ec464..ce43ddf6c062 100644
@@ -1156,6 +1156,15 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
         return -1;
     }
 
+    /*
+     * The flexible disk page is only implemented by floppy drives.  Some
+     * guests (HP-UX 9 ioscan) take a disk that returns it for a floppy.
+     */
+    if (page == MODE_PAGE_FLEXIBLE_DISK_GEOMETRY &&
+        (s->quirks & (1 << SCSI_DISK_QUIRK_MODE_PAGE_NO_FLEXIBLE_DISK))) {
+        return -1;
+    }
+
     /*
      * If Changeable Values are requested, a mask denoting those mode parameters
      * that are changeable shall be returned. As we currently don't support
@@ -3293,6 +3302,8 @@ static const Property scsi_hd_properties[] = {
                     0),
     DEFINE_PROP_BIT("quirk_mode_page_set_block_size", SCSIDiskState,
                     quirks, SCSI_DISK_QUIRK_MODE_PAGE_SET_BLOCK_SIZE, 0),
+    DEFINE_PROP_BIT("quirk_mode_page_no_flexible_disk", SCSIDiskState,
+                    quirks, SCSI_DISK_QUIRK_MODE_PAGE_NO_FLEXIBLE_DISK, 0),
     DEFINE_BLOCK_CHS_PROPERTIES(SCSIDiskState, qdev.conf),
 };
 
@@ -3401,6 +3412,8 @@ static const Property scsi_cd_properties[] = {
                     SCSI_DISK_QUIRK_MODE_PAGE_TRUNCATED, 0),
     DEFINE_PROP_BIT("quirk_mode_page_set_block_size", SCSIDiskState,
                     quirks, SCSI_DISK_QUIRK_MODE_PAGE_SET_BLOCK_SIZE, 0),
+    DEFINE_PROP_BIT("quirk_mode_page_no_flexible_disk", SCSIDiskState,
+                    quirks, SCSI_DISK_QUIRK_MODE_PAGE_NO_FLEXIBLE_DISK, 0),
 };
 
 static void scsi_cd_class_initfn(ObjectClass *klass, const void *data)
Signature · 1 line
2.55.0
#4 lore raw

RFC v4 4/14 hw/scsi/lasi_ncr710: Limit max_target and max_lun to 7

In reply to Philippe Mathieu-Daudé

SCSI target IDs and LUNs on this bus are 3-bit values, so the highest valid one is 7. scsi-bus.c treats max_target and max_lun as inclusive limits (id > max_target is rejected), so 8 wrongly allowed an ID and a LUN that the chip cannot address. This matches esp.c and esp-pci.c.

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
 hw/scsi/lasi_ncr710.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/scsi/lasi_ncr710.c +2 -2
index 4fde2265b5be..27234aadd390 100644
@@ -137,8 +137,8 @@ static void lasi_ncr710_command_complete(SCSIRequest *req, size_t resid)
 
 static const struct SCSIBusInfo lasi_ncr710_scsi_info = {
     .tcq = true,
-    .max_target = 8,
-    .max_lun = 8,  /* full LUN support */
+    .max_target = 7,
+    .max_lun = 7,
 
     .transfer_data = lasi_ncr710_transfer_data,
     .complete = lasi_ncr710_command_complete,
Signature · 1 line
2.55.0
#5 lore raw

RFC v4 5/14 hw/scsi/ncr53c710: Keep DCNTL.EA and DMODE.FC1 across an ISTAT.RST reset

In reply to Philippe Mathieu-Daudé

The NCR 53C710 data manual, ISTAT bit 6 (RST) description, says the software reset clears all registers except that "This reset will not clear the Enable Acknowledge (EA) or Function Control One (FC1) bits". EA is DCNTL bit 5 and FC1 is DMODE bit 4. ncr710_soft_reset() cleared both registers entirely.

Add named defines for the two bits and preserve them in the soft reset. ncr710_soft_reset() is also used for device reset and realize, which must still clear both bits, so those callers (the LASI reset and realize handlers and the sysbus reset handler) now zero DCNTL and DMODE after calling it.

The effect on real guest drivers has not been tested.

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
 hw/scsi/ncr53c710.h   | 5 +++++
 hw/scsi/lasi_ncr710.c | 6 ++++++
 hw/scsi/ncr53c710.c   | 7 +++++--
 3 files changed, 16 insertions(+), 2 deletions(-)
hw/scsi/ncr53c710.h +5 -0
index 00b6a01577c0..7dd0fe5f7589 100644
@@ -85,6 +85,11 @@
 #define NCR710_DCNTL_REG        0x3B    /* DMA Control */
 #define NCR710_ADDER_REG        0x3C    /* Adder Sum Output (32-bit, LE) */
 
+/* DMODE bit 4: Function Code 1 (FC1), kept by an ISTAT.RST soft reset. */
+#define NCR710_DMODE_FC1  0x10
+/* DCNTL bit 5: Enable Acknowledge (EA), kept by an ISTAT.RST soft reset. */
+#define NCR710_DCNTL_EA   0x20
+
 #define NCR710_REG_SIZE         0x100
 
 #define NCR710_BUF_SIZE         4096
hw/scsi/lasi_ncr710.c +6 -0
index 27234aadd390..27d8b5c74935 100644
@@ -186,6 +186,9 @@ static void lasi_ncr710_realize(DeviceState *dev, Error **errp)
                      &s->ncr710);
 
     ncr710_soft_reset(&s->ncr710);
+    /* A device reset clears EA and FC1; only ISTAT.RST keeps them. */
+    s->ncr710.dcntl = 0;
+    s->ncr710.dmode = 0;
 
     trace_lasi_ncr710_timers_initialized(
         (uint64_t)s->ncr710.reselection_retry_timer);
@@ -246,6 +249,9 @@ static void lasi_ncr710_reset(DeviceState *dev)
     LasiNCR710State *s = LASI_NCR710(dev);
     trace_lasi_ncr710_device_reset();
     ncr710_soft_reset(&s->ncr710);
+    /* A device reset clears EA and FC1; only ISTAT.RST keeps them. */
+    s->ncr710.dcntl = 0;
+    s->ncr710.dmode = 0;
 }
 
 static void lasi_ncr710_instance_init(Object *obj)
hw/scsi/ncr53c710.c +5 -2
index 9ea2c47744e7..55153418e409 100644
@@ -349,8 +349,8 @@ void ncr710_soft_reset(NCR710State *s)
     s->ctest5 = 0;
     s->dsp = 0;
     s->dsps = 0;
-    s->dmode = 0;
-    s->dcntl = 0;
+    s->dmode &= NCR710_DMODE_FC1;
+    s->dcntl &= NCR710_DCNTL_EA;
     s->scntl0 = 0xc0;
     s->scntl1 = 0;
     s->sstat0 = 0;
@@ -2266,6 +2266,9 @@ static void ncr710_device_reset(DeviceState *dev)
     NCR710State *s = &sysbus_dev->ncr710;
 
     ncr710_soft_reset(s);
+    /* A device reset clears EA and FC1; only ISTAT.RST keeps them. */
+    s->dcntl = 0;
+    s->dmode = 0;
 }
 
 static const struct SCSIBusInfo ncr710_scsi_info = {
Signature · 1 line
2.55.0
#6 lore raw

RFC v4 6/14 hw/scsi: Move shared LSI/NCR definitions to lsi_scsi.h

In reply to Philippe Mathieu-Daudé

From: Keith Monahan <[email protected]>

Move common defines and structures of the lsi53c895a driver to lsi_scsi.h so that the 53c710 driver can share them.

Pure code movement, no functional change: nothing is renamed and the lsi53c895a device is unchanged.

Licence: the moved code comes from lsi53c895a.c, which is licensed under the LGPL (Copyright (c) 2006 CodeSourcery, written by Paul Brook), so the new header keeps that licence (SPDX LGPL-2.1-or-later) rather than the preferred GPL-2.0-or-later; it is not relicensed.

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
 MAINTAINERS          |   1 +
 hw/scsi/lsi_scsi.h   | 104 +++++++++++++++++++++++++++++++++++++++++++
 hw/scsi/lsi53c895a.c |  79 +-------------------------------
 3 files changed, 106 insertions(+), 78 deletions(-)
 create mode 100644 hw/scsi/lsi_scsi.h
MAINTAINERS +1 -0
index 3a9b4d34a0fc..752519a7f82f 100644
@@ -2431,6 +2431,7 @@ R: Fam Zheng <[email protected]>
 S: Supported
 F: include/hw/scsi/*
 F: hw/scsi/*
+F: hw/scsi/lsi_scsi.h
 F: tests/qtest/virtio-scsi-test.c
 F: tests/qtest/fuzz-virtio-scsi-test.c
 F: tests/qtest/am53c974-test.c
hw/scsi/lsi_scsi.h new file +104 -0

104 lines not on this page · raw message

hw/scsi/lsi53c895a.c +1 -78

143 lines not on this page · raw message

Signature · 1 line
2.55.0
Reviewed-by on v4 6/14
#7 lore raw

Re: [RFC PATCH-for-11.2? v4 06/14] hw/scsi: Move shared LSI/NCR definitions to lsi_scsi.h

Quoted 13 lines · Philippe Mathieu-Daudé

From: Keith Monahan <[email protected]>

Move common defines and structures of the lsi53c895a driver to lsi_scsi.h so that the 53c710 driver can share them.

Pure code movement, no functional change: nothing is renamed and the lsi53c895a device is unchanged.

Licence: the moved code comes from lsi53c895a.c, which is licensed under the LGPL (Copyright (c) 2006 CodeSourcery, written by Paul Brook), so the new header keeps that licence (SPDX LGPL-2.1-or-later) rather than the preferred GPL-2.0-or-later; it is not relicensed.

Quoted 5 lines

AI-used-for: Patch series decomposition (commit splitting and ordering)

#8 lore raw

RFC v4 7/14 hw/scsi/ncr53c710: Rewrite the 53C710 SCRIPTS engine

In reply to Philippe Mathieu-Daudé

From: Keith Monahan <[email protected]>

Rewrite the NCR 53C710 model with a SCRIPTS engine derived from QEMU's LSI53C895A model (hw/scsi/lsi53c895a.c), an actively maintained sibling in the same NCR/LSI SCRIPTS family, adapted to the 53C710: its register map, single byte (DSTAT/SSTAT0) interrupt model, big endian SCRIPTS and table indirect fetch (the part sits on the big endian PA-RISC LASI bus), and 24 bit DMA counts. Behaviour follows the NCR 53C710 Data Manual (Jun 1992) and Programmer's Guide (Oct 1990).

The LASI glue (hw/scsi/lasi_ncr710.c) is the only instantiated device and embeds one NCR710State by value. It gains the free_request SCSIBusInfo callback and request queue init the new core needs, renames the reselection timer to scripts_timer, and drops the old model's dead scaffolding (the unused SCNR define, the DPRINTF macros, and unused or shadowing register macros).

Disconnect and reselect, adapted from lsi53c895a, let a driver overlap tagged commands: a disconnecting command's request moves onto a per device queue and is reselected once its data is ready and the engine is parked at Wait Reselect. Reselection follows the 53C700 family rather than the 8xx parts: gated on the (re)selection interrupt enable (SIEN.SEL) alone, one hot SDID, an SFBR id bitmask in 700 compatibility mode, and IDENTIFY (plus SIMPLE QUEUE TAG when tagged) replayed on reconnect. A disconnect is fabricated only for a tagged command under a driver that parks on Wait Reselect with SIEN.SEL clear, which today means HP-UX; untagged transfers and reselection interrupt drivers (e.g. Linux 53c700) keep the existing connected completion path.

SDTR/WDTR/PPR negotiation is declined with MESSAGE REJECT.

Completion deferral, the synchronous drain, the HP-UX MESSAGE REJECT quirk, the reentrancy guard and the soft reset request cancel are added by the following patches, as is the migration version bump: this patch does not preserve the migration stream of the model it replaces.

Derived from hw/scsi/lsi53c895a.c (Copyright (c) 2006 CodeSourcery, written by Paul Brook), which is LGPL; this derived work is distributed under GPL-2.0-or-later, as the LGPL permits. Replaces the 53C710 model written for Google Summer of Code 2025 by Soumyajyotii Ssarkar, itself based on earlier NCR 53C710 work by Helge Deller and by Toni Wilen (for UAE).

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
 hw/scsi/lasi_ncr710.h |   28 +-
 hw/scsi/ncr53c710.h   |  263 ++--
 hw/scsi/lasi_ncr710.c |  108 +-
 hw/scsi/ncr53c710.c   | 2843 ++++++++++++++---------------------------
 hw/scsi/trace-events  |   42 +-
 5 files changed, 1131 insertions(+), 2153 deletions(-)
hw/scsi/lasi_ncr710.h +3 -25
index 450fb7e1c3dc..5168f6171568 100644
@@ -1,12 +1,9 @@
 /*
- * LASI Wrapper for NCR710 SCSI Controller
+ * LASI wrapper for the NCR 53C710 SCSI controller
  *
  * Copyright (c) 2025 Soumyajyotii Ssarkar <[email protected]>
- * This driver was developed during the Google Summer of Code 2025 program.
- * Mentored by Helge Deller <[email protected]>
- *
- * NCR710 SCSI Controller implementation
- * Based on the NCR53C710 Technical Manual Version 3.2, December 2000
+ * Developed during Google Summer of Code 2025, mentored by
+ * Helge Deller <[email protected]>.
  *
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
@@ -22,29 +19,10 @@
 #define TYPE_LASI_NCR710 "lasi-ncr710"
 OBJECT_DECLARE_SIMPLE_TYPE(LasiNCR710State, LASI_NCR710)
 
-#define LASI_SCSI_RESET         0x000   /* SCSI Reset Register */
-#define LASI_SCSI_NCR710_BASE   0x100   /* NCR710 Base Register Offset */
-
-#define PARISC_DEVICE_ID_OFF    0x00    /* HW type, HVERSION, SVERSION */
-#define PARISC_DEVICE_CONFIG_OFF 0x04   /* Configuration data */
-
-#define PHASE_MASK              7
-#define PHASE_DO                0
-
-#define NCR710_SCNTL1_RST       0x08    /* SCSI Reset */
-#define NCR710_ISTAT_RST        0x40    /* Device Reset */
-#define NCR710_ISTAT_ABRT       0x80    /* Script Abort */
-#define NCR710_ISTAT_CON        0x08    /* ISTAT_Connected */
-#define NCR710_DSTAT_DFE        0x80    /* DMA FIFO Empty */
-#define NCR710_CTEST2_DACK      0x01    /* DMA Acknowledge */
-
 typedef struct LasiNCR710State {
     SysBusDevice parent_obj;
     MemoryRegion mmio;
     qemu_irq lasi_irq;       /* IRQ line to LASI controller */
-    uint32_t hw_type;        /* Hardware type (HPHW_*) */
-    uint32_t sversion;       /* Software version */
-    uint32_t hversion;       /* Hardware version */
     NCR710State ncr710;
 } LasiNCR710State;
 
hw/scsi/ncr53c710.h +85 -178

318 lines not on this page · raw message

hw/scsi/lasi_ncr710.c +41 -67

229 lines not on this page · raw message

hw/scsi/ncr53c710.c +971 -1872

2,409 lines not on this page · raw message

hw/scsi/trace-events +31 -11

42 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.55.0

Part of the diff is not shown here. View the raw message.

#9 lore raw

Re: [RFC PATCH-for-11.2??? v4 07/14] hw/scsi/ncr53c710: Rewrite the 53C710 SCRIPTS engine

Quoted 54 lines · Philippe Mathieu-Daudé

From: Keith Monahan <[email protected]>

Rewrite the NCR 53C710 model with a SCRIPTS engine derived from QEMU's LSI53C895A model (hw/scsi/lsi53c895a.c), an actively maintained sibling in the same NCR/LSI SCRIPTS family, adapted to the 53C710: its register map, single byte (DSTAT/SSTAT0) interrupt model, big endian SCRIPTS and table indirect fetch (the part sits on the big endian PA-RISC LASI bus), and 24 bit DMA counts. Behaviour follows the NCR 53C710 Data Manual (Jun 1992) and Programmer's Guide (Oct 1990).

The LASI glue (hw/scsi/lasi_ncr710.c) is the only instantiated device and embeds one NCR710State by value. It gains the free_request SCSIBusInfo callback and request queue init the new core needs, renames the reselection timer to scripts_timer, and drops the old model's dead scaffolding (the unused SCNR define, the DPRINTF macros, and unused or shadowing register macros).

Disconnect and reselect, adapted from lsi53c895a, let a driver overlap tagged commands: a disconnecting command's request moves onto a per device queue and is reselected once its data is ready and the engine is parked at Wait Reselect. Reselection follows the 53C700 family rather than the 8xx parts: gated on the (re)selection interrupt enable (SIEN.SEL) alone, one hot SDID, an SFBR id bitmask in 700 compatibility mode, and IDENTIFY (plus SIMPLE QUEUE TAG when tagged) replayed on reconnect. A disconnect is fabricated only for a tagged command under a driver that parks on Wait Reselect with SIEN.SEL clear, which today means HP-UX; untagged transfers and reselection interrupt drivers (e.g. Linux 53c700) keep the existing connected completion path.

SDTR/WDTR/PPR negotiation is declined with MESSAGE REJECT.

Completion deferral, the synchronous drain, the HP-UX MESSAGE REJECT quirk, the reentrancy guard and the soft reset request cancel are added by the following patches, as is the migration version bump: this patch does not preserve the migration stream of the model it replaces.

Derived from hw/scsi/lsi53c895a.c (Copyright (c) 2006 CodeSourcery, written by Paul Brook), which is LGPL; this derived work is distributed under GPL-2.0-or-later, as the LGPL permits. Replaces the 53C710 model written for Google Summer of Code 2025 by Soumyajyotii Ssarkar, itself based on earlier NCR 53C710 work by Helge Deller and by Toni Wilen (for UAE).

AI-used-for: Patch series decomposition (commit splitting and ordering)

---

hw/scsi/lasi_ncr710.h |   28 +-
hw/scsi/ncr53c710.h   |  263 ++--
hw/scsi/lasi_ncr710.c |  108 +-
hw/scsi/ncr53c710.c   | 2843 ++++++++++++++---------------------------
hw/scsi/trace-events  |   42 +-
5 files changed, 1131 insertions(+), 2153 deletions(-)

[...]

Quoted 865 lines
hw/scsi/ncr53c710.c +177 -586
index 55153418e409..305958b92f4a 100644
@@ -1,1497 +1,958 @@
 /*
- * QEMU NCR710 SCSI Controller
+ * QEMU NCR 53C710 SCSI I/O Processor emulation
 *
- * Copyright (c) 2025 Soumyajyotii Ssarkar <[email protected]>
- * This driver was developed during the Google Summer of Code 2025 program.
+ * Copyright (c) 2026 Keith Monahan <[email protected]>
+ * Copyright (c) 2006 CodeSourcery (lsi53c895a.c, written by Paul Brook)
 *
- * NCR710 SCSI Controller implementation
- * Based on the NCR53C710 Technical Manual Version 3.2, December 2000
+ * The SCRIPTS engine is derived from QEMU's LSI53C895A model and adapted to
+ * the 53C710's register map, single byte interrupt model, big endian SCRIPTS
+ * fetch and 24 bit DMA, per the NCR 53C710 Data Manual and Programmer's Guide.
 *
- * Developed from an implementation of NCR53C710 by Helge Deller
- * which was interim based on the implementation by Toni Wilen for UAE.
+ * Replaces the 53C710 model written for Google Summer of Code 2025 by
+ * Soumyajyotii Ssarkar <[email protected]>, itself based on
+ * earlier NCR 53C710 work by Helge Deller and by Toni Wilen (for UAE).
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
- *
- * Contents:
- * 1. Register Definitions
- * 2. Register name functions
- * 3. Parity functions
- * 4. SCSI FIFO Structures
- * 5. Scripts Misc functions
- * 6. DMA functions
- * 7. Scripts functions
- * 8. Read and Write functions
- * 9. QEMU Device model functions
- *
 */
 
 #include "qemu/osdep.h"
-#include "qapi/error.h"
-#include "qemu/timer.h"
-#include "hw/core/irq.h"
-#include "hw/core/sysbus.h"
-#include "hw/scsi/scsi.h"
-#include "hw/scsi/ncr53c710.h"
-#include "migration/vmstate.h"
-#include "system/dma.h"
+#include "qemu/bitops.h"
 #include "qemu/log.h"
-#include "qemu/module.h"
+#include "qemu/main-loop.h"
+#include "hw/core/irq.h"
+#include "hw/scsi/ncr53c710.h"
+#include "system/block-backend.h"
 #include "trace.h"
-#include "qom/object.h"
 
-#define NCR710_MAX_DEVS 7
+/* SCNTL0 (0x00) */
+#define LSI_SCNTL0_EPG       0x04
 
-/* SCNTL0 (0x00) - SCSI Control Register 0 */
-#define NCR710_SCNTL0_TRG    0x01
-#define NCR710_SCNTL0_AAP    0x02
-#define NCR710_SCNTL0_EPG    0x04
-#define NCR710_SCNTL0_EPC    0x08
-#define NCR710_SCNTL0_WATN   0x10
-#define NCR710_SCNTL0_START  0x20
-#define NCR710_SCNTL0_ARB0   0x40
-#define NCR710_SCNTL0_ARB1   0x80
+/* SCNTL1 (0x01) */
+#define LSI_SCNTL1_ESR       0x20
 
-/* SCNTL1 (0x01) - SCSI Control Register 1 */
-#define NCR710_SCNTL1_RES0   0x01
-#define NCR710_SCNTL1_RES1   0x02
-#define NCR710_SCNTL1_AESP   0x04
-#define NCR710_SCNTL1_RST    0x08
-#define NCR710_SCNTL1_CON    0x10
-#define NCR710_SCNTL1_ESR    0x20
-#define NCR710_SCNTL1_ADB    0x40
-#define NCR710_SCNTL1_EXC    0x80
+/* SSTAT0 (0x0d) and SIEN (0x03) share this bit layout. */
+#define LSI_STAT0_PAR        0x01
+#define LSI_STAT0_RST        0x02
+#define LSI_STAT0_UDC        0x04
+#define LSI_STAT0_SGE        0x08
+#define LSI_STAT0_SEL        0x10
+#define LSI_STAT0_STO        0x20
+#define LSI_STAT0_FCMP       0x40
+#define LSI_STAT0_MA         0x80
 
-/* ISTAT (0x21) - Interrupt Status Register */
-#define NCR710_ISTAT_DIP    0x01
-#define NCR710_ISTAT_SIP    0x02
-#define NCR710_ISTAT_CON    0x08
-#define NCR710_ISTAT_SIGP   0x20
-#define NCR710_ISTAT_RST    0x40
-#define NCR710_ISTAT_ABRT   0x80
+/* DSTAT (0x0c) and DIEN (0x39) share this bit layout. */
+#define LSI_DSTAT_WTD        0x02
 
-/* SSTAT0 (0x0D) - SCSI Status Register 0 */
-#define NCR710_SSTAT0_PAR    0x01
-#define NCR710_SSTAT0_RST    0x02
-#define NCR710_SSTAT0_UDC    0x04
-#define NCR710_SSTAT0_SGE    0x08
-#define NCR710_SSTAT0_SEL    0x10
-#define NCR710_SSTAT0_STO    0x20
-#define NCR710_SSTAT0_FCMP   0x40
-#define NCR710_SSTAT0_MA     0x80
+/* SBCL (0x0b): low 3 bits mirror the SCSI phase, upper bits are bus signals. */
+#define LSI_SBCL_SEL         0x10
 
-/* SSTAT1 (0x0E) - SCSI Status Register 1 */
-#define NCR710_SSTAT1_ORF    0x02
-#define NCR710_SSTAT1_ILF    0x04
+/* DCNTL (0x3b) */
+#define LSI_DCNTL_FA         0x02
+#define LSI_DCNTL_LLM        0x08
+#define LSI_DCNTL_EA         0x20
 
-/* SSTAT2 (0x0F) - SCSI Status Register 2 */
-#define NCR710_SSTAT2_FF0    0x01
-#define NCR710_SSTAT2_FF1    0x02
-#define NCR710_SSTAT2_FF2    0x04
-#define NCR710_SSTAT2_FF3    0x08
+#define LSI_BUF_SIZE     4096
 
-/* SOCL (0x07) / SBCL (0x0B) - SCSI Output/Bus Control Lines */
-#define NCR710_SOCL_IO       0x01
-#define NCR710_SOCL_CD       0x02
-#define NCR710_SOCL_MSG      0x04
-#define NCR710_SOCL_ATN      0x08
-#define NCR710_SOCL_SEL      0x10
-#define NCR710_SOCL_BSY      0x20
-#define NCR710_SOCL_ACK      0x40
-#define NCR710_SOCL_REQ      0x80
+static const char *const lsi_reg_names[64] = {
+    "SCNTL0", "SCNTL1", "SDID", "SIEN", "SCID", "SXFER", "SODL", "SOCL",
+    "SFBR", "SIDL", "SBDL", "SBCL", "DSTAT", "SSTAT0", "SSTAT1", "SSTAT2",
+    "DSA0", "DSA1", "DSA2", "DSA3", "CTEST0", "CTEST1", "CTEST2", "CTEST3",
+    "CTEST4", "CTEST5", "CTEST6", "CTEST7", "TEMP0", "TEMP1", "TEMP2", "TEMP3",
+    "DFIFO", "ISTAT", "CTEST8", "LCRC", "DBC0", "DBC1", "DBC2", "DCMD",
+    "DNAD0", "DNAD1", "DNAD2", "DNAD3", "DSP0", "DSP1", "DSP2", "DSP3",
+    "DSPS0", "DSPS1", "DSPS2", "DSPS3", "SCRATCH0", "SCRATCH1", "SCRATCH2",
+    "SCRATCH3", "DMODE", "DIEN", "DWT", "DCNTL", "ADDER0", "ADDER1", "ADDER2",
+    "ADDER3",
+};
 
-/* SBCL bits same as SOCL */
-#define NCR710_SBCL_IO       0x01
-#define NCR710_SBCL_CD       0x02
-#define NCR710_SBCL_MSG      0x04
-#define NCR710_SBCL_ATN      0x08
-#define NCR710_SBCL_SEL      0x10
-#define NCR710_SBCL_BSY      0x20
-#define NCR710_SBCL_ACK      0x40
-#define NCR710_SBCL_REQ      0x80
-
-/* DSTAT (0x0C) - DMA Status Register */
-#define NCR710_DSTAT_IID     0x01
-#define NCR710_DSTAT_SIR     0x04
-#define NCR710_DSTAT_SSI     0x08
-#define NCR710_DSTAT_ABRT    0x10
-#define NCR710_DSTAT_BF      0x20
-#define NCR710_DSTAT_MDPE    0x40
-#define NCR710_DSTAT_DFE     0x80
-
-/* DCNTL (0x3B) - DMA Control Register */
-#define NCR710_DCNTL_COM     0x01
-#define NCR710_DCNTL_IRQD    0x02
-#define NCR710_DCNTL_STD     0x04
-#define NCR710_DCNTL_IRQM    0x08
-#define NCR710_DCNTL_SSM     0x10
-#define NCR710_DCNTL_PFEN    0x20
-#define NCR710_DCNTL_PFF     0x40
-
-/* DMODE (0x38) - DMA Mode Register */
-#define NCR710_DMODE_MAN     0x01
-#define NCR710_DMODE_BOF     0x02
-#define NCR710_DMODE_ERMP    0x04
-#define NCR710_DMODE_ERL     0x08
-#define NCR710_DMODE_DIOM    0x10
-#define NCR710_DMODE_SIOM    0x20
-#define NCR710_DMODE_BL_MASK 0xC0
-#define NCR710_DMODE_BL_1    0x00
-#define NCR710_DMODE_BL_2    0x40
-#define NCR710_DMODE_BL_4    0x80
-#define NCR710_DMODE_BL_8    0xC0
-
-/* CTEST2 (0x16) - Chip Test Register 2 */
-#define NCR710_CTEST2_DACK   0x01
-#define NCR710_CTEST2_DREQ   0x02
-#define NCR710_CTEST2_TEOP   0x04
-#define NCR710_CTEST2_PCICIE 0x08
-#define NCR710_CTEST2_CM     0x10
-#define NCR710_CTEST2_CIO    0x20
-#define NCR710_CTEST2_SIGP   0x40
-#define NCR710_CTEST2_DDIR   0x80
-
-/* CTEST5 (0x19) - Chip Test Register 5 */
-#define NCR710_CTEST5_BL2    0x04
-#define NCR710_CTEST5_DDIR   0x08
-#define NCR710_CTEST5_MASR   0x10
-#define NCR710_CTEST5_DFSN   0x20
-#define NCR710_CTEST5_BBCK   0x40
-#define NCR710_CTEST5_ADCK   0x80
-
-/* SCID (0x04) - SCSI Chip ID Register */
-#define NCR710_SCID_RRE      0x60
-#define NCR710_SCID_ID_MASK  0x07
-
-#define NCR710_HOST_ID       7
-
-/* NCR53C710 has 8-byte SCSI FIFO */
-#define NCR710_MAX_MSGIN_LEN 8
-#define NCR710_BUF_SIZE         4096
-
-/* Standard SCSI Message Byte Constants */
-#define SCSI_MSG_ABORT                      0x06
-#define SCSI_MSG_BUS_DEVICE_RESET           0x0c
-#define SCSI_MSG_COMMAND_COMPLETE           0x00
-#define SCSI_MSG_DISCONNECT                 0x04
-#define SCSI_MSG_EXTENDED_MESSAGE           0x01
-#define SCSI_MSG_IDENTIFY                   0x80
-#define SCSI_MSG_IGNORE_WIDE_RESIDUE        0x23
-#define SCSI_MSG_MESSAGE_PARITY_ERROR       0x09
-#define SCSI_MSG_MESSAGE_REJECT             0x07
-#define SCSI_MSG_NO_OPERATION               0x08
-#define SCSI_MSG_RELEASE_RECOVERY           0x10
-#define SCSI_MSG_RESTORE_POINTERS           0x03
-#define SCSI_MSG_SAVE_DATA_POINTER          0x02
-#define SCSI_MSG_SYNCHRONOUS_DATA_TRANSFER  0x01
-#define SCSI_MSG_WIDE_DATA_TRANSFER         0x03
-
-/* Script interrupt codes */
-#define A_GOOD_STATUS_AFTER_STATUS          0x401
-#define A_DISCONNECT_AFTER_CMD              0x380
-#define A_DISCONNECT_AFTER_DATA             0x580
-#define A_DISCONNECT_DURING_DATA            0x780
-#define A_RESELECTION_IDENTIFIED            0x1003
-#define A_UNEXPECTED_PHASE                  0x20
-#define A_FATAL                             0x2000
-#define A_DEBUG_INTERRUPT                   0x3000
-
-/* SCSI Script execution states */
-#define SCRIPT_STATE_IDLE                  0
-#define SCRIPT_STATE_SELECTING             1
-#define SCRIPT_STATE_COMMAND               2
-#define SCRIPT_STATE_DATA                  3
-#define SCRIPT_STATE_STATUS                4
-#define SCRIPT_STATE_MESSAGE               5
-#define SCRIPT_STATE_DISCONNECTED          6
-
-#define AFTER_SELECTION         0x100
-#define BEFORE_CMD              0x200
-#define AFTER_CMD               0x300
-#define AFTER_STATUS            0x400
-#define AFTER_DATA_IN           0x500
-#define AFTER_DATA_OUT          0x600
-#define DURING_DATA_IN          0x700
-
-#define NOT_MSG_OUT             0x10
-#define UNEXPECTED_PHASE        0x20
-#define NOT_MSG_IN              0x30
-#define UNEXPECTED_MSG          0x40
-#define MSG_IN                  0x50
-#define SDTR_MSG_R              0x60
-#define REJECT_MSG_R            0x70
-#define DISCONNECT              0x80
-#define MSG_OUT                 0x90
-#define WDTR_MSG_R              0xA0
-
-#define GOOD_STATUS             0x1
-
-#define NOT_MSG_OUT_AFTER_SELECTION         0x110
-#define UNEXPECTED_PHASE_BEFORE_CMD         0x220
-#define UNEXPECTED_PHASE_AFTER_CMD          0x320
-#define NOT_MSG_IN_AFTER_STATUS             0x430
-#define GOOD_STATUS_AFTER_STATUS            0x401
-#define UNEXPECTED_PHASE_AFTER_DATA_IN      0x520
-#define UNEXPECTED_PHASE_AFTER_DATA_OUT     0x620
-#define UNEXPECTED_MSG_BEFORE_CMD           0x240
-#define MSG_IN_BEFORE_CMD                   0x250
-#define MSG_IN_AFTER_CMD                    0x350
-#define SDTR_MSG_BEFORE_CMD                 0x260
-#define REJECT_MSG_BEFORE_CMD               0x270
-#define DISCONNECT_AFTER_CMD                0x380
-#define SDTR_MSG_AFTER_CMD                  0x360
-#define WDTR_MSG_AFTER_CMD                  0x3A0
-#define MSG_IN_AFTER_STATUS                 0x440
-#define DISCONNECT_AFTER_DATA               0x580
-#define MSG_IN_AFTER_DATA_IN                0x550
-#define MSG_IN_AFTER_DATA_OUT               0x650
-#define MSG_OUT_AFTER_DATA_IN               0x590
-#define DATA_IN_AFTER_DATA_IN               0x5a0
-#define MSG_IN_DURING_DATA_IN               0x750
-#define DISCONNECT_DURING_DATA              0x780
-
-#define RESELECTED_DURING_SELECTION      0x1000
-#define COMPLETED_SELECTION_AS_TARGET    0x1001
-#define RESELECTION_IDENTIFIED           0x1003
-
-#define FATAL                            0x2000
-#define FATAL_UNEXPECTED_RESELECTION_MSG 0x2000
-#define FATAL_SEND_MSG                   0x2001
-#define FATAL_NOT_MSG_IN_AFTER_SELECTION 0x2002
-#define FATAL_ILLEGAL_MSG_LENGTH         0x2003
-
-#define DEBUG_INTERRUPT     0x3000
-#define DEBUG_INTERRUPT1    0x3001
-#define DEBUG_INTERRUPT2    0x3002
-#define DEBUG_INTERRUPT3    0x3003
-#define DEBUG_INTERRUPT4    0x3004
-#define DEBUG_INTERRUPT5    0x3005
-#define DEBUG_INTERRUPT6    0x3006
-
-#define COMMAND_COMPLETE_MSG      0x00
-#define EXTENDED_MSG              0x01
-#define SDTR_MSG                  0x01
-#define SAVE_DATA_PTRS_MSG        0x02
-#define RESTORE_DATA_PTRS_MSG     0x03
-#define WDTR_MSG                  0x03
-#define DISCONNECT_MSG            0x04
-#define REJECT_MSG                0x07
-#define PARITY_ERROR_MSG          0x09
-#define SIMPLE_TAG_MSG            0x20
-#define IDENTIFY_MSG              0x80
-#define IDENTIFY_MSG_MASK         0x7F
-#define TWO_BYTE_MSG              0x20
-#define TWO_BYTE_MSG_MASK         0x0F
-
-/* SCSI phases */
-#define PHASE_DO   0  /* Data out phase */
-#define PHASE_DI   1  /* Data in phase */
-#define PHASE_CO   2  /* Command phase */
-#define PHASE_SI   3  /* Status phase */
-#define PHASE_ST   3  /* Status phase (alias) */
-#define PHASE_MO   6  /* Message out phase */
-#define PHASE_MI   7  /* Message in phase */
-#define PHASE_MASK 7  /* Mask for phase bits */
-
-#define NCR710_TAG_VALID     (1 << 16)
-
-static void ncr710_scsi_fifo_init(NCR710_SCSI_FIFO *fifo);
-static const char *ncr710_reg_name(int offset);
-static void ncr710_script_scsi_interrupt(NCR710State *s, int stat0);
-static void ncr710_update_irq(NCR710State *s);
-static void ncr710_script_dma_interrupt(NCR710State *s, int stat);
-static void ncr710_request_free(NCR710State *s, NCR710Request *p);
-static inline void ncr710_dma_read(NCR710State *s, uint32_t addr,
-                                   void *buf, uint32_t len);
-static inline void ncr710_dma_write(NCR710State *s, uint32_t addr,
-                                    const void *buf, uint32_t len);
-static uint8_t ncr710_reg_readb(NCR710State *s, int offset);
-static void ncr710_reg_writeb(NCR710State *s, int offset, uint8_t val);
-
-
-static inline int ncr710_irq_on_rsl(NCR710State *s)
+static const char *lsi_reg_name(int offset)
 {
-    return (s->sien0 & NCR710_SSTAT0_SEL) != 0;
+    return (offset >= 0 && offset < 64) ? lsi_reg_names[offset] : "???";
 }
 
-static void ncr710_clear_pending_irq(NCR710State *s)
+static uint8_t lsi_reg_readb(NCR710State *s, int offset);
+static void lsi_reg_writeb(NCR710State *s, int offset, uint8_t val);
+static void lsi_execute_script(NCR710State *s);
+static void lsi_set_phase(NCR710State *s, int phase);
+
+/*
+ * On the 53C700 family the Select/Reselect destination ID and SDID are a one
+ * hot bitmask, unlike the 53C8xx's binary target number.
+ */
+static int lsi_id_from_bits(unsigned bits)
 {
-    if (s->current) {
-        if (s->current->req) {
-            s->current->req->hba_private = NULL;
+    int i;
+
+    bits &= 0xff;
+    for (i = 0; i < 8; i++) {
+        if (bits & (1u << i)) {
+            return i;
        }
-        ncr710_request_free(s, s->current);
-        s->current = NULL;
    }
+    qemu_log_mask(LOG_GUEST_ERROR,
+                  "ncr710: empty destination ID bitmask; defaulting to ID 0\n");
+    return 0;
 }
 
 void ncr710_soft_reset(NCR710State *s)
 {
    trace_ncr710_reset();
+
    s->carry = 0;
-    s->msg_action = NCR710_MSG_ACTION_NONE;
+    s->msg_action = LSI_MSG_ACTION_COMMAND;
    s->msg_len = 0;
-    s->waiting = NCR710_WAIT_NONE;
-    s->wait_reselect = false;
-    s->reselection_id = 0;
-    s->dsa = 0;
-    s->dnad = 0;
-    s->dbc = 0;
-    s->temp = 0;
-    s->scratch = 0;
-    s->istat &= 0x40;
-    s->dcmd = 0x40;
-    s->dstat = NCR710_DSTAT_DFE;
-    s->dien = 0x04;
-    s->sien0 = 0;
-    s->ctest2 = NCR710_CTEST2_DACK;
-    s->ctest3 = 0;
-    s->ctest4 = 0;
-    s->ctest5 = 0;
-    s->dsp = 0;
-    s->dsps = 0;
-    s->dmode &= NCR710_DMODE_FC1;
-    s->dcntl &= NCR710_DCNTL_EA;
-    s->scntl0 = 0xc0;
+    s->waiting = LSI_NOWAIT;
+    s->current_lun = 0;
+    s->select_tag = 0;
+    s->command_complete = 0;
+    s->script_running = false;
+
+    s->scntl0 = 0xc0;       /* full arbitration */
    s->scntl1 = 0;
+    s->sdid = 0;
+    s->sien = 0;
+    s->scid = 0;
+    s->sxfer = 0;
+    s->sodl = 0;
+    s->socl = 0;
+    s->sfbr = 0;
+    s->sidl = 0;
+    s->sbdl = 0;
+    s->sbcl = 0;
+    s->dstat = 0;           /* DFE is OR'd in on read */
    s->sstat0 = 0;
    s->sstat1 = 0;
    s->sstat2 = 0;
-    s->scid = 0x80;
-    s->sxfer = 0;
-    s->socl = 0;
-    s->sdid = 0;
-    s->sbcl = 0;
-    s->sidl = 0;
-    s->sfbr = 0;
-    qemu_set_irq(s->irq, 0);
-    if (s->current && s->current->req) {
-        /* Drops hba_private via ncr710_request_cancelled() */
-        scsi_req_cancel(s->current->req);
-    }
-    ncr710_clear_pending_irq(s);
-    ncr710_scsi_fifo_init(&s->scsi_fifo);
-}
+    s->dsa = 0;
+    s->ctest0 = 0;
+    s->ctest3 = 0;
+    s->ctest4 = 0;
+    s->ctest5 = 0;
+    s->ctest7 = 0;
+    s->temp = 0;
+    s->dfifo = 0;
+    s->istat = 0;
+    s->lcrc = 0;
+    s->dbc = 0;
+    s->dcmd = 0;
+    s->dnad = 0;
+    s->dsp = 0;
+    s->dsps = 0;
+    s->scratch = 0;
+    s->dmode &= NCR710_DMODE_FC1;
+    s->dien = 0;
+    s->dwt = 0;
+    s->dcntl &= NCR710_DCNTL_EA;
+    s->adder = 0;
 
-static const char *ncr710_reg_name(int offset)
-{
-    switch (offset) {
-    case NCR710_SCNTL0_REG:      return "SCNTL0";
-    case NCR710_SCNTL1_REG:      return "SCNTL1";
-    case NCR710_SDID_REG:        return "SDID";
-    case NCR710_SIEN_REG:        return "SIEN";
-    case NCR710_SCID_REG:        return "SCID";
-    case NCR710_SXFER_REG:       return "SXFER";
-    case NCR710_SODL_REG:        return "SODL";
-    case NCR710_SOCL_REG:        return "SOCL";
-    case NCR710_SFBR_REG:        return "SFBR";
-    case NCR710_SIDL_REG:        return "SIDL";
-    case NCR710_SBDL_REG:        return "SBDL";
-    case NCR710_SBCL_REG:        return "SBCL";
-    case NCR710_DSTAT_REG:       return "DSTAT";
-    case NCR710_SSTAT0_REG:      return "SSTAT0";
-    case NCR710_SSTAT1_REG:      return "SSTAT1";
-    case NCR710_SSTAT2_REG:      return "SSTAT2";
-    case NCR710_DSA_REG:         return "DSA";
-    case NCR710_DSA_REG + 1:     return "DSA+1";
-    case NCR710_DSA_REG + 2:     return "DSA+2";
-    case NCR710_DSA_REG + 3:     return "DSA+3";
-    case NCR710_CTEST0_REG:      return "CTEST0";
-    case NCR710_CTEST1_REG:      return "CTEST1";
-    case NCR710_CTEST2_REG:      return "CTEST2";
-    case NCR710_CTEST3_REG:      return "CTEST3";
-    case NCR710_CTEST4_REG:      return "CTEST4";
-    case NCR710_CTEST5_REG:      return "CTEST5";
-    case NCR710_CTEST6_REG:      return "CTEST6";
-    case NCR710_CTEST7_REG:      return "CTEST7";
-    case NCR710_TEMP_REG:        return "TEMP";
-    case NCR710_TEMP_REG + 1:    return "TEMP+1";
-    case NCR710_TEMP_REG + 2:    return "TEMP+2";
-    case NCR710_TEMP_REG + 3:    return "TEMP+3";
-    case NCR710_DFIFO_REG:       return "DFIFO";
-    case NCR710_ISTAT_REG:       return "ISTAT";
-    case NCR710_CTEST8_REG:      return "CTEST8";
-    case NCR710_LCRC_REG:        return "LCRC";
-    case NCR710_DBC_REG:         return "DBC";
-    case NCR710_DBC_REG + 1:     return "DBC+1";
-    case NCR710_DBC_REG + 2:     return "DBC+2";
-    case NCR710_DCMD_REG:        return "DCMD";
-    case NCR710_DNAD_REG:        return "DNAD";
-    case NCR710_DNAD_REG + 1:    return "DNAD+1";
-    case NCR710_DNAD_REG + 2:    return "DNAD+2";
-    case NCR710_DNAD_REG + 3:    return "DNAD+3";
-    case NCR710_DSP_REG:         return "DSP";
-    case NCR710_DSP_REG + 1:     return "DSP+1";
-    case NCR710_DSP_REG + 2:     return "DSP+2";
-    case NCR710_DSP_REG + 3:     return "DSP+3";
-    case NCR710_DSPS_REG:        return "DSPS";
-    case NCR710_DSPS_REG + 1:    return "DSPS+1";
-    case NCR710_DSPS_REG + 2:    return "DSPS+2";
-    case NCR710_DSPS_REG + 3:    return "DSPS+3";
-    case NCR710_SCRATCH_REG:     return "SCRATCH";
-    case NCR710_SCRATCH_REG + 1: return "SCRATCH+1";
-    case NCR710_SCRATCH_REG + 2: return "SCRATCH+2";
-    case NCR710_SCRATCH_REG + 3: return "SCRATCH+3";
-    case NCR710_DMODE_REG:       return "DMODE";
-    case NCR710_DIEN_REG:        return "DIEN";
-    case NCR710_DWT_REG:         return "DWT";
-    case NCR710_DCNTL_REG:       return "DCNTL";
-    case NCR710_ADDER_REG:       return "ADDER";
-    case NCR710_ADDER_REG + 1:   return "ADDER+1";
-    case NCR710_ADDER_REG + 2:   return "ADDER+2";
-    case NCR710_ADDER_REG + 3:   return "ADDER+3";
-    default:                     return "UNKNOWN";
+    if (s->scripts_timer) {
+        timer_del(s->scripts_timer);
    }
 }
 
-static uint8_t ncr710_generate_scsi_parity(NCR710State *s, uint8_t data)
+static inline void lsi_mem_read(NCR710State *s, uint32_t addr,
+                                void *buf, uint32_t len)
 {
-    uint8_t parity = parity8(data);
-
-    if (s->scntl1 & NCR710_SCNTL1_AESP) {
-        parity = !parity;
-    }
-
-    return parity;
+    address_space_read(s->as, addr, MEMTXATTRS_UNSPECIFIED, buf, len);
 }
 
-static bool ncr710_check_scsi_parity(NCR710State *s, uint8_t data,
-                                     uint8_t parity)
+static inline void lsi_mem_write(NCR710State *s, uint32_t addr,
+                                 const void *buf, uint32_t len)
 {
-    if (!(s->scntl0 & NCR710_SCNTL0_EPC)) {
-        return true;
-    }
-
-    uint8_t expected_parity = ncr710_generate_scsi_parity(s, data);
-    return parity == expected_parity;
+    address_space_write(s->as, addr, MEMTXATTRS_UNSPECIFIED, buf, len);
 }
 
-static void ncr710_handle_parity_error(NCR710State *s)
-{
-    s->sstat0 |= NCR710_SSTAT0_PAR;
-
-    /* If parity error ATN is enabled, assert ATN */
-    if (s->scntl0 & NCR710_SCNTL0_AAP) {
-        s->socl |= NCR710_SOCL_ATN;
-    }
-
-    ncr710_script_scsi_interrupt(s, NCR710_SSTAT0_PAR);
-}
-
-/*
- * NCR710 SCSI FIFO IMPLEMENTATION
- *
- * Hardware Specifications (NCR53C710 datasheet):
- * - Width: 9 bits (8 data bits + 1 parity bit)
- * - Depth: 8 bytes
- * - Type: Circular buffer
- *
- * Implementation:
- * - Enqueue: Add byte at tail position ((head + count) % 8)
- * - Dequeue: Remove byte from head position, advance head
- * - Status: Empty (count=0), Full (count=8)
- *
- * FIFO Operations:
- * - ncr710_scsi_fifo_init()    - Reset FIFO to empty state
- * - ncr710_scsi_fifo_enqueue() - Add byte with parity to tail
- * - ncr710_scsi_fifo_dequeue() - Remove byte with parity from head
- * - ncr710_scsi_fifo_empty()   - Check if FIFO is empty
- * - ncr710_scsi_fifo_full()    - Check if FIFO is full
- */
-
-static void ncr710_scsi_fifo_init(NCR710_SCSI_FIFO *fifo)
-{
-    memset(fifo->data, 0, NCR710_SCSI_FIFO_SIZE);
-    memset(fifo->parity, 0, NCR710_SCSI_FIFO_SIZE);
-    fifo->head = 0;
-    fifo->count = 0;
-}
-
-static inline bool ncr710_scsi_fifo_empty(NCR710_SCSI_FIFO *fifo)
-{
-    return fifo->count == 0;
-}
-
-static inline bool ncr710_scsi_fifo_full(NCR710_SCSI_FIFO *fifo)
-{
-    return fifo->count == NCR710_SCSI_FIFO_SIZE;
-}
-
-static inline int ncr710_scsi_fifo_enqueue(NCR710_SCSI_FIFO *fifo,
-                                           uint8_t data, uint8_t parity)
-{
-    if (ncr710_scsi_fifo_full(fifo)) {
-        return -1; /* FIFO full - 8 transfers deep */
-    }
-
-    /* Add data at the tail (head + count) */
-    int tail_pos = (fifo->head + fifo->count) % NCR710_SCSI_FIFO_SIZE;
-    fifo->data[tail_pos] = data;
-    fifo->parity[tail_pos] = parity;
-    fifo->count++;
-
-    return 0;
-}
-
-static inline uint8_t ncr710_scsi_fifo_dequeue(NCR710_SCSI_FIFO *fifo,
-                                                uint8_t *parity)
-{
-    uint8_t data;
-
-    if (ncr710_scsi_fifo_empty(fifo)) {
-        *parity = 0;
-        return 0; /* FIFO empty */
-    }
-
-    /* Taking data from the head position */
-    data = fifo->data[fifo->head];
-    *parity = fifo->parity[fifo->head];
-    fifo->head = (fifo->head + 1) % NCR710_SCSI_FIFO_SIZE;
-    fifo->count--;
-
-    return data;
-}
-
-static inline uint32_t ncr710_read_dword(NCR710State *s, uint32_t addr)
+/* SCRIPTS and table indirect structures are built by the big endian CPU. */
+static inline uint32_t lsi_read_dword(NCR710State *s, uint32_t addr)
 {
    uint32_t buf;
-    address_space_read(s->as, addr, MEMTXATTRS_UNSPECIFIED,
-                       (uint8_t *)&buf, 4);
-    /*
-     * The NCR710 datasheet saying "operates internally in LE mode"
-     * refers to its internal register organization,
-     * not how it reads SCRIPTS from host memory.
-     */
-    buf = be32_to_cpu(buf);
-    NCR710_DPRINTF("Read dword %08x from %08x\n", buf, addr);
-    return buf;
+
+    address_space_read(s->as, addr, MEMTXATTRS_UNSPECIFIED, &buf, 4);
+    return be32_to_cpu(buf);
 }
 
-static inline void ncr710_dma_read(NCR710State *s, uint32_t addr,
-                                   void *buf, uint32_t len)
+static void lsi_stop_script(NCR710State *s)
 {
-    address_space_read(s->as, addr, MEMTXATTRS_UNSPECIFIED,
-                       buf, len);
-    NCR710_DPRINTF("Read %d bytes from %08x: ", len, addr);
-    for (int i = 0; i < len && i < 16; i++) {
-        NCR710_DPRINTF("%02x ", ((uint8_t *)buf)[i]);
-    }
-    NCR710_DPRINTF("\n");
+    s->script_running = false;
 }
 
-static inline void ncr710_dma_write(NCR710State *s, uint32_t addr,
-                                    const void *buf, uint32_t len)
-{
-    address_space_write(s->as, addr, MEMTXATTRS_UNSPECIFIED,
-                        buf, len);
-    NCR710_DPRINTF("Wrote %d bytes to %08x\n", len, addr);
-}
-
-static void ncr710_stop_script(NCR710State *s)
-{
-    s->script_active = 0;
-    s->scntl1 &= ~NCR710_SCNTL1_CON;
-    s->istat &= ~NCR710_ISTAT_CON;
-}
-
-static void ncr710_update_irq(NCR710State *s)
+static void lsi_update_irq(NCR710State *s)
 {
    int level = 0;
 
-    if (s->dstat & ~NCR710_DSTAT_DFE) {
+    if (s->dstat) {
        if (s->dstat & s->dien) {
            level = 1;
        }
-        s->istat |= NCR710_ISTAT_DIP;
+        s->istat |= LSI_ISTAT0_DIP;
    } else {
-        s->istat &= ~NCR710_ISTAT_DIP;
+        s->istat &= ~LSI_ISTAT0_DIP;
    }
 
    if (s->sstat0) {
-        if ((s->sstat0 & s->sien0)) {
+        if (s->sstat0 & s->sien) {
            level = 1;
        }
-        s->istat |= NCR710_ISTAT_SIP;
+        s->istat |= LSI_ISTAT0_SIP;
    } else {
-        s->istat &= ~NCR710_ISTAT_SIP;
+        s->istat &= ~LSI_ISTAT0_SIP;
    }
 
+    trace_ncr710_update_irq(level, s->istat, s->sstat0, s->dstat);
    qemu_set_irq(s->irq, level);
 }
 
-static void ncr710_script_scsi_interrupt(NCR710State *s, int stat0)
+/* Raise a SCSI interrupt and stop SCRIPTS on a fatal/unmasked condition. */
+static void lsi_script_scsi_interrupt(NCR710State *s, int stat0)
 {
-    uint32_t mask0;
+    uint8_t mask;
 
    trace_ncr710_script_scsi_interrupt(stat0, s->sstat0);
    s->sstat0 |= stat0;
-    mask0 = stat0 & s->sien0;
-    if (mask0) {
-        ncr710_stop_script(s);
-        s->istat |= NCR710_ISTAT_SIP;
-        ncr710_update_irq(s);
+    /*
+     * FCMP and SEL are nonfatal (only stop when enabled in SIEN); STO never
+     * stops here (execution continues until the next SCSI bus instruction).
+     */
+    mask = s->sien | (uint8_t)~(LSI_STAT0_FCMP | LSI_STAT0_SEL);
+    mask &= ~LSI_STAT0_STO;
+    if (s->sstat0 & mask) {
+        lsi_stop_script(s);
    }
+    lsi_update_irq(s);
 }
 
-static void ncr710_script_dma_interrupt(NCR710State *s, int stat)
+/* Raise a DMA interrupt and stop SCRIPTS (all DMA interrupts are fatal). */
+static void lsi_script_dma_interrupt(NCR710State *s, int stat)
 {
    trace_ncr710_script_dma_interrupt(stat, s->dstat);
-    if (stat == NCR710_DSTAT_SIR && (s->dstat & NCR710_DSTAT_DFE)) {
-        s->dstat &= ~NCR710_DSTAT_DFE;
-    }
-
    s->dstat |= stat;
-    s->istat |= NCR710_ISTAT_DIP;
-    ncr710_update_irq(s);
-    ncr710_stop_script(s);
+    lsi_update_irq(s);
+    lsi_stop_script(s);
 }
 
-inline void ncr710_set_phase(NCR710State *s, int phase)
+static void lsi_set_phase(NCR710State *s, int phase)
 {
+    trace_ncr710_set_phase(phase);
+    s->sbcl = (s->sbcl & ~PHASE_MASK) | phase | LSI_SBCL_REQ;
    s->sstat2 = (s->sstat2 & ~PHASE_MASK) | phase;
-    s->ctest0 &= ~1;
-    if (phase == PHASE_DI) {
-        s->ctest0 |= 1;
-    }
-    s->sbcl &= ~NCR710_SBCL_REQ;
 }
 
-static void ncr710_disconnect(NCR710State *s)
+/* 53C710 has no phase mismatch jump feature; a bad phase always interrupts. */
+static int lsi_bad_phase(NCR710State *s, int new_phase)
+{
+    lsi_script_scsi_interrupt(s, LSI_STAT0_MA);
+    lsi_stop_script(s);
+    lsi_set_phase(s, new_phase);
+    return 1;
+}
+
+static void lsi_resume_script(NCR710State *s)
+{
+    trace_ncr710_resume_script(s->waiting);
+    if (s->waiting != LSI_DMA_SCRIPTS) {
+        s->waiting = LSI_NOWAIT;
+        lsi_execute_script(s);
+    } else {
+        s->waiting = LSI_NOWAIT;
+    }
+}
+
+static void lsi_disconnect(NCR710State *s)
 {
    trace_ncr710_disconnect(s->waiting);
-    if (s->waiting == NCR710_WAIT_NONE) {
-        s->scntl1 &= ~NCR710_SCNTL1_CON;
-        s->istat &= ~NCR710_ISTAT_CON;
-    }
+    s->scntl1 &= ~LSI_SCNTL1_CON;
    s->sstat2 &= ~PHASE_MASK;
+    s->sbcl = 0;
 }
 
-static void ncr710_bad_selection(NCR710State *s, uint32_t id)
+static void lsi_bad_selection(NCR710State *s, uint32_t id)
 {
    trace_ncr710_bad_selection(id);
-    s->dstat = 0;
-    s->dsps = 0;
-    ncr710_script_scsi_interrupt(s, NCR710_SSTAT0_STO);
-    ncr710_disconnect(s);
+    lsi_script_scsi_interrupt(s, LSI_STAT0_STO);
+    lsi_disconnect(s);
 }
 
-static void ncr710_clear_selection_timeout(NCR710State *s)
-{
-    if (s->sstat0 & NCR710_SSTAT0_STO) {
-        s->sstat0 &= ~NCR710_SSTAT0_STO;
-        ncr710_clear_pending_irq(s);
-        if (s->sstat0 == 0) {
-            s->istat &= ~NCR710_ISTAT_SIP;

hw/scsi/ncr53c710.c line 278

Quoted 10 lines
hw/scsi/ncr53c710.c +1 -6
-        }
-        ncr710_update_irq(s);
-    }
-}
-
-static void ncr710_do_dma(NCR710State *s, int out)
+static void lsi_do_dma(NCR710State *s, int out)
 {
    uint32_t count;
    uint32_t addr;

lsi53c895a.c has dma_addr_t addr; here.

Regards,
BALATON Zoltan

#10 lore raw

RFC v4 8/14 hw/scsi/ncr53c710: Deliver completions from bottom halves

In reply to Philippe Mathieu-Daudé

From: Keith Monahan <[email protected]>

Completions are delivered asynchronously, as the real chip delivers them, rather than reentrantly inside the interpreter: a reselect reconnect and a tagged completion off host cached media (the install CD-ROM) are deferred to a bottom half. A reentrant completion would collapse the disconnect and the completion interrupt into the one guest MMIO write driving the engine and race the HP-UX 10.20 c720 driver's completion bookkeeping. Untagged and polled transfers keep inline completion.

A SIGP kick that lands on a stopped engine, rather than one parked at Wait Reselect, is held in sigp_pending_resume and replayed once the engine parks.

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
 hw/scsi/ncr53c710.h |  8 ++++
 hw/scsi/ncr53c710.c | 92 ++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 90 insertions(+), 10 deletions(-)
hw/scsi/ncr53c710.h +8 -0
index 82202940caa6..8b5cbfc135e3 100644
@@ -93,6 +93,14 @@ typedef struct NCR710State {
     uint32_t select_tag;
     int command_complete;
     bool script_running;
+    /*
+     * A SIGP arrived while the engine was halted instead of parked at Wait
+     * Reselect; the Wait Reselect handler consumes it when the engine next
+     * parks.
+     */
+    bool sigp_pending_resume;
+    /* A SCSI continue was deferred to lsi_issue_bh. */
+    bool issue_pending;
     lsi_request *current;
     /* Disconnected tagged commands awaiting reselection. */
     QTAILQ_HEAD(, lsi_request) queue;
hw/scsi/ncr53c710.c +82 -10

154 lines not on this page · raw message

Signature · 1 line
2.55.0
#11 lore raw

RFC v4 9/14 hw/scsi/ncr53c710: Drain asynchronous transfers in the register write

In reply to Philippe Mathieu-Daudé

From: Keith Monahan <[email protected]>

The c720 driver of HP-UX 10.20 needs the completion interrupt ordering hardware provides, starting a command with interrupts masked and then spinning. So after a register write starts an asynchronous transfer the model drives it to completion before returning to the guest (a bounded synchronous drain under the BQL, as IDE and MegaSAS do, falling back to asynchronous completion if it cannot advance).

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
 hw/scsi/ncr53c710.c  | 29 +++++++++++++++++++++++++++++
 hw/scsi/trace-events |  1 +
 2 files changed, 30 insertions(+)
hw/scsi/ncr53c710.c +29 -0
index b9ebeb4d96dc..9ca025ff6334 100644
@@ -53,6 +53,12 @@
 
 #define LSI_BUF_SIZE     4096
 
+/*
+ * Safety bound on the synchronous completion drain loop in ncr710_reg_write();
+ * it then falls back to asynchronous completion.
+ */
+#define LSI_DRAIN_MAX_ITERS  100000
+
 static const char *const lsi_reg_names[64] = {
     "SCNTL0", "SCNTL1", "SDID", "SIEN", "SCID", "SXFER", "SODL", "SOCL",
     "SFBR", "SIDL", "SBDL", "SBCL", "DSTAT", "SSTAT0", "SSTAT1", "SSTAT2",
@@ -1552,7 +1558,30 @@ uint64_t ncr710_reg_read(NCR710State *s, hwaddr addr, unsigned size)
 
 void ncr710_reg_write(NCR710State *s, hwaddr addr, uint64_t val, unsigned size)
 {
+    unsigned drained = 0;
+
     lsi_reg_writeb(s, addr & 0xff, val & 0xff);
+
+    /*
+     * Drive any asynchronous SCSI transfer the register write kicked off to
+     * completion before returning to the guest, so its completion interrupt is
+     * raised first.  A deferred continue (lsi_issue_bh) has not issued its
+     * backing I/O yet, so pump it inline; otherwise blk_drain the backend.
+     */
+    while (s->waiting == LSI_DMA_IN_PROGRESS && s->current != NULL &&
+           s->current->req != NULL) {
+        if (drained++ >= LSI_DRAIN_MAX_ITERS) {
+            trace_ncr710_drain_exhausted(drained);
+            break;
+        }
+        if (s->issue_pending) {
+            lsi_issue_bh(s);
+        } else if (s->current->req->dev->conf.blk != NULL) {
+            blk_drain(s->current->req->dev->conf.blk);
+        } else {
+            break;      /* nothing deferred and no backend to drain */
+        }
+    }
 }
 
 static int lsi_pre_save(void *opaque)
hw/scsi/trace-events +1 -0
index f0eb1457022e..843d8f1a1e27 100644
@@ -340,6 +340,7 @@ ncr710_memmove(uint32_t dest, uint32_t src, int count) "MOVE MEMORY dest=0x%08x
 ncr710_do_dma_unavailable(void) "DMA: data not yet available"
 ncr710_wait_disconnect(void) "Wait Disconnect"
 ncr710_illegal_insn(uint32_t insn) "ILLEGAL instruction 0x%08x"
+ncr710_drain_exhausted(unsigned iters) "synchronous completion drain gave up after %u iters"
 
 # lasi_ncr710.c
 lasi_ncr710_device_realize(void) "Device realized"
Signature · 1 line
2.55.0
#12 lore raw

RFC v4 10/14 hw/scsi/ncr53c710: Append SAVE DATA POINTERS after MESSAGE REJECT for HP-UX

In reply to Philippe Mathieu-Daudé

From: Keith Monahan <[email protected]>

The HP-UX 10.20 install kernel is nonconformant: its self modifying SCRIPTS reads a second message byte after the MESSAGE REJECT that declines SDTR/WDTR/PPR negotiation and hangs unless it is SAVE DATA POINTERS, while NetBSD's osiop resets the bus if it sees that byte. The two are told apart by ATN state as the reject is consumed (HP-UX has deasserted ATN, a conformant initiator has not), so the extra byte is appended only for HP-UX.

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
 hw/scsi/ncr53c710.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
hw/scsi/ncr53c710.c +10 -1
index 9ca025ff6334..dfed2f2f9fdd 100644
@@ -699,6 +699,10 @@ static void lsi_do_msgin(NCR710State *s)
     if (!s->msg_len) {
         switch (s->msg_action) {
         case LSI_MSG_ACTION_COMMAND:
+            /* A MESSAGE REJECT declining negotiation was just consumed. */
+            if (s->sfbr == 7 && !(s->socl & LSI_SOCL_ATN)) {
+                lsi_add_msg_byte(s, 2);   /* SAVE DATA POINTERS (HP-UX) */
+            }
             /* Stay in MSG IN until the next block move requests COMMAND. */
             break;
         case LSI_MSG_ACTION_DISCONNECT:
@@ -794,7 +798,12 @@ static void lsi_do_msgout(NCR710State *s)
     }
     return;
 reject:
-    /* Decline SDTR/WDTR/PPR negotiation with a single MESSAGE REJECT. */
+    /*
+     * Decline SDTR/WDTR/PPR negotiation with a single MESSAGE REJECT.  HP-UX
+     * requires a trailing SAVE DATA POINTERS (0x02), which other initiators
+     * reject.  HP-UX reads the reject with ATN deasserted, so lsi_do_msgin
+     * appends the 0x02 only then.
+     */
     lsi_set_phase(s, PHASE_MI);
     lsi_add_msg_byte(s, 7);           /* MESSAGE REJECT */
     s->msg_action = LSI_MSG_ACTION_COMMAND;
Signature · 1 line
2.55.0
#13 lore raw

RFC v4 11/14 hw/scsi/ncr53c710: Guard SCRIPTS reentrancy and cancel requests on soft reset

In reply to Philippe Mathieu-Daudé

From: Keith Monahan <[email protected]>

The interpreter guards the reentrancy class behind CVE-2023-0330: a completion that fires synchronously while lsi_execute_script is already on the stack no longer recurses, and a script that retriggers itself is bounded by a recursion depth limit.

A guest ISTAT.RST soft reset cancels the connected and any queued tagged requests, so a stale s->current cannot dangle into the next command and queued requests are not leaked, mirroring the SCNTL1.RST bus reset teardown.

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
 hw/scsi/ncr53c710.h |  5 +++++
 hw/scsi/ncr53c710.c | 41 +++++++++++++++++++++++++++++++++++++++--
 2 files changed, 44 insertions(+), 2 deletions(-)
hw/scsi/ncr53c710.h +5 -0
index 8b5cbfc135e3..9a4816794e1d 100644
@@ -101,6 +101,11 @@ typedef struct NCR710State {
     bool sigp_pending_resume;
     /* A SCSI continue was deferred to lsi_issue_bh. */
     bool issue_pending;
+    /*
+     * SCRIPTS interpreter recursion depth; always 0 outside
+     * lsi_execute_script, so it is not migrated.
+     */
+    int reentrancy_level;
     lsi_request *current;
     /* Disconnected tagged commands awaiting reselection. */
     QTAILQ_HEAD(, lsi_request) queue;
hw/scsi/ncr53c710.c +39 -2

78 lines not on this page · raw message

Signature · 1 line
2.55.0
#14 lore raw

Re: [RFC PATCH-for-11.2? v4 11/14] hw/scsi/ncr53c710: Guard SCRIPTS reentrancy and cancel requests on soft reset

Quoted 6 lines · Philippe Mathieu-Daudé

From: Keith Monahan <[email protected]>

The interpreter guards the reentrancy class behind CVE-2023-0330: a completion that fires synchronously while lsi_execute_script is already on the stack no longer recurses, and a script that retriggers itself is bounded by a recursion depth limit.

I don't understand this sentence above. Does it make sense or could it be clarified?

Regards,
BALATON Zoltan

Quoted 118 lines

A guest ISTAT.RST soft reset cancels the connected and any queued tagged requests, so a stale s->current cannot dangle into the next command and queued requests are not leaked, mirroring the SCNTL1.RST bus reset teardown.

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
hw/scsi/ncr53c710.h | 5 +++++
hw/scsi/ncr53c710.c | 41 +++++++++++++++++++++++++++++++++++++++--

2 files changed, 44 insertions(+), 2 deletions(-)
hw/scsi/ncr53c710.h +5 -0
index 8b5cbfc135e3..9a4816794e1d 100644
@@ -101,6 +101,11 @@ typedef struct NCR710State {
    bool sigp_pending_resume;
    /* A SCSI continue was deferred to lsi_issue_bh. */
    bool issue_pending;
+    /*
+     * SCRIPTS interpreter recursion depth; always 0 outside
+     * lsi_execute_script, so it is not migrated.
+     */
+    int reentrancy_level;
    lsi_request *current;
    /* Disconnected tagged commands awaiting reselection. */
    QTAILQ_HEAD(, lsi_request) queue;
hw/scsi/ncr53c710.c +31 -0
index dfed2f2f9fdd..f75540da7720 100644
@@ -103,8 +103,23 @@ static int lsi_id_from_bits(unsigned bits)
 
 void ncr710_soft_reset(NCR710State *s)
 {
+    lsi_request *p, *p_next;
+
    trace_ncr710_reset();
 
+    /*
+     * A guest ISTAT.RST soft reset can land with commands still in flight.
+     * Cancel them so no stale pointer survives the reset.
+     */
+    if (s->current && s->current->req) {
+        scsi_req_cancel(s->current->req);
+    }
+    QTAILQ_FOREACH_SAFE(p, &s->queue, next, p_next) {
+        if (p->req) {
+            scsi_req_cancel(p->req);
+        }
+    }
+
    s->carry = 0;
    s->msg_action = LSI_MSG_ACTION_COMMAND;
    s->msg_len = 0;
@@ -114,6 +129,11 @@ void ncr710_soft_reset(NCR710State *s)
    s->command_complete = 0;
    s->script_running = false;
    s->sigp_pending_resume = false;
+    /*
+     * Do not reset reentrancy_level here.  A SCRIPTS driven soft reset can run
+     * while lsi_execute_script frames are still on the stack; those frames
+     * decrement the counter as they unwind.
+     */
 
    s->scntl0 = 0xc0;       /* full arbitration */
    s->scntl1 = 0;
@@ -257,6 +277,16 @@ static int lsi_bad_phase(NCR710State *s, int new_phase)
 static void lsi_resume_script(NCR710State *s)
 {
    trace_ncr710_resume_script(s->waiting);
+    if (s->reentrancy_level > 0) {
+        /*
+         * A completion fired synchronously while the SCRIPTS interpreter is
+         * already on the stack.  Do not recurse: release the wait so the outer
+         * loop continues to the next instruction, which the completion has
+         * already armed.
+         */
+        s->waiting = LSI_NOWAIT;
+        return;
+    }
    if (s->waiting != LSI_DMA_SCRIPTS) {
        s->waiting = LSI_NOWAIT;
        lsi_execute_script(s);
@@ -857,13 +887,18 @@ static void lsi_execute_script(NCR710State *s)
        s->waiting = LSI_NOWAIT;
    }
 
+    s->reentrancy_level++;
    s->script_running = true;

again:

hw/scsi/ncr53c710.c +8 -2
-    /* Yield to the CPU after LSI_MAX_INSN instructions. */
-    if (++insn_processed > LSI_MAX_INSN) {
+    /*
+     * Yield to the CPU after LSI_MAX_INSN instructions, and guard against a
+     * script that retriggers itself (CVE-2023-0330).
+     */
+    if (++insn_processed > LSI_MAX_INSN || s->reentrancy_level > 8) {
        trace_ncr710_script_yield(insn_processed);
        s->waiting = LSI_WAIT_SCRIPTS;
        lsi_scripts_timer_start(s);
+        s->reentrancy_level--;
        return;
    }
@@ -1209,6 +1244,8 @@ again:
            goto again;
        }
    }
+
+    s->reentrancy_level--;
 }
 
 static uint8_t lsi_reg_readb(NCR710State *s, int offset)
#15 lore raw

Re: [RFC PATCH-for-11.2? v4 11/14] hw/scsi/ncr53c710: Guard SCRIPTS reentrancy and cancel requests on soft reset

Thanks Zoltan, Philippe and everyone for their help with this.

I apologize if you already know the background info I'm giving below.

Quoted 9 lines · BALATON Zoltan
Quoted 6 lines · Philippe Mathieu-Daudé

From: Keith Monahan <[email protected]>

The interpreter guards the reentrancy class behind CVE-2023-0330: a completion that fires synchronously while lsi_execute_script is already on the stack no longer recurses, and a script that retriggers itself is bounded by a recursion depth limit.

I don't understand this sentence above. Does it make sense or could it be clarified?

This is a vulnerability found a few years ago, which affects the 895. A malicious guest could, on purpose, crash the host QEMU process by repeated nested controller restarts, which would eventually exhaust the stack.

QEMU added a generic restriction, where a device can't trigger its own control registers, while handling an access to them. This won't work for the 895, because real drivers need to access to the chip's own registers. So instead, they put a limit into the 895 model, and once it gets to 8 levels deep, it stops.

The 710 accesses its registers internally, but not through memory, so the global QEMU rule is ok here. Limiting the nesting to 8 levels, like the 895, isn't enough. One level can run part of the SCRIPTS program twice. During testing, this broke the timing the HP-UX driver relies on, and was hanging the install. My solution was to not let command completions nest, but instead deliver command completions afterwards, which is closer to the way the hardware works anyway. I kept the 8-level limit in the 710 just as a backstop.

So given all this, how about something like

The SCRIPTS interpreter guards against CVE-2023-0330. When a command finishes while the interpreter is running, the interpreter moves on to the next instruction without restarting itself. If a script keeps triggering itself, the interpreter stops it after 8 nested restarts.

Is that better?

Thanks,
Keith

Quoted 130 lines

Regards,
BALATON Zoltan

Quoted 126 lines

A guest ISTAT.RST soft reset cancels the connected and any queued tagged requests, so a stale s->current cannot dangle into the next command and queued requests are not leaked, mirroring the SCNTL1.RST bus reset teardown.

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
hw/scsi/ncr53c710.h |  5 +++++
hw/scsi/ncr53c710.c | 41 +++++++++++++++++++++++++++++++++++++++--

2 files changed, 44 insertions(+), 2 deletions(-)
hw/scsi/ncr53c710.h +5 -0
index 8b5cbfc135e3..9a4816794e1d 100644
@@ -101,6 +101,11 @@ typedef struct NCR710State {
     bool sigp_pending_resume;
     /* A SCSI continue was deferred to lsi_issue_bh. */
     bool issue_pending;
+    /*
+     * SCRIPTS interpreter recursion depth; always 0 outside
+     * lsi_execute_script, so it is not migrated.
+     */
+    int reentrancy_level;
     lsi_request *current;
     /* Disconnected tagged commands awaiting reselection. */
     QTAILQ_HEAD(, lsi_request) queue;
hw/scsi/ncr53c710.c +4 -0
index dfed2f2f9fdd..f75540da7720 100644
@@ -103,8 +103,23 @@ static int lsi_id_from_bits(unsigned bits)
 
 void ncr710_soft_reset(NCR710State *s)
 {
+    lsi_request *p, *p_next;
+
     trace_ncr710_reset();
 
+    /*
+     * A guest ISTAT.RST soft reset can land with commands still in 

flight.
+     * Cancel them so no stale pointer survives the reset. +     */
+    if (s->current && s->current->req) {
+        scsi_req_cancel(s->current->req);
+    }
+    QTAILQ_FOREACH_SAFE(p, &s->queue, next, p_next) { +        if (p->req) {
+            scsi_req_cancel(p->req);
+        }
+    }
+
    s->carry = 0;
    s->msg_action = LSI_MSG_ACTION_COMMAND; s->msg_len = 0;

hw/scsi/ncr53c710.c +2 -0
@@ -114,6 +129,11 @@ void ncr710_soft_reset(NCR710State *s)
     s->command_complete = 0;
     s->script_running = false;
     s->sigp_pending_resume = false;
+    /*
+     * Do not reset reentrancy_level here.  A SCRIPTS driven soft 

reset can run
+     * while lsi_execute_script frames are still on the stack; those frames
+     * decrement the counter as they unwind.
+     */

    s->scntl0 = 0xc0;       /* full arbitration */ s->scntl1 = 0;

hw/scsi/ncr53c710.c +3 -0
@@ -257,6 +277,16 @@ static int lsi_bad_phase(NCR710State *s, int 
 new_phase)
 static void lsi_resume_script(NCR710State *s)
 {
     trace_ncr710_resume_script(s->waiting);
+    if (s->reentrancy_level > 0) {
+        /*
+         * A completion fired synchronously while the SCRIPTS 

interpreter is
+         * already on the stack.  Do not recurse: release the wait so the outer
+         * loop continues to the next instruction, which the completion has
+         * already armed.
+         */
+        s->waiting = LSI_NOWAIT;
+        return;
+    }
    if (s->waiting != LSI_DMA_SCRIPTS) {
        s->waiting = LSI_NOWAIT;
        lsi_execute_script(s);

hw/scsi/ncr53c710.c +1 -0
@@ -857,13 +887,18 @@ static void lsi_execute_script(NCR710State *s)
         s->waiting = LSI_NOWAIT;
     }
 
+    s->reentrancy_level++;
     s->script_running = true;

again:
-    /* Yield to the CPU after LSI_MAX_INSN instructions. */ -    if (++insn_processed > LSI_MAX_INSN) {
+    /*
+     * Yield to the CPU after LSI_MAX_INSN instructions, and guard against a
+     * script that retriggers itself (CVE-2023-0330).
+     */
+    if (++insn_processed > LSI_MAX_INSN || s->reentrancy_level > 8) { trace_ncr710_script_yield(insn_processed); s->waiting = LSI_WAIT_SCRIPTS; lsi_scripts_timer_start(s);
+        s->reentrancy_level--;
        return;
    }

hw/scsi/ncr53c710.c +2 -0
@@ -1209,6 +1244,8 @@ again:
             goto again;
         }
     }
+
+    s->reentrancy_level--;
 }
 
 static uint8_t lsi_reg_readb(NCR710State *s, int offset)
#16 lore raw

RFC v4 12/14 hw/scsi/lasi_ncr710: Map the full LASI SCSI module page

In reply to Philippe Mathieu-Daudé

From: Keith Monahan <[email protected]>

0x100..0x1ff goes to the chip core as before. The rest of the module page reads as 0: HP-UX reads a board strap at 0xd85 (bit 0x20:
differential bus, 25 MHz clock); 0 is single ended, 50 MHz.

0x10..0xff and 0x200..0xfff are unmapped module space. Writes to all of them are ignored.

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
 hw/scsi/lasi_ncr710.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
hw/scsi/lasi_ncr710.c +11 -4
index cbb04017ce9c..c8a28cd987b8 100644
@@ -45,7 +45,8 @@ static uint64_t lasi_ncr710_reg_read(void *opaque, hwaddr addr,
         return val;
     }
 
-    if (addr >= 0x100) {
+    /* 0x100..0x1ff goes to the chip core. */
+    if (addr >= 0x100 && addr + size <= 0x200) {
         hwaddr ncr_addr = addr - 0x100;
         if (size == 1) {
             /*
@@ -68,6 +69,11 @@ static uint64_t lasi_ncr710_reg_read(void *opaque, hwaddr addr,
 
         trace_lasi_ncr710_reg_forward_read(addr, val);
     } else {
+        /*
+         * The rest of the module page reads as 0.  HP-UX reads a board strap
+         * at 0xd85 (bit 0x20: differential bus, 25 MHz clock); 0 is single
+         * ended, 50 MHz.
+         */
         val = 0;
         trace_lasi_ncr710_reg_read(addr, val, size);
     }
@@ -83,13 +89,14 @@ static void lasi_ncr710_reg_write(void *opaque, hwaddr addr,
 
     /*
      * 0x00..0x0f is the read only LASI module header (ID/SVERSION/HVERSION);
-     * writes to it are ignored.
+     * 0x10..0xff and 0x200..0xfff are unmapped module space.  Writes to all
+     * of them are ignored.
      */
     if (addr <= 0x0f) {
         return;
     }
 
-    if (addr >= 0x100) {
+    if (addr >= 0x100 && addr + size <= 0x200) {
         hwaddr ncr_addr = addr - 0x100;
 
         if (size == 1) {
@@ -191,7 +198,7 @@ static void lasi_ncr710_realize(DeviceState *dev, Error **errp)
         (uint64_t)s->ncr710.scripts_timer);
 
     memory_region_init_io(&s->mmio, OBJECT(dev), &lasi_ncr710_mmio_ops, s,
-                          "lasi-ncr710", 0x200);
+                          "lasi-ncr710", 0x1000);
     sysbus_init_mmio(sbd, &s->mmio);
 }
 
Signature · 1 line
2.55.0
#17 lore raw

RFC v4 13/14 hw/scsi/ncr53c710: Document the SIGP latch deviation

In reply to Philippe Mathieu-Daudé

Comment only, no functional change. The data manual describes SIGP (ISTAT bit 5) as a read/write flag that stays set until reset by the CPU, either through ISTAT or by reading CTEST2. The emulation drops the bit at once when it is set while the engine is halted and remembers the kick in sigp_pending_resume instead. Note the deviation at the code. The reason is not documented in the history.

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
 hw/scsi/ncr53c710.c | 8 ++++++++
 1 file changed, 8 insertions(+)
hw/scsi/ncr53c710.c +8 -0
index f75540da7720..af26d26a05bb 100644
@@ -1524,6 +1524,14 @@ static void lsi_reg_writeb(NCR710State *s, int offset, uint8_t val)
              * Reselect consumption would, without disturbing the pending
              * completion.  Remember the kick so the next command is selected
              * once the engine parks again at Wait Reselect.
+             *
+             * This deviates from the data manual, which describes SIGP as a
+             * read/write flag that stays set until the CPU resets it, either
+             * via ISTAT or by reading CTEST2: here a halted engine drops the
+             * bit at once, so a read of ISTAT or CTEST2 no longer sees it.
+             * The reason is not documented beyond the commit that added
+             * sigp_pending_resume (6bf09c62fa), which only says that a kick
+             * on a stopped engine is held and replayed once the engine parks.
              */
             s->istat &= ~LSI_ISTAT0_SIGP;
             s->sigp_pending_resume = true;
Signature · 1 line
2.55.0
#18 lore raw

RFC v4 14/14 hw/scsi/ncr53c710: Bump the migration version

In reply to Philippe Mathieu-Daudé

From: Keith Monahan <[email protected]>

The migration format is incompatible with the model this replaces, so the ncr710 and lasi_ncr710 vmstate descriptions raise minimum_version_id in lockstep: an old stream is rejected rather than silently misparsed. sigp_pending_resume is a version 3 field: a deferred SIGP kick can be live across a migration point.

Intermediate patches of this series do not preserve migration streams.

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
 hw/scsi/lasi_ncr710.c |  4 ++--
 hw/scsi/ncr53c710.c   | 11 ++++++++---
 2 files changed, 10 insertions(+), 5 deletions(-)
hw/scsi/lasi_ncr710.c +2 -2
index c8a28cd987b8..62608d039c1e 100644
@@ -163,8 +163,8 @@ static const MemoryRegionOps lasi_ncr710_mmio_ops = {
 
 static const VMStateDescription vmstate_lasi_ncr710 = {
     .name = "lasi-ncr710",
-    .version_id = 1,
-    .minimum_version_id = 1,
+    .version_id = 2,
+    .minimum_version_id = 2,
     .fields = (const VMStateField[]) {
         VMSTATE_STRUCT(ncr710, LasiNCR710State, 1, vmstate_ncr710, NCR710State),
         VMSTATE_END_OF_LIST()
hw/scsi/ncr53c710.c +8 -3
index af26d26a05bb..4a37d011f229 100644
@@ -1674,8 +1674,9 @@ static int lsi_post_load(void *opaque, int version_id)
 
 const VMStateDescription vmstate_ncr710 = {
     .name = "ncr710",
-    .version_id = 1,
-    .minimum_version_id = 1,
+    /* minimum_version_id rejects streams from the earlier 53C710 model. */
+    .version_id = 3,
+    .minimum_version_id = 2,
     .pre_save = lsi_pre_save,
     .post_load = lsi_post_load,
     .fields = (const VMStateField[]) {
@@ -1689,7 +1690,11 @@ const VMStateDescription vmstate_ncr710 = {
         VMSTATE_UINT32(select_tag, NCR710State),
         VMSTATE_INT32(command_complete, NCR710State),
         VMSTATE_BOOL(script_running, NCR710State),
-        VMSTATE_BOOL(sigp_pending_resume, NCR710State),
+        /*
+         * Version 3+.  A deferred SIGP kick can be live across a migration
+         * point.
+         */
+        VMSTATE_BOOL_V(sigp_pending_resume, NCR710State, 3),
 
         VMSTATE_UINT8(scntl0, NCR710State),
         VMSTATE_UINT8(scntl1, NCR710State),
Signature · 1 line
2.55.0
#19 lore raw

Re: [RFC PATCH-for-11.2? v4 14/14] hw/scsi/ncr53c710: Bump the migration version

Quoted 9 lines · Philippe Mathieu-Daudé

From: Keith Monahan <[email protected]>

The migration format is incompatible with the model this replaces, so the ncr710 and lasi_ncr710 vmstate descriptions raise minimum_version_id in lockstep: an old stream is rejected rather than silently misparsed. sigp_pending_resume is a version 3 field: a deferred SIGP kick can be live across a migration point.

Intermediate patches of this series do not preserve migration streams.

Should this be squashed in the patch that changes the VMState (i.e. patch 7) or come right after it instead of at end of series? Also why there is version 3 when there are only two versions?

Regards,
BALATON Zoltan

Quoted 54 lines

AI-used-for: Patch series decomposition (commit splitting and ordering)

---
hw/scsi/lasi_ncr710.c | 4 ++--
hw/scsi/ncr53c710.c | 11 ++++++++---

2 files changed, 10 insertions(+), 5 deletions(-)
hw/scsi/lasi_ncr710.c +2 -2
index c8a28cd987b8..62608d039c1e 100644
@@ -163,8 +163,8 @@ static const MemoryRegionOps lasi_ncr710_mmio_ops = {
 
 static const VMStateDescription vmstate_lasi_ncr710 = {
    .name = "lasi-ncr710",
-    .version_id = 1,
-    .minimum_version_id = 1,
+    .version_id = 2,
+    .minimum_version_id = 2,
    .fields = (const VMStateField[]) {
        VMSTATE_STRUCT(ncr710, LasiNCR710State, 1, vmstate_ncr710, NCR710State),
        VMSTATE_END_OF_LIST()
hw/scsi/ncr53c710.c +8 -3
index af26d26a05bb..4a37d011f229 100644
@@ -1674,8 +1674,9 @@ static int lsi_post_load(void *opaque, int version_id)
 
 const VMStateDescription vmstate_ncr710 = {
    .name = "ncr710",
-    .version_id = 1,
-    .minimum_version_id = 1,
+    /* minimum_version_id rejects streams from the earlier 53C710 model. */
+    .version_id = 3,
+    .minimum_version_id = 2,
    .pre_save = lsi_pre_save,
    .post_load = lsi_post_load,
    .fields = (const VMStateField[]) {
@@ -1689,7 +1690,11 @@ const VMStateDescription vmstate_ncr710 = {
        VMSTATE_UINT32(select_tag, NCR710State),
        VMSTATE_INT32(command_complete, NCR710State),
        VMSTATE_BOOL(script_running, NCR710State),
-        VMSTATE_BOOL(sigp_pending_resume, NCR710State),
+        /*
+         * Version 3+.  A deferred SIGP kick can be live across a migration
+         * point.
+         */
+        VMSTATE_BOOL_V(sigp_pending_resume, NCR710State, 3),
 
        VMSTATE_UINT8(scntl0, NCR710State),
        VMSTATE_UINT8(scntl1, NCR710State),
#20 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 28 lines · Philippe Mathieu-Daudé

Fourth attempt to replace the existing 53c710 driver by a new driver based on the code of the lsi53c895a.c :)

Used LLM to decompose v3 as logical / atomic changes when possible (didn't work well with the rewrite patch).

Fixes extracted first so could be merged for v11.2 (patches 1 to 5). The rest is the rewrite, so up to the maintainers (Helge, Mark) and is probably OK as hobbyist-only code.

Since v3:
- header split, Suggested-by tag (Zoltan)
- I couldn't figure the "hw/misc/lasi.c" change so dropped the comment about it.
- Dropped "move to COMMAND on CLEAR ACK after MESSAGE REJECT"
- Split rewrite patch as separated commits:
- base engine
- asynchronous completions
- synchronous drain
- HP-UX MESSAGE REJECT quirk
- reentrancy guard and reset-time request cancel

hw/scsi/ncr53c710.c is derived from hw/scsi/lsi53c895a.c which is LGPL, the rewrite is now declared GPL-2.0-or-later. hw/scsi/lsi_scsi.h, which is moved verbatim from lsi53c895a.c, keeps the original terms: its header says "This code is licensed under the LGPL." with SPDX-License-Identifier: LGPL-2.1-or-later.

Quoted 3 lines

Series reviewed against the NCR 53C710 data manual but totally untested (I don't have guest code to run), thus compile-checked only. I haven't tested whether the series is bisectable.

This is only a split experiment if Helge/Keith/Mark/Zoltan want to pursue, I'm not going to respin.

Quoted 14 lines

Keith Monahan (9):
hw/scsi/scsi-disk: Add quirk_mode_page_no_flexible_disk, use it on the

     715

hw/scsi: Move shared LSI/NCR definitions to lsi_scsi.h hw/scsi/ncr53c710: Rewrite the 53C710 SCRIPTS engine hw/scsi/ncr53c710: Deliver completions from bottom halves hw/scsi/ncr53c710: Drain asynchronous transfers in the register write hw/scsi/ncr53c710: Append SAVE DATA POINTERS after MESSAGE REJECT for
HP-UX
hw/scsi/ncr53c710: Guard SCRIPTS reentrancy and cancel requests on
soft reset
hw/scsi/lasi_ncr710: Map the full LASI SCSI module page hw/scsi/ncr53c710: Bump the migration version

Quoted 1 line

Philippe Mathieu-Daudé (5):

Oops here author should be Keith Monahan?

Quoted 7 lines

hw/scsi/ncr53c710: Cancel the in-flight request on soft reset hw/scsi/ncr53c710: Do not load SBCL from DBC after a SCRIPTS phase
move
hw/scsi/lasi_ncr710: Limit max_target and max_lun to 7 hw/scsi/ncr53c710: Keep DCNTL.EA and DMODE.FC1 across an ISTAT.RST
reset
hw/scsi/ncr53c710: Document the SIGP latch deviation

#21 lore raw
Quoted 29 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Philippe Mathieu-Daudé

Fourth attempt to replace the existing 53c710 driver by a new driver based on the code of the lsi53c895a.c :)

Used LLM to decompose v3 as logical / atomic changes when possible (didn't work well with the rewrite patch).

Fixes extracted first so could be merged for v11.2 (patches 1 to 5). The rest is the rewrite, so up to the maintainers (Helge, Mark) and is probably OK as hobbyist-only code.

Since v3:
- header split, Suggested-by tag (Zoltan)
- I couldn't figure the "hw/misc/lasi.c" change so dropped the comment about it.
- Dropped "move to COMMAND on CLEAR ACK after MESSAGE REJECT"
- Split rewrite patch as separated commits:
- base engine
- asynchronous completions
- synchronous drain
- HP-UX MESSAGE REJECT quirk
- reentrancy guard and reset-time request cancel

hw/scsi/ncr53c710.c is derived from hw/scsi/lsi53c895a.c which is LGPL, the rewrite is now declared GPL-2.0-or-later. hw/scsi/lsi_scsi.h, which is moved verbatim from lsi53c895a.c, keeps the original terms: its header says "This code is licensed under the LGPL." with SPDX-License-Identifier: LGPL-2.1-or-later.

Quoted 6 lines
Quoted 3 lines

Series reviewed against the NCR 53C710 data manual but totally untested (I don't have guest code to run), thus compile-checked only. I haven't tested whether the series is bisectable.

This is only a split experiment if Helge/Keith/Mark/Zoltan want to pursue, I'm not going to respin.

This helps reviewing but not perfect yet so if nobody is going to take it and make a v2 then it's a dead end. I added some comments nevertheless if somebody can do something about that.

Regards,
BALATON Zoltan

Quoted 27 lines
Quoted 14 lines

Keith Monahan (9):
hw/scsi/scsi-disk: Add quirk_mode_page_no_flexible_disk, use it on the

     715

hw/scsi: Move shared LSI/NCR definitions to lsi_scsi.h hw/scsi/ncr53c710: Rewrite the 53C710 SCRIPTS engine hw/scsi/ncr53c710: Deliver completions from bottom halves hw/scsi/ncr53c710: Drain asynchronous transfers in the register write hw/scsi/ncr53c710: Append SAVE DATA POINTERS after MESSAGE REJECT for
HP-UX
hw/scsi/ncr53c710: Guard SCRIPTS reentrancy and cancel requests on
soft reset
hw/scsi/lasi_ncr710: Map the full LASI SCSI module page hw/scsi/ncr53c710: Bump the migration version

Quoted 1 line

Philippe Mathieu-Daudé (5):

Oops here author should be Keith Monahan?

Quoted 7 lines

hw/scsi/ncr53c710: Cancel the in-flight request on soft reset hw/scsi/ncr53c710: Do not load SBCL from DBC after a SCRIPTS phase
move
hw/scsi/lasi_ncr710: Limit max_target and max_lun to 7 hw/scsi/ncr53c710: Keep DCNTL.EA and DMODE.FC1 across an ISTAT.RST
reset
hw/scsi/ncr53c710: Document the SIGP latch deviation

#22 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 29 lines · Philippe Mathieu-Daudé
Quoted 28 lines · Philippe Mathieu-Daudé

Fourth attempt to replace the existing 53c710 driver by a new driver based on the code of the lsi53c895a.c :)

Used LLM to decompose v3 as logical / atomic changes when possible (didn't work well with the rewrite patch).

Fixes extracted first so could be merged for v11.2 (patches 1 to 5). The rest is the rewrite, so up to the maintainers (Helge, Mark) and is probably OK as hobbyist-only code.

Since v3:
- header split, Suggested-by tag (Zoltan)
- I couldn't figure the "hw/misc/lasi.c" change so dropped the comment about it.
- Dropped "move to COMMAND on CLEAR ACK after MESSAGE REJECT"
- Split rewrite patch as separated commits:
    - base engine
    - asynchronous completions
    - synchronous drain
    - HP-UX MESSAGE REJECT quirk
    - reentrancy guard and reset-time request cancel

hw/scsi/ncr53c710.c is derived from hw/scsi/lsi53c895a.c which is LGPL, the rewrite is now declared GPL-2.0-or-later. hw/scsi/lsi_scsi.h, which is moved verbatim from lsi53c895a.c, keeps the original terms: its header says "This code is licensed under the LGPL." with SPDX-License-Identifier: LGPL-2.1-or-later.

Quoted 6 lines
Quoted 3 lines

Series reviewed against the NCR 53C710 data manual but totally untested (I don't have guest code to run), thus compile-checked only. I haven't tested whether the series is bisectable.

This is only a split experiment if Helge/Keith/Mark/Zoltan want to pursue, I'm not going to respin.

Thank you Philippe!
That was very good work.
The result is pretty much the original (and yours is actually a little bit nicer though). I just gave it a runtime spin, and it booted Linux nicely up to a prompt.

Quoted 14 lines
Quoted 14 lines

Keith Monahan (9):
   hw/scsi/scsi-disk: Add quirk_mode_page_no_flexible_disk, use it on the 715
   hw/scsi: Move shared LSI/NCR definitions to lsi_scsi.h hw/scsi/ncr53c710: Rewrite the 53C710 SCRIPTS engine hw/scsi/ncr53c710: Deliver completions from bottom halves hw/scsi/ncr53c710: Drain asynchronous transfers in the register write hw/scsi/ncr53c710: Append SAVE DATA POINTERS after MESSAGE REJECT for HP-UX
   hw/scsi/ncr53c710: Guard SCRIPTS reentrancy and cancel requests on soft reset
   hw/scsi/lasi_ncr710: Map the full LASI SCSI module page hw/scsi/ncr53c710: Bump the migration version

Quoted 3 lines
Quoted 1 line

Philippe Mathieu-Daudé (5):

Oops here author should be Keith Monahan?

That's easy to fix for me.

Thank you!
Helge

Quoted 8 lines
Quoted 7 lines

   hw/scsi/ncr53c710: Cancel the in-flight request on soft reset hw/scsi/ncr53c710: Do not load SBCL from DBC after a SCRIPTS phase move
   hw/scsi/lasi_ncr710: Limit max_target and max_lun to 7 hw/scsi/ncr53c710: Keep DCNTL.EA and DMODE.FC1 across an ISTAT.RST reset
   hw/scsi/ncr53c710: Document the SIGP latch deviation