ZPODD patches
Subsystems (4)
v7 cover ZPODD patches
v7:
Re work of runtime pm of sr driver, based on ideas of Alan Stern and Oliver Neukum.
Jeff, due to the ready_to_power_off flag added, there is a small change in [PATCH v7 6/6] libata: acpi: respect may_power_off flag, please check if I can still get your ack, thanks.
v6:
When user changes may_power_off flag through sysfs entry and if device is already runtime suspended, resume resume it so that it can respect this flag next time it is runtime suspended as suggested by Alan Stern. Call scsi_autopm_get/put_device once in sr_check_events as suggested by Alan Stern.
v5:
Add may_power_off flag to scsi device.
Alan Stern suggested that I should not mess runtime suspend with runtime power off, but the current zpodd implementation made it not easy to seperate. So I re-wrote the zpodd implementation, the end result is, normal ODD can also enter runtime suspended state, but their power won't be removed.
v4:
Rebase on top of Linus' tree, due to this, the problem of a missing flag in v3 is gone;
Add a new function scsi_autopm_put_device_autosuspend to first mark last busy for the device and then put autosuspend it as suggested by Oliver Neukum.
Typo fix as pointed by Sergei Shtylyov.
Check can_power_off flag before any runtime pm operations in sr.
v3:
Rebase on top of scsi-misc tree;
Add the sr related patches previously in Jeff's libata tree; Re-organize the sr patches.
A problem for now: for patch
scsi: sr: support zero power ODD(ZPODD)
I can't set a flag in libata-acpi.c since a related function is missing in scsi-misc tree. Will fix this when 3.6-rc1 released.
v2:
Bug fix for v1;
Use scsi_autopm_* in sr driver instead of pm_runtime_*;
v1:
Here are some patches to make ZPODD easier to use for end users and a fix for using ZPODD with system suspend.
Aaron Lu (6):
block: genhd: add an interface to set disk poll interval
scsi: sr: support runtime pm
scsi: sr: support zero power ODD(ZPODD)
scsi: pm: add may_power_off flag
scsi: sr: use may_power_off
libata: acpi: respect may_power_off flag
block/genhd.c | 23 +++++++++---- drivers/ata/libata-acpi.c | 30 +++++++++++----- drivers/scsi/scsi_sysfs.c | 37 +++++++++++++++++++- drivers/scsi/sr.c | 86 +++++++++++++++++++++++++++++++++++++++++++--- drivers/scsi/sr.h | 1 + drivers/scsi/sr_ioctl.c | 7 +++- include/linux/genhd.h | 1 + include/scsi/scsi_device.h | 4 +++ 8 files changed, 168 insertions(+), 21 deletions(-)
Signature · 1 line
1.7.12.21.g871e293
PATCH v7 1/6 block: genhd: add an interface to set disk poll interval
--- block/genhd.c | 23 +++++++++++++++++------ include/linux/genhd.h | 1 + 2 files changed, 18 insertions(+), 6 deletions(-)
block/genhd.c +17 -6
@@ -1627,6 +1627,19 @@ static void disk_events_workfn(struct work_struct *work)kobject_uevent_env (&disk_to_dev (disk)->kobj,KOBJ_CHANGE , envp); } +int disk_events_set_poll_msecs (struct gendisk *disk,long intv) +{ +if (intv <0 && intv !=-1 ) +return -EINVAL ; + +disk_block_events (disk); + disk->ev->poll_msecs = intv; +__disk_unblock_events (disk, true); + +return 0 ; +} +EXPORT_SYMBOL (disk_events_set_poll_msecs); +/* * A disk events enabled device has the following sysfs nodes under * its /sys/block/X/ directory.
@@ -1683,16 +1696,14 @@ static ssize_t disk_events_poll_msecs_store(struct device *dev, {struct gendisk *disk =dev_to_disk (dev);long intv; +int ret;if (!count || !sscanf (buf,"%ld" , &intv))return -EINVAL ; -if (intv <0 && intv !=-1 ) -return -EINVAL ; - -disk_block_events (disk); - disk->ev->poll_msecs = intv; -__disk_unblock_events (disk, true); + ret =disk_events_set_poll_msecs (disk, intv); +if (ret) +return ret;return count; }
include/linux/genhd.h +1 -0
@@ -423,6 +423,7 @@ extern void disk_block_events(struct gendisk *disk);extern void disk_unblock_events (struct gendisk *disk);extern void disk_flush_events (struct gendisk *disk,unsigned int mask);extern unsigned int disk_clear_events (struct gendisk *disk,unsigned int mask); +extern int disk_events_set_poll_msecs (struct gendisk *disk,long intv);/* drivers/char/random.c */ extern void add_disk_randomness (struct gendisk *disk);
Signature · 1 line
1.7.12.21.g871e293
Re: [PATCH v7 1/6] block: genhd: add an interface to set disk poll interval
Please add a changelog explaining who's going to use the new interface, in addition to the original user of that code, and why it is exported.
Thanks,
Rafael
Quoted 64 lines · Aaron Lu
Signed-off-by Aaron Lu <[email protected]>--- block/genhd.c | 23 +++++++++++++++++------ include/linux/genhd.h | 1 + 2 files changed, 18 insertions(+), 6 deletions(-)block/genhd.c +17
-6@@ -1627,6 +1627,19 @@ static void disk_events_workfn(struct work_struct *work)kobject_uevent_env (&disk_to_dev (disk)->kobj,KOBJ_CHANGE , envp); } +int disk_events_set_poll_msecs (struct gendisk *disk,long intv) +{ +if (intv <0 && intv !=-1 ) +return -EINVAL ; + +disk_block_events (disk); + disk->ev->poll_msecs = intv; +__disk_unblock_events (disk, true); + +return 0 ; +} +EXPORT_SYMBOL (disk_events_set_poll_msecs); +/* * A disk events enabled device has the following sysfs nodes under * its /sys/block/X/ directory. @@ -1683,16 +1696,14 @@ static ssize_t disk_events_poll_msecs_store(struct device *dev, {struct gendisk *disk =dev_to_disk (dev);long intv; +int ret;if (!count || !sscanf (buf,"%ld" , &intv))return -EINVAL ; -if (intv <0 && intv !=-1 ) -return -EINVAL ; - -disk_block_events (disk); - disk->ev->poll_msecs = intv; -__disk_unblock_events (disk, true); + ret =disk_events_set_poll_msecs (disk, intv); +if (ret) +return ret;return count; }include/linux/genhd.h +1
-0@@ -423,6 +423,7 @@ extern void disk_block_events(struct gendisk *disk);extern void disk_unblock_events (struct gendisk *disk);extern void disk_flush_events (struct gendisk *disk,unsigned int mask);extern unsigned int disk_clear_events (struct gendisk *disk,unsigned int mask); +extern int disk_events_set_poll_msecs (struct gendisk *disk,long intv);/* drivers/char/random.c */ extern void add_disk_randomness (struct gendisk *disk);
PATCH v7 2/6 scsi: sr: support runtime pm
In reply to Aaron LuPlace the ODD into runtime suspend state as soon as there is nobody using it. The only exception is, if we just find that a new medium is inserted, we wait for the next events checking to idle it.
Based on ideas of Alan Stern and Oliver Neukum.
--- drivers/scsi/sr.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)
drivers/scsi/sr.c +25 -4
@@ -45,6 +45,7 @@#include <linux/blkdev.h> #include <linux/mutex.h> #include <linux/slab.h> +#include <linux/pm_runtime.h> #include <asm/uaccess.h> #include <scsi/scsi.h>
@@ -146,8 +147,12 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)kref_get (&cd->kref);if (scsi_device_get (cd->device)) goto out_put; +if (scsi_autopm_get_device (cd->device)) + goto out_pm; goto out; + out_pm: +scsi_device_put (cd->device); out_put:kref_put (&cd->kref, sr_kref_release); cd =NULL ;
@@ -163,6 +168,7 @@ static void scsi_cd_put(struct scsi_cd *cd)mutex_lock (&sr_ref_mutex);kref_put (&cd->kref, sr_kref_release);scsi_device_put (sdev); +scsi_autopm_put_device (sdev);mutex_unlock (&sr_ref_mutex); }
@@ -211,7 +217,7 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi, unsigned int clearing, int slot) {struct scsi_cd *cd = cdi->handle; -bool last_present; +bool last_present = cd->media_present;struct scsi_sense_hdr sshdr;unsigned int events;int ret;
@@ -220,6 +226,8 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi,if (CDSL_CURRENT != slot)return 0 ; +scsi_autopm_get_device (cd->device); + events =sr_get_events (cd->device); cd->get_event_changed |= events &DISK_EVENT_MEDIA_CHANGE ;
@@ -246,10 +254,9 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi, }if (!(clearing &DISK_EVENT_MEDIA_CHANGE )) -return events; + goto out; do_tur:/* let's see whether the media is there with TUR */ - last_present = cd->media_present; ret =scsi_test_unit_ready (cd->device,SR_TIMEOUT ,MAX_RETRIES , &sshdr);/*
@@ -270,7 +277,7 @@ do_tur: }if (cd->ignore_get_event) -return events; + goto out;/* check whether GET_EVENT is reporting spurious MEDIA_CHANGE */ if (!cd->tur_changed) {
@@ -287,6 +294,12 @@ do_tur: cd->tur_changed = false; cd->get_event_changed = false; +out: +if (cd->media_present && !last_present) +pm_runtime_put_noidle (&cd->device->sdev_gendev); +else +scsi_autopm_put_device (cd->device); +return events; }
@@ -715,9 +728,14 @@ static int sr_probe(struct device *dev)dev_set_drvdata (dev, cd); disk->flags |=GENHD_FL_REMOVABLE ;add_disk (disk); +disk_events_set_poll_msecs (disk,5000 );sdev_printk (KERN_DEBUG , sdev,"Attached scsi CD-ROM %s\n" , cd->cdi.name); + +/* enable runtime pm */ +scsi_autopm_put_device (cd->device); +return 0 ; fail_put:
@@ -965,6 +983,9 @@ static int sr_remove(struct device *dev) {struct scsi_cd *cd =dev_get_drvdata (dev); +/* disable runtime pm */ +scsi_autopm_get_device (cd->device); +blk_queue_prep_rq (cd->device->request_queue, scsi_prep_fn);del_gendisk (cd->disk);
Signature · 1 line
1.7.12.21.g871e293
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 2 lines · Aaron Lu
Place the ODD into runtime suspend state as soon as there is nobody using it.
OK, so how is ODD related to the sr driver?
Quoted 2 lines
The only exception is, if we just find that a new medium is inserted, we wait for the next events checking to idle it.
What exactly do you mean by "to idle it"?
Does this patch have any functional effect without the following patches?
Quoted 20 lines
Based on ideas of Alan Stern and Oliver Neukum.
Signed-off-by Aaron Lu <[email protected]>--- drivers/scsi/sr.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)drivers/scsi/sr.c +1
-0@@ -45,6 +45,7 @@#include <linux/blkdev.h> #include <linux/mutex.h> #include <linux/slab.h> +#include <linux/pm_runtime.h> #include <asm/uaccess.h> #include <scsi/scsi.h>
drivers/scsi/sr.c static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) · line 152
Quoted 6 lines
drivers/scsi/sr.c +2
-0@@ -146,8 +147,12 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)kref_get (&cd->kref);if (scsi_device_get (cd->device)) goto out_put; +if (scsi_autopm_get_device (cd->device)) + goto out_pm; goto out;
Why don't you do
drivers/scsi/sr.c static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) · line 154
Quoted 2 lines
drivers/scsi/sr.c +2
-0+if (!scsi_autopm_get_device (cd->device)) + goto out;
without the new label?
Quoted 54 lines
drivers/scsi/sr.c +8
-4+ out_pm: +scsi_device_put (cd->device); out_put:kref_put (&cd->kref, sr_kref_release); cd =NULL ;@@ -163,6 +168,7 @@ static void scsi_cd_put(struct scsi_cd *cd)mutex_lock (&sr_ref_mutex);kref_put (&cd->kref, sr_kref_release);scsi_device_put (sdev); +scsi_autopm_put_device (sdev);mutex_unlock (&sr_ref_mutex); }@@ -211,7 +217,7 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi, unsigned int clearing, int slot) {struct scsi_cd *cd = cdi->handle; -bool last_present; +bool last_present = cd->media_present;struct scsi_sense_hdr sshdr;unsigned int events;int ret;@@ -220,6 +226,8 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi,if (CDSL_CURRENT != slot)return 0 ; +scsi_autopm_get_device (cd->device); + events =sr_get_events (cd->device); cd->get_event_changed |= events &DISK_EVENT_MEDIA_CHANGE ;@@ -246,10 +254,9 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi, }if (!(clearing &DISK_EVENT_MEDIA_CHANGE )) -return events; + goto out; do_tur:/* let's see whether the media is there with TUR */ - last_present = cd->media_present; ret =scsi_test_unit_ready (cd->device,SR_TIMEOUT ,MAX_RETRIES , &sshdr);/* @@ -270,7 +277,7 @@ do_tur: }if (cd->ignore_get_event) -return events; + goto out;/* check whether GET_EVENT is reporting spurious MEDIA_CHANGE */ if (!cd->tur_changed) {
drivers/scsi/sr.c do_tur: · line 302
Quoted 9 lines
drivers/scsi/sr.c +6
-0@@ -287,6 +294,12 @@ do_tur: cd->tur_changed = false; cd->get_event_changed = false; +out: +if (cd->media_present && !last_present) +pm_runtime_put_noidle (&cd->device->sdev_gendev); +else +scsi_autopm_put_device (cd->device); +
This thing is asking for a comment.
It looks like you're kind of avoiding to call _idle() for the device, but why? What might go wrong if pm_runtime_put() is used instead of the whole conditional, among other things?
drivers/scsi/sr.c static int sr_probe(struct device *dev) · line 731
Quoted 8 lines
drivers/scsi/sr.c +1
-0return events; }@@ -715,9 +728,14 @@ static int sr_probe(struct device *dev)dev_set_drvdata (dev, cd); disk->flags |=GENHD_FL_REMOVABLE ;add_disk (disk); +disk_events_set_poll_msecs (disk,5000 );
Why do you need this and why is the poll interval universally suitable?
drivers/scsi/sr.c static int sr_probe(struct device *dev) · line 736
Quoted 5 lines
drivers/scsi/sr.c +2
-0sdev_printk (KERN_DEBUG , sdev,"Attached scsi CD-ROM %s\n" , cd->cdi.name); + +/* enable runtime pm */
Not really. What it does is to enable the device to be suspended.
drivers/scsi/sr.c static int sr_remove(struct device *dev) · line 986
Quoted 10 lines
drivers/scsi/sr.c +3
-0+scsi_autopm_put_device (cd->device); +return 0 ; fail_put:@@ -965,6 +983,9 @@ static int sr_remove(struct device *dev) {struct scsi_cd *cd =dev_get_drvdata (dev); +/* disable runtime pm */
And that prevents the device from being suspended (which means that it's going to be resumed at this point in case it was suspended before).
drivers/scsi/sr.c static int sr_remove(struct device *dev) · line 991
Quoted 6 lines
drivers/scsi/sr.c +2
-0+scsi_autopm_get_device (cd->device); +blk_queue_prep_rq (cd->device->request_queue, scsi_prep_fn);del_gendisk (cd->disk);
Thanks,
Rafael
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 5 lines · Rafael J. Wysocki
Quoted 2 lines · Aaron Lu
Place the ODD into runtime suspend state as soon as there is nobody using it.
OK, so how is ODD related to the sr driver?
Aaron did not make it clear in this patch description, although it may have been mentioned in the overall 0/6 description. "ODD" stands for "Optical Disc Drive" -- in other words, a CD or DVD drive. Once you know this, the relation is clear: sr is the SCSI driver for CD/DVD drives.
Alan Stern
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
Quoted 2 lines · Aaron Lu
Place the ODD into runtime suspend state as soon as there is nobody using it.
OK, so how is ODD related to the sr driver?
As Alan has explained, ODD(optical disk drive) is driven by scsi sr driver.
Quoted 5 lines
Quoted 3 lines
The only exception is, if we just find that a new medium is inserted, we wait for the next events checking to idle it.
What exactly do you mean by "to idle it"?
I mean to put its usage count so that its idle callback will kick in.
Quoted 2 lines
Does this patch have any functional effect without the following patches?
Yes, this one alone takes care of ODD's runtime pm while the following patches take care of removing its power after it's runtime suspended. But it doesn't have any real benefit without the following patches.
Quoted 30 lines
Quoted 21 lines
Based on ideas of Alan Stern and Oliver Neukum.
Signed-off-by Aaron Lu <[email protected]>--- drivers/scsi/sr.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)drivers/scsi/sr.c +1
-0@@ -45,6 +45,7 @@#include <linux/blkdev.h> #include <linux/mutex.h> #include <linux/slab.h> +#include <linux/pm_runtime.h> #include <asm/uaccess.h> #include <scsi/scsi.h> drivers/scsi/sr.c static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) · line 152
Quoted 6 lines
drivers/scsi/sr.c +2
-0@@ -146,8 +147,12 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)kref_get (&cd->kref);if (scsi_device_get (cd->device)) goto out_put; +if (scsi_autopm_get_device (cd->device)) + goto out_pm; goto out;Why don't you do
Quoted 4 lines
drivers/scsi/sr.c static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) · line 154
Quoted 2 lines
drivers/scsi/sr.c +2
-0+if (!scsi_autopm_get_device (cd->device)) + goto out;without the new label?
I was just stupidly following the pattern.
Thanks and I'll change this.
Quoted 67 lines
Quoted 55 lines
drivers/scsi/sr.c +8
-4+ out_pm: +scsi_device_put (cd->device); out_put:kref_put (&cd->kref, sr_kref_release); cd =NULL ;@@ -163,6 +168,7 @@ static void scsi_cd_put(struct scsi_cd *cd)mutex_lock (&sr_ref_mutex);kref_put (&cd->kref, sr_kref_release);scsi_device_put (sdev); +scsi_autopm_put_device (sdev);mutex_unlock (&sr_ref_mutex); }@@ -211,7 +217,7 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi, unsigned int clearing, int slot) {struct scsi_cd *cd = cdi->handle; -bool last_present; +bool last_present = cd->media_present;struct scsi_sense_hdr sshdr;unsigned int events;int ret;@@ -220,6 +226,8 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi,if (CDSL_CURRENT != slot)return 0 ; +scsi_autopm_get_device (cd->device); + events =sr_get_events (cd->device); cd->get_event_changed |= events &DISK_EVENT_MEDIA_CHANGE ;@@ -246,10 +254,9 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi, }if (!(clearing &DISK_EVENT_MEDIA_CHANGE )) -return events; + goto out; do_tur:/* let's see whether the media is there with TUR */ - last_present = cd->media_present; ret =scsi_test_unit_ready (cd->device,SR_TIMEOUT ,MAX_RETRIES , &sshdr);/* @@ -270,7 +277,7 @@ do_tur: }if (cd->ignore_get_event) -return events; + goto out;/* check whether GET_EVENT is reporting spurious MEDIA_CHANGE */ if (!cd->tur_changed) {drivers/scsi/sr.c do_tur: · line 302
Quoted 9 lines
drivers/scsi/sr.c +6
-0@@ -287,6 +294,12 @@ do_tur: cd->tur_changed = false; cd->get_event_changed = false; +out: +if (cd->media_present && !last_present) +pm_runtime_put_noidle (&cd->device->sdev_gendev); +else +scsi_autopm_put_device (cd->device); +This thing is asking for a comment.
Quoted 3 lines
It looks like you're kind of avoiding to call
_idle()for the device, but why? What might go wrong ifpm_runtime_put()is used instead of the whole conditional, among other things?
The above code means, if we found that a disc is just inserted(reflected by cd->media_present is true and last_present is false), we do not want to put the device into suspend state immediately until next poll. In the interval, some programs may decide to use this device by opening it.
Nothing will go wrong, but it can possibly avoid a runtime status change.
Quoted 11 lines
drivers/scsi/sr.c static int sr_probe(struct device *dev) · line 731
Quoted 9 lines
drivers/scsi/sr.c +1
-0return events; }@@ -715,9 +728,14 @@ static int sr_probe(struct device *dev)dev_set_drvdata (dev, cd); disk->flags |=GENHD_FL_REMOVABLE ;add_disk (disk); +disk_events_set_poll_msecs (disk,5000 );Why do you need this and why is the poll interval universally suitable?
For a system with udev, the block module parameter events_dfl_poll_msecs will be set to 2s. If disk's events_poll_msecs is not set, that will be used. So the disk will be polled every 2s, that means it will be runtime suspended/resumed every 2s if there is no user. I set it to 5s so that the device can stay in runtime suspended state longer.
And the sysfs interface is still there, if udev thinks a device needs special setting, it will do that and I'll not overwrite that setting.
Quoted 8 lines
drivers/scsi/sr.c static int sr_probe(struct device *dev) · line 736
Quoted 6 lines
drivers/scsi/sr.c +2
-0sdev_printk (KERN_DEBUG , sdev,"Attached scsi CD-ROM %s\n" , cd->cdi.name); + +/* enable runtime pm */ Not really. What it does is to enable the device to be suspended.
OK, will change this.
Quoted 10 lines
Quoted 10 lines
drivers/scsi/sr.c +2
-0+scsi_autopm_put_device (cd->device); +return 0 ; fail_put:@@ -965,6 +983,9 @@ static int sr_remove(struct device *dev) {struct scsi_cd *cd =dev_get_drvdata (dev);
Quoted 4 lines
drivers/scsi/sr.c static int sr_remove(struct device *dev) · line 986
Quoted 1 line
drivers/scsi/sr.c +1
-0+/* disable runtime pm */ And that prevents the device from being suspended (which means that it's going to be resumed at this point in case it was suspended before).
Yes, that's what I want.
We are removing its driver and I think we should undo what we have done to it.
Thanks,
Aaron
Quoted 10 lines
drivers/scsi/sr.c static int sr_remove(struct device *dev) · line 991
Quoted 7 lines
drivers/scsi/sr.c +2
-0+scsi_autopm_get_device (cd->device); +blk_queue_prep_rq (cd->device->request_queue, scsi_prep_fn);del_gendisk (cd->disk);Thanks,
Rafael
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 9 lines · Aaron Lu
Quoted 5 lines · Rafael J. Wysocki
Quoted 2 lines · Aaron Lu
Place the ODD into runtime suspend state as soon as there is nobody using it.
OK, so how is ODD related to the sr driver?
As Alan has explained, ODD(optical disk drive) is driven by scsi sr driver.
OK, but what about writing "ODD (Optical Disk Drive)" in the changelog?
People reading git logs may not know all of the hardware acronyms and the "0" message doesn't go into the git log. :-)
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
The only exception is, if we just find that a new medium is inserted, we wait for the next events checking to idle it.
What exactly do you mean by "to idle it"?
I mean to put its usage count so that its idle callback will kick in.
So I'd just write that directly in the changelog.
Quoted 3 lines
Quoted 1 line
Does this patch have any functional effect without the following patches?
Yes, this one alone takes care of ODD's runtime pm
I suppose you mean the runtime PM status and usage counter? I.e. the "software state"?
Quoted 3 lines
while the following
patches take care of removing its power after it's runtime suspended. But it doesn't have any real benefit without the following patches.
Please put that information into the changelog too.
Quoted 108 lines
Quoted 29 lines
Quoted 20 lines
Based on ideas of Alan Stern and Oliver Neukum.
Signed-off-by Aaron Lu <[email protected]>--- drivers/scsi/sr.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)drivers/scsi/sr.c +1
-0@@ -45,6 +45,7 @@#include <linux/blkdev.h> #include <linux/mutex.h> #include <linux/slab.h> +#include <linux/pm_runtime.h> #include <asm/uaccess.h> #include <scsi/scsi.h> drivers/scsi/sr.c static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) · line 152
Quoted 6 lines
drivers/scsi/sr.c +2
-0@@ -146,8 +147,12 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)kref_get (&cd->kref);if (scsi_device_get (cd->device)) goto out_put; +if (scsi_autopm_get_device (cd->device)) + goto out_pm; goto out;Why don't you do
Quoted 4 lines
drivers/scsi/sr.c static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) · line 154
Quoted 2 lines
drivers/scsi/sr.c +2
-0+if (!scsi_autopm_get_device (cd->device)) + goto out;without the new label?
I was just stupidly following the pattern.
Thanks and I'll change this.Quoted 67 lines
Quoted 55 lines
drivers/scsi/sr.c +8
-4+ out_pm: +scsi_device_put (cd->device); out_put:kref_put (&cd->kref, sr_kref_release); cd =NULL ;@@ -163,6 +168,7 @@ static void scsi_cd_put(struct scsi_cd *cd)mutex_lock (&sr_ref_mutex);kref_put (&cd->kref, sr_kref_release);scsi_device_put (sdev); +scsi_autopm_put_device (sdev);mutex_unlock (&sr_ref_mutex); }@@ -211,7 +217,7 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi, unsigned int clearing, int slot) {struct scsi_cd *cd = cdi->handle; -bool last_present; +bool last_present = cd->media_present;struct scsi_sense_hdr sshdr;unsigned int events;int ret;@@ -220,6 +226,8 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi,if (CDSL_CURRENT != slot)return 0 ; +scsi_autopm_get_device (cd->device); + events =sr_get_events (cd->device); cd->get_event_changed |= events &DISK_EVENT_MEDIA_CHANGE ;@@ -246,10 +254,9 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi, }if (!(clearing &DISK_EVENT_MEDIA_CHANGE )) -return events; + goto out; do_tur:/* let's see whether the media is there with TUR */ - last_present = cd->media_present; ret =scsi_test_unit_ready (cd->device,SR_TIMEOUT ,MAX_RETRIES , &sshdr);/* @@ -270,7 +277,7 @@ do_tur: }if (cd->ignore_get_event) -return events; + goto out;/* check whether GET_EVENT is reporting spurious MEDIA_CHANGE */ if (!cd->tur_changed) {drivers/scsi/sr.c do_tur: · line 302
Quoted 9 lines
drivers/scsi/sr.c +6
-0@@ -287,6 +294,12 @@ do_tur: cd->tur_changed = false; cd->get_event_changed = false; +out: +if (cd->media_present && !last_present) +pm_runtime_put_noidle (&cd->device->sdev_gendev); +else +scsi_autopm_put_device (cd->device); +This thing is asking for a comment.
Quoted 3 lines
It looks like you're kind of avoiding to call
_idle()for the device, but why? What might go wrong ifpm_runtime_put()is used instead of the whole conditional, among other things?
Quoted 6 lines
The above code means, if we found that a disc is just
inserted(reflected by cd->media_present is true and last_present is false), we do not want to put the device into suspend state immediately until next poll. In the interval, some programs may decide to use this device by opening it.Nothing will go wrong, but it can possibly avoid a runtime status change.
OK, so suppose the condition is true and we do the _noidle() put. Who's going to suspend the device in that case if no one actually uses the device?
Quoted 11 lines
Quoted 10 lines
drivers/scsi/sr.c static int sr_probe(struct device *dev) · line 731
Quoted 8 lines
drivers/scsi/sr.c +1
-0return events; }@@ -715,9 +728,14 @@ static int sr_probe(struct device *dev)dev_set_drvdata (dev, cd); disk->flags |=GENHD_FL_REMOVABLE ;add_disk (disk); +disk_events_set_poll_msecs (disk,5000 );Why do you need this and why is the poll interval universally suitable?
Quoted 8 lines
For a system with udev, the block module parameter
events_dfl_poll_msecswill be set to 2s. If disk'sevents_poll_msecsis not set, that will be used. So the disk will be polled every 2s, that means it will be runtime suspended/resumed every 2s if there is no user. I set it to 5s so that the device can stay in runtime suspended state longer.And the sysfs interface is still there, if udev thinks a device needs special setting, it will do that and I'll not overwrite that setting.
I'm not quite convinced this is the right approach here.
So if you set it to 5 s this way, the user space will have no idea that the polling happens less often than it thinks, or am I misunderstanding what you said above?
Moreover, what about changing the code so that the polling doesn't actually resume the device?
Quoted 20 lines
Quoted 7 lines
drivers/scsi/sr.c static int sr_probe(struct device *dev) · line 736
Quoted 5 lines
drivers/scsi/sr.c +2
-0sdev_printk (KERN_DEBUG , sdev,"Attached scsi CD-ROM %s\n" , cd->cdi.name); + +/* enable runtime pm */ Not really. What it does is to enable the device to be suspended.
OK, will change this.
Quoted 10 lines
Quoted 10 lines
drivers/scsi/sr.c +2
-0+scsi_autopm_put_device (cd->device); +return 0 ; fail_put:@@ -965,6 +983,9 @@ static int sr_remove(struct device *dev) {struct scsi_cd *cd =dev_get_drvdata (dev);
Quoted 8 lines
Quoted 4 lines
drivers/scsi/sr.c static int sr_remove(struct device *dev) · line 986
Quoted 1 line
drivers/scsi/sr.c +1
-0+/* disable runtime pm */ And that prevents the device from being suspended (which means that it's going to be resumed at this point in case it was suspended before).
Yes, that's what I want.
We are removing its driver and I think we should undo what we have done to it.
Yes, I agree. Only the comment wording can better reflect what really happens here (runtime PM is not disabled, in particular).
Thanks,
Rafael
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 23 lines · Rafael J. Wysocki
Quoted 9 lines · Aaron Lu
Quoted 5 lines · Rafael J. Wysocki
Quoted 2 lines · Aaron Lu
Place the ODD into runtime suspend state as soon as there is nobody using it.
OK, so how is ODD related to the sr driver?
As Alan has explained, ODD(optical disk drive) is driven by scsi sr driver.
OK, but what about writing "ODD (Optical Disk Drive)" in the changelog?
People reading git logs may not know all of the hardware acronyms and the "0" message doesn't go into the git log. :-)
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
The only exception is, if we just find that a new medium is inserted, we wait for the next events checking to idle it.
What exactly do you mean by "to idle it"?
I mean to put its usage count so that its idle callback will kick in.
Quoted 8 lines
So I'd just write that directly in the changelog.
Quoted 3 lines
Quoted 1 line
Does this patch have any functional effect without the following patches?
Yes, this one alone takes care of ODD's runtime pm
I suppose you mean the runtime PM status and usage counter? I.e. the "software state"?
Yes.
Quoted 6 lines
Quoted 4 lines
while the following
patches take care of removing its power after it's runtime suspended. But it doesn't have any real benefit without the following patches.Please put that information into the changelog too.
As Alan explained, I think I would say:
Though currently it doesn't have any benefit, it allows its parent devices enter runtime suspend state which may save some power.
Quoted 114 lines
Quoted 114 lines
Quoted 30 lines
Quoted 21 lines
Based on ideas of Alan Stern and Oliver Neukum.
Signed-off-by Aaron Lu <[email protected]>--- drivers/scsi/sr.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)drivers/scsi/sr.c +1
-0@@ -45,6 +45,7 @@#include <linux/blkdev.h> #include <linux/mutex.h> #include <linux/slab.h> +#include <linux/pm_runtime.h> #include <asm/uaccess.h> #include <scsi/scsi.h> drivers/scsi/sr.c static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) · line 152
Quoted 6 lines
drivers/scsi/sr.c +2
-0@@ -146,8 +147,12 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)kref_get (&cd->kref);if (scsi_device_get (cd->device)) goto out_put; +if (scsi_autopm_get_device (cd->device)) + goto out_pm; goto out;Why don't you do
Quoted 4 lines
drivers/scsi/sr.c static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) · line 154
Quoted 2 lines
drivers/scsi/sr.c +2
-0+if (!scsi_autopm_get_device (cd->device)) + goto out;without the new label?
I was just stupidly following the pattern.
Thanks and I'll change this.Quoted 67 lines
Quoted 55 lines
drivers/scsi/sr.c +8
-4+ out_pm: +scsi_device_put (cd->device); out_put:kref_put (&cd->kref, sr_kref_release); cd =NULL ;@@ -163,6 +168,7 @@ static void scsi_cd_put(struct scsi_cd *cd)mutex_lock (&sr_ref_mutex);kref_put (&cd->kref, sr_kref_release);scsi_device_put (sdev); +scsi_autopm_put_device (sdev);mutex_unlock (&sr_ref_mutex); }@@ -211,7 +217,7 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi, unsigned int clearing, int slot) {struct scsi_cd *cd = cdi->handle; -bool last_present; +bool last_present = cd->media_present;struct scsi_sense_hdr sshdr;unsigned int events;int ret;@@ -220,6 +226,8 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi,if (CDSL_CURRENT != slot)return 0 ; +scsi_autopm_get_device (cd->device); + events =sr_get_events (cd->device); cd->get_event_changed |= events &DISK_EVENT_MEDIA_CHANGE ;@@ -246,10 +254,9 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi, }if (!(clearing &DISK_EVENT_MEDIA_CHANGE )) -return events; + goto out; do_tur:/* let's see whether the media is there with TUR */ - last_present = cd->media_present; ret =scsi_test_unit_ready (cd->device,SR_TIMEOUT ,MAX_RETRIES , &sshdr);/* @@ -270,7 +277,7 @@ do_tur: }if (cd->ignore_get_event) -return events; + goto out;/* check whether GET_EVENT is reporting spurious MEDIA_CHANGE */ if (!cd->tur_changed) {drivers/scsi/sr.c do_tur: · line 302
Quoted 9 lines
drivers/scsi/sr.c +6
-0@@ -287,6 +294,12 @@ do_tur: cd->tur_changed = false; cd->get_event_changed = false; +out: +if (cd->media_present && !last_present) +pm_runtime_put_noidle (&cd->device->sdev_gendev); +else +scsi_autopm_put_device (cd->device); +This thing is asking for a comment.
Quoted 3 lines
It looks like you're kind of avoiding to call
_idle()for the device, but why? What might go wrong ifpm_runtime_put()is used instead of the whole conditional, among other things?The above code means, if we found that a disc is just
inserted(reflected by cd->media_present is true and last_present is false), we do not want to put the device into suspend state immediately until next poll. In the interval, some programs may decide to use this device by opening it.
Quoted 4 lines
Quoted 1 line
Nothing will go wrong, but it can possibly avoid a runtime status change.
OK, so suppose the condition is true and we do the
_noidle()put. Who's going to suspend the device in that case if no one actually uses the device?
Next time when the check_events poll runs, it will find that:
1 Either the disc is still there, then both last_present and
media_present would be true, we will do the put to idle it;
2 Or the disc is ejected, we will do the put to idle it.
The poll runs periodically, until the device is powered off(reflected by the powered_off flag), in which case, the poll will simply return 0 without touching this device.
Quoted 18 lines
Quoted 18 lines
Quoted 11 lines
drivers/scsi/sr.c static int sr_probe(struct device *dev) · line 731
Quoted 9 lines
drivers/scsi/sr.c +1
-0return events; }@@ -715,9 +728,14 @@ static int sr_probe(struct device *dev)dev_set_drvdata (dev, cd); disk->flags |=GENHD_FL_REMOVABLE ;add_disk (disk); +disk_events_set_poll_msecs (disk,5000 );Why do you need this and why is the poll interval universally suitable?
For a system with udev, the block module parameter
events_dfl_poll_msecswill be set to 2s. If disk'sevents_poll_msecsis not set, that will be used. So the disk will be polled every 2s, that means it will be runtime suspended/resumed every 2s if there is no user. I set it to 5s so that the device can stay in runtime suspended state longer.
Quoted 8 lines
Quoted 2 lines
And the sysfs interface is still there, if udev thinks a device needs special setting, it will do that and I'll not overwrite that setting.
I'm not quite convinced this is the right approach here.
So if you set it to 5 s this way, the user space will have no idea that the polling happens less often than it thinks, or am I misunderstanding what you said above?
That's correct.
AFAIK, user space does not care how often the device is polled, it cares only one thing: when there is a media change event, please let me know(through uevent).
I agree that we can't make user wait for too long before seeing something happen(auto play, etc.) after he inserted a disc, and 5 seconds doesn't seem too long to me.
Quoted 3 lines
Moreover, what about changing the code so that the polling doesn't actually resume the device?
Since the device is going to do IO(executing a scsi command), I think I should resume the device.
But there is a case for ZPODD, when the ODD is powered off(reflected by the powered_off flag), the events checking will simply return without resuming the device.
Quoted 26 lines
Quoted 26 lines
Quoted 8 lines
drivers/scsi/sr.c static int sr_probe(struct device *dev) · line 736
Quoted 6 lines
drivers/scsi/sr.c +2
-0sdev_printk (KERN_DEBUG , sdev,"Attached scsi CD-ROM %s\n" , cd->cdi.name); + +/* enable runtime pm */ Not really. What it does is to enable the device to be suspended.
OK, will change this.
Quoted 14 lines
drivers/scsi/sr.c static int sr_remove(struct device *dev) · line 986
Quoted 11 lines
drivers/scsi/sr.c +3
-0+scsi_autopm_put_device (cd->device); +return 0 ; fail_put:@@ -965,6 +983,9 @@ static int sr_remove(struct device *dev) {struct scsi_cd *cd =dev_get_drvdata (dev); +/* disable runtime pm */ And that prevents the device from being suspended (which means that it's going to be resumed at this point in case it was suspended before).
Quoted 6 lines
Quoted 3 lines
Yes, that's what I want.
We are removing its driver and I think we should undo what we have done to it.Yes, I agree. Only the comment wording can better reflect what really happens here (runtime PM is not disabled, in particular).
OK, looks like you are saying by disable, disable_depth is the subject while I'm playing with usage_count. I'll pay attention to these words, thanks for the remind.
-Aaron
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 40 lines · Aaron Lu
Quoted 23 lines · Rafael J. Wysocki
Quoted 9 lines · Aaron Lu
Quoted 5 lines · Rafael J. Wysocki
Quoted 2 lines · Aaron Lu
Place the ODD into runtime suspend state as soon as there is nobody using it.
OK, so how is ODD related to the sr driver?
As Alan has explained, ODD(optical disk drive) is driven by scsi sr driver.
OK, but what about writing "ODD (Optical Disk Drive)" in the changelog?
People reading git logs may not know all of the hardware acronyms and the "0" message doesn't go into the git log. :-)
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
The only exception is, if we just find that a new medium is inserted, we wait for the next events checking to idle it.
What exactly do you mean by "to idle it"?
I mean to put its usage count so that its idle callback will kick in.
Quoted 8 lines
So I'd just write that directly in the changelog.
Quoted 3 lines
Quoted 1 line
Does this patch have any functional effect without the following patches?
Yes, this one alone takes care of ODD's runtime pm
I suppose you mean the runtime PM status and usage counter? I.e. the "software state"?
Yes.
Quoted 5 lines
Quoted 4 lines
while the following
patches take care of removing its power after it's runtime suspended. But it doesn't have any real benefit without the following patches.
Quoted 5 lines
Quoted 1 line
Please put that information into the changelog too.
As Alan explained, I think I would say:
Though currently it doesn't have any benefit, it allows its parent devices enter runtime suspend state which may save some power.
Well, please say that in the changelog, then. :-)
Quoted 115 lines
Quoted 115 lines
Quoted 114 lines
Quoted 29 lines
Quoted 20 lines
Based on ideas of Alan Stern and Oliver Neukum.
Signed-off-by Aaron Lu <[email protected]>--- drivers/scsi/sr.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)drivers/scsi/sr.c +1
-0@@ -45,6 +45,7 @@#include <linux/blkdev.h> #include <linux/mutex.h> #include <linux/slab.h> +#include <linux/pm_runtime.h> #include <asm/uaccess.h> #include <scsi/scsi.h> drivers/scsi/sr.c static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) · line 152
Quoted 6 lines
drivers/scsi/sr.c +2
-0@@ -146,8 +147,12 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)kref_get (&cd->kref);if (scsi_device_get (cd->device)) goto out_put; +if (scsi_autopm_get_device (cd->device)) + goto out_pm; goto out;Why don't you do
Quoted 4 lines
drivers/scsi/sr.c static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) · line 154
Quoted 2 lines
drivers/scsi/sr.c +2
-0+if (!scsi_autopm_get_device (cd->device)) + goto out;without the new label?
I was just stupidly following the pattern.
Thanks and I'll change this.Quoted 67 lines
Quoted 55 lines
drivers/scsi/sr.c +8
-4+ out_pm: +scsi_device_put (cd->device); out_put:kref_put (&cd->kref, sr_kref_release); cd =NULL ;@@ -163,6 +168,7 @@ static void scsi_cd_put(struct scsi_cd *cd)mutex_lock (&sr_ref_mutex);kref_put (&cd->kref, sr_kref_release);scsi_device_put (sdev); +scsi_autopm_put_device (sdev);mutex_unlock (&sr_ref_mutex); }@@ -211,7 +217,7 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi, unsigned int clearing, int slot) {struct scsi_cd *cd = cdi->handle; -bool last_present; +bool last_present = cd->media_present;struct scsi_sense_hdr sshdr;unsigned int events;int ret;@@ -220,6 +226,8 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi,if (CDSL_CURRENT != slot)return 0 ; +scsi_autopm_get_device (cd->device); + events =sr_get_events (cd->device); cd->get_event_changed |= events &DISK_EVENT_MEDIA_CHANGE ;@@ -246,10 +254,9 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi, }if (!(clearing &DISK_EVENT_MEDIA_CHANGE )) -return events; + goto out; do_tur:/* let's see whether the media is there with TUR */ - last_present = cd->media_present; ret =scsi_test_unit_ready (cd->device,SR_TIMEOUT ,MAX_RETRIES , &sshdr);/* @@ -270,7 +277,7 @@ do_tur: }if (cd->ignore_get_event) -return events; + goto out;/* check whether GET_EVENT is reporting spurious MEDIA_CHANGE */ if (!cd->tur_changed) {drivers/scsi/sr.c do_tur: · line 302
Quoted 9 lines
drivers/scsi/sr.c +6
-0@@ -287,6 +294,12 @@ do_tur: cd->tur_changed = false; cd->get_event_changed = false; +out: +if (cd->media_present && !last_present) +pm_runtime_put_noidle (&cd->device->sdev_gendev); +else +scsi_autopm_put_device (cd->device); +This thing is asking for a comment.
Quoted 3 lines
It looks like you're kind of avoiding to call
_idle()for the device, but why? What might go wrong ifpm_runtime_put()is used instead of the whole conditional, among other things?The above code means, if we found that a disc is just
inserted(reflected by cd->media_present is true and last_present is false), we do not want to put the device into suspend state immediately until next poll. In the interval, some programs may decide to use this device by opening it.Nothing will go wrong, but it can possibly avoid a runtime status change.
Quoted 7 lines
Quoted 2 lines
OK, so suppose the condition is true and we do the
_noidle()put. Who's going to suspend the device in that case if no one actually uses the device?Next time when the
check_eventspoll runs, it will find that:
1 Either the disc is still there, then bothlast_presentand
media_presentwould be true, we will do the put to idle it;
2 Or the disc is ejected, we will do the put to idle it.
In that case I would do:
pm_runtime_put_noidle(&cd->device->sdev_gendev);
if (cd->media_present && !last_present)
pm_runtime_suspend(&cd->device->sdev_gendev);
And I'd add a comment about the next poll.
This appears somewhat racy, though, because in theory a media may be inserted while we are removing power from the device. Isn't that a problem?
Quoted 3 lines
The poll runs periodically, until the device is powered
off(reflected by the powered_off flag), in which case, the poll will simply return 0 without touching this device.
Is it useful to poll the device after it has been suspended, but not powered off?
Quoted 22 lines
Quoted 22 lines
Quoted 11 lines
Quoted 10 lines
drivers/scsi/sr.c static int sr_probe(struct device *dev) · line 731
Quoted 8 lines
drivers/scsi/sr.c +1
-0return events; }@@ -715,9 +728,14 @@ static int sr_probe(struct device *dev)dev_set_drvdata (dev, cd); disk->flags |=GENHD_FL_REMOVABLE ;add_disk (disk); +disk_events_set_poll_msecs (disk,5000 );Why do you need this and why is the poll interval universally suitable?
Quoted 8 lines
For a system with udev, the block module parameter
events_dfl_poll_msecswill be set to 2s. If disk'sevents_poll_msecsis not set, that will be used. So the disk will be polled every 2s, that means it will be runtime suspended/resumed every 2s if there is no user. I set it to 5s so that the device can stay in runtime suspended state longer.And the sysfs interface is still there, if udev thinks a device needs special setting, it will do that and I'll not overwrite that setting.
I'm not quite convinced this is the right approach here.
Quoted 8 lines
Quoted 3 lines
So if you set it to 5 s this way, the user space will have no idea that the polling happens less often than it thinks, or am I misunderstanding what you said above?
That's correct.
AFAIK, user space does not care how often the device is polled, it cares only one thing: when there is a media change event, please let me know(through uevent).
So that's why we do the polling, right?
Quoted 8 lines
I agree that we can't make user wait for too long before seeing something
happen(auto play, etc.)after he inserted a disc, and 5 seconds doesn't seem too long to me.Quoted 3 lines
Moreover, what about changing the code so that the polling doesn't actually resume the device?
Quoted 6 lines
Since the device is going to do IO(executing a scsi command), I think I should resume the device.
But there is a case for ZPODD, when the ODD is powered
off(reflected by the powered_off flag), the events checking will simply return without resuming the device.
Yes, I understand that. My question is whether or not we still need to poll if the device hasn't been powered off, although it has been suspended.
Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 7 lines
drivers/scsi/sr.c static int sr_probe(struct device *dev) · line 736
Quoted 5 lines
drivers/scsi/sr.c +2
-0sdev_printk (KERN_DEBUG , sdev,"Attached scsi CD-ROM %s\n" , cd->cdi.name); + +/* enable runtime pm */ Not really. What it does is to enable the device to be suspended.
OK, will change this.
Quoted 10 lines
Quoted 10 lines
drivers/scsi/sr.c +2
-0+scsi_autopm_put_device (cd->device); +return 0 ; fail_put:@@ -965,6 +983,9 @@ static int sr_remove(struct device *dev) {struct scsi_cd *cd =dev_get_drvdata (dev);Quoted 4 lines
drivers/scsi/sr.c static int sr_remove(struct device *dev) · line 986
Quoted 1 line
drivers/scsi/sr.c +1
-0+/* disable runtime pm */ And that prevents the device from being suspended (which means that it's going to be resumed at this point in case it was suspended before).
Yes, that's what I want.
We are removing its driver and I think we should undo what we have done to it.
Quoted 6 lines
Quoted 2 lines
Yes, I agree. Only the comment wording can better reflect what really happens here (runtime PM is not disabled, in particular).
OK, looks like you are saying by disable,
disable_depthis the subject while I'm playing withusage_count. I'll pay attention to these words, thanks for the remind.
Please do.
Thanks,
Rafael
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 172 lines · Rafael J. Wysocki
Quoted 40 lines · Aaron Lu
Quoted 23 lines · Rafael J. Wysocki
Quoted 9 lines · Aaron Lu
Quoted 5 lines · Rafael J. Wysocki
Quoted 2 lines · Aaron Lu
Place the ODD into runtime suspend state as soon as there is nobody using it.
OK, so how is ODD related to the sr driver?
As Alan has explained, ODD(optical disk drive) is driven by scsi sr driver.
OK, but what about writing "ODD (Optical Disk Drive)" in the changelog?
People reading git logs may not know all of the hardware acronyms and the "0" message doesn't go into the git log. :-)
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
The only exception is, if we just find that a new medium is inserted, we wait for the next events checking to idle it.
What exactly do you mean by "to idle it"?
I mean to put its usage count so that its idle callback will kick in.
Quoted 8 lines
So I'd just write that directly in the changelog.
Quoted 3 lines
Quoted 1 line
Does this patch have any functional effect without the following patches?
Yes, this one alone takes care of ODD's runtime pm
I suppose you mean the runtime PM status and usage counter? I.e. the "software state"?
Yes.
Quoted 5 lines
Quoted 4 lines
while the following
patches take care of removing its power after it's runtime suspended. But it doesn't have any real benefit without the following patches.Quoted 5 lines
Quoted 1 line
Please put that information into the changelog too.
As Alan explained, I think I would say:
Though currently it doesn't have any benefit, it allows its parent devices enter runtime suspend state which may save some power.Well, please say that in the changelog, then. :-)
Quoted 115 lines
Quoted 115 lines
Quoted 114 lines
Quoted 29 lines
Quoted 20 lines
Based on ideas of Alan Stern and Oliver Neukum.
Signed-off-by Aaron Lu <[email protected]>--- drivers/scsi/sr.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)drivers/scsi/sr.c +1
-0@@ -45,6 +45,7 @@#include <linux/blkdev.h> #include <linux/mutex.h> #include <linux/slab.h> +#include <linux/pm_runtime.h> #include <asm/uaccess.h> #include <scsi/scsi.h> drivers/scsi/sr.c static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) · line 152
Quoted 6 lines
drivers/scsi/sr.c +2
-0@@ -146,8 +147,12 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)kref_get (&cd->kref);if (scsi_device_get (cd->device)) goto out_put; +if (scsi_autopm_get_device (cd->device)) + goto out_pm; goto out;Why don't you do
Quoted 4 lines
drivers/scsi/sr.c static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) · line 154
Quoted 2 lines
drivers/scsi/sr.c +2
-0+if (!scsi_autopm_get_device (cd->device)) + goto out;without the new label?
I was just stupidly following the pattern.
Thanks and I'll change this.Quoted 67 lines
Quoted 55 lines
drivers/scsi/sr.c +8
-4+ out_pm: +scsi_device_put (cd->device); out_put:kref_put (&cd->kref, sr_kref_release); cd =NULL ;@@ -163,6 +168,7 @@ static void scsi_cd_put(struct scsi_cd *cd)mutex_lock (&sr_ref_mutex);kref_put (&cd->kref, sr_kref_release);scsi_device_put (sdev); +scsi_autopm_put_device (sdev);mutex_unlock (&sr_ref_mutex); }@@ -211,7 +217,7 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi, unsigned int clearing, int slot) {struct scsi_cd *cd = cdi->handle; -bool last_present; +bool last_present = cd->media_present;struct scsi_sense_hdr sshdr;unsigned int events;int ret;@@ -220,6 +226,8 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi,if (CDSL_CURRENT != slot)return 0 ; +scsi_autopm_get_device (cd->device); + events =sr_get_events (cd->device); cd->get_event_changed |= events &DISK_EVENT_MEDIA_CHANGE ;@@ -246,10 +254,9 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi, }if (!(clearing &DISK_EVENT_MEDIA_CHANGE )) -return events; + goto out; do_tur:/* let's see whether the media is there with TUR */ - last_present = cd->media_present; ret =scsi_test_unit_ready (cd->device,SR_TIMEOUT ,MAX_RETRIES , &sshdr);/* @@ -270,7 +277,7 @@ do_tur: }if (cd->ignore_get_event) -return events; + goto out;/* check whether GET_EVENT is reporting spurious MEDIA_CHANGE */ if (!cd->tur_changed) {drivers/scsi/sr.c do_tur: · line 302
Quoted 9 lines
drivers/scsi/sr.c +6
-0@@ -287,6 +294,12 @@ do_tur: cd->tur_changed = false; cd->get_event_changed = false; +out: +if (cd->media_present && !last_present) +pm_runtime_put_noidle (&cd->device->sdev_gendev); +else +scsi_autopm_put_device (cd->device); +This thing is asking for a comment.
Quoted 3 lines
It looks like you're kind of avoiding to call
_idle()for the device, but why? What might go wrong ifpm_runtime_put()is used instead of the whole conditional, among other things?The above code means, if we found that a disc is just
inserted(reflected by cd->media_present is true and last_present is false), we do not want to put the device into suspend state immediately until next poll. In the interval, some programs may decide to use this device by opening it.Nothing will go wrong, but it can possibly avoid a runtime status change.
Quoted 7 lines
Quoted 2 lines
OK, so suppose the condition is true and we do the
_noidle()put. Who's going to suspend the device in that case if no one actually uses the device?Next time when the
check_eventspoll runs, it will find that:
1 Either the disc is still there, then bothlast_presentand
media_presentwould be true, we will do the put to idle it;
2 Or the disc is ejected, we will do the put to idle it.
Quoted 5 lines
In that case I would do:
pm_runtime_put_noidle(&cd->device->sdev_gendev);
if (cd->media_present&& !last_present)pm_runtime_suspend(&cd->device->sdev_gendev);
This doesn't cover the !cd->media_present(media not present) case. If there is no media present, we will also need to idle it.
Quoted 5 lines
And I'd add a comment about the next poll.
This appears somewhat racy, though, because in theory a media may be inserted while we are removing power from the device. Isn't that a problem?
Yes, this is a problem.
To avoid this race, I think the following needs to be done:
- For slot type ODD, make it such that user can't insert a disc;
- For tray type ODD, make it such that when user presses the eject button, the tray doesn't open.
I'll see if this is possible, thanks for the remind.
Quoted 7 lines
Quoted 4 lines
The poll runs periodically, until the device is powered
off(reflected by the powered_off flag), in which case, the poll will simply return 0 without touching this device.Is it useful to poll the device after it has been suspended, but not powered off?
Yes, it is necessary to poll the device when it has been suspended with power left. The reason is, we need to check if there is a media change event happened, and the way to check this is to issue a GET_EVENT_STATUS_NOTIFICATION comand.
Please note that when the drive is not powered off, it will not send us a notification when its eject button is pressed.
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 12 lines
Quoted 11 lines
drivers/scsi/sr.c static int sr_probe(struct device *dev) · line 731
Quoted 9 lines
drivers/scsi/sr.c +1
-0return events; }@@ -715,9 +728,14 @@ static int sr_probe(struct device *dev)dev_set_drvdata (dev, cd); disk->flags |=GENHD_FL_REMOVABLE ;add_disk (disk); +disk_events_set_poll_msecs (disk,5000 );Why do you need this and why is the poll interval universally suitable?
Quoted 8 lines
For a system with udev, the block module parameter
events_dfl_poll_msecswill be set to 2s. If disk'sevents_poll_msecsis not set, that will be used. So the disk will be polled every 2s, that means it will be runtime suspended/resumed every 2s if there is no user. I set it to 5s so that the device can stay in runtime suspended state longer.And the sysfs interface is still there, if udev thinks a device needs special setting, it will do that and I'll not overwrite that setting.
I'm not quite convinced this is the right approach here.
So if you set it to 5 s this way, the user space will have no idea that the polling happens less often than it thinks, or am I misunderstanding what you said above?
Quoted 6 lines
Quoted 4 lines
That's correct.
AFAIK, user space does not care how often the device is polled, it cares only one thing: when there is a media change event, please let me know(through uevent).So that's why we do the polling, right?
Yes.
Quoted 12 lines
Quoted 12 lines
I agree that we can't make user wait for too long before seeing something
happen(auto play, etc.)after he inserted a disc, and 5 seconds doesn't seem too long to me.Quoted 3 lines
Moreover, what about changing the code so that the polling doesn't actually resume the device?
Since the device is going to do IO(executing a scsi command), I think I should resume the device.
Quoted 6 lines
Quoted 3 lines
But there is a case for ZPODD, when the ODD is powered
off(reflected by the powered_off flag), the events checking will simply return without resuming the device.Yes, I understand that. My question is whether or not we still need to poll if the device hasn't been powered off, although it has been suspended.
Yes, it's necessary.
Thanks,
Aaron
Quoted 41 lines
Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Quoted 8 lines
drivers/scsi/sr.c static int sr_probe(struct device *dev) · line 736
Quoted 6 lines
drivers/scsi/sr.c +2
-0sdev_printk (KERN_DEBUG , sdev,"Attached scsi CD-ROM %s\n" , cd->cdi.name); + +/* enable runtime pm */ Not really. What it does is to enable the device to be suspended.
OK, will change this.
Quoted 10 lines
Quoted 10 lines
drivers/scsi/sr.c +2
-0+scsi_autopm_put_device (cd->device); +return 0 ; fail_put:@@ -965,6 +983,9 @@ static int sr_remove(struct device *dev) {struct scsi_cd *cd =dev_get_drvdata (dev);Quoted 4 lines
drivers/scsi/sr.c static int sr_remove(struct device *dev) · line 986
Quoted 1 line
drivers/scsi/sr.c +1
-0+/* disable runtime pm */ And that prevents the device from being suspended (which means that it's going to be resumed at this point in case it was suspended before).
Yes, that's what I want.
We are removing its driver and I think we should undo what we have done to it.Quoted 6 lines
Quoted 2 lines
Yes, I agree. Only the comment wording can better reflect what really happens here (runtime PM is not disabled, in particular).
OK, looks like you are saying by disable,
disable_depthis the subject while I'm playing withusage_count. I'll pay attention to these words, thanks for the remind.Please do.
Thanks,
Rafael
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 6 lines · Aaron Lu
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Aaron Lu
Quoted 3 lines · Rafael J. Wysocki
Quoted 2 lines · Aaron Lu
Quoted 1 line · Rafael J. Wysocki
On Wednesday, September 12, 2012, Aaron Lu wrote:
[...]
Quoted 34 lines
Quoted 34 lines
Quoted 33 lines
Quoted 24 lines
Quoted 24 lines
Quoted 15 lines
Review do_tur: · line 302
Quoted 12 lines
(quoted diff) +6
-0/* check whether GET_EVENT is reporting spurious MEDIA_CHANGE */ if (!cd->tur_changed) {@@ -287,6 +294,12 @@ do_tur: cd->tur_changed = false; cd->get_event_changed = false; +out: + if (cd->media_present && !last_present) + pm_runtime_put_noidle(&cd->device->sdev_gendev); + else + scsi_autopm_put_device(cd->device); +This thing is asking for a comment.
Quoted 3 lines
It looks like you're kind of avoiding to call
_idle()for the device, but why? What might go wrong ifpm_runtime_put()is used instead of the whole conditional, among other things?The above code means, if we found that a disc is just
inserted(reflected by cd->media_present is true and last_present is false), we do not want to put the device into suspend state immediately until next poll. In the interval, some programs may decide to use this device by opening it.Quoted 4 lines
Quoted 1 line
Nothing will go wrong, but it can possibly avoid a runtime status change.
OK, so suppose the condition is true and we do the
_noidle()put. Who's going to suspend the device in that case if no one actually uses the device?Next time when the
check_eventspoll runs, it will find that:
1 Either the disc is still there, then bothlast_presentand
media_presentwould be true, we will do the put to idle it;
2 Or the disc is ejected, we will do the put to idle it.
Quoted 8 lines
Quoted 5 lines
In that case I would do:
pm_runtime_put_noidle(&cd->device->sdev_gendev);
if (cd->media_present&& !last_present)pm_runtime_suspend(&cd->device->sdev_gendev);This doesn't cover the !cd->media_present(media not present) case. If there is no media present, we will also need to idle it.
Oh, I got the condition backwards. I meant:
pm_runtime_put_noidle(&cd->device->sdev_gendev);
if (!cd->media_present || last_present)
pm_runtime_suspend(&cd->device->sdev_gendev);
which should be equivalent to your original code (if I'm not mistaken again).
Quoted 11 lines
Quoted 4 lines
And I'd add a comment about the next poll.
This appears somewhat racy, though, because in theory a media may be inserted while we are removing power from the device. Isn't that a problem?
Yes, this is a problem.
To avoid this race, I think the following needs to be done:
- For slot type ODD, make it such that user can't insert a disc;
- For tray type ODD, make it such that when user presses the eject button, the tray doesn't open.
I'll see if this is possible, thanks for the remind.
OK
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
The poll runs periodically, until the device is powered
off(reflected by the powered_off flag), in which case, the poll will simply return 0 without touching this device.Is it useful to poll the device after it has been suspended, but not powered off?
Quoted 7 lines
Yes, it is necessary to poll the device when it has been suspended with power left. The reason is, we need to check if there is a media change event happened, and the way to check this is to issue a
GET_EVENT_STATUS_NOTIFICATIONcomand.Please note that when the drive is not powered off, it will not send us a notification when its eject button is pressed.
I'm not sure about that, actually. If it doesn't notify us, that whole thing is inherently racy pretty much beyond fixing, because it is always possible that the user will press the eject button right after we've checked the status last time and right before power removal. We're going to lose that event, so the user will have to push the button once again in that case.
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 11 lines
Quoted 10 lines
Review static int sr_probe(struct device *dev) · line 731
Quoted 8 lines
(quoted diff) +1
-0return events; }@@ -715,9 +728,14 @@ static int sr_probe(struct device *dev) dev_set_drvdata(dev, cd); disk->flags |= GENHD_FL_REMOVABLE; add_disk(disk); + disk_events_set_poll_msecs(disk, 5000);Why do you need this and why is the poll interval universally suitable?
Quoted 8 lines
For a system with udev, the block module parameter
events_dfl_poll_msecswill be set to 2s. If disk'sevents_poll_msecsis not set, that will be used. So the disk will be polled every 2s, that means it will be runtime suspended/resumed every 2s if there is no user. I set it to 5s so that the device can stay in runtime suspended state longer.And the sysfs interface is still there, if udev thinks a device needs special setting, it will do that and I'll not overwrite that setting.
I'm not quite convinced this is the right approach here.
So if you set it to 5 s this way, the user space will have no idea that the polling happens less often than it thinks, or am I misunderstanding what you said above?
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
That's correct.
AFAIK, user space does not care how often the device is polled, it cares only one thing: when there is a media change event, please let me know(through uevent).So that's why we do the polling, right?
Yes.
Well, that's difficult.
If the remote wakeup is signaled through a GPE, it should be possible to enable it before we actually put the device into D3cold. That may allow us to eliminate the races.
Thanks,
Rafael
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 7 lines · Rafael J. Wysocki
Quoted 6 lines · Aaron Lu
Quoted 4 lines · Rafael J. Wysocki
And I'd add a comment about the next poll.
This appears somewhat racy, though, because in theory a media may be inserted while we are removing power from the device. Isn't that a problem?
Quoted 8 lines
Quoted 6 lines
Yes, this is a problem.
To avoid this race, I think the following needs to be done:
- For slot type ODD, make it such that user can't insert a disc;
- For tray type ODD, make it such that when user presses the eject button, the tray doesn't open.
I'll see if this is possible, thanks for the remind.OK
Looks like this is not the right thing to do, if I lock the door user will be confused.
Quoted 13 lines
Quoted 13 lines
Quoted 7 lines
Quoted 4 lines
The poll runs periodically, until the device is powered
off(reflected by the powered_off flag), in which case, the poll will simply return 0 without touching this device.Is it useful to poll the device after it has been suspended, but not powered off?
Yes, it is necessary to poll the device when it has been suspended with power left. The reason is, we need to check if there is a media change event happened, and the way to check this is to issue a
GET_EVENT_STATUS_NOTIFICATIONcomand.
Quoted 8 lines
Quoted 2 lines
Please note that when the drive is not powered off, it will not send us a notification when its eject button is pressed.
I'm not sure about that, actually. If it doesn't notify us, that whole thing is inherently racy pretty much beyond fixing, because it is always possible that the user will press the eject button right after we've checked the status last time and right before power removal. We're going to lose that event, so the user will have to push the button once again in that case.
I just checked the spec again and tested, when the ODD has power, it will also send out notifications on pressing the eject button/inserting a disc. So we should be able to capture such a event.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
That's correct.
AFAIK, user space does not care how often the device is polled, it cares only one thing: when there is a media change event, please let me know(through uevent).So that's why we do the polling, right?
Quoted 7 lines
Quoted 1 line
Yes.
Well, that's difficult.
If the remote wakeup is signaled through a GPE, it should be possible to enable it before we actually put the device into D3cold. That may allow us to eliminate the races.
Thanks for the suggestion, I'll update the code.
I'm thinking of enabling this GPE in sr_suspend once we decided that it is ready to be powered off, so the time frame between sr_suspend and when the power is actually removed in libata should be taken care of by the GPE. If GPE fires, the notification function will request a runtime resume of the device. Does this sound OK?
Thanks,
Aaron
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 42 lines · Aaron Lu
Quoted 7 lines · Rafael J. Wysocki
Quoted 6 lines · Aaron Lu
Quoted 4 lines · Rafael J. Wysocki
And I'd add a comment about the next poll.
This appears somewhat racy, though, because in theory a media may be inserted while we are removing power from the device. Isn't that a problem?
Quoted 8 lines
Quoted 6 lines
Yes, this is a problem.
To avoid this race, I think the following needs to be done:
- For slot type ODD, make it such that user can't insert a disc;
- For tray type ODD, make it such that when user presses the eject button, the tray doesn't open.
I'll see if this is possible, thanks for the remind.OK
Looks like this is not the right thing to do, if I lock the door user will be confused.
Quoted 13 lines
Quoted 13 lines
Quoted 7 lines
Quoted 4 lines
The poll runs periodically, until the device is powered
off(reflected by the powered_off flag), in which case, the poll will simply return 0 without touching this device.Is it useful to poll the device after it has been suspended, but not powered off?
Yes, it is necessary to poll the device when it has been suspended with power left. The reason is, we need to check if there is a media change event happened, and the way to check this is to issue a
GET_EVENT_STATUS_NOTIFICATIONcomand.Quoted 8 lines
Quoted 2 lines
Please note that when the drive is not powered off, it will not send us a notification when its eject button is pressed.
I'm not sure about that, actually. If it doesn't notify us, that whole thing is inherently racy pretty much beyond fixing, because it is always possible that the user will press the eject button right after we've checked the status last time and right before power removal. We're going to lose that event, so the user will have to push the button once again in that case.
Quoted 3 lines
I just checked the spec again and tested, when the ODD has power, it will also send out notifications on pressing the eject button/inserting a disc. So we should be able to capture such a event.
Good!
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
That's correct.
AFAIK, user space does not care how often the device is polled, it cares only one thing: when there is a media change event, please let me know(through uevent).So that's why we do the polling, right?
Quoted 7 lines
Quoted 1 line
Yes.
Well, that's difficult.
If the remote wakeup is signaled through a GPE, it should be possible to enable it before we actually put the device into D3cold. That may allow us to eliminate the races.
Quoted 7 lines
Thanks for the suggestion, I'll update the code.
I'm thinking of enabling this GPE in
sr_suspendonce we decided that it is ready to be powered off, so the time frame betweensr_suspendand when the power is actually removed in libata should be taken care of by the GPE. If GPE fires, the notification function will request a runtime resume of the device. Does this sound OK?
Well, depending on the implementation. sr_suspend() should be rather generic, but the ACPI association (including the GPE thing) is specific to ATA.
Thanks,
Rafael
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 9 lines · Rafael J. Wysocki
Quoted 5 lines · Aaron Lu
I'm thinking of enabling this GPE in
sr_suspendonce we decided that it is ready to be powered off, so the time frame betweensr_suspendand when the power is actually removed in libata should be taken care of by the GPE. If GPE fires, the notification function will request a runtime resume of the device. Does this sound OK?Well, depending on the implementation.
sr_suspend()should be rather generic, but the ACPI association (including the GPE thing) is specific to ATA.
Sorry, but don't quite understand this.
We have ACPI bindings for scsi devices, isn't that for us to use ACPI when needed in scsi?
BTW, if sr_suspend should be generic, that would suggest I shouldn't write any ZPODD related code there, right? Any suggestion where these code should go then?
Thanks,
Aaron
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 8 lines · On Tuesday 25 September 2012 22:20:21 Aaron Lu wrote:
Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines · Aaron Lu
I'm thinking of enabling this GPE in
sr_suspendonce we decided that it is ready to be powered off, so the time frame betweensr_suspendand when the power is actually removed in libata should be taken care of by the GPE. If GPE fires, the notification function will request a runtime resume of the device. Does this sound OK?
Quoted 7 lines
Quoted 2 lines
Well, depending on the implementation.
sr_suspend()should be rather generic, but the ACPI association (including the GPE thing) is specific to ATA.Sorry, but don't quite understand this.
We have ACPI bindings for scsi devices, isn't that for us to use ACPI when needed in scsi?
We don't have ACPI bindings for generic SCSI devices. We have such bindings for SATA drives. You can put such things only in sr if it applies to all (maybe most) types of drives.
Quoted 3 lines
BTW, if
sr_suspendshould be generic, that would suggest I shouldn't write any ZPODD related code there, right? Any suggestion where these code should go then?
libata. Maybe some generic hooks can be called in sr_suspend().
Regards
Oliver
PS: Are you sure sr_suspend() handles DVD-RAMs correctly?
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 12 lines · Oliver Neukum
Quoted 11 lines · On Tuesday 25 September 2012 22:20:21 Aaron Lu wrote:
Quoted 9 lines · Rafael J. Wysocki
Quoted 5 lines · Aaron Lu
I'm thinking of enabling this GPE in
sr_suspendonce we decided that it is ready to be powered off, so the time frame betweensr_suspendand when the power is actually removed in libata should be taken care of by the GPE. If GPE fires, the notification function will request a runtime resume of the device. Does this sound OK?Well, depending on the implementation.
sr_suspend()should be rather generic, but the ACPI association (including the GPE thing) is specific to ATA.
Quoted 8 lines
Quoted 4 lines
Sorry, but don't quite understand this.
We have ACPI bindings for scsi devices, isn't that for us to use ACPI when needed in scsi?
We don't have ACPI bindings for generic SCSI devices. We have such bindings for SATA drives. You can put such things only in sr if it applies to all (maybe most) types of drives.
OK. Then these scsi bindings for sata drives will be pretty much of no use I think.
Quoted 6 lines
Quoted 4 lines
BTW, if
sr_suspendshould be generic, that would suggest I shouldn't write any ZPODD related code there, right? Any suggestion where these code should go then?libata. Maybe some generic hooks can be called in
sr_suspend().
Thanks for the suggestion.
The problem is, I need to know whether the door is closed and if there is a medium inside. I've no way of getting such information in libata.
Quoted 1 line
PS: Are you sure
sr_suspend()handles DVD-RAMs correctly?
No. Is there a spec for it?
Considering there are many different drives sr handle, is it possible to write a generic sr_suspend?
Maybe your suggestion of callback is the way to go.
What about this idea, if we find this is a ZPODD capable drive, we enable runtime suspend for it and write a suspend callback according to ZPODD spec. For other drives that does not have a suspend callback, we do not enable runtime suspend.
Does this sound reasonable?
Thanks,
Aaron
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 30 lines · Aaron Lu
Quoted 12 lines · Oliver Neukum
Quoted 11 lines · On Tuesday 25 September 2012 22:20:21 Aaron Lu wrote:
Quoted 9 lines · Rafael J. Wysocki
Quoted 5 lines · Aaron Lu
I'm thinking of enabling this GPE in
sr_suspendonce we decided that it is ready to be powered off, so the time frame betweensr_suspendand when the power is actually removed in libata should be taken care of by the GPE. If GPE fires, the notification function will request a runtime resume of the device. Does this sound OK?Well, depending on the implementation.
sr_suspend()should be rather generic, but the ACPI association (including the GPE thing) is specific to ATA.Quoted 8 lines
Quoted 4 lines
Sorry, but don't quite understand this.
We have ACPI bindings for scsi devices, isn't that for us to use ACPI when needed in scsi?
We don't have ACPI bindings for generic SCSI devices. We have such bindings for SATA drives. You can put such things only in sr if it applies to all (maybe most) types of drives.
OK. Then these scsi bindings for sata drives will be pretty much of no use I think.
Quoted 5 lines
Quoted 4 lines
BTW, if
sr_suspendshould be generic, that would suggest I shouldn't write any ZPODD related code there, right? Any suggestion where these code should go then?
Quoted 5 lines
Quoted 1 line
libata. Maybe some generic hooks can be called in
sr_suspend().Thanks for the suggestion.
The problem is, I need to know whether the door is closed and if there is a medium inside. I've no way of getting such information in libata.
How does sr get to know it in the libata case?
Quoted 10 lines
Quoted 1 line
PS: Are you sure
sr_suspend()handles DVD-RAMs correctly?No. Is there a spec for it?
Considering there are many different drives sr handle, is it possible to write a genericsr_suspend?
Maybe your suggestion of callback is the way to go.
What about this idea, if we find this is a ZPODD capable drive, we enable runtime suspend for it and write a suspend callback according to ZPODD spec. For other drives that does not have a suspend callback, we do not enable runtime suspend.
You can enable runtime PM for all kinds of drives, but make the suspend and resume callbacks only do something for ZPODD ones. This may allow their parents to use runtime PM (as Alan said earlier in this thread), even if the drives themseleves are not really physically suspended.
Quoted 1 line
Does this sound reasonable?
First, we need to know when the drive is not in use. That information we can get from the sr's runtime PM and it looks like we need to notify libata about that somehow. I'm not sure what mechanism is the best for that at the moment.
Second, when the device is resumed by remote wakeup, we need to notify sr about that. A "resume" alone is not sufficient, though, because it may be necessary to open the tray. Perhaps in that case we can use the same mechanism by which user events are processed by libata and delivered to sr?
Rafael
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 31 lines · Rafael J. Wysocki
Quoted 30 lines · Aaron Lu
Quoted 12 lines · Oliver Neukum
Quoted 11 lines · On Tuesday 25 September 2012 22:20:21 Aaron Lu wrote:
Quoted 9 lines · Rafael J. Wysocki
Quoted 5 lines · Aaron Lu
I'm thinking of enabling this GPE in
sr_suspendonce we decided that it is ready to be powered off, so the time frame betweensr_suspendand when the power is actually removed in libata should be taken care of by the GPE. If GPE fires, the notification function will request a runtime resume of the device. Does this sound OK?Well, depending on the implementation.
sr_suspend()should be rather generic, but the ACPI association (including the GPE thing) is specific to ATA.Quoted 8 lines
Quoted 4 lines
Sorry, but don't quite understand this.
We have ACPI bindings for scsi devices, isn't that for us to use ACPI when needed in scsi?
We don't have ACPI bindings for generic SCSI devices. We have such bindings for SATA drives. You can put such things only in sr if it applies to all (maybe most) types of drives.
OK. Then these scsi bindings for sata drives will be pretty much of no use I think.
Quoted 5 lines
Quoted 4 lines
BTW, if
sr_suspendshould be generic, that would suggest I shouldn't write any ZPODD related code there, right? Any suggestion where these code should go then?
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
libata. Maybe some generic hooks can be called in
sr_suspend().Thanks for the suggestion.
The problem is, I need to know whether the door is closed and if there is a medium inside. I've no way of getting such information in libata.How does sr get to know it in the libata case?
By executing a test_unit_ready command.
Libata does/should not have any routine to do this, it is one of the transport of SCSI devices and it relies on SCSI driver to manage the device(both disk and ODD).
Quoted 12 lines
Quoted 11 lines
Quoted 2 lines
PS: Are you sure
sr_suspend()handles DVD-RAMs correctly?No. Is there a spec for it?
Considering there are many different drives sr handle, is it possible to write a genericsr_suspend?
Maybe your suggestion of callback is the way to go.
What about this idea, if we find this is a ZPODD capable drive, we enable runtime suspend for it and write a suspend callback according to ZPODD spec. For other drives that does not have a suspend callback, we do not enable runtime suspend.
Quoted 4 lines
You can enable runtime PM for all kinds of drives, but make the suspend and resume callbacks only do something for ZPODD ones. This may allow their parents to use runtime PM (as Alan said earlier in this thread), even if the drives themseleves are not really physically suspended.
Sounds good.
Quoted 7 lines
Quoted 2 lines
Does this sound reasonable?
First, we need to know when the drive is not in use. That information we can get from the sr's runtime PM and it looks like we need to notify libata about that somehow. I'm not sure what mechanism is the best for that at the moment.
The current mechanism to notify libata is by rumtime suspend. When scsi device is runtime suspended, its parent device will be suspended. And ata_port is one of the ancestor devices of scsi device, and we will remove its power in ata_port's runtime suspend callback.
Quoted 5 lines
Second, when the device is resumed by remote wakeup, we need to notify sr about that. A "resume" alone is not sufficient, though, because it may be necessary to open the tray. Perhaps in that case we can use the same mechanism by which user events are processed by libata and delivered to sr?
Thanks for the suggestion.
I'm not aware of any user events processed by libata. Do you mean the events_checking poll? I'm not sure about this events passing thing, as in that case, I will need to add code to listen to a socket in sr.
Thanks,
Aaron
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 73 lines · Aaron Lu
Quoted 31 lines · Rafael J. Wysocki
Quoted 30 lines · Aaron Lu
Quoted 12 lines · Oliver Neukum
Quoted 11 lines · On Tuesday 25 September 2012 22:20:21 Aaron Lu wrote:
Quoted 9 lines · Rafael J. Wysocki
Quoted 5 lines · Aaron Lu
I'm thinking of enabling this GPE in
sr_suspendonce we decided that it is ready to be powered off, so the time frame betweensr_suspendand when the power is actually removed in libata should be taken care of by the GPE. If GPE fires, the notification function will request a runtime resume of the device. Does this sound OK?Well, depending on the implementation.
sr_suspend()should be rather generic, but the ACPI association (including the GPE thing) is specific to ATA.Quoted 8 lines
Quoted 4 lines
Sorry, but don't quite understand this.
We have ACPI bindings for scsi devices, isn't that for us to use ACPI when needed in scsi?
We don't have ACPI bindings for generic SCSI devices. We have such bindings for SATA drives. You can put such things only in sr if it applies to all (maybe most) types of drives.
OK. Then these scsi bindings for sata drives will be pretty much of no use I think.
Quoted 5 lines
Quoted 4 lines
BTW, if
sr_suspendshould be generic, that would suggest I shouldn't write any ZPODD related code there, right? Any suggestion where these code should go then?Quoted 7 lines
Quoted 5 lines
Quoted 1 line
libata. Maybe some generic hooks can be called in
sr_suspend().Thanks for the suggestion.
The problem is, I need to know whether the door is closed and if there is a medium inside. I've no way of getting such information in libata.How does sr get to know it in the libata case?
By executing a
test_unit_readycommand.Libata does/should not have any routine to do this, it is one of the transport of SCSI devices and it relies on SCSI driver to manage the device(both disk and ODD).
Quoted 12 lines
Quoted 11 lines
Quoted 2 lines
PS: Are you sure
sr_suspend()handles DVD-RAMs correctly?No. Is there a spec for it?
Considering there are many different drives sr handle, is it possible to write a genericsr_suspend?
Maybe your suggestion of callback is the way to go.
What about this idea, if we find this is a ZPODD capable drive, we enable runtime suspend for it and write a suspend callback according to ZPODD spec. For other drives that does not have a suspend callback, we do not enable runtime suspend.Quoted 4 lines
You can enable runtime PM for all kinds of drives, but make the suspend and resume callbacks only do something for ZPODD ones. This may allow their parents to use runtime PM (as Alan said earlier in this thread), even if the drives themseleves are not really physically suspended.
Sounds good.
Quoted 7 lines
Quoted 2 lines
Does this sound reasonable?
First, we need to know when the drive is not in use. That information we can get from the sr's runtime PM and it looks like we need to notify libata about that somehow. I'm not sure what mechanism is the best for that at the moment.
Quoted 4 lines
The current mechanism to notify libata is by rumtime suspend. When scsi device is runtime suspended, its parent device will be suspended. And
ata_portis one of the ancestor devices of scsi device, and we will remove its power in ata_port's runtime suspend callback.
The problem, then, is that the ata_port's runtime suspend callback would have to know whether or not power can be removed from the drive.
I'm going to post patches introducing a "no power off" flag for PM QoS, among other things, today or tomorrow. I suppose this flag might be used to tell the ata_port's suspend not to remove power from the attached device.
Quoted 8 lines
Quoted 4 lines
Second, when the device is resumed by remote wakeup, we need to notify sr about that. A "resume" alone is not sufficient, though, because it may be necessary to open the tray. Perhaps in that case we can use the same mechanism by which user events are processed by libata and delivered to sr?
Thanks for the suggestion.
I'm not aware of any user events processed by libata. Do you mean theevents_checkingpoll?
Yes, basically. In the remote wakeup case libata might report the same status as in the "user pressed the eject button" situation happening normally with power on.
Thanks,
Rafael
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 79 lines · Rafael J. Wysocki
Quoted 73 lines · Aaron Lu
Quoted 31 lines · Rafael J. Wysocki
Quoted 30 lines · Aaron Lu
Quoted 12 lines · Oliver Neukum
Quoted 11 lines · On Tuesday 25 September 2012 22:20:21 Aaron Lu wrote:
Quoted 9 lines · Rafael J. Wysocki
Quoted 5 lines · Aaron Lu
I'm thinking of enabling this GPE in
sr_suspendonce we decided that it is ready to be powered off, so the time frame betweensr_suspendand when the power is actually removed in libata should be taken care of by the GPE. If GPE fires, the notification function will request a runtime resume of the device. Does this sound OK?Well, depending on the implementation.
sr_suspend()should be rather generic, but the ACPI association (including the GPE thing) is specific to ATA.Quoted 8 lines
Quoted 4 lines
Sorry, but don't quite understand this.
We have ACPI bindings for scsi devices, isn't that for us to use ACPI when needed in scsi?
We don't have ACPI bindings for generic SCSI devices. We have such bindings for SATA drives. You can put such things only in sr if it applies to all (maybe most) types of drives.
OK. Then these scsi bindings for sata drives will be pretty much of no use I think.
Quoted 5 lines
Quoted 4 lines
BTW, if
sr_suspendshould be generic, that would suggest I shouldn't write any ZPODD related code there, right? Any suggestion where these code should go then?Quoted 7 lines
Quoted 5 lines
Quoted 1 line
libata. Maybe some generic hooks can be called in
sr_suspend().Thanks for the suggestion.
The problem is, I need to know whether the door is closed and if there is a medium inside. I've no way of getting such information in libata.How does sr get to know it in the libata case?
By executing a
test_unit_readycommand.Libata does/should not have any routine to do this, it is one of the transport of SCSI devices and it relies on SCSI driver to manage the device(both disk and ODD).
Quoted 12 lines
Quoted 11 lines
Quoted 2 lines
PS: Are you sure
sr_suspend()handles DVD-RAMs correctly?No. Is there a spec for it?
Considering there are many different drives sr handle, is it possible to write a genericsr_suspend?
Maybe your suggestion of callback is the way to go.
What about this idea, if we find this is a ZPODD capable drive, we enable runtime suspend for it and write a suspend callback according to ZPODD spec. For other drives that does not have a suspend callback, we do not enable runtime suspend.Quoted 4 lines
You can enable runtime PM for all kinds of drives, but make the suspend and resume callbacks only do something for ZPODD ones. This may allow their parents to use runtime PM (as Alan said earlier in this thread), even if the drives themseleves are not really physically suspended.
Sounds good.
Quoted 7 lines
Quoted 2 lines
Does this sound reasonable?
First, we need to know when the drive is not in use. That information we can get from the sr's runtime PM and it looks like we need to notify libata about that somehow. I'm not sure what mechanism is the best for that at the moment.
Quoted 4 lines
The current mechanism to notify libata is by rumtime suspend. When scsi device is runtime suspended, its parent device will be suspended. And
ata_portis one of the ancestor devices of scsi device, and we will remove its power in ata_port's runtime suspend callback.
Quoted 6 lines
The problem, then, is that the ata_port's runtime suspend callback would have to know whether or not power can be removed from the drive.
I'm going to post patches introducing a "no power off" flag for PM QoS, among other things, today or tomorrow. I suppose this flag might be used to tell the ata_port's suspend not to remove power from the attached device.
Cool, thanks.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Second, when the device is resumed by remote wakeup, we need to notify sr about that. A "resume" alone is not sufficient, though, because it may be necessary to open the tray. Perhaps in that case we can use the same mechanism by which user events are processed by libata and delivered to sr?
Quoted 7 lines
Quoted 3 lines
Thanks for the suggestion.
I'm not aware of any user events processed by libata. Do you mean theevents_checkingpoll?Yes, basically. In the remote wakeup case libata might report the same status as in the "user pressed the eject button" situation happening normally with power on.
Maybe I didn't explain it clearly. The "user pressed the eject button" is reported
by ACPI through GPE, while the events_checking poll sends a command to the device to let it report events like media_change, etc.
And the events is reported to user space, that doesn't seem can help us in this case.
Thanks,
Aaron
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
In reply to Aaron LuQuoted 11 lines · On Tuesday 25 September 2012 22:46:06 Aaron Lu wrote:
Quoted 5 lines · Oliver Neukum
Quoted 3 lines
BTW, if
sr_suspendshould be generic, that would suggest I shouldn't write any ZPODD related code there, right? Any suggestion where these code should go then?libata. Maybe some generic hooks can be called in
sr_suspend().Thanks for the suggestion.
The problem is, I need to know whether the door is closed and if there is a medium inside. I've no way of getting such information in libata.
Hooks can be called with the necessary parameters. I suggest a triplett of medium presence, tray state and door lock state. That should cover most types of drives.
Quoted 3 lines
Quoted 1 line
PS: Are you sure
sr_suspend()handles DVD-RAMs correctly?No. Is there a spec for it?
Mount Fuji I presume.
Quoted 2 lines
Considering there are many different drives sr handle, is it possible to write a generic
sr_suspend?
There are two different issues. sr handles some different devices:
CD/DVD/BD-ROMs, -writers and -RAMs. For those you can have different code paths in sr. That is no problem at all.
In addition devices can be attached by different hardware. In fact the same drive can be attached in a USB enclosure or by SATA.
Quoted 1 line
From the perspective of power management they are no longer
the same device.
Those are best handled in callbacks and limited use of special cases in sr.
Quoted 6 lines
Maybe your suggestion of callback is the way to go.
What about this idea, if we find this is a ZPODD capable drive, we enable runtime suspend for it and write a suspend callback according to ZPODD spec. For other drives that does not have a suspend callback, we do not enable runtime suspend.
Does this sound reasonable?
No. It would badly harm usb-storage.
You need to leave paths open for other device types.
Regards
Oliver
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
In reply to Aaron LuQuoted 7 lines · On Tuesday 25 September 2012 16:01:35 Aaron Lu wrote:
Quoted 2 lines · Rafael J. Wysocki
Quoted 1 line · Aaron Lu
On Mon, Sep 24, 2012 at 02:55:31PM +0200, Rafael J. Wysocki wrote:
I just checked the spec again and tested, when the ODD has power, it will also send out notifications on pressing the eject button/inserting a disc. So we should be able to capture such a event.
In this case there's no need to poll for disk change unless the button has been pressed.
Quoted 5 lines
I'm thinking of enabling this GPE in
sr_suspendonce we decided that it is ready to be powered off, so the time frame betweensr_suspendand when the power is actually removed in libata should be taken care of by the GPE. If GPE fires, the notification function will request a runtime resume of the device. Does this sound OK?
This sounds terribly, needlessly complicated. Just enable it when you detect the presence of a disk drive that supports it.
Furthermore we have a device which can detect that a button has been pressed. It is fundamentally wrong to poll for medium change in such devices. You know that it hasn't been changed.
We should notify the upper layers that we can do medium change detection on our own.
Regards
Oliver
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 11 lines · Oliver Neukum
Quoted 7 lines · On Tuesday 25 September 2012 16:01:35 Aaron Lu wrote:
Quoted 2 lines · Rafael J. Wysocki
Quoted 1 line · Aaron Lu
On Mon, Sep 24, 2012 at 02:55:31PM +0200, Rafael J. Wysocki wrote:
I just checked the spec again and tested, when the ODD has power, it will also send out notifications on pressing the eject button/inserting a disc. So we should be able to capture such a event.
In this case there's no need to poll for disk change unless the button has been pressed.
The SATA spec says the device attention pin shall assert when:
- For tray type ODD, its front panel button is released;
- For slot type ODD, media is inserted.
I've a slot type ODD which has a eject button. The notification will be sent when a disc is inserted, but not when the eject button is pressed, and this doesn't violate the spec.
But if we disable the poll for disc changes, we will lose an event when the disc is ejected by the eject button(the device attention pin shall not trigger this time). I suppose this is a problem?
I think the device attention scheme is not designed to do this job, while SATA asynchronous notification is.
Quoted 7 lines
Quoted 6 lines
I'm thinking of enabling this GPE in
sr_suspendonce we decided that it is ready to be powered off, so the time frame betweensr_suspendand when the power is actually removed in libata should be taken care of by the GPE. If GPE fires, the notification function will request a runtime resume of the device. Does this sound OK?
Quoted 6 lines
This sounds terribly, needlessly complicated. Just enable it when you detect the presence of a disk drive that supports it.
Furthermore we have a device which can detect that a button has been pressed. It is fundamentally wrong to poll for medium change in such devices. You know that it hasn't been changed.
That may depend on the ODD's capability. For the slot type ODD I mentioned above, we will not know when the disc is gone.
Thanks,
Aaron
Quoted 6 lines
We should notify the upper layers that we can do medium change detection on our own.
Regards
Oliver
PATCH v7 3/6 scsi: sr: support zero power ODD(ZPODD)
In reply to Aaron LuWhen ODD is runtime suspended, we will check if it is OK to remove its power:
1 For tray type, no medium inside and tray closed;
2 For slot type, no medium inside.
And if yes, we will set the ready_to_power_off flag as an indication to ATA layer that it is safe to place this device into ACPI D3 cold power state.
And when it is powered off, we will set the powered_off flag so that the periodically running check_events will not bother this device by simply return.
--- drivers/ata/libata-acpi.c | 27 +++++++++++++++-------- drivers/scsi/sr.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/scsi/sr.h | 1 + drivers/scsi/sr_ioctl.c | 7 +++++- include/scsi/scsi_device.h | 3 +++ 5 files changed, 81 insertions(+), 10 deletions(-)
drivers/ata/libata-acpi.c +18 -9
@@ -854,7 +854,7 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) {struct ata_device *dev;acpi_handle handle; -int acpi_state; +int acpi_state, ret;/* channel first and then drives for power on and vica versa for power off */
@@ -869,17 +869,24 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)if (state.event !=PM_EVENT_ON ) { acpi_state =acpi_pm_device_sleep_state ( - &dev->sdev->sdev_gendev,NULL ,ACPI_STATE_D3 ); -if (acpi_state >0 ) -acpi_bus_set_power (handle, acpi_state); -/* TBD: need to check if it's runtime pm request */ -acpi_pm_device_run_wake ( - &dev->sdev->sdev_gendev, true); + &dev->sdev->sdev_gendev,NULL , + dev->sdev->ready_to_power_off ? +ACPI_STATE_D3 :ACPI_STATE_D3_HOT ); +if (acpi_state >0 ) { + ret =acpi_bus_set_power (handle, acpi_state); +if (!ret && acpi_state ==ACPI_STATE_D3 ) + dev->sdev->powered_off =1 ; + +/* TODO: check if it's runtime pm request */ +acpi_pm_device_run_wake ( + &dev->sdev->sdev_gendev, true); + } }else {/* Ditto */ acpi_pm_device_run_wake ( &dev->sdev->sdev_gendev, false);acpi_bus_set_power (handle,ACPI_STATE_D0 ); + dev->sdev->powered_off =0 ; } }
@@ -985,8 +992,10 @@ static void ata_acpi_wake_dev(acpi_handle handle, u32 event, void *context)struct ata_device *ata_dev = context;if (event ==ACPI_NOTIFY_DEVICE_WAKE && ata_dev && -pm_runtime_suspended (&ata_dev->sdev->sdev_gendev)) -scsi_autopm_get_device (ata_dev->sdev); + ata_dev->sdev->powered_off) { + ata_dev->sdev->need_eject =1 ; +pm_runtime_resume (&ata_dev->sdev->sdev_gendev); + } }static void ata_acpi_add_pm_notifier (struct ata_device *dev)
drivers/scsi/sr.c +53 -0
77 lines not on this page · raw message
drivers/scsi/sr.h +1 -0
@@ -41,6 +41,7 @@ typedef struct scsi_cd { unsigned readcd_known:1; /* drive supports READ_CD (0xbe) */ unsigned readcd_cdda:1; /* reading audio data using READ_CD */ unsigned media_present:1; /* media is present */ + unsigned door_locked:1; /* door is locked *//* GET_EVENT spurious event handling, blk layer guarantees exclusion */ int tur_mismatch;/* nr of get_event TUR mismatches */
drivers/scsi/sr_ioctl.c +6 -1
@@ -292,10 +292,15 @@ int sr_tray_move(struct cdrom_device_info *cdi, int pos)int sr_lock_door (struct cdrom_device_info *cdi,int lock) { +int ret;Scsi_CD *cd = cdi->handle; -return scsi_set_medium_removal (cd->device, lock ? + ret =scsi_set_medium_removal (cd->device, lock ?SCSI_REMOVAL_PREVENT :SCSI_REMOVAL_ALLOW ); +if (!ret) + cd->door_locked = lock; + +return ret; }int sr_drive_status (struct cdrom_device_info *cdi,int slot)
include/scsi/scsi_device.h +3 -0
@@ -156,6 +156,9 @@ struct scsi_device { unsigned is_visible:1; /* is the device visible in sysfs */ unsigned can_power_off:1; /* Device supports runtime power off */ unsigned wce_default_on:1; /* Cache is ON by default */ + unsigned need_eject:1; /* Need eject the tray when wakes up */ + unsigned ready_to_power_off:1; /* Device is ready to be powered off */ + unsigned powered_off:1; /* Device is powered off */DECLARE_BITMAP (supported_events,SDEV_EVT_MAXBITS );/* supported events */ struct list_head event_list;/* asserted events */
Signature · 1 line
1.7.12.21.g871e293
Re: [PATCH v7 3/6] scsi: sr: support zero power ODD(ZPODD)
Quoted 11 lines · Aaron Lu
When ODD is runtime suspended, we will check if it is OK to remove its power:
1 For tray type, no medium inside and tray closed;
2 For slot type, no medium inside.
And if yes, we will set theready_to_power_offflag as an indication to ATA layer that it is safe to place this device into ACPI D3 cold power state.And when it is powered off, we will set the
powered_offflag so that the periodically runningcheck_eventswill not bother this device by simply return.
Well, so I agree with James that the PM flags in struct scsi_device are kind of odd and it would be better to put them somewhere else.
I'd probably prefer them to sit in the ACPI layer with some helper functions allowing the sr driver to manipulate them, but that depends on the resulting code complexity.
Quoted 89 lines
Signed-off-by Aaron Lu <[email protected]>--- drivers/ata/libata-acpi.c | 27 +++++++++++++++-------- drivers/scsi/sr.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/scsi/sr.h | 1 + drivers/scsi/sr_ioctl.c | 7 +++++- include/scsi/scsi_device.h | 3 +++ 5 files changed, 81 insertions(+), 10 deletions(-)drivers/ata/libata-acpi.c +18
-9@@ -854,7 +854,7 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) {struct ata_device *dev;acpi_handle handle; -int acpi_state; +int acpi_state, ret;/* channel first and then drives for power on and vica versa for power off */ @@ -869,17 +869,24 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)if (state.event !=PM_EVENT_ON ) { acpi_state =acpi_pm_device_sleep_state ( - &dev->sdev->sdev_gendev,NULL ,ACPI_STATE_D3 ); -if (acpi_state >0 ) -acpi_bus_set_power (handle, acpi_state); -/* TBD: need to check if it's runtime pm request */ -acpi_pm_device_run_wake ( - &dev->sdev->sdev_gendev, true); + &dev->sdev->sdev_gendev,NULL , + dev->sdev->ready_to_power_off ? +ACPI_STATE_D3 :ACPI_STATE_D3_HOT ); +if (acpi_state >0 ) { + ret =acpi_bus_set_power (handle, acpi_state); +if (!ret && acpi_state ==ACPI_STATE_D3 ) + dev->sdev->powered_off =1 ; + +/* TODO: check if it's runtime pm request */ +acpi_pm_device_run_wake ( + &dev->sdev->sdev_gendev, true); + } }else {/* Ditto */ acpi_pm_device_run_wake ( &dev->sdev->sdev_gendev, false);acpi_bus_set_power (handle,ACPI_STATE_D0 ); + dev->sdev->powered_off =0 ; } }@@ -985,8 +992,10 @@ static void ata_acpi_wake_dev(acpi_handle handle, u32 event, void *context)struct ata_device *ata_dev = context;if (event ==ACPI_NOTIFY_DEVICE_WAKE && ata_dev && -pm_runtime_suspended (&ata_dev->sdev->sdev_gendev)) -scsi_autopm_get_device (ata_dev->sdev); + ata_dev->sdev->powered_off) { + ata_dev->sdev->need_eject =1 ; +pm_runtime_resume (&ata_dev->sdev->sdev_gendev); + } }static void ata_acpi_add_pm_notifier (struct ata_device *dev)drivers/scsi/sr.c +4
-0@@ -80,6 +80,8 @@ static DEFINE_MUTEX(sr_mutex);static int sr_probe (struct device *);static int sr_remove (struct device *);static int sr_done (struct scsi_cmnd *); +static int sr_suspend (struct device *,pm_message_t msg); +static int sr_resume (struct device *);static struct scsi_driver sr_template = { .owner =THIS_MODULE ,@@ -87,6 +89,8 @@ static struct scsi_driver sr_template = { .name = "sr", .probe = sr_probe, .remove = sr_remove, + .suspend = sr_suspend, + .resume = sr_resume, }, .done = sr_done, };
drivers/scsi/sr.c static void scsi_cd_put(struct scsi_cd *cd) · line 177
Quoted 2 lines
drivers/scsi/sr.c +0
-0@@ -172,6 +176,52 @@ static void scsi_cd_put(struct scsi_cd *cd)mutex_unlock (&sr_ref_mutex); }
Besides, I need some help to understand how this is supposed to work.
Do I think correctly that sr_suspend(), for example, will be run by the SCSI bus type layer in case of a CD device runtime suspend? However, won't this routine be used during system suspend as well and won't it cause problems to happen if so?
Quoted 97 lines
drivers/scsi/sr.c +49
-0+static int sr_suspend (struct device *dev,pm_message_t msg) +{ +struct scsi_sense_hdr sshdr; +struct scsi_cd *cd =dev_get_drvdata (dev); + +if (!cd->device->can_power_off) +return 0 ; + +/* See if we can power off this ZPODD device */ +scsi_test_unit_ready (cd->device,SR_TIMEOUT ,MAX_RETRIES , &sshdr); +if (cd->cdi.mask &CDC_CLOSE_TRAY ) +/* no media for caddy/slot type ODD */ + cd->device->ready_to_power_off =scsi_sense_valid (&sshdr) && + sshdr.asc ==0x3a ; +else +/* no media and door closed for tray type ODD */ + cd->device->ready_to_power_off =scsi_sense_valid (&sshdr) && + sshdr.asc ==0x3a && sshdr.ascq ==0x01 ; + +return 0 ; +} + +static int sr_resume (struct device *dev) +{ +struct scsi_cd *cd; +struct scsi_sense_hdr sshdr; + + cd =dev_get_drvdata (dev); + +if (!cd->device->powered_off) +return 0 ; + +/* get the disk ready */ +scsi_test_unit_ready (cd->device,SR_TIMEOUT ,MAX_RETRIES , &sshdr); + +/* If user wakes up the ODD, eject the tray */ +if (cd->device->need_eject) { + cd->device->need_eject =0 ; +/* But only for tray type ODD when door is not locked */ +if (!(cd->cdi.mask &CDC_CLOSE_TRAY ) && !cd->door_locked) +sr_tray_move (&cd->cdi,1 ); + } + +return 0 ; +} +static unsigned int sr_get_events (struct scsi_device *sdev) {u8 buf[8 ];@@ -226,6 +276,9 @@ static unsigned int sr_check_events(struct cdrom_device_info *cdi,if (CDSL_CURRENT != slot)return 0 ; +if (cd->device->powered_off) +return 0 ; +scsi_autopm_get_device (cd->device); events =sr_get_events (cd->device);drivers/scsi/sr.h +1
-0@@ -41,6 +41,7 @@ typedef struct scsi_cd { unsigned readcd_known:1; /* drive supports READ_CD (0xbe) */ unsigned readcd_cdda:1; /* reading audio data using READ_CD */ unsigned media_present:1; /* media is present */ + unsigned door_locked:1; /* door is locked *//* GET_EVENT spurious event handling, blk layer guarantees exclusion */ int tur_mismatch;/* nr of get_event TUR mismatches */ drivers/scsi/sr_ioctl.c +6
-1@@ -292,10 +292,15 @@ int sr_tray_move(struct cdrom_device_info *cdi, int pos)int sr_lock_door (struct cdrom_device_info *cdi,int lock) { +int ret;Scsi_CD *cd = cdi->handle; -return scsi_set_medium_removal (cd->device, lock ? + ret =scsi_set_medium_removal (cd->device, lock ?SCSI_REMOVAL_PREVENT :SCSI_REMOVAL_ALLOW ); +if (!ret) + cd->door_locked = lock; + +return ret; }int sr_drive_status (struct cdrom_device_info *cdi,int slot)include/scsi/scsi_device.h +0
-0
include/scsi/scsi_device.h struct scsi_device { · line 164
Quoted 9 lines
include/scsi/scsi_device.h +3
-0@@ -156,6 +156,9 @@ struct scsi_device { unsigned is_visible:1; /* is the device visible in sysfs */ unsigned can_power_off:1; /* Device supports runtime power off */ unsigned wce_default_on:1; /* Cache is ON by default */ + unsigned need_eject:1; /* Need eject the tray when wakes up */ + unsigned ready_to_power_off:1; /* Device is ready to be powered off */ + unsigned powered_off:1; /* Device is powered off */DECLARE_BITMAP (supported_events,SDEV_EVT_MAXBITS );/* supported events */ struct list_head event_list;/* asserted events */
Thanks,
Rafael
Re: [PATCH v7 3/6] scsi: sr: support zero power ODD(ZPODD)
Quoted 18 lines · Rafael J. Wysocki
Quoted 12 lines · Aaron Lu
static struct
scsi_driversr_template= {drivers/scsi/sr.c +2
-0.owner = THIS_MODULE,@@ -87,6 +89,8 @@ static struct scsi_driver sr_template = { .name = "sr", .probe = sr_probe, .remove = sr_remove, + .suspend = sr_suspend, + .resume = sr_resume, }, .done = sr_done, };drivers/scsi/sr.c static void scsi_cd_put(struct scsi_cd *cd) · line 177
Quoted 2 lines
drivers/scsi/sr.c +0
-0@@ -172,6 +176,52 @@ static void scsi_cd_put(struct scsi_cd *cd)mutex_unlock (&sr_ref_mutex); }Besides, I need some help to understand how this is supposed to work.
Quoted 2 lines
Do I think correctly that
sr_suspend(), for example, will be run by the SCSI bus type layer in case of a CD device runtime suspend? However,
Yes.
Quoted 2 lines
won't this routine be used during system suspend as well and won't it cause problems to happen if so?
On system suspend, nothing needs to be done.
I'll add the following code in next version.
if (!PMSG_IS_AUTO(msg)) return 0;
Thanks,
Aaron
Re: [PATCH v7 3/6] scsi: sr: support zero power ODD(ZPODD)
Quoted 24 lines · Aaron Lu
Quoted 18 lines · Rafael J. Wysocki
Quoted 12 lines · Aaron Lu
static struct
scsi_driversr_template= {drivers/scsi/sr.c +2
-0.owner = THIS_MODULE,@@ -87,6 +89,8 @@ static struct scsi_driver sr_template = { .name = "sr", .probe = sr_probe, .remove = sr_remove, + .suspend = sr_suspend, + .resume = sr_resume, }, .done = sr_done, };drivers/scsi/sr.c static void scsi_cd_put(struct scsi_cd *cd) · line 177
Quoted 2 lines
drivers/scsi/sr.c +0
-0@@ -172,6 +176,52 @@ static void scsi_cd_put(struct scsi_cd *cd)mutex_unlock (&sr_ref_mutex); }Besides, I need some help to understand how this is supposed to work.
Quoted 2 lines
Do I think correctly that
sr_suspend(), for example, will be run by the SCSI bus type layer in case of a CD device runtime suspend? However,Yes.
Quoted 8 lines
Quoted 2 lines
won't this routine be used during system suspend as well and won't it cause problems to happen if so?
On system suspend, nothing needs to be done.
I'll add the following code in next version.if (!PMSG_IS_AUTO(msg)) return 0;
Please don't. The pm_message_t thing is obsolete and shoulnd't really be used by device drivers. I know that ATA relies on it internally, but that's just something that needs to be changed at one point.
Moreover, I'd like to migrate SCSI drivers to the PM handling based on struct dev_pm_ops eventually and your change is kind of going in the opposite direction. I don't know how much effort the migration is going to take, though, so perhaps we can just make this change first.
On a slightly related note, suppose that we have an "enabled" bit in flags in struct acpi_device_power_state and suppose that we have a helper function pm_platform_power_off_allowed(dev, bool), such that if the driver (or subsystem) does pm_platform_power_off_allowed(dev, false) and the platform is ACPI, the "enabled" bit for the D3cold state will be cleared. Then, the ACPI device PM routines will never use D3cold as the device power state.
In that case, it seems, you won't need the "ready_to_power_off" flag in struct scsi_device any more.
Thanks,
Rafael
Re: [PATCH v7 3/6] scsi: sr: support zero power ODD(ZPODD)
Quoted 34 lines · Rafael J. Wysocki
Quoted 24 lines · Aaron Lu
Quoted 18 lines · Rafael J. Wysocki
Quoted 12 lines · Aaron Lu
static struct
scsi_driversr_template= {(quoted diff) +2
-0.owner = THIS_MODULE,@@ -87,6 +89,8 @@ static struct scsi_driver sr_template = { .name = "sr", .probe = sr_probe, .remove = sr_remove, + .suspend = sr_suspend, + .resume = sr_resume, }, .done = sr_done, };Review static void scsi_cd_put(struct scsi_cd *cd) · line 177
Quoted 2 lines
(quoted diff) +0
-0@@ -172,6 +176,52 @@ static void scsi_cd_put(struct scsi_cd *cd) mutex_unlock(&sr_ref_mutex); }Besides, I need some help to understand how this is supposed to work.
Quoted 2 lines
Do I think correctly that
sr_suspend(), for example, will be run by the SCSI bus type layer in case of a CD device runtime suspend? However,Yes.
Quoted 8 lines
Quoted 2 lines
won't this routine be used during system suspend as well and won't it cause problems to happen if so?
On system suspend, nothing needs to be done.
I'll add the following code in next version.if (!PMSG_IS_AUTO(msg)) return 0;
Quoted 8 lines
Please don't. The
pm_message_tthing is obsolete and shoulnd't really be used by device drivers. I know that ATA relies on it internally, but that's just something that needs to be changed at one point.Moreover, I'd like to migrate SCSI drivers to the PM handling based on struct
dev_pm_opseventually and your change is kind of going in the opposite direction. I don't know how much effort the migration is going to take, though, so perhaps we can just make this change first.
Does the following change look OK?
drivers/scsi/scsi_pm.c +17 -2
@@ -143,7 +143,15 @@ static int scsi_runtime_suspend(struct device *dev)dev_dbg (dev,"scsi_runtime_suspend\n" );if (scsi_is_sdev_device (dev)) { - err =scsi_dev_type_suspend (dev,PMSG_AUTO_SUSPEND ); + err =scsi_device_quiesce (to_scsi_device (dev)); +if (err) + goto out; + + err =pm_generic_runtime_suspend (dev); +if (!err) + goto out; + +scsi_device_resume (to_scsi_device (dev));if (err == -EAGAIN )pm_schedule_suspend (dev,jiffies_to_msecs (round_jiffies_up_relative (HZ /10 )));
@@ -151,6 +159,7 @@ static int scsi_runtime_suspend(struct device *dev)/* Insert hooks here for targets, hosts, and transport classes */ +out:return err; }
@@ -159,11 +168,17 @@ static int scsi_runtime_resume(struct device *dev)int err =0 ;dev_dbg (dev,"scsi_runtime_resume\n" ); -if (scsi_is_sdev_device (dev)) +if (scsi_is_sdev_device (dev)) { + err =pm_generic_runtime_resume (dev); +if (err) + goto out; + err =scsi_dev_type_resume (dev); + }/* Insert hooks here for targets, hosts, and transport classes */ +out:return err; }
And I'll define runtime callbacks for sr and sd.
Thanks,
Aaron
Re: [PATCH v7 3/6] scsi: sr: support zero power ODD(ZPODD)
Quoted 18 lines · Aaron Lu
Quoted 4 lines
Moreover, I'd like to migrate SCSI drivers to the PM handling based on struct
dev_pm_opseventually and your change is kind of going in the opposite direction. I don't know how much effort the migration is going to take, though, so perhaps we can just make this change first.Does the following change look OK?
drivers/scsi/scsi_pm.c +2
-1@@ -143,7 +143,15 @@ static int scsi_runtime_suspend(struct device *dev)dev_dbg (dev,"scsi_runtime_suspend\n" );if (scsi_is_sdev_device (dev)) { - err =scsi_dev_type_suspend (dev,PMSG_AUTO_SUSPEND ); + err =scsi_device_quiesce (to_scsi_device (dev)); +if (err)
drivers/scsi/scsi_pm.c static int scsi_runtime_suspend(struct device *dev) · line 157
Quoted 10 lines
drivers/scsi/scsi_pm.c +7
-0+ goto out; + + err =pm_generic_runtime_suspend (dev); +if (!err) + goto out; + +scsi_device_resume (to_scsi_device (dev));if (err == -EAGAIN )pm_schedule_suspend (dev,jiffies_to_msecs (round_jiffies_up_relative (HZ /10 )));
Maybe in the end it will be better, but for now this looks like unnecessary code duplication. Basically you are copying scsi_dev_type_suspend() into scsi_runtime_suspend(), except that you omitted the debugging statement.
Alan Stern
Re: [PATCH v7 3/6] scsi: sr: support zero power ODD(ZPODD)
Quoted 27 lines · Alan Stern
Quoted 25 lines · Aaron Lu
Quoted 4 lines
Moreover, I'd like to migrate SCSI drivers to the PM handling based on struct
dev_pm_opseventually and your change is kind of going in the opposite direction. I don't know how much effort the migration is going to take, though, so perhaps we can just make this change first.Does the following change look OK?
drivers/scsi/scsi_pm.c +9
-1@@ -143,7 +143,15 @@ static int scsi_runtime_suspend(struct device *dev)dev_dbg (dev,"scsi_runtime_suspend\n" );if (scsi_is_sdev_device (dev)) { - err =scsi_dev_type_suspend (dev,PMSG_AUTO_SUSPEND ); + err =scsi_device_quiesce (to_scsi_device (dev)); +if (err) + goto out; + + err =pm_generic_runtime_suspend (dev); +if (!err) + goto out; + +scsi_device_resume (to_scsi_device (dev));
Quoted 8 lines
drivers/scsi/scsi_pm.c static int scsi_runtime_suspend(struct device *dev) · line 157
Quoted 3 lines
drivers/scsi/scsi_pm.c +0
-0if (err == -EAGAIN )pm_schedule_suspend (dev,jiffies_to_msecs (round_jiffies_up_relative (HZ /10 )));Maybe in the end it will be better, but for now this looks like unnecessary code duplication. Basically you are copying
scsi_dev_type_suspend()intoscsi_runtime_suspend(), except that you omitted the debugging statement.
And I've used pm_generic_runtime_suspend :-)
That would allow me to write runtime callbacks of dev_pm_ops for indivisual scsi drivers, like sr.
Thanks,
Aaron
Re: [PATCH v7 3/6] scsi: sr: support zero power ODD(ZPODD)
Quoted 37 lines · Aaron Lu
Quoted 27 lines · Alan Stern
Quoted 25 lines · Aaron Lu
Quoted 4 lines
Moreover, I'd like to migrate SCSI drivers to the PM handling based on struct
dev_pm_opseventually and your change is kind of going in the opposite direction. I don't know how much effort the migration is going to take, though, so perhaps we can just make this change first.Does the following change look OK?
drivers/scsi/scsi_pm.c +9
-1@@ -143,7 +143,15 @@ static int scsi_runtime_suspend(struct device *dev)dev_dbg (dev,"scsi_runtime_suspend\n" );if (scsi_is_sdev_device (dev)) { - err =scsi_dev_type_suspend (dev,PMSG_AUTO_SUSPEND ); + err =scsi_device_quiesce (to_scsi_device (dev)); +if (err) + goto out; + + err =pm_generic_runtime_suspend (dev); +if (!err) + goto out; + +scsi_device_resume (to_scsi_device (dev));Quoted 8 lines
drivers/scsi/scsi_pm.c static int scsi_runtime_suspend(struct device *dev) · line 157
Quoted 3 lines
drivers/scsi/scsi_pm.c +0
-0if (err == -EAGAIN )pm_schedule_suspend (dev,jiffies_to_msecs (round_jiffies_up_relative (HZ /10 )));Maybe in the end it will be better, but for now this looks like unnecessary code duplication. Basically you are copying
scsi_dev_type_suspend()intoscsi_runtime_suspend(), except that you omitted the debugging statement.
Quoted 3 lines
And I've used
pm_generic_runtime_suspend:-)
That would allow me to write runtime callbacks ofdev_pm_opsfor indivisual scsi drivers, like sr.
Well, actually, I meant something different.
The above patch would make it possible for drivers to provide runtime PM callbacks through dev->driver.pm, but drv->suspend and drv->resume would still be used for system suspend/resume (and hibernation).
The transition to struct dev_pm_ops I meant, however, would be to start using callbacks from dev->driver.pm for _all_ device PM operations by default and fall back to drv->suspend and drv->resume for the drivers whose dev->driver.pm is NULL (along the lines of what PCI does). The next step would be to convert all drivers to use dev->driver.pm only.
So I wouldn't like any drivers to use dev->driver.pm callbacks for some operations and drv->suspend and drv->resume for the remaining ones at the same time.
Thanks,
Rafael
Re: [PATCH v7 3/6] scsi: sr: support zero power ODD(ZPODD)
In reply to Aaron LuQuoted 67 lines · Aaron Lu
When ODD is runtime suspended, we will check if it is OK to remove its power:
1 For tray type, no medium inside and tray closed;
2 For slot type, no medium inside.
And if yes, we will set theready_to_power_offflag as an indication to ATA layer that it is safe to place this device into ACPI D3 cold power state.And when it is powered off, we will set the
powered_offflag so that the periodically runningcheck_eventswill not bother this device by simply return.Signed-off-by Aaron Lu <[email protected]>--- drivers/ata/libata-acpi.c | 27 +++++++++++++++-------- drivers/scsi/sr.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/scsi/sr.h | 1 + drivers/scsi/sr_ioctl.c | 7 +++++- include/scsi/scsi_device.h | 3 +++ 5 files changed, 81 insertions(+), 10 deletions(-)drivers/ata/libata-acpi.c +14
-7@@ -854,7 +854,7 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) {struct ata_device *dev;acpi_handle handle; -int acpi_state; +int acpi_state, ret;/* channel first and then drives for power on and vica versa for power off */ @@ -869,17 +869,24 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)if (state.event !=PM_EVENT_ON ) { acpi_state =acpi_pm_device_sleep_state ( - &dev->sdev->sdev_gendev,NULL ,ACPI_STATE_D3 ); -if (acpi_state >0 ) -acpi_bus_set_power (handle, acpi_state); -/* TBD: need to check if it's runtime pm request */ -acpi_pm_device_run_wake ( - &dev->sdev->sdev_gendev, true); + &dev->sdev->sdev_gendev,NULL , + dev->sdev->ready_to_power_off ? +ACPI_STATE_D3 :ACPI_STATE_D3_HOT ); +if (acpi_state >0 ) { + ret =acpi_bus_set_power (handle, acpi_state); +if (!ret && acpi_state ==ACPI_STATE_D3 ) + dev->sdev->powered_off =1 ; + +/* TODO: check if it's runtime pm request */ +acpi_pm_device_run_wake ( + &dev->sdev->sdev_gendev, true); + } }else {/* Ditto */ acpi_pm_device_run_wake ( &dev->sdev->sdev_gendev, false);acpi_bus_set_power (handle,ACPI_STATE_D0 ); + dev->sdev->powered_off =0 ; } }@@ -985,8 +992,10 @@ static void ata_acpi_wake_dev(acpi_handle handle, u32 event, void *context)struct ata_device *ata_dev = context;
drivers/ata/libata-acpi.c static void ata_acpi_wake_dev(acpi_handle handle, u32 event, void *context) · line 1000
Quoted 10 lines
drivers/ata/libata-acpi.c +4
-2if (event ==ACPI_NOTIFY_DEVICE_WAKE && ata_dev && -pm_runtime_suspended (&ata_dev->sdev->sdev_gendev)) -scsi_autopm_get_device (ata_dev->sdev); + ata_dev->sdev->powered_off) { + ata_dev->sdev->need_eject =1 ; +pm_runtime_resume (&ata_dev->sdev->sdev_gendev); + } }
these bits are Acked-by: Jeff Garzik <[email protected]>
but obviously that is contingent upon acceptance of the upper level SCSI and ACPI changes.
PATCH v7 4/6 scsi: pm: add may_power_off flag
In reply to Aaron LuAdd a new flag may_power_off for scsi device, it gives the user a chance to control when the device is runtime suspended, can we remove its power if possible.
And if the device can be powered off(reflected by can_power_off flag, determined by individual driver), create a sysfs entry named may_power_off to let user control the flag.
When user changes this flag through sysfs entry and if the device is already runtime suspended, runtime resume it so that it can respect this flag next time it is runtime suspended.
I'm planning using this flag for sr and sd.
--- drivers/scsi/scsi_sysfs.c | 37 ++++++++++++++++++++++++++++++++++++- include/scsi/scsi_device.h | 1 + 2 files changed, 37 insertions(+), 1 deletion(-)
drivers/scsi/scsi_sysfs.c +36 -1
@@ -509,6 +509,7 @@ sdev_store_##field (struct device *dev, struct device_attribute *attr, \return ret; \ } \ static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, sdev_store_##field); +#endif /* * scsi_sdev_check_buf_bit: return 0 if buf is "0", return 1 if buf is "1",
@@ -526,7 +527,7 @@ static int scsi_sdev_check_buf_bit(const char *buf) }else return -EINVAL ; } -#endif +/* * Create the actual show/store functions and data structures. */
@@ -860,6 +861,37 @@ static struct device_attribute sdev_attr_queue_type_rw =__ATTR (queue_type,S_IRUGO |S_IWUSR , show_queue_type_field, sdev_store_queue_type_rw); +static ssize_t +sdev_show_may_power_off (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct scsi_device *sdev; + sdev =to_scsi_device (dev); +return snprintf (buf,20 ,"%d\n" , sdev->may_power_off); +} + +static ssize_t +sdev_store_may_power_off (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +int ret; +struct scsi_device *sdev; + + ret =scsi_sdev_check_buf_bit (buf); +if (ret >=0 ) { + sdev =to_scsi_device (dev); +if (sdev->may_power_off != ret) { + sdev->may_power_off = ret; +if (pm_runtime_suspended (dev)) +pm_runtime_resume (dev); + } + ret = count; + } +return ret; +} +static DEVICE_ATTR(may_power_off, S_IRUGO | S_IWUSR, + sdev_show_may_power_off, sdev_store_may_power_off); +/** * scsi_sysfs_add_sdev - add scsi device to sysfs * @sdev: scsi_device to add
@@ -950,6 +982,9 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev) } } +if (sdev->can_power_off) +device_create_file (&sdev->sdev_gendev, &dev_attr_may_power_off); +return error; }
include/scsi/scsi_device.h +1 -0
@@ -159,6 +159,7 @@ struct scsi_device { unsigned need_eject:1; /* Need eject the tray when wakes up */ unsigned ready_to_power_off:1; /* Device is ready to be powered off */ unsigned powered_off:1; /* Device is powered off */ + unsigned may_power_off:1; /* Power off is allowed by user */DECLARE_BITMAP (supported_events,SDEV_EVT_MAXBITS );/* supported events */ struct list_head event_list;/* asserted events */
Signature · 1 line
1.7.12.21.g871e293
PATCH v7 5/6 scsi: sr: use may_power_off
In reply to Aaron LuIf may_power_off is 0, we do not check if it is ready to be powered off in its suspend callback.
--- drivers/scsi/sr.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/sr.c +5 -1
@@ -181,7 +181,7 @@ static int sr_suspend(struct device *dev, pm_message_t msg)struct scsi_sense_hdr sshdr;struct scsi_cd *cd =dev_get_drvdata (dev); -if (!cd->device->can_power_off) +if (!cd->device->may_power_off)return 0 ;/* See if we can power off this ZPODD device */
@@ -786,6 +786,10 @@ static int sr_probe(struct device *dev)sdev_printk (KERN_DEBUG , sdev,"Attached scsi CD-ROM %s\n" , cd->cdi.name); +/* By default, we allow power off of ZPODD */ +if (cd->device->can_power_off) + cd->device->may_power_off =1 ; +/* enable runtime pm */ scsi_autopm_put_device (cd->device);
Signature · 1 line
1.7.12.21.g871e293
PATCH v7 6/6 libata: acpi: respect may_power_off flag
In reply to Aaron LuIf user does not want the device to be powered off when runtime suspended by setting may_power_off flag to 0, we will not choose D3 cold for it.
--- drivers/ata/libata-acpi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/ata/libata-acpi.c +4 -1
@@ -855,6 +855,7 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)struct ata_device *dev;acpi_handle handle;int acpi_state, ret; +bool power_off_allowed;/* channel first and then drives for power on and vica versa for power off */
@@ -868,9 +869,11 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)continue ;if (state.event !=PM_EVENT_ON ) { + power_off_allowed = dev->sdev->ready_to_power_off && + dev->sdev->may_power_off; acpi_state =acpi_pm_device_sleep_state ( &dev->sdev->sdev_gendev,NULL , - dev->sdev->ready_to_power_off ? + power_off_allowed ?ACPI_STATE_D3 :ACPI_STATE_D3_HOT );if (acpi_state >0 ) { ret =acpi_bus_set_power (handle, acpi_state);
Signature · 1 line
1.7.12.21.g871e293
Re: [PATCH v7 6/6] libata: acpi: respect may_power_off flag
Quoted 22 lines · Aaron Lu
If user does not want the device to be powered off when runtime suspended by setting
may_power_offflag to 0, we will not choose D3 cold for it.Signed-off-by Aaron Lu <[email protected]>--- drivers/ata/libata-acpi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/ata/libata-acpi.c +1
-0@@ -855,6 +855,7 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)struct ata_device *dev;acpi_handle handle;int acpi_state, ret; +bool power_off_allowed;/* channel first and then drives for power on and vica versa for power off */
drivers/ata/libata-acpi.c void ata_acpi_set_state(struct ata_port *ap, pm_message_t state) · line 877
Quoted 10 lines
drivers/ata/libata-acpi.c +3
-1@@ -868,9 +869,11 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)continue ;if (state.event !=PM_EVENT_ON ) { + power_off_allowed = dev->sdev->ready_to_power_off && + dev->sdev->may_power_off; acpi_state =acpi_pm_device_sleep_state ( &dev->sdev->sdev_gendev,NULL , - dev->sdev->ready_to_power_off ? + power_off_allowed ?ACPI_STATE_D3 :ACPI_STATE_D3_HOT );
with the same caveat as with the rest of this patchset: contingent upon acceptance of the other API changes.
Hi James,
May I know if this patchset will enter v3.7?
Thanks,
Aaron
Quoted 70 lines · Aaron Lu
v7:
Re work of runtime pm of sr driver, based on ideas of Alan Stern and Oliver Neukum.Jeff, due to the
ready_to_power_offflag added, there is a small change in [PATCH v7 6/6] libata: acpi: respectmay_power_offflag, please check if I can still get your ack, thanks.v6:
When user changesmay_power_offflag through sysfs entry and if device is already runtime suspended, resume resume it so that it can respect this flag next time it is runtime suspended as suggested by Alan Stern. Call scsi_autopm_get/put_device once insr_check_eventsas suggested by Alan Stern.v5:
Addmay_power_offflag to scsi device.
Alan Stern suggested that I should not mess runtime suspend with runtime power off, but the current zpodd implementation made it not easy to seperate. So I re-wrote the zpodd implementation, the end result is, normal ODD can also enter runtime suspended state, but their power won't be removed.v4:
Rebase on top of Linus' tree, due to this, the problem of a missing flag in v3 is gone;
Add a new functionscsi_autopm_put_device_autosuspendto first mark last busy for the device and then put autosuspend it as suggested by Oliver Neukum.
Typo fix as pointed by Sergei Shtylyov.
Checkcan_power_offflag before any runtime pm operations in sr.v3:
Rebase on top of scsi-misc tree;
Add the sr related patches previously in Jeff's libata tree; Re-organize the sr patches.
A problem for now: for patch
scsi: sr: support zero power ODD(ZPODD)
I can't set a flag inlibata-acpi.csince a related function is missing in scsi-misc tree. Will fix this when 3.6-rc1 released.v2:
Bug fix for v1;
Use scsi_autopm_* in sr driver instead of pm_runtime_*;v1:
Here are some patches to make ZPODD easier to use for end users and a fix for using ZPODD with system suspend.Aaron Lu (6):
block: genhd: add an interface to set disk poll interval
scsi: sr: support runtime pm
scsi: sr: support zero power ODD(ZPODD)
scsi: pm: addmay_power_offflag
scsi: sr: usemay_power_off
libata: acpi: respectmay_power_offflagblock/genhd.c | 23 +++++++++---- drivers/ata/libata-acpi.c | 30 +++++++++++----- drivers/scsi/scsi_sysfs.c | 37 +++++++++++++++++++- drivers/scsi/sr.c | 86 +++++++++++++++++++++++++++++++++++++++++++--- drivers/scsi/sr.h | 1 + drivers/scsi/sr_ioctl.c | 7 +++- include/linux/genhd.h | 1 + include/scsi/scsi_device.h | 4 +++ 8 files changed, 168 insertions(+), 21 deletions(-)Signature · 1 line
1.7.12.21.g871e293
James Bottomley
maintainerQuoted 3 lines · Aaron Lu
Hi James,
May I know if this patchset will enter v3.7?
Sigh, well, I was hoping to persuade the PM people to sort this out first.
The first observation is that all this looks to be too specific. ZPO may be ACPI specific, but the property it abstracts: whether the particular device is powered off or not is generic and probably should be known at the generic PM level. Nothing actually really cares about how we power off the device until you get all the way down to the ACPI controller.
I think we could do this with a couple of flags sitting inside struct device itself: one for pm state and capabilities defined at a generic level and one for device specific pm state. The latter would be for things like the door lock information which is very specific to CDs (although not specific to SCSI CDs). Alternatively, even if we can't use these capabilities at the generic pm level, we still need an internal state set of flags because power state stuff traverses the stack and struct device is the only universal object in that stack.
So I definitely think all of the sdev flags should become either generic or specific flags in device.
James
Quoted 24 lines · James Bottomley
Quoted 3 lines · Aaron Lu
Hi James,
May I know if this patchset will enter v3.7?
Sigh, well, I was hoping to persuade the PM people to sort this out first.
The first observation is that all this looks to be too specific. ZPO may be ACPI specific, but the property it abstracts: whether the particular device is powered off or not is generic and probably should be known at the generic PM level. Nothing actually really cares about how we power off the device until you get all the way down to the ACPI controller.
I think we could do this with a couple of flags sitting inside struct device itself: one for pm state and capabilities defined at a generic level and one for device specific pm state. The latter would be for things like the door lock information which is very specific to CDs (although not specific to SCSI CDs). Alternatively, even if we can't use these capabilities at the generic pm level, we still need an internal state set of flags because power state stuff traverses the stack and struct device is the only universal object in that stack.
Quoted 2 lines
So I definitely think all of the sdev flags should become either generic or specific flags in device.
Well, the problem is that it is kind of irrelevant to the core whether or not the given device can be powered off. Moreover, the actual meaning of what "power off" means depends on the platform (it may be an individual device state or a power domain state, for instance). Also, the set of available low-power states depends on the platform (or the bus type) and generally cannot be universally represented and there are low-power states that aren't "power off" per se, but still require the device state to be restored when putting it back into full power.
We've discussed that for a few times and each time we've ended up agreeing that struct device is not the right place to store this information (for example, PCI stores it in struct pci_dev, USB has its own rules etc.).
I'll have a look at the patchset again and see what can be done about this.
Thanks,
Rafael
Quoted 37 lines · Rafael J. Wysocki
Quoted 24 lines · James Bottomley
Quoted 3 lines · Aaron Lu
Hi James,
May I know if this patchset will enter v3.7?
Sigh, well, I was hoping to persuade the PM people to sort this out first.
The first observation is that all this looks to be too specific. ZPO may be ACPI specific, but the property it abstracts: whether the particular device is powered off or not is generic and probably should be known at the generic PM level. Nothing actually really cares about how we power off the device until you get all the way down to the ACPI controller.
I think we could do this with a couple of flags sitting inside struct device itself: one for pm state and capabilities defined at a generic level and one for device specific pm state. The latter would be for things like the door lock information which is very specific to CDs (although not specific to SCSI CDs). Alternatively, even if we can't use these capabilities at the generic pm level, we still need an internal state set of flags because power state stuff traverses the stack and struct device is the only universal object in that stack.
Quoted 2 lines
So I definitely think all of the sdev flags should become either generic or specific flags in device.
Well, the problem is that it is kind of irrelevant to the core whether or not the given device can be powered off. Moreover, the actual meaning of what "power off" means depends on the platform (it may be an individual device state or a power domain state, for instance). Also, the set of available low-power states depends on the platform (or the bus type) and generally cannot be universally represented and there are low-power states that aren't "power off" per se, but still require the device state to be restored when putting it back into full power.
Quoted 5 lines
We've discussed that for a few times and each time we've ended up agreeing that struct device is not the right place to store this information (for example, PCI stores it in struct
pci_dev, USB has its own rules etc.).I'll have a look at the patchset again and see what can be done about this.
Thanks Rafael, and if there is any question/problem, please kindly let me know.
-Aaron
Quoted 38 lines · Aaron Lu
Quoted 37 lines · Rafael J. Wysocki
Quoted 24 lines · James Bottomley
Quoted 3 lines · Aaron Lu
Hi James,
May I know if this patchset will enter v3.7?
Sigh, well, I was hoping to persuade the PM people to sort this out first.
The first observation is that all this looks to be too specific. ZPO may be ACPI specific, but the property it abstracts: whether the particular device is powered off or not is generic and probably should be known at the generic PM level. Nothing actually really cares about how we power off the device until you get all the way down to the ACPI controller.
I think we could do this with a couple of flags sitting inside struct device itself: one for pm state and capabilities defined at a generic level and one for device specific pm state. The latter would be for things like the door lock information which is very specific to CDs (although not specific to SCSI CDs). Alternatively, even if we can't use these capabilities at the generic pm level, we still need an internal state set of flags because power state stuff traverses the stack and struct device is the only universal object in that stack.
Quoted 2 lines
So I definitely think all of the sdev flags should become either generic or specific flags in device.
Well, the problem is that it is kind of irrelevant to the core whether or not the given device can be powered off. Moreover, the actual meaning of what "power off" means depends on the platform (it may be an individual device state or a power domain state, for instance). Also, the set of available low-power states depends on the platform (or the bus type) and generally cannot be universally represented and there are low-power states that aren't "power off" per se, but still require the device state to be restored when putting it back into full power.
Quoted 8 lines
Quoted 5 lines
We've discussed that for a few times and each time we've ended up agreeing that struct device is not the right place to store this information (for example, PCI stores it in struct
pci_dev, USB has its own rules etc.).I'll have a look at the patchset again and see what can be done about this.
Thanks Rafael, and if there is any question/problem, please kindly let me know.
Well, unfortunately my initial review indicates that the patchset is not quite ready to go upstream yet.
I'll send comments in replies to the individual patches, but overall I can say that at this stage of development, when I look at the patches, it should be clear to me not only what is being changed, but _why_ it is being changed in the first place and, secondly, why it is being changed in this particular way. It's far from that, though.
The first patch in the series doesn't even have a changelog. How the changelog of the second patch is related to it's actual contents is more than quite unclear to me. Etc.
Thanks,
Rafael
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines · Aaron Lu
Thanks Rafael, and if there is any question/problem, please kindly let me know.
Quoted 8 lines
Well, unfortunately my initial review indicates that the patchset is not quite ready to go upstream yet.
I'll send comments in replies to the individual patches, but overall I can say that at this stage of development, when I look at the patches, it should be clear to me not only what is being changed, but _why_ it is being changed in the first place and, secondly, why it is being changed in this particular way. It's far from that, though.
I'm adding zero power support for optical disk drive(ZPODD), which is made possible with the newly defined device attention(DA) pin introduced in SATA 3.1 spec.
The idea here is to use runtime pm to achieve this, so I basically did 2 things:
1 Add runtime pm support for ODD;
2 Add power off support for ODD after it is runtime suspended.
Patch 2 is runtime pm support for ODD, the reason it is done this way is discussed here:
http://www.spinics.net/lists/linux-scsi/msg61551.html
The basic idea is, the ODD will be runtime suspended as long as there is nobody using it, that is, no programs opening the block device.
The ODD will be polled periodically, so it will be runtime resumed before checking if there is any events pending and suspended when done. The only exception is, if we found a disc is just inserted, we will not idle it immediately at the end of the poll, reason explained in another mail.
This is the rational I wrote patch 2, and patch 1 is used by patch 2.
Patch 3 is adding power off support for ODD after it is runtime suspended, the condition is specified in section 15:
ftp://ftp.seagate.com/sff/INF-8090.PDF
That is, for tray type ODD: no media inside and door closed; for slot type ODD: no media inside.
The is the reason sr_suspend is written, for non-ZPODD capable devices, it does nothing; for ZPODD devices, it will check the above condition to see if it is ready to be powered off. The ready_to_power_off flag will be used by ATA layer to decide if power can be removed.
When in powered off state, if user presses the eject button or insert a disc, an ACPI event will be generated and our acpi wake handler will pm_runtime_resume the ODD. And if it is a tray type ODD, its tray should be ejected(need_eject flag) after powered on. This is patch 3.
And patch 4-6 introduces a new sysfs file may_power_off to give user a chance to disable the power off of the device due to various reasons like the ODD claims support of device attention while actually it is broken.
I hope it makes more sense to you now.
Thanks,
Aaron
Quoted 7 lines
The first patch in the series doesn't even have a changelog. How the changelog of the second patch is related to it's actual contents is more than quite unclear to me. Etc.
Thanks,
Rafael
Quoted 18 lines · Aaron Lu
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines · Aaron Lu
Thanks Rafael, and if there is any question/problem, please kindly let me know.
Quoted 8 lines
Well, unfortunately my initial review indicates that the patchset is not quite ready to go upstream yet.
I'll send comments in replies to the individual patches, but overall I can say that at this stage of development, when I look at the patches, it should be clear to me not only what is being changed, but _why_ it is being changed in the first place and, secondly, why it is being changed in this particular way. It's far from that, though.
I'm adding zero power support for optical disk drive(ZPODD), which is made possible with the newly defined device attention(DA) pin introduced in SATA 3.1 spec.
Quoted 8 lines
The idea here is to use runtime pm to achieve this, so I basically did 2 things:
1 Add runtime pm support for ODD;
2 Add power off support for ODD after it is runtime suspended.Patch 2 is runtime pm support for ODD, the reason it is done this way is discussed here:
http://www.spinics.net/lists/linux-scsi/msg61551.html
Why isn't it explained in the patch changelog, then? People should be able to learn why things are done the way they are done from git logs.
Quoted 5 lines
The basic idea is, the ODD will be runtime suspended as long as there is nobody using it, that is, no programs opening the block device.
The ODD will be polled periodically, so it will be runtime resumed before checking if there is any events pending and suspended when done.
OK. So what happens if we power off the drive via runtime PM. Does it it really make sense to resumie it through polling in that case?
Quoted 10 lines
The only exception is, if we found a disc is just inserted, we will not idle it immediately at the end of the poll, reason explained in another mail.
This is the rational I wrote patch 2, and patch 1 is used by patch 2.
Patch 3 is adding power off support for ODD after it is runtime suspended, the condition is specified in section 15:
ftp://ftp.seagate.com/sff/INF-8090.PDF
Quoted 7 lines
That is, for tray type ODD: no media inside and door closed; for slot type ODD: no media inside.
The is the reason
sr_suspendis written, for non-ZPODD capable devices, it does nothing; for ZPODD devices, it will check the above condition to see if it is ready to be powered off. Theready_to_power_offflag will be used by ATA layer to decide if power can be removed.
Now, James says he doesn't like the way ready_to_power_off is used. Sure enough, it is totally irrelevant to the majority of SCSI devices. It actually is totally irrelevant to everything in the SCSI subsystem except for the sr driver and libata. So I wonder if you have considered any alternative way to address the use case at hand?
Quoted 4 lines
When in powered off state, if user presses the eject button or insert a disc, an ACPI event will be generated and our acpi wake handler will
pm_runtime_resumethe ODD. And if it is a tray type ODD, its tray should beejected(need_eject flag)after powered on. This is patch 3.
That sounds reasonable enough, but the role of the powered_off and need_eject flags could be explained a bit better. In particular, it would be nice to have explained why they have to be present in struct scsi_device, because they don't seem to be particularly useful for many SCSI devices that aren't CD drives (the need_eject one in particular).
Quoted 4 lines
And patch 4-6 introduces a new sysfs file
may_power_offto give user a chance to disable the power off of the device due to various reasons like the ODD claims support of device attention while actually it is broken.
User space has an interface to disable runtime PM of any device and it looks like that interface should be sufficient to disable the feature in question. Why do you think the new interface is needed?
Quoted 1 line
I hope it makes more sense to you now.
Well, thanks for the explanation. :-)
Rafael
Quoted 5 lines · On Friday 21 September 2012 23:18:27 Rafael J. Wysocki wrote:
Now, James says he doesn't like the way
ready_to_power_offis used. Sure enough, it is totally irrelevant to the majority of SCSI devices. It actually is totally irrelevant to everything in the SCSI subsystem except for the sr driver and libata. So I wonder if you have considered any alternative way to address the use case at hand?
Strictly speaking, USB on very modern systems could use it, but doesn't in the current implementation.
Quoted 2 lines
That sounds reasonable enough, but the role of the
powered_offandneed_ejectflags could be explained a bit better. In particular, it would
I think need_eject needs to be renamed. Something like "media_change_detected"
Quoted 3 lines
be nice to have explained why they have to be present in struct
scsi_device, because they don't seem to be particularly useful for many SCSI devices that aren't CD drives (theneed_ejectone in particular).
There are sd devices with removable media.
Quoted 3 lines
User space has an interface to disable runtime PM of any device and it looks like that interface should be sufficient to disable the feature in question. Why do you think the new interface is needed?
Because this is not equivalent to doing no runtime PM at all. SCSI now defines some powersaving states which do not involve powering down and thus losing state.
Regards
Oliver
Quoted 10 lines · Oliver Neukum
Quoted 5 lines · On Friday 21 September 2012 23:18:27 Rafael J. Wysocki wrote:
Now, James says he doesn't like the way
ready_to_power_offis used. Sure enough, it is totally irrelevant to the majority of SCSI devices. It actually is totally irrelevant to everything in the SCSI subsystem except for the sr driver and libata. So I wonder if you have considered any alternative way to address the use case at hand?Strictly speaking, USB on very modern systems could use it, but doesn't in the current implementation.
OK
Still, why does the flag have to be in struct scsi_device for this purpose?
Quoted 10 lines
Quoted 2 lines
That sounds reasonable enough, but the role of the
powered_offandneed_ejectflags could be explained a bit better. In particular, it wouldI think
need_ejectneeds to be renamed. Something like "media_change_detected"Quoted 3 lines
be nice to have explained why they have to be present in struct
scsi_device, because they don't seem to be particularly useful for many SCSI devices that aren't CD drives (theneed_ejectone in particular).There are sd devices with removable media.
OK. Does the SCSI layer distinguish them from devices without removable media?
Quoted 7 lines
Quoted 3 lines
User space has an interface to disable runtime PM of any device and it looks like that interface should be sufficient to disable the feature in question. Why do you think the new interface is needed?
Because this is not equivalent to doing no runtime PM at all. SCSI now defines some powersaving states which do not involve powering down and thus losing state.
I see. So the sr's runtime suspend may be useful even without the power-off feature, right?
Rafael
Quoted 3 lines · Rafael J. Wysocki
Quoted 1 line
There are sd devices with removable media.
OK. Does the SCSI layer distinguish them from devices without removable media?
Yes, it does. struct scsi_device has a .removable member, and the Removable flag is part of the response data to the INQUIRY command (which belongs to the primary command set common to all SCSI devices).
Quoted 10 lines
Quoted 7 lines
Quoted 3 lines
User space has an interface to disable runtime PM of any device and it looks like that interface should be sufficient to disable the feature in question. Why do you think the new interface is needed?
Because this is not equivalent to doing no runtime PM at all. SCSI now defines some powersaving states which do not involve powering down and thus losing state.
I see. So the sr's runtime suspend may be useful even without the power-off feature, right?
Exactly. Even though the drive itself may not be powered off, by putting it into runtime suspend we gain the ability to suspend the ancestor devices.
Alan Stern
Quoted 18 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki
Quoted 1 line
There are sd devices with removable media.
OK. Does the SCSI layer distinguish them from devices without removable media?
Yes, it does. struct
scsi_devicehas a .removable member, and the Removable flag is part of the response data to the INQUIRY command (which belongs to the primary command set common to all SCSI devices).Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
User space has an interface to disable runtime PM of any device and it looks like that interface should be sufficient to disable the feature in question. Why do you think the new interface is needed?
Because this is not equivalent to doing no runtime PM at all. SCSI now defines some powersaving states which do not involve powering down and thus losing state.
Quoted 6 lines
Quoted 2 lines
I see. So the sr's runtime suspend may be useful even without the power-off feature, right?
Exactly. Even though the drive itself may not be powered off, by putting it into runtime suspend we gain the ability to suspend the ancestor devices.
OK, so what about using a PM QoS-based approach as described (in general terms) in this message in the "USB ports power off" thread:
http://marc.info/?l=linux-pm&m=134831537224566&w=4
Rafael
Quoted 11 lines · Rafael J. Wysocki
Quoted 6 lines
Quoted 2 lines
I see. So the sr's runtime suspend may be useful even without the power-off feature, right?
Exactly. Even though the drive itself may not be powered off, by putting it into runtime suspend we gain the ability to suspend the ancestor devices.
OK, so what about using a PM QoS-based approach as described (in general terms) in this message in the "USB ports power off" thread:
I'm not entirely sure. It may well work out better in this case than in the USB ports case.
For the ZPODD stuff, the userspace control amounts to a single flag ("do not allow zero-power") which can easily be represented as a QoS constraint.
For the USB ports, the situation is more complicated. The decision about whether or not to power-off a port depends not just on the port itself but also on the device plugged into the port, and there's no direct relation between the two in the sysfs device tree. (That could be fixed perhaps by adding symbolic links between them.) This should be discussed in the USB thread, though...
Alan Stern
Quoted 21 lines · Alan Stern
Quoted 11 lines · Rafael J. Wysocki
Quoted 6 lines
Quoted 2 lines
I see. So the sr's runtime suspend may be useful even without the power-off feature, right?
Exactly. Even though the drive itself may not be powered off, by putting it into runtime suspend we gain the ability to suspend the ancestor devices.
OK, so what about using a PM QoS-based approach as described (in general terms) in this message in the "USB ports power off" thread:
I'm not entirely sure. It may well work out better in this case than in the USB ports case.
For the ZPODD stuff, the userspace control amounts to a single flag ("do not allow zero-power") which can easily be represented as a QoS constraint.
Quoted 5 lines
For the USB ports, the situation is more complicated. The decision about whether or not to power-off a port depends not just on the port itself but also on the device plugged into the port, and there's no direct relation between the two in the sysfs device tree. (That could be fixed perhaps by adding symbolic links between them.)
That doesn't seem to be a big obstacle as far as PM QoS is concerned, though. The trick may be to add PM QoS constraints not for the device itself, but directly for the port it is connected to (it always is possible to add a constraint for the device too, but that simply may be unnecessary). Then, whoever decides whether or not to power off the port would only have to look at the effective PM QoS requirement bits of the port.
Quoted 1 line
This should be discussed in the USB thread, though...
Sure.
Thanks,
Rafael
Quoted 31 lines · Rafael J. Wysocki
Quoted 18 lines · Aaron Lu
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines · Aaron Lu
Thanks Rafael, and if there is any question/problem, please kindly let me know.
Quoted 8 lines
Well, unfortunately my initial review indicates that the patchset is not quite ready to go upstream yet.
I'll send comments in replies to the individual patches, but overall I can say that at this stage of development, when I look at the patches, it should be clear to me not only what is being changed, but _why_ it is being changed in the first place and, secondly, why it is being changed in this particular way. It's far from that, though.
I'm adding zero power support for optical disk drive(ZPODD), which is made possible with the newly defined device attention(DA) pin introduced in SATA 3.1 spec.
Quoted 8 lines
The idea here is to use runtime pm to achieve this, so I basically did 2 things:
1 Add runtime pm support for ODD;
2 Add power off support for ODD after it is runtime suspended.Patch 2 is runtime pm support for ODD, the reason it is done this way is discussed here:
http://www.spinics.net/lists/linux-scsi/msg61551.htmlWhy isn't it explained in the patch changelog, then? People should be able to learn why things are done the way they are done from git logs.
Quoted 8 lines
Quoted 5 lines
The basic idea is, the ODD will be runtime suspended as long as there is nobody using it, that is, no programs opening the block device.
The ODD will be polled periodically, so it will be runtime resumed before checking if there is any events pending and suspended when done.
OK. So what happens if we power off the drive via runtime PM. Does it it really make sense to resumie it through polling in that case?
No, this is the reason I introduced the powered_off flag. If set, the poll will simply return without touching the device.
I've tried to do a disk_block_events call on its suspend callback when it is ready to be powered off, but there is a race that I don't know how to solve:pm_runtime_suspend disk_events_workfn
scsi_dev_type_suspend sr_block_check_events
sr_suspend cdrom_check_events
disk_block_events cdrom_update_events
(this call waits for all sr_check_events
running events_checking function scsi_autopm_get_device
to return)
Suppose sr_suspend runs first, and then sr_check_events comes in. sr_suspend calls disk_block_events, which waits for sr_check_events, while scsi_autopm_get_device wait for suspend callback to finish, deadlock.
Quoted 25 lines
Quoted 11 lines
The only exception is, if we found a disc is just inserted, we will not idle it immediately at the end of the poll, reason explained in another mail.
This is the rational I wrote patch 2, and patch 1 is used by patch 2.
Patch 3 is adding power off support for ODD after it is runtime suspended, the condition is specified in section 15:
ftp://ftp.seagate.com/sff/INF-8090.PDFQuoted 7 lines
That is, for tray type ODD: no media inside and door closed; for slot type ODD: no media inside.
The is the reason
sr_suspendis written, for non-ZPODD capable devices, it does nothing; for ZPODD devices, it will check the above condition to see if it is ready to be powered off. Theready_to_power_offflag will be used by ATA layer to decide if power can be removed.Now, James says he doesn't like the way
ready_to_power_offis used. Sure enough, it is totally irrelevant to the majority of SCSI devices. It actually is totally irrelevant to everything in the SCSI subsystem except for the sr driver and libata. So I wonder if you have considered any alternative way to address the use case at hand?
Quoted 7 lines
Quoted 4 lines
When in powered off state, if user presses the eject button or insert a disc, an ACPI event will be generated and our acpi wake handler will
pm_runtime_resumethe ODD. And if it is a tray type ODD, its tray should beejected(need_eject flag)after powered on. This is patch 3.That sounds reasonable enough, but the role of the
powered_offandneed_ejectflags could be explained a bit better. In particular, it would
powered_off: set when the device is powered off, clear otherwise.
need_eject:
First consider how the device will be runtime resumed:
1 Some program opens the block device;
2 Events checking poll when it's not powered off yet;
3 User presses the eject button or inserts a disc into the slot when the
device is in powered off state.
And the need_eject flag is for case 3, when the device is in powered off state and user presses the eject button, it will be powered on(through acpi wake notification function) and runtime resumed. In its runtime resume callback, its tray needs to be ejected since user just presses the eject button. The whole process of ZPODD is opaque to the user, he/she doesn't know the ODD lost power so the ODD has to behave exactly like it doesn't lose power.
Hi Oliver,
This flag is really to say the tray needs to be ejected after runtime resumed, it's not that media change detected. It is possible that user ejects the tray without putting any disc inside and simply close the tray, which doesn't qualify a media change event. And if user does put a disc in, the sr_check_events will find that and report the media change event to user space. Agree?
Quoted 3 lines
be nice to have explained why they have to be present in struct
scsi_device, because they don't seem to be particularly useful for many SCSI devices that aren't CD drives (theneed_ejectone in particular).
With your suggestion of pm_platform_power_off_allowed, I suppose powered_off can be eliminated similarly with something like pm_platform_powered_off returning true or false(for ACPI platform, return true when device is in D3 cold state).
And for the need_eject flag, I don't know if there is a better place for it. The acpi wake notification code resides in libata(where we need to record that this resume is due to user presses the eject button and the tray needs to be ejected after resumed), and the runtime resume callback resides in scsi driver(where we actually eject the tray). Ideally, this flag should sit in scsi_cd structure, but libata does not have access to it.
Thanks,
Aaron
Quoted 15 lines
Quoted 5 lines
And patch 4-6 introduces a new sysfs file
may_power_offto give user a chance to disable the power off of the device due to various reasons like the ODD claims support of device attention while actually it is broken.User space has an interface to disable runtime PM of any device and it looks like that interface should be sufficient to disable the feature in question. Why do you think the new interface is needed?
Quoted 1 line
I hope it makes more sense to you now.
Well, thanks for the explanation. :-)
Rafael
Quoted 55 lines · Aaron Lu
Quoted 31 lines · Rafael J. Wysocki
Quoted 18 lines · Aaron Lu
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines · Aaron Lu
Thanks Rafael, and if there is any question/problem, please kindly let me know.
Quoted 8 lines
Well, unfortunately my initial review indicates that the patchset is not quite ready to go upstream yet.
I'll send comments in replies to the individual patches, but overall I can say that at this stage of development, when I look at the patches, it should be clear to me not only what is being changed, but _why_ it is being changed in the first place and, secondly, why it is being changed in this particular way. It's far from that, though.
I'm adding zero power support for optical disk drive(ZPODD), which is made possible with the newly defined device attention(DA) pin introduced in SATA 3.1 spec.
Quoted 8 lines
The idea here is to use runtime pm to achieve this, so I basically did 2 things:
1 Add runtime pm support for ODD;
2 Add power off support for ODD after it is runtime suspended.Patch 2 is runtime pm support for ODD, the reason it is done this way is discussed here:
http://www.spinics.net/lists/linux-scsi/msg61551.htmlWhy isn't it explained in the patch changelog, then? People should be able to learn why things are done the way they are done from git logs.
Quoted 8 lines
Quoted 5 lines
The basic idea is, the ODD will be runtime suspended as long as there is nobody using it, that is, no programs opening the block device.
The ODD will be polled periodically, so it will be runtime resumed before checking if there is any events pending and suspended when done.
OK. So what happens if we power off the drive via runtime PM. Does it it really make sense to resumie it through polling in that case?
No, this is the reason I introduced the
powered_offflag. If set, the poll will simply return without touching the device.I've tried to do a
disk_block_eventscall on its suspend callback when it is ready to be powered off, but there is a race that I don't know how to solve:pm_runtime_suspenddisk_events_workfn
scsi_dev_type_suspendsr_block_check_events
sr_suspendcdrom_check_events
disk_block_eventscdrom_update_events
(this call waits for allsr_check_events
runningevents_checkingfunctionscsi_autopm_get_device
to return)
Quoted 4 lines
Suppose
sr_suspendruns first, and thensr_check_eventscomes in.sr_suspendcallsdisk_block_events, which waits forsr_check_events, whilescsi_autopm_get_devicewait for suspend callback to finish, deadlock.
I need some more time to think about this, stay tuned.
Quoted 29 lines
Quoted 29 lines
Quoted 10 lines
The only exception is, if we found a disc is just inserted, we will not idle it immediately at the end of the poll, reason explained in another mail.
This is the rational I wrote patch 2, and patch 1 is used by patch 2.
Patch 3 is adding power off support for ODD after it is runtime suspended, the condition is specified in section 15:
ftp://ftp.seagate.com/sff/INF-8090.PDFQuoted 7 lines
That is, for tray type ODD: no media inside and door closed; for slot type ODD: no media inside.
The is the reason
sr_suspendis written, for non-ZPODD capable devices, it does nothing; for ZPODD devices, it will check the above condition to see if it is ready to be powered off. Theready_to_power_offflag will be used by ATA layer to decide if power can be removed.Now, James says he doesn't like the way
ready_to_power_offis used. Sure enough, it is totally irrelevant to the majority of SCSI devices. It actually is totally irrelevant to everything in the SCSI subsystem except for the sr driver and libata. So I wonder if you have considered any alternative way to address the use case at hand?Quoted 4 lines
When in powered off state, if user presses the eject button or insert a disc, an ACPI event will be generated and our acpi wake handler will
pm_runtime_resumethe ODD. And if it is a tray type ODD, its tray should beejected(need_eject flag)after powered on. This is patch 3.
Quoted 4 lines
Quoted 2 lines
That sounds reasonable enough, but the role of the
powered_offandneed_ejectflags could be explained a bit better. In particular, it would
powered_off: set when the device is powered off, clear otherwise.
That's pretty clear, but I think this flag should be called no_polling or something like this, because that's what it means to the SCSI layer.
Quoted 5 lines
need_eject:
First consider how the device will be runtime resumed:
1 Some program opens the block device;
2 Events checking poll when it's not powered off yet;
3 User presses the eject button or inserts a disc into the slot when the
Quoted 8 lines
device is in powered off state.
And theneed_ejectflag is for case 3, when the device is in powered off state and user presses the eject button, it will be powered on(through acpi wake notification function) and runtime resumed. In its runtime resume callback, its tray needs to be ejected since user just presses the eject button. The whole process of ZPODD is opaque to the user, he/she doesn't know the ODD lost power so the ODD has to behave exactly like it doesn't lose power.
Do you think it can be useful for other types of devices, not necessarily handled through ACPI?
Quoted 8 lines
Hi Oliver,
This flag is really to say the tray needs to be ejected after runtime resumed, it's not that media change detected. It is possible that user ejects the tray without putting any disc inside and simply close the tray, which doesn't qualify a media change event. And if user does put a disc in, thesr_check_eventswill find that and report the media change event to user space. Agree?
Quoted 8 lines
Quoted 3 lines
be nice to have explained why they have to be present in struct
scsi_device, because they don't seem to be particularly useful for many SCSI devices that aren't CD drives (theneed_ejectone in particular).With your suggestion of
pm_platform_power_off_allowed, I supposepowered_offcan be eliminated similarly with something likepm_platform_powered_offreturning true orfalse(for ACPI platform, return true when device is in D3 cold state).
I'm currently thinking that using PM QoS may be a better approach here.
Quoted 7 lines
And for the
need_ejectflag, I don't know if there is a better place for it. The acpi wake notification code resides in libata(where we need to record that this resume is due to user presses the eject button and the tray needs to be ejected after resumed), and the runtime resume callback resides in scsi driver(where we actually eject the tray). Ideally, this flag should sit inscsi_cdstructure, but libata does not have access to it.
Yes, that's the problem that James mentioned.
Thanks,
Rafael
Quoted 56 lines · Rafael J. Wysocki
Quoted 55 lines · Aaron Lu
Quoted 31 lines · Rafael J. Wysocki
Quoted 18 lines · Aaron Lu
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines · Aaron Lu
Thanks Rafael, and if there is any question/problem, please kindly let me know.
Quoted 8 lines
Well, unfortunately my initial review indicates that the patchset is not quite ready to go upstream yet.
I'll send comments in replies to the individual patches, but overall I can say that at this stage of development, when I look at the patches, it should be clear to me not only what is being changed, but _why_ it is being changed in the first place and, secondly, why it is being changed in this particular way. It's far from that, though.
I'm adding zero power support for optical disk drive(ZPODD), which is made possible with the newly defined device attention(DA) pin introduced in SATA 3.1 spec.
Quoted 8 lines
The idea here is to use runtime pm to achieve this, so I basically did 2 things:
1 Add runtime pm support for ODD;
2 Add power off support for ODD after it is runtime suspended.Patch 2 is runtime pm support for ODD, the reason it is done this way is discussed here:
http://www.spinics.net/lists/linux-scsi/msg61551.htmlWhy isn't it explained in the patch changelog, then? People should be able to learn why things are done the way they are done from git logs.
Quoted 8 lines
Quoted 5 lines
The basic idea is, the ODD will be runtime suspended as long as there is nobody using it, that is, no programs opening the block device.
The ODD will be polled periodically, so it will be runtime resumed before checking if there is any events pending and suspended when done.
OK. So what happens if we power off the drive via runtime PM. Does it it really make sense to resumie it through polling in that case?
No, this is the reason I introduced the
powered_offflag. If set, the poll will simply return without touching the device.I've tried to do a
disk_block_eventscall on its suspend callback when it is ready to be powered off, but there is a race that I don't know how to solve:pm_runtime_suspenddisk_events_workfn
scsi_dev_type_suspendsr_block_check_events
sr_suspendcdrom_check_events
disk_block_eventscdrom_update_events
(this call waits for allsr_check_events
runningevents_checkingfunctionscsi_autopm_get_device
to return)
Quoted 6 lines
Quoted 4 lines
Suppose
sr_suspendruns first, and thensr_check_eventscomes in.sr_suspendcallsdisk_block_events, which waits forsr_check_events, whilescsi_autopm_get_devicewait for suspend callback to finish, deadlock.I need some more time to think about this, stay tuned.
Thanks.
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 11 lines
The only exception is, if we found a disc is just inserted, we will not idle it immediately at the end of the poll, reason explained in another mail.
This is the rational I wrote patch 2, and patch 1 is used by patch 2.
Patch 3 is adding power off support for ODD after it is runtime suspended, the condition is specified in section 15:
ftp://ftp.seagate.com/sff/INF-8090.PDFQuoted 7 lines
That is, for tray type ODD: no media inside and door closed; for slot type ODD: no media inside.
The is the reason
sr_suspendis written, for non-ZPODD capable devices, it does nothing; for ZPODD devices, it will check the above condition to see if it is ready to be powered off. Theready_to_power_offflag will be used by ATA layer to decide if power can be removed.Now, James says he doesn't like the way
ready_to_power_offis used. Sure enough, it is totally irrelevant to the majority of SCSI devices. It actually is totally irrelevant to everything in the SCSI subsystem except for the sr driver and libata. So I wonder if you have considered any alternative way to address the use case at hand?Quoted 4 lines
When in powered off state, if user presses the eject button or insert a disc, an ACPI event will be generated and our acpi wake handler will
pm_runtime_resumethe ODD. And if it is a tray type ODD, its tray should beejected(need_eject flag)after powered on. This is patch 3.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
That sounds reasonable enough, but the role of the
powered_offandneed_ejectflags could be explained a bit better. In particular, it would
powered_off: set when the device is powered off, clear otherwise.That's pretty clear, but I think this flag should be called
no_pollingor something like this, because that's what it means to the SCSI layer.
Agree.
Quoted 15 lines
Quoted 14 lines
need_eject:
First consider how the device will be runtime resumed:
1 Some program opens the block device;
2 Events checking poll when it's not powered off yet;
3 User presses the eject button or inserts a disc into the slot when the
device is in powered off state.
And theneed_ejectflag is for case 3, when the device is in powered off state and user presses the eject button, it will be powered on(through acpi wake notification function) and runtime resumed. In its runtime resume callback, its tray needs to be ejected since user just presses the eject button. The whole process of ZPODD is opaque to the user, he/she doesn't know the ODD lost power so the ODD has to behave exactly like it doesn't lose power.
Quoted 2 lines
Do you think it can be useful for other types of devices, not necessarily handled through ACPI?
I can only say that it is useful for ZPODD, if ZPODD someday is used on another platform that does not use ACPI, the need_eject flag should still be needed.
As for other scsi devices, I'm not sure.
Quoted 13 lines
Quoted 13 lines
Hi Oliver,
This flag is really to say the tray needs to be ejected after runtime resumed, it's not that media change detected. It is possible that user ejects the tray without putting any disc inside and simply close the tray, which doesn't qualify a media change event. And if user does put a disc in, thesr_check_eventswill find that and report the media change event to user space. Agree?Quoted 3 lines
be nice to have explained why they have to be present in struct
scsi_device, because they don't seem to be particularly useful for many SCSI devices that aren't CD drives (theneed_ejectone in particular).
Quoted 6 lines
Quoted 4 lines
With your suggestion of
pm_platform_power_off_allowed, I supposepowered_offcan be eliminated similarly with something likepm_platform_powered_offreturning true orfalse(for ACPI platform, return true when device is in D3 cold state).I'm currently thinking that using PM QoS may be a better approach here.
Is it something like a "power_off_allowed" binary constraint? Then both the sr driver and the user can change the value so that both the ready_to_power_off and may_power_off is no longer needed.
Quoted 10 lines
Quoted 8 lines
And for the
need_ejectflag, I don't know if there is a better place for it. The acpi wake notification code resides in libata(where we need to record that this resume is due to user presses the eject button and the tray needs to be ejected after resumed), and the runtime resume callback resides in scsi driver(where we actually eject the tray). Ideally, this flag should sit inscsi_cdstructure, but libata does not have access to it.Yes, that's the problem that James mentioned.
Right, not easy to find a home for need_eject...
Thanks,
Aaron
Quoted 3 lines
Thanks,
Rafael
Quoted 57 lines · Aaron Lu
Quoted 56 lines · Rafael J. Wysocki
Quoted 55 lines · Aaron Lu
Quoted 31 lines · Rafael J. Wysocki
Quoted 18 lines · Aaron Lu
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines · Aaron Lu
Thanks Rafael, and if there is any question/problem, please kindly let me know.
Quoted 8 lines
Well, unfortunately my initial review indicates that the patchset is not quite ready to go upstream yet.
I'll send comments in replies to the individual patches, but overall I can say that at this stage of development, when I look at the patches, it should be clear to me not only what is being changed, but _why_ it is being changed in the first place and, secondly, why it is being changed in this particular way. It's far from that, though.
I'm adding zero power support for optical disk drive(ZPODD), which is made possible with the newly defined device attention(DA) pin introduced in SATA 3.1 spec.
Quoted 8 lines
The idea here is to use runtime pm to achieve this, so I basically did 2 things:
1 Add runtime pm support for ODD;
2 Add power off support for ODD after it is runtime suspended.Patch 2 is runtime pm support for ODD, the reason it is done this way is discussed here:
http://www.spinics.net/lists/linux-scsi/msg61551.htmlWhy isn't it explained in the patch changelog, then? People should be able to learn why things are done the way they are done from git logs.
Quoted 8 lines
Quoted 5 lines
The basic idea is, the ODD will be runtime suspended as long as there is nobody using it, that is, no programs opening the block device.
The ODD will be polled periodically, so it will be runtime resumed before checking if there is any events pending and suspended when done.
OK. So what happens if we power off the drive via runtime PM. Does it it really make sense to resumie it through polling in that case?
No, this is the reason I introduced the
powered_offflag. If set, the poll will simply return without touching the device.I've tried to do a
disk_block_eventscall on its suspend callback when it is ready to be powered off, but there is a race that I don't know how to solve:pm_runtime_suspenddisk_events_workfn
scsi_dev_type_suspendsr_block_check_events
sr_suspendcdrom_check_events
disk_block_eventscdrom_update_events
(this call waits for allsr_check_events
runningevents_checkingfunctionscsi_autopm_get_device
to return)
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Suppose
sr_suspendruns first, and thensr_check_eventscomes in.sr_suspendcallsdisk_block_events, which waits forsr_check_events, whilescsi_autopm_get_devicewait for suspend callback to finish, deadlock.I need some more time to think about this, stay tuned.
Thanks.
Alan has just given you a good suggestion, you can follow it I think.
Quoted 54 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 10 lines
The only exception is, if we found a disc is just inserted, we will not idle it immediately at the end of the poll, reason explained in another mail.
This is the rational I wrote patch 2, and patch 1 is used by patch 2.
Patch 3 is adding power off support for ODD after it is runtime suspended, the condition is specified in section 15:
ftp://ftp.seagate.com/sff/INF-8090.PDFQuoted 7 lines
That is, for tray type ODD: no media inside and door closed; for slot type ODD: no media inside.
The is the reason
sr_suspendis written, for non-ZPODD capable devices, it does nothing; for ZPODD devices, it will check the above condition to see if it is ready to be powered off. Theready_to_power_offflag will be used by ATA layer to decide if power can be removed.Now, James says he doesn't like the way
ready_to_power_offis used. Sure enough, it is totally irrelevant to the majority of SCSI devices. It actually is totally irrelevant to everything in the SCSI subsystem except for the sr driver and libata. So I wonder if you have considered any alternative way to address the use case at hand?Quoted 4 lines
When in powered off state, if user presses the eject button or insert a disc, an ACPI event will be generated and our acpi wake handler will
pm_runtime_resumethe ODD. And if it is a tray type ODD, its tray should beejected(need_eject flag)after powered on. This is patch 3.Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
That sounds reasonable enough, but the role of the
powered_offandneed_ejectflags could be explained a bit better. In particular, it would
powered_off: set when the device is powered off, clear otherwise.That's pretty clear, but I think this flag should be called
no_pollingor something like this, because that's what it means to the SCSI layer.Agree.
Quoted 15 lines
Quoted 14 lines
need_eject:
First consider how the device will be runtime resumed:
1 Some program opens the block device;
2 Events checking poll when it's not powered off yet;
3 User presses the eject button or inserts a disc into the slot when the
device is in powered off state.
And theneed_ejectflag is for case 3, when the device is in powered off state and user presses the eject button, it will be powered on(through acpi wake notification function) and runtime resumed. In its runtime resume callback, its tray needs to be ejected since user just presses the eject button. The whole process of ZPODD is opaque to the user, he/she doesn't know the ODD lost power so the ODD has to behave exactly like it doesn't lose power.
Quoted 8 lines
Quoted 2 lines
Do you think it can be useful for other types of devices, not necessarily handled through ACPI?
I can only say that it is useful for ZPODD, if ZPODD someday is used on another platform that does not use ACPI, the
need_ejectflag should still be needed.As for other scsi devices, I'm not sure.
I see. This means we don't really have good arguments for putting that flag into struct scsi_device ...
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Hi Oliver,
This flag is really to say the tray needs to be ejected after runtime resumed, it's not that media change detected. It is possible that user ejects the tray without putting any disc inside and simply close the tray, which doesn't qualify a media change event. And if user does put a disc in, thesr_check_eventswill find that and report the media change event to user space. Agree?Quoted 3 lines
be nice to have explained why they have to be present in struct
scsi_device, because they don't seem to be particularly useful for many SCSI devices that aren't CD drives (theneed_ejectone in particular).With your suggestion of
pm_platform_power_off_allowed, I supposepowered_offcan be eliminated similarly with something likepm_platform_powered_offreturning true orfalse(for ACPI platform, return true when device is in D3 cold state).
Quoted 5 lines
Quoted 1 line
I'm currently thinking that using PM QoS may be a better approach here.
Is it something like a "
power_off_allowed" binary constraint? Then both the sr driver and the user can change the value so that both theready_to_power_offandmay_power_offis no longer needed.
Yes, that's the idea.
Thanks,
Rafael
Quoted 20 lines · Rafael J. Wysocki
Quoted 19 lines · Aaron Lu
Quoted 17 lines · Rafael J. Wysocki
Quoted 5 lines · Aaron Lu
need_eject:
First consider how the device will be runtime resumed:
1 Some program opens the block device;
2 Events checking poll when it's not powered off yet;
3 User presses the eject button or inserts a disc into the slot when theQuoted 8 lines
device is in powered off state.
And theneed_ejectflag is for case 3, when the device is in powered off state and user presses the eject button, it will be powered on(through acpi wake notification function) and runtime resumed. In its runtime resume callback, its tray needs to be ejected since user just presses the eject button. The whole process of ZPODD is opaque to the user, he/she doesn't know the ODD lost power so the ODD has to behave exactly like it doesn't lose power.Do you think it can be useful for other types of devices, not necessarily handled through ACPI?
Quoted 8 lines
Quoted 5 lines
I can only say that it is useful for ZPODD, if ZPODD someday is used on another platform that does not use ACPI, the
need_ejectflag should still be needed.As for other scsi devices, I'm not sure.
I see. This means we don't really have good arguments for putting that flag into struct
scsi_device...
OK.
I'm thinking of moving the acpi wake notification code from ata to scsi, so that the notification function lives in sr module and then I do not need to set this need_eject flag in scsi_device and scsi_cd structure needs to host this flag.
A example patch would be something like the following, I didn't seperate these ACPI calls in sr.c as this is just a concept proof, if this is the right thing to do, I will separate them into another file sr-acpi.c and make empty stubs for them in sr.h for systems do not have ACPI configured.
drivers/scsi/sr.c +60 -4
@@ -46,6 +46,7 @@#include <linux/mutex.h> #include <linux/slab.h> #include <linux/pm_runtime.h> +#include <linux/acpi.h> #include <asm/uaccess.h> #include <scsi/scsi.h>
@@ -57,6 +58,8 @@#include <scsi/scsi_host.h> #include <scsi/scsi_ioctl.h> /* For the door lock/unlock commands */ +#include <acpi/acpi_bus.h> +#include "scsi_logging.h" #include "sr.h"
@@ -212,8 +220,8 @@ static int sr_resume(struct device *dev)scsi_test_unit_ready (cd->device,SR_TIMEOUT ,MAX_RETRIES , &sshdr);/* If user wakes up the ODD, eject the tray */ -if (cd->device->need_eject) { - cd->device->need_eject =0 ; +if (cd->need_eject) { + cd->need_eject = false;/* But only for tray type ODD when door is not locked */ if (!(cd->cdi.mask &CDC_CLOSE_TRAY ) && !cd->door_locked)sr_tray_move (&cd->cdi,1 );
@@ -704,6 +711,58 @@ static void sr_release(struct cdrom_device_info *cdi) } +static void sr_acpi_wake_dev (acpi_handle handle,u32 event,void *context) +{ +struct device *dev = context; +struct scsi_cd *cd =dev_get_drvdata (dev); + +if (event ==ACPI_NOTIFY_DEVICE_WAKE &&pm_runtime_suspended (dev)) { + cd->need_eject = true; +pm_runtime_resume (dev); + } +} + +static void sr_acpi_add_pm_notifier (struct device *dev) +{ +struct acpi_device *acpi_dev; +acpi_handle handle; +acpi_status status; + + handle = dev->archdata.acpi_handle; +if (!handle) +return ; + + status =acpi_bus_get_device (handle, &acpi_dev); +if (ACPI_FAILURE (status)) +return ; + +acpi_power_resource_register_device (dev, handle); +acpi_install_notify_handler (handle,ACPI_SYSTEM_NOTIFY , + sr_acpi_wake_dev, dev); +device_set_run_wake (dev, true); +} + +static void sr_acpi_remove_pm_notifier (struct device *dev) +{ +struct acpi_device *acpi_dev; +acpi_handle handle; +acpi_status status; + + handle = dev->archdata.acpi_handle; +if (!handle) +return ; + + status =acpi_bus_get_device (handle, &acpi_dev); +if (ACPI_FAILURE (status)) +return ; + +acpi_power_resource_unregister_device (dev, handle); +device_set_run_wake (dev, false); +acpi_remove_notify_handler (handle,ACPI_SYSTEM_NOTIFY , sr_acpi_wake_dev); +} +static int sr_probe (struct device *dev) {struct scsi_device *sdev =to_scsi_device (dev);
@@ -786,7 +845,9 @@ static int sr_probe(struct device *dev)sdev_printk (KERN_DEBUG , sdev,"Attached scsi CD-ROM %s\n" , cd->cdi.name); -/* enable runtime pm */ +if (sdev->can_power_off) +sr_acpi_add_pm_notifier (dev); +scsi_autopm_put_device (cd->device);return 0 ;
@@ -1036,8 +1097,9 @@ static int sr_remove(struct device *dev) {struct scsi_cd *cd =dev_get_drvdata (dev); -/* disable runtime pm */ scsi_autopm_get_device (cd->device); +if (cd->device->can_power_off) +sr_acpi_remove_pm_notifier (dev);blk_queue_prep_rq (cd->device->request_queue, scsi_prep_fn);del_gendisk (cd->disk);
Thanks,
Aaron
James Bottomley
maintainerQuoted 4 lines · Aaron Lu
A example patch would be something like the following, I didn't seperate these ACPI calls in
sr.cas this is just a concept proof, if this is the right thing to do, I will separate them into another filesr-acpi.cand make empty stubs for them insr.hfor systems do not have ACPI configured.
Apart from the needed separation to compile in the !ACPI case
Quoted 44 lines
drivers/scsi/sr.c +13
-2@@ -46,6 +46,7 @@#include <linux/mutex.h> #include <linux/slab.h> #include <linux/pm_runtime.h> +#include <linux/acpi.h> #include <asm/uaccess.h> #include <scsi/scsi.h> @@ -57,6 +58,8 @@#include <scsi/scsi_host.h> #include <scsi/scsi_ioctl.h> /* For the door lock/unlock commands */ +#include <acpi/acpi_bus.h> +#include "scsi_logging.h" #include "sr.h" @@ -212,8 +220,8 @@ static int sr_resume(struct device *dev)scsi_test_unit_ready (cd->device,SR_TIMEOUT ,MAX_RETRIES , &sshdr);/* If user wakes up the ODD, eject the tray */ -if (cd->device->need_eject) { - cd->device->need_eject =0 ; +if (cd->need_eject) { + cd->need_eject = false;/* But only for tray type ODD when door is not locked */ if (!(cd->cdi.mask &CDC_CLOSE_TRAY ) && !cd->door_locked)sr_tray_move (&cd->cdi,1 );@@ -704,6 +711,58 @@ static void sr_release(struct cdrom_device_info *cdi) } +static void sr_acpi_wake_dev (acpi_handle handle,u32 event,void *context) +{ +struct device *dev = context; +struct scsi_cd *cd =dev_get_drvdata (dev); + +if (event ==ACPI_NOTIFY_DEVICE_WAKE &&pm_runtime_suspended (dev)) { + cd->need_eject = true; +pm_runtime_resume (dev);
drivers/scsi/sr.c static void sr_release(struct cdrom_device_info *cdi) · line 731
Quoted 10 lines
drivers/scsi/sr.c +10
-0+ } +} + +static void sr_acpi_add_pm_notifier (struct device *dev) +{ +struct acpi_device *acpi_dev; +acpi_handle handle; +acpi_status status; + + handle = dev->archdata.acpi_handle;
This is a complete no-no. archdata is defined to be specific to the architecture it's supposed to be opaque to non-arch code. You'll find that only x86 and ia64 defines an acpi_handle there. This will instantly fail to compile on non intel. If you need the handle, it should be obtained via some accessor like dev_to_acpi_handle() which will allow this to continue to function when, say, arm acquires ACPI.
I've got to say, this looks like a fault in ACPI itself. If the handles are 1:1 with struct device, then why not have all the functions taking handles take the device instead and leave the embedded handle safely in the architecture specific code?
James
Quoted 59 lines · James Bottomley
Quoted 4 lines · Aaron Lu
A example patch would be something like the following, I didn't seperate these ACPI calls in
sr.cas this is just a concept proof, if this is the right thing to do, I will separate them into another filesr-acpi.cand make empty stubs for them insr.hfor systems do not have ACPI configured.Apart from the needed separation to compile in the !ACPI case
Quoted 51 lines
drivers/scsi/sr.c +20
-2@@ -46,6 +46,7 @@#include <linux/mutex.h> #include <linux/slab.h> #include <linux/pm_runtime.h> +#include <linux/acpi.h> #include <asm/uaccess.h> #include <scsi/scsi.h> @@ -57,6 +58,8 @@#include <scsi/scsi_host.h> #include <scsi/scsi_ioctl.h> /* For the door lock/unlock commands */ +#include <acpi/acpi_bus.h> +#include "scsi_logging.h" #include "sr.h" @@ -212,8 +220,8 @@ static int sr_resume(struct device *dev)scsi_test_unit_ready (cd->device,SR_TIMEOUT ,MAX_RETRIES , &sshdr);/* If user wakes up the ODD, eject the tray */ -if (cd->device->need_eject) { - cd->device->need_eject =0 ; +if (cd->need_eject) { + cd->need_eject = false;/* But only for tray type ODD when door is not locked */ if (!(cd->cdi.mask &CDC_CLOSE_TRAY ) && !cd->door_locked)sr_tray_move (&cd->cdi,1 );@@ -704,6 +711,58 @@ static void sr_release(struct cdrom_device_info *cdi) } +static void sr_acpi_wake_dev (acpi_handle handle,u32 event,void *context) +{ +struct device *dev = context; +struct scsi_cd *cd =dev_get_drvdata (dev); + +if (event ==ACPI_NOTIFY_DEVICE_WAKE &&pm_runtime_suspended (dev)) { + cd->need_eject = true; +pm_runtime_resume (dev); + } +} + +static void sr_acpi_add_pm_notifier (struct device *dev) +{ +struct acpi_device *acpi_dev; +acpi_handle handle;
Quoted 8 lines
drivers/scsi/sr.c static void sr_release(struct cdrom_device_info *cdi) · line 731
Quoted 3 lines
drivers/scsi/sr.c +3
-0+acpi_status status; + + handle = dev->archdata.acpi_handle;This is a complete no-no. archdata is defined to be specific to the architecture it's supposed to be opaque to non-arch code. You'll find that only x86 and ia64 defines an
acpi_handlethere. This will instantly fail to compile on non intel. If you need the handle, it
If you are OK with this change to solve the need_eject flag, I'll prepare a formal patch, in which, all of the newly added function will be within the range of
#ifdef CONFIG_ACPI
... ...
#endif
And for the CONFIG_ACPI not defined case, they will be static inline empty functions. Then there should be no compile errors.
Quoted 2 lines
should be obtained via some accessor like
dev_to_acpi_handle()which will allow this to continue to function when, say, arm acquires ACPI.
There is a DEVICE_ACPI_HANDLE macro that I'll use when preparing the formal patch. I'm rushing out these code to show the idea. Sorry for not considering these things.
Thanks,
Aaron
Quoted 23 lines · James Bottomley
Quoted 4 lines · Aaron Lu
A example patch would be something like the following, I didn't seperate these ACPI calls in
sr.cas this is just a concept proof, if this is the right thing to do, I will separate them into another filesr-acpi.cand make empty stubs for them insr.hfor systems do not have ACPI configured.Apart from the needed separation to compile in the !ACPI case
Review
Quoted 7 lines
(quoted diff) +7
-0+static void sr_acpi_add_pm_notifier(struct device *dev) +{ + struct acpi_device *acpi_dev; + acpi_handle handle; + acpi_status status; + + handle = dev->archdata.acpi_handle;This is a complete no-no. archdata is defined to be specific to the architecture it's supposed to be opaque to non-arch code. You'll find that only x86 and ia64 defines an
acpi_handlethere. This will instantly fail to compile on non intel. If you need the handle, it should be obtained via some accessor likedev_to_acpi_handle()which will allow this to continue to function when, say, arm acquires ACPI.
Quoted 4 lines
I've got to say, this looks like a fault in ACPI itself. If the handles are 1:1 with struct device, then why not have all the functions taking handles take the device instead and leave the embedded handle safely in the architecture specific code?
I've prepared a complete code change for you to take a look, with the notification code resides in sr, I can move the need_eject flag from scsi_device to scsi_cd, which should make more sense.
drivers/scsi/Makefile +1 -0
@@ -177,6 +177,7 @@ sd_mod-objs := sd.o sd_mod-$(CONFIG_BLK_DEV_INTEGRITY) += sd_dif.o sr_mod-objs := sr.o sr_ioctl.o sr_vendor.o +sr_mod-$(CONFIG_ACPI) += sr_acpi.o ncr53c8xx-flags-$(CONFIG_SCSI_ZALON) \ := -DCONFIG_NCR53C8XX_PREFETCH -DSCSI_NCR_BIG_ENDIAN \ -DCONFIG_SCSI_NCR53C8XX_NO_WORD_TRANSFERS
drivers/scsi/sr.c +2 -0
@@ -734,6 +734,7 @@ static int sr_probe(struct device *dev)sdev_printk (KERN_DEBUG , sdev,"Attached scsi CD-ROM %s\n" , cd->cdi.name); +sr_acpi_add_pm_notifier (dev);scsi_autopm_put_device (cd->device);return 0 ;
@@ -984,6 +985,7 @@ static int sr_remove(struct device *dev)struct scsi_cd *cd =dev_get_drvdata (dev);scsi_autopm_get_device (cd->device); +sr_acpi_remove_pm_notifier (dev);blk_queue_prep_rq (cd->device->request_queue, scsi_prep_fn);del_gendisk (cd->disk);
drivers/scsi/sr.h +11 -0
@@ -48,6 +48,8 @@ typedef struct scsi_cd { bool get_event_changed:1; /* changed according to GET_EVENT */ bool ignore_get_event:1; /* GET_EVENT is unreliable, use TUR */ + bool need_eject:1; /* User wakes up the ODD, need eject the tray */ +struct cdrom_device_info cdi;/* We hold gendisk and scsi_device references on probe and use * the refs on this kref to decide when to release them */
@@ -74,4 +76,13 @@ void sr_vendor_init(Scsi_CD *);int sr_cd_check (struct cdrom_device_info *);int sr_set_blocklength (Scsi_CD *,int blocklength); +/* sr_acpi.c */ +#ifdef CONFIG_ACPI +extern void sr_acpi_add_pm_notifier (struct device *); +extern void sr_acpi_remove_pm_notifier (struct device *); +#else +static inline void sr_acpi_add_pm_notifier (struct device *dev) {} +static inline void sr_acpi_remove_pm_notifier (struct device *dev) {} +#endif +#endif
drivers/scsi/sr_acpi.c new file +64 -0
64 lines not on this page · raw message
Thanks,
Aaron
[CC: list trimmed somewhat]
Quoted 11 lines · Aaron Lu
I've tried to do a
disk_block_eventscall on its suspend callback when it is ready to be powered off, but there is a race that I don't know how to solve:pm_runtime_suspenddisk_events_workfn
scsi_dev_type_suspendsr_block_check_events
sr_suspendcdrom_check_events
disk_block_eventscdrom_update_events
(this call waits for allsr_check_events
runningevents_checkingfunctionscsi_autopm_get_device
to return)
Quoted 4 lines
Suppose
sr_suspendruns first, and thensr_check_eventscomes in.sr_suspendcallsdisk_block_events, which waits forsr_check_events, whilescsi_autopm_get_devicewait for suspend callback to finish, deadlock.
The problem is in the scsi_autopm_get_device call. What you need to do here is increment the PM usage counter without resuming the drive. Then if the runtime PM status is RPM_SUSPENDING, decrement the usage counter and return immediately (skip the status check); otherwise call scsi_autopm_get_device as before and do an extra decrement after the status check is finished.
It's a little more tricky than this because you need to acquire the private runtime PM spinlock in addition to incrementing the usage counter, for proper synchronization. I don't think we have any interface to do this, although it would be easy to add one.
Alan Stern
James Bottomley
maintainerQuoted 28 lines · Rafael J. Wysocki
Quoted 24 lines · James Bottomley
Quoted 3 lines · Aaron Lu
Hi James,
May I know if this patchset will enter v3.7?
Sigh, well, I was hoping to persuade the PM people to sort this out first.
The first observation is that all this looks to be too specific. ZPO may be ACPI specific, but the property it abstracts: whether the particular device is powered off or not is generic and probably should be known at the generic PM level. Nothing actually really cares about how we power off the device until you get all the way down to the ACPI controller.
I think we could do this with a couple of flags sitting inside struct device itself: one for pm state and capabilities defined at a generic level and one for device specific pm state. The latter would be for things like the door lock information which is very specific to CDs (although not specific to SCSI CDs). Alternatively, even if we can't use these capabilities at the generic pm level, we still need an internal state set of flags because power state stuff traverses the stack and struct device is the only universal object in that stack.
Quoted 2 lines
So I definitely think all of the sdev flags should become either generic or specific flags in device.
Quoted 8 lines
Well, the problem is that it is kind of irrelevant to the core whether or not the given device can be powered off. Moreover, the actual meaning of what "power off" means depends on the platform (it may be an individual device state or a power domain state, for instance). Also, the set of available low-power states depends on the platform (or the bus type) and generally cannot be universally represented and there are low-power states that aren't "power off" per se, but still require the device state to be restored when putting it back into full power.
So I don't insist on it being generic, but we do need somewhere to hang the state.
Quoted 3 lines
We've discussed that for a few times and each time we've ended up agreeing that struct device is not the right place to store this information (for example, PCI stores it in struct
pci_dev, USB has its own rules etc.).
So, here's the problem this causes. In SCSI, lower level devices have no access to the drivers (to which the upper layer structures are tied), so we have no way to go from device/scsi device to the scsi_disk structure say. This means that a lot of device specific PM stuff tends to have flags in scsi_device just so we can get access to it. A flag in device would allow us to carry the information farther (say to struct cdrom for instance).
Quoted 1 line
I'll have a look at the patchset again and see what can be done about this.
Thanks,
James
Quoted 45 lines · James Bottomley
Quoted 28 lines · Rafael J. Wysocki
Quoted 24 lines · James Bottomley
Quoted 3 lines · Aaron Lu
Hi James,
May I know if this patchset will enter v3.7?
Sigh, well, I was hoping to persuade the PM people to sort this out first.
The first observation is that all this looks to be too specific. ZPO may be ACPI specific, but the property it abstracts: whether the particular device is powered off or not is generic and probably should be known at the generic PM level. Nothing actually really cares about how we power off the device until you get all the way down to the ACPI controller.
I think we could do this with a couple of flags sitting inside struct device itself: one for pm state and capabilities defined at a generic level and one for device specific pm state. The latter would be for things like the door lock information which is very specific to CDs (although not specific to SCSI CDs). Alternatively, even if we can't use these capabilities at the generic pm level, we still need an internal state set of flags because power state stuff traverses the stack and struct device is the only universal object in that stack.
Quoted 2 lines
So I definitely think all of the sdev flags should become either generic or specific flags in device.
Quoted 8 lines
Well, the problem is that it is kind of irrelevant to the core whether or not the given device can be powered off. Moreover, the actual meaning of what "power off" means depends on the platform (it may be an individual device state or a power domain state, for instance). Also, the set of available low-power states depends on the platform (or the bus type) and generally cannot be universally represented and there are low-power states that aren't "power off" per se, but still require the device state to be restored when putting it back into full power.
So I don't insist on it being generic, but we do need somewhere to hang the state.
Quoted 3 lines
We've discussed that for a few times and each time we've ended up agreeing that struct device is not the right place to store this information (for example, PCI stores it in struct
pci_dev, USB has its own rules etc.).
Quoted 9 lines
So, here's the problem this causes. In SCSI, lower level devices have no access to the drivers (to which the upper layer structures are tied), so we have no way to go from device/scsi device to the
scsi_diskstructure say. This means that a lot of device specific PM stuff tends to have flags inscsi_devicejust so we can get access to it. A flag in device would allow us to carry the information farther (say to struct cdrom for instance).Quoted 1 line
I'll have a look at the patchset again and see what can be done about this.
I think I see what you mean.
For example, the sr driver uses its "device" member to pass information to the libata layer, if I understand things correctly, and the libata layer cannot go back to its struct scsi_cd, right?
First off, I agree with you that putting those PM fields into struct scsi_device is not the cleanest approach and it would be good to find some other place for them. However, I also don't think that struct device (or struct dev_pm_info embedded in it for that matter) is any better (those fields in there would make as little sense as they do in struct scsi_device).
Now, the question is where to store them and I think there are a couple of places worth considering. For instance, there's the void *driver_data field in struct acpi_device that I bet is unused for the ACPI devices associated with ATA ones and in principle it might be set by libata to point to a PM data structure (that would require some "platform" helper functions for the sr, sd etc. drivers to access that structure). There also is the subsys_data field in struct dev_pm_info that might be used to point to some libata-specific PM data (although the question is which struct dev_pm_info to use in that case, the sdev's one, or the sdev->gendev's one?).
Thanks,
Rafael
Quoted 8 lines · On Wednesday 19 September 2012 13:27:47 James Bottomley wrote:
Quoted 3 lines · Aaron Lu
Hi James,
May I know if this patchset will enter v3.7?
Sigh, well, I was hoping to persuade the PM people to sort this out first.
Quoted 6 lines
The first observation is that all this looks to be too specific. ZPO may be ACPI specific, but the property it abstracts: whether the particular device is powered off or not is generic and probably should be known at the generic PM level. Nothing actually really cares about how we power off the device until you get all the way down to the ACPI controller.
The SCSI layer however needs to know whether the cache is handled by the OS or in the device and under which circumstances a device can detect media change events.
Regards
Oliver
Signature · 10 lines
- - - SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg) Maxfeldstraße 5 90409 Nürnberg Germany - - - -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · James Bottomley
I think we could do this with a couple of flags sitting inside struct device itself: one for pm state and capabilities defined at a generic level and one for device specific pm state. The latter would be for things like the door lock information which is very specific to CDs (although not specific to SCSI CDs). Alternatively, even if we can't use these capabilities at the generic pm level, we still need an internal state set of flags because power state stuff traverses the stack and struct device is the only universal object in that stack.
FWIW the SATA Device Sleep support, which is currently only used (in a patch which is pending) automatically as an extension of the AHCI link power management, can also be triggered manually by a GPIO line; I've got a platform where it's done with an ACPI call. I suspect we'll see that kind of manual setup on a few embedded platforms too.
If we're working on hooking this up through the device layers, perhaps that's worth taking into consideration?
Signature · 2 lines
David Woodhouse Open Source Technology Centre [email protected] Intel Corporation
Quoted 17 lines · James Bottomley
Quoted 8 lines
I think we could do this with a couple of flags sitting inside struct device itself: one for pm state and capabilities defined at a generic level and one for device specific pm state. The latter would be for things like the door lock information which is very specific to CDs (although not specific to SCSI CDs). Alternatively, even if we can't use these capabilities at the generic pm level, we still need an internal state set of flags because power state stuff traverses the stack and struct device is the only universal object in that stack.
FWIW the SATA Device Sleep support, which is currently only used (in a patch which is pending) automatically as an extension of the AHCI link power management, can also be triggered manually by a GPIO line; I've got a platform where it's done with an ACPI call. I suspect we'll see that kind of manual setup on a few embedded platforms too.
Quoted 4 lines
If we're working on hooking this up through the device layers, perhaps that's worth taking into consideration?
--
Hi David,
For SATA Device sleep, what's the appropriate time to set the Device sleep, this seems also part of runtime PM?
Best regards!
Jack
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
[Adding more people and list back in]
Quoted 35 lines · Rafael J. Wysocki
Quoted 34 lines · Aaron Lu
Quoted 22 lines · Rafael J. Wysocki
Quoted 12 lines · Aaron Lu
Quoted 3 lines · Rafael J. Wysocki
Say the user has pressed the eject button. What does need to happen so that the tray is physically ejected?
The tray is ejected by the ODD itself, host does not have to do anything.
There is a
command(PREVENT_MEDIUM_REMOVAL)to lock the door so that when user presses the eject button, the tray will not be ejected. This command is usually sent when we have a disc inside and a user space program opened the underlying block device(e.g./dev/sr0) to read/write data.Quoted 8 lines
And host can also eject the tray by sending a
START_STOP_UNITcommand with param LoEj set to 1 and we have a function calledsr_tray_moveto do just this. And this is also what I've used to eject the tray after user wakes up the ODD, as when user presses the eject button when the ODD is in zero power state, it can't eject the tray as usual, so host software will need to do this, that's the reason I need to know such information:
When ODD is resumed, is it because user wakes it up?Quoted 1 line
But
START_STOP_UNITeventually causesata_scsi_start_stop_xlat()to beYou are following ata case, while the ODD is an atapi device :-) The translation function is
atapi_xlat, but that doesn't affect the idea here.Quoted 4 lines
executed, so I wonder if we really need to go up through the SCSI stack to send that command to the drive from there? It should be possible to issue STANDBY/READ VERIFY to the device directly from libata if an eject event is signaled through a GPE.
Quoted 6 lines
Quoted 4 lines
Yes, this is possible.
Though it doesn't feel very cool, since I have no idea if the ODD is a tray type or slot type in ATA layer and I'll blindly send this command to it then, not a problem maybe.It would be good to verify if that works for slot devices, if possible.
The ACPI GPE event is triggered when user inserts a disc into a slot type ODD, and if I send an eject command to it, the disc will be ejected, which is wrong.
I need to know the loading mechanism(tray type or slot type) of the ODD to decide if I should send this command.
Quoted 6 lines
Quoted 3 lines
And what do you think of moving the acpi notification code to sr?
http://marc.info/?l=linux-pm&m=134873904332704&w=4I don't think this is a good idea, quite frankly. sr seems to be a too generic place for that.
Does this mean sr can only have code that is useful to all devices it manages? i.e. If a piece of code enables a feature for a special kind of ODD(like the sata based ZPODD), it shouldn't be done in sr?
Quoted 2 lines
Ideally, the whole ZPODD handling should not be visible to the SCSI layer,
I can see 2 problems:
- Don't know its loading machanism so we have the problem above;
- Need to send command to find out if ODD is zero power ready somewhere in ata layer, this implies the device is doing IO after it is runtime suspended in scsi layer.
Quoted 2 lines
perhaps except the "
no_polling" flag disabling the polling that may be useful for other purposes in principle.
I hope so, let's hear what other people has to say.
Quoted 3 lines
I'm not sure if it's possible at this point, but if not we need to know very precisely why not.
There is nothing in theory stopping us from doing this in ata layer. For the loading mechanism, we can always send an ATAPI command to figure it out.
So gentlemen, I need your opinions on where this ZPODD code should live before I can continue this work, thanks.
-Aaron
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 6 lines · Aaron Lu
Quoted 2 lines
I don't think this is a good idea, quite frankly. sr seems to be a too generic place for that.
Does this mean sr can only have code that is useful to all devices it manages? i.e. If a piece of code enables a feature for a special kind of ODD(like the sata based ZPODD), it shouldn't be done in sr?
Drivers are allowed to have special features and quirks that apply only to some devices.
Quoted 6 lines
There is nothing in theory stopping us from doing this in ata layer. For the loading mechanism, we can always send an ATAPI command to figure it out.
So gentlemen, I need your opinions on where this ZPODD code should live before I can continue this work, thanks.
Can arbitrary SCSI devices be ZP, or does this notion apply only to ATAPI-based drives? That's the key question, and the answer determines where the ZP support belongs.
On the other hand, the sr driver certainly deserves to have some form of runtime PM support, even for devices that aren't ZP.
Alan Stern
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 11 lines · Alan Stern
Quoted 6 lines · Aaron Lu
Quoted 2 lines
I don't think this is a good idea, quite frankly. sr seems to be a too generic place for that.
Does this mean sr can only have code that is useful to all devices it manages? i.e. If a piece of code enables a feature for a special kind of ODD(like the sata based ZPODD), it shouldn't be done in sr?
Drivers are allowed to have special features and quirks that apply only to some devices.
I think SATA based zero power capable ODDs are the "some devices".
Quoted 11 lines
Quoted 7 lines
There is nothing in theory stopping us from doing this in ata layer. For the loading mechanism, we can always send an ATAPI command to figure it out.
So gentlemen, I need your opinions on where this ZPODD code should live before I can continue this work, thanks.
Can arbitrary SCSI devices be ZP, or does this notion apply only to ATAPI-based drives? That's the key question, and the answer determines where the ZP support belongs.
I don't know if arbitrary SCSI devices can be ZP or not, the SPC spec doesn't seem to define such a power state.
ZPODD is defined for sata based ATAPI ODD which supports device attention, but doesn't specify how the ODD is powered off and how the device attention pin notifies OS. On x86 systems, these are implemented by ACPI.
Though SCSI devices may not have a general notion of ZP, the fact that ZPODD are managed by sr driver is enough to make the decision that ZPODD code can live in sr?
Quoted 3 lines
On the other hand, the sr driver certainly deserves to have some form of runtime PM support, even for devices that aren't ZP.
Agree.
And the following codes need to find a home:
- Code used to handle ACPI wake notification(currently done in ATA, but causes the "annoying" need_eject flag in scsi_device);
- Code to check if the ODD is ready to be powered off per the ZPODD spec.
Thanks,
Aaron
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 30 lines · Aaron Lu
Quoted 11 lines · Alan Stern
Quoted 6 lines · Aaron Lu
Quoted 2 lines
I don't think this is a good idea, quite frankly. sr seems to be a too generic place for that.
Does this mean sr can only have code that is useful to all devices it manages? i.e. If a piece of code enables a feature for a special kind of ODD(like the sata based ZPODD), it shouldn't be done in sr?
Drivers are allowed to have special features and quirks that apply only to some devices.
I think SATA based zero power capable ODDs are the "some devices".
Quoted 11 lines
Quoted 7 lines
There is nothing in theory stopping us from doing this in ata layer. For the loading mechanism, we can always send an ATAPI command to figure it out.
So gentlemen, I need your opinions on where this ZPODD code should live before I can continue this work, thanks.
Can arbitrary SCSI devices be ZP, or does this notion apply only to ATAPI-based drives? That's the key question, and the answer determines where the ZP support belongs.
I don't know if arbitrary SCSI devices can be ZP or not, the SPC spec doesn't seem to define such a power state.
Quoted 8 lines
ZPODD is defined for sata based ATAPI ODD which supports device attention, but doesn't specify how the ODD is powered off and how the device attention pin notifies OS. On x86 systems, these are implemented by ACPI.
Though SCSI devices may not have a general notion of ZP, the fact that ZPODD are managed by sr driver is enough to make the decision that ZPODD code can live in sr?
Well, only a part of it is handled by sr, the high-level part so to speak. The low-level handling is done by the ATA layer. Now, since sr is the high-level part and is supposed to be generic, I don't think it's appropriate to make it care about some low-level things specific to ATA (because there is another layer of code supposed to handle those).
Quoted 8 lines
Quoted 2 lines
On the other hand, the sr driver certainly deserves to have some form of runtime PM support, even for devices that aren't ZP.
Agree.
And the following codes need to find a home:
- Code used to handle ACPI wakenotification(currently done in ATA, but causes the "annoying" need_eject flag in scsi_device);
And quite frankly I'd more and more convinced that this flag isn't really necessary.
What you really want to achieve is to eject the tray of a tray-type ODD if the eject is signaled through a GPE. I don't see anything for sr to do in that. Moreover, you probably would like to do that even if the drive is not powered down, right?
I wonder if this mechanism can be used for user space notification without polling regardless of whether or not the zero-power feature is used?
Quoted 2 lines
- Code to check if the ODD is ready to be powered off per the ZPODD spec.
If that can be done at the ATA level, I'd prefer it too.
Thanks,
Rafael
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 40 lines · Rafael J. Wysocki
Quoted 30 lines · Aaron Lu
Quoted 11 lines · Alan Stern
Quoted 6 lines · Aaron Lu
Quoted 2 lines
I don't think this is a good idea, quite frankly. sr seems to be a too generic place for that.
Does this mean sr can only have code that is useful to all devices it manages? i.e. If a piece of code enables a feature for a special kind of ODD(like the sata based ZPODD), it shouldn't be done in sr?
Drivers are allowed to have special features and quirks that apply only to some devices.
I think SATA based zero power capable ODDs are the "some devices".
Quoted 11 lines
Quoted 7 lines
There is nothing in theory stopping us from doing this in ata layer. For the loading mechanism, we can always send an ATAPI command to figure it out.
So gentlemen, I need your opinions on where this ZPODD code should live before I can continue this work, thanks.
Can arbitrary SCSI devices be ZP, or does this notion apply only to ATAPI-based drives? That's the key question, and the answer determines where the ZP support belongs.
I don't know if arbitrary SCSI devices can be ZP or not, the SPC spec doesn't seem to define such a power state.
Quoted 8 lines
ZPODD is defined for sata based ATAPI ODD which supports device attention, but doesn't specify how the ODD is powered off and how the device attention pin notifies OS. On x86 systems, these are implemented by ACPI.
Though SCSI devices may not have a general notion of ZP, the fact that ZPODD are managed by sr driver is enough to make the decision that ZPODD code can live in sr?
Quoted 5 lines
Well, only a part of it is handled by sr, the high-level part so to speak. The low-level handling is done by the ATA layer. Now, since sr is the high-level part and is supposed to be generic, I don't think it's appropriate to make it care about some low-level things specific to ATA (because there is another layer of code supposed to handle those).
Makes sense to me, but there is a problem if I want to block events checking for the disk, as I do not have a pointer to the gendisk in ATA layer.
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines
On the other hand, the sr driver certainly deserves to have some form of runtime PM support, even for devices that aren't ZP.
Agree.
And the following codes need to find a home:
- Code used to handle ACPI wakenotification(currently done in ATA, but causes the "annoying" need_eject flag in scsi_device);
Quoted 7 lines
And quite frankly I'd more and more convinced that this flag isn't really necessary.
What you really want to achieve is to eject the tray of a tray-type ODD if the eject is signaled through a GPE. I don't see anything for sr to do in that. Moreover, you probably would like to do that even if the drive is not powered down, right?
The tray will be ejected by the ODD itself when it has power, I do not need to do that. Moreover, I don't think I need enable the GPE bit when it has power.
Quoted 4 lines
I wonder if this mechanism can be used for user space notification without polling regardless of whether or not the zero-power feature is used?
This may be a reason the GPE should be always enabled no matter if power is removed or not. But I have concerns that this mechanism is designed to acheive this, as explained in another mail thread:
http://marc.info/?l=linux-pm&m=134882049212936&w=2
Copied here:
The SATA spec says the device attention pin shall assert when:
- For tray type ODD, its front panel button is released;
- For slot type ODD, media is inserted.
I've a slot type ODD which has a eject button. The notification will be sent when a disc is inserted, but not when the eject button is pressed, and this doesn't violate the spec.
But if we disable the poll for disc changes, we will lose an event when the disc is ejected by the eject button(the device attention pin shall not trigger this time). I suppose this is a problem?
I think the device attention scheme is not designed to do this job, while SATA asynchronous notification is.
Thanks,
Aaron
Quoted 12 lines
Quoted 3 lines
- Code to check if the ODD is ready to be powered off per the ZPODD spec.
If that can be done at the ATA level, I'd prefer it too.
Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 7 lines · Aaron Lu
Makes sense to me, but there is a problem if I want to block events checking for the disk, as I do not have a pointer to the gendisk in ATA layer.
The tray will be ejected by the ODD itself when it has power, I do not need to do that. Moreover, I don't think I need enable the GPE bit when it has power.
It sounds like you need to add only two things to the sr layer: An interface to enable/disable event checking and an interface to request an eject. (And perhaps ejects can be carried out entirely within the ATAPI layer, with no need to involve sr.)
Alan Stern
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 6 lines · Alan Stern
Quoted 3 lines · Aaron Lu
Makes sense to me, but there is a problem if I want to block events checking for the disk, as I do not have a pointer to the gendisk in ATA layer.
Quoted 8 lines
Quoted 3 lines
The tray will be ejected by the ODD itself when it has power, I do not need to do that. Moreover, I don't think I need enable the GPE bit when it has power.
It sounds like you need to add only two things to the sr layer: An interface to enable/disable event checking and an interface to request an eject. (And perhaps ejects can be carried out entirely within the ATAPI layer, with no need to involve sr.)
Thanks for the suggestion, I'll try to do this.
-Aaron
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
In reply to Alan SternQuoted 5 lines · Alan Stern
Quoted 3 lines · Aaron Lu
Makes sense to me, but there is a problem if I want to block events checking for the disk, as I do not have a pointer to the gendisk in ATA layer.
You may discover the gendisk by going the ATA -> SCSI -> block route.
Quoted 8 lines
Quoted 3 lines
The tray will be ejected by the ODD itself when it has power, I do not need to do that. Moreover, I don't think I need enable the GPE bit when it has power.
It sounds like you need to add only two things to the sr layer: An interface to enable/disable event checking and an interface to request an eject. (And perhaps ejects can be carried out entirely within the ATAPI layer, with no need to involve sr.)
Sounds reasonable.
Jeff
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
In reply to Rafael J. WysockiQuoted 58 lines · Rafael J. Wysocki
Quoted 30 lines · Aaron Lu
Quoted 11 lines · Alan Stern
Quoted 6 lines · Aaron Lu
Quoted 2 lines
I don't think this is a good idea, quite frankly. sr seems to be a too generic place for that.
Does this mean sr can only have code that is useful to all devices it manages? i.e. If a piece of code enables a feature for a special kind of ODD(like the sata based ZPODD), it shouldn't be done in sr?
Drivers are allowed to have special features and quirks that apply only to some devices.
I think SATA based zero power capable ODDs are the "some devices".
Quoted 11 lines
Quoted 7 lines
There is nothing in theory stopping us from doing this in ata layer. For the loading mechanism, we can always send an ATAPI command to figure it out.
So gentlemen, I need your opinions on where this ZPODD code should live before I can continue this work, thanks.
Can arbitrary SCSI devices be ZP, or does this notion apply only to ATAPI-based drives? That's the key question, and the answer determines where the ZP support belongs.
I don't know if arbitrary SCSI devices can be ZP or not, the SPC spec doesn't seem to define such a power state.
Quoted 8 lines
ZPODD is defined for sata based ATAPI ODD which supports device attention, but doesn't specify how the ODD is powered off and how the device attention pin notifies OS. On x86 systems, these are implemented by ACPI.
Though SCSI devices may not have a general notion of ZP, the fact that ZPODD are managed by sr driver is enough to make the decision that ZPODD code can live in sr?
Well, only a part of it is handled by sr, the high-level part so to speak. The low-level handling is done by the ATA layer. Now, since sr is the high-level part and is supposed to be generic, I don't think it's appropriate to make it care about some low-level things specific to ATA (because there is another layer of code supposed to handle those).
Quoted 8 lines
Quoted 2 lines
On the other hand, the sr driver certainly deserves to have some form of runtime PM support, even for devices that aren't ZP.
Agree.
And the following codes need to find a home:
- Code used to handle ACPI wakenotification(currently done in ATA, but causes the "annoying" need_eject flag in scsi_device);And quite frankly I'd more and more convinced that this flag isn't really necessary.
Quoted 8 lines
What you really want to achieve is to eject the tray of a tray-type ODD if the eject is signaled through a GPE. I don't see anything for sr to do in that. Moreover, you probably would like to do that even if the drive is not powered down, right?
I wonder if this mechanism can be used for user space notification without polling regardless of whether or not the zero-power feature is used?
Fair questions, and I think this is finally getting to the heart of the matter/solution.
Quoted 4 lines
Quoted 2 lines
- Code to check if the ODD is ready to be powered off per the ZPODD spec.
If that can be done at the ATA level, I'd prefer it too.
Does the ready-to-poweroff check involve SCSI/MMC command set commands?
If no, it probably belongs in libata.
If yes, it probably belongs in sr.
Jeff
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
In reply to Alan SternQuoted 16 lines · Alan Stern
Quoted 6 lines · Aaron Lu
Quoted 2 lines
I don't think this is a good idea, quite frankly. sr seems to be a too generic place for that.
Does this mean sr can only have code that is useful to all devices it manages? i.e. If a piece of code enables a feature for a special kind of ODD(like the sata based ZPODD), it shouldn't be done in sr?
Drivers are allowed to have special features and quirks that apply only to some devices.
Quoted 4 lines
There is nothing in theory stopping us from doing this in ata layer. For the loading mechanism, we can always send an ATAPI command to figure it out.
Quoted 6 lines
Quoted 2 lines
So gentlemen, I need your opinions on where this ZPODD code should live before I can continue this work, thanks.
Can arbitrary SCSI devices be ZP, or does this notion apply only to ATAPI-based drives? That's the key question, and the answer determines where the ZP support belongs.
I agree. That said for now I'm not aware of any other ZP devices. It also is unclear whether or not their requirements would be the same for the ZPODD devices.
Quoted 2 lines
On the other hand, the sr driver certainly deserves to have some form of runtime PM support, even for devices that aren't ZP.
Yes, it does, but it is unclear to me at this point what it should do in its callbacks.
Thanks,
Rafael
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Alan Stern
Can arbitrary SCSI devices be ZP, or does this notion apply only to ATAPI-based drives? That's the key question, and the answer determines where the ZP support belongs.
I agree. That said for now I'm not aware of any other ZP devices. It also is unclear whether or not their requirements would be the same for the ZPODD devices.
Not quite.
The key question is whether or not this operates at the SCSI command set level. ATAPI is simply SCSI MMC command set tunnelling.
The ATA-specific bits that belong in libata include everything below the SCSI command set: bus details, delivering the command to the device, returning the command response, etc.
sr handles the SCSI command set details. SATA optical devices are aligned with the SCSI MMC command set, which periodically synchronizes with USB and ATAPI industry efforts.
There are ugly hacks around the edges, where sometimes ATA or USB subsystems may tweak the request or response in passing, but that is the general model: it belongs in libata UNLESS the operation is occurring wholly at the SCSI command set level.
Because USB and ATA chose to use the SCSI command set, it is sadly inevitable that there might be a few details -- hopefully glossed over with layer-hopping hooks and flags -- within 'sr' that are bus-specific.
The simple fact of "only ZPODD devices out there are ATA" is not the decision-maker for where the code should live. It is more a question where ZPODD belongs in the device/command set model currently employed.
Jeff
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 3 lines · Jeff Garzik
The simple fact of "only ZPODD devices out there are ATA" is not the decision-maker for where the code should live. It is more a question where ZPODD belongs in the device/command set model currently employed.
I don't really accept this argument. It's a little like saying: The tty layer uses ioctl commands to control RS232 line settings; therefore RS232 settings should be handled in the VFS layer as part of the ioctl core.
Regardless, according to Aaron the ZP power-off stuff is currently implemented only in ACPI, tied more closely to the ATA layer than the SCSI layer (though not part of either). It is not part of the SCSI spec in any form. Now it's true that determining whether a device is in the right state for power to be removed involves sending a TEST UNIT READY command, which is of course a SCSI command. This seems to be incidental to the overall scheme, however.
Alan Stern
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 10 lines · Alan Stern
Quoted 3 lines · Jeff Garzik
The simple fact of "only ZPODD devices out there are ATA" is not the decision-maker for where the code should live. It is more a question where ZPODD belongs in the device/command set model currently employed.
I don't really accept this argument. It's a little like saying: The tty layer uses ioctl commands to control RS232 line settings; therefore RS232 settings should be handled in the VFS layer as part of the ioctl core.
Hardly -- sr is an optical device driver, much more aligned.
And libata is probably at least 50% of the entire sr userbase, if not much much more.
Jeff
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
In reply to Alan SternQuoted 11 lines · Alan Stern
Quoted 3 lines · Jeff Garzik
The simple fact of "only ZPODD devices out there are ATA" is not the decision-maker for where the code should live. It is more a question where ZPODD belongs in the device/command set model currently employed.
I don't really accept this argument. It's a little like saying: The tty layer uses ioctl commands to control RS232 line settings; therefore RS232 settings should be handled in the VFS layer as part of the ioctl core.
Quoted 4 lines
Regardless, according to Aaron the ZP power-off stuff is currently implemented only in ACPI, tied more closely to the ATA layer than the SCSI layer (though not part of either). It is not part of the SCSI spec in any form.
The mechanism of SATA ODD zero power model is specified in Mount Fuji spec v8 section 15 describing what the ODD needs support, how to sense if the ODD is ready to be powered off and on power up what needs to be done, etc. And the actual power off and wakeup is implemented in ACPI and SATA.
Quoted 4 lines
Now it's true that determining whether a device is
in the right state for power to be removed involves sending a TEST UNIT READY command, which is of course a SCSI command. This seems to be incidental to the overall scheme, however.
I need to add that, there are 2 schemes to sense if the ODD is ready to be powered off:
1 the one I used here, by checking if the door is closed and no media
inside with test_unit_ready;
2 some ZP capable ODDs can report zero power ready(ZPReady) event to
host when queried, eliminating the need of host checking the conditions.
Thanks,
Aaron
James Bottomley
maintainerRe: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 28 lines · Aaron Lu
Quoted 11 lines · Alan Stern
Quoted 3 lines · Jeff Garzik
The simple fact of "only ZPODD devices out there are ATA" is not the decision-maker for where the code should live. It is more a question where ZPODD belongs in the device/command set model currently employed.
I don't really accept this argument. It's a little like saying: The tty layer uses ioctl commands to control RS232 line settings; therefore RS232 settings should be handled in the VFS layer as part of the ioctl core.
Quoted 4 lines
Regardless, according to Aaron the ZP power-off stuff is currently implemented only in ACPI, tied more closely to the ATA layer than the SCSI layer (though not part of either). It is not part of the SCSI spec in any form.
The mechanism of SATA ODD zero power model is specified in Mount Fuji spec v8 section 15 describing what the ODD needs support, how to sense if the ODD is ready to be powered off and on power up what needs to be done, etc. And the actual power off and wakeup is implemented in ACPI and SATA.
Quoted 4 lines
Now it's true that determining whether a device is
in the right state for power to be removed involves sending a TEST UNIT READY command, which is of course a SCSI command. This seems to be incidental to the overall scheme, however.
Quoted 6 lines
I need to add that, there are 2 schemes to sense if the ODD is ready to be powered off:
1 the one I used here, by checking if the door is closed and no media
inside withtest_unit_ready;
2 some ZP capable ODDs can report zero power ready(ZPReady) event to
host when queried, eliminating the need of host checking the conditions.
The way I read the standard is that ZP ODD is a hack to try and get to off and ZPready is the same hack but integrated into the standardised power management states (and hence available to normal power saving). The standard even implies ZP ODD is a less desirable hack by recommending the use of ZPready.
The ZPready method, being an extension of the usual SCSI power management model, is pretty much what we support today (especially as the whole thing is timer driven from values in the mode page and happens pretty much invisibly to us).
Since the object is to make this as painless as possible, why don't we just implement ZPODD the way the spec recommends? i.e. emulate the timers at an incredibly low level and intercept and emulate the non-disk commands listed in table 321. I bet, in Linux, since we moved basically to GET_EVENT_STATUS_NOTIFICATION, that's the only one that actually needs an emulation.
The state model seems to work if you snoop the polled media event, so you wait for no media, then set your internal timer, stop it if we get a media change and power off the device after interval expiry. Thereafter you emulate media event with no change keeping the device powered off. If a disc gets inserted or the eject button is pressed, you see that via the SATA PHY events (so wake the drive) and if the Upper Layer sends an unexpected command, you also power on the drive.
That way all of this should be nicely containable within SATA/ACPI.
James
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 29 lines · James Bottomley
Quoted 28 lines · Aaron Lu
Quoted 11 lines · Alan Stern
Quoted 3 lines · Jeff Garzik
The simple fact of "only ZPODD devices out there are ATA" is not the decision-maker for where the code should live. It is more a question where ZPODD belongs in the device/command set model currently employed.
I don't really accept this argument. It's a little like saying: The tty layer uses ioctl commands to control RS232 line settings; therefore RS232 settings should be handled in the VFS layer as part of the ioctl core.
Quoted 4 lines
Regardless, according to Aaron the ZP power-off stuff is currently implemented only in ACPI, tied more closely to the ATA layer than the SCSI layer (though not part of either). It is not part of the SCSI spec in any form.
The mechanism of SATA ODD zero power model is specified in Mount Fuji spec v8 section 15 describing what the ODD needs support, how to sense if the ODD is ready to be powered off and on power up what needs to be done, etc. And the actual power off and wakeup is implemented in ACPI and SATA.
Quoted 4 lines
Now it's true that determining whether a device is
in the right state for power to be removed involves sending a TEST UNIT READY command, which is of course a SCSI command. This seems to be incidental to the overall scheme, however.
Quoted 8 lines
Quoted 6 lines
I need to add that, there are 2 schemes to sense if the ODD is ready to be powered off:
1 the one I used here, by checking if the door is closed and no media
inside withtest_unit_ready;
2 some ZP capable ODDs can report zero power ready(ZPReady) event to
host when queried, eliminating the need of host checking the conditions.The way I read the standard is that ZP ODD is a hack to try and get to
Thanks for your time.
Quoted 4 lines
off and ZPready is the same hack but integrated into the standardised power management states (and hence available to normal power saving). The standard even implies ZP ODD is a less desirable hack by recommending the use of ZPready.
There are ZPODDs not supporting ZPready and I want to support them so the sense scheme 1 is used.
Quoted 21 lines
The ZPready method, being an extension of the usual SCSI power management model, is pretty much what we support today (especially as the whole thing is timer driven from values in the mode page and happens pretty much invisibly to us).
Since the object is to make this as painless as possible, why don't we just implement ZPODD the way the spec recommends? i.e. emulate the timers at an incredibly low level and intercept and emulate the non-disk commands listed in table 321. I bet, in Linux, since we moved basically to
GET_EVENT_STATUS_NOTIFICATION, that's the only one that actually needs an emulation.The state model seems to work if you snoop the polled media event, so you wait for no media, then set your internal timer, stop it if we get a media change and power off the device after interval expiry. Thereafter you emulate media event with no change keeping the device powered off. If a disc gets inserted or the eject button is pressed, you see that via the SATA PHY events (so wake the drive) and if the Upper Layer sends an unexpected command, you also power on the drive.
Quoted 1 line
That way all of this should be nicely containable within SATA/ACPI.
Thanks for the suggestion, it is really something that I've never thought of :-)
But I was hoping to use the runtime pm framework to support ZPODD. With your suggestion, I don't know how to do this. Maybe I can set the scsi device representing the ODD to runtime suspended once I decided to power it off and resume it when I power it up. But there is a problem, that I'm setting a scsi device's runtime status in ATA layer, this doesn't feel right. And someday, someone may want to add runtime pm support for sr and the runtime status of the scsi device will be messed.
The reason I want to use runtime PM is, when the scsi device is runtime suspended, its ancestor devices will have a chance to enter runtime suspend state, e.g. the sata controller.
Thanks,
Aaron
James Bottomley
maintainerRe: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 41 lines · Aaron Lu
Quoted 29 lines · James Bottomley
Quoted 28 lines · Aaron Lu
Quoted 11 lines · Alan Stern
Quoted 3 lines · Jeff Garzik
The simple fact of "only ZPODD devices out there are ATA" is not the decision-maker for where the code should live. It is more a question where ZPODD belongs in the device/command set model currently employed.
I don't really accept this argument. It's a little like saying: The tty layer uses ioctl commands to control RS232 line settings; therefore RS232 settings should be handled in the VFS layer as part of the ioctl core.
Quoted 4 lines
Regardless, according to Aaron the ZP power-off stuff is currently implemented only in ACPI, tied more closely to the ATA layer than the SCSI layer (though not part of either). It is not part of the SCSI spec in any form.
The mechanism of SATA ODD zero power model is specified in Mount Fuji spec v8 section 15 describing what the ODD needs support, how to sense if the ODD is ready to be powered off and on power up what needs to be done, etc. And the actual power off and wakeup is implemented in ACPI and SATA.
Quoted 4 lines
Now it's true that determining whether a device is
in the right state for power to be removed involves sending a TEST UNIT READY command, which is of course a SCSI command. This seems to be incidental to the overall scheme, however.Quoted 8 lines
Quoted 6 lines
I need to add that, there are 2 schemes to sense if the ODD is ready to be powered off:
1 the one I used here, by checking if the door is closed and no media
inside withtest_unit_ready;
2 some ZP capable ODDs can report zero power ready(ZPReady) event to
host when queried, eliminating the need of host checking the conditions.The way I read the standard is that ZP ODD is a hack to try and get to
Thanks for your time.
Quoted 7 lines
Quoted 4 lines
off and ZPready is the same hack but integrated into the standardised power management states (and hence available to normal power saving). The standard even implies ZP ODD is a less desirable hack by recommending the use of ZPready.
There are ZPODDs not supporting ZPready and I want to support them so the sense scheme 1 is used.
Right, but what I'm saying is that ZPODD looks like a hack until ZPready is fairly universally implemented. ZPready makes far more sense since it's integrated into the usual SCSI power management, so ZPODD should have a limited shelf life.
Quoted 21 lines
Quoted 21 lines
The ZPready method, being an extension of the usual SCSI power management model, is pretty much what we support today (especially as the whole thing is timer driven from values in the mode page and happens pretty much invisibly to us).
Since the object is to make this as painless as possible, why don't we just implement ZPODD the way the spec recommends? i.e. emulate the timers at an incredibly low level and intercept and emulate the non-disk commands listed in table 321. I bet, in Linux, since we moved basically to
GET_EVENT_STATUS_NOTIFICATION, that's the only one that actually needs an emulation.The state model seems to work if you snoop the polled media event, so you wait for no media, then set your internal timer, stop it if we get a media change and power off the device after interval expiry. Thereafter you emulate media event with no change keeping the device powered off. If a disc gets inserted or the eject button is pressed, you see that via the SATA PHY events (so wake the drive) and if the Upper Layer sends an unexpected command, you also power on the drive.
Quoted 6 lines
Quoted 1 line
That way all of this should be nicely containable within SATA/ACPI.
Thanks for the suggestion, it is really something that I've never thought of :-)
But I was hoping to use the runtime pm framework to support ZPODD.
Well, the runtime pm framework doesn't support the current SCSI power management states within the drive, that's why it makes sense to treat what is essentially a hack to them in the same manner.
Quoted 6 lines
With your suggestion, I don't know how to do this. Maybe I can set the scsi device representing the ODD to runtime suspended once I decided to power it off and resume it when I power it up. But there is a problem, that I'm setting a scsi device's runtime status in ATA layer, this doesn't feel right. And someday, someone may want to add runtime pm support for sr and the runtime status of the scsi device will be messed.
No, if we ever actually supported the standard power management states, you'd simply be intercepting the SCSI commands that forced the state transitions (START_STOP_UNIT) and act when yours was forced.
Quoted 3 lines
The reason I want to use runtime PM is, when the scsi device is runtime suspended, its ancestor devices will have a chance to enter runtime suspend state, e.g. the sata controller.
But this, I think, is why it looks odd. You're implementing a lower state than standard SCSI power model which the current runtime pm doesn't support anyway.
There is, of course, the question of whether we *should* force the SCSI transitions in runtime pm ... but that's orthogonal to this discussion.
James
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 47 lines · James Bottomley
Quoted 46 lines · Aaron Lu
Quoted 29 lines · James Bottomley
Quoted 28 lines · Aaron Lu
Quoted 11 lines · Alan Stern
Quoted 3 lines · Jeff Garzik
The simple fact of "only ZPODD devices out there are ATA" is not the decision-maker for where the code should live. It is more a question where ZPODD belongs in the device/command set model currently employed.
I don't really accept this argument. It's a little like saying: The tty layer uses ioctl commands to control RS232 line settings; therefore RS232 settings should be handled in the VFS layer as part of the ioctl core.
Quoted 4 lines
Regardless, according to Aaron the ZP power-off stuff is currently implemented only in ACPI, tied more closely to the ATA layer than the SCSI layer (though not part of either). It is not part of the SCSI spec in any form.
The mechanism of SATA ODD zero power model is specified in Mount Fuji spec v8 section 15 describing what the ODD needs support, how to sense if the ODD is ready to be powered off and on power up what needs to be done, etc. And the actual power off and wakeup is implemented in ACPI and SATA.
Quoted 4 lines
Now it's true that determining whether a device is
in the right state for power to be removed involves sending a TEST UNIT READY command, which is of course a SCSI command. This seems to be incidental to the overall scheme, however.Quoted 8 lines
Quoted 6 lines
I need to add that, there are 2 schemes to sense if the ODD is ready to be powered off:
1 the one I used here, by checking if the door is closed and no media
inside withtest_unit_ready;
2 some ZP capable ODDs can report zero power ready(ZPReady) event to
host when queried, eliminating the need of host checking the conditions.The way I read the standard is that ZP ODD is a hack to try and get to
Thanks for your time.
Quoted 4 lines
off and ZPready is the same hack but integrated into the standardised power management states (and hence available to normal power saving). The standard even implies ZP ODD is a less desirable hack by recommending the use of ZPready.
Quoted 7 lines
Quoted 2 lines
There are ZPODDs not supporting ZPready and I want to support them so the sense scheme 1 is used.
Right, but what I'm saying is that ZPODD looks like a hack until ZPready is fairly universally implemented. ZPready makes far more sense since it's integrated into the usual SCSI power management, so ZPODD should have a limited shelf life.
I hope so :-)
Quoted 24 lines
Quoted 24 lines
Quoted 23 lines
The ZPready method, being an extension of the usual SCSI power management model, is pretty much what we support today (especially as the whole thing is timer driven from values in the mode page and happens pretty much invisibly to us).
Since the object is to make this as painless as possible, why don't we just implement ZPODD the way the spec recommends? i.e. emulate the timers at an incredibly low level and intercept and emulate the non-disk commands listed in table 321. I bet, in Linux, since we moved basically to
GET_EVENT_STATUS_NOTIFICATION, that's the only one that actually needs an emulation.The state model seems to work if you snoop the polled media event, so you wait for no media, then set your internal timer, stop it if we get a media change and power off the device after interval expiry. Thereafter you emulate media event with no change keeping the device powered off. If a disc gets inserted or the eject button is pressed, you see that via the SATA PHY events (so wake the drive) and if the Upper Layer sends an unexpected command, you also power on the drive.
That way all of this should be nicely containable within SATA/ACPI.
Quoted 8 lines
Quoted 4 lines
Thanks for the suggestion, it is really something that I've never thought of :-)
But I was hoping to use the runtime pm framework to support ZPODD.
Well, the runtime pm framework doesn't support the current SCSI power management states within the drive, that's why it makes sense to treat what is essentially a hack to them in the same manner.
OK, I agree, and it amused me a little bit :-)
And here are some thoughts on runtime pm regarding SCSI power state in ODD's case.
The Mount Fuji spec has words like this in section 16.1.1:
When no media is mounted, the logical unit should enter Standby state. So we do not need to do anything for no media case if Standby is acceptable.
And when there is media inside, the ODD's power state will either be controlled by its internal timer or by host's command.
So for runtime pm code to participate, the only place to do some work is when there is media inside and we decide when the ODD is not in use and place it into Standby and when the ODD is in use, we place it into Active. But in this case, it seems better we let the ODD handle this power state transition by itself by programming its internal timer.
So there doesn't seem to be anything related to SCSI power state that runtime pm code needs to do for media inside case either.
The runtime pm support for sr may still be desired in that we can give the pm core a hint that this device is now not in use and its ancestor devices can be runtime suspended now(as already suggested by some people several times), but no need to touch the SCSI power state of the device.
Following this thought, I can see why you people are suggesting me to implement ZPODD in SATA. I think we can totally forget setting power state in sr's runtime code. The runtime pm code for sr should just serve as a hint to pm core, and the actual power state should be either handled by the device itself(for the standard power state case using internal time) or by the underlying layer(for the ZP case).
Thanks,
Aaron
Quoted 26 lines
Quoted 7 lines
With your suggestion, I don't know how to do this. Maybe I can set the scsi device representing the ODD to runtime suspended once I decided to power it off and resume it when I power it up. But there is a problem, that I'm setting a scsi device's runtime status in ATA layer, this doesn't feel right. And someday, someone may want to add runtime pm support for sr and the runtime status of the scsi device will be messed.
No, if we ever actually supported the standard power management states, you'd simply be intercepting the SCSI commands that forced the state transitions (
START_STOP_UNIT) and act when yours was forced.Quoted 3 lines
The reason I want to use runtime PM is, when the scsi device is runtime suspended, its ancestor devices will have a chance to enter runtime suspend state, e.g. the sata controller.
But this, I think, is why it looks odd. You're implementing a lower state than standard SCSI power model which the current runtime pm doesn't support anyway.
There is, of course, the question of whether we *should* force the SCSI transitions in runtime pm ... but that's orthogonal to this discussion.
James
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
In reply to Aaron LuQuoted 70 lines · On Tuesday 09 of October 2012 15:20:39 Aaron Lu wrote:
Quoted 29 lines · James Bottomley
Quoted 28 lines · Aaron Lu
Quoted 11 lines · Alan Stern
Quoted 3 lines · Jeff Garzik
The simple fact of "only ZPODD devices out there are ATA" is not the decision-maker for where the code should live. It is more a question where ZPODD belongs in the device/command set model currently employed.
I don't really accept this argument. It's a little like saying: The tty layer uses ioctl commands to control RS232 line settings; therefore RS232 settings should be handled in the VFS layer as part of the ioctl core.
Quoted 4 lines
Regardless, according to Aaron the ZP power-off stuff is currently implemented only in ACPI, tied more closely to the ATA layer than the SCSI layer (though not part of either). It is not part of the SCSI spec in any form.
The mechanism of SATA ODD zero power model is specified in Mount Fuji spec v8 section 15 describing what the ODD needs support, how to sense if the ODD is ready to be powered off and on power up what needs to be done, etc. And the actual power off and wakeup is implemented in ACPI and SATA.
Quoted 4 lines
Now it's true that determining whether a device is
in the right state for power to be removed involves sending a TEST UNIT READY command, which is of course a SCSI command. This seems to be incidental to the overall scheme, however.Quoted 8 lines
Quoted 6 lines
I need to add that, there are 2 schemes to sense if the ODD is ready to be powered off:
1 the one I used here, by checking if the door is closed and no media
inside withtest_unit_ready;
2 some ZP capable ODDs can report zero power ready(ZPReady) event to
host when queried, eliminating the need of host checking the conditions.The way I read the standard is that ZP ODD is a hack to try and get to
Thanks for your time.
Quoted 4 lines
off and ZPready is the same hack but integrated into the standardised power management states (and hence available to normal power saving). The standard even implies ZP ODD is a less desirable hack by recommending the use of ZPready.
There are ZPODDs not supporting ZPready and I want to support them so the sense scheme 1 is used.
Quoted 21 lines
The ZPready method, being an extension of the usual SCSI power management model, is pretty much what we support today (especially as the whole thing is timer driven from values in the mode page and happens pretty much invisibly to us).
Since the object is to make this as painless as possible, why don't we just implement ZPODD the way the spec recommends? i.e. emulate the timers at an incredibly low level and intercept and emulate the non-disk commands listed in table 321. I bet, in Linux, since we moved basically to
GET_EVENT_STATUS_NOTIFICATION, that's the only one that actually needs an emulation.The state model seems to work if you snoop the polled media event, so you wait for no media, then set your internal timer, stop it if we get a media change and power off the device after interval expiry. Thereafter you emulate media event with no change keeping the device powered off. If a disc gets inserted or the eject button is pressed, you see that via the SATA PHY events (so wake the drive) and if the Upper Layer sends an unexpected command, you also power on the drive.
Quoted 4 lines
Quoted 1 line
That way all of this should be nicely containable within SATA/ACPI.
Thanks for the suggestion, it is really something that I've never thought of :-)
Well, that's what I wanted to say previously, but James expressed it much better than I could. ;-)
Quoted 11 lines
But I was hoping to use the runtime pm framework to support ZPODD. With your suggestion, I don't know how to do this. Maybe I can set the scsi device representing the ODD to runtime suspended once I decided to power it off and resume it when I power it up. But there is a problem, that I'm setting a scsi device's runtime status in ATA layer, this doesn't feel right. And someday, someone may want to add runtime pm support for sr and the runtime status of the scsi device will be messed.
The reason I want to use runtime PM is, when the scsi device is runtime suspended, its ancestor devices will have a chance to enter runtime suspend state, e.g. the sata controller.
You can add runtime PM support for sr that won't do anything hardware-specific and in addition to that you can do pm_runtime_get_sync() on the parent directly from the ATA layer when you know it is needed and pm_runtime_put() when you know it is safe for it to go to a low-power state.
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
In reply to Aaron LuQuoted 56 lines · Aaron Lu
[Adding more people and list back in]
Quoted 35 lines · Rafael J. Wysocki
Quoted 34 lines · Aaron Lu
Quoted 22 lines · Rafael J. Wysocki
Quoted 12 lines · Aaron Lu
Quoted 3 lines · Rafael J. Wysocki
Say the user has pressed the eject button. What does need to happen so that the tray is physically ejected?
The tray is ejected by the ODD itself, host does not have to do anything.
There is a
command(PREVENT_MEDIUM_REMOVAL)to lock the door so that when user presses the eject button, the tray will not be ejected. This command is usually sent when we have a disc inside and a user space program opened the underlying block device(e.g./dev/sr0) to read/write data.Quoted 8 lines
And host can also eject the tray by sending a
START_STOP_UNITcommand with param LoEj set to 1 and we have a function calledsr_tray_moveto do just this. And this is also what I've used to eject the tray after user wakes up the ODD, as when user presses the eject button when the ODD is in zero power state, it can't eject the tray as usual, so host software will need to do this, that's the reason I need to know such information:
When ODD is resumed, is it because user wakes it up?Quoted 1 line
But
START_STOP_UNITeventually causesata_scsi_start_stop_xlat()to beYou are following ata case, while the ODD is an atapi device :-) The translation function is
atapi_xlat, but that doesn't affect the idea here.Quoted 4 lines
executed, so I wonder if we really need to go up through the SCSI stack to send that command to the drive from there? It should be possible to issue STANDBY/READ VERIFY to the device directly from libata if an eject event is signaled through a GPE.
Quoted 6 lines
Quoted 4 lines
Yes, this is possible.
Though it doesn't feel very cool, since I have no idea if the ODD is a tray type or slot type in ATA layer and I'll blindly send this command to it then, not a problem maybe.It would be good to verify if that works for slot devices, if possible.
The ACPI GPE event is triggered when user inserts a disc into a slot type ODD, and if I send an eject command to it, the disc will be ejected, which is wrong.
I need to know the loading mechanism(tray type or slot type) of the ODD to decide if I should send this command.
Quoted 4 lines
Quoted 3 lines
And what do you think of moving the acpi notification code to sr?
http://marc.info/?l=linux-pm&m=134873904332704&w=4
Quoted 6 lines
Quoted 2 lines
I don't think this is a good idea, quite frankly. sr seems to be a too generic place for that.
Does this mean sr can only have code that is useful to all devices it manages? i.e. If a piece of code enables a feature for a special kind of ODD(like the sata based ZPODD), it shouldn't be done in sr?
If the feature is specific to one special kind of ODD only, then I don't think sr is the right place to add support for it.
Quoted 4 lines
Quoted 1 line
Ideally, the whole ZPODD handling should not be visible to the SCSI layer,
I can see 2 problems:
- Don't know its loading machanism so we have the problem above;
Does using the need_eject flag address this problem somehow?
Quoted 3 lines
- Need to send command to find out if ODD is zero power ready somewhere in ata layer, this implies the device is doing IO after it is runtime suspended in scsi layer.
There's nothing wrong with accessig suspended devices as long as we know that they will respond. :-)
Quoted 9 lines
Quoted 2 lines
perhaps except the "
no_polling" flag disabling the polling that may be useful for other purposes in principle.I hope so, let's hear what other people has to say.
Quoted 3 lines
I'm not sure if it's possible at this point, but if not we need to know very precisely why not.
Quoted 6 lines
There is nothing in theory stopping us from doing this in ata layer. For the loading mechanism, we can always send an ATAPI command to figure it out.
So gentlemen, I need your opinions on where this ZPODD code should live before I can continue this work, thanks.
I would _try_ to add it at the ATA level.
Thanks,
Rafael
Re: [PATCH v7 2/6] scsi: sr: support runtime pm
Quoted 67 lines · Rafael J. Wysocki
Quoted 56 lines · Aaron Lu
[Adding more people and list back in]
Quoted 35 lines · Rafael J. Wysocki
Quoted 34 lines · Aaron Lu
Quoted 22 lines · Rafael J. Wysocki
Quoted 12 lines · Aaron Lu
Quoted 3 lines · Rafael J. Wysocki
Say the user has pressed the eject button. What does need to happen so that the tray is physically ejected?
The tray is ejected by the ODD itself, host does not have to do anything.
There is a
command(PREVENT_MEDIUM_REMOVAL)to lock the door so that when user presses the eject button, the tray will not be ejected. This command is usually sent when we have a disc inside and a user space program opened the underlying block device(e.g./dev/sr0) to read/write data.Quoted 8 lines
And host can also eject the tray by sending a
START_STOP_UNITcommand with param LoEj set to 1 and we have a function calledsr_tray_moveto do just this. And this is also what I've used to eject the tray after user wakes up the ODD, as when user presses the eject button when the ODD is in zero power state, it can't eject the tray as usual, so host software will need to do this, that's the reason I need to know such information:
When ODD is resumed, is it because user wakes it up?Quoted 1 line
But
START_STOP_UNITeventually causesata_scsi_start_stop_xlat()to beYou are following ata case, while the ODD is an atapi device :-) The translation function is
atapi_xlat, but that doesn't affect the idea here.Quoted 4 lines
executed, so I wonder if we really need to go up through the SCSI stack to send that command to the drive from there? It should be possible to issue STANDBY/READ VERIFY to the device directly from libata if an eject event is signaled through a GPE.
Quoted 6 lines
Quoted 4 lines
Yes, this is possible.
Though it doesn't feel very cool, since I have no idea if the ODD is a tray type or slot type in ATA layer and I'll blindly send this command to it then, not a problem maybe.It would be good to verify if that works for slot devices, if possible.
The ACPI GPE event is triggered when user inserts a disc into a slot type ODD, and if I send an eject command to it, the disc will be ejected, which is wrong.
I need to know the loading mechanism(tray type or slot type) of the ODD to decide if I should send this command.
Quoted 4 lines
Quoted 3 lines
And what do you think of moving the acpi notification code to sr?
http://marc.info/?l=linux-pm&m=134873904332704&w=4Quoted 6 lines
Quoted 2 lines
I don't think this is a good idea, quite frankly. sr seems to be a too generic place for that.
Does this mean sr can only have code that is useful to all devices it manages? i.e. If a piece of code enables a feature for a special kind of ODD(like the sata based ZPODD), it shouldn't be done in sr?
If the feature is specific to one special kind of ODD only, then I don't think sr is the right place to add support for it.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Ideally, the whole ZPODD handling should not be visible to the SCSI layer,
I can see 2 problems:
- Don't know its loading machanism so we have the problem above;Does using the
need_ejectflag address this problem somehow?
The need_eject flag is used to give sr a hint that on resume, please eject its tray. And sr knows what loading mechanism this ODD is.
Quoted 7 lines
Quoted 4 lines
- Need to send command to find out if ODD is zero power ready somewhere in ata layer, this implies the device is doing IO after it is runtime suspended in scsi layer.
There's nothing wrong with accessig suspended devices as long as we know that they will respond. :-)
Oh, I was reading the comments above the struct dev_pm_ops in /include/linux/pm.h and thought that was a requirement :-)
Thanks,
Aaron
Quoted 25 lines
Quoted 10 lines
Quoted 3 lines
perhaps except the "
no_polling" flag disabling the polling that may be useful for other purposes in principle.I hope so, let's hear what other people has to say.
Quoted 3 lines
I'm not sure if it's possible at this point, but if not we need to know very precisely why not.
Quoted 6 lines
There is nothing in theory stopping us from doing this in ata layer. For the loading mechanism, we can always send an ATAPI command to figure it out.
So gentlemen, I need your opinions on where this ZPODD code should live before I can continue this work, thanks.
I would _try_ to add it at the ATA level.
Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html