Skip to contentSkip to conversation

PCI: Cadence: Add quirk for Gen2 controller to do autonomous speed change.

PATCH In review Nadeem Athani 4 participants 7 messages Sep 23, 2020 – Sep 30, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 PCI: Cadence: Add quirk for Gen2 controller to do autonomous speed change.

Cadence controller will not initiate autonomous speed change if strapped as Gen2. The Retrain bit is set as a quirk to trigger this speed change.

---
 drivers/pci/controller/cadence/pcie-cadence-host.c | 14 ++++++++++++++
 drivers/pci/controller/cadence/pcie-cadence.h      | 15 +++++++++++++++
 2 files changed, 29 insertions(+)
drivers/pci/controller/cadence/pcie-cadence-host.c +14 -0
index 4550e0d469ca..a2317614268d 100644
@@ -83,6 +83,9 @@ static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)
 	struct cdns_pcie *pcie = &rc->pcie;
 	u32 value, ctrl;
 	u32 id;
+	u32 link_cap = CDNS_PCIE_LINK_CAP_OFFSET;
+	u8 sls;
+	u16 lnk_ctl;
 
 	/*
 	 * Set the root complex BAR configuration register:
@@ -111,6 +114,17 @@ static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)
 	if (rc->device_id != 0xffff)
 		cdns_pcie_rp_writew(pcie, PCI_DEVICE_ID, rc->device_id);
 
+	/* Quirk to enable autonomous speed change for GEN2 controller */
+	/* Reading Supported Link Speed value */
+	sls = PCI_EXP_LNKCAP_SLS &
+		cdns_pcie_rp_readb(pcie, link_cap + PCI_EXP_LNKCAP);
+	if (sls == PCI_EXP_LNKCAP_SLS_5_0GB) {
+		/* Since this a Gen2 controller, set Retrain Link(RL) bit */
+		lnk_ctl = cdns_pcie_rp_readw(pcie, link_cap + PCI_EXP_LNKCTL);
+		lnk_ctl |= PCI_EXP_LNKCTL_RL;
+		cdns_pcie_rp_writew(pcie, link_cap + PCI_EXP_LNKCTL, lnk_ctl);
+	}
+
 	cdns_pcie_rp_writeb(pcie, PCI_CLASS_REVISION, 0);
 	cdns_pcie_rp_writeb(pcie, PCI_CLASS_PROG, 0);
 	cdns_pcie_rp_writew(pcie, PCI_CLASS_DEVICE, PCI_CLASS_BRIDGE_PCI);
drivers/pci/controller/cadence/pcie-cadence.h +15 -0
index feed1e3038f4..fe560480c573 100644
@@ -120,6 +120,7 @@
  */
 #define CDNS_PCIE_RP_BASE	0x00200000
 
+#define CDNS_PCIE_LINK_CAP_OFFSET 0xC0
 
 /*
  * Address Translation Registers
@@ -413,6 +414,20 @@ static inline void cdns_pcie_rp_writew(struct cdns_pcie *pcie,
 	cdns_pcie_write_sz(addr, 0x2, value);
 }
 
+static inline u8 cdns_pcie_rp_readb(struct cdns_pcie *pcie, u32 reg)
+{
+	void __iomem *addr = pcie->reg_base + CDNS_PCIE_RP_BASE + reg;
+
+	return cdns_pcie_read_sz(addr, 0x1);
+}
+
+static inline u16 cdns_pcie_rp_readw(struct cdns_pcie *pcie, u32 reg)
+{
+	void __iomem *addr = pcie->reg_base + CDNS_PCIE_RP_BASE + reg;
+
+	return cdns_pcie_read_sz(addr, 0x2);
+}
+
 /* Endpoint Function register access */
 static inline void cdns_pcie_ep_fn_writeb(struct cdns_pcie *pcie, u8 fn,
 					  u32 reg, u8 value)
Signature · 1 line
2.15.0
reviewer
#1 lore raw
Quoted 26 lines · Nadeem Athani

Cadence controller will not initiate autonomous speed change if strapped as Gen2. The Retrain bit is set as a quirk to trigger this speed change.

---
 drivers/pci/controller/cadence/pcie-cadence-host.c | 14 ++++++++++++++
 drivers/pci/controller/cadence/pcie-cadence.h      | 15 +++++++++++++++
 2 files changed, 29 insertions(+)
