linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] pcie-dpc: Decode extended reasons
@ 2017-02-03 21:46 Keith Busch
  2017-02-03 21:46 ` [PATCH 2/2] pcie-dpc: Wait for root port busy to clear Keith Busch
  2017-02-10 21:03 ` [PATCH 1/2] pcie-dpc: Decode extended reasons Bjorn Helgaas
  0 siblings, 2 replies; 4+ messages in thread
From: Keith Busch @ 2017-02-03 21:46 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas; +Cc: Gabriele Paoloni, Keith Busch

This is just informational to decode the currently defined extended
event reasons rather than just using the generic "extended" explanation.

Signed-off-by: Keith Busch <keith.busch@intel.com>
---
 drivers/pci/pcie/pcie-dpc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pcie/pcie-dpc.c b/drivers/pci/pcie/pcie-dpc.c
index d91e538..9ca74f4 100644
--- a/drivers/pci/pcie/pcie-dpc.c
+++ b/drivers/pci/pcie/pcie-dpc.c
@@ -77,11 +77,15 @@ static irqreturn_t dpc_irq(int irq, void *context)
 
 	if (status & PCI_EXP_DPC_STATUS_TRIGGER) {
 		u16 reason = (status >> 1) & 0x3;
+		u16 ext_reason = (status >> 5) & 0x3;
 
-		dev_warn(&dpc->dev->device, "DPC %s triggered, remove downstream devices\n",
+		dev_warn(&dpc->dev->device, "DPC %s detected, remove downstream devices\n",
 			 (reason == 0) ? "unmasked uncorrectable error" :
 			 (reason == 1) ? "ERR_NONFATAL" :
-			 (reason == 2) ? "ERR_FATAL" : "extended error");
+			 (reason == 2) ? "ERR_FATAL" :
+			 (ext_reason == 0) ? "RP PIO error" :
+			 (ext_reason == 1) ? "software trigger" :
+					     "reserved error");
 		schedule_work(&dpc->work);
 	}
 	return IRQ_HANDLED;
-- 
2.7.2

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

* [PATCH 2/2] pcie-dpc: Wait for root port busy to clear
  2017-02-03 21:46 [PATCH 1/2] pcie-dpc: Decode extended reasons Keith Busch
@ 2017-02-03 21:46 ` Keith Busch
  2017-02-06 11:15   ` Gabriele Paoloni
  2017-02-10 21:03 ` [PATCH 1/2] pcie-dpc: Decode extended reasons Bjorn Helgaas
  1 sibling, 1 reply; 4+ messages in thread
From: Keith Busch @ 2017-02-03 21:46 UTC (permalink / raw)
  To: linux-pci, Bjorn Helgaas; +Cc: Gabriele Paoloni, Keith Busch

Root Ports implementing DPC optionally advertise extensions that, when
advertised, require the driver wait for the RP Busy status to clear prior
to releasing from containment. Results are undefined if we release from
containment while this bit is set.

Signed-off-by: Keith Busch <keith.busch@intel.com>
---
 drivers/pci/pcie/pcie-dpc.c   | 26 +++++++++++++++++++++++++-
 include/uapi/linux/pci_regs.h |  1 +
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pcie/pcie-dpc.c b/drivers/pci/pcie/pcie-dpc.c
index 9ca74f4..2acd9de 100644
--- a/drivers/pci/pcie/pcie-dpc.c
+++ b/drivers/pci/pcie/pcie-dpc.c
@@ -20,8 +20,28 @@ struct dpc_dev {
 	struct pcie_device	*dev;
 	struct work_struct	work;
 	int			cap_pos;
+	bool			rp;
 };
 
+static int dpc_wait_rp_inactive(struct dpc_dev *dpc)
+{
+	unsigned long timeout = jiffies + HZ;
+	struct pci_dev *pdev = dpc->dev->port;
+	u16 status;
+
+	pci_read_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_STATUS, &status);
+	while (status & PCI_EXP_DPC_RP_BUSY &&
+					!time_after(jiffies, timeout)) {
+		msleep(10);
+		pci_read_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_STATUS, &status);
+	}
+	if (status & PCI_EXP_DPC_RP_BUSY) {
+		dev_warn(&pdev->dev, "DPC root port still busy\n");
+		return -EBUSY;
+	}
+	return 0;
+}
+
 static void dpc_wait_link_inactive(struct pci_dev *pdev)
 {
 	unsigned long timeout = jiffies + HZ;
@@ -34,7 +54,7 @@ static void dpc_wait_link_inactive(struct pci_dev *pdev)
 		pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status);
 	}
 	if (lnk_status & PCI_EXP_LNKSTA_DLLLA)
-		dev_warn(&pdev->dev, "Link state not disabled for DPC event");
+		dev_warn(&pdev->dev, "Link state not disabled for DPC event\n");
 }
 
 static void interrupt_event_handler(struct work_struct *work)
@@ -56,6 +76,8 @@ static void interrupt_event_handler(struct work_struct *work)
 	pci_unlock_rescan_remove();
 
 	dpc_wait_link_inactive(pdev);
+	if (dpc->rp && dpc_wait_rp_inactive(dpc))
+		return;
 	pci_write_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_STATUS,
 		PCI_EXP_DPC_STATUS_TRIGGER | PCI_EXP_DPC_STATUS_INTERRUPT);
 }
@@ -119,6 +141,8 @@ static int dpc_probe(struct pcie_device *dev)
 	pci_read_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_CAP, &cap);
 	pci_read_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_CTL, &ctl);
 
+	dpc->rp = (cap & PCI_EXP_DPC_CAP_RP_EXT);
+
 	ctl |= PCI_EXP_DPC_CTL_EN_NONFATAL | PCI_EXP_DPC_CTL_INT_EN;
 	pci_write_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_CTL, ctl);
 
diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h
index 174d114..c1b94b0 100644
--- a/include/uapi/linux/pci_regs.h
+++ b/include/uapi/linux/pci_regs.h
@@ -973,6 +973,7 @@
 #define PCI_EXP_DPC_STATUS		8	/* DPC Status */
 #define  PCI_EXP_DPC_STATUS_TRIGGER	0x01	/* Trigger Status */
 #define  PCI_EXP_DPC_STATUS_INTERRUPT	0x08	/* Interrupt Status */
+#define  PCI_EXP_DPC_RP_BUSY		0x10	/* Root Port Busy */
 
 #define PCI_EXP_DPC_SOURCE_ID		10	/* DPC Source Identifier */
 
-- 
2.7.2

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

* RE: [PATCH 2/2] pcie-dpc: Wait for root port busy to clear
  2017-02-03 21:46 ` [PATCH 2/2] pcie-dpc: Wait for root port busy to clear Keith Busch
