Skip to contentSkip to conversation

new Power Management for libata

PATCH In review Tejun Heo 5 participants 39 messages Jun 12, 2006 – Jun 19, 2006

Subsystems (2)
lore
Share & tools
lore
author
#1 lore raw

PATCH 1/10 libata: power down controller only on PMSG_SUSPEND

In reply to Tejun Heo

The controller only needs to be powered down on PMSG_SUSPEND. Skip powering down for all other messages. This makes disk suspend prep cycle more efficient and helps controllers which have problems waking up from D3hot without intervening power removal.

---

 drivers/scsi/libata-core.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

85016ad86323924d10dc99ac9d7e9e5c0b967b8e

drivers/scsi/libata-core.c +4 -1
index 9a3bd15..51d3b4b 100644
@@ -5661,7 +5661,10 @@ int ata_pci_device_suspend(struct pci_de
 {
 	pci_save_state(pdev);
 	pci_disable_device(pdev);
-	pci_set_power_state(pdev, PCI_D3hot);
+
+	if (state.event == PM_EVENT_SUSPEND)
+		pci_set_power_state(pdev, PCI_D3hot);
+
 	return 0;
 }
 
Signature · 1 line
1.3.2

Tejun Heo

author
#0 lore raw

PATCH 1/1 new Power Management for libata

Hello, all.

This patchset implements new Power Management for libata. Currently, only controller-wide suspend and resume are supported. No per-device power management yet. Both memsleep and disksleep work on supported controllers.

All PM operations are performed by EH and thus fully synchronized w/ EH. Suspend/resume operations should be safe under all circumstances as long as libata is concerned. Attaching/detaching/exchanging devices while sleeping is allowed and handled correctly.

ata_piix, sata_sil and sata_sil24 are updated to use new PM. PM is tested on the following machines.

* ASUS P5LD2: sky2 disabled as it oopses on PM

O ICH7R in piix mode (advanced/compatible) O sil3112 PCI card
O sil3114 PCI card
O sil3124 PCI-x card on PCI slot
X sil3132 failed probably due to PCI-e PM problem

* Fujitsu lifebook P7120: enabled ATA_ENABLE_PATA and added entry for 0x266f in ata_piix pci table. Net console makes resume from memsleep fail.

O ICH6M in piix mode
O sil3112 PCMCIA card

This patchset contains 10 patches.

#01-04 prep for new PM
#05-06 implement new PM
#07-10 update LLDs

This patchset is against

upstream (aeb2ecd6096182cc080d37679080c0f088dcd4a4)
+ [1] kill-ATA_FLAG_SRST patch
+ [2] shift-ATA_FLAG_-bits patch

Jens, Mark, can you guys please test if this patch works on your notebooks? Note that AHCI isn't updated yet.

Zhao, can you port your AHCI PM stuff over this? This should solve the problem you talked about in the other mail. Recent changes update ahci such that it listens to more PHY events for hotplug and that causes EH to kick in after resuming. The original PM implementation didn't synchronize w/ EH and thus caused problems.

This patchset is for review only.

Thanks.

--
tejun

[1] http://marc.theaimsgroup.com/?l=linux-ide&m=115012501502940&w=2
[2] http://marc.theaimsgroup.com/?l=linux-ide&m=115012349728574&w=2

author
#4 lore raw

PATCH 2/10 libata: kill per-device PM

As new PM implementation will expand the existing controller-wide PM to trigger ATA bus wide PM operations, it collides with per-device PM. Kill per-device PM in preparation for new PM framework.

---

 drivers/scsi/ata_piix.c    |    2 -
 drivers/scsi/libata-core.c |   83 --------------------------------------------
 drivers/scsi/libata-scsi.c |   16 --------
 include/linux/libata.h     |    4 --
 4 files changed, 0 insertions(+), 105 deletions(-)

aa2de6bd3de34adcf6a736a70e88f90aba652c3b

drivers/scsi/ata_piix.c +0 -2
index 521b718..75aa47f 100644
@@ -220,8 +220,6 @@ static struct scsi_host_template piix_sh
 	.slave_configure	= ata_scsi_slave_config,
 	.slave_destroy		= ata_scsi_slave_destroy,
 	.bios_param		= ata_std_bios_param,
-	.resume			= ata_scsi_device_resume,
-	.suspend		= ata_scsi_device_suspend,
 };
 
 static const struct ata_port_operations piix_pata_ops = {
drivers/scsi/libata-core.c +0 -83

95 lines not on this page · raw message

drivers/scsi/libata-scsi.c +0 -16
index 45a49be..0c30e6c 100644
@@ -399,22 +399,6 @@ void ata_dump_status(unsigned id, struct
 	}
 }
 
-int ata_scsi_device_resume(struct scsi_device *sdev)
-{
-	struct ata_port *ap = ata_shost_to_port(sdev->host);
-	struct ata_device *dev = __ata_scsi_find_dev(ap, sdev);
-
-	return ata_device_resume(dev);
-}
-
-int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state)
-{
-	struct ata_port *ap = ata_shost_to_port(sdev->host);
-	struct ata_device *dev = __ata_scsi_find_dev(ap, sdev);
-
-	return ata_device_suspend(dev, state);
-}
-
 /**
  *	ata_to_sense_error - convert ATA error to SCSI error
  *	@id: ATA device number
include/linux/libata.h +0 -4
index 369f821..17c8ced 100644
@@ -657,10 +657,6 @@ extern int sata_scr_write(struct ata_por
 extern int sata_scr_write_flush(struct ata_port *ap, int reg, u32 val);
 extern int ata_port_online(struct ata_port *ap);
 extern int ata_port_offline(struct ata_port *ap);
-extern int ata_scsi_device_resume(struct scsi_device *);
-extern int ata_scsi_device_suspend(struct scsi_device *, pm_message_t state);
-extern int ata_device_resume(struct ata_device *);
-extern int ata_device_suspend(struct ata_device *, pm_message_t state);
 extern int ata_ratelimit(void);
 extern unsigned int ata_busy_sleep(struct ata_port *ap,
 				   unsigned long timeout_pat,
Signature · 1 line
1.3.2
author
#5 lore raw

PATCH 3/10 libata: move ata_do_simple_cmd() right below ata_exec_internal()

In reply to Tejun Heo

Move ata_do_simple_cmd() right below ata_exec_internal().

---

 drivers/scsi/libata-core.c |   46 ++++++++++++++++++++++----------------------
 1 files changed, 23 insertions(+), 23 deletions(-)

0b531e7f20027038fe1fb44e301fe0e4e88abbb8

drivers/scsi/libata-core.c +23 -23
index d9fdbbd..4fc8759 100644
@@ -1123,6 +1123,29 @@ unsigned ata_exec_internal(struct ata_de
 	return err_mask;
 }
 
+/*
+ * Execute a 'simple' command, that only consists of the opcode 'cmd' itself,
+ * without filling any other registers
+ */
+static int ata_do_simple_cmd(struct ata_device *dev, u8 cmd)
+{
+	struct ata_taskfile tf;
+	int err;
+
+	ata_tf_init(dev, &tf);
+
+	tf.command = cmd;
+	tf.flags |= ATA_TFLAG_DEVICE;
+	tf.protocol = ATA_PROT_NODATA;
+
+	err = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0);
+	if (err)
+		ata_dev_printk(dev, KERN_ERR, "%s: ata command failed: %d\n",
+			       __FUNCTION__, err);
+
+	return err;
+}
+
 /**
  *	ata_pio_need_iordy	-	check if iordy needed
  *	@adev: ATA device
@@ -4924,29 +4947,6 @@ int ata_port_offline(struct ata_port *ap
 	return 0;
 }
 
-/*
- * Execute a 'simple' command, that only consists of the opcode 'cmd' itself,
- * without filling any other registers
- */
-static int ata_do_simple_cmd(struct ata_device *dev, u8 cmd)
-{
-	struct ata_taskfile tf;
-	int err;
-
-	ata_tf_init(dev, &tf);
-
-	tf.command = cmd;
-	tf.flags |= ATA_TFLAG_DEVICE;
-	tf.protocol = ATA_PROT_NODATA;
-
-	err = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0);
-	if (err)
-		ata_dev_printk(dev, KERN_ERR, "%s: ata command failed: %d\n",
-			       __FUNCTION__, err);
-
-	return err;
-}
-
 /**
  *	ata_port_start - Set port up for dma.
  *	@ap: Port to initialize
Signature · 1 line
1.3.2
author
#6 lore raw

PATCH 4/10 libata: update ata_do_simple_cmd()

In reply to Tejun Heo

* export ata_do_simple_cmd() in drivers/scsi/libata.h
* add proper leading comment
* fix return value
* don't print error message. it's the caller's responsibility

This will be used by new PM.

---

 drivers/scsi/libata-core.c |   25 ++++++++++++++-----------
 drivers/scsi/libata.h      |    1 +
 2 files changed, 15 insertions(+), 11 deletions(-)

722e4a01585700ae416ae7c7a746fd6835ddae34

drivers/scsi/libata-core.c +14 -11
index 4fc8759..ba9f346 100644
@@ -1123,14 +1123,22 @@ unsigned ata_exec_internal(struct ata_de
 	return err_mask;
 }
 
-/*
- * Execute a 'simple' command, that only consists of the opcode 'cmd' itself,
- * without filling any other registers
+/*	ata_do_simple_cmd - execute simple internal command
+ *	@dev: Device to which the command is sent
+ *	@cmd: Opcode to execute
+ *
+ *	Execute a 'simple' command, that only consists of the opcode
+ *	'cmd' itself, without filling any other registers
+ *
+ *	LOCKING:
+ *	Kernel thread context (may sleep).
+ *
+ *	RETURNS:
+ *	Zero on success, AC_ERR_* mask on failure
  */