drivers/pci/controller/cadence/pcie-cadence-host.c +3 -0
index 4550e0d469ca..a2317614268d 100644
@@ -83,6 +83,9 @@ static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)
        struct cdns_pcie *pcie = &rc->pcie;
        u32 value, ctrl;
        u32 id;
+       u32 link_cap = CDNS_PCIE_LINK_CAP_OFFSET;
+       u8 sls;
+       u16 lnk_ctl;
 
        /*
         * Set the root complex BAR configuration register:

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc) · line 120

Quoted 7 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +4 -0
@@ -111,6 +114,17 @@ static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)
        if (rc->device_id != 0xffff)
                cdns_pcie_rp_writew(pcie, PCI_DEVICE_ID, rc->device_id);
 
+       /* Quirk to enable autonomous speed change for GEN2 controller */
+       /* Reading Supported Link Speed value */
+       sls = PCI_EXP_LNKCAP_SLS &
+               cdns_pcie_rp_readb(pcie, link_cap + PCI_EXP_LNKCAP);

A 32-bit register, right?

Quoted 46 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +7 -0
+       if (sls == PCI_EXP_LNKCAP_SLS_5_0GB) {
+               /* Since this a Gen2 controller, set Retrain Link(RL) bit */
+               lnk_ctl = cdns_pcie_rp_readw(pcie, link_cap + PCI_EXP_LNKCTL);
+               lnk_ctl |= PCI_EXP_LNKCTL_RL;
+               cdns_pcie_rp_writew(pcie, link_cap + PCI_EXP_LNKCTL, lnk_ctl);
+       }
+
        cdns_pcie_rp_writeb(pcie, PCI_CLASS_REVISION, 0);
        cdns_pcie_rp_writeb(pcie, PCI_CLASS_PROG, 0);
        cdns_pcie_rp_writew(pcie, PCI_CLASS_DEVICE, PCI_CLASS_BRIDGE_PCI);
drivers/pci/controller/cadence/pcie-cadence.h +15 -1
index feed1e3038f4..fe560480c573 100644
@@ -120,6 +120,7 @@
  */
 #define CDNS_PCIE_RP_BASE      0x00200000
 
+#define CDNS_PCIE_LINK_CAP_OFFSET 0xC0
 
 /*
  * Address Translation Registers
@@ -413,6 +414,20 @@ static inline void cdns_pcie_rp_writew(struct cdns_pcie *pcie,
        cdns_pcie_write_sz(addr, 0x2, value);
 }
 
+static inline u8 cdns_pcie_rp_readb(struct cdns_pcie *pcie, u32 reg)
+{
+       void __iomem *addr = pcie->reg_base + CDNS_PCIE_RP_BASE + reg;
+
+       return cdns_pcie_read_sz(addr, 0x1);
+}
+
+static inline u16 cdns_pcie_rp_readw(struct cdns_pcie *pcie, u32 reg)
+{
+       void __iomem *addr = pcie->reg_base + CDNS_PCIE_RP_BASE + reg;
+
+       return cdns_pcie_read_sz(addr, 0x2);
+}
+
 /* Endpoint Function register access */
 static inline void cdns_pcie_ep_fn_writeb(struct cdns_pcie *pcie, u8 fn,
                                          u32 reg, u8 value)
--

2.15.0

#2 lore raw

Hi Rob,

Quoted 50 lines

-----Original Message-----
From: Rob Herring <[email protected]>
Sent: Thursday, September 24, 2020 1:16 AM
To: Athani Nadeem Ladkhan <[email protected]>
Cc: Tom Joseph <[email protected]>; Lorenzo Pieralisi <[email protected]>; Bjorn Helgaas <[email protected]>; PCI <[email protected]>; [email protected]; Kishon Vijay Abraham I <[email protected]>; Milind Parab <[email protected]>; Swapnil Kashinath Jakhade <[email protected]>
Subject: Re: [PATCH v2] PCI: Cadence: Add quirk for Gen2 controller to do autonomous speed change.

EXTERNAL MAIL

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct

Quoted 17 lines · Nadeem Athani

Cadence controller will not initiate autonomous speed change if strapped as Gen2. The Retrain bit is set as a quirk to trigger this speed change.

---
 drivers/pci/controller/cadence/pcie-cadence-host.c | 14 ++++++++++++++
 drivers/pci/controller/cadence/pcie-cadence.h      | 15 +++++++++++++++
 2 files changed, 29 insertions(+)
