Skip to contentSkip to conversation

PCI: dwc: dra7xx: Print link state to console for debug

PATCH Superseded Faiz Abbas 3 participants 5 messages Oct 17, 2017 – Oct 19, 2017 PCI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Faiz Abbas

author
#0 lore raw

PATCH 1/1 PCI: dwc: dra7xx: Print link state to console for debug

Enable support for printing the LTSSM link state for debugging PCI when link is down.

---
 drivers/pci/dwc/pci-dra7xx.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/pci/dwc/pci-dra7xx.c +21 -0
index 34427a6..7b150b0 100644
@@ -98,6 +98,18 @@ struct dra7xx_pcie_of_data {
 
 #define to_dra7xx_pcie(x)	dev_get_drvdata((x)->dev)
 
+static char state[][20] = {
+	"DETECT_QUIET", "DETECT_ACT", "POLL_ACTIVE", "POLL_COMPLIANCE",
+	"POLL_CONFIG", "PRE_DETECT_QUIET", "DETECT_WAIT", "CFG_LINKWD_START",
+	"CFG_LINKWD_ACEPT", "CFG_LANENUM_WAIT", "CFG_LANENUM_ACEPT",
+	"CFG_COMPLETE", "CFG_IDLE", "RCVRY_LOCK", "RCVRY_SPEED",
+	"RCVRY_RCVRCFG", "RCVRY_IDLE", "L0", "L0S", "L123_SEND_EIDLE",
+	"L1_IDLE", "L2_IDLE", "L2_WAKE", "DISABLED_ENTRY", "DISABLED_IDLE",
+	"DISABLED", "LPBK_ENTRY", "LPBK_ACTIVE", "LPBK_EXIT",
+	"LPBK_EXIT_TIMEOUT", "HOT_RESET_ENTRY", "HOT_RESET", "RCVRY_EQ0",
+	"RCVRY_EQ1", "RCVRY_EQ2", "RCVRY_EQ3"
+};
+
 static inline u32 dra7xx_pcie_readl(struct dra7xx_pcie *pcie, u32 offset)
 {
 	return readl(pcie->base + offset);
@@ -118,6 +130,15 @@ static int dra7xx_pcie_link_up(struct dw_pcie *pci)
 {
 	struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci);
 	u32 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_PHY_CS);
+	u32 cmd_reg;
+	u32 ltssm_state;
+
+	if (!(reg & LINK_UP)) {
+		cmd_reg = dra7xx_pcie_readl(dra7xx,
+					    PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
+		ltssm_state = (cmd_reg & GENMASK(7, 2)) >> 2;
+		dev_err(pci->dev, "Link state:%s\n", state[ltssm_state]);
+	}
 
 	return !!(reg & LINK_UP);
 }
Signature · 1 line
2.7.4
#1 lore raw
Quoted 2 lines · Faiz Abbas

Enable support for printing the LTSSM link state for debugging PCI when link is down.

[]

Quoted 8 lines
drivers/pci/dwc/pci-dra7xx.c +0 -0
index 34427a6..7b150b0 100644
@@ -98,6 +98,18 @@ struct dra7xx_pcie_of_data {
 
 #define to_dra7xx_pcie(x)	dev_get_drvdata((x)->dev)
 

drivers/pci/dwc/pci-dra7xx.c struct dra7xx_pcie_of_data { · line 110

Quoted 10 lines
drivers/pci/dwc/pci-dra7xx.c +10 -0
+static char state[][20] = {
+	"DETECT_QUIET", "DETECT_ACT", "POLL_ACTIVE", "POLL_COMPLIANCE",
+	"POLL_CONFIG", "PRE_DETECT_QUIET", "DETECT_WAIT", "CFG_LINKWD_START",
+	"CFG_LINKWD_ACEPT", "CFG_LANENUM_WAIT", "CFG_LANENUM_ACEPT",
+	"CFG_COMPLETE", "CFG_IDLE", "RCVRY_LOCK", "RCVRY_SPEED",
+	"RCVRY_RCVRCFG", "RCVRY_IDLE", "L0", "L0S", "L123_SEND_EIDLE",
+	"L1_IDLE", "L2_IDLE", "L2_WAKE", "DISABLED_ENTRY", "DISABLED_IDLE",
+	"DISABLED", "LPBK_ENTRY", "LPBK_ACTIVE", "LPBK_EXIT",
+	"LPBK_EXIT_TIMEOUT", "HOT_RESET_ENTRY", "HOT_RESET", "RCVRY_EQ0",
+	"RCVRY_EQ1", "RCVRY_EQ2", "RCVRY_EQ3"

what's wrong with using the far more typical

static const char *link_state[] = {
	"DETECT_QUIET",
	...
};
Quoted 7 lines
drivers/pci/dwc/pci-dra7xx.c +2 -0
+};
+
 static inline u32 dra7xx_pcie_readl(struct dra7xx_pcie *pcie, u32 offset)
 {
 	return readl(pcie->base + offset);
@@ -118,6 +130,15 @@ static int dra7xx_pcie_link_up(struct dw_pcie *pci)
 {

drivers/pci/dwc/pci-dra7xx.c static int dra7xx_pcie_link_up(struct dw_pcie *pci) · line 140

Quoted 10 lines
drivers/pci/dwc/pci-dra7xx.c +8 -0
 	struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci);
 	u32 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_PHY_CS);
+	u32 cmd_reg;
+	u32 ltssm_state;
+
+	if (!(reg & LINK_UP)) {
+		cmd_reg = dra7xx_pcie_readl(dra7xx,
+					    PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
+		ltssm_state = (cmd_reg & GENMASK(7, 2)) >> 2;
+		dev_err(pci->dev, "Link state:%s\n", state[ltssm_state]);

and why is this a dev_err and not dev_info? and if it's really for debugging, why not dev_dbg?

Quoted 4 lines
drivers/pci/dwc/pci-dra7xx.c +1 -0
+	}
 
 	return !!(reg & LINK_UP);
 }
#2 lore raw

From: Joe Perches

Quoted 26 lines

Sent: 17 October 2017 07:35

Quoted 2 lines · Faiz Abbas

Enable support for printing the LTSSM link state for debugging PCI when link is down.

[]

Quoted 8 lines
drivers/pci/dwc/pci-dra7xx.c +0 -0
index 34427a6..7b150b0 100644
@@ -98,6 +98,18 @@ struct dra7xx_pcie_of_data {
 
 #define to_dra7xx_pcie(x)	dev_get_drvdata((x)->dev)
 

drivers/pci/dwc/pci-dra7xx.c struct dra7xx_pcie_of_data { · line 110

Quoted 10 lines
drivers/pci/dwc/pci-dra7xx.c +10 -0
+static char state[][20] = {
+	"DETECT_QUIET", "DETECT_ACT", "POLL_ACTIVE", "POLL_COMPLIANCE",
+	"POLL_CONFIG", "PRE_DETECT_QUIET", "DETECT_WAIT", "CFG_LINKWD_START",
+	"CFG_LINKWD_ACEPT", "CFG_LANENUM_WAIT", "CFG_LANENUM_ACEPT",
+	"CFG_COMPLETE", "CFG_IDLE", "RCVRY_LOCK", "RCVRY_SPEED",
+	"RCVRY_RCVRCFG", "RCVRY_IDLE", "L0", "L0S", "L123_SEND_EIDLE",
+	"L1_IDLE", "L2_IDLE", "L2_WAKE", "DISABLED_ENTRY", "DISABLED_IDLE",
+	"DISABLED", "LPBK_ENTRY", "LPBK_ACTIVE", "LPBK_EXIT",
+	"LPBK_EXIT_TIMEOUT", "HOT_RESET_ENTRY", "HOT_RESET", "RCVRY_EQ0",
+	"RCVRY_EQ1", "RCVRY_EQ2", "RCVRY_EQ3"

what's wrong with using the far more typical

Quoted 3 lines
static const char *link_state[] = {
	"DETECT_QUIET",
	...

Or 4 aligned columns.
Better still used named initialisers:
[xxx_DETECT_QUIET] = "DETECT_QUIET",
you really don't want an 'off-by-one' in that list.

David

author
#4 lore raw
In reply to Joe Perches
Quoted 25 lines · Joe Perches
Quoted 2 lines · Faiz Abbas

Enable support for printing the LTSSM link state for debugging PCI when link is down.

[]

Quoted 8 lines
drivers/pci/dwc/pci-dra7xx.c +0 -0
index 34427a6..7b150b0 100644
@@ -98,6 +98,18 @@ struct dra7xx_pcie_of_data {
 
 #define to_dra7xx_pcie(x)	dev_get_drvdata((x)->dev)
 

drivers/pci/dwc/pci-dra7xx.c struct dra7xx_pcie_of_data { · line 110

Quoted 10 lines
drivers/pci/dwc/pci-dra7xx.c +10 -0
+static char state[][20] = {
+	"DETECT_QUIET", "DETECT_ACT", "POLL_ACTIVE", "POLL_COMPLIANCE",
+	"POLL_CONFIG", "PRE_DETECT_QUIET", "DETECT_WAIT", "CFG_LINKWD_START",
+	"CFG_LINKWD_ACEPT", "CFG_LANENUM_WAIT", "CFG_LANENUM_ACEPT",
+	"CFG_COMPLETE", "CFG_IDLE", "RCVRY_LOCK", "RCVRY_SPEED",
+	"RCVRY_RCVRCFG", "RCVRY_IDLE", "L0", "L0S", "L123_SEND_EIDLE",
+	"L1_IDLE", "L2_IDLE", "L2_WAKE", "DISABLED_ENTRY", "DISABLED_IDLE",
+	"DISABLED", "LPBK_ENTRY", "LPBK_ACTIVE", "LPBK_EXIT",
+	"LPBK_EXIT_TIMEOUT", "HOT_RESET_ENTRY", "HOT_RESET", "RCVRY_EQ0",
+	"RCVRY_EQ1", "RCVRY_EQ2", "RCVRY_EQ3"

what's wrong with using the far more typical

Quoted 4 lines
static const char *link_state[] = {
	"DETECT_QUIET",
	...
};

Too many lines?

Quoted 22 lines
Quoted 8 lines
drivers/pci/dwc/pci-dra7xx.c +2 -0
+};
+
 static inline u32 dra7xx_pcie_readl(struct dra7xx_pcie *pcie, u32 offset)
 {
 	return readl(pcie->base + offset);
@@ -118,6 +130,15 @@ static int dra7xx_pcie_link_up(struct dw_pcie *pci)
 {

drivers/pci/dwc/pci-dra7xx.c static int dra7xx_pcie_link_up(struct dw_pcie *pci) · line 140

Quoted 10 lines
drivers/pci/dwc/pci-dra7xx.c +8 -0
 	struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci);
 	u32 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_PHY_CS);
+	u32 cmd_reg;
+	u32 ltssm_state;
+
+	if (!(reg & LINK_UP)) {
+		cmd_reg = dra7xx_pcie_readl(dra7xx,
+					    PCIECTRL_DRA7XX_CONF_DEVICE_CMD);
+		ltssm_state = (cmd_reg & GENMASK(7, 2)) >> 2;
+		dev_err(pci->dev, "Link state:%s\n", state[ltssm_state]);

and why is this a dev_err and not dev_info? and if it's really for debugging, why not dev_dbg?

Quoted 4 lines

drivers/pci/dwc/pci-dra7xx.c static int dra7xx_pcie_link_up(struct dw_pcie *pci) · line 144

Quoted 4 lines
drivers/pci/dwc/pci-dra7xx.c +1 -0
+	}
 
 	return !!(reg & LINK_UP);
 }

Will change to dev_dbg.

Thanks,
Faiz

author
#3 lore raw
In reply to David Laight

Hi,

Quoted 27 lines · David Laight

From: Joe Perches

Quoted 26 lines

Sent: 17 October 2017 07:35

Quoted 2 lines · Faiz Abbas

Enable support for printing the LTSSM link state for debugging PCI when link is down.

[]

Quoted 8 lines
drivers/pci/dwc/pci-dra7xx.c +0 -0
index 34427a6..7b150b0 100644
@@ -98,6 +98,18 @@ struct dra7xx_pcie_of_data {
 
 #define to_dra7xx_pcie(x)	dev_get_drvdata((x)->dev)
 

drivers/pci/dwc/pci-dra7xx.c struct dra7xx_pcie_of_data { · line 110

Quoted 10 lines
drivers/pci/dwc/pci-dra7xx.c +10 -0
+static char state[][20] = {
+	"DETECT_QUIET", "DETECT_ACT", "POLL_ACTIVE", "POLL_COMPLIANCE",
+	"POLL_CONFIG", "PRE_DETECT_QUIET", "DETECT_WAIT", "CFG_LINKWD_START",
+	"CFG_LINKWD_ACEPT", "CFG_LANENUM_WAIT", "CFG_LANENUM_ACEPT",
+	"CFG_COMPLETE", "CFG_IDLE", "RCVRY_LOCK", "RCVRY_SPEED",
+	"RCVRY_RCVRCFG", "RCVRY_IDLE", "L0", "L0S", "L123_SEND_EIDLE",
+	"L1_IDLE", "L2_IDLE", "L2_WAKE", "DISABLED_ENTRY", "DISABLED_IDLE",
+	"DISABLED", "LPBK_ENTRY", "LPBK_ACTIVE", "LPBK_EXIT",
+	"LPBK_EXIT_TIMEOUT", "HOT_RESET_ENTRY", "HOT_RESET", "RCVRY_EQ0",
+	"RCVRY_EQ1", "RCVRY_EQ2", "RCVRY_EQ3"

what's wrong with using the far more typical

Quoted 5 lines
Quoted 3 lines
static const char *link_state[] = {
	"DETECT_QUIET",
	...

Or 4 aligned columns.

4 aligned columns are difficult as the strings are of different sizes.

Quoted 3 lines

Better still used named initialisers:
[xxx_DETECT_QUIET] = "DETECT_QUIET",
you really don't want an 'off-by-one' in that list.

Sounds good. Let me see how I can implement this.

Thanks,
Faiz