Enable support for printing the LTSSM link state for debugging PCI
when link is down.
Signed-off-by: Faiz Abbas <[email protected]>
---
v2:
1. Changed dev_err() to dev_dbg()
2. Changed static char array to static const char * const
3. format changes
drivers/pci/dwc/pci-dra7xx.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/drivers/pci/dwc/pci-dra7xx.c b/drivers/pci/dwc/pci-dra7xx.c
index 34427a6..0e70e77 100644
--- a/drivers/pci/dwc/pci-dra7xx.c
+++ b/drivers/pci/dwc/pci-dra7xx.c
@@ -98,6 +98,45 @@ struct dra7xx_pcie_of_data {
#define to_dra7xx_pcie(x) dev_get_drvdata((x)->dev)
+static const char * const state[] = {
+ "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 +157,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_dbg(pci->dev, "Link state:%s\n", state[ltssm_state]);
+ }
return !!(reg & LINK_UP);
}
--
2.7.4
From 1581692623992864891@xxx Thu Oct 19 13:27:11 +0000 2017
X-GM-THRID: 1581691652519634530
X-Gmail-Labels: Inbox,Category Forums
From: Faiz Abbas
> Sent: 19 October 2017 14:09
> On Thursday 19 October 2017 06:13 PM, Faiz Abbas wrote:
> > Enable support for printing the LTSSM link state for debugging PCI
> > when link is down.
> >
> > Signed-off-by: Faiz Abbas <[email protected]>
> > ---
> > v2:
> > 1. Changed dev_err() to dev_dbg()
> > 2. Changed static char array to static const char * const
> > 3. format changes
> >
> > drivers/pci/dwc/pci-dra7xx.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 48 insertions(+)
> >
> > diff --git a/drivers/pci/dwc/pci-dra7xx.c b/drivers/pci/dwc/pci-dra7xx.c
> > index 34427a6..0e70e77 100644
> > --- a/drivers/pci/dwc/pci-dra7xx.c
> > +++ b/drivers/pci/dwc/pci-dra7xx.c
> > @@ -98,6 +98,45 @@ struct dra7xx_pcie_of_data {
> >
> > #define to_dra7xx_pcie(x) dev_get_drvdata((x)->dev)
> >
> > +static const char * const state[] = {
> > + "DETECT_QUIET",
...
> > + "RCVRY_EQ3"
> > +};
> > +
> > static inline u32 dra7xx_pcie_readl(struct dra7xx_pcie *pcie, u32 offset)
> > {
> > return readl(pcie->base + offset);
> > @@ -118,6 +157,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_dbg(pci->dev, "Link state:%s\n", state[ltssm_state]);
Hmmm... GENMASK leaves by hunting header files...
Why not (cmd_reg >> 2) & 63 and explicitly define state[64]
to guarantee that you never print anything worse than a NULL
pointer.
> > + }
> >
> > return !!(reg & LINK_UP);
> > }
> >
>
> I missed David's comment in v1. Will submit a new version. Please ignore.
I've a 'neat' trick for generating strings that match constants.
You can get the compiler to do all the work for you:
(Assuming I've typed it correctly)
#define LTSSM_DEFS(x) \
x(DETECT_QUIET) \
x(DETECT_ACT) \
(continue for all the names)
Define an enum with the named constants:
#define X(name) LTSSM_STATE_##name,
enum (LTSSM_DEFS(X) LTSSM_STATE_SIZE=64);
#undef X
Array of strings:
#define X(name) [LTSSM_STATE_##name] = #name
static const char * const state_names[LTSSM_STATE_SIZE] = { LTSSM_DEFS(X) };
#undef X
David
?&ן5??z?nu????}??S?㜷_u??u??~?M4?M{_???1? ????z?^?}?~9?E?f????m?l??ۣ?jנ??????
On Thursday 19 October 2017 06:13 PM, Faiz Abbas wrote:
> Enable support for printing the LTSSM link state for debugging PCI
> when link is down.
>
> Signed-off-by: Faiz Abbas <[email protected]>
> ---
> v2:
> 1. Changed dev_err() to dev_dbg()
> 2. Changed static char array to static const char * const
> 3. format changes
>
> drivers/pci/dwc/pci-dra7xx.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 48 insertions(+)
>
> diff --git a/drivers/pci/dwc/pci-dra7xx.c b/drivers/pci/dwc/pci-dra7xx.c
> index 34427a6..0e70e77 100644
> --- a/drivers/pci/dwc/pci-dra7xx.c
> +++ b/drivers/pci/dwc/pci-dra7xx.c
> @@ -98,6 +98,45 @@ struct dra7xx_pcie_of_data {
>
> #define to_dra7xx_pcie(x) dev_get_drvdata((x)->dev)
>
> +static const char * const state[] = {
> + "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 +157,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_dbg(pci->dev, "Link state:%s\n", state[ltssm_state]);
> + }
>
> return !!(reg & LINK_UP);
> }
>
I missed David's comment in v1. Will submit a new version. Please ignore.
Thanks,
Faiz
From 1583951429178262129@xxx Mon Nov 13 11:49:56 +0000 2017
X-GM-THRID: 1583223837737058963
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread