pciehp: Disable/enable link during slot power off/on
PATCH 1/1 pciehp: Disable/enable link during slot power off/on
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.
--- drivers/pci/hotplug/pciehp_hpc.c | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
drivers/pci/hotplug/pciehp_hpc.c +46 -0
@@ -315,6 +315,42 @@ int pciehp_check_link_status(struct contreturn 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 * sctrl_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);
Quoted 18 lines · On Fri, 02 Dec 2011 15:10:08 -0800 Yinghai Lu <[email protected]> wrote:
One system have repeater in system board to support gen2 hotplug.
Found when EM is removed from some slots,
/var/log/messagewill 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.
Quoted 4 lines
So We could do the same thing to disable/enable link during power off/on.
Signed-off-by Yinghai Lu <[email protected]>
Kenji-san, any comment or chance to test?
Thanks,
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
Quoted 18 lines · On Fri, 02 Dec 2011 15:10:08 -0800 Yinghai Lu <[email protected]> wrote:
One system have repeater in system board to support gen2 hotplug.
Found when EM is removed from some slots,
/var/log/messagewill 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.
Quoted 3 lines
So We could do the same thing to disable/enable link during power off/on.
Signed-off-by Yinghai Lu <[email protected]>
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?
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
Quoted 23 lines · Jesse Barnes
Quoted 20 lines · On Fri, 02 Dec 2011 15:10:08 -0800 Yinghai Lu <[email protected]> wrote:
One system have repeater in system board to support gen2 hotplug.
Found when EM is removed from some slots,
/var/log/messagewill 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.
Quoted 7 lines
Quoted 1 line
Signed-off-by Yinghai Lu <[email protected]>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
Quoted 6 lines · On Fri, 27 Jan 2012 09:39:02 -0800 Yinghai Lu <[email protected]> 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.gitfor-pci-hp
Quoted 7 lines
you can find other patches in
git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.gitfor-pci2and
git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.gitfor-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,
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
Quoted 12 lines · Jesse Barnes
Quoted 10 lines · On Fri, 27 Jan 2012 09:39:02 -0800 Yinghai Lu <[email protected]> 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.gitfor-pci-hpyou can find other patches in
git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.gitfor-pci2
Quoted 7 lines
Quoted 3 lines
and
git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.gitfor-pci-busn-allocOk 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