From: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
To: qemu-devel@nongnu.org
Cc: "Helge Deller" <deller@gmx.de>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Fam Zheng" <fam@euphon.net>,
"Keith Monahan" <keith@techtravels.org>,
"BALATON Zoltan" <balaton@eik.bme.hu>,
"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
Subject: [RFC PATCH-for-11.2? v4 09/14] hw/scsi/ncr53c710: Drain asynchronous transfers in the register write
Date: Fri, 20 Nov 2026 18:12:29 +0100 [thread overview]
Message-ID: <20261120171235.61325-10-philmd@oss.qualcomm.com> (raw)
In-Reply-To: <20261120171235.61325-1-philmd@oss.qualcomm.com>
From: Keith Monahan <keith@techtravels.org>
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).
Signed-off-by: Keith Monahan <keith@techtravels.org>
Signed-off-by: Helge Deller <deller@gmx.de>
AI-used-for: Patch series decomposition (commit splitting and ordering)
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
hw/scsi/ncr53c710.c | 29 +++++++++++++++++++++++++++++
hw/scsi/trace-events | 1 +
2 files changed, 30 insertions(+)
diff --git a/hw/scsi/ncr53c710.c b/hw/scsi/ncr53c710.c
index b9ebeb4d96dc..9ca025ff6334 100644
--- a/hw/scsi/ncr53c710.c
+++ b/hw/scsi/ncr53c710.c
@@ -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)
diff --git a/hw/scsi/trace-events b/hw/scsi/trace-events
index f0eb1457022e..843d8f1a1e27 100644
--- a/hw/scsi/trace-events
+++ b/hw/scsi/trace-events
@@ -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"
--
2.55.0
next prev parent reply other threads:[~2026-11-20 17:14 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 17:12 [RFC PATCH-for-11.2 v4 00/14] nc53c710 rewrite Philippe Mathieu-Daudé
2026-11-20 17:12 ` [RFC PATCH-for-11.2 v4 01/14] hw/scsi/ncr53c710: Cancel the in-flight request on soft reset Philippe Mathieu-Daudé
2026-11-20 17:12 ` [RFC PATCH-for-11.2 v4 02/14] hw/scsi/ncr53c710: Do not load SBCL from DBC after a SCRIPTS phase move Philippe Mathieu-Daudé
2026-11-20 17:12 ` [RFC PATCH-for-11.2 v4 03/14] hw/scsi/scsi-disk: Add quirk_mode_page_no_flexible_disk, use it on the 715 Philippe Mathieu-Daudé
2026-11-20 17:12 ` [RFC PATCH-for-11.2 v4 04/14] hw/scsi/lasi_ncr710: Limit max_target and max_lun to 7 Philippe Mathieu-Daudé
2026-11-20 17:12 ` [RFC PATCH-for-11.2 v4 05/14] hw/scsi/ncr53c710: Keep DCNTL.EA and DMODE.FC1 across an ISTAT.RST reset Philippe Mathieu-Daudé
2026-11-20 17:12 ` [RFC PATCH-for-11.2? v4 06/14] hw/scsi: Move shared LSI/NCR definitions to lsi_scsi.h Philippe Mathieu-Daudé
2026-11-20 22:10 ` BALATON Zoltan
2026-11-20 17:12 ` [RFC PATCH-for-11.2??? v4 07/14] hw/scsi/ncr53c710: Rewrite the 53C710 SCRIPTS engine Philippe Mathieu-Daudé
2026-11-20 22:13 ` BALATON Zoltan
2026-11-20 17:12 ` [RFC PATCH-for-11.2? v4 08/14] hw/scsi/ncr53c710: Deliver completions from bottom halves Philippe Mathieu-Daudé
2026-11-20 17:12 ` Philippe Mathieu-Daudé [this message]
2026-11-20 17:12 ` [RFC PATCH-for-11.2? v4 10/14] hw/scsi/ncr53c710: Append SAVE DATA POINTERS after MESSAGE REJECT for HP-UX Philippe Mathieu-Daudé
2026-11-20 17:12 ` [RFC PATCH-for-11.2? v4 11/14] hw/scsi/ncr53c710: Guard SCRIPTS reentrancy and cancel requests on soft reset Philippe Mathieu-Daudé
2026-11-20 22:17 ` BALATON Zoltan
2026-11-20 17:12 ` [RFC PATCH-for-11.2? v4 12/14] hw/scsi/lasi_ncr710: Map the full LASI SCSI module page Philippe Mathieu-Daudé
2026-11-20 17:12 ` [RFC PATCH-for-11.2? v4 13/14] hw/scsi/ncr53c710: Document the SIGP latch deviation Philippe Mathieu-Daudé
2026-11-20 17:12 ` [RFC PATCH-for-11.2? v4 14/14] hw/scsi/ncr53c710: Bump the migration version Philippe Mathieu-Daudé
2026-11-20 22:21 ` BALATON Zoltan
2026-11-20 17:20 ` [RFC PATCH-for-11.2 v4 00/14] nc53c710 rewrite Philippe Mathieu-Daudé
2026-11-20 22:09 ` BALATON Zoltan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120171235.61325-10-philmd@oss.qualcomm.com \
--to=philmd@oss.qualcomm.com \
--cc=balaton@eik.bme.hu \
--cc=deller@gmx.de \
--cc=fam@euphon.net \
--cc=keith@techtravels.org \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.