Skip to contentSkip to conversation

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

PATCH Superseded Nadeem Athani 2 participants 5 messages Sep 18, 2020 – Sep 23, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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 |   13 +++++++++++++
 drivers/pci/controller/cadence/pcie-cadence.h      |    6 ++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
drivers/pci/controller/cadence/pcie-cadence-host.c +13 -0
index 4550e0d..4cb7f29 100644
@@ -83,6 +83,8 @@ 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, lnk_ctl;
 
 	/*
 	 * Set the root complex BAR configuration register:
@@ -111,6 +113,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_readb(pcie, link_cap + PCI_EXP_LNKCTL);
+		lnk_ctl |= PCI_EXP_LNKCTL_RL;
+		cdns_pcie_rp_writeb(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 +6 -0
index feed1e3..075c263 100644
@@ -120,6 +120,7 @@
  */
 #define CDNS_PCIE_RP_BASE	0x00200000
 
+#define CDNS_PCIE_LINK_CAP_OFFSET 0xC0
 
 /*
  * Address Translation Registers
@@ -413,6 +414,11 @@ 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)
+{
+	return readb(pcie->reg_base + CDNS_PCIE_RP_BASE + reg);
+}
+
 /* 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
1.7.1
reviewer
#1 lore raw
Quoted 27 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 |   13 +++++++++++++
 drivers/pci/controller/cadence/pcie-cadence.h      |    6 ++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
drivers/pci/controller/cadence/pcie-cadence-host.c +2 -0
index 4550e0d..4cb7f29 100644
@@ -83,6 +83,8 @@ 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, lnk_ctl;
 
        /*
         * Set the root complex BAR configuration register:
@@ -111,6 +113,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 124

Quoted 10 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +9 -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_readb(pcie, link_cap + PCI_EXP_LNKCTL);
+               lnk_ctl |= PCI_EXP_LNKCTL_RL;
+               cdns_pcie_rp_writeb(pcie, link_cap + PCI_EXP_LNKCTL, lnk_ctl);

Why the byte accesses? This is a 16-bit register.

Quoted 32 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);
drivers/pci/controller/cadence/pcie-cadence.h +6 -1
index feed1e3..075c263 100644
@@ -120,6 +120,7 @@
  */
 #define CDNS_PCIE_RP_BASE      0x00200000
 
+#define CDNS_PCIE_LINK_CAP_OFFSET 0xC0
 
 /*
  * Address Translation Registers
@@ -413,6 +414,11 @@ 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)
+{
+       return readb(pcie->reg_base + CDNS_PCIE_RP_BASE + reg);
+}
+
 /* Endpoint Function register access */
 static inline void cdns_pcie_ep_fn_writeb(struct cdns_pcie *pcie, u8 fn,
                                          u32 reg, u8 value)
--

1.7.1

#2 lore raw

Hi Rob,

Quoted 60 lines

-----Original Message-----
From: Rob Herring <[email protected]>
Sent: Tuesday, September 22, 2020 11:08 PM
To: Athani Nadeem Ladkhan <[email protected]>
Cc: Tom Joseph <[email protected]>; Lorenzo Pieralisi <[email protected]>; Bjorn Helgaas <[email protected]>; PCI <[email protected]>; [email protected]; Milind Parab <[email protected]>; Swapnil Kashinath Jakhade <[email protected]>
Subject: Re: [PATCH] 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 |   13 +++++++++++++
 drivers/pci/controller/cadence/pcie-cadence.h      |    6 ++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
drivers/pci/controller/cadence/pcie-cadence-host.c +0 -0
index 4550e0d..4cb7f29 100644
@@ -83,6 +83,8 @@ 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 9 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +2 -0
        struct cdns_pcie *pcie = &rc->pcie;
        u32 value, ctrl;
        u32 id;
