Patchwork [02/10] SCSI: STARTSTOPUNIT only eject/load media if powercondition is 0

login
register
mail settings
Submitter Paolo Bonzini
Date Aug. 3, 2012, 8:06 a.m.
Message ID <1343981180-23817-3-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/174947/
State New
Headers show

Comments

Paolo Bonzini - Aug. 3, 2012, 8:06 a.m.
From: Ronnie Sahlberg <ronniesahlberg@gmail.com>

The START STOP UNIT command will only eject/load media if
power condition is zero.

If power condition is !0 then LOEJ and START will be ignored.

From MMC (sbc contains similar wordings too)
  The Power Conditions field requests the block device to be placed
  in the power condition defined in
  Table 558. If this field has a value other than 0h then the Start
  and LoEj bits shall be ignored.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/scsi-disk.c |    6 ++++++
 1 file changed, 6 insertions(+)

Patch

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 84b63ff..e2ec177 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1247,6 +1247,12 @@  static int scsi_disk_emulate_start_stop(SCSIDiskReq *r)
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
     bool start = req->cmd.buf[4] & 1;
     bool loej = req->cmd.buf[4] & 2; /* load on start, eject on !start */
+    int pwrcnd = req->cmd.buf[4] & 0xf0;
+
+    if (pwrcnd) {
+        /* eject/load only happens for power condition == 0 */
+        return 0;
+    }
 
     if ((s->features & (1 << SCSI_DISK_F_REMOVABLE)) && loej) {
         if (!start && !s->tray_open && s->tray_locked) {