linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: mediatek-gen3: Print LTSSM state when PCIe link down
@ 2022-03-24  7:25 Jianjun Wang
  2022-03-28 14:39 ` AngeloGioacchino Del Regno
  0 siblings, 1 reply; 3+ messages in thread
From: Jianjun Wang @ 2022-03-24  7:25 UTC (permalink / raw)
  To: Ryder Lee, Lorenzo Pieralisi, Bjorn Helgaas
  Cc: Jianjun Wang, Rob Herring, Krzysztof Wilczyński,
	Matthias Brugger, linux-pci, linux-mediatek, linux-kernel,
	linux-arm-kernel, jieyy.yang, chuanjia.liu, qizhong.cheng,
	jian.yang

Print current LTSSM state when PCIe link down instead of the register
value, make it easier to get the link status.

Signed-off-by: Jianjun Wang <jianjun.wang@mediatek.com>
---
 drivers/pci/controller/pcie-mediatek-gen3.c | 40 ++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c b/drivers/pci/controller/pcie-mediatek-gen3.c
index 7705d61fba4c..54663f025e27 100644
--- a/drivers/pci/controller/pcie-mediatek-gen3.c
+++ b/drivers/pci/controller/pcie-mediatek-gen3.c
@@ -153,6 +153,37 @@ struct mtk_gen3_pcie {
 	DECLARE_BITMAP(msi_irq_in_use, PCIE_MSI_IRQS_NUM);
 };
 
+/* LTSSM state in PCIE_LTSSM_STATUS_REG bit[28:24] */
+static const char *const ltssm_str[] = {
+	"detect.quiet",			/* 0x00 */
+	"detect.active",		/* 0x01 */
+	"polling.active",		/* 0x02 */
+	"polling.compliance",		/* 0x03 */
+	"polling.configuration",	/* 0x04 */
+	"config.linkwidthstart",	/* 0x05 */
+	"config.linkwidthaccept",	/* 0x06 */
+	"config.lanenumwait",		/* 0x07 */
+	"config.lanenumaccept",		/* 0x08 */
+	"config.complete",		/* 0x09 */
+	"config.idle",			/* 0x0A */
+	"recovery.receiverlock",	/* 0x0B */
+	"recovery.equalization",	/* 0x0C */
+	"recovery.speed",		/* 0x0D */
+	"recovery.receiverconfig",	/* 0x0E */
+	"recovery.idle",		/* 0x0F */
+	"L0",				/* 0x10 */
+	"L0s",				/* 0x11 */
+	"L1.entry",			/* 0x12 */
+	"L1.idle",			/* 0x13 */
+	"L2.idle",			/* 0x14 */
+	"L2.transmitwake",		/* 0x15 */
+	"disable",			/* 0x16 */
+	"loopback.entry",		/* 0x17 */
+	"loopback.active",		/* 0x18 */
+	"loopback.exit",		/* 0x19 */
+	"hotreset",			/* 0x1A */
+};
+
 /**
  * mtk_pcie_config_tlp_header() - Configure a configuration TLP header
  * @bus: PCI bus to query
@@ -327,8 +358,15 @@ static int mtk_pcie_startup_port(struct mtk_gen3_pcie *pcie)
 				 !!(val & PCIE_PORT_LINKUP), 20,
 				 PCI_PM_D3COLD_WAIT * USEC_PER_MSEC);
 	if (err) {
+		const char *ltssm_state;
+		int ltssm_index;
+
 		val = readl_relaxed(pcie->base + PCIE_LTSSM_STATUS_REG);
-		dev_err(pcie->dev, "PCIe link down, ltssm reg val: %#x\n", val);
+		ltssm_index = PCIE_LTSSM_STATE(val);
+		ltssm_state = ltssm_index >= ARRAY_SIZE(ltssm_str) ?
+			      "Unknown state" : ltssm_str[ltssm_index];
+		dev_err(pcie->dev, "PCIe link down, current ltssm state: %s\n",
+			ltssm_state);
 		return err;
 	}
 
-- 
2.18.0


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

* Re: [PATCH] PCI: mediatek-gen3: Print LTSSM state when PCIe link down
  2022-03-24  7:25 [PATCH] PCI: mediatek-gen3: Print LTSSM state when PCIe link down Jianjun Wang
@ 2022-03-28 14:39 ` AngeloGioacchino Del Regno
  2022-03-29  2:00   ` Jianjun Wang
  0 siblings, 1 reply; 3+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-03-28 14:39 UTC (permalink / raw)
  To: Jianjun Wang, Ryder Lee, Lorenzo Pieralisi, Bjorn Helgaas
  Cc: Rob Herring, Krzysztof Wilczyński, Matthias Brugger,
	linux-pci, linux-mediatek, linux-kernel, linux-arm-kernel,
	jieyy.yang, chuanjia.liu, qizhong.cheng, jian.yang

Il 24/03/22 08:25, Jianjun Wang ha scritto:
> Print current LTSSM state when PCIe link down instead of the register
> value, make it easier to get the link status.
> 
> Signed-off-by: Jianjun Wang <jianjun.wang@mediatek.com>

Hello Jianjun,
this patch is really helpful when comes to understand the source of an issue,
so I agree with it - and thank you for that.

Though, I think that you should still print the hex number along with the
meaning of it, check below:

> ---
>   drivers/pci/controller/pcie-mediatek-gen3.c | 40 ++++++++++++++++++++-
>   1 file changed, 39 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c b/drivers/pci/controller/pcie-mediatek-gen3.c
> index 7705d61fba4c..54663f025e27 100644
> --- a/drivers/pci/controller/pcie-mediatek-gen3.c
> +++ b/drivers/pci/controller/pcie-mediatek-gen3.c

..snip..

> @@ -327,8 +358,15 @@ static int mtk_pcie_startup_port(struct mtk_gen3_pcie *pcie)
>   				 !!(val & PCIE_PORT_LINKUP), 20,
>   				 PCI_PM_D3COLD_WAIT * USEC_PER_MSEC);
>   	if (err) {
> +		const char *ltssm_state;
> +		int ltssm_index;
> +
>   		val = readl_relaxed(pcie->base + PCIE_LTSSM_STATUS_REG);
> -		dev_err(pcie->dev, "PCIe link down, ltssm reg val: %#x\n", val);
> +		ltssm_index = PCIE_LTSSM_STATE(val);
> +		ltssm_state = ltssm_index >= ARRAY_SIZE(ltssm_str) ?
> +			      "Unknown state" : ltssm_str[ltssm_index];
> +		dev_err(pcie->dev, "PCIe link down, current ltssm state: %s\n",

There, I think that you should do:

dev_err(pcie->dev, "PCIe link down, current LTSSM state: %s (%#x)\n",
	ltssm_state, val);

this will be extremely useful in the "Unknown state" case.

After fixing that,

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

Regards,
Angelo

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

* Re: [PATCH] PCI: mediatek-gen3: Print LTSSM state when PCIe link down
  2022-03-28 14:39 ` AngeloGioacchino Del Regno