+       u32 link_cap = CDNS_PCIE_LINK_CAP_OFFSET;
+       u8 sls, lnk_ctl;
 
        /*
         * Set the root complex BAR configuration register:
@@ -111,6 +113,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);
 

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 +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_readb(pcie, link_cap + PCI_EXP_LNKCTL);
+               lnk_ctl |= PCI_EXP_LNKCTL_RL;
+               cdns_pcie_rp_writeb(pcie, link_cap + PCI_EXP_LNKCTL,
+ lnk_ctl);
Quoted 1 line

Why the byte accesses? This is a 16-bit register.

This is a 32bit register. But the register field require is at first byte only. Hence the byte access.

Quoted 34 lines

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

Quoted 21 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); diff --git
a/drivers/pci/controller/cadence/pcie-cadence.h
b/drivers/pci/controller/cadence/pcie-cadence.h
index feed1e3..075c263 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,11 @@ static inline void cdns_pcie_rp_writew(struct

cdns_pcie *pcie,

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

1.7.1

reviewer
#3 lore raw
Quoted 63 lines · Athani Nadeem Ladkhan

Hi Rob,

Quoted 60 lines

-----Original Message-----
From: Rob Herring <[email protected]>
Sent: Tuesday, September 22, 2020 11:08 PM
To: Athani Nadeem Ladkhan <[email protected]>
Cc: Tom Joseph <[email protected]>; Lorenzo Pieralisi <[email protected]>; Bjorn Helgaas <[email protected]>; PCI <[email protected]>; [email protected]; Milind Parab <[email protected]>; Swapnil Kashinath Jakhade <[email protected]>
Subject: Re: [PATCH] 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 |   13 +++++++++++++
 drivers/pci/controller/cadence/pcie-cadence.h      |    6 ++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
drivers/pci/controller/cadence/pcie-cadence-host.c +0 -0
index 4550e0d..4cb7f29 100644
@@ -83,6 +83,8 @@ 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 9 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +2 -0
        struct cdns_pcie *pcie = &rc->pcie;
        u32 value, ctrl;
        u32 id;
+       u32 link_cap = CDNS_PCIE_LINK_CAP_OFFSET;
+       u8 sls, lnk_ctl;
 
        /*
         * Set the root complex BAR configuration register:
@@ -111,6 +113,17 @@ static int cdns_pcie_host_init_root_port(struct

cdns_pcie_rc *rc)

Quoted 14 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +10 -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_readb(pcie, link_cap + PCI_EXP_LNKCTL);
+               lnk_ctl |= PCI_EXP_LNKCTL_RL;
+               cdns_pcie_rp_writeb(pcie, link_cap + PCI_EXP_LNKCTL,
+ lnk_ctl);
Quoted 2 lines
Quoted 1 line

Why the byte accesses? This is a 16-bit register.

This is a 32bit register. But the register field require is at first byte only. Hence the byte access.

No, it's a 16-bit register as Link Status is at the next half word:

#define PCI_EXP_LNKCTL 16 /* Link Control */
#define PCI_EXP_LNKSTA 18 /* Link Status */

Use accesses that match the register size.

Rob

#4 lore raw
In reply to Rob Herring
Quoted 97 lines

-----Original Message-----
From: Rob Herring <[email protected]>
Sent: Tuesday, September 22, 2020 11:08 PM
To: Athani Nadeem Ladkhan <[email protected]>
Cc: Tom Joseph <[email protected]>; Lorenzo Pieralisi <[email protected]>; Bjorn Helgaas <[email protected]>; PCI <[email protected]>; [email protected]; Milind Parab <[email protected]>; Swapnil Kashinath Jakhade <[email protected]>
Subject: Re: [PATCH] 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 |   13 +++++++++++++
 drivers/pci/controller/cadence/pcie-cadence.h      |    6 ++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
drivers/pci/controller/cadence/pcie-cadence-host.c +0 -0
index 4550e0d..4cb7f29 100644
@@ -83,6 +83,8 @@ 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 9 lines
drivers/pci/controller/cadence/pcie-cadence-host.c +2 -0
        struct cdns_pcie *pcie = &rc->pcie;
        u32 value, ctrl;
        u32 id;
+       u32 link_cap = CDNS_PCIE_LINK_CAP_OFFSET;
+       u8 sls, lnk_ctl;
 
        /*
         * Set the root complex BAR configuration register:
@@ -111,6 +113,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);
 

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 +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_readb(pcie, link_cap + PCI_EXP_LNKCTL);
+               lnk_ctl |= PCI_EXP_LNKCTL_RL;
+               cdns_pcie_rp_writeb(pcie, link_cap + PCI_EXP_LNKCTL,
+ lnk_ctl);

Why the byte accesses? This is a 16-bit register.
This is a 32bit register. But the register field require is at first byte only. Hence the byte access.

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

Quoted 20 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); diff --git
a/drivers/pci/controller/cadence/pcie-cadence.h
b/drivers/pci/controller/cadence/pcie-cadence.h
index feed1e3..075c263 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,11 @@ static inline void cdns_pcie_rp_writew(struct

cdns_pcie *pcie,

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

1.7.1