qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, jsnow@redhat.com
Subject: [Qemu-devel] [PULL 35/35] ahci: fix sdb fis semantics
Date: Sat,  4 Jul 2015 02:07:14 -0400	[thread overview]
Message-ID: <1435990034-8945-36-git-send-email-jsnow@redhat.com> (raw)
In-Reply-To: <1435990034-8945-1-git-send-email-jsnow@redhat.com>

There are two things to fix here:

The first one is subtle: the PxSACT register in the AHCI HBA has different
semantics from the field it is shadowing, the ACT field in the
Set Device Bits FIS.

In the HBA register, PxSACT acts as a bitfield indicating outstanding
NCQ commands where a set bit indicates a pending NCQ operation. The FIS
field however operates as an RWC register update to PxSACT, where a set
bit indicates a *successfully* completed command.

Correct the FIS semantics. At the same time, move the "clear finished"
action to the SDB FIS generation instead of the register read to mimick
how the other shadow registers work, which always just report the last
reported value from a FIS, and not the most current values which may
not have been reported by a FIS yet.

Lastly and more simply, SATA 3.2 section 13.6.4.2 (and later sections)
all specify that the Interrupt bit for the SDB FIS should always be set
to one for NCQ commands. That's currently the only time we generate this
FIS, so set it on all the time.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id: 1435767578-32743-16-git-send-email-jsnow@redhat.com
---
 hw/ide/ahci.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index eadd8b3..bb6a92f 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -106,8 +106,6 @@ static uint32_t  ahci_port_read(AHCIState *s, int port, int offset)
         val = pr->scr_err;
         break;
     case PORT_SCR_ACT:
-        pr->scr_act &= ~s->dev[port].finished;
-        s->dev[port].finished = 0;
         val = pr->scr_act;
         break;
     case PORT_CMD_ISSUE:
@@ -666,14 +664,14 @@ static void ahci_unmap_clb_address(AHCIDevice *ad)
     ad->lst = NULL;
 }
 
-static void ahci_write_fis_sdb(AHCIState *s, int port, uint32_t finished)
+static void ahci_write_fis_sdb(AHCIState *s, NCQTransferState *ncq_tfs)
 {
-    AHCIDevice *ad = &s->dev[port];
+    AHCIDevice *ad = ncq_tfs->drive;
     AHCIPortRegs *pr = &ad->port_regs;
     IDEState *ide_state;
     SDBFIS *sdb_fis;
 
-    if (!s->dev[port].res_fis ||
+    if (!ad->res_fis ||
         !(pr->cmd & PORT_CMD_FIS_RX)) {
         return;
     }
@@ -683,19 +681,23 @@ static void ahci_write_fis_sdb(AHCIState *s, int port, uint32_t finished)
 
     sdb_fis->type = SATA_FIS_TYPE_SDB;
     /* Interrupt pending & Notification bit */
-    sdb_fis->flags = (ad->hba->control_regs.irqstatus ? (1 << 6) : 0);
+    sdb_fis->flags = 0x40; /* Interrupt bit, always 1 for NCQ */
     sdb_fis->status = ide_state->status & 0x77;
     sdb_fis->error = ide_state->error;
     /* update SAct field in SDB_FIS */
-    s->dev[port].finished |= finished;
     sdb_fis->payload = cpu_to_le32(ad->finished);
 
     /* Update shadow registers (except BSY 0x80 and DRQ 0x08) */
     pr->tfdata = (ad->port.ifs[0].error << 8) |
         (ad->port.ifs[0].status & 0x77) |
         (pr->tfdata & 0x88);
+    pr->scr_act &= ~ad->finished;
+    ad->finished = 0;
 
-    ahci_trigger_irq(s, ad, PORT_IRQ_SDB_FIS);
+    /* Trigger IRQ if interrupt bit is set (which currently, it always is) */
+    if (sdb_fis->flags & 0x40) {
+        ahci_trigger_irq(s, ad, PORT_IRQ_SDB_FIS);
+    }
 }
 
 static void ahci_write_fis_pio(AHCIDevice *ad, uint16_t len)
@@ -895,11 +897,14 @@ static void ncq_err(NCQTransferState *ncq_tfs)
 
 static void ncq_finish(NCQTransferState *ncq_tfs)
 {
-    /* Clear bit for this tag in SActive */
-    ncq_tfs->drive->port_regs.scr_act &= ~(1 << ncq_tfs->tag);
+    /* If we didn't error out, set our finished bit. Errored commands
+     * do not get a bit set for the SDB FIS ACT register, nor do they
+     * clear the outstanding bit in scr_act (PxSACT). */
+    if (!(ncq_tfs->drive->port_regs.scr_err & (1 << ncq_tfs->tag))) {
+        ncq_tfs->drive->finished |= (1 << ncq_tfs->tag);
+    }
 
-    ahci_write_fis_sdb(ncq_tfs->drive->hba, ncq_tfs->drive->port_no,
-                       (1 << ncq_tfs->tag));
+    ahci_write_fis_sdb(ncq_tfs->drive->hba, ncq_tfs);
 
     DPRINTF(ncq_tfs->drive->port_no, "NCQ transfer tag %d finished\n",
             ncq_tfs->tag);
-- 
2.1.0

  parent reply	other threads:[~2015-07-04  6:07 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-04  6:06 [Qemu-devel] [PULL 00/35] Ide patches John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 01/35] ahci: Do not ignore memory access read size John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 02/35] qtest/ahci: add test_max John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 03/35] libqos/ahci: fix memory management bugs John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 04/35] qtest/ahci: add port_reset test John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 05/35] ahci: Rename NCQFIS structure fields John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 06/35] ahci: use shorter variables John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 07/35] ahci: add ncq_err helper John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 08/35] ahci: check for ncq prdtl overflow John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 09/35] ahci: separate prdtl from opts John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 10/35] ahci: add ncq debug checks John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 11/35] ahci: ncq sector count correction John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 12/35] ahci/qtest: Execute IDENTIFY prior to data commands John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 13/35] libqos/ahci: fix cmd_sanity for ncq John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 14/35] libqos/ahci: add NCQ frame support John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 15/35] libqos/ahci: edit wait to be ncq aware John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 16/35] libqos/ahci: adjust expected NCQ interrupts John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 17/35] libqos/ahci: set the NCQ tag on command_commit John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 18/35] libqos/ahci: Force all NCQ commands to be LBA48 John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 19/35] qtest/ahci: simple ncq data test John Snow
