Commit 6f4c827e authored by Aaron Lu's avatar Aaron Lu Committed by Jeff Garzik

[libata] scsi: no poll when ODD is powered off

When the ODD is powered off, any action the user did to the ODD that
would generate a media event will trigger an ACPI interrupt, so the
poll for media event is no longer necessary. And the poll will also
cause a runtime status change, which will stop the ODD from staying in
powered off state, so the poll should better be stopped.

But since we don't have access to the gendisk structure in LLDs, here
comes the disk_events_disable_depth for scsi device. This field is a
hint set by LLDs to convey information to upper layer drivers. A value
of 0 means media poll is necessary for the device, while values above 0
means media poll is not needed and should better be skipped. So we can
increase its value when we are to power off the ODD in ATA layer and
decrease its value when the ODD is powered on, effectively silence the
media events poll.
Signed-off-by: default avatarAaron Lu <aaron.lu@intel.com>
Signed-off-by: default avatarJeff Garzik <jgarzik@redhat.com>
parent 6c7f1e2f
...@@ -178,11 +178,16 @@ bool zpodd_zpready(struct ata_device *dev) ...@@ -178,11 +178,16 @@ bool zpodd_zpready(struct ata_device *dev)
* Enable runtime wake capability through ACPI and set the powered_off flag, * Enable runtime wake capability through ACPI and set the powered_off flag,
* this flag will be used during resume to decide what operations are needed * this flag will be used during resume to decide what operations are needed
* to take. * to take.
*
* Also, media poll needs to be silenced, so that it doesn't bring the ODD
* back to full power state every few seconds.
*/ */
void zpodd_enable_run_wake(struct ata_device *dev) void zpodd_enable_run_wake(struct ata_device *dev)
{ {
struct zpodd *zpodd = dev->zpodd; struct zpodd *zpodd = dev->zpodd;
sdev_disable_disk_events(dev->sdev);
zpodd->powered_off = true; zpodd->powered_off = true;
device_set_run_wake(&dev->sdev->sdev_gendev, true); device_set_run_wake(&dev->sdev->sdev_gendev, true);
acpi_pm_device_run_wake(&dev->sdev->sdev_gendev, true); acpi_pm_device_run_wake(&dev->sdev->sdev_gendev, true);
...@@ -231,6 +236,8 @@ void zpodd_post_poweron(struct ata_device *dev) ...@@ -231,6 +236,8 @@ void zpodd_post_poweron(struct ata_device *dev)
zpodd->zp_sampled = false; zpodd->zp_sampled = false;
zpodd->zp_ready = false; zpodd->zp_ready = false;
sdev_enable_disk_events(dev->sdev);
} }
static void zpodd_wake_dev(acpi_handle handle, u32 event, void *context) static void zpodd_wake_dev(acpi_handle handle, u32 event, void *context)
......
...@@ -2617,3 +2617,17 @@ void scsi_kunmap_atomic_sg(void *virt) ...@@ -2617,3 +2617,17 @@ void scsi_kunmap_atomic_sg(void *virt)
kunmap_atomic(virt); kunmap_atomic(virt);
} }
EXPORT_SYMBOL(scsi_kunmap_atomic_sg); EXPORT_SYMBOL(scsi_kunmap_atomic_sg);
void sdev_disable_disk_events(struct scsi_device *sdev)
{
atomic_inc(&sdev->disk_events_disable_depth);
}
EXPORT_SYMBOL(sdev_disable_disk_events);
void sdev_enable_disk_events(struct scsi_device *sdev)
{
if (WARN_ON_ONCE(atomic_read(&sdev->disk_events_disable_depth) <= 0))
return;
atomic_dec(&sdev->disk_events_disable_depth);
}
EXPORT_SYMBOL(sdev_enable_disk_events);
...@@ -602,9 +602,13 @@ static unsigned int sr_block_check_events(struct gendisk *disk, ...@@ -602,9 +602,13 @@ static unsigned int sr_block_check_events(struct gendisk *disk,
struct scsi_cd *cd = scsi_cd(disk); struct scsi_cd *cd = scsi_cd(disk);
unsigned int ret; unsigned int ret;
if (atomic_read(&cd->device->disk_events_disable_depth) == 0) {
scsi_autopm_get_device(cd->device); scsi_autopm_get_device(cd->device);
ret = cdrom_check_events(&cd->cdi, clearing); ret = cdrom_check_events(&cd->cdi, clearing);
scsi_autopm_put_device(cd->device); scsi_autopm_put_device(cd->device);
} else {
ret = 0;
}
return ret; return ret;
} }
......
...@@ -161,6 +161,8 @@ struct scsi_device { ...@@ -161,6 +161,8 @@ struct scsi_device {
unsigned wce_default_on:1; /* Cache is ON by default */ unsigned wce_default_on:1; /* Cache is ON by default */
unsigned no_dif:1; /* T10 PI (DIF) should be disabled */ unsigned no_dif:1; /* T10 PI (DIF) should be disabled */
atomic_t disk_events_disable_depth; /* disable depth for disk events */
DECLARE_BITMAP(supported_events, SDEV_EVT_MAXBITS); /* supported events */ DECLARE_BITMAP(supported_events, SDEV_EVT_MAXBITS); /* supported events */
struct list_head event_list; /* asserted events */ struct list_head event_list; /* asserted events */
struct work_struct event_work; struct work_struct event_work;
...@@ -397,6 +399,8 @@ extern int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd, ...@@ -397,6 +399,8 @@ extern int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd,
int data_direction, void *buffer, unsigned bufflen, int data_direction, void *buffer, unsigned bufflen,
struct scsi_sense_hdr *, int timeout, int retries, struct scsi_sense_hdr *, int timeout, int retries,
int *resid); int *resid);
extern void sdev_disable_disk_events(struct scsi_device *sdev);
extern void sdev_enable_disk_events(struct scsi_device *sdev);
#ifdef CONFIG_PM_RUNTIME #ifdef CONFIG_PM_RUNTIME
extern int scsi_autopm_get_device(struct scsi_device *); extern int scsi_autopm_get_device(struct scsi_device *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment