linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pciehp: Disable/enable link during slot power off/on
@ 2011-12-02 23:10 Yinghai Lu
  2011-12-05 19:23 ` Jesse Barnes
  2012-01-27 17:26 ` Jesse Barnes
  0 siblings, 2 replies; 6+ messages in thread
From: Yinghai Lu @ 2011-12-02 23:10 UTC (permalink / raw)
  To: Jesse Barnes, Kenji Kaneshige; +Cc: linux-pci, linux-kernel


One system have repeater in system board to support gen2 hotplug.

Found when EM is removed from some slots, /var/log/message will be full of
"card present/not present" warning.

It turns out root complex still try to train the link to repeater because
repeater is not reset.

This patch will disable link to make repeater could reset properly.
Also could kill AER during EM removal.

Recently when testing hotplug on one system under development, found if boot
the system without EM, and later hotplug does not work with Linux.
But other OS is ok.
The root cause is that bios left link disabled when slot is empty,
and other OS is playing link disable bit in link ctrl during power on/off.

So We could do the same thing to disable/enable link during power off/on.

Signed-off-by: Yinghai Lu <yinghai.lu@oracle.com>

---
 drivers/pci/hotplug/pciehp_hpc.c |   46 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

Index: linux-2.6/drivers/pci/hotplug/pciehp_hpc.c
===================================================================
--- linux-2.6.orig/drivers/pci/hotplug/pciehp_hpc.c
+++ linux-2.6/drivers/pci/hotplug/pciehp_hpc.c
@@ -315,6 +315,42 @@ int pciehp_check_link_status(struct cont
 	return retval;
 }
 
+static int __pciehp_link_set(struct controller *ctrl, bool enable)
+{
+	u16 lnk_ctrl;
+	int retval = 0;
+
+	retval = pciehp_readw(ctrl, PCI_EXP_LNKCTL, &lnk_ctrl);
+	if (retval) {
+		ctrl_err(ctrl, "Cannot read LNKCTRL register\n");
+		return retval;
+	}
+
+	if (enable)
+		lnk_ctrl &= ~PCI_EXP_LNKCTL_LD;
+	else
+		lnk_ctrl |= PCI_EXP_LNKCTL_LD;
+
+	retval = pciehp_writew(ctrl, PCI_EXP_LNKCTL, lnk_ctrl);
+	if (retval) {
+		ctrl_err(ctrl, "Cannot write LNKCTRL register\n");
+		return retval;
+	}
+	ctrl_dbg(ctrl, "%s: lnk_ctrl = %x\n", __func__, lnk_ctrl);
+
+	return retval;
+}
+
+static int pciehp_link_enable(struct controller *ctrl)
+{
+	return __pciehp_link_set(ctrl, true);
+}
+
+static int pciehp_link_disable(struct controller *ctrl)
+{
+	return __pciehp_link_set(ctrl, false);
+}
+
 int pciehp_get_attention_status(struct slot *slot, u8 *status)
 {
 	struct controller *ctrl = slot->ctrl;
@@ -533,6 +569,12 @@ int pciehp_power_on_slot(struct slot * s
 	ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__,
 		 pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_cmd);
 
+	/* Need to wait before enabling link */
+	msleep(100);
+	retval = pciehp_link_enable(ctrl);
+	if (retval)
+		ctrl_err(ctrl, "%s: Can not enable the link!\n", __func__);
+
 	return retval;
 }
 
@@ -543,6 +585,10 @@ int pciehp_power_off_slot(struct slot *
 	u16 cmd_mask;
 	int retval;
 
+	/* Disable the link at first */
+	pciehp_link_disable(ctrl);
+	msleep(100);
+
 	slot_cmd = POWER_OFF;
 	cmd_mask = PCI_EXP_SLTCTL_PCC;
 	retval = pcie_write_cmd(ctrl, slot_cmd, cmd_mask);

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pciehp: Disable/enable link during slot power off/on
  2011-12-02 23:10 [PATCH] pciehp: Disable/enable link during slot power off/on Yinghai Lu
@ 2011-12-05 19:23 ` Jesse Barnes
  2012-01-27 17:26 ` Jesse Barnes
  1 sibling, 0 replies; 6+ messages in thread
From: Jesse Barnes @ 2011-12-05 19:23 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Kenji Kaneshige, linux-pci, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1078 bytes --]

On Fri, 02 Dec 2011 15:10:08 -0800
Yinghai Lu <yinghai.lu@oracle.com> wrote:

> 
> One system have repeater in system board to support gen2 hotplug.
> 
> Found when EM is removed from some slots, /var/log/message will be full of
> "card present/not present" warning.
> 
> It turns out root complex still try to train the link to repeater because
> repeater is not reset.
> 
> This patch will disable link to make repeater could reset properly.
> Also could kill AER during EM removal.
> 
> Recently when testing hotplug on one system under development, found if boot
> the system without EM, and later hotplug does not work with Linux.
> But other OS is ok.
> The root cause is that bios left link disabled when slot is empty,
> and other OS is playing link disable bit in link ctrl during power on/off.
> 
> So We could do the same thing to disable/enable link during power off/on.
> 
> Signed-off-by: Yinghai Lu <yinghai.lu@oracle.com>
> 

Kenji-san, any comment or chance to test?

Thanks,
-- 
Jesse Barnes, Intel Open Source Technology Center

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pciehp: Disable/enable link during slot power off/on
  2011-12-02 23:10 [PATCH] pciehp: Disable/enable link during slot power off/on Yinghai Lu
  2011-12-05 19:23 ` Jesse Barnes
@ 2012-01-27 17:26 ` Jesse Barnes
  2012-01-27 17:39   ` Yinghai Lu
  1 sibling, 1 reply; 6+ messages in thread
From: Jesse Barnes @ 2012-01-27 17:26 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Kenji Kaneshige, linux-pci, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1254 bytes --]

On Fri, 02 Dec 2011 15:10:08 -0800
Yinghai Lu <yinghai.lu@oracle.com> wrote:

> 
> One system have repeater in system board to support gen2 hotplug.
> 
> Found when EM is removed from some slots, /var/log/message will be full of
> "card present/not present" warning.
> 
> It turns out root complex still try to train the link to repeater because
> repeater is not reset.
> 
> This patch will disable link to make repeater could reset properly.
> Also could kill AER during EM removal.
> 
> Recently when testing hotplug on one system under development, found if boot
> the system without EM, and later hotplug does not work with Linux.
> But other OS is ok.
> The root cause is that bios left link disabled when slot is empty,
> and other OS is playing link disable bit in link ctrl during power on/off.
> 
> So We could do the same thing to disable/enable link during power off/on.
> 
> Signed-off-by: Yinghai Lu <yinghai.lu@oracle.com>

Ok I had to massage that commit message quite a bit, please let me know
if it's still accurate.

The 100ms delay still needs to be clarified; if it's really necessary
maybe we could move the delays into a delayed work handler?

-- 
Jesse Barnes, Intel Open Source Technology Center

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pciehp: Disable/enable link during slot power off/on
  2012-01-27 17:26 ` Jesse Barnes
@ 2012-01-27 17:39   ` Yinghai Lu
  2012-01-27 18:33     ` Jesse Barnes
  0 siblings, 1 reply; 6+ messages in thread
From: Yinghai Lu @ 2012-01-27 17:39 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Kenji Kaneshige, linux-pci, linux-kernel

On 01/27/2012 09:26 AM, Jesse Barnes wrote:

> On Fri, 02 Dec 2011 15:10:08 -0800
> Yinghai Lu <yinghai.lu@oracle.com> wrote:
> 
>>
>> One system have repeater in system board to support gen2 hotplug.
>>
>> Found when EM is removed from some slots, /var/log/message will be full of
>> "card present/not present" warning.
>>
>> It turns out root complex still try to train the link to repeater because
>> repeater is not reset.
>>
>> This patch will disable link to make repeater could reset properly.
>> Also could kill AER during EM removal.
>>
>> Recently when testing hotplug on one system under development, found if boot
>> the system without EM, and later hotplug does not work with Linux.
>> But other OS is ok.
>> The root cause is that bios left link disabled when slot is empty,
>> and other OS is playing link disable bit in link ctrl during power on/off.
>>
>> So We could do the same thing to disable/enable link during power off/on.
>>
>> Signed-off-by: Yinghai Lu <yinghai.lu@oracle.com>
> 
> Ok I had to massage that commit message quite a bit, please let me know
> if it's still accurate.
> 
> The 100ms delay still needs to be clarified; if it's really necessary
> maybe we could move the delays into a delayed work handler?


Please you check updated versions that i sent later.

it was changed to three patches... i sent those patchs 1/123

git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-hp

you can find other patches in 

git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci2

and

git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-busn-alloc

Thanks

Yinghai

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pciehp: Disable/enable link during slot power off/on
  2012-01-27 17:39   ` Yinghai Lu
@ 2012-01-27 18:33     ` Jesse Barnes
  2012-01-27 19:08       ` Yinghai Lu
  0 siblings, 1 reply; 6+ messages in thread
From: Jesse Barnes @ 2012-01-27 18:33 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Kenji Kaneshige, linux-pci, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 777 bytes --]

On Fri, 27 Jan 2012 09:39:02 -0800
Yinghai Lu <yinghai.lu@oracle.com> wrote:
> Please you check updated versions that i sent later.
> 
> it was changed to three patches... i sent those patchs 1/123
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-hp
> 
> you can find other patches in 
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci2
> 
> and
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-busn-alloc

Ok I'll see if I can dig them out of the list; note I can't pull
directly from your branches since I usually need to rewrite the
changelogs and the patches need careful review.

Thanks,
-- 
Jesse Barnes, Intel Open Source Technology Center

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pciehp: Disable/enable link during slot power off/on
  2012-01-27 18:33     ` Jesse Barnes
@ 2012-01-27 19:08       ` Yinghai Lu
  0 siblings, 0 replies; 6+ messages in thread
From: Yinghai Lu @ 2012-01-27 19:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Kenji Kaneshige, linux-pci, linux-kernel

On Fri, Jan 27, 2012 at 10:33 AM, Jesse Barnes <jbarnes@virtuousgeek.org> wrote:
> On Fri, 27 Jan 2012 09:39:02 -0800
> Yinghai Lu <yinghai.lu@oracle.com> wrote:
>> Please you check updated versions that i sent later.
>>
>> it was changed to three patches... i sent those patchs 1/123
>>
>> git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-hp
>>
>> you can find other patches in
>>
>> git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci2
>>
>> and
>>
>> git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-busn-alloc
>
> Ok I'll see if I can dig them out of the list; note I can't pull
> directly from your branches since I usually need to rewrite the
> changelogs and the patches need careful review.

Agreed, I just put them into tree for your reference, in case you are
picking up a wrong version from mail.

Thanks

Yinghai

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-01-27 19:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-02 23:10 [PATCH] pciehp: Disable/enable link during slot power off/on Yinghai Lu
2011-12-05 19:23 ` Jesse Barnes
2012-01-27 17:26 ` Jesse Barnes
2012-01-27 17:39   ` Yinghai Lu
2012-01-27 18:33     ` Jesse Barnes
2012-01-27 19:08       ` Yinghai Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).