@ 2017-02-06 11:15   ` Gabriele Paoloni
  0 siblings, 0 replies; 4+ messages in thread
From: Gabriele Paoloni @ 2017-02-06 11:15 UTC (permalink / raw)
  To: Keith Busch, linux-pci, Bjorn Helgaas

Hi Keith

> -----Original Message-----
> From: Keith Busch [mailto:keith.busch@intel.com]
> Sent: 03 February 2017 21:46
> To: linux-pci@vger.kernel.org; Bjorn Helgaas
> Cc: Gabriele Paoloni; Keith Busch
> Subject: [PATCH 2/2] pcie-dpc: Wait for root port busy to clear
> 
> Root Ports implementing DPC optionally advertise extensions that, when
> advertised, require the driver wait for the RP Busy status to clear
> prior
> to releasing from containment. Results are undefined if we release from
> containment while this bit is set.

Many thanks for this I should be able to test it in March.
BTW the patch looks ok to me

Cheers
Gab

> 
> Signed-off-by: Keith Busch <keith.busch@intel.com>
> ---

[...]

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

* Re: [PATCH 1/2] pcie-dpc: Decode extended reasons
  2017-02-03 21:46 [PATCH 1/2] pcie-dpc: Decode extended reasons Keith Busch
  2017-02-03 21:46 ` [PATCH 2/2] pcie-dpc: Wait for root port busy to clear Keith Busch
@ 2017-02-10 21:03 ` Bjorn Helgaas
  1 sibling, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2017-02-10 21:03 UTC (permalink / raw)
  To: Keith Busch; +Cc: linux-pci, Bjorn Helgaas, Gabriele Paoloni

On Fri, Feb 03, 2017 at 04:46:12PM -0500, Keith Busch wrote:
> This is just informational to decode the currently defined extended
> event reasons rather than just using the generic "extended" explanation.
> 
> Signed-off-by: Keith Busch <keith.busch@intel.com>

Applied both of these to pci/dpc for v4.11, thanks, Keith!

> ---
>  drivers/pci/pcie/pcie-dpc.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/pcie/pcie-dpc.c b/drivers/pci/pcie/pcie-dpc.c
> index d91e538..9ca74f4 100644
> --- a/drivers/pci/pcie/pcie-dpc.c
> +++ b/drivers/pci/pcie/pcie-dpc.c
> @@ -77,11 +77,15 @@ static irqreturn_t dpc_irq(int irq, void *context)
>  
>  	if (status & PCI_EXP_DPC_STATUS_TRIGGER) {
>  		u16 reason = (status >> 1) & 0x3;
> +		u16 ext_reason = (status >> 5) & 0x3;
>  
> -		dev_warn(&dpc->dev->device, "DPC %s triggered, remove downstream devices\n",
> +		dev_warn(&dpc->dev->device, "DPC %s detected, remove downstream devices\n",
>  			 (reason == 0) ? "unmasked uncorrectable error" :
>  			 (reason == 1) ? "ERR_NONFATAL" :
> -			 (reason == 2) ? "ERR_FATAL" : "extended error");
> +			 (reason == 2) ? "ERR_FATAL" :
> +			 (ext_reason == 0) ? "RP PIO error" :
> +			 (ext_reason == 1) ? "software trigger" :
> +					     "reserved error");
>  		schedule_work(&dpc->work);
>  	}
>  	return IRQ_HANDLED;
> -- 
> 2.7.2
> 

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

end of thread, other threads:[~2017-02-10 21:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-03 21:46 [PATCH 1/2] pcie-dpc: Decode extended reasons Keith Busch
2017-02-03 21:46 ` [PATCH 2/2] pcie-dpc: Wait for root port busy to clear Keith Busch
2017-02-06 11:15   ` Gabriele Paoloni
2017-02-10 21:03 ` [PATCH 1/2] pcie-dpc: Decode extended reasons Bjorn Helgaas

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).