Skip to contentSkip to conversation

fw-ohci breaks suspend-to-RAM

DISCUSSION Marcus Better 5 participants 21 messages May 18, 2007 – Jun 7, 2007 13 messages not in the archive Firewire

lore
Share & tools
lore
#2 lore raw
Quoted 4 lines · Andrew Morton
Quoted 3 lines · On Fri, 18 May 2007 12:07:40 +0200 Marcus Better <[email protected]> wrote:

the fw-ohci driver breaks suspend to RAM on my Thinkpad R60, Intel Core 2 Duo, kernel 2.6.22-rc1 (x86_64, SMP). It does suspend but hangs on resume if the fw-ohci module is loaded. (See also the original report [1]).

...

Quoted 1 line
Quoted 1 line

[1] http://permalink.gmane.org/gmane.linux.power-management.general/5819

Marcus, thanks for the report. I will try to reproduce and fix it unless Kristian is faster.

Signature · 3 lines
Stefan Richter
-=====-=-=== -=-= =--=-
http://arcgraph.de/sr/
#4 lore raw
In reply to a message not in the archive
Quoted 4 lines
Quoted 4 lines · On Fri, 18 May 2007 12:07:40 +0200 Marcus Better <[email protected]> wrote:
Quoted 3 lines

the fw-ohci driver breaks suspend to RAM on my Thinkpad R60, Intel Core 2 Duo, kernel 2.6.22-rc1 (x86_64, SMP). It does suspend but hangs on resume if the fw-ohci module is loaded.

Could you test the following patch? I don't have a machine to test it myself at the moment but may have one tonight or tomorrow.

From: Stefan Richter <[email protected]>
Subject: firewire: simple support for suspend/resume

---
 drivers/firewire/fw-ohci.c |   37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
drivers/firewire/fw-ohci.c +35 -2
Index: linux/drivers/firewire/fw-ohci.c
===================================================================
@@ -1716,8 +1716,11 @@ static int software_reset(struct fw_ohci
 	return -EBUSY;
 }
 