@ 2022-03-29  2:00   ` Jianjun Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Jianjun Wang @ 2022-03-29  2:00 UTC (permalink / raw)
  To: AngeloGioacchino Del Regno, Ryder Lee, Lorenzo Pieralisi, Bjorn Helgaas
  Cc: Rob Herring, Krzysztof Wilczyński, Matthias Brugger,
	linux-pci, linux-mediatek, linux-kernel, linux-arm-kernel,
	jieyy.yang, chuanjia.liu, qizhong.cheng, jian.yang

On Mon, 2022-03-28 at 16:39 +0200, AngeloGioacchino Del Regno wrote:
> Il 24/03/22 08:25, Jianjun Wang ha scritto:
> > Print current LTSSM state when PCIe link down instead of the
> > register
> > value, make it easier to get the link status.
> > 
> > Signed-off-by: Jianjun Wang <jianjun.wang@mediatek.com>
> 
> Hello Jianjun,
> this patch is really helpful when comes to understand the source of
> an issue,
> so I agree with it - and thank you for that.
> 
> Though, I think that you should still print the hex number along with
> the
> meaning of it, check below:
> 
> > ---
> >   drivers/pci/controller/pcie-mediatek-gen3.c | 40
> > ++++++++++++++++++++-
> >   1 file changed, 39 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c
> > b/drivers/pci/controller/pcie-mediatek-gen3.c
> > index 7705d61fba4c..54663f025e27 100644
> > --- a/drivers/pci/controller/pcie-mediatek-gen3.c
> > +++ b/drivers/pci/controller/pcie-mediatek-gen3.c
> 
> ..snip..
> 
> > @@ -327,8 +358,15 @@ static int mtk_pcie_startup_port(struct
> > mtk_gen3_pcie *pcie)
> >   				 !!(val & PCIE_PORT_LINKUP), 20,
> >   				 PCI_PM_D3COLD_WAIT * USEC_PER_MSEC);
> >   	if (err) {
> > +		const char *ltssm_state;
> > +		int ltssm_index;
> > +
> >   		val = readl_relaxed(pcie->base +
> > PCIE_LTSSM_STATUS_REG);
> > -		dev_err(pcie->dev, "PCIe link down, ltssm reg val:
> > %#x\n", val);
> > +		ltssm_index = PCIE_LTSSM_STATE(val);
> > +		ltssm_state = ltssm_index >= ARRAY_SIZE(ltssm_str) ?
> > +			      "Unknown state" : ltssm_str[ltssm_index];
> > +		dev_err(pcie->dev, "PCIe link down, current ltssm
> > state: %s\n",
> 
> There, I think that you should do:
> 
> dev_err(pcie->dev, "PCIe link down, current LTSSM state: %s (%#x)\n",
> 	ltssm_state, val);
> 
> this will be extremely useful in the "Unknown state" case.
> 
> After fixing that,
> 
> Reviewed-by: AngeloGioacchino Del Regno <
> angelogioacchino.delregno@collabora.com>

Thanks!

> 
> Regards,
> Angelo


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

end of thread, other threads:[~2022-03-29  2:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24  7:25 [PATCH] PCI: mediatek-gen3: Print LTSSM state when PCIe link down Jianjun Wang
2022-03-28 14:39 ` AngeloGioacchino Del Regno
2022-03-29  2:00   ` Jianjun Wang

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