-static int ata_do_simple_cmd(struct ata_device *dev, u8 cmd)
+unsigned int ata_do_simple_cmd(struct ata_device *dev, u8 cmd)
 {
 	struct ata_taskfile tf;
-	int err;
 
 	ata_tf_init(dev, &tf);
 
@@ -1138,12 +1146,7 @@ static int ata_do_simple_cmd(struct ata_
 	tf.flags |= ATA_TFLAG_DEVICE;
 	tf.protocol = ATA_PROT_NODATA;
 
-	err = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0);
-	if (err)
-		ata_dev_printk(dev, KERN_ERR, "%s: ata command failed: %d\n",
-			       __FUNCTION__, err);
-
-	return err;
+	return ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0);
 }
 
 /**
drivers/scsi/libata.h +1 -0
index bdd4888..539b0b5 100644
@@ -50,6 +50,7 @@ extern void ata_port_flush_task(struct a
 extern unsigned ata_exec_internal(struct ata_device *dev,
 				  struct ata_taskfile *tf, const u8 *cdb,
 				  int dma_dir, void *buf, unsigned int buflen);
+extern unsigned int ata_do_simple_cmd(struct ata_device *dev, u8 cmd);
 extern int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
 			   int post_reset, u16 *id);
 extern int ata_dev_configure(struct ata_device *dev, int print_info);
Signature · 1 line
1.3.2
author
#27 lore raw

PATCH 8/10 sata_sil: add suspend/sleep support

In reply to Tejun Heo

Add suspend/sleep support.

---

 drivers/scsi/sata_sil.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

cfac09b587dd3913ebf3f75766a57559e75de672

drivers/scsi/sata_sil.c +13 -0
index 4bff260..bb63db2 100644
@@ -107,6 +107,7 @@ enum {
 };
 
 static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
+static int sil_pci_device_resume(struct pci_dev *pdev);
 static void sil_dev_config(struct ata_port *ap, struct ata_device *dev);
 static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg);
 static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
@@ -158,6 +159,8 @@ static struct pci_driver sil_pci_driver 
 	.id_table		= sil_pci_tbl,
 	.probe			= sil_init_one,
 	.remove			= ata_pci_remove_one,
+	.suspend		= ata_pci_device_suspend,
+	.resume			= sil_pci_device_resume,
 };
 
 static struct scsi_host_template sil_sht = {
@@ -660,6 +663,16 @@ err_out:
 	return rc;
 }
 
+static int sil_pci_device_resume(struct pci_dev *pdev)
+{
+	struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
+
+	sil_init_controller(pdev, host_set->n_ports, host_set->ports[0]->flags,
+			    host_set->mmio_base);
+
+	return ata_pci_device_resume(pdev);
+}
+
 static int __init sil_init(void)
 {
 	return pci_module_init(&sil_pci_driver);
Signature · 1 line
1.3.2
author
#7 lore raw

PATCH 5/10 libata: implement new EH action ATA_EH_SPINUP

In reply to Tejun Heo

Implement new EH action ATA_EH_SPINUP. This will be used by new PM implementation.

---

 drivers/scsi/libata-eh.c |   36 ++++++++++++++++++++++++++++++++++++
 include/linux/libata.h   |    1 +
 2 files changed, 37 insertions(+), 0 deletions(-)

c0a5ccaf24b0acc3e03c4b265ef6495db36623ae

drivers/scsi/libata-eh.c +36 -0
index 531a4e1..8711e83 100644
@@ -1585,6 +1585,37 @@ static int ata_eh_revalidate_and_attach(
 	return rc;
 }
 
+static int ata_eh_spinup(struct ata_port *ap, struct ata_device **r_failed_dev)
+{
+	struct ata_eh_context *ehc = &ap->eh_context;
+	struct ata_device *dev;
+	unsigned int err_mask = 0;
+	int i;
+
+	if (!(ehc->i.action & ATA_EH_SPINUP))
+		return 0;
+
+	for (i = 0; i < ATA_MAX_DEVICES; i++) {
+		dev = &ap->device[i];
+
+		if (dev->class != ATA_DEV_ATA)
+			continue;
+
+		ata_eh_about_to_do(ap, ATA_EH_SPINUP);
+		err_mask = ata_do_simple_cmd(dev, ATA_CMD_IDLEIMMEDIATE);
+		if (err_mask)
+			break;
+	}
+
+	if (err_mask == 0) {
+		ehc->i.action &= ~ATA_EH_SPINUP;
+		return 0;
+	} else {
+		*r_failed_dev = dev;
+		return -EIO;
+	}
+}
+
 static int ata_port_nr_enabled(struct ata_port *ap)
 {
 	int i, cnt = 0;
@@ -1711,6 +1742,11 @@ static int ata_eh_recover(struct ata_por
 	if (rc)
 		goto dev_fail;
 
+	/* spin up if requested */
+	rc = ata_eh_spinup(ap, &dev);
+	if (rc)
+		goto dev_fail;
+
 	/* configure transfer mode if the port has been reset */
 	if (ehc->i.flags & ATA_EHI_DID_RESET) {
 		rc = ata_set_mode(ap, &dev);
include/linux/libata.h +1 -0
index 17c8ced..e5ff148 100644
@@ -246,6 +246,7 @@ enum {
 	ATA_EH_REVALIDATE	= (1 << 0),
 	ATA_EH_SOFTRESET	= (1 << 1),
 	ATA_EH_HARDRESET	= (1 << 2),
+	ATA_EH_SPINUP		= (1 << 3),
 
 	ATA_EH_RESET_MASK	= ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
 
Signature · 1 line
1.3.2
author
#11 lore raw

PATCH 6/10 libata: implement new Power Management framework

In reply to Tejun Heo

Implement new Power Management framework. All PM operations are bus-wide and performed by EH. ata_host_set_suspend() and ata_host_set_resume() are used to request PM suspend and resume on all ports of a host_set. PCI suspend/resume callbacks calls these two functions for each host_set the controller implements.

Suspend is performed parallely on all ports of a host_set and resume is done parallely in background to decrease the time necessary before responding to user.

New PM is fully synchronized w/ all other EH events and it's safe to suspend and resume any time. All the usual EH stuff is performed on resume and removing device or exchanging them while suspended shouldn't cause any trouble for libata.

---

 drivers/scsi/libata-core.c |  140 ++++++++++++++++++++++++++++++++++++++++--
 drivers/scsi/libata-eh.c   |  148 +++++++++++++++++++++++++++++++++++++++++++-
 include/linux/libata.h     |    7 ++
 3 files changed, 286 insertions(+), 9 deletions(-)

240ed4c86ceaf789e40f638a63402d60e7c0555c

drivers/scsi/libata-core.c +134 -6
index ba9f346..0ee7ab4 100644
@@ -70,6 +70,7 @@ static unsigned int ata_dev_init_params(
 					u16 heads, u16 sectors);
 static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
 static void ata_dev_xfermask(struct ata_device *dev);
+static int ata_host_set_resume(struct ata_host_set *host_set);
 
 static unsigned int ata_unique_id = 1;
 static struct workqueue_struct *ata_wq;
@@ -4950,6 +4951,104 @@ int ata_port_offline(struct ata_port *ap
 	return 0;
 }
 
+static void ata_host_set_request_pm(struct ata_host_set *host_set,
+				    pm_message_t mesg)
+{
+	int i;
+
+	for (i = 0; i < host_set->n_ports; i++) {
+		struct ata_port *ap = host_set->ports[i];
+		unsigned long flags;
+
+		spin_lock_irqsave(&ap->host_set->lock, flags);
+
+		/* Previous resume operation might still be in
+		 * progress.  Wait for PM_PENDING to clear.
+		 */
+		while (ap->flags & ATA_FLAG_PM_PENDING) {
+			spin_unlock_irqrestore(&ap->host_set->lock, flags);
+			ata_port_wait_eh(ap);
+			spin_lock_irqsave(&ap->host_set->lock, flags);
+		}
+
+		/* request PM ops to EH */
+		ap->flags |= ATA_FLAG_PM_PENDING;
+		ap->pm_mesg = mesg;
+		ap->pm_result = 0;
+		ata_port_schedule_eh(ap);
+
+		spin_unlock_irqrestore(&ap->host_set->lock, flags);
+	}
+}
+
+static int ata_host_set_wait_pm(struct ata_host_set *host_set)
+{
+	int i, rc = 0;
+
+	for (i = 0; i < host_set->n_ports; i++) {
+		struct ata_port *ap = host_set->ports[i];
+
+		ata_port_wait_eh(ap);
+		WARN_ON(ap->flags & ATA_FLAG_PM_PENDING);
+
+		if (ap->pm_result)
+			rc = ap->pm_result;
+	}
+
+	return rc;
+}
+
+/**
+ *	ata_host_set_suspend - suspend host_set
+ *	@host_set: host_set to suspend
+ *	@mesg: PM message
+ *
+ *	Suspend @host_set.  Actual operation is performed by EH.  This
+ *	function requests EH to perform PM operations and waits for EH
+ *	to finish.
+ *
+ *	LOCKING:
+ *	Kernel thread context (may sleep).
+ *
+ *	RETURNS:
+ *	0 on success, -errno on failure.
+ */
+static int ata_host_set_suspend(struct ata_host_set *host_set,
+				pm_message_t mesg)
+{
+	int rc;
+
+	ata_host_set_request_pm(host_set, mesg);
+	rc = ata_host_set_wait_pm(host_set);
+
+	host_set->dev->power.power_state = mesg;
+	if (rc)
+		ata_host_set_resume(host_set);
+
+	return rc;
+}
+
+/**
+ *	ata_host_set_resume - resume host_set
+ *	@host_set: host_set to resume
+ *
+ *	Resume @host_set.  Actual operation is performed by EH.  This
+ *	function requests EH to perform PM operations and returns.
+ *	Note that all resume operations are performed parallely.
+ *
+ *	LOCKING:
+ *	Kernel thread context (may sleep).
+ *
+ *	RETURNS:
+ *	0.
+ */
+static int ata_host_set_resume(struct ata_host_set *host_set)
+{
+	ata_host_set_request_pm(host_set, PMSG_ON);
+	host_set->dev->power.power_state = PMSG_ON;
+	return 0;
+}
+
 /**
  *	ata_port_start - Set port up for dma.
  *	@ap: Port to initialize
@@ -5584,22 +5683,51 @@ int pci_test_config_bits(struct pci_dev 
 
 int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state)
 {
-	pci_save_state(pdev);
-	pci_disable_device(pdev);
+	struct ata_host_set *first_hset = dev_get_drvdata(&pdev->dev);
+	struct ata_host_set *host_set;
+	int rc = 0;
+
+	for (host_set = first_hset; host_set; host_set = host_set->next) {
+		rc = ata_host_set_suspend(host_set, state);
+		if (rc)
+			break;
+	}
 
-	if (state.event == PM_EVENT_SUSPEND)
-		pci_set_power_state(pdev, PCI_D3hot);
+	if (rc == 0) {
+		pci_save_state(pdev);
+		pci_disable_device(pdev);
 
-	return 0;
+		if (state.event == PM_EVENT_SUSPEND)
+			pci_set_power_state(pdev, PCI_D3hot);
+	} else {
+		/* Resume the first host_set too if the second one
+		 * failed to sleep.
+		 */
+		if (host_set != first_hset)
+			ata_host_set_resume(first_hset);
+	}
+
+	return rc;
 }
 
 int ata_pci_device_resume(struct pci_dev *pdev)
 {
+	struct ata_host_set *first_hset = dev_get_drvdata(&pdev->dev);
+	struct ata_host_set *host_set;
+	int tmp, rc = 0;
+
 	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev);
 	pci_enable_device(pdev);
 	pci_set_master(pdev);
