All of lore.kernel.org
 help / color / mirror / Atom feed
From: Niklas Cassel <cassel@kernel.org>
To: John Snow <jsnow@redhat.com>, "Denis V. Lunev" <den@openvz.org>
Cc: Damien Le Moal <dlemoal@kernel.org>,
	Niklas Cassel <cassel@kernel.org>,
	qemu-block@nongnu.org, qemu-devel@nongnu.org
Subject: [PATCH 01/13] hw/ide: report the SMART state in IDENTIFY DEVICE
Date: Fri, 27 Nov 2026 20:12:36 +0100	[thread overview]
Message-ID: <20261127191250.3298004-2-cassel@kernel.org> (raw)
In-Reply-To: <20261127191250.3298004-1-cassel@kernel.org>

Currently, IDENTIFY DEVICE word 85 bit 0 always reports the SMART feature
set as enabled, regardless if it has been disabled using SET FEATURES or
SMART DISABLE OPERATIONS.

Add a helper to build word85, such that the SMART feature set and the
write cache is reported in IDENTIFY DEVICE correctly.

Also, just like the write cache state is re-initialized after migration,
re-initialize the SMART state after migration.

Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
 hw/ide/core.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 06e6bb6067..7e3f882969 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -138,6 +138,14 @@ static void ide_identify_size(IDEState *s)
     put_le16(p + 103, s->nb_sectors >> 48);
 }
 
+/* IDENTIFY DEVICE word 85: the commands and feature sets that are enabled */
+static uint16_t ide_identify_word85(IDEState *s)
+{
+    /* 14 = NOP supported, 5=WCACHE enabled, 0=SMART feature set enabled */
+    return (1 << 14) | (blk_enable_write_cache(s->blk) ? 1 << 5 : 0) |
+           (s->smart_enabled ? 1 : 0);
+}
+
 static void ide_identify(IDEState *s)
 {
     uint16_t *p;
@@ -204,12 +212,7 @@ static void ide_identify(IDEState *s)
     } else {
         put_le16(p + 84, (1 << 14) | 0);
     }
-    /* 14 = NOP supported, 5=WCACHE enabled, 0=SMART feature set enabled */
-    if (blk_enable_write_cache(s->blk)) {
-        put_le16(p + 85, (1 << 14) | (1 << 5) | 1);
-    } else {
-        put_le16(p + 85, (1 << 14) | 1);
-    }
+    put_le16(p + 85, ide_identify_word85(s));
     /* 13=flush_cache_ext,12=flush_cache,10=lba48 */
     put_le16(p + 86, (1 << 13) | (1 <<12) | (1 << 10));
     /* 14=set to 1, 8=has WWN, 1=SMART self test, 0=SMART error logging */
@@ -1714,12 +1717,12 @@ static bool cmd_set_features(IDEState *s, uint8_t cmd)
     case 0x02: /* write cache enable */
         blk_set_enable_write_cache(s->blk, true);
         identify_data = (uint16_t *)s->identify_data;
-        put_le16(identify_data + 85, (1 << 14) | (1 << 5) | 1);
+        put_le16(identify_data + 85, ide_identify_word85(s));
         return true;
     case 0x82: /* write cache disable */
         blk_set_enable_write_cache(s->blk, false);
         identify_data = (uint16_t *)s->identify_data;
-        put_le16(identify_data + 85, (1 << 14) | 1);
+        put_le16(identify_data + 85, ide_identify_word85(s));
         ide_flush_cache(s);
         return false;
     case 0xcc: /* reverting to power-on defaults enable */
@@ -1942,11 +1945,9 @@ static bool cmd_smart(IDEState *s, uint8_t cmd)
 
     switch (s->feature) {
     case SMART_DISABLE:
-        s->smart_enabled = 0;
-        return true;
-
     case SMART_ENABLE:
-        s->smart_enabled = 1;
+        s->smart_enabled = s->feature == SMART_ENABLE;
+        put_le16((uint16_t *)s->identify_data + 85, ide_identify_word85(s));
         return true;
 
     case SMART_ATTR_AUTOSAVE:
@@ -2901,6 +2902,7 @@ static int ide_drive_post_load(void *opaque, int version_id)
 
     if (s->blk && s->identify_set) {
         blk_set_enable_write_cache(s->blk, !!(s->identify_data[85] & (1 << 5)));
+        s->smart_enabled = s->identify_data[85] & 1;
     }
     return 0;
 }
-- 
2.56.1



  reply	other threads:[~2026-11-27 19:14 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 19:12 [PATCH 00/13] hw/ide: add missing features required for SATA Niklas Cassel
2026-11-27 19:12 ` Niklas Cassel [this message]
2026-11-30  5:10   ` [PATCH 01/13] hw/ide: report the SMART state in IDENTIFY DEVICE Damien Le Moal
2026-11-27 19:12 ` [PATCH 02/13] hw/ide/ahci: stop processing commands after a fatal error Niklas Cassel
2026-11-30  5:13   ` Damien Le Moal
2026-11-27 19:12 ` [PATCH 03/13] hw/ide/ahci: clear a stale error status when an NCQ command is queued Niklas Cassel
2026-11-30  5:15   ` Damien Le Moal
2026-11-27 19:12 ` [PATCH 04/13] hw/ide/ahci: complete unsupported NCQ commands Niklas Cassel
2026-11-30  5:16   ` Damien Le Moal
2026-11-27 19:12 ` [PATCH 05/13] hw/ide: add General Purpose Logging (GPL) feature set support Niklas Cassel
2026-11-30  5:20   ` Damien Le Moal
2026-11-27 19:12 ` [PATCH 06/13] hw/ide: add the IDENTIFY DEVICE data log Niklas Cassel
2026-11-30  5:23   ` Damien Le Moal
2026-11-27 19:12 ` [PATCH 07/13] hw/ide/ahci: add RECEIVE FPDMA QUEUED support Niklas Cassel
2026-11-30  5:25   ` Damien Le Moal
2026-11-27 19:12 ` [PATCH 08/13] hw/ide: add Sense Data Reporting feature set support Niklas Cassel
2026-11-30  5:30   ` Damien Le Moal
2026-11-27 19:12 ` [PATCH 09/13] hw/ide: implement the NCQ Command Error log (10h) Niklas Cassel
2026-11-30  5:34   ` Damien Le Moal
2026-11-27 19:12 ` [PATCH 10/13] tests/qtest/libqos: skip some checks for commands expected to fail Niklas Cassel
2026-11-27 19:12 ` [PATCH 11/13] hw/ide: report out-of-range accesses as ILLEGAL REQUEST Niklas Cassel
2026-11-30  5:35   ` Damien Le Moal
2026-11-27 19:12 ` [PATCH 12/13] hw/ide/ahci: check the LBA range of NCQ commands Niklas Cassel
2026-11-30  5:36   ` Damien Le Moal
2026-11-27 19:12 ` [PATCH 13/13] hw/ide: report ACS-6 compliance behind AHCI Niklas Cassel
2026-11-30  5:37   ` Damien Le Moal

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=20261127191250.3298004-2-cassel@kernel.org \
    --to=cassel@kernel.org \
    --cc=den@openvz.org \
    --cc=dlemoal@kernel.org \
    --cc=jsnow@redhat.com \
    --cc=qemu-block@nongnu.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 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.