linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Stuart Hayes <stuart.w.hayes@gmail.com>
Cc: Austin Bolen <austin_bolen@dell.com>,
	keith.busch@intel.com, Alexandru Gagniuc <mr.nuke.me@gmail.com>,
	"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	"Gustavo A . R . Silva" <gustavo@embeddedor.com>,
	Sinan Kaya <okaya@kernel.org>,
	Oza Pawandeep <poza@codeaurora.org>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	lukas@wunner.de, Libor Pechacek <lpechacek@suse.cz>
Subject: Re: [PATCH v4 0/3] PCI: pciehp: Do not turn off slot if presence comes up after link
Date: Mon, 10 Feb 2020 18:08:16 -0600	[thread overview]
Message-ID: <20200211000816.GA89075@google.com> (raw)
In-Reply-To: <20191025190047.38130-1-stuart.w.hayes@gmail.com>

[+cc Libor (thanks for the ping!)]

On Fri, Oct 25, 2019 at 03:00:44PM -0400, Stuart Hayes wrote:
> In older PCIe specs, PDS (presence detect) would come up when the
> "in-band" presence detect pin connected, and would be up before DLLLA
> (link active).
> 
> In PCIe 4.0 (as an ECN) and in PCIe 5.0, there is a new bit to show if
> in-band presence detection can be disabled for the slot, and another bit
> that disables it--and a recommendation that it should be disabled if it
> can be. In addition, certain OEMs disable in-band presence detection
> without implementing these bits.
> 
> This means it is possible to get a "card present" interrupt after the
> link is up and the driver is loaded.  This causes an erroneous removal
> of the device driver, followed by an immediate re-probing.
> 
> This patch set defines these new bits, uses them to disable in-band
> presence detection if it can be, waits for PDS to go up if in-band
> presence detection is disabled, and adds a DMI table that will let us
> know if we should assume in-band presence is disabled on a system.
> 
> The first two patches in this set come from a patch set that was
> submitted but not accepted many months ago by Alexandru Gagniuc [1].
> The first is unmodified, the second has the commit message and timeout 
> modified.
> 
> [1] https://patchwork.kernel.org/cover/10909167/
>     [v3,0/4] PCI: pciehp: Do not turn off slot if presence comes up after link
> 
> v2:
> - modify loop in pcie_wait_for_presence to do..while
> 
> v3:
> - remove unused variable declaration
> - modify text of warning message
> 
> v4:
> - remove "!!" boolean conversion in an "if" condition for readability
> - add explanation comment in dmi table
> 
> Alexandru Gagniuc (2):
>   PCI: pciehp: Add support for disabling in-band presence
>   PCI: pciehp: Wait for PDS if in-band presence is disabled
> 
> Stuart Hayes (1):
>   PCI: pciehp: Add dmi table for in-band presence disabled
> 
>  drivers/pci/hotplug/pciehp.h     |  1 +
>  drivers/pci/hotplug/pciehp_hpc.c | 50 +++++++++++++++++++++++++++++++-
>  include/uapi/linux/pci_regs.h    |  2 ++
>  3 files changed, 52 insertions(+), 1 deletion(-)

I added the spec reference to the 1/3 commit log, tried to make the
tweaks Lukas suggested (interdiff below), used ctrl_info() instead of
pci_info() (I would actually like to change the whole driver to use
pci_info(), but better to be consistent for now), and applied to
pci/hotplug for v5.7.

Somebody should also update lspci to:

  - Do something with DevCap AttnBtn, AttnInd, PwrInd to indicate that
    they were only defined for PCIe r1.0 and have been explicitly
    undefined since then.  If there's a way to identify those 1.0
    devices and only decode those fields for 1.0, that would be nice.

  - Add SltCap2 and SltCtrl2 decoding.

Speak up if you plan to do this so we don't duplicate effort.

Bjorn

diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index ae0108b92084..469873b44a8e 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -284,7 +284,7 @@ static void pcie_wait_for_presence(struct pci_dev *pdev)
 		timeout -= 10;
 	} while (timeout > 0);
 
-	pci_info(pdev, "Timeout waiting for Presence Detect state to be set\n");
+	ctrl_info(ctrl, "Timeout waiting for Presence Detect\n");
 }
 
 int pciehp_check_link_status(struct controller *ctrl)
@@ -921,6 +921,16 @@ struct controller *pcie_init(struct pcie_device *dev)
 	ctrl->state = list_empty(&subordinate->devices) ? OFF_STATE : ON_STATE;
 	up_read(&pci_bus_sem);
 
+	pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP2, &slot_cap2);
+	if (slot_cap2 & PCI_EXP_SLTCAP2_IBPD) {
+		pcie_write_cmd_nowait(ctrl, PCI_EXP_SLTCTL_IBPD_DISABLE,
+				      PCI_EXP_SLTCTL_IBPD_DISABLE);
+		ctrl->inband_presence_disabled = 1;
+	}
+
+	if (dmi_first_match(inband_presence_disabled_dmi_table))
+		ctrl->inband_presence_disabled = 1;
+
 	/* Check if Data Link Layer Link Active Reporting is implemented */
 	pcie_capability_read_dword(pdev, PCI_EXP_LNKCAP, &link_cap);
 