-	return 0;
+
+	for (host_set = first_hset; host_set; host_set = host_set->next) {
+		tmp = ata_host_set_resume(host_set);
+		if (tmp)
+			rc = tmp;
+	}
+
+	return rc;
 }
 #endif /* CONFIG_PCI */
 
drivers/scsi/libata-eh.c +145 -3

164 lines not on this page · raw message

include/linux/libata.h +7 -0
index e5ff148..267f3d8 100644
@@ -172,6 +172,7 @@ enum {
 
 	ATA_FLAG_DISABLED	= (1 << 21), /* port is disabled, ignore it */
 	ATA_FLAG_SUSPENDED	= (1 << 22), /* port is suspended (power) */
+	ATA_FLAG_PM_PENDING	= (1 << 23), /* PM event pending */
 
 	/* bits 24:31 of ap->flags are reserved for LLDD specific flags */
 
@@ -531,6 +532,9 @@ struct ata_port {
 	struct list_head	eh_done_q;
 	wait_queue_head_t	eh_wait_q;
 
+	pm_message_t		pm_mesg;
+	int			pm_result;
+
 	void			*private_data;
 
 	u8			sector_buf[ATA_SECT_SIZE]; /* owned by EH */
@@ -585,6 +589,9 @@ struct ata_port_operations {
 	void (*scr_write) (struct ata_port *ap, unsigned int sc_reg,
 			   u32 val);
 
+	int (*suspend) (struct ata_port *ap, pm_message_t mesg);
+	int (*resume) (struct ata_port *ap);
+
 	int (*port_start) (struct ata_port *ap);
 	void (*port_stop) (struct ata_port *ap);
 
Signature · 1 line
1.3.2
author
#26 lore raw

PATCH 7/10 sata_sil: separate out sil_init_controller()

In reply to Tejun Heo

Separate out controller initialization from sil_init_one() into sil_init_controller(). This will be used by resume.

---

 drivers/scsi/sata_sil.c |   86 ++++++++++++++++++++++++++---------------------
 1 files changed, 48 insertions(+), 38 deletions(-)

6b3d220117016445f055a0244516cb5de4c8dbe9

drivers/scsi/sata_sil.c +48 -38
index a7e99a1..4bff260 100644
@@ -526,6 +526,52 @@ static void sil_dev_config(struct ata_po
 	}
 }
 
+static void sil_init_controller(struct pci_dev *pdev,
+				int n_ports, unsigned long host_flags,
+				void __iomem *mmio_base)
+{
+	u8 cls;
+	u32 tmp;
+	int i;
+
+	/* Initialize FIFO PCI bus arbitration */
+	cls = sil_get_device_cache_line(pdev);
+	if (cls) {
+		cls >>= 3;
+		cls++;  /* cls = (line_size/8)+1 */
+		for (i = 0; i < n_ports; i++)
+			writew(cls << 8 | cls,
+			       mmio_base + sil_port[i].fifo_cfg);
+	} else
+		dev_printk(KERN_WARNING, &pdev->dev,
+			   "cache line size not set.  Driver may not function\n");
+
+	/* Apply R_ERR on DMA activate FIS errata workaround */
+	if (host_flags & SIL_FLAG_RERR_ON_DMA_ACT) {
+		int cnt;
+
+		for (i = 0, cnt = 0; i < n_ports; i++) {
+			tmp = readl(mmio_base + sil_port[i].sfis_cfg);
+			if ((tmp & 0x3) != 0x01)
+				continue;
+			if (!cnt)
+				dev_printk(KERN_INFO, &pdev->dev,
+					   "Applying R_ERR on DMA activate "
+					   "FIS errata fix\n");
+			writel(tmp & ~0x3, mmio_base + sil_port[i].sfis_cfg);
+			cnt++;
+		}
+	}
+
+	if (n_ports == 4) {
+		/* flip the magic "make 4 ports work" bit */
+		tmp = readl(mmio_base + sil_port[2].bmdma);
+		if ((tmp & SIL_INTR_STEERING) == 0)
+			writel(tmp | SIL_INTR_STEERING,
+			       mmio_base + sil_port[2].bmdma);
+	}
+}
+
 static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	static int printed_version;
@@ -535,8 +581,6 @@ static int sil_init_one (struct pci_dev 
 	int rc;
 	unsigned int i;
 	int pci_dev_busy = 0;
-	u32 tmp;
-	u8 cls;
 
 	if (!printed_version++)
 		dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
@@ -595,42 +639,8 @@ static int sil_init_one (struct pci_dev 
 		ata_std_ports(&probe_ent->port[i]);
 	}
 
-	/* Initialize FIFO PCI bus arbitration */
-	cls = sil_get_device_cache_line(pdev);
-	if (cls) {
-		cls >>= 3;
-		cls++;  /* cls = (line_size/8)+1 */
-		for (i = 0; i < probe_ent->n_ports; i++)
-			writew(cls << 8 | cls,
-			       mmio_base + sil_port[i].fifo_cfg);
-	} else
-		dev_printk(KERN_WARNING, &pdev->dev,
-			   "cache line size not set.  Driver may not function\n");
-
-	/* Apply R_ERR on DMA activate FIS errata workaround */
-	if (probe_ent->host_flags & SIL_FLAG_RERR_ON_DMA_ACT) {
-		int cnt;
-
-		for (i = 0, cnt = 0; i < probe_ent->n_ports; i++) {
-			tmp = readl(mmio_base + sil_port[i].sfis_cfg);
-			if ((tmp & 0x3) != 0x01)
-				continue;
-			if (!cnt)
-				dev_printk(KERN_INFO, &pdev->dev,
-					   "Applying R_ERR on DMA activate "
-					   "FIS errata fix\n");
-			writel(tmp & ~0x3, mmio_base + sil_port[i].sfis_cfg);
-			cnt++;
-		}
-	}
-
-	if (ent->driver_data == sil_3114) {
-		/* flip the magic "make 4 ports work" bit */
-		tmp = readl(mmio_base + sil_port[2].bmdma);
-		if ((tmp & SIL_INTR_STEERING) == 0)
-			writel(tmp | SIL_INTR_STEERING,
-			       mmio_base + sil_port[2].bmdma);
-	}
+	sil_init_controller(pdev, probe_ent->n_ports, probe_ent->host_flags,
+			    mmio_base);
 
 	pci_set_master(pdev);
 
Signature · 1 line
1.3.2
author
#28 lore raw

PATCH 9/10 sata_sil24: separate out sil24_init_controller()

In reply to Tejun Heo

Separate out controller initialization from sil24_init_one() into sil24_init_controller(). This will be used by resume.

---

 drivers/scsi/sata_sil24.c |  107 ++++++++++++++++++++++++++-------------------
 1 files changed, 62 insertions(+), 45 deletions(-)

d7124568707660f0a347a158051cf7533478edcf

drivers/scsi/sata_sil24.c +62 -45
index c8b477c..7726e6e 100644
@@ -988,6 +988,64 @@ static void sil24_host_stop(struct ata_h
 	kfree(hpriv);
 }
 
+static void sil24_init_controller(struct pci_dev *pdev, int n_ports,
+				  unsigned long host_flags,
+				  void __iomem *host_base,
+				  void __iomem *port_base)
+{
+	u32 tmp;
+	int i;
+
+	/* GPIO off */
+	writel(0, host_base + HOST_FLASH_CMD);
+
+	/* clear global reset & mask interrupts during initialization */
+	writel(0, host_base + HOST_CTRL);
+
+	/* init ports */
+	for (i = 0; i < n_ports; i++) {
+		void __iomem *port = port_base + i * PORT_REGS_SIZE;
+
+		/* Initial PHY setting */
+		writel(0x20c, port + PORT_PHY_CFG);
+
+		/* Clear port RST */
+		tmp = readl(port + PORT_CTRL_STAT);
+		if (tmp & PORT_CS_PORT_RST) {
+			writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR);
+			tmp = ata_wait_register(port + PORT_CTRL_STAT,
+						PORT_CS_PORT_RST,
+						PORT_CS_PORT_RST, 10, 100);
+			if (tmp & PORT_CS_PORT_RST)
+				dev_printk(KERN_ERR, &pdev->dev,
+				           "failed to clear port RST\n");
+		}
+
+		/* Configure IRQ WoC */
+		if (host_flags & SIL24_FLAG_PCIX_IRQ_WOC)
+			writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_STAT);
+		else
+			writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_CLR);
+
+		/* Zero error counters. */
+		writel(0x8000, port + PORT_DECODE_ERR_THRESH);
+		writel(0x8000, port + PORT_CRC_ERR_THRESH);
+		writel(0x8000, port + PORT_HSHK_ERR_THRESH);
+		writel(0x0000, port + PORT_DECODE_ERR_CNT);
+		writel(0x0000, port + PORT_CRC_ERR_CNT);
+		writel(0x0000, port + PORT_HSHK_ERR_CNT);
+
+		/* Always use 64bit activation */
+		writel(PORT_CS_32BIT_ACTV, port + PORT_CTRL_CLR);
+
+		/* Clear port multiplier enable and resume bits */
+		writel(PORT_CS_PM_EN | PORT_CS_RESUME, port + PORT_CTRL_CLR);
+	}
+
+	/* Turn on interrupts */
+	writel(IRQ_STAT_4PORTS, host_base + HOST_CTRL);
+}
+
 static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	static int printed_version = 0;