drivers/pci/controller/cadence/pcie-cadence-host.c +0 -0
index 4550e0d469ca..a2317614268d 100644
@@ -83,6 +83,9 @@ static int cdns_pcie_host_init_root_port(struct

cdns_pcie_rc *rc)

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct

Quoted 10 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +3 -0
        struct cdns_pcie *pcie = &rc->pcie;
        u32 value, ctrl;
        u32 id;
+       u32 link_cap = CDNS_PCIE_LINK_CAP_OFFSET;
+       u8 sls;
+       u16 lnk_ctl;
 
        /*
         * Set the root complex BAR configuration register:
@@ -111,6 +114,17 @@ static int cdns_pcie_host_init_root_port(struct

cdns_pcie_rc *rc)

Quoted 4 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +0 -0
        if (rc->device_id != 0xffff)
                cdns_pcie_rp_writew(pcie, PCI_DEVICE_ID,
 rc->device_id);
 
Quoted 6 lines

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc) · line 120

Quoted 4 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +4 -0
+       /* Quirk to enable autonomous speed change for GEN2 controller */
+       /* Reading Supported Link Speed value */
+       sls = PCI_EXP_LNKCAP_SLS &
+               cdns_pcie_rp_readb(pcie, link_cap + PCI_EXP_LNKCAP);

A 32-bit register, right?

Right, this will be corrected in patch version 3.

Quoted 47 lines

drivers/pci/controller/cadence/pcie-cadence.h static inline void cdns_pcie_rp_writew(struct

Quoted 26 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +7 -0
+       if (sls == PCI_EXP_LNKCAP_SLS_5_0GB) {
+               /* Since this a Gen2 controller, set Retrain Link(RL) bit */
+               lnk_ctl = cdns_pcie_rp_readw(pcie, link_cap + PCI_EXP_LNKCTL);
+               lnk_ctl |= PCI_EXP_LNKCTL_RL;
+               cdns_pcie_rp_writew(pcie, link_cap + PCI_EXP_LNKCTL, lnk_ctl);
+       }
+
        cdns_pcie_rp_writeb(pcie, PCI_CLASS_REVISION, 0);
        cdns_pcie_rp_writeb(pcie, PCI_CLASS_PROG, 0);

cdns_pcie_rp_writew(pcie, PCI_CLASS_DEVICE,
PCI_CLASS_BRIDGE_PCI); diff --git a/drivers/pci/controller/cadence/pcie-cadence.h b/drivers/pci/controller/cadence/pcie-cadence.h index feed1e3038f4..fe560480c573 100644

drivers/pci/controller/cadence/pcie-cadence.h +1 -0
@@ -120,6 +120,7 @@
  */
 #define CDNS_PCIE_RP_BASE      0x00200000
 
+#define CDNS_PCIE_LINK_CAP_OFFSET 0xC0
 
 /*
  * Address Translation Registers
@@ -413,6 +414,20 @@ static inline void cdns_pcie_rp_writew(struct

cdns_pcie *pcie,

Quoted 20 lines
drivers/pci/controller/cadence/pcie-cadence.h +12 -1
        cdns_pcie_write_sz(addr, 0x2, value);  }
 
+static inline u8 cdns_pcie_rp_readb(struct cdns_pcie *pcie, u32 reg)
+{
+       void __iomem *addr = pcie->reg_base + CDNS_PCIE_RP_BASE + reg;
+
+       return cdns_pcie_read_sz(addr, 0x1); }
+
+static inline u16 cdns_pcie_rp_readw(struct cdns_pcie *pcie, u32 reg)
+{
+       void __iomem *addr = pcie->reg_base + CDNS_PCIE_RP_BASE + reg;
+
+       return cdns_pcie_read_sz(addr, 0x2); }
+
 /* Endpoint Function register access */  static inline void
 cdns_pcie_ep_fn_writeb(struct cdns_pcie *pcie, u8 fn,
                                          u32 reg, u8 value)
--

2.15.0

#3 lore raw
In reply to Nadeem Athani

Something like:

PCI: cadence: Retrain Link to work around Gen2 training defect

to match history (see "git log --oneline drivers/pci/controller/cadence/pcie-cadence-host.c").

Quoted 3 lines · Nadeem Athani

Cadence controller will not initiate autonomous speed change if strapped as Gen2. The Retrain bit is set as a quirk to trigger this speed change.

To match the spec terminology:

Set the Retrain Link bit ...

Obviously I don't know the details of your device or even how PCIe works at this level. But IIUC a link always comes up at 2.5 GT/s first and then the upstream and downstream components negotiate the highest speed they both support. It sounds like your controller doesn't actually do this negotiation unless you set the Retrain Link bit?

Is cdns_pcie_host_init_root_port() the only time this needs to be done? We don't have to worry about doing this again after a reset, hot-add event, etc?

Quoted 11 lines
---
 drivers/pci/controller/cadence/pcie-cadence-host.c | 14 ++++++++++++++
 drivers/pci/controller/cadence/pcie-cadence.h      | 15 +++++++++++++++
 2 files changed, 29 insertions(+)
drivers/pci/controller/cadence/pcie-cadence-host.c +0 -0
index 4550e0d469ca..a2317614268d 100644

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc) · line 86

