From 9e7313088fddd18cbd5b1aea4ad47cff3cf39f78 Mon Sep 17 00:00:00 2001
From: John Snow <jsnow@redhat.com>
Date: Thu, 16 Oct 2014 14:42:49 +0200
Subject: [PATCH 1/5] ide: Add wwn support to IDE-ATAPI drive

Message-id: <1413470569-30061-2-git-send-email-jsnow@redhat.com>
Patchwork-id: 61724
O-Subject: [RHEV-7.1 qemu-kvm-rhev PATCH 1/1] ide: Add wwn support to IDE-ATAPI drive
Bugzilla: 1150820
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
RH-Acked-by: Fam Zheng <famz@redhat.com>
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>

Although it is possible to specify the wwn
property for cdrom devices on the command line,
the underlying driver fails to relay this information
to the guest operating system via IDENTIFY.

This is a simple patch to correct that.

See ATA8-ACS 6a, Table 39 (IDENTIFY PACKET DEVICE data),
parts 7 and 11. (7.17.6.34 and 7.17.6.44)

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit c5fe97e359bf03db9a005433092f25d27d57398f)
Signed-off-by: John Snow <jsnow@redhat.com>
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>

Conflicts:
	hw/ide/core.c
        Minor conflict with previous IDENTIFY re-ordering.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 hw/ide/core.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index acf1910..608b47f 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -242,10 +242,23 @@ static void ide_atapi_identify(IDEState *s)
     }
 
     put_le16(p + 80, 0x1e); /* support up to ATA/ATAPI-4 */
+    if (s->wwn) {
+        put_le16(p + 84, (1 << 8)); /* supports WWN for words 108-111 */
+        put_le16(p + 87, (1 << 8)); /* WWN enabled */
+    }
+
 #ifdef USE_DMA_CDROM
     put_le16(p + 88, 0x3f | (1 << 13)); /* udma5 set and supported */
 #endif
 
+    if (s->wwn) {
+        /* LE 16-bit words 111-108 contain 64-bit World Wide Name */
+        put_le16(p + 108, s->wwn >> 48);
+        put_le16(p + 109, s->wwn >> 32);
+        put_le16(p + 110, s->wwn >> 16);
+        put_le16(p + 111, s->wwn);
+    }
+
     s->identify_set = 1;
 
 fill_buffer:
-- 
1.8.3.1