@@ -1076,9 +1134,6 @@ static int sil24_init_one(struct pci_dev
 		}
 	}
 
-	/* GPIO off */
-	writel(0, host_base + HOST_FLASH_CMD);
-
 	/* Apply workaround for completion IRQ loss on PCI-X errata */
 	if (probe_ent->host_flags & SIL24_FLAG_PCIX_IRQ_WOC) {
 		tmp = readl(host_base + HOST_CTRL);
@@ -1090,56 +1145,18 @@ static int sil24_init_one(struct pci_dev
 			probe_ent->host_flags &= ~SIL24_FLAG_PCIX_IRQ_WOC;
 	}
 
-	/* clear global reset & mask interrupts during initialization */
-	writel(0, host_base + HOST_CTRL);
-
 	for (i = 0; i < probe_ent->n_ports; i++) {
-		void __iomem *port = port_base + i * PORT_REGS_SIZE;
-		unsigned long portu = (unsigned long)port;
+		unsigned long portu =
+			(unsigned long)port_base + i * PORT_REGS_SIZE;
 
 		probe_ent->port[i].cmd_addr = portu;
 		probe_ent->port[i].scr_addr = portu + PORT_SCONTROL;
 
 		ata_std_ports(&probe_ent->port[i]);
-
-		/* Initial PHY setting */
-		writel(0x20c, port + PORT_PHY_CFG);
-
-		/* Clear port RST */
-		tmp = readl(port + PORT_CTRL_STAT);
-		if (tmp & PORT_CS_PORT_RST) {
-			writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR);
-			tmp = ata_wait_register(port + PORT_CTRL_STAT,
-						PORT_CS_PORT_RST,
-						PORT_CS_PORT_RST, 10, 100);
-			if (tmp & PORT_CS_PORT_RST)
-				dev_printk(KERN_ERR, &pdev->dev,
-				           "failed to clear port RST\n");
-		}
-
-		/* Configure IRQ WoC */
-		if (probe_ent->host_flags & SIL24_FLAG_PCIX_IRQ_WOC)
-			writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_STAT);
-		else
-			writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_CLR);
-
-		/* Zero error counters. */
-		writel(0x8000, port + PORT_DECODE_ERR_THRESH);
-		writel(0x8000, port + PORT_CRC_ERR_THRESH);
-		writel(0x8000, port + PORT_HSHK_ERR_THRESH);
-		writel(0x0000, port + PORT_DECODE_ERR_CNT);
-		writel(0x0000, port + PORT_CRC_ERR_CNT);
-		writel(0x0000, port + PORT_HSHK_ERR_CNT);
-
-		/* Always use 64bit activation */
-		writel(PORT_CS_32BIT_ACTV, port + PORT_CTRL_CLR);
-
-		/* Clear port multiplier enable and resume bits */
-		writel(PORT_CS_PM_EN | PORT_CS_RESUME, port + PORT_CTRL_CLR);
 	}
 
-	/* Turn on interrupts */
-	writel(IRQ_STAT_4PORTS, host_base + HOST_CTRL);
+	sil24_init_controller(pdev, probe_ent->n_ports, probe_ent->host_flags,
+			      host_base, port_base);
 
 	pci_set_master(pdev);
 
Signature · 1 line
1.3.2
author
#29 lore raw

PATCH 10/10 sata_sil24: add suspend/sleep support

In reply to Tejun Heo

Add suspend/sleep support.

---

 drivers/scsi/sata_sil24.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

79fd0e52c2c53999865a61f160919a0a6308dbc8