-static int __devinit
-pci_probe(struct pci_dev *dev, const struct pci_device_id *ent)
+static int
+#ifndef CONFIG_PM
+__devinit
+#endif
+pci_probe_or_resume(struct pci_dev *dev)
 {
 	struct fw_ohci *ohci;
 	u32 bus_options, max_receive, link_speed;
@@ -1879,6 +1882,12 @@ pci_probe(struct pci_dev *dev, const str
 	return err;
 }
 
+static int __devinit
+pci_probe(struct pci_dev *dev, const struct pci_device_id *ent)
+{
+	return pci_probe_or_resume(dev);
+}
+
 static void pci_remove(struct pci_dev *dev)
 {
 	struct fw_ohci *ohci;
@@ -1907,6 +1916,26 @@ static void pci_remove(struct pci_dev *d
 	fw_notify("Removed fw-ohci device.\n");
 }
 
+#ifdef CONFIG_PM
+/*
+ * FIXME: Implement it as transparent to upper layers as possible.  To those
+ * drivers without special requirements, a suspend--resume cycle should merely
+ * look like a prolonged bus reset phase.  For example, fw-sbp2 should just
+ * re-login after resume.
+ */
+static int pci_suspend(struct pci_dev *dev, pm_message_t state)
+{
+	pci_remove(dev);
+	return 0;
+}
+
+static int pci_resume(struct pci_dev *dev)
+{
+	pci_probe_or_resume(dev);
+	return 0;
+}
+#endif /* CONFIG_PM */
+
 static struct pci_device_id pci_table[] = {
 	{ PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_FIREWIRE_OHCI, ~0) },
 	{ }
@@ -1919,6 +1948,10 @@ static struct pci_driver fw_ohci_pci_dri
 	.id_table	= pci_table,
 	.probe		= pci_probe,
 	.remove		= pci_remove,
+#ifdef CONFIG_PM
+	.suspend	= pci_suspend,
+	.resume		= pci_resume,
+#endif
 };
 
 MODULE_AUTHOR("Kristian Hoegsberg <[email protected]>");
Signature · 3 lines
Stefan Richter
-=====-=-=== -=-= =-=--
http://arcgraph.de/sr/
#6 lore raw
In reply to a message not in the archive
Quoted 2 lines · I wrote:

Could you test the following patch? I don't have a machine to test it myself at the moment but may have one tonight or tomorrow.

Sorry. I tried with a new ACPI PC and and old APM notebook. The former does not resume after s2ram (screen remains blank after resume), and the latter has a serious bug in APM resume under 2.6.22-rc2 (without FireWire drivers loaded but with some other drivers present; it resumes but anything I do quickly locks up, even "dmesg").

I will try to get 2.6.21 or .20 plus backports of the new FireWire drivers set up on the APM notebook during next week. But I'd appreciate if you could test the patch from my previous post.

Signature · 3 lines
Stefan Richter
-=====-=-=== -=-= =-=--
http://arcgraph.de/sr/
#11 lore raw
In reply to a message not in the archive
Quoted 1 line · Marcus Better

Now it hangs on the second suspend to RAM (at suspend, not resume).

Unless Kristian implements something better before release, we might go with the following patch. Does it abort s2ram as I intend?

(It does not abort APM suspend, but on the APM notebook I tested with 2.6.20 and the new firewire drivers, I could unload and reload fw-ohci after APM resume without problem. I still have no machine which supports s2ram, and the APM machine is too slow to do driver development on it. I might try to install suspend2 for hibernate-to-swapfile on a reasonable machine, but not earlier than in two weeks. Therefore don't expect anything better than the below from me anytime soon.)

From: Stefan Richter <[email protected]>
Subject: firewire: suspend/resume is unimplemented

2.6.22-rc1 reportedly hangs in resume if fw-ohci is loaded.

---
 drivers/firewire/fw-ohci.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/firewire/fw-ohci.c +17 -0
Index: linux/drivers/firewire/fw-ohci.c
===================================================================
@@ -1908,6 +1908,19 @@ static void pci_remove(struct pci_dev *d
 	fw_notify("Removed fw-ohci device.\n");
 }
 
+#ifdef CONFIG_PM
+static int pci_suspend(struct pci_dev *dev, pm_message_t state)
+{
+	fw_notify("ERROR: Unload this driver before hibernate or suspend\n");
+	return -ENOSYS;
+}
+
+static int pci_resume(struct pci_dev *dev)
+{
+	return -ENOSYS;
+}
+#endif /* CONFIG_PM */
+
 static struct pci_device_id pci_table[] = {
 	{ PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_FIREWIRE_OHCI, ~0) },
 	{ }
@@ -1920,6 +1933,10 @@ static struct pci_driver fw_ohci_pci_dri
 	.id_table	= pci_table,
 	.probe		= pci_probe,
 	.remove		= pci_remove,
+#ifdef CONFIG_PM
+	.suspend	= pci_suspend,
+	.resume		= pci_resume,
+#endif
 };
 
 MODULE_AUTHOR("Kristian Hoegsberg <[email protected]>");
Signature · 3 lines
Stefan Richter
-=====-=-=== -=-= ==-=-
http://arcgraph.de/sr/
#13 lore raw
In reply to a message not in the archive
Quoted 6 lines · Stefan Richter
Quoted 1 line · Marcus Better

Now it hangs on the second suspend to RAM (at suspend, not resume).

Unless Kristian implements something better before release, we might go with the following patch. Does it abort s2ram as I intend?

Quoted 7 lines

(It does not abort APM suspend, but on the APM notebook I tested with 2.6.20 and the new firewire drivers, I could unload and reload fw-ohci after APM resume without problem. I still have no machine which supports s2ram, and the APM machine is too slow to do driver development on it. I might try to install suspend2 for hibernate-to-swapfile on a reasonable machine, but not earlier than in two weeks. Therefore don't expect anything better than the below from me anytime soon.)

Actually you can try swsusp too (the built-in stuff). As far as the handling of devices is concerned it's pretty much equivalent to suspend2 and you don't need to patch the kernel in order to use it.

Greetings,
Rafael

#15 lore raw
In reply to a message not in the archive
Quoted 4 lines · Rafael J. Wysocki
Quoted 1 line · Stefan Richter

I might try to install suspend2 for hibernate-to-swapfile

Actually you can try swsusp too (the built-in stuff).

I don't have a swap partition.

Signature · 3 lines
Stefan Richter
-=====-=-=== -=-= ==-=-
http://arcgraph.de/sr/
#17 lore raw
In reply to a message not in the archive
Quoted 7 lines · Stefan Richter
Quoted 4 lines · Rafael J. Wysocki
Quoted 1 line · Stefan Richter

I might try to install suspend2 for hibernate-to-swapfile

Actually you can try swsusp too (the built-in stuff).

I don't have a swap partition.

Please see Documentation/power/swsusp-and-swap-files.txt

In the suspend package containing s2ram there is the program swap-offset that you can use to obtain the resume_offset value for your swap file (NOTE: this doesn't work with swap files on LVM).

Greetings,
Rafael

#18 lore raw
In reply to a message not in the archive

Marcus, please test:

From: =?utf-8?q?Kristian_H=C3=B8gsberg?= <[email protected]>
Subject: [PATCH] Implement suspend/resume PCI driver hooks.
Date: Wed, 30 May 2007 19:06:35 -0400

It's a low-impact design, that just makes suspend/resume look like a bus reset to the upper level drivers, but it should be sufficient.

---

 drivers/firewire/fw-card.c |    5 -
 drivers/firewire/fw-ohci.c |  187 +++++++++++++++++++++++++++++---------------
 2 files changed, 123 insertions(+), 69 deletions(-)
drivers/firewire/fw-card.c +0 -5
index 636151a..9eb1eda 100644
@@ -407,11 +407,6 @@ fw_card_add(struct fw_card *card,
 	card->link_speed = link_speed;
 	card->guid = guid;
 
-	/* Activate link_on bit and contender bit in our self ID packets.*/
-	if (card->driver->update_phy_reg(card, 4, 0,
-					 PHY_LINK_ACTIVE | PHY_CONTENDER) < 0)
-		return -EIO;
-
 	/*
 	 * The subsystem grabs a reference when the card is added and
 	 * drops it when the driver calls fw_core_remove_card.
drivers/firewire/fw-ohci.c +123 -64

242 lines not on this page · raw message

Signature · 3 lines
Stefan Richter
-=====-=-=== -=-= =====
http://arcgraph.de/sr/
#20 lore raw
In reply to a message not in the archive
Quoted 3 lines · Stefan Richter

Marcus, please test:

From: =?utf-8?q?Kristian_H=C3=B8gsberg?= <[email protected]>

I have trouble applying this patch, perhaps due to the encoding. Can you resend it without quoted-printable? (Or am I doing something wrong?)

$ patch -p1 --dry-run < /home/marcus/fw.diff
patching file drivers/firewire/fw-card.c
patch: **** malformed patch at line 11: --- 408,407 ----

Marcus

#22 lore raw
In reply to a message not in the archive
Quoted 8 lines · Marcus Better

I have trouble applying this patch, perhaps due to the encoding. Can you resend it without quoted-printable? (Or am I doing something wrong?)

$ patch -p1 --dry-run < /home/marcus/fw.diff
patching file drivers/firewire/fw-card.c
patch: **** malformed patch at line 11: --- 408,407 ----

Marcus

If you have linux-2.6.22-rc1...-rc3 (not the latest -git), then you need the following patch first in order to apply the suspend/resume patch cleanly. (I will follow up with a ASCIIfied version of the suspend/resume patch.)

From: Kristian Hoegsberg <[email protected]>
Subject: firewire: Add missing byteswapping for receive DMA programs.
Date: Tue, 22 May 2007 18:55:48 -0400

---
 drivers/firewire/fw-ohci.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/firewire/fw-ohci.c +3 -2
Index: linux-2.6.22-rc3/drivers/firewire/fw-ohci.c
===================================================================
@@ -268,7 +268,7 @@ static int ar_context_add_page(struct ar
 
 	dma_sync_single_for_device(dev, ab_bus, PAGE_SIZE, DMA_BIDIRECTIONAL);
 
-	ctx->last_buffer->descriptor.branch_address = ab_bus | 1;
+	ctx->last_buffer->descriptor.branch_address = cpu_to_le32(ab_bus | 1);
 	ctx->last_buffer->next = ab;
 	ctx->last_buffer = ab;
 
@@ -417,7 +417,8 @@ ar_context_init(struct ar_context *ctx, 
 	ctx->current_buffer = ab.next;
 	ctx->pointer = ctx->current_buffer->data;
 
-	reg_write(ctx->ohci, COMMAND_PTR(ctx->regs), ab.descriptor.branch_address);
+	reg_write(ctx->ohci, COMMAND_PTR(ctx->regs),
+		  le32_to_cpu(ab.descriptor.branch_address));
 	reg_write(ctx->ohci, CONTROL_SET(ctx->regs), CONTEXT_RUN);
 	flush_writes(ctx->ohci);
 
Signature · 3 lines
Stefan Richter
-=====-=-=== -=-= =====
http://arcgraph.de/sr/
#24 lore raw
In reply to a message not in the archive
Quoted 2 lines

(I will follow up with a ASCIIfied version of the
suspend/resume patch.)

From: Kristian Hoegsberg <[email protected]>
Subject: [PATCH] Implement suspend/resume PCI driver hooks.
Date: Wed, 30 May 2007 19:06:35 -0400

It's a low-impact design, that just makes suspend/resume look like a bus reset to the upper level drivers, but it should be sufficient.

---

 drivers/firewire/fw-card.c |    5 
 drivers/firewire/fw-ohci.c |  187 ++++++++++++++++++++++++-------------
 2 files changed, 123 insertions(+), 69 deletions(-)
drivers/firewire/fw-card.c +0 -5
Index: linux-2.6.22-rc3/drivers/firewire/fw-card.c
===================================================================
@@ -407,11 +407,6 @@ fw_card_add(struct fw_card *card,
 	card->link_speed = link_speed;
 	card->guid = guid;
 
-	/* Activate link_on bit and contender bit in our self ID packets.*/
-	if (card->driver->update_phy_reg(card, 4, 0,
-					 PHY_LINK_ACTIVE | PHY_CONTENDER) < 0)
-		return -EIO;
-
 	/*
 	 * The subsystem grabs a reference when the card is added and
 	 * drops it when the driver calls fw_core_remove_card.
drivers/firewire/fw-ohci.c +123 -64

242 lines not on this page · raw message

Signature · 3 lines
Stefan Richter
-=====-=-=== -=-= =====
http://arcgraph.de/sr/
#31 lore raw
Quoted 1 line · Kristian Høgsberg

I've posted an updated version of the patch here

                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^

You mean "addition to the previous" patch. :-)

Quoted 4 lines

that fixes a byteswapping problem, and should make the stack actually work after resuming:

http://marc.info/?l=linux1394-devel&m=118108604226326&w=2

That is, protocols which do not involve showing the local ROM to remote nodes are unaffected? In that case I would prefer to defer this new patch until the next merge window if you don't mind. Nevertheless, if Marcus could take the time to check whether his machine keeps happily resuming with the new patch applied, that would be good. I will test it with APM suspend and SBP-2 circa tomorrow.

Signature · 3 lines
Stefan Richter
-=====-=-=== -==- --==-
http://arcgraph.de/sr/
#32 lore raw
Quoted 4 lines · Stefan Richter
Quoted 1 line · Kristian Høgsberg

I've posted an updated version of the patch here

                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^

You mean "addition to the previous" patch. :-)

Yes, sorry about that.

Quoted 11 lines
Quoted 4 lines

that fixes a byteswapping problem, and should make the stack actually work after resuming:

http://marc.info/?l=linux1394-devel&m=118108604226326&w=2

That is, protocols which do not involve showing the local ROM to remote nodes are unaffected? In that case I would prefer to defer this new patch until the next merge window if you don't mind. Nevertheless, if Marcus could take the time to check whether his machine keeps happily resuming with the new patch applied, that would be good. I will test it with APM suspend and SBP-2 circa tomorrow.

No there's more to it than that. When the ohci controller processes the bus reset, it loads back values from the config rom into a couple of ohci registers, specifically BusOptions[1]. If we provide the wrong value in config_rom[2], the controller will load that value after reset and we'll typically end up with a 0 in the max_rec field, which will prevent async receive from working. So byteswapping this correctly will very likely fix the problem you saw, where your box came back from suspend, but the firewire stack was busted.

cheers,
Kristian

[1] If you look at the bus reset tasklet, you'll see that there's more to it. I turns out that not all controllers agree on whether or not to byteswap the be32 value read from the config_rom map. Specifically, the ricoh chipset in my laptop gets it right and swaps it from be32 to le32 before writing to the ohci register, but all TI chipsets just writes the value as is, effectively making the otherwise well designed atomic config rom update mechanism useless. So in the end I manually write the BusOptions register in the bus reset tasklet, but I also load it from the ohci->config_rom map, so this has to be the right byte order.

#33 lore raw
In reply to Stefan Richter
Quoted 2 lines · Stefan Richter

Marcus could take the time to check whether his machine keeps happily resuming with the new patch applied, that would be good.

Yes it works, but I didn't check firewire functionality after resume.

Marcus