2015-07-04  6:06 ` [Qemu-devel] [PULL 20/35] qtest/ahci: ncq migration test John Snow
2015-07-04  6:07 ` [Qemu-devel] [PULL 21/35] ide: add limit to .prepare_buf() John Snow
2015-07-04  6:07 ` [Qemu-devel] [PULL 22/35] ahci: stash ncq command John Snow
2015-07-04  6:07 ` [Qemu-devel] [PULL 23/35] ahci: assert is_ncq for process_ncq John Snow
2015-07-04  6:07 ` [Qemu-devel] [PULL 24/35] ahci: refactor process_ncq_command John Snow
2015-07-04  6:07 ` [Qemu-devel] [PULL 25/35] ahci: factor ncq_finish out of ncq_cb John Snow
2015-07-04  6:07 ` [Qemu-devel] [PULL 26/35] ahci: add rwerror=stop support for ncq John Snow
2015-07-04  6:07 ` [Qemu-devel] [PULL 27/35] ahci: correct types in NCQTransferState John Snow
2015-07-04  6:07 ` [Qemu-devel] [PULL 28/35] ahci: correct ncq sector count John Snow
2015-07-04  6:07 ` [Qemu-devel] [PULL 29/35] qtest/ahci: halted NCQ test John Snow
2015-07-04  6:07 ` [Qemu-devel] [PULL 30/35] ahci: add cmd header to ncq transfer state John Snow
2015-07-04  6:07 ` [Qemu-devel] [PULL 31/35] ahci: add get_cmd_header helper John Snow
2015-07-04  6:07 ` [Qemu-devel] [PULL 32/35] ahci: ncq migration John Snow
2015-07-09 14:11   ` Paolo Bonzini
2015-07-04  6:07 ` [Qemu-devel] [PULL 33/35] ahci: Do not map cmd_fis to generate response John Snow
2015-07-04  6:07 ` [Qemu-devel] [PULL 34/35] qtest/ahci: halted ncq migration test John Snow
2015-07-04  6:07 ` John Snow [this message]
2015-07-05 21:01 ` [Qemu-devel] [PULL 00/35] Ide patches Peter Maydell

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=1435990034-8945-36-git-send-email-jsnow@redhat.com \
    --to=jsnow@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).