From: Helge Deller <deller@kernel.org>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Keith Monahan" <keith@techtravels.org>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Helge Deller" <deller@gmx.de>,
"BALATON Zoltan" <balaton@eik.bme.hu>
Subject: [PULL for 11.2 08/14] hw/scsi/ncr53c710: Deliver completions from bottom halves
Date: Wed, 25 Nov 2026 03:49:45 +0100 [thread overview]
Message-ID: <20261125024951.10428-9-deller@kernel.org> (raw)
In-Reply-To: <20261125024951.10428-1-deller@kernel.org>
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>
AI-used-for: Patch series decomposition (commit splitting and ordering)
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Signed-off-by: Helge Deller <deller@gmx.de>
---
hw/scsi/ncr53c710.c | 92 ++++++++++++++++++++++++++++++++++++++++-----
hw/scsi/ncr53c710.h | 8 ++++
2 files changed, 90 insertions(+), 10 deletions(-)
diff --git a/hw/scsi/ncr53c710.c b/hw/scsi/ncr53c710.c
index 46d2ada97d..9a7b76a597 100644
--- a/hw/scsi/ncr53c710.c
+++ b/hw/scsi/ncr53c710.c
@@ -74,6 +74,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);
/*
@@ -107,6 +108,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;
@@ -273,6 +275,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;
@@ -315,7 +336,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);
@@ -418,20 +453,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;
+ }
+ 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;
}
- if (s->current == NULL) {
- s->waiting = LSI_WAIT_RESELECT;
+ /*
+ * 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);
}
}
@@ -931,9 +989,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.
@@ -941,6 +1000,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);
@@ -1413,6 +1473,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:
@@ -1544,6 +1615,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),
diff --git a/hw/scsi/ncr53c710.h b/hw/scsi/ncr53c710.h
index 82202940ca..8b5cbfc135 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;
--
2.54.0
next prev parent reply other threads:[~2026-11-25 2:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 2:49 [PULL for 11.2 00/14] ncr53c710 driver rewrite Helge Deller
2026-11-25 2:49 ` [PULL for 11.2 01/14] hw/scsi/ncr53c710: Cancel the in-flight request on soft reset Helge Deller
2026-11-25 2:49 ` [PULL for 11.2 02/14] hw/scsi/ncr53c710: Do not load SBCL from DBC after a SCRIPTS phase move Helge Deller
2026-11-25 2:49 ` [PULL for 11.2 03/14] hw/scsi/scsi-disk: Add quirk_mode_page_no_flexible_disk, use it on the 715 Helge Deller
2026-11-25 2:49 ` [PULL for 11.2 04/14] hw/scsi/lasi_ncr710: Limit max_target and max_lun to 7 Helge Deller
2026-11-25 2:49 ` [PULL for 11.2 05/14] hw/scsi/ncr53c710: Keep DCNTL.EA and DMODE.FC1 across an ISTAT.RST reset Helge Deller
2026-11-25 2:49 ` [PULL for 11.2 06/14] hw/scsi: Move shared LSI/NCR definitions to lsi_scsi.h Helge Deller
2026-11-25 2:49 ` [PULL for 11.2 07/14] hw/scsi/ncr53c710: Rewrite the 53C710 SCRIPTS engine Helge Deller
2026-11-25 2:49 ` Helge Deller [this message]
2026-11-25 2:49 ` [PULL for 11.2 09/14] hw/scsi/ncr53c710: Drain asynchronous transfers in the register write Helge Deller
2026-11-25 2:49 ` [PULL for 11.2 10/14] hw/scsi/ncr53c710: Append SAVE DATA POINTERS after MESSAGE REJECT for HP-UX Helge Deller
2026-11-25 2:49 ` [PULL for 11.2 11/14] hw/scsi/ncr53c710: Guard SCRIPTS reentrancy and cancel requests on soft reset Helge Deller
2026-11-25 2:49 ` [PULL for 11.2 12/14] hw/scsi/lasi_ncr710: Map the full LASI SCSI module page Helge Deller
2026-11-25 2:49 ` [PULL for 11.2 13/14] hw/scsi/ncr53c710: Document the SIGP latch deviation Helge Deller
2026-11-25 2:49 ` [PULL for 11.2 14/14] hw/scsi/ncr53c710: Bump the migration version Helge Deller
2026-11-25 20:54 ` [PULL for 11.2 00/14] ncr53c710 driver rewrite Richard Henderson
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=20261125024951.10428-9-deller@kernel.org \
--to=deller@kernel.org \
--cc=balaton@eik.bme.hu \
--cc=deller@gmx.de \
--cc=keith@techtravels.org \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=philmd@oss.qualcomm.com \
--cc=qemu-devel@nongnu.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.