Quoted 4 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +1 -0
@@ -83,6 +83,9 @@ static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)
 	struct cdns_pcie *pcie = &rc->pcie;
 	u32 value, ctrl;
 	u32 id;
+	u32 link_cap = CDNS_PCIE_LINK_CAP_OFFSET;

This is not actually the link cap offset. Based on the usage, this appears to be the offset of the PCIe Capability.

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc) · line 120

Quoted 13 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +6 -0
+	u8 sls;
+	u16 lnk_ctl;
 
 	/*
 	 * Set the root complex BAR configuration register:
@@ -111,6 +114,17 @@ static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)
 	if (rc->device_id != 0xffff)
 		cdns_pcie_rp_writew(pcie, PCI_DEVICE_ID, rc->device_id);
 
+	/* Quirk to enable autonomous speed change for GEN2 controller */
+	/* Reading Supported Link Speed value */
+	sls = PCI_EXP_LNKCAP_SLS &
+		cdns_pcie_rp_readb(pcie, link_cap + PCI_EXP_LNKCAP);

The conventional way to write this would be

sls = cdns_pcie_rp_readb(pcie, link_cap + PCI_EXP_LNKCAP) &

    PCI_EXP_LNKCAP_SLS;
Quoted 15 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +7 -0
+	if (sls == PCI_EXP_LNKCAP_SLS_5_0GB) {
+		/* Since this a Gen2 controller, set Retrain Link(RL) bit */
+		lnk_ctl = cdns_pcie_rp_readw(pcie, link_cap + PCI_EXP_LNKCTL);
+		lnk_ctl |= PCI_EXP_LNKCTL_RL;
+		cdns_pcie_rp_writew(pcie, link_cap + PCI_EXP_LNKCTL, lnk_ctl);
+	}
+
 	cdns_pcie_rp_writeb(pcie, PCI_CLASS_REVISION, 0);
 	cdns_pcie_rp_writeb(pcie, PCI_CLASS_PROG, 0);
 	cdns_pcie_rp_writew(pcie, PCI_CLASS_DEVICE, PCI_CLASS_BRIDGE_PCI);
drivers/pci/controller/cadence/pcie-cadence.h +0 -0
index feed1e3038f4..fe560480c573 100644

drivers/pci/controller/cadence/pcie-cadence.h line 123

Quoted 4 lines
drivers/pci/controller/cadence/pcie-cadence.h +1 -0
@@ -120,6 +120,7 @@
  */
 #define CDNS_PCIE_RP_BASE	0x00200000
 
+#define CDNS_PCIE_LINK_CAP_OFFSET 0xC0

Use lower-case in hex as the rest of the file does.

Quoted 26 lines
drivers/pci/controller/cadence/pcie-cadence.h +14 -0
 /*
  * Address Translation Registers
@@ -413,6 +414,20 @@ static inline void cdns_pcie_rp_writew(struct cdns_pcie *pcie,
 	cdns_pcie_write_sz(addr, 0x2, value);
 }
 
+static inline u8 cdns_pcie_rp_readb(struct cdns_pcie *pcie, u32 reg)
+{
+	void __iomem *addr = pcie->reg_base + CDNS_PCIE_RP_BASE + reg;
+
+	return cdns_pcie_read_sz(addr, 0x1);
+}
+
+static inline u16 cdns_pcie_rp_readw(struct cdns_pcie *pcie, u32 reg)
+{
+	void __iomem *addr = pcie->reg_base + CDNS_PCIE_RP_BASE + reg;
+
+	return cdns_pcie_read_sz(addr, 0x2);
+}
+
 /* Endpoint Function register access */
 static inline void cdns_pcie_ep_fn_writeb(struct cdns_pcie *pcie, u8 fn,
 					  u32 reg, u8 value)
