Disk shock protection in libata
Hi all,
since Bart has already added patches #1, #3 and #4 of my previous series to his pata tree, I'm now going to resend only patches #1 and #2. There are no changes to the first one, it is just that the second depends on it. The crucial difference between the provious and the new version of the second patch is that we now use completion rather than simple wait queues and wake up calls, so as not to interfere with msleep() during command execution in ata_eh_park_issue_cmd(). The patches have been rebased to next-20080919.
Regards,
Elias
PATCH v3 1/2 Introduce ata_id_has_unload()
Add a function to check an ATA device's id for head unload support as specified in ATA-7.
---
include/linux/ata.h | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
include/linux/ata.h +9 -0
@@ -707,6 +707,15 @@ static inline int ata_id_has_dword_io(const u16 *id)return 0 ; } +static inline int ata_id_has_unload (const u16 *id) +{ +if (ata_id_major_version (id) >=7 && + (id[ATA_ID_CFSSE ] &0xC000 ) ==0x4000 && + id[ATA_ID_CFSSE ] & (1 <<13 )) +return 1 ; +return 0 ; +} +static inline int ata_id_current_chs_valid (const u16 *id) {/* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command
PATCH v3 2/2 libata: Implement disk shock protection support
In reply to Elias OltmannsOn user request (through sysfs), the IDLE IMMEDIATE command with UNLOAD FEATURE as specified in ATA-7 is issued to the device and processing of the request queue is stopped thereafter until the specified timeout expires or user space asks to resume normal operation. This is supposed to prevent the heads of a hard drive from accidentally crashing onto the platter when a heavy shock is anticipated (like a falling laptop expected to hit the floor). In fact, the whole port stops processing commands until the timeout has expired in order to avoid any resets due to failed commands on another device.
---
drivers/ata/ahci.c | 1 drivers/ata/libata-core.c | 1 drivers/ata/libata-eh.c | 110 +++++++++++++++++++++++++++++++++++++++++++++ drivers/ata/libata-scsi.c | 108 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/libata.h | 13 +++++ 5 files changed, 230 insertions(+), 3 deletions(-)
drivers/ata/ahci.c +1 -0
@@ -316,6 +316,7 @@ static struct device_attribute *ahci_shost_attrs[] = {static struct device_attribute *ahci_sdev_attrs[] = { &dev_attr_sw_activity, + &dev_attr_unload_heads,NULL };
drivers/ata/libata-core.c +1 -0
@@ -5264,6 +5264,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host)INIT_WORK (&ap->scsi_rescan_task, ata_scsi_dev_rescan);INIT_LIST_HEAD (&ap->eh_done_q);init_waitqueue_head (&ap->eh_wait_q); +init_completion (&ap->park_req_pending);init_timer_deferrable (&ap->fastdrain_timer); ap->fastdrain_timer.function = ata_eh_fastdrain_timerfn; ap->fastdrain_timer.data = (unsigned long )ap;
drivers/ata/libata-eh.c +109 -1
128 lines not on this page · raw message
drivers/ata/libata-scsi.c +108 -0
126 lines not on this page · raw message
include/linux/libata.h +11 -2
@@ -146,6 +146,7 @@ enum {ATA_DFLAG_SPUNDOWN = (1 <<14 ),/* XXX: for spindown_compat */ ATA_DFLAG_SLEEPING = (1 <<15 ),/* device is sleeping */ ATA_DFLAG_DUBIOUS_XFER = (1 <<16 ),/* data transfer not verified */ +ATA_DFLAG_NO_UNLOAD = (1 <<17 ),/* device doesn't support unload */ ATA_DFLAG_INIT_MASK = (1 <<24 ) -1 , ATA_DFLAG_DETACH = (1 << 24),
@@ -244,6 +245,7 @@ enum {ATA_TMOUT_BOOT =30000 ,/* heuristic */ ATA_TMOUT_BOOT_QUICK =7000 ,/* heuristic */ ATA_TMOUT_INTERNAL_QUICK =5000 , +ATA_TMOUT_MAX_PARK =30000 ,/* FIXME: GoVault needs 2s but we can't afford that without * parallel probing. 800ms is enough for iVDR disk
@@ -319,8 +321,9 @@ enum {ATA_EH_RESET =ATA_EH_SOFTRESET |ATA_EH_HARDRESET ,ATA_EH_ENABLE_LINK = (1 <<3 ),ATA_EH_LPM = (1 <<4 ),/* link power management action */ +ATA_EH_PARK = (1 <<5 ),/* unload heads and stop I/O */ -ATA_EH_PERDEV_MASK =ATA_EH_REVALIDATE , +ATA_EH_PERDEV_MASK =ATA_EH_REVALIDATE |ATA_EH_PARK ,/* ata_eh_info->flags */ ATA_EHI_HOTPLUGGED = (1 << 0), /* could have been hotplugged */
@@ -452,6 +455,7 @@ enum link_pm { MEDIUM_POWER, };extern struct device_attribute dev_attr_link_power_management_policy; +extern struct device_attribute dev_attr_unload_heads;extern struct device_attribute dev_attr_em_message_type;extern struct device_attribute dev_attr_em_message;extern struct device_attribute dev_attr_sw_activity;
@@ -564,6 +568,7 @@ struct ata_device {/* n_sector is used as CLEAR_OFFSET, read comment above CLEAR_OFFSET */ u64 n_sectors;/* size of device, if ATA */ unsigned int class;/* ATA_DEV_xxx */ +unsigned long unpark_deadline;u8 pio_mode;u8 dma_mode;
@@ -621,6 +626,7 @@ struct ata_eh_context { [ATA_EH_CMD_TIMEOUT_TABLE_SIZE ];unsigned int classes[ATA_MAX_DEVICES ];unsigned int did_probe_mask; +unsigned int unloaded_mask;unsigned int saved_ncq_enabled;u8 saved_xfer_mode[ATA_MAX_DEVICES ];/* timestamp for the last reset attempt or success */
@@ -709,6 +715,7 @@ struct ata_port {struct list_head eh_done_q;wait_queue_head_t eh_wait_q;int eh_tries; +struct completion park_req_pending;pm_message_t pm_mesg;int *pm_result;
@@ -1098,6 +1105,7 @@ extern void ata_std_error_handler(struct ata_port *ap);*/ extern const struct ata_port_operations ata_base_port_ops;extern const struct ata_port_operations sata_port_ops; +extern struct device_attribute *ata_common_sdev_attrs[];#define ATA_BASE_SHT (drv_name) \ .module = THIS_MODULE, \
@@ -1112,7 +1120,8 @@ extern const struct ata_port_operations sata_port_ops; .proc_name = drv_name, \ .slave_configure = ata_scsi_slave_config, \ .slave_destroy = ata_scsi_slave_destroy, \ - .bios_param = ata_std_bios_param + .bios_param = ata_std_bios_param, \ + .sdev_attrs = ata_common_sdev_attrs#define ATA_NCQ_SHT (drv_name) \ ATA_BASE_SHT(drv_name), \
Re: [PATCH 2/2 v3] libata: Implement disk shock protection support
Hello, Elias.
Ah... we're so close but no ack yet. Just a few nits.
It would be nice if there's explanation why action pulling is necessary in the first place.
Quoted 20 lines
drivers/ata/libata-eh.c +20
-0+static inline void ata_eh_pull_park_action (struct ata_port *ap) +{ +struct ata_link *link; +struct ata_device *dev; +unsigned long flags; + +/* +* All write accesses to &ap->park_req_pending through +* INIT_COMPLETION() (see below) or complete_all() (see +* ata_scsi_park_store()) are protected by the host lock. As a +* result we have that park_req_pending.done is zero on exit +* from this function, i.e. when ATA_EH_PARK actions for *all* +* devices on port ap have been pulled into the respective +* eh_context structs. If, and only if, park_req_pending.done +* is non-zero by the time we reach +* wait_for_completion_timeout(), another ATA_EH_PARK action +* has been scheduled for at least one of the devices on port +* ap and we have to cycle over the do { } while () loop in +* ata_eh_recover() again. +*/
...
drivers/ata/libata-eh.c int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, · line 2899
Quoted 4 lines
drivers/ata/libata-eh.c +4
-0+ do { + unsigned long now; + + ata_eh_pull_park_action(ap);
How about adding the folloiwng to the above line?
/* clears park_req_pending */
Quoted 4 lines
drivers/ata/libata-scsi.c +4
-0+static ssize_t ata_scsi_park_store (struct device *device, +struct device_attribute *attr, +const char *buf,size_t len) +{
...
drivers/ata/libata-scsi.c DEVICE_ATTR(link_power_management_policy, S_IRUGO | S_IWUSR, · line 265
Quoted 1 line
drivers/ata/libata-scsi.c +1
-0+complete_all (&ap->park_req_pending);
Sorry to catching this this late but calling complete_all() twice will overflow the done counter. I think complete() should just work here, no?
Thanks.
Signature · 1 line
tejun
Re: [PATCH 2/2 v3] libata: Implement disk shock protection support
Quoted 3 lines · Tejun Heo
Hello, Elias.
Ah... we're so close but no ack yet. Just a few nits.
A pity ;-) but you are quite right.
Quoted 3 lines
It would be nice if there's explanation why action pulling is necessary in the first place.
Right.
Quoted 22 lines
Quoted 21 lines
drivers/ata/libata-eh.c +20
-0+static inline void ata_eh_pull_park_action (struct ata_port *ap) +{ +struct ata_link *link; +struct ata_device *dev; +unsigned long flags; + +/* +* All write accesses to &ap->park_req_pending through +* INIT_COMPLETION() (see below) or complete_all() (see +* ata_scsi_park_store()) are protected by the host lock. As a +* result we have that park_req_pending.done is zero on exit +* from this function, i.e. when ATA_EH_PARK actions for *all* +* devices on port ap have been pulled into the respective +* eh_context structs. If, and only if, park_req_pending.done +* is non-zero by the time we reach +* wait_for_completion_timeout(), another ATA_EH_PARK action +* has been scheduled for at least one of the devices on port +* ap and we have to cycle over the do { } while () loop in +* ata_eh_recover() again. +*/ ...
Quoted 7 lines
drivers/ata/libata-eh.c int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, · line 2899
Quoted 4 lines
drivers/ata/libata-eh.c +4
-0+ do { + unsigned long now; + + ata_eh_pull_park_action(ap);How about adding the folloiwng to the above line?
/* clears park_req_pending */
Yes. I take it that this is in addition to some explanation within ata_eh_pull_park_action() you have asked for above?
Quoted 11 lines
Quoted 5 lines
drivers/ata/libata-scsi.c +4
-0+static ssize_t ata_scsi_park_store (struct device *device, +struct device_attribute *attr, +const char *buf,size_t len) +{...
drivers/ata/libata-scsi.c DEVICE_ATTR(link_power_management_policy, S_IRUGO | S_IWUSR, · line 265
Quoted 1 line
drivers/ata/libata-scsi.c +1
-0+complete_all (&ap->park_req_pending);Sorry to catching this this late but calling
complete_all()twice will overflow the done counter. I thinkcomplete()should just work here, no?
Sorry for missing that in the first place, rather embarrassing that. I had just assumed that the done counter was set to an absolute value rather than added to. I really think that this is what we actually want, so, perhaps, a seperate patch for Ingo or someone is in order?
The reason why I'd like to call complete_all() rather than complete() is
this: if two drives on seperate ports have been parked and userspace updates the timeout for one of them, then complete() will only wake up the thread that comes first in the wait queue park_req_pending.wait -- please note that complete() and complete_all() pass different arguments to __wake_up_common().
Regards,
Elias
Re: [PATCH 2/2 v3] libata: Implement disk shock protection support
[ Readding LKML which I dropped when starting this thread for some inexplicable reason. ]
Quoted 12 lines · Elias Oltmanns
Quoted 10 lines · Tejun Heo
Quoted 4 lines
drivers/ata/libata-scsi.c +4
-0+static ssize_t ata_scsi_park_store (struct device *device, +struct device_attribute *attr, +const char *buf,size_t len) +{...
drivers/ata/libata-scsi.c DEVICE_ATTR(link_power_management_policy, S_IRUGO | S_IWUSR, · line 265
Quoted 1 line
drivers/ata/libata-scsi.c +1
-0+complete_all (&ap->park_req_pending);Sorry to catching this this late but calling
complete_all()twice will overflow the done counter. I thinkcomplete()should just work here, no?
Quoted 4 lines
Sorry for missing that in the first place, rather embarrassing that. I had just assumed that the done counter was set to an absolute value rather than added to. I really think that this is what we actually want, so, perhaps, a seperate patch for Ingo or someone is in order?
By the way, this doesn't really matter in our particular case. The reason is that we only care about whether park_req_pending.done is equal or unequal to zero. Since UINT_MAX is of the form 2n+1 (where n is some interger value), calling complete_all() m times may overflow but will still result in a non-zero value provided that m is smaller than n. Assuming that m != 0 is even, we have:
m * n < m / 2 * (2 * n + 2).
Additionally, we have:
(m / 2 - 1) * (2 * n + 2) == (m - 2) * (n + 1) == m * n + m - (2 * n + 2).
This means that for 0 < m < UINT_MAX (and m even) we get:
m * n > (m / 2 - 1) * (2 * n + 2)
and consequently
m * n % (UINT_MAX + 1) == m * n - (m / 2) * (2 * n + 2) == 2 * n + 2 - m == UINT_MAX + 1 - m.
Now consider the case that m is odd:
m * n < (m + 1) / 2 * (2 * n + 2).
But
(m - 1) / 2 * (2 * n + 2) == (m - 1) * (n + 1) == m * n + m - n - 1.
For m <= n (and m odd) we get:
m * n >= (m - 1) / 2 * (2 * n + 2)
and consequently
m * n % (UINT_MAX + 1) == m * n - (m - 1) / 2 * (2 * n + 2) == n + 1 - m.
This proves that the done counter will be non-zero if we call complete_all() at least once and up to (UINT_MAX - 1) / 2 times. So, I'll add some more comments about clearing ATA_EH_PARK and why it's needed and then resend the patch. Mind you, I still think that complete_all() should be changed. I'll take a look at other use cases in the kernel and see whether overflowing is an issue there.
Regards,
Elias
PATCH v4 2/2 libata: Implement disk shock protection support
On user request (through sysfs), the IDLE IMMEDIATE command with UNLOAD FEATURE as specified in ATA-7 is issued to the device and processing of the request queue is stopped thereafter until the specified timeout expires or user space asks to resume normal operation. This is supposed to prevent the heads of a hard drive from accidentally crashing onto the platter when a heavy shock is anticipated (like a falling laptop expected to hit the floor). In fact, the whole port stops processing commands until the timeout has expired in order to avoid any resets due to failed commands on another device.
---
Added comments only.
drivers/ata/ahci.c | 1 drivers/ata/libata-core.c | 1 drivers/ata/libata-eh.c | 126 +++++++++++++++++++++++++++++++++++++++++++++ drivers/ata/libata-scsi.c | 108 +++++++++++++++++++++++++++++++++++++++ include/linux/libata.h | 13 ++++- 5 files changed, 246 insertions(+), 3 deletions(-)
drivers/ata/ahci.c +1 -0
@@ -316,6 +316,7 @@ static struct device_attribute *ahci_shost_attrs[] = {static struct device_attribute *ahci_sdev_attrs[] = { &dev_attr_sw_activity, + &dev_attr_unload_heads,NULL };
drivers/ata/libata-core.c +1 -0
@@ -5264,6 +5264,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host)INIT_WORK (&ap->scsi_rescan_task, ata_scsi_dev_rescan);INIT_LIST_HEAD (&ap->eh_done_q);init_waitqueue_head (&ap->eh_wait_q); +init_completion (&ap->park_req_pending);init_timer_deferrable (&ap->fastdrain_timer); ap->fastdrain_timer.function = ata_eh_fastdrain_timerfn; ap->fastdrain_timer.data = (unsigned long )ap;
drivers/ata/libata-eh.c +125 -1
144 lines not on this page · raw message
drivers/ata/libata-scsi.c +108 -0
126 lines not on this page · raw message
include/linux/libata.h +11 -2
@@ -146,6 +146,7 @@ enum {ATA_DFLAG_SPUNDOWN = (1 <<14 ),/* XXX: for spindown_compat */ ATA_DFLAG_SLEEPING = (1 <<15 ),/* device is sleeping */ ATA_DFLAG_DUBIOUS_XFER = (1 <<16 ),/* data transfer not verified */ +ATA_DFLAG_NO_UNLOAD = (1 <<17 ),/* device doesn't support unload */ ATA_DFLAG_INIT_MASK = (1 <<24 ) -1 , ATA_DFLAG_DETACH = (1 << 24),
@@ -244,6 +245,7 @@ enum {ATA_TMOUT_BOOT =30000 ,/* heuristic */ ATA_TMOUT_BOOT_QUICK =7000 ,/* heuristic */ ATA_TMOUT_INTERNAL_QUICK =5000 , +ATA_TMOUT_MAX_PARK =30000 ,/* FIXME: GoVault needs 2s but we can't afford that without * parallel probing. 800ms is enough for iVDR disk
@@ -319,8 +321,9 @@ enum {ATA_EH_RESET =ATA_EH_SOFTRESET |ATA_EH_HARDRESET ,ATA_EH_ENABLE_LINK = (1 <<3 ),ATA_EH_LPM = (1 <<4 ),/* link power management action */ +ATA_EH_PARK = (1 <<5 ),/* unload heads and stop I/O */ -ATA_EH_PERDEV_MASK =ATA_EH_REVALIDATE , +ATA_EH_PERDEV_MASK =ATA_EH_REVALIDATE |ATA_EH_PARK ,/* ata_eh_info->flags */ ATA_EHI_HOTPLUGGED = (1 << 0), /* could have been hotplugged */
@@ -452,6 +455,7 @@ enum link_pm { MEDIUM_POWER, };extern struct device_attribute dev_attr_link_power_management_policy; +extern struct device_attribute dev_attr_unload_heads;extern struct device_attribute dev_attr_em_message_type;extern struct device_attribute dev_attr_em_message;extern struct device_attribute dev_attr_sw_activity;
@@ -564,6 +568,7 @@ struct ata_device {/* n_sector is used as CLEAR_OFFSET, read comment above CLEAR_OFFSET */ u64 n_sectors;/* size of device, if ATA */ unsigned int class;/* ATA_DEV_xxx */ +unsigned long unpark_deadline;u8 pio_mode;u8 dma_mode;
@@ -621,6 +626,7 @@ struct ata_eh_context { [ATA_EH_CMD_TIMEOUT_TABLE_SIZE ];unsigned int classes[ATA_MAX_DEVICES ];unsigned int did_probe_mask; +unsigned int unloaded_mask;unsigned int saved_ncq_enabled;u8 saved_xfer_mode[ATA_MAX_DEVICES ];/* timestamp for the last reset attempt or success */
@@ -709,6 +715,7 @@ struct ata_port {struct list_head eh_done_q;wait_queue_head_t eh_wait_q;int eh_tries; +struct completion park_req_pending;pm_message_t pm_mesg;int *pm_result;
@@ -1098,6 +1105,7 @@ extern void ata_std_error_handler(struct ata_port *ap);*/ extern const struct ata_port_operations ata_base_port_ops;extern const struct ata_port_operations sata_port_ops; +extern struct device_attribute *ata_common_sdev_attrs[];#define ATA_BASE_SHT (drv_name) \ .module = THIS_MODULE, \
@@ -1112,7 +1120,8 @@ extern const struct ata_port_operations sata_port_ops; .proc_name = drv_name, \ .slave_configure = ata_scsi_slave_config, \ .slave_destroy = ata_scsi_slave_destroy, \ - .bios_param = ata_std_bios_param + .bios_param = ata_std_bios_param, \ + .sdev_attrs = ata_common_sdev_attrs#define ATA_NCQ_SHT (drv_name) \ ATA_BASE_SHT(drv_name), \
Re: [PATCH 2/2 v4] libata: Implement disk shock protection support
Quoted 11 lines · Elias Oltmanns
On user request (through sysfs), the IDLE IMMEDIATE command with UNLOAD FEATURE as specified in ATA-7 is issued to the device and processing of the request queue is stopped thereafter until the specified timeout expires or user space asks to resume normal operation. This is supposed to prevent the heads of a hard drive from accidentally crashing onto the platter when a heavy shock is anticipated (like a falling laptop expected to hit the floor). In fact, the whole port stops processing commands until the timeout has expired in order to avoid any resets due to failed commands on another device.
Signed-off-by Elias Oltmanns <[email protected]>
As for completion, yes, I think it would be nice to update complete such that multiple complete_all() calls don't overflow and completion can be used for this type of usage. Anyways, that's for another day I guess.
Thanks.
Signature · 1 line
tejun
Re: [PATCH 2/2 v3] libata: Implement disk shock protection support
In reply to Elias OltmannsQuoted 1 line · Elias Oltmanns
Tejun Heo <[email protected]> wrote:
[...]
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
drivers/ata/libata-scsi.c +4
-0+static ssize_t ata_scsi_park_store (struct device *device, +struct device_attribute *attr, +const char *buf,size_t len) +{...
drivers/ata/libata-scsi.c DEVICE_ATTR(link_power_management_policy, S_IRUGO | S_IWUSR, · line 265
Quoted 1 line
drivers/ata/libata-scsi.c +1
-0+complete_all (&ap->park_req_pending);Sorry to catching this this late but calling
complete_all()twice will overflow the done counter. I thinkcomplete()should just work here, no?
[...]
Quoted 6 lines
The reason why I'd like to call
complete_all()rather thancomplete()is
this: if two drives on seperate ports have been parked and userspace updates the timeout for one of them, thencomplete()will only wake up the thread that comes first in the wait queue park_req_pending.wait -- please note thatcomplete()andcomplete_all()pass different arguments to__wake_up_common().
What utter nonsense, I can't have been thinking straight here. Since we have per-port completion structs park_req_pending and since there is always at most a single EH thread per port, complete() is quite sufficient. I even remember thinking about all this when I wrote this code originally. Don't know why I forgot all about it later. Sorry for causing this confusion and all the noise over the last two days.
I'll repost the exact same patch which you have acked except for the change from complete_all() back to complete() again.
Thanks for your patience,
Elias
PATCH v5 2/2 libata: Implement disk shock protection support
In reply to Tejun HeoOn user request (through sysfs), the IDLE IMMEDIATE command with UNLOAD FEATURE as specified in ATA-7 is issued to the device and processing of the request queue is stopped thereafter until the specified timeout expires or user space asks to resume normal operation. This is supposed to prevent the heads of a hard drive from accidentally crashing onto the platter when a heavy shock is anticipated (like a falling laptop expected to hit the floor). In fact, the whole port stops processing commands until the timeout has expired in order to avoid any resets due to failed commands on another device.
---
drivers/ata/ahci.c | 1 drivers/ata/libata-core.c | 1 drivers/ata/libata-eh.c | 126 +++++++++++++++++++++++++++++++++++++++++++++ drivers/ata/libata-scsi.c | 108 +++++++++++++++++++++++++++++++++++++++ include/linux/libata.h | 13 ++++- 5 files changed, 246 insertions(+), 3 deletions(-)
drivers/ata/ahci.c +1 -0
@@ -316,6 +316,7 @@ static struct device_attribute *ahci_shost_attrs[] = {static struct device_attribute *ahci_sdev_attrs[] = { &dev_attr_sw_activity, + &dev_attr_unload_heads,NULL };
drivers/ata/libata-core.c +1 -0
@@ -5264,6 +5264,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host)INIT_WORK (&ap->scsi_rescan_task, ata_scsi_dev_rescan);INIT_LIST_HEAD (&ap->eh_done_q);init_waitqueue_head (&ap->eh_wait_q); +init_completion (&ap->park_req_pending);init_timer_deferrable (&ap->fastdrain_timer); ap->fastdrain_timer.function = ata_eh_fastdrain_timerfn; ap->fastdrain_timer.data = (unsigned long )ap;
drivers/ata/libata-eh.c +125 -1
144 lines not on this page · raw message
drivers/ata/libata-scsi.c +108 -0
126 lines not on this page · raw message
include/linux/libata.h +11 -2
@@ -146,6 +146,7 @@ enum {ATA_DFLAG_SPUNDOWN = (1 <<14 ),/* XXX: for spindown_compat */ ATA_DFLAG_SLEEPING = (1 <<15 ),/* device is sleeping */ ATA_DFLAG_DUBIOUS_XFER = (1 <<16 ),/* data transfer not verified */ +ATA_DFLAG_NO_UNLOAD = (1 <<17 ),/* device doesn't support unload */ ATA_DFLAG_INIT_MASK = (1 <<24 ) -1 , ATA_DFLAG_DETACH = (1 << 24),
@@ -244,6 +245,7 @@ enum {ATA_TMOUT_BOOT =30000 ,/* heuristic */ ATA_TMOUT_BOOT_QUICK =7000 ,/* heuristic */ ATA_TMOUT_INTERNAL_QUICK =5000 , +ATA_TMOUT_MAX_PARK =30000 ,/* FIXME: GoVault needs 2s but we can't afford that without * parallel probing. 800ms is enough for iVDR disk
@@ -319,8 +321,9 @@ enum {ATA_EH_RESET =ATA_EH_SOFTRESET |ATA_EH_HARDRESET ,ATA_EH_ENABLE_LINK = (1 <<3 ),ATA_EH_LPM = (1 <<4 ),/* link power management action */ +ATA_EH_PARK = (1 <<5 ),/* unload heads and stop I/O */ -ATA_EH_PERDEV_MASK =ATA_EH_REVALIDATE , +ATA_EH_PERDEV_MASK =ATA_EH_REVALIDATE |ATA_EH_PARK ,/* ata_eh_info->flags */ ATA_EHI_HOTPLUGGED = (1 << 0), /* could have been hotplugged */
@@ -452,6 +455,7 @@ enum link_pm { MEDIUM_POWER, };extern struct device_attribute dev_attr_link_power_management_policy; +extern struct device_attribute dev_attr_unload_heads;extern struct device_attribute dev_attr_em_message_type;extern struct device_attribute dev_attr_em_message;extern struct device_attribute dev_attr_sw_activity;
@@ -564,6 +568,7 @@ struct ata_device {/* n_sector is used as CLEAR_OFFSET, read comment above CLEAR_OFFSET */ u64 n_sectors;/* size of device, if ATA */ unsigned int class;/* ATA_DEV_xxx */ +unsigned long unpark_deadline;u8 pio_mode;u8 dma_mode;
@@ -621,6 +626,7 @@ struct ata_eh_context { [ATA_EH_CMD_TIMEOUT_TABLE_SIZE ];unsigned int classes[ATA_MAX_DEVICES ];unsigned int did_probe_mask; +unsigned int unloaded_mask;unsigned int saved_ncq_enabled;u8 saved_xfer_mode[ATA_MAX_DEVICES ];/* timestamp for the last reset attempt or success */
@@ -709,6 +715,7 @@ struct ata_port {struct list_head eh_done_q;wait_queue_head_t eh_wait_q;int eh_tries; +struct completion park_req_pending;pm_message_t pm_mesg;int *pm_result;
@@ -1098,6 +1105,7 @@ extern void ata_std_error_handler(struct ata_port *ap);*/ extern const struct ata_port_operations ata_base_port_ops;extern const struct ata_port_operations sata_port_ops; +extern struct device_attribute *ata_common_sdev_attrs[];#define ATA_BASE_SHT (drv_name) \ .module = THIS_MODULE, \
@@ -1112,7 +1120,8 @@ extern const struct ata_port_operations sata_port_ops; .proc_name = drv_name, \ .slave_configure = ata_scsi_slave_config, \ .slave_destroy = ata_scsi_slave_destroy, \ - .bios_param = ata_std_bios_param + .bios_param = ata_std_bios_param, \ + .sdev_attrs = ata_common_sdev_attrs#define ATA_NCQ_SHT (drv_name) \ ATA_BASE_SHT(drv_name), \
Re: [PATCH 2/2 v5] libata: Implement disk shock protection support
Quoted 11 lines · Elias Oltmanns
On user request (through sysfs), the IDLE IMMEDIATE command with UNLOAD FEATURE as specified in ATA-7 is issued to the device and processing of the request queue is stopped thereafter until the specified timeout expires or user space asks to resume normal operation. This is supposed to prevent the heads of a hard drive from accidentally crashing onto the platter when a heavy shock is anticipated (like a falling laptop expected to hit the floor). In fact, the whole port stops processing commands until the timeout has expired in order to avoid any resets due to failed commands on another device.
Signed-off-by Elias Oltmanns <[email protected]>
Thanks.
Signature · 1 line
tejun
Re: [PATCH 1/2 v3] Introduce ata_id_has_unload()
In reply to Elias OltmannsQuoted 19 lines · Elias Oltmanns
Add a function to check an ATA device's id for head unload support as specified in ATA-7.
Signed-off-by Elias Oltmanns <[email protected]>---
include/linux/ata.h | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)include/linux/ata.h +2
-0@@ -707,6 +707,15 @@ static inline int ata_id_has_dword_io(const u16 *id)return 0 ; } +static inline int ata_id_has_unload (const u16 *id) +{
include/linux/ata.h static inline int ata_id_has_dword_io(const u16 *id) · line 721
Quoted 10 lines
include/linux/ata.h +7
-0+if (ata_id_major_version (id) >=7 && + (id[ATA_ID_CFSSE ] &0xC000 ) ==0x4000 && + id[ATA_ID_CFSSE ] & (1 <<13 )) +return 1 ; +return 0 ; +} +static inline int ata_id_current_chs_valid (const u16 *id) {/* For ATA-1 devices, if the INITIALIZE DEVICE PARAMETERS command
applied 1-2