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 08/14] hw/scsi/ncr53c710: Deliver completions from bottom halves
Date: Fri, 20 Nov 2026 18:12:28 +0100 [thread overview]
Message-ID: <20261120171235.61325-9-philmd@oss.qualcomm.com> (raw)
In-Reply-To: <20261120171235.61325-1-philmd@oss.qualcomm.com>
From: Keith Monahan <keith@techtravels.org>
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.
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.h | 8 ++++
hw/scsi/ncr53c710.c | 92 ++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 90 insertions(+), 10 deletions(-)
diff --git a/hw/scsi/ncr53c710.h b/hw/scsi/ncr53c710.h
index 82202940caa6..8b5cbfc135e3 100644
--- a/hw/scsi/ncr53c710.h
+++ b/hw/scsi/ncr53c710.h
@@ -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;
diff --git a/hw/scsi/ncr53c710.c b/hw/scsi/ncr53c710.c
index 305958b92f4a..b9ebeb4d96dc 100644
--- a/hw/scsi/ncr53c710.c
+++ b/hw/scsi/ncr53c710.c
@@ -73,6 +73,7 @@ static const char *lsi_reg_name(int offset)
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_issue_bh(void *opaque);
static void lsi_set_phase(NCR710State *s, int phase);
/*
@@ -106,6 +107,7 @@ void ncr710_soft_reset(NCR710State *s)
s->select_tag = 0;
s->command_complete = 0;
s->script_running = false;
+ s->sigp_pending_resume = false;
s->scntl0 = 0xc0; /* full arbitration */
s->scntl1 = 0;
@@ -272,6 +274,25 @@ static void lsi_bad_selection(NCR710State *s, uint32_t id)
lsi_disconnect(s);
}
+/*
+ * Deferred half of lsi_do_dma()'s SCSI continue. It runs on a clean stack,
+ * so a cached backend's completion cannot arrive reentrantly inside the
+ * SCRIPTS interpreter.
+ */
+static void lsi_issue_bh(void *opaque)
+{
+ NCR710State *s = opaque;
+
+ if (!s->issue_pending) {
+ return;
+ }
+ s->issue_pending = false;
+ if (s->current == NULL || s->current->orphan) {
+ return;
+ }
+ scsi_req_continue(s->current->req);
+}
+
static void lsi_do_dma(NCR710State *s, int out)
{
uint32_t count;
@@ -314,7 +335,21 @@ static void lsi_do_dma(NCR710State *s, int out)
p->dma_len -= count;
if (p->dma_len == 0) {
p->dma_buf = NULL;
- scsi_req_continue(req);
+ /*
+ * Defer the completing continue (dbc == 0) of a tagged transfer to a
+ * bottom half; the engine parks at DMA_IN_PROGRESS (set by the caller)
+ * meanwhile.
+ */
+ if ((p->tag & LSI_TAG_VALID) && s->dbc == 0) {
+ s->issue_pending = true;
+ aio_bh_schedule_oneshot(qemu_get_aio_context(), lsi_issue_bh, s);
+ } else {
+ /*
+ * Complete inline for untagged transfers and mid-transfer
+ * continues (dbc > 0).
+ */
+ scsi_req_continue(req);
+ }
} else {
p->dma_buf += count;
lsi_resume_script(s);
@@ -417,20 +452,43 @@ static int lsi_queue_req(NCR710State *s, SCSIRequest *req, uint32_t len)
return 1;
}
-/* SCRIPTS Wait Reselect: reconnect a ready queued command, else park. */
-static void lsi_wait_reselect(NCR710State *s)
+/*
+ * Deferred half of lsi_wait_reselect(): reconnect a disconnected command
+ * whose data is ready and resume the engine. Does nothing if the engine moved
+ * on while this was pending.
+ */
+static void lsi_reselect_bh(void *opaque)
{
+ NCR710State *s = opaque;
lsi_request *p;
- if (s->current) {
+ if (s->current != NULL || s->waiting != LSI_WAIT_RESELECT) {
return;
}
p = lsi_get_pending_req(s);
- if (p) {
- lsi_reselect(s, p);
+ if (p == NULL) {
+ return;
}
- if (s->current == NULL) {
- s->waiting = LSI_WAIT_RESELECT;
+ lsi_reselect(s, p);
+ s->waiting = LSI_NOWAIT;
+ lsi_execute_script(s);
+}
+
+/* SCRIPTS Wait Reselect: reconnect a ready queued command, else park. */
+static void lsi_wait_reselect(NCR710State *s)
+{
+ if (s->current) {
+ return;
+ }
+ /*
+ * Reselecting synchronously here, inside the guest register write that
+ * drove the engine to this Wait Reselect, would deliver the command's
+ * completion interrupt reentrantly. Defer the reconnect to a bottom half;
+ * the engine parks meanwhile.
+ */
+ s->waiting = LSI_WAIT_RESELECT;
+ if (lsi_get_pending_req(s)) {
+ aio_bh_schedule_oneshot(qemu_get_aio_context(), lsi_reselect_bh, s);
}
}
@@ -930,9 +988,10 @@ again:
/*
* Two things release a Wait Reselect: SIGP (jump to the
* dispatch address latched in DNAD), or a disconnected command
- * becoming ready to reselect.
+ * becoming ready to reselect. A SIGP that arrived while the
+ * engine was halted is held in sigp_pending_resume.
*/
- if (s->istat & LSI_ISTAT0_SIGP) {
+ if ((s->istat & LSI_ISTAT0_SIGP) || s->sigp_pending_resume) {
/*
* The SIGP divert is a one-shot: clear the latch so a
* later Wait Reselect does not re-fire on a stale SIGP.
@@ -940,6 +999,7 @@ again:
* auto-switching.
*/
s->istat &= ~LSI_ISTAT0_SIGP;
+ s->sigp_pending_resume = false;
s->dsp = s->dnad;
} else if (!lsi_irq_on_rsl(s)) {
lsi_wait_reselect(s);
@@ -1404,6 +1464,17 @@ static void lsi_reg_writeb(NCR710State *s, int offset, uint8_t val)
s->waiting = LSI_NOWAIT;
s->dsp = s->dnad;
lsi_execute_script(s);
+ } else if ((val & LSI_ISTAT0_SIGP) && !s->script_running &&
+ s->waiting == LSI_NOWAIT) {
+ /*
+ * SIGP while the engine is halted on a just completed command,
+ * not parked at Wait Reselect. Clear the SIGP latch, as a Wait
+ * 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.
+ */
+ s->istat &= ~LSI_ISTAT0_SIGP;
+ s->sigp_pending_resume = true;
}
break;
case NCR710_CTEST8:
@@ -1535,6 +1606,7 @@ 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),
VMSTATE_UINT8(scntl0, NCR710State),
VMSTATE_UINT8(scntl1, NCR710State),
--
2.55.0
next prev parent reply other threads:[~2026-11-20 17:15 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 ` Philippe Mathieu-Daudé [this message]
2026-11-20 17:12 ` [RFC PATCH-for-11.2? v4 09/14] hw/scsi/ncr53c710: Drain asynchronous transfers in the register write Philippe Mathieu-Daudé
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-9-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.