Signature · 1 line
2.15.0
#4 lore raw

Hi Bjorn,

Quoted 15 lines

-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: Thursday, September 24, 2020 2:08 AM
To: Athani Nadeem Ladkhan <[email protected]>
Cc: Tom Joseph <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; Milind Parab <[email protected]>; Swapnil Kashinath Jakhade <[email protected]>
Subject: Re: [PATCH v2] PCI: Cadence: Add quirk for Gen2 controller to do autonomous speed change.

EXTERNAL MAIL

Quoted 6 lines

Something like:

PCI: cadence: Retrain Link to work around Gen2 training defect

to match history (see "git log --oneline drivers/pci/controller/cadence/pcie- cadence-host.c").

This will be corrected in patch version 3.

Quoted 9 lines · Nadeem Athani
Quoted 3 lines

Cadence controller will not initiate autonomous speed change if strapped as Gen2. The Retrain bit is set as a quirk to trigger this speed change.

To match the spec terminology:

Set the Retrain Link bit ...

This will be corrected in patch version 3.

Quoted 6 lines

Obviously I don't know the details of your device or even how PCIe works at this level. But IIUC a link always comes up at 2.5 GT/s first and then the upstream and downstream components negotiate the highest speed they both support. It sounds like your controller doesn't actually do this negotiation unless you set the Retrain Link bit?

Some Gen2 controller variants doesn't support this negotiation. Hence required to set the Retrain Link bit. This will be handled in much better way in patch version 3.

Quoted 3 lines

Is cdns_pcie_host_init_root_port() the only time this needs to be done? We don't have to worry about doing this again after a reset, hot-add event, etc?

Yes. Only during init.

Quoted 14 lines

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct

Quoted 13 lines
---
 drivers/pci/controller/cadence/pcie-cadence-host.c | 14 ++++++++++++++
 drivers/pci/controller/cadence/pcie-cadence.h      | 15 +++++++++++++++
 2 files changed, 29 insertions(+)
drivers/pci/controller/cadence/pcie-cadence-host.c +0 -0
index 4550e0d469ca..a2317614268d 100644
@@ -83,6 +83,9 @@ static int cdns_pcie_host_init_root_port(struct

cdns_pcie_rc *rc)

Quoted 7 lines

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc) · line 86

Quoted 4 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +1 -0
 	struct cdns_pcie *pcie = &rc->pcie;
 	u32 value, ctrl;
 	u32 id;
+	u32 link_cap = CDNS_PCIE_LINK_CAP_OFFSET;

This is not actually the link cap offset. Based on the usage, this appears to be the offset of the PCIe Capability.

This will be corrected in patch version 3.

Quoted 18 lines

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct

Quoted 7 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +2 -0
+	u8 sls;
+	u16 lnk_ctl;
 
 	/*
 	 * Set the root complex BAR configuration register:
@@ -111,6 +114,17 @@ static int cdns_pcie_host_init_root_port(struct

cdns_pcie_rc *rc)

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc) · line 120

Quoted 7 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +4 -0
 	if (rc->device_id != 0xffff)
 		cdns_pcie_rp_writew(pcie, PCI_DEVICE_ID, rc->device_id);
 
+	/* Quirk to enable autonomous speed change for GEN2 controller */
+	/* Reading Supported Link Speed value */
+	sls = PCI_EXP_LNKCAP_SLS &
+		cdns_pcie_rp_readb(pcie, link_cap + PCI_EXP_LNKCAP);

The conventional way to write this would be

Quoted 2 lines

sls = cdns_pcie_rp_readb(pcie, link_cap + PCI_EXP_LNKCAP) &

    PCI_EXP_LNKCAP_SLS;

This will be corrected in patch version 3.

Quoted 23 lines

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)

