aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata
diff options
context:
space:
mode:
authorAaron Lu <aaron.lu@intel.com>2013-01-15 04:21:00 -0500
committerJeff Garzik <jgarzik@redhat.com>2013-01-21 15:41:34 -0500
commit3dc67440d99b2c718ef5f1eb1424a9066ffa3fb9 (patch)
tree4eee59932d2b99daf76f2bca624c05e719a4b004 /drivers/ata
parentf064a20dded807448669426c9bfb7d03aba5659c (diff)
libata: check zero power ready status for ZPODD
Per the Mount Fuji spec, the ODD is considered zero power ready when: - For slot type ODD, no media inside; - For tray type ODD, no media inside and tray closed. The information can be retrieved by either the returned information of command GET_EVENT_STATUS_NOTIFICATION(the command is used to poll for media event) or sense code. The information provided by the media status byte is not accurate, it is possible that after a new disc is just inserted, the status byte still returns media not present. So this information can not be used as the deciding factor, we use sense code to decide if zpready status is true. When we first sensed the ODD in the zero power ready state, the zp_sampled will be set and timestamp will be recoreded. And after ODD stayed in this state for some pre-defined period, the ODD is considered as power off ready and the zp_ready flag will be set. The zp_ready flag serves as the deciding factor other code will use to see if power off is OK for the ODD. The Mount Fuji spec suggests a delay should be used here, to avoid the case user ejects the ODD and then instantly inserts a new one again, so that we can avoid a power transition. And some ODDs may be slow to place its head to the home position after disc is ejected, so a delay here is generally a good idea. And the delay time can be changed via the module param zpodd_poweroff_delay. The zero power ready status check is performed in the ata port's runtime suspend code path, when port is not frozen yet, as we need to issue some IOs to the ODD. Signed-off-by: Aaron Lu <aaron.lu@intel.com> Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
Diffstat (limited to 'drivers/ata')
-rw-r--r--drivers/ata/libata-eh.c14
-rw-r--r--drivers/ata/libata-zpodd.c75
-rw-r--r--drivers/ata/libata.h5
3 files changed, 92 insertions, 2 deletions
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index bcf4437214f5..a0dddc3b4924 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -1591,7 +1591,7 @@ static int ata_eh_read_log_10h(struct ata_device *dev,
1591 * RETURNS: 1591 * RETURNS:
1592 * 0 on success, AC_ERR_* mask on failure. 1592 * 0 on success, AC_ERR_* mask on failure.
1593 */ 1593 */
1594static unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key) 1594unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key)
1595{ 1595{
1596 u8 cdb[ATAPI_CDB_LEN] = { TEST_UNIT_READY, 0, 0, 0, 0, 0 }; 1596 u8 cdb[ATAPI_CDB_LEN] = { TEST_UNIT_READY, 0, 0, 0, 0, 0 };
1597 struct ata_taskfile tf; 1597 struct ata_taskfile tf;
@@ -1624,7 +1624,7 @@ static unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key)
1624 * RETURNS: 1624 * RETURNS:
1625 * 0 on success, AC_ERR_* mask on failure 1625 * 0 on success, AC_ERR_* mask on failure
1626 */ 1626 */
1627static unsigned int atapi_eh_request_sense(struct ata_device *dev, 1627unsigned int atapi_eh_request_sense(struct ata_device *dev,
1628 u8 *sense_buf, u8 dfl_sense_key) 1628 u8 *sense_buf, u8 dfl_sense_key)
1629{ 1629{
1630 u8 cdb[ATAPI_CDB_LEN] = 1630 u8 cdb[ATAPI_CDB_LEN] =
@@ -4022,6 +4022,7 @@ static void ata_eh_handle_port_suspend(struct ata_port *ap)
4022{ 4022{
4023 unsigned long flags; 4023 unsigned long flags;
4024 int rc = 0; 4024 int rc = 0;
4025 struct ata_device *dev;
4025 4026
4026 /* are we suspending? */ 4027 /* are we suspending? */
4027 spin_lock_irqsave(ap->lock, flags); 4028 spin_lock_irqsave(ap->lock, flags);
@@ -4034,6 +4035,15 @@ static void ata_eh_handle_port_suspend(struct ata_port *ap)
4034 4035
4035 WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED); 4036 WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED);
4036 4037
4038 /*
4039 * If we have a ZPODD attached, check its zero
4040 * power ready status before the port is frozen.
4041 */
4042 ata_for_each_dev(dev, &ap->link, ENABLED) {
4043 if (zpodd_dev_enabled(dev))
4044 zpodd_on_suspend(dev);
4045 }
4046
4037 /* tell ACPI we're suspending */ 4047 /* tell ACPI we're suspending */
4038 rc = ata_acpi_on_suspend(ap); 4048 rc = ata_acpi_on_suspend(ap);
4039 if (rc) 4049 if (rc)
diff --git a/drivers/ata/libata-zpodd.c b/drivers/ata/libata-zpodd.c
index 9a0d90d09d81..71dd48c94f2c 100644
--- a/drivers/ata/libata-zpodd.c
+++ b/drivers/ata/libata-zpodd.c
@@ -1,10 +1,15 @@
1#include <linux/libata.h> 1#include <linux/libata.h>
2#include <linux/cdrom.h> 2#include <linux/cdrom.h>
3#include <linux/pm_runtime.h> 3#include <linux/pm_runtime.h>
4#include <linux/module.h>
4#include <scsi/scsi_device.h> 5#include <scsi/scsi_device.h>
5 6
6#include "libata.h" 7#include "libata.h"
7 8
9static int zpodd_poweroff_delay = 30; /* 30 seconds for power off delay */
10module_param(zpodd_poweroff_delay, int, 0644);
11MODULE_PARM_DESC(zpodd_poweroff_delay, "Poweroff delay for ZPODD in seconds");
12
8enum odd_mech_type { 13enum odd_mech_type {
9 ODD_MECH_TYPE_SLOT, 14 ODD_MECH_TYPE_SLOT,
10 ODD_MECH_TYPE_DRAWER, 15 ODD_MECH_TYPE_DRAWER,
@@ -18,6 +23,9 @@ struct zpodd {
18 /* The following fields are synchronized by PM core. */ 23 /* The following fields are synchronized by PM core. */
19 bool from_notify; /* resumed as a result of 24 bool from_notify; /* resumed as a result of
20 * acpi wake notification */ 25 * acpi wake notification */
26 bool zp_ready; /* ZP ready state */
27 unsigned long last_ready; /* last ZP ready timestamp */
28 bool zp_sampled; /* ZP ready state sampled */
21}; 29};
22 30
23/* Per the spec, only slot type and drawer type ODD can be supported */ 31/* Per the spec, only slot type and drawer type ODD can be supported */
@@ -74,6 +82,73 @@ static bool odd_can_poweroff(struct ata_device *ata_dev)
74 return acpi_device_can_poweroff(acpi_dev); 82 return acpi_device_can_poweroff(acpi_dev);
75} 83}
76 84
85/* Test if ODD is zero power ready by sense code */
86static bool zpready(struct ata_device *dev)
87{
88 u8 sense_key, *sense_buf;
89 unsigned int ret, asc, ascq, add_len;
90 struct zpodd *zpodd = dev->zpodd;
91
92 ret = atapi_eh_tur(dev, &sense_key);
93
94 if (!ret || sense_key != NOT_READY)
95 return false;
96
97 sense_buf = dev->link->ap->sector_buf;
98 ret = atapi_eh_request_sense(dev, sense_buf, sense_key);
99 if (ret)
100 return false;
101
102 /* sense valid */
103 if ((sense_buf[0] & 0x7f) != 0x70)
104 return false;
105
106 add_len = sense_buf[7];
107 /* has asc and ascq */
108 if (add_len < 6)
109 return false;
110
111 asc = sense_buf[12];
112 ascq = sense_buf[13];
113
114 if (zpodd->mech_type == ODD_MECH_TYPE_SLOT)
115 /* no media inside */
116 return asc == 0x3a;
117 else
118 /* no media inside and door closed */
119 return asc == 0x3a && ascq == 0x01;
120}
121
122/*
123 * Update the zpodd->zp_ready field. This field will only be set
124 * if the ODD has stayed in ZP ready state for zpodd_poweroff_delay
125 * time, and will be used to decide if power off is allowed. If it
126 * is set, it will be cleared during resume from powered off state.
127 */
128void zpodd_on_suspend(struct ata_device *dev)
129{
130 struct zpodd *zpodd = dev->zpodd;
131 unsigned long expires;
132
133 if (!zpready(dev)) {
134 zpodd->zp_sampled = false;
135 return;
136 }
137
138 if (!zpodd->zp_sampled) {
139 zpodd->zp_sampled = true;
140 zpodd->last_ready = jiffies;
141 return;
142 }
143
144 expires = zpodd->last_ready +
145 msecs_to_jiffies(zpodd_poweroff_delay * 1000);
146 if (time_before(jiffies, expires))
147 return;
148
149 zpodd->zp_ready = true;
150}
151
77static void zpodd_wake_dev(acpi_handle handle, u32 event, void *context) 152static void zpodd_wake_dev(acpi_handle handle, u32 event, void *context)
78{ 153{
79 struct ata_device *ata_dev = context; 154 struct ata_device *ata_dev = context;
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index a21740b4ee11..b9b2bb1d5dc6 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -182,6 +182,9 @@ extern void ata_eh_finish(struct ata_port *ap);
182extern int ata_ering_map(struct ata_ering *ering, 182extern int ata_ering_map(struct ata_ering *ering,
183 int (*map_fn)(struct ata_ering_entry *, void *), 183 int (*map_fn)(struct ata_ering_entry *, void *),
184 void *arg); 184 void *arg);
185extern unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key);
186extern unsigned int atapi_eh_request_sense(struct ata_device *dev,
187 u8 *sense_buf, u8 dfl_sense_key);
185 188
186/* libata-pmp.c */ 189/* libata-pmp.c */
187#ifdef CONFIG_SATA_PMP 190#ifdef CONFIG_SATA_PMP
@@ -238,10 +241,12 @@ static inline bool zpodd_dev_enabled(struct ata_device *dev)
238{ 241{
239 return dev->zpodd != NULL; 242 return dev->zpodd != NULL;
240} 243}
244void zpodd_on_suspend(struct ata_device *dev);
241#else /* CONFIG_SATA_ZPODD */ 245#else /* CONFIG_SATA_ZPODD */
242static inline void zpodd_init(struct ata_device *dev) {} 246static inline void zpodd_init(struct ata_device *dev) {}
243static inline void zpodd_exit(struct ata_device *dev) {} 247static inline void zpodd_exit(struct ata_device *dev) {}
244static inline bool zpodd_dev_enabled(struct ata_device *dev) { return false; } 248static inline bool zpodd_dev_enabled(struct ata_device *dev) { return false; }
249static inline void zpodd_on_suspend(struct ata_device *dev) {}
245#endif /* CONFIG_SATA_ZPODD */ 250#endif /* CONFIG_SATA_ZPODD */
246 251
247#endif /* __LIBATA_H__ */ 252#endif /* __LIBATA_H__ */