drivers/scsi/sata_sil24.c +19 -0
index 7726e6e..8c438ba 100644
@@ -92,6 +92,7 @@ enum {
 	HOST_CTRL_STOP		= (1 << 18), /* latched PCI STOP */
 	HOST_CTRL_DEVSEL	= (1 << 19), /* latched PCI DEVSEL */
 	HOST_CTRL_REQ64		= (1 << 20), /* latched PCI REQ64 */
+	HOST_CTRL_GLOBAL_RST	= (1 << 31), /* global reset */
 
 	/*
 	 * Port registers
@@ -338,6 +339,7 @@ static int sil24_port_start(struct ata_p
 static void sil24_port_stop(struct ata_port *ap);
 static void sil24_host_stop(struct ata_host_set *host_set);
 static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
+static int sil24_pci_device_resume(struct pci_dev *pdev);
 
 static const struct pci_device_id sil24_pci_tbl[] = {
 	{ 0x1095, 0x3124, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3124 },
@@ -353,6 +355,8 @@ static struct pci_driver sil24_pci_drive
 	.id_table		= sil24_pci_tbl,
 	.probe			= sil24_init_one,
 	.remove			= ata_pci_remove_one, /* safe? */
+	.suspend		= ata_pci_device_suspend,
+	.resume			= sil24_pci_device_resume,
 };
 
 static struct scsi_host_template sil24_sht = {
@@ -1179,6 +1183,21 @@ static int sil24_init_one(struct pci_dev
 	return rc;
 }
 
+static int sil24_pci_device_resume(struct pci_dev *pdev)
+{
+	struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
+	struct sil24_host_priv *hpriv = host_set->private_data;
+
+	if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND)
+		writel(HOST_CTRL_GLOBAL_RST, hpriv->host_base + HOST_CTRL);
+
+	sil24_init_controller(pdev, host_set->n_ports,
+			      host_set->ports[0]->flags,
+			      hpriv->host_base, hpriv->port_base);
+
+	return ata_pci_device_resume(pdev);
+}
+
 static int __init sil24_init(void)
 {
 	return pci_module_init(&sil24_pci_driver);
Signature · 1 line
1.3.2
#12 lore raw

Re: [PATCH 06/10] libata: implement new Power Management framework

In reply to Tejun Heo

Ar Maw, 2006-06-13 am 00:50 +0900, ysgrifennodd Tejun Heo:

Quoted 3 lines

Suspend is performed parallely on all ports of a host_set and resume is done parallely in background to decrease the time necessary before responding to user.

Do we need a disk count here - some large disk setups rely on the fact drives don't all spin up at once to avoid overloading the PSU ?

Something like four disk spinups at a time ought to avoid biting anyone too badly and would mean normal users saw a parallel spinup.

Alan

#2 lore raw

Re: [PATCH 01/10] libata: power down controller only on PMSG_SUSPEND

In reply to Tejun Heo
Quoted 18 lines · Tejun Heo

The controller only needs to be powered down on PMSG_SUSPEND. Skip powering down for all other messages. This makes disk suspend prep cycle more efficient and helps controllers which have problems waking up from D3hot without intervening power removal.

---

 drivers/scsi/libata-core.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

85016ad86323924d10dc99ac9d7e9e5c0b967b8e

drivers/scsi/libata-core.c +0 -0
index 9a3bd15..51d3b4b 100644

drivers/scsi/libata-core.c int ata_pci_device_suspend(struct pci_de · line 5666

Quoted 7 lines
drivers/scsi/libata-core.c +3 -1
@@ -5661,7 +5661,10 @@ int ata_pci_device_suspend(struct pci_de
 {
 	pci_save_state(pdev);
 	pci_disable_device(pdev);
-	pci_set_power_state(pdev, PCI_D3hot);
+
+	if (state.event == PM_EVENT_SUSPEND)
+		pci_set_power_state(pdev, PCI_D3hot);

If this change makes sense for the D0->D3 transition, surely it would make sense to cover the other operations (save-state, disable) as well?

Jeff

author
#13 lore raw

Re: [PATCH 06/10] libata: implement new Power Management framework

In reply to Alan Cox
Quoted 7 lines · Alan Cox

Ar Maw, 2006-06-13 am 00:50 +0900, ysgrifennodd Tejun Heo:

Quoted 3 lines

Suspend is performed parallely on all ports of a host_set and resume is done parallely in background to decrease the time necessary before responding to user.

Do we need a disk count here - some large disk setups rely on the fact drives don't all spin up at once to avoid overloading the PSU ?

For most desktops and notebooks, it doesn't really matter as power is removed from disks during memsleep and they all spin up immediately after resume regardless of what libata does. For external enclosures with separate power supply, limiting the number of concurrent spinups during resume is necessary though.

I think we need to make a central disk spinup limiter to control the number of concurrent spinups across both ATA and SCSI. SATA staggered spinup should be considered too. Depending on situation, a drive may spin up on power up, PHY ready or IDLE_IMM after resuming from memsleep.

FWIW, my cheapo 325w PSU (< 30USD) hasn't had any problem spinning up 11 drives simultaneously.

I think it's okay to leave it as it is for the time being. It's not like people w/ external enclosures use suspend/resume a lot.

Signature · 1 line
tejun
author
#3 lore raw

Re: [PATCH 01/10] libata: power down controller only on PMSG_SUSPEND

In reply to Jeff Garzik
Quoted 13 lines · Jeff Garzik
Quoted 12 lines · Tejun Heo

The controller only needs to be powered down on PMSG_SUSPEND. Skip powering down for all other messages. This makes disk suspend prep cycle more efficient and helps controllers which have problems waking up from D3hot without intervening power removal.

---

 drivers/scsi/libata-core.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
Quoted 15 lines

drivers/scsi/libata-core.c int ata_pci_device_suspend(struct pci_de · line 5666

Quoted 13 lines

85016ad86323924d10dc99ac9d7e9e5c0b967b8e

drivers/scsi/libata-core.c +3 -1
index 9a3bd15..51d3b4b 100644
@@ -5661,7 +5661,10 @@ int ata_pci_device_suspend(struct pci_de
 {
     pci_save_state(pdev);
     pci_disable_device(pdev);
-    pci_set_power_state(pdev, PCI_D3hot);
+
+    if (state.event == PM_EVENT_SUSPEND)
+        pci_set_power_state(pdev, PCI_D3hot);

If this change makes sense for the D0->D3 transition, surely it would make sense to cover the other operations (save-state, disable) as well?

It probably makes sense for disable but not for save-state. Swsusp takes snapshot of memory after freezing all devices and resumes again to write the snapshot. Resume must be able to reinitialize the hardware from scratch and it depends on PCI config regs saved w/ pci_save_state(). So, state must be saved during freeze.

I'll put pci_disable_device() in the if clause and retest. That should work.

Signature · 1 line
tejun
#14 lore raw

Re: [PATCH 06/10] libata: implement new Power Management framework

In reply to Tejun Heo
Quoted 5 lines · Tejun Heo
drivers/scsi/libata-core.c +0 -1
@@ -5584,22 +5683,51 @@ int pci_test_config_bits(struct pci_dev 
 
 int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state)
 {
-	pci_save_state(pdev);

drivers/scsi/libata-core.c int pci_test_config_bits(struct pci_dev · line 5694

Quoted 10 lines
drivers/scsi/libata-core.c +9 -1
-	pci_disable_device(pdev);
+	struct ata_host_set *first_hset = dev_get_drvdata(&pdev->dev);
+	struct ata_host_set *host_set;
+	int rc = 0;
+
+	for (host_set = first_hset; host_set; host_set = host_set->next) {
+		rc = ata_host_set_suspend(host_set, state);
+		if (rc)
+			break;
+	}

My original understanding is that a host_set represents a physical SATA controller in a PCI slot. In which case will a SATA controller include multiple host_set?

Forrest

#31 lore raw
In reply to Tejun Heo
Quoted 6 lines · Tejun Heo

Zhao, can you port your AHCI PM stuff over this? This should solve the problem you talked about in the other mail. Recent changes update ahci such that it listens to more PHY events for hotplug and that causes EH to kick in after resuming. The original PM implementation didn't synchronize w/ EH and thus caused problems.

I'm doing the porting work, but not sure if I should send out patch ASAP, or not send it out until your PM patches are merged into #upstream.

Forrest

#17 lore raw

Re: [PATCH 06/10] libata: implement new Power Management framework

In reply to Tejun Heo
Quoted 23 lines · Tejun Heo

int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state) {

drivers/scsi/libata-core.c +14 -5
-	pci_save_state(pdev);
-	pci_disable_device(pdev);
+	struct ata_host_set *first_hset = dev_get_drvdata(&pdev->dev);
+	struct ata_host_set *host_set;
+	int rc = 0;
+
+	for (host_set = first_hset; host_set; host_set = host_set->next) {
+		rc = ata_host_set_suspend(host_set, state);
+		if (rc)
+			break;
+	}
 
-	if (state.event == PM_EVENT_SUSPEND)
-		pci_set_power_state(pdev, PCI_D3hot);
+	if (rc == 0) {
+		pci_save_state(pdev);
+		pci_disable_device(pdev);
 
-	return 0;
+		if (state.event == PM_EVENT_SUSPEND)
+			pci_set_power_state(pdev, PCI_D3hot);

drivers/scsi/libata-core.c int pci_test_config_bits(struct pci_dev · line 5711

Quoted 10 lines
drivers/scsi/libata-core.c +9 -0
+	} else {
+		/* Resume the first host_set too if the second one
+		 * failed to sleep.
+		 */
+		if (host_set != first_hset)
+			ata_host_set_resume(first_hset);
+	}
+
+	return rc;
 }

Is it possible to add a callback in ata_pci_device_suspend() to do controller-level operation before calling pci_save_state()......? One possible solution is to put this callback into a structure together with host_set.
Otherwise user-defined ahci_pci_device_suspend() will duplicate most code of ata_pci_device_suspend().

Thanks,
Forrest

#21 lore raw

Re: [PATCH 06/10] libata: implement new Power Management framework

In reply to Tejun Heo
Quoted 12 lines · Tejun Heo

int ata_pci_device_resume(struct pci_dev *pdev)
{

drivers/scsi/libata-core.c +4 -1
+	struct ata_host_set *first_hset = dev_get_drvdata(&pdev->dev);
+	struct ata_host_set *host_set;
+	int tmp, rc = 0;
+
 	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev);
 	pci_enable_device(pdev);
 	pci_set_master(pdev);
-	return 0;

drivers/scsi/libata-core.c int pci_test_config_bits(struct pci_dev · line 5732

Quoted 10 lines
drivers/scsi/libata-core.c +8 -0
+
+	for (host_set = first_hset; host_set; host_set = host_set->next) {
+		tmp = ata_host_set_resume(host_set);
+		if (tmp)
+			rc = tmp;
+	}
+
+	return rc;
 }
 #endif /* CONFIG_PCI */

Similar here. Is it possible to introduce two controller-level callbacks, say ->pre_resume(), which is called before pci_set_power_state(), ->post_resume(), which is called after for() loop? This is needed by AHCI resume. Otherwise most code of ata_pci_device_resume() will be duplicated in ahci_pci_device_resume(). Another point is for AHCI resume we need to wait the resume operation of all ports to complete before calling ->post_resume().

Thanks,
Forrest

author
#15 lore raw

Re: [PATCH 06/10] libata: implement new Power Management framework

In reply to zhao, forrest
Quoted 12 lines · forrest
Quoted 11 lines · Tejun Heo
drivers/scsi/libata-core.c +5 -2
@@ -5584,22 +5683,51 @@ int pci_test_config_bits(struct pci_dev 
 
 int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state)
 {
-	pci_save_state(pdev);
-	pci_disable_device(pdev);
+	struct ata_host_set *first_hset = dev_get_drvdata(&pdev->dev);
+	struct ata_host_set *host_set;
+	int rc = 0;
+
+	for (host_set = first_hset; host_set; host_set = host_set->next) {
Quoted 8 lines

drivers/scsi/libata-core.c int pci_test_config_bits(struct pci_dev · line 5694

Quoted 4 lines
drivers/scsi/libata-core.c +4 -0
+		rc = ata_host_set_suspend(host_set, state);
+		if (rc)
+			break;
+	}

My original understanding is that a host_set represents a physical SATA controller in a PCI slot. In which case will a SATA controller include multiple host_set?

Please read ata_pci_init_one() and ata_pci_init_legacy_port() in libata-bmdma.c. It's for IDE controllers in legacy mode (not native PCI) mode.

Signature · 1 line
tejun
author
#18 lore raw

Re: [PATCH 06/10] libata: implement new Power Management framework

In reply to zhao, forrest
Quoted 6 lines · forrest

Is it possible to add a callback in ata_pci_device_suspend() to do controller-level operation before calling pci_save_state()......? One possible solution is to put this callback into a structure together with host_set.
Otherwise user-defined ahci_pci_device_suspend() will duplicate most code of ata_pci_device_suspend().

If a LLD wants to do controller specific things, define its own device_suspend/resume() routines and call ata_pci_device_*() from those functions after doing controller-specific stuff. Please read how sil_pci_device_resume() and sil24_pci_device_resume() are defined later in this patchset.

If ata_pci_device_suspend/resume() do things incorrect for a controller(), export ata_host_set_suspend/resume() and call those from LLD's suspend/resume() routines.

Signature · 1 line
tejun
#19 lore raw

Re: [PATCH 06/10] libata: implement new Power Management framework

Quoted 4 lines · Tejun Heo

If ata_pci_device_suspend/resume() do things incorrect for a controller(), export ata_host_set_suspend/resume() and call those from LLD's suspend/resume() routines.

OK. I'll export them in the upcoming AHCI suspend/resume patches.

Thanks,
Forrest

author
#32 lore raw

rolled up patch for new Power Management for libata

In reply to Tejun Heo

This is a rolled up version of new-pm patchset for testing as requested by Jens.

This patch is against

	libata-dev #upstream (aeb2ecd6096182cc080d37679080c0f088dcd4a4)

And contains the following patches

upstream (aeb2ecd6096182cc080d37679080c0f088dcd4a4)
+ [1] kill-ATA_FLAG_SRST patch
+ [2] shift-ATA_FLAG_-bits patch
+ [3] new-power-management-for-libata patchset

[1] http://marc.theaimsgroup.com/?l=linux-ide&m=115012501502940&w=2
[2] http://marc.theaimsgroup.com/?l=linux-ide&m=115012349728574&w=2
[3] http://marc.theaimsgroup.com/?l=linux-ide&m=115012753926326&w=2

The git tree containing these changes can be accessed at the following URL.

	http://htj.dyndns.org/git/?p=libata-tj.git;a=shortlog;h=new-pm
	git://htj.dyndns.org/libata-tj new-pm

Patch follows...

drivers/scsi/ata_piix.c +0 -2
index 521b718..75aa47f 100644
@@ -220,8 +220,6 @@ static struct scsi_host_template piix_sh
 	.slave_configure	= ata_scsi_slave_config,
 	.slave_destroy		= ata_scsi_slave_destroy,
 	.bios_param		= ata_std_bios_param,
-	.resume			= ata_scsi_device_resume,
-	.suspend		= ata_scsi_device_suspend,
 };
 
 static const struct ata_port_operations piix_pata_ops = {
drivers/scsi/libata-bmdma.c +13 -2
index 4bc0537..13fab97 100644
@@ -1076,10 +1076,21 @@ int ata_pci_init_one (struct pci_dev *pd
 
 	/* FIXME: check ata_device_add return */
 	if (legacy_mode) {
-		if (legacy_mode & (1 << 0))
+		struct device *dev = &pdev->dev;
+		struct ata_host_set *host_set = NULL;
+
+		if (legacy_mode & (1 << 0)) {
 			ata_device_add(probe_ent);
-		if (legacy_mode & (1 << 1))
+			host_set = dev_get_drvdata(dev);
+		}
+
+		if (legacy_mode & (1 << 1)) {
 			ata_device_add(probe_ent2);
+			if (host_set) {
+				host_set->next = dev_get_drvdata(dev);
+				dev_set_drvdata(dev, host_set);
+			}
+		}
 	} else
 		ata_device_add(probe_ent);
 
drivers/scsi/libata-core.c +141 -95

328 lines not on this page · raw message

drivers/scsi/libata-eh.c +181 -3

212 lines not on this page · raw message

drivers/scsi/libata-scsi.c +0 -16
index 45a49be..0c30e6c 100644
@@ -399,22 +399,6 @@ void ata_dump_status(unsigned id, struct
 	}
 }
 
-int ata_scsi_device_resume(struct scsi_device *sdev)
-{
-	struct ata_port *ap = ata_shost_to_port(sdev->host);
-	struct ata_device *dev = __ata_scsi_find_dev(ap, sdev);
-
-	return ata_device_resume(dev);
-}
-
-int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state)
-{
-	struct ata_port *ap = ata_shost_to_port(sdev->host);
-	struct ata_device *dev = __ata_scsi_find_dev(ap, sdev);
-
-	return ata_device_suspend(dev, state);
-}
-
 /**
  *	ata_to_sense_error - convert ATA error to SCSI error
  *	@id: ATA device number
drivers/scsi/libata.h +1 -0
index bdd4888..539b0b5 100644
@@ -50,6 +50,7 @@ extern void ata_port_flush_task(struct a
 extern unsigned ata_exec_internal(struct ata_device *dev,
 				  struct ata_taskfile *tf, const u8 *cdb,
 				  int dma_dir, void *buf, unsigned int buflen);
+extern unsigned int ata_do_simple_cmd(struct ata_device *dev, u8 cmd);
 extern int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
 			   int post_reset, u16 *id);
 extern int ata_dev_configure(struct ata_device *dev, int print_info);
drivers/scsi/pdc_adma.c +2 -2
index 7ebe8e0..3831858 100644
@@ -182,8 +182,8 @@ static struct ata_port_info adma_port_in
 	/* board_1841_idx */
 	{
 		.sht		= &adma_ata_sht,
-		.host_flags	= ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST |
-				  ATA_FLAG_NO_LEGACY | ATA_FLAG_MMIO,
+		.host_flags	= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_LEGACY |
+				  ATA_FLAG_MMIO,
 		.pio_mask	= 0x10, /* pio4 */
 		.udma_mask	= 0x1f, /* udma0-4 */
 		.port_ops	= &adma_ata_ops,
drivers/scsi/sata_nv.c +0 -1
index 9055124..aa69753 100644
@@ -257,7 +257,6 @@ static struct ata_port_info nv_port_info
 	.sht		= &nv_sht,
 	.host_flags	= ATA_FLAG_SATA |
 			  /* ATA_FLAG_SATA_RESET | */
-			  ATA_FLAG_SRST |
 			  ATA_FLAG_NO_LEGACY,
 	.pio_mask	= NV_PIO_MASK,
 	.mwdma_mask	= NV_MWDMA_MASK,
drivers/scsi/sata_promise.c +2 -3
index b2b6ed5..083e06e 100644
@@ -75,9 +75,8 @@ enum {
 
 	PDC_RESET		= (1 << 11), /* HDMA reset */
 
-	PDC_COMMON_FLAGS	= ATA_FLAG_NO_LEGACY | ATA_FLAG_SRST |
-				  ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI |
-				  ATA_FLAG_PIO_POLLING,
+	PDC_COMMON_FLAGS	= ATA_FLAG_NO_LEGACY | ATA_FLAG_MMIO |
+				  ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING,
 };
 
 
drivers/scsi/sata_qstor.c +0 -1
index 98ddc25..5c84b06 100644
@@ -176,7 +176,6 @@ static const struct ata_port_info qs_por
 		.sht		= &qs_ata_sht,
 		.host_flags	= ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
 				  ATA_FLAG_SATA_RESET |
-				  //FIXME ATA_FLAG_SRST |
 				  ATA_FLAG_MMIO | ATA_FLAG_PIO_POLLING,
 		.pio_mask	= 0x10, /* pio4 */
 		.udma_mask	= 0x7f, /* udma0-6 */
drivers/scsi/sata_sil.c +61 -38

135 lines not on this page · raw message

drivers/scsi/sata_sil24.c +81 -45

176 lines not on this page · raw message

drivers/scsi/sata_sx4.c +2 -2
index 7f86441..58a60ef 100644
@@ -219,8 +219,8 @@ static const struct ata_port_info pdc_po
 	{
 		.sht		= &pdc_sata_sht,
 		.host_flags	= ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
-				  ATA_FLAG_SRST | ATA_FLAG_MMIO |
-				  ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING,
+				  ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI |
+				  ATA_FLAG_PIO_POLLING,
 		.pio_mask	= 0x1f, /* pio0-4 */
 		.mwdma_mask	= 0x07, /* mwdma0-2 */
 		.udma_mask	= 0x7f, /* udma0-6 ; FIXME */
drivers/scsi/sata_via.c +1 -1
index c6975c5..44fc057 100644
@@ -142,7 +142,7 @@ static const struct ata_port_operations 
 
 static struct ata_port_info svia_port_info = {
 	.sht		= &svia_sht,
-	.host_flags	= ATA_FLAG_SATA | ATA_FLAG_SRST | ATA_FLAG_NO_LEGACY,
+	.host_flags	= ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
 	.pio_mask	= 0x1f,
 	.mwdma_mask	= 0x07,
 	.udma_mask	= 0x7f,
include/linux/libata.h +29 -25

95 lines not on this page · raw message

author
#20 lore raw

Re: [PATCH 06/10] libata: implement new Power Management framework

In reply to zhao, forrest
Quoted 5 lines · forrest
Quoted 2 lines · Tejun Heo

If ata_pci_device_suspend/resume() do things incorrect for a controller(), export ata_host_set_suspend/resume() and call those from LLD's suspend/resume() routines.

OK. I'll export them in the upcoming AHCI suspend/resume patches.

Hmmm... sil/sil24 are currently initialize controller before they restore power state, which is wrong. I'll fix that. Thanks for raising the issue.

Signature · 1 line
tejun
#33 lore raw

Re: rolled up patch for new Power Management for libata

In reply to Tejun Heo
Quoted 2 lines · Tejun Heo

This is a rolled up version of new-pm patchset for testing as requested by Jens.

Patch works great for me. Only tested one resume cycle so far, but it worked and was much quicker than before.

Signature · 1 line
Jens Axboe
#16 lore raw

Re: [PATCH 06/10] libata: implement new Power Management framework

In reply to Tejun Heo
Quoted 1 line · Tejun Heo

Please read ata_pci_init_one() and ata_pci_init_legacy_port() in libata-bmdma.c. It's for IDE controllers in legacy mode (not native PCI) mode.

Just to be picky: ata_pci_init_one() is for native or legacy mode. ata_pci_init_legacy_port() is [obviously] only referring to legacy mode.

Jeff

#8 lore raw

Re: [PATCH 05/10] libata: implement new EH action ATA_EH_SPINUP

In reply to Tejun Heo
Quoted 4 lines · Tejun Heo

Implement new EH action ATA_EH_SPINUP. This will be used by new PM implementation.

This patch further reinforces something I've been thinking about, as I watch the EH grow: these EH actions really should be separated into small, discrete operations. Then the EH "driver" will push discrete operations onto an execution stack.

It's always getting tough to follow ata_eh_recover() and ata_eh_reset() 's code through multiple iterations of recovery. This patch (ata_eh_spinup) also illustrates how difficult it would be if the ordering of these operations ever needed to change.

So, I'm not NAK'ing the patch, just throwing out a 'caution' sign. :)

I've often thought something along the lines of a list of tasks ("eh_op_list"), for when a port is frozen and doing EH:

	ata_eh_freeze()
	ata_eh_push(ap, EH_OP_RESET_BUS, ...)
	ata_eh_push(ap, EH_OP_SPINUP, ...)
	ata_eh_push(ap, EH_OP_CONFIGURE, ...)
	ata_eh_push(ap, EH_OP_SET_MODE, ...)
	ata_eh_run()
	ata_eh_thaw()

would be nice. A discrete operation would handle its own discrete operation, prepend and append other operations to eh_op_list, or optionally cause the engine to fail, and return immediately.

Jeff

#35 lore raw
In reply to Tejun Heo
Quoted 6 lines · Tejun Heo

Hello, all.

This patchset implements new Power Management for libata. Currently, only controller-wide suspend and resume are supported. No per-device power management yet. Both memsleep and disksleep work on supported controllers.

I suppose this is just an RFC?

We don't want to lose to SCSI device suspend, so merging that would be a regression AFAICS? While we're still married to the SCSI layer, we need to do suspend through sd.c and similar paths.

I also wonder if any developers or users make use of the ability to suspend/resume individual pieces of hardware, as is (somewhat) supported in ata_piix in 2.6.17-rcX.

Jeff

#22 lore raw

Re: [PATCH 06/10] libata: implement new Power Management framework

In reply to Tejun Heo
Quoted 21 lines · Tejun Heo

+ */

drivers/scsi/libata-eh.c +20 -0
+static void ata_eh_handle_resume(struct ata_port *ap)
+{
+	unsigned long flags;
+	int rc = 0;
+
+	spin_lock_irqsave(&ap->host_set->lock, flags);
+	if (!(ap->flags & ATA_FLAG_PM_PENDING) ||
+	    !(ap->flags & ATA_FLAG_SUSPENDED) ||
+	    ap->pm_mesg.event != PM_EVENT_ON) {
+		spin_unlock_irqrestore(&ap->host_set->lock, flags);
+		return;
+	}
+	ap->flags &= ~ATA_FLAG_PM_PENDING;
+	spin_unlock_irqrestore(&ap->host_set->lock, flags);
+
+	if (ap->host_set->dev->power.power_state.event == PM_EVENT_SUSPEND) {
+		struct ata_eh_context *ehc = &ap->eh_context;
+
+		ehc->i.action |= ATA_EH_SPINUP;
+		ata_ehi_hotplugged(&ehc->i);

drivers/scsi/libata-eh.c void ata_do_eh(struct ata_port *ap, ata_ · line 2033

Quoted 10 lines
drivers/scsi/libata-eh.c +10 -0
+	}
+
+	if (ap->ops->resume)
+		rc = ap->ops->resume(ap);
+
+	spin_lock_irqsave(&ap->host_set->lock, flags);
+	ap->flags &= ~ATA_FLAG_SUSPENDED;
+	ap->pm_result = rc;
+	spin_unlock_irqrestore(&ap->host_set->lock, flags);
+}

I ported AHCI suspend/resume patches against your new PM framework. At first resume from memsleep took 65 seconds to go through soft-reset, hard-reset; then after I removed line
"if (ap->host_set->dev->power.power_state.event == PM_EVENT_SUSPEND)" in ata_eh_handle_resume(), AHCI can resume from memsleep in a few seconds. After inserting a printk(), I found the "ap->host_set->dev->power. power_state.event" is always 0(PM_EVENT_ON).

I think we can introduce a new field in struct ata_port to record the power_state.event, which was passed in suspend callback.

Thanks,
Forrest

author
#23 lore raw

Re: [PATCH 06/10] libata: implement new Power Management framework

Quoted 31 lines · forrest
Quoted 30 lines · Tejun Heo

+ */

drivers/scsi/libata-eh.c +29 -0
+static void ata_eh_handle_resume(struct ata_port *ap)
+{
+	unsigned long flags;
+	int rc = 0;
+
+	spin_lock_irqsave(&ap->host_set->lock, flags);
+	if (!(ap->flags & ATA_FLAG_PM_PENDING) ||
+	    !(ap->flags & ATA_FLAG_SUSPENDED) ||
+	    ap->pm_mesg.event != PM_EVENT_ON) {
+		spin_unlock_irqrestore(&ap->host_set->lock, flags);
+		return;
+	}
+	ap->flags &= ~ATA_FLAG_PM_PENDING;
+	spin_unlock_irqrestore(&ap->host_set->lock, flags);
+
+	if (ap->host_set->dev->power.power_state.event == PM_EVENT_SUSPEND) {
+		struct ata_eh_context *ehc = &ap->eh_context;
+
+		ehc->i.action |= ATA_EH_SPINUP;
+		ata_ehi_hotplugged(&ehc->i);
+	}
+
+	if (ap->ops->resume)
+		rc = ap->ops->resume(ap);
+
+	spin_lock_irqsave(&ap->host_set->lock, flags);
+	ap->flags &= ~ATA_FLAG_SUSPENDED;
+	ap->pm_result = rc;
+	spin_unlock_irqrestore(&ap->host_set->lock, flags);
Quoted 8 lines
Quoted 1 line

+}

I ported AHCI suspend/resume patches against your new PM framework. At
first resume from memsleep took 65 seconds to go through soft-reset,
hard-reset; then after I removed line "if (ap->host_set->dev->power.power_state.event == PM_EVENT_SUSPEND)" in ata_eh_handle_resume(), AHCI can resume from memsleep in a few seconds.
After inserting a printk(), I found the "ap->host_set->dev->power.
power_state.event" is always 0(PM_EVENT_ON).

Can you post the AHCI patch you did? The suspend routine is supposed to set power state to PM_EVENT_SUSPEND on memsleep such that resume can notice it's resuming from actual suspend.

Signature · 1 line
tejun
author
#36 lore raw
In reply to Jeff Garzik
Quoted 9 lines · Jeff Garzik
Quoted 6 lines · Tejun Heo

Hello, all.

This patchset implements new Power Management for libata. Currently, only controller-wide suspend and resume are supported. No per-device power management yet. Both memsleep and disksleep work on supported controllers.

I suppose this is just an RFC?

Well, not really.

Quoted 3 lines

We don't want to lose to SCSI device suspend, so merging that would be a regression AFAICS? While we're still married to the SCSI layer, we need to do suspend through sd.c and similar paths.

I also wonder if any developers or users make use of the ability to suspend/resume individual pieces of hardware, as is (somewhat) supported in ata_piix in 2.6.17-rcX.

At first I thought about implementing that and asked Pavel about how to discern between partial PM and system-wide PM so that libata can do things bus-wide on system-wide PM event. Pavel's response was...

"> And, one more things. As written in the first mail, for libata, it

Quoted 2 lines
Quoted 2 lines

would be nice to know if a device suspend is due to runtime PM event (per-device) or system wide suspend. What do you think about this?

If

Quoted 1 line
Quoted 1 line

you agree, what method do you recommend to determine that?

Currently, runtime pm is unsupported/broken; so any request can be thought as system pm.
Pavel"

So, I determined to ignore per-device PM for the time being. I think I can still implement it but I'm a bit skeptical about its usefulness. I personally haven't seen any user of partial power management using sysfs interface. IIRC, dynamic power management on IDE disks from userspace is done by issuing STANDBY using raw command interface.

What do you think?

Signature · 1 line
tejun
author
#9 lore raw

Re: [PATCH 05/10] libata: implement new EH action ATA_EH_SPINUP

In reply to Jeff Garzik
Quoted 21 lines · Jeff Garzik
Quoted 4 lines · Tejun Heo

Implement new EH action ATA_EH_SPINUP. This will be used by new PM implementation.

This patch further reinforces something I've been thinking about, as I watch the EH grow: these EH actions really should be separated into small, discrete operations. Then the EH "driver" will push discrete operations onto an execution stack.

It's always getting tough to follow ata_eh_recover() and ata_eh_reset() 's code through multiple iterations of recovery. This patch (ata_eh_spinup) also illustrates how difficult it would be if the ordering of these operations ever needed to change.

So, I'm not NAK'ing the patch, just throwing out a 'caution' sign. :)

I've often thought something along the lines of a list of tasks ("eh_op_list"), for when a port is frozen and doing EH:

    ata_eh_freeze()
    ata_eh_push(ap, EH_OP_RESET_BUS, ...)
    ata_eh_push(ap, EH_OP_SPINUP, ...)
    ata_eh_push(ap, EH_OP_CONFIGURE, ...)
    ata_eh_push(ap, EH_OP_SET_MODE, ...)
    ata_eh_run()
    ata_eh_thaw()
Quoted 1 line

would be nice. A discrete operation would handle its own discrete operation, prepend and append other operations to eh_op_list, or optionally cause the engine to fail, and return immediately.

At first, I thought many different controllers would use different EH drive routines, so I put all EH operations in separate functions and grouped them into several larger steps - currently autopsy, report, recover and finish.

In earlier implementation, sil24 and ahci actually had to implement their own drive routine calling those ops and doing private things in-between, but as EH implementation matures all those are handled by feeding proper information into the core EH. I'm looking at other drivers to convert them to new EH but haven't found any driver which the current standard EH can't handle. Although I haven't looked at all drivers yet and some of them may indeed need such specialized implementation.

I think it boils down to the fact that the core EH is more about ATA devices than it's about controllers. Controllers vary from one another but ATA/ATAPI devices are the same old ATA/ATAPI devices whatever the controller is. So, as long as LLD has a way to feed enough information to core EH about the state of the attached device && core EH's controller interface (freeze, thaw & resets) fits the controller to acceptable degree, core EH doesn't have to be different across different LLDs.

IMHO, it's best to keep single unified implementation until it begins to pick up many special cases to deal with specific LLDs. I think we're still in the safe regarding that. If we pass that point, I think we should start by implementing private drive routines in LLDs before making core EH programmable. After several such tries, the requirements for programmable EH would be much clearer and we would be able to do much better job of implementing something which is flexible enough but still as simple as possible.

To sum up...

* Until now, unified EH seems good enough. In fact, not a single driver needs to go further than calling ata_do_eh() w/ proper callbacks.

* I agree that it would be nice to have programmable EH, but let's do it when it's actually needed. It seems that early implementation of complex infrastructure seldom ends up in something pleasant to look at.

Thanks.

Signature · 1 line
tejun
#10 lore raw

Re: [PATCH 05/10] libata: implement new EH action ATA_EH_SPINUP

Quoted 2 lines

* Until now, unified EH seems good enough. In fact, not a single driver needs to go further than calling ata_do_eh() w/ proper callbacks.

This has been shown to be fairly true for the old IDE as well. Other than the years old unfixed promise crash (for which patches exist) the core error recovery doesn't need to do anything in a different order for different devices.

For PATA controllerrs using the traditional i/o API the variances are small and normally around the resetting of the bus, and whether you also have to whack the state machine with a large hammer to get it back into shape after an error case, or whether hardware does it.

The promise is "special" purely because if you reset the state machine then read from the data port before you do another operation you hang the box, and that sequence of events is a failure of the old IDE design rather than a "different" ordering of events.

Alan

#24 lore raw

Re: [PATCH 06/10] libata: implement new Power Management framework

In reply to Tejun Heo
Quoted 42 lines · Tejun Heo
Quoted 33 lines · forrest
Quoted 21 lines · Tejun Heo

+ */

drivers/scsi/libata-eh.c +20 -0
+static void ata_eh_handle_resume(struct ata_port *ap)
+{
+	unsigned long flags;
+	int rc = 0;
+
+	spin_lock_irqsave(&ap->host_set->lock, flags);
+	if (!(ap->flags & ATA_FLAG_PM_PENDING) ||
+	    !(ap->flags & ATA_FLAG_SUSPENDED) ||
+	    ap->pm_mesg.event != PM_EVENT_ON) {
+		spin_unlock_irqrestore(&ap->host_set->lock, flags);
+		return;
+	}
+	ap->flags &= ~ATA_FLAG_PM_PENDING;
+	spin_unlock_irqrestore(&ap->host_set->lock, flags);
+
+	if (ap->host_set->dev->power.power_state.event == PM_EVENT_SUSPEND) {
+		struct ata_eh_context *ehc = &ap->eh_context;
+
+		ehc->i.action |= ATA_EH_SPINUP;
+		ata_ehi_hotplugged(&ehc->i);

drivers/scsi/libata-eh.c void ata_do_eh(struct ata_port *ap, ata_ · line 2033

Quoted 10 lines
drivers/scsi/libata-eh.c +10 -0
+	}
+
+	if (ap->ops->resume)
+		rc = ap->ops->resume(ap);
+
+	spin_lock_irqsave(&ap->host_set->lock, flags);
+	ap->flags &= ~ATA_FLAG_SUSPENDED;
+	ap->pm_result = rc;
+	spin_unlock_irqrestore(&ap->host_set->lock, flags);
+}
Quoted 7 lines

I ported AHCI suspend/resume patches against your new PM framework. At first resume from memsleep took 65 seconds to go through soft-reset, hard-reset; then after I removed line
"if (ap->host_set->dev->power.power_state.event == PM_EVENT_SUSPEND)" in ata_eh_handle_resume(), AHCI can resume from memsleep in a few seconds. After inserting a printk(), I found the "ap->host_set->dev->power. power_state.event" is always 0(PM_EVENT_ON).

Quoted 3 lines

Can you post the AHCI patch you did? The suspend routine is supposed to set power state to PM_EVENT_SUSPEND on memsleep such that resume can notice it's resuming from actual suspend.

Yeah, on memsleep host_set->dev->power.power_state is set to PM_EVENT_SUSPEND in ata_host_set_suspend(). Then during resume process, firstly ata_host_set_resume() is called, in which host_set->dev->power. power_state is set to PMSG_ON, then ata_eh_handle_resume() is called later. This is the reason why ap->host_set->dev->power.power_state.event is 0 in ata_eh_handle_resume(). This is a race condition.

Thanks,
Forrest

author
#25 lore raw

Re: [PATCH 06/10] libata: implement new Power Management framework

Quoted 6 lines · forrest

Yeah, on memsleep host_set->dev->power.power_state is set to PM_EVENT_SUSPEND in ata_host_set_suspend(). Then during resume process, firstly ata_host_set_resume() is called, in which host_set->dev->power. power_state is set to PMSG_ON, then ata_eh_handle_resume() is called later. This is the reason why ap->host_set->dev->power.power_state.event is 0 in ata_eh_handle_resume(). This is a race condition.

Yeap, you're right. Hmmm.. weird. I haven't noticed that race condition during my tests. I think we can use a DFLAG to mark that a device had been spun down. Thanks for spotting it.

Signature · 1 line
tejun
#37 lore raw
In reply to Tejun Heo
Quoted 35 lines · Tejun Heo
Quoted 9 lines · Jeff Garzik
Quoted 6 lines · Tejun Heo

Hello, all.

This patchset implements new Power Management for libata. Currently, only controller-wide suspend and resume are supported. No per-device power management yet. Both memsleep and disksleep work on supported controllers.

I suppose this is just an RFC?

Well, not really.

Quoted 7 lines

We don't want to lose to SCSI device suspend, so merging that would be a regression AFAICS? While we're still married to the SCSI layer, we need to do suspend through sd.c and similar paths.

I also wonder if any developers or users make use of the ability to suspend/resume individual pieces of hardware, as is (somewhat) supported in ata_piix in 2.6.17-rcX.

At first I thought about implementing that and asked Pavel about how to discern between partial PM and system-wide PM so that libata can do things bus-wide on system-wide PM event. Pavel's response was...

"> And, one more things. As written in the first mail, for libata, it

Quoted 2 lines
Quoted 2 lines

would be nice to know if a device suspend is due to runtime PM event (per-device) or system wide suspend. What do you think about this?

If

Quoted 1 line
Quoted 1 line

you agree, what method do you recommend to determine that?

Currently, runtime pm is unsupported/broken; so any request can be thought as system pm.
Pavel"

Quoted 7 lines

So, I determined to ignore per-device PM for the time being. I think I can still implement it but I'm a bit skeptical about its usefulness. I personally haven't seen any user of partial power management using sysfs interface. IIRC, dynamic power management on IDE disks from userspace is done by issuing STANDBY using raw command interface.

What do you think?

Jeff and Tejun,

Have we achieved a consensus about this new PM patches? The AHCI suspend/resume patch and ACPI-SATA patch will definitely depend on this new PM.

Thanks,
Forrest

#34 lore raw

Re: rolled up patch for new Power Management for libata

In reply to Jens Axboe
Quoted 6 lines · Jens Axboe
Quoted 2 lines · Tejun Heo

This is a rolled up version of new-pm patchset for testing as requested by Jens.

Patch works great for me. Only tested one resume cycle so far, but it worked and was much quicker than before.

Notebook hasn't been booted since, so I can confirm it's very reliable. No issues seen so far, and I'm enjoying the snappier resume.

Signature · 1 line
Jens Axboe
author
#38 lore raw
In reply to zhao, forrest
Quoted 5 lines

Jeff and Tejun,

Have we achieved a consensus about this new PM patches? The AHCI suspend/resume patch and ACPI-SATA patch will definitely depend on this new PM.

The consensus seems to be me doing another round of this patchset w/ per-dev PM support. I'm currently working on it. I don't think it will take more than a few days.

Thanks.

Signature · 1 line
tejun