Quoted 4 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +3 -0
+	if (sls == PCI_EXP_LNKCAP_SLS_5_0GB) {
+		/* Since this a Gen2 controller, set Retrain Link(RL) bit */
+		lnk_ctl = cdns_pcie_rp_readw(pcie, link_cap +

PCI_EXP_LNKCTL);

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct · line 125

Quoted 2 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +2 -0
+		lnk_ctl |= PCI_EXP_LNKCTL_RL;
+		cdns_pcie_rp_writew(pcie, link_cap + PCI_EXP_LNKCTL,

lnk_ctl);

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)

Quoted 5 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +2 -0
+	}
+
 	cdns_pcie_rp_writeb(pcie, PCI_CLASS_REVISION, 0);
 	cdns_pcie_rp_writeb(pcie, PCI_CLASS_PROG, 0);
 	cdns_pcie_rp_writew(pcie, PCI_CLASS_DEVICE,

PCI_CLASS_BRIDGE_PCI);

Quoted 9 lines
drivers/pci/controller/cadence/pcie-cadence.h +0 -0
index feed1e3038f4..fe560480c573 100644
@@ -120,6 +120,7 @@
  */
 #define CDNS_PCIE_RP_BASE	0x00200000
 
Quoted 3 lines

drivers/pci/controller/cadence/pcie-cadence.h line 123

Quoted 1 line
drivers/pci/controller/cadence/pcie-cadence.h +1 -0
+#define CDNS_PCIE_LINK_CAP_OFFSET 0xC0

Use lower-case in hex as the rest of the file does.

This will be corrected in patch version 3.

Quoted 25 lines

drivers/pci/controller/cadence/pcie-cadence.h static inline void cdns_pcie_rp_writew(struct

Quoted 4 lines
drivers/pci/controller/cadence/pcie-cadence.h +0 -0
 /*
  * Address Translation Registers
@@ -413,6 +414,20 @@ static inline void cdns_pcie_rp_writew(struct

cdns_pcie *pcie,

Quoted 20 lines
drivers/pci/controller/cadence/pcie-cadence.h +12 -1
 	cdns_pcie_write_sz(addr, 0x2, value);  }
 
+static inline u8 cdns_pcie_rp_readb(struct cdns_pcie *pcie, u32 reg)
+{
+	void __iomem *addr = pcie->reg_base + CDNS_PCIE_RP_BASE + reg;
+
+	return cdns_pcie_read_sz(addr, 0x1); }
+
+static inline u16 cdns_pcie_rp_readw(struct cdns_pcie *pcie, u32 reg)
+{
+	void __iomem *addr = pcie->reg_base + CDNS_PCIE_RP_BASE + reg;
+
+	return cdns_pcie_read_sz(addr, 0x2); }
+
 /* Endpoint Function register access */  static inline void
 cdns_pcie_ep_fn_writeb(struct cdns_pcie *pcie, u8 fn,
 					  u32 reg, u8 value)
--

2.15.0

#5 lore raw
In reply to Nadeem Athani

Hi Nadeem,

Quoted 28 lines · Nadeem Athani

Cadence controller will not initiate autonomous speed change if strapped as Gen2. The Retrain bit is set as a quirk to trigger this speed change.

---
 drivers/pci/controller/cadence/pcie-cadence-host.c | 14 ++++++++++++++
 drivers/pci/controller/cadence/pcie-cadence.h      | 15 +++++++++++++++
 2 files changed, 29 insertions(+)
drivers/pci/controller/cadence/pcie-cadence-host.c +3 -0
index 4550e0d469ca..a2317614268d 100644
@@ -83,6 +83,9 @@ static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)
 	struct cdns_pcie *pcie = &rc->pcie;
 	u32 value, ctrl;
 	u32 id;
+	u32 link_cap = CDNS_PCIE_LINK_CAP_OFFSET;
+	u8 sls;
+	u16 lnk_ctl;
 
 	/*
 	 * Set the root complex BAR configuration register:
@@ -111,6 +114,17 @@ static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)
 	if (rc->device_id != 0xffff)
 		cdns_pcie_rp_writew(pcie, PCI_DEVICE_ID, rc->device_id);
 

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc) · line 126

Quoted 10 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +10 -0
+	/* Quirk to enable autonomous speed change for GEN2 controller */
+	/* Reading Supported Link Speed value */
+	sls = PCI_EXP_LNKCAP_SLS &
+		cdns_pcie_rp_readb(pcie, link_cap + PCI_EXP_LNKCAP);
+	if (sls == PCI_EXP_LNKCAP_SLS_5_0GB) {
+		/* Since this a Gen2 controller, set Retrain Link(RL) bit */
+		lnk_ctl = cdns_pcie_rp_readw(pcie, link_cap + PCI_EXP_LNKCTL);
+		lnk_ctl |= PCI_EXP_LNKCTL_RL;
+		cdns_pcie_rp_writew(pcie, link_cap + PCI_EXP_LNKCTL, lnk_ctl);
+	}