@@ -930,7 +940,7 @@ struct controller *pcie_init(struct pcie_device *dev)
 		PCI_EXP_SLTSTA_MRLSC | PCI_EXP_SLTSTA_CC |
 		PCI_EXP_SLTSTA_DLLSC | PCI_EXP_SLTSTA_PDC);
 
-	ctrl_info(ctrl, "Slot #%d AttnBtn%c PwrCtrl%c MRL%c AttnInd%c PwrInd%c HotPlug%c Surprise%c Interlock%c NoCompl%c LLActRep%c%s\n",
+	ctrl_info(ctrl, "Slot #%d AttnBtn%c PwrCtrl%c MRL%c AttnInd%c PwrInd%c HotPlug%c Surprise%c Interlock%c NoCompl%c IbPresDis%c LLActRep%c%s\n",
 		(slot_cap & PCI_EXP_SLTCAP_PSN) >> 19,
 		FLAG(slot_cap, PCI_EXP_SLTCAP_ABP),
 		FLAG(slot_cap, PCI_EXP_SLTCAP_PCP),
@@ -941,19 +951,10 @@ struct controller *pcie_init(struct pcie_device *dev)
 		FLAG(slot_cap, PCI_EXP_SLTCAP_HPS),
 		FLAG(slot_cap, PCI_EXP_SLTCAP_EIP),
 		FLAG(slot_cap, PCI_EXP_SLTCAP_NCCS),
+		ctrl->inband_presence_disabled,
 		FLAG(link_cap, PCI_EXP_LNKCAP_DLLLARC),
 		pdev->broken_cmd_compl ? " (with Cmd Compl erratum)" : "");
 
-	pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP2, &slot_cap2);
-	if (slot_cap2 & PCI_EXP_SLTCAP2_IBPD) {
-		pcie_write_cmd_nowait(ctrl, PCI_EXP_SLTCTL_IBPD_DISABLE,
-				      PCI_EXP_SLTCTL_IBPD_DISABLE);
-		ctrl->inband_presence_disabled = 1;
-	}
-
-	if (dmi_first_match(inband_presence_disabled_dmi_table))
-		ctrl->inband_presence_disabled = 1;
-
 	/*
 	 * If empty slot's power status is on, turn power off.  The IRQ isn't
 	 * requested yet, so avoid triggering a notification with this command.
diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h
index b464d2f76513..f9701410d3b5 100644
--- a/include/uapi/linux/pci_regs.h
+++ b/include/uapi/linux/pci_regs.h
@@ -681,7 +681,7 @@
 #define PCI_EXP_LNKSTA2		50	/* Link Status 2 */
 #define PCI_CAP_EXP_ENDPOINT_SIZEOF_V2	52	/* v2 endpoints with link end here */
 #define PCI_EXP_SLTCAP2		52	/* Slot Capabilities 2 */
-#define  PCI_EXP_SLTCAP2_IBPD	0x0001	/* In-band PD Disable Supported */
+#define  PCI_EXP_SLTCAP2_IBPD	0x00000001 /* In-band PD Disable Supported */
 #define PCI_EXP_SLTCTL2		56	/* Slot Control 2 */
 #define PCI_EXP_SLTSTA2		58	/* Slot Status 2 */
 

  parent reply	other threads:[~2020-02-11  0:08 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-25 19:00 [PATCH v4 0/3] PCI: pciehp: Do not turn off slot if presence comes up after link Stuart Hayes
2019-10-25 19:00 ` [PATCH v4 1/3] PCI: pciehp: Add support for disabling in-band presence Stuart Hayes
2019-10-25 19:15   ` Andy Shevchenko
2019-11-27  1:36   ` Bjorn Helgaas
2019-11-27  2:19     ` Stuart Hayes
2019-12-31 22:06       ` Stuart Hayes
2020-01-29 13:15         ` Libor Pechacek
2019-10-25 19:00 ` [PATCH v4 2/3] PCI: pciehp: Wait for PDS if in-band presence is disabled Stuart Hayes
2019-10-25 19:16   ` Andy Shevchenko
2019-10-25 19:00 ` [PATCH v4 3/3] PCI: pciehp: Add dmi table for in-band presence disabled Stuart Hayes
2019-10-25 19:18   ` Andy Shevchenko
2020-02-21  5:21   ` Bjorn Helgaas
2020-02-21 17:46     ` Stuart Hayes
2019-10-28 11:31 ` [PATCH v4 0/3] PCI: pciehp: Do not turn off slot if presence comes up after link Mika Westerberg
2020-02-08 20:22 ` Lukas Wunner
2020-02-11  0:08 ` Bjorn Helgaas [this message]
2020-02-11  4:49   ` Lukas Wunner
2020-02-11 14:14     ` Bjorn Helgaas
2020-02-11 14:32       ` Lukas Wunner
2020-02-11 19:31         ` Bjorn Helgaas
2020-02-18 17:32         ` Bjorn Helgaas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200211000816.GA89075@google.com \
    --to=helgaas@kernel.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=austin_bolen@dell.com \
    --cc=gustavo@embeddedor.com \
    --cc=keith.busch@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpechacek@suse.cz \
    --cc=lukas@wunner.de \
    --cc=mika.westerberg@linux.intel.com \
    --cc=mr.nuke.me@gmail.com \
    --cc=okaya@kernel.org \
    --cc=poza@codeaurora.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=stuart.w.hayes@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).