Is this workaround required for all Cadence controller? If not, enable this workaround only for versions which doesn't do autonomous speed change.

I think this workaround should also be applied only after checking for link status (cdns_pcie_link_up()).

And this is also applicable for GEN3/GEN4 controller. So the check should be to see the capability of the connected PCIe device and not the controller itself.

Thanks
Kishon

#6 lore raw

Hi Kishon,

Quoted 57 lines

-----Original Message-----
From: Kishon Vijay Abraham I <[email protected]>
Sent: Thursday, September 24, 2020 9:45 AM
To: Athani Nadeem Ladkhan <[email protected]>; Tom Joseph <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]
Cc: Milind Parab <[email protected]>; Swapnil Kashinath Jakhade <[email protected]>
Subject: Re: [PATCH v2] PCI: Cadence: Add quirk for Gen2 controller to do autonomous speed change.

EXTERNAL MAIL

Hi Nadeem,

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct

Quoted 16 lines · Nadeem Athani

Cadence controller will not initiate autonomous speed change if strapped as Gen2. The Retrain bit is set as a quirk to trigger this speed change.

---
 drivers/pci/controller/cadence/pcie-cadence-host.c | 14 ++++++++++++++
 drivers/pci/controller/cadence/pcie-cadence.h      | 15 +++++++++++++++
 2 files changed, 29 insertions(+)
drivers/pci/controller/cadence/pcie-cadence-host.c +0 -0
index 4550e0d469ca..a2317614268d 100644
@@ -83,6 +83,9 @@ static int cdns_pcie_host_init_root_port(struct

cdns_pcie_rc *rc)

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct

Quoted 10 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +3 -0
 	struct cdns_pcie *pcie = &rc->pcie;
 	u32 value, ctrl;
 	u32 id;
+	u32 link_cap = CDNS_PCIE_LINK_CAP_OFFSET;
+	u8 sls;
+	u16 lnk_ctl;
 
 	/*
 	 * Set the root complex BAR configuration register:
@@ -111,6 +114,17 @@ static int cdns_pcie_host_init_root_port(struct

cdns_pcie_rc *rc)

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)

Quoted 10 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +7 -0
 	if (rc->device_id != 0xffff)
 		cdns_pcie_rp_writew(pcie, PCI_DEVICE_ID, rc->device_id);
 
+	/* Quirk to enable autonomous speed change for GEN2 controller */
+	/* Reading Supported Link Speed value */
+	sls = PCI_EXP_LNKCAP_SLS &
+		cdns_pcie_rp_readb(pcie, link_cap + PCI_EXP_LNKCAP);
+	if (sls == PCI_EXP_LNKCAP_SLS_5_0GB) {
+		/* Since this a Gen2 controller, set Retrain Link(RL) bit */
+		lnk_ctl = cdns_pcie_rp_readw(pcie, link_cap +

PCI_EXP_LNKCTL);

Quoted 7 lines

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct · line 125

Quoted 2 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +2 -0
+		lnk_ctl |= PCI_EXP_LNKCTL_RL;
+		cdns_pcie_rp_writew(pcie, link_cap + PCI_EXP_LNKCTL,

lnk_ctl);

drivers/pci/controller/cadence/pcie-cadence-host.c static int cdns_pcie_host_init_root_port(struct · line 126

Quoted 1 line
drivers/pci/controller/cadence/pcie-cadence-host.c +1 -0
+	}

Is this workaround required for all Cadence controller? If not, enable this workaround only for versions which doesn't do autonomous speed change.

No. This is taken care in patch version 3.

Quoted 3 lines

I think this workaround should also be applied only after checking for link status (cdns_pcie_link_up()).

Yes. This is taken care in patch version 3.

Quoted 4 lines

And this is also applicable for GEN3/GEN4 controller. So the check should be to see the capability of the connected PCIe device and not the controller itself.

This is taken care in patch version 3.

Quoted 3 lines

Thanks
Kishon