PCI: aardvark controller fixes
Subsystems (3)
v2 cover PCI: aardvark controller fixes
Hi Lorenzo,
as requested I am sending v2 of this series.
Changes since v1:
- updated commit message in patch 6 as suggested by Mark
- updated patch 6 to also drop the early return
- changed the LTSSM definitions to enum in patch 12
- dropped the Fixes tags for those patches where it was inappropriate
Marek Behún (2):
PCI: aardvark: Don't spam about PIO Response Status
PCI: aardvark: Deduplicate code in advk_pcie_rd_conf()
Pali Rohár (11):
PCI: Add PCI_EXP_DEVCTL_PAYLOAD_* macros
PCI: aardvark: Fix PCIe Max Payload Size setting
PCI: aardvark: Fix preserving PCI_EXP_RTCTL_CRSSVE flag on emulated
bridge
PCI: aardvark: Fix configuring Reference clock
PCI: aardvark: Do not clear status bits of masked interrupts
PCI: aardvark: Do not unmask unused interrupts
PCI: aardvark: Implement re-issuing config requests on CRS response
PCI: aardvark: Simplify initialization of rootcap on virtual bridge
PCI: aardvark: Fix link training
PCI: aardvark: Fix checking for link up via LTSSM state
PCI: aardvark: Fix reporting Data Link Layer Link Active
drivers/pci/controller/pci-aardvark.c | 372 +++++++++++++++----------- include/uapi/linux/pci_regs.h | 6 + 2 files changed, 217 insertions(+), 161 deletions(-)
Signature · 1 line
2.32.0
PATCH v2 1/13 PCI: Add PCI_EXP_DEVCTL_PAYLOAD_* macros
From: Pali Rohár <[email protected]>
Define a macro PCI_EXP_DEVCTL_PAYLOAD_* for every possible Max Payload Size in linux/pci_regs.h, in the same style as PCI_EXP_DEVCTL_READRQ_*.
--- include/uapi/linux/pci_regs.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/uapi/linux/pci_regs.h +6 -0
@@ -504,6 +504,12 @@#define PCI_EXP_DEVCTL_URRE 0x0008/* Unsupported Request Reporting En. */ #define PCI_EXP_DEVCTL_RELAX_EN 0x0010/* Enable relaxed ordering */ #define PCI_EXP_DEVCTL_PAYLOAD 0x00e0/* Max_Payload_Size */ +#define PCI_EXP_DEVCTL_PAYLOAD_128B 0x0000/* 128 Bytes */ +#define PCI_EXP_DEVCTL_PAYLOAD_256B 0x0020/* 256 Bytes */ +#define PCI_EXP_DEVCTL_PAYLOAD_512B 0x0040/* 512 Bytes */ +#define PCI_EXP_DEVCTL_PAYLOAD_1024B 0x0060/* 1024 Bytes */ +#define PCI_EXP_DEVCTL_PAYLOAD_2048B 0x0080/* 2048 Bytes */ +#define PCI_EXP_DEVCTL_PAYLOAD_4096B 0x00a0/* 4096 Bytes */ #define PCI_EXP_DEVCTL_EXT_TAG 0x0100/* Extended Tag Field Enable */ #define PCI_EXP_DEVCTL_PHANTOM 0x0200/* Phantom Functions Enable */ #define PCI_EXP_DEVCTL_AUX_PME 0x0400/* Auxiliary Power PM Enable */
Signature · 1 line
2.32.0
PATCH v2 2/13 PCI: aardvark: Fix PCIe Max Payload Size setting
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
Change PCIe Max Payload Size setting in PCIe Device Control register to 512 bytes to align with PCIe Link Initialization sequence as defined in Marvell Armada 3700 Functional Specification. According to the specification, maximal Max Payload Size supported by this device is 512 bytes.
Without this kernel prints suspicious line:
pci 0000:01:00.0: Upstream bridge's Max Payload Size set to 256 (was 16384, max 512)
With this change it changes to:
pci 0000:01:00.0: Upstream bridge's Max Payload Size set to 256 (was 512, max 512)
--- drivers/pci/controller/pci-aardvark.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/controller/pci-aardvark.c +2 -1
@@ -488,8 +488,9 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie) reg =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP +PCI_EXP_DEVCTL ); reg &= ~PCI_EXP_DEVCTL_RELAX_EN ; reg &= ~PCI_EXP_DEVCTL_NOSNOOP_EN ; + reg &= ~PCI_EXP_DEVCTL_PAYLOAD ; reg &= ~PCI_EXP_DEVCTL_READRQ ; - reg |=PCI_EXP_DEVCTL_PAYLOAD ;/* Set max payload size */ + reg |=PCI_EXP_DEVCTL_PAYLOAD_512B ; reg |=PCI_EXP_DEVCTL_READRQ_512B ;advk_writel (pcie, reg,PCIE_CORE_PCIEXP_CAP +PCI_EXP_DEVCTL );
Signature · 1 line
2.32.0
PATCH v2 3/13 PCI: aardvark: Don't spam about PIO Response Status
In reply to Marek BehúnUse dev_dbg() instead of dev_err() in advk_pcie_check_pio_status().
For example CRS is not an error status, it just says that the request should be retried.
--- drivers/pci/controller/pci-aardvark.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pci-aardvark.c +1 -1
@@ -683,7 +683,7 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3else str_posted ="Posted" ; -dev_err (dev,"%s PIO Response Status: %s, %#x @ %#x\n" , +dev_dbg (dev,"%s PIO Response Status: %s, %#x @ %#x\n" , str_posted, strcomp_status, reg,advk_readl (pcie,PIO_ADDR_LS ));return -EFAULT ;
Signature · 1 line
2.32.0
PATCH v2 4/13 PCI: aardvark: Fix preserving PCI_EXP_RTCTL_CRSSVE flag on emulated bridge
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
Commit 43f5c77bcbd2 ("PCI: aardvark: Fix reporting CRS value") started using CRSSVE flag for handling CRS responses.
PCI_EXP_RTCTL_CRSSVE flag is stored only in emulated config space buffer and there is handler for PCI_EXP_RTCTL register. So every read operation from config space automatically clears CRSSVE flag as it is not defined in PCI_EXP_RTCTL read handler.
Fix this by reading current CRSSVE bit flag from emulated space buffer and appending it to PCI_EXP_RTCTL read response.
--- drivers/pci/controller/pci-aardvark.c | 1 + 1 file changed, 1 insertion(+)
drivers/pci/controller/pci-aardvark.c +1 -0
@@ -724,6 +724,7 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,case PCI_EXP_RTCTL : {u32 val =advk_readl (pcie,PCIE_ISR0_MASK_REG ); *value = (val &PCIE_MSG_PM_PME_MASK ) ?0 :PCI_EXP_RTCTL_PMEIE ; + *value |=le16_to_cpu (bridge->pcie_conf.rootctl) &PCI_EXP_RTCTL_CRSSVE ; *value |=PCI_EXP_RTCAP_CRSVIS <<16 ;return PCI_BRIDGE_EMUL_HANDLED ; }
Signature · 1 line
2.32.0
PATCH v2 5/13 PCI: aardvark: Fix configuring Reference clock
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
Commit 366697018c9a ("PCI: aardvark: Add PHY support") introduced configuration of PCIe Reference clock via PCIE_CORE_REF_CLK_REG register, but did it incorrectly.
PCIe Reference clock differential pair is routed from system board to endpoint card, so on CPU side it has output direction. Therefore it is required to enable transmitting and disable receiving.
Default configuration according to Armada 3700 Functional Specifications is enabled receiver part and disabled transmitter.
We need this change because otherwise PCIe Reference clock is configured to some undefined state when differential pair is used for both transmitting and receiving.
Fix this by disabling receiver part.
--- drivers/pci/controller/pci-aardvark.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/pci/controller/pci-aardvark.c +8 -1
@@ -99,6 +99,7 @@#define PCIE_CORE_CTRL2_MSI_ENABLE BIT(10)#define PCIE_CORE_REF_CLK_REG (CONTROL_BASE_ADDR + 0x14)#define PCIE_CORE_REF_CLK_TX_ENABLE BIT(1) +#define PCIE_CORE_REF_CLK_RX_ENABLE BIT(2)#define PCIE_MSG_LOG_REG (CONTROL_BASE_ADDR + 0x30)#define PCIE_ISR0_REG (CONTROL_BASE_ADDR + 0x40)#define PCIE_MSG_PM_PME_MASK BIT(7)
@@ -451,9 +452,15 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie)u32 reg;int i; -/* Enable TX */ +/* +* Configure PCIe Reference clock. Direction is from the PCIe +* controller to the endpoint card, so enable transmitting of +* Reference clock differential signal off-chip and disable +* receiving off-chip differential signal. +*/ reg =advk_readl (pcie,PCIE_CORE_REF_CLK_REG ); reg |=PCIE_CORE_REF_CLK_TX_ENABLE ; + reg &= ~PCIE_CORE_REF_CLK_RX_ENABLE ;advk_writel (pcie, reg,PCIE_CORE_REF_CLK_REG );/* Set to Direct mode */
Signature · 1 line
2.32.0
PATCH v2 6/13 PCI: aardvark: Do not clear status bits of masked interrupts
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
The PCIE_ISR1_REG says which interrupts are currently set / active, including those which are masked.
The driver currently reads this register and looks if some unmasked interrupts are active, and if not, it clears status bits of _all_ interrupts, including the masked ones.
This is incorrect, since, for example, some drivers may poll these bits.
Remove this clearing, and also remove this early return statement completely, since it does not change functionality in any way.
--- drivers/pci/controller/pci-aardvark.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/pci/controller/pci-aardvark.c +0 -6
@@ -1295,12 +1295,6 @@ static void advk_pcie_handle_int(struct advk_pcie *pcie) isr1_mask =advk_readl (pcie,PCIE_ISR1_MASK_REG ); isr1_status = isr1_val & ((~isr1_mask) &PCIE_ISR1_ALL_MASK ); -if (!isr0_status && !isr1_status) { -advk_writel (pcie, isr0_val,PCIE_ISR0_REG ); -advk_writel (pcie, isr1_val,PCIE_ISR1_REG ); -return ; - } -/* Process MSI interrupts */ if (isr0_status &PCIE_ISR0_MSI_INT_PENDING )advk_pcie_handle_msi (pcie);
Signature · 1 line
2.32.0
PATCH v2 7/13 PCI: aardvark: Do not unmask unused interrupts
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
There are lot of undocumented interrupt bits. Fix all *_ALL_MASK macros to define all interrupt bits, so that driver can properly mask all interrupts, including those which are undocumented.
--- drivers/pci/controller/pci-aardvark.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pci/controller/pci-aardvark.c +3 -3
@@ -107,13 +107,13 @@#define PCIE_ISR0_MSI_INT_PENDING BIT(24)#define PCIE_ISR0_INTX_ASSERT (val) BIT(16 + (val))#define PCIE_ISR0_INTX_DEASSERT (val) BIT(20 + (val)) -#define PCIE_ISR0_ALL_MASK GENMASK(26, 0) +#define PCIE_ISR0_ALL_MASK GENMASK(31, 0)#define PCIE_ISR1_REG (CONTROL_BASE_ADDR + 0x48)#define PCIE_ISR1_MASK_REG (CONTROL_BASE_ADDR + 0x4C)#define PCIE_ISR1_POWER_STATE_CHANGE BIT(4)#define PCIE_ISR1_FLUSH BIT(5)#define PCIE_ISR1_INTX_ASSERT (val) BIT(8 + (val)) -#define PCIE_ISR1_ALL_MASK GENMASK(11, 4) +#define PCIE_ISR1_ALL_MASK GENMASK(31, 0)#define PCIE_MSI_ADDR_LOW_REG (CONTROL_BASE_ADDR + 0x50)#define PCIE_MSI_ADDR_HIGH_REG (CONTROL_BASE_ADDR + 0x54)#define PCIE_MSI_STATUS_REG (CONTROL_BASE_ADDR + 0x58)
@@ -199,7 +199,7 @@#define PCIE_IRQ_MSI_INT2_DET BIT(21)#define PCIE_IRQ_RC_DBELL_DET BIT(22)#define PCIE_IRQ_EP_STATUS BIT(23) -#define PCIE_IRQ_ALL_MASK 0xfff0fb +#define PCIE_IRQ_ALL_MASK GENMASK(31, 0)#define PCIE_IRQ_ENABLE_INTS_MASK PCIE_IRQ_CORE_INT/* Transaction types */
Signature · 1 line
2.32.0
Re: [PATCH v2 07/13] PCI: aardvark: Do not unmask unused interrupts
[CC Sasha for stable kernel rules]
Quoted 11 lines · Marek Behún
From: Pali Rohár <[email protected]>
There are lot of undocumented interrupt bits. Fix all
*_ALL_MASKmacros to define all interrupt bits, so that driver can properly mask all interrupts, including those which are undocumented.Fixes 8c39d710363c ("PCI: aardvark: Add Aardvark PCI host controller driver")Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>Signed-off-by Marek Behún <[email protected]>
I don't think this is a fix and I don't think it should be sent to stable kernels in _preparation_ for other fixes to come (that may never land in mainline).
If, for future fixes a depedency is detected they can be added in the relevant commit log.
That's my understanding, Sasha can clarify if needed.
Patch itself is fine.
Thanks,
Lorenzo
Quoted 36 lines
--- drivers/pci/controller/pci-aardvark.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/pci/controller/pci-aardvark.c +3
-3@@ -107,13 +107,13 @@#define PCIE_ISR0_MSI_INT_PENDING BIT(24)#define PCIE_ISR0_INTX_ASSERT (val) BIT(16 + (val))#define PCIE_ISR0_INTX_DEASSERT (val) BIT(20 + (val)) -#define PCIE_ISR0_ALL_MASK GENMASK(26, 0) +#define PCIE_ISR0_ALL_MASK GENMASK(31, 0)#define PCIE_ISR1_REG (CONTROL_BASE_ADDR + 0x48)#define PCIE_ISR1_MASK_REG (CONTROL_BASE_ADDR + 0x4C)#define PCIE_ISR1_POWER_STATE_CHANGE BIT(4)#define PCIE_ISR1_FLUSH BIT(5)#define PCIE_ISR1_INTX_ASSERT (val) BIT(8 + (val)) -#define PCIE_ISR1_ALL_MASK GENMASK(11, 4) +#define PCIE_ISR1_ALL_MASK GENMASK(31, 0)#define PCIE_MSI_ADDR_LOW_REG (CONTROL_BASE_ADDR + 0x50)#define PCIE_MSI_ADDR_HIGH_REG (CONTROL_BASE_ADDR + 0x54)#define PCIE_MSI_STATUS_REG (CONTROL_BASE_ADDR + 0x58)@@ -199,7 +199,7 @@#define PCIE_IRQ_MSI_INT2_DET BIT(21)#define PCIE_IRQ_RC_DBELL_DET BIT(22)#define PCIE_IRQ_EP_STATUS BIT(23) -#define PCIE_IRQ_ALL_MASK 0xfff0fb +#define PCIE_IRQ_ALL_MASK GENMASK(31, 0)#define PCIE_IRQ_ENABLE_INTS_MASK PCIE_IRQ_CORE_INT/* Transaction types */ Signature · 1 line
2.32.0
Re: [PATCH v2 07/13] PCI: aardvark: Do not unmask unused interrupts
Quoted 15 lines · On Wed, 6 Oct 2021 10:13:38 +0100 Lorenzo Pieralisi…
[CC Sasha for stable kernel rules]
Quoted 11 lines · Marek Behún
From: Pali Rohár <[email protected]>
There are lot of undocumented interrupt bits. Fix all
*_ALL_MASKmacros to define all interrupt bits, so that driver can properly mask all interrupts, including those which are undocumented.Fixes 8c39d710363c ("PCI: aardvark: Add Aardvark PCI host controller driver")Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>Signed-off-by Marek Behún <[email protected]>
Quoted 3 lines
I don't think this is a fix and I don't think it should be sent to stable kernels in _preparation_ for other fixes to come (that may never land in mainline).
This patch is a fix because it fixes masking interrupts, which may prevent spurious interrupts - we don't want interrupts which kernel didn't request for.
I agree that the commit message should probably mention this, though... :(
Marek
Re: [PATCH v2 07/13] PCI: aardvark: Do not unmask unused interrupts
Quoted 22 lines · Marek Behún
Quoted 15 lines · On Wed, 6 Oct 2021 10:13:38 +0100 Lorenzo Pieralisi…
[CC Sasha for stable kernel rules]
Quoted 11 lines · Marek Behún
From: Pali Rohár <[email protected]>
There are lot of undocumented interrupt bits. Fix all
*_ALL_MASKmacros to define all interrupt bits, so that driver can properly mask all interrupts, including those which are undocumented.Fixes 8c39d710363c ("PCI: aardvark: Add Aardvark PCI host controller driver")Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>Signed-off-by Marek Behún <[email protected]>Quoted 3 lines
I don't think this is a fix and I don't think it should be sent to stable kernels in _preparation_ for other fixes to come (that may never land in mainline).
Quoted 6 lines
This patch is a fix because it fixes masking interrupts, which may prevent spurious interrupts - we don't want interrupts which kernel didn't request for.
I agree that the commit message should probably mention this, though... :(
Now it does ;-), will notify you when I push the series out so that you can have a look to check.
Thanks,
Lorenzo
Quoted 2 lines
Marek
PATCH v2 8/13 PCI: aardvark: Deduplicate code in advk_pcie_rd_conf()
In reply to Marek BehúnAvoid code repetition in advk_pcie_rd_conf() by handling errors with goto jump, as is customary in kernel.
--- drivers/pci/controller/pci-aardvark.c | 48 +++++++++++---------------- 1 file changed, 20 insertions(+), 28 deletions(-)
drivers/pci/controller/pci-aardvark.c +20 -28
@@ -920,18 +920,8 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn, (le16_to_cpu (pcie->bridge.pcie_conf.rootctl) &PCI_EXP_RTCTL_CRSSVE ); -if (advk_pcie_pio_is_running (pcie)) { -/* -* If it is possible return Completion Retry Status so caller -* tries to issue the request again instead of failing. -*/ -if (allow_crs) { - *val =CFG_RD_CRS_VAL ; -return PCIBIOS_SUCCESSFUL ; - } - *val =0xffffffff ; -return PCIBIOS_SET_FAILED ; - } +if (advk_pcie_pio_is_running (pcie)) + goto try_crs;/* Program the control register */ reg =advk_readl (pcie,PIO_CTRL );
@@ -955,25 +945,13 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,advk_writel (pcie,1 ,PIO_START ); ret =advk_pcie_wait_pio (pcie); -if (ret <0 ) { -/* -* If it is possible return Completion Retry Status so caller -* tries to issue the request again instead of failing. -*/ -if (allow_crs) { - *val =CFG_RD_CRS_VAL ; -return PCIBIOS_SUCCESSFUL ; - } - *val =0xffffffff ; -return PCIBIOS_SET_FAILED ; - } +if (ret <0 ) + goto try_crs;/* Check PIO status and get the read result */ ret =advk_pcie_check_pio_status (pcie, allow_crs, val); -if (ret <0 ) { - *val =0xffffffff ; -return PCIBIOS_SET_FAILED ; - } +if (ret <0 ) + goto fail;if (size ==1 ) *val = (*val >> (8 * (where &3 ))) &0xff ;
@@ -981,6 +959,20 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn, *val = (*val >> (8 * (where &3 ))) &0xffff ;return PCIBIOS_SUCCESSFUL ; + +try_crs: +/* +* If it is possible, return Completion Retry Status so that caller +* tries to issue the request again instead of failing. +*/ +if (allow_crs) { + *val =CFG_RD_CRS_VAL ; +return PCIBIOS_SUCCESSFUL ; + } + +fail: + *val =0xffffffff ; +return PCIBIOS_SET_FAILED ; } static int advk_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
Signature · 1 line
2.32.0
PATCH v2 9/13 PCI: aardvark: Implement re-issuing config requests on CRS response
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
Commit 43f5c77bcbd2 ("PCI: aardvark: Fix reporting CRS value") fixed handling of CRS response and when CRSSVE flag was not enabled it marked CRS response as failed transaction (due to simplicity).
But pci-aardvark.c driver is already waiting up to the PIO_RETRY_CNT count for PIO config response and so we can with a small change implement re-issuing of config requests as described in PCIe base specification.
This change implements re-issuing of config requests when response is CRS. Set upper bound of wait cycles to around PIO_RETRY_CNT, afterwards the transaction is marked as failed and an all-ones value is returned as before.
We do this by returning appropriate error codes from function advk_pcie_check_pio_status(). On CRS we return -EAGAIN and caller then reissues transaction.
--- drivers/pci/controller/pci-aardvark.c | 67 +++++++++++++++++---------- 1 file changed, 43 insertions(+), 24 deletions(-)
drivers/pci/controller/pci-aardvark.c +43 -24
@@ -603,6 +603,7 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3u32 reg;unsigned int status;char *strcomp_status, *str_posted; +int ret; reg =advk_readl (pcie,PIO_STAT ); status = (reg & PIO_COMPLETION_STATUS_MASK) >>
@@ -627,6 +628,7 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3case PIO_COMPLETION_STATUS_OK :if (reg &PIO_ERR_STATUS ) { strcomp_status ="COMP_ERR" ; + ret = -EFAULT ;break ; }/* Get the read result */
@@ -634,9 +636,11 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3 *val =advk_readl (pcie,PIO_RD_DATA );/* No error */ strcomp_status =NULL ; + ret =0 ;break ;case PIO_COMPLETION_STATUS_UR : strcomp_status ="UR" ; + ret = -EOPNOTSUPP ;break ;case PIO_COMPLETION_STATUS_CRS :if (allow_crs && val) {
@@ -654,6 +658,7 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3*/ *val =CFG_RD_CRS_VAL ; strcomp_status =NULL ; + ret =0 ;break ; }/* PCIe r4.0, sec 2.3.2, says:
@@ -669,21 +674,24 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3* Request and taking appropriate action, e.g., complete the * Request to the host as a failed transaction. * -* To simplify implementation do not re-issue the Configuration -* Request and complete the Request as a failed transaction. +* So return -EAGAIN and caller (pci-aardvark.c driver) will +* re-issue request again up to the PIO_RETRY_CNT retries. */ strcomp_status ="CRS" ; + ret = -EAGAIN ;break ;case PIO_COMPLETION_STATUS_CA : strcomp_status ="CA" ; + ret = -ECANCELED ;break ;default : strcomp_status ="Unknown" ; + ret = -EINVAL ;break ; }if (!strcomp_status) -return 0 ; +return ret;if (reg &PIO_NON_POSTED_REQ ) str_posted ="Non-posted" ;
@@ -693,7 +701,7 @@ static int advk_pcie_check_pio_status(struct advk_pcie *pcie, bool allow_crs, u3dev_dbg (dev,"%s PIO Response Status: %s, %#x @ %#x\n" , str_posted, strcomp_status, reg,advk_readl (pcie,PIO_ADDR_LS )); -return -EFAULT ; +return ret; }static int advk_pcie_wait_pio (struct advk_pcie *pcie)
@@ -701,13 +709,13 @@ static int advk_pcie_wait_pio(struct advk_pcie *pcie)struct device *dev = &pcie->pdev->dev;int i; -for (i =0 ; i <PIO_RETRY_CNT ; i++) { +for (i =1 ; i <=PIO_RETRY_CNT ; i++) {u32 start, isr; start =advk_readl (pcie,PIO_START ); isr =advk_readl (pcie,PIO_ISR );if (!start && isr) -return 0 ; +return i;udelay (PIO_RETRY_DELAY ); }
@@ -898,6 +906,7 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where, int size, u32 *val) { struct advk_pcie *pcie = bus->sysdata; +int retry_count;bool allow_crs;u32 reg;int ret;
@@ -940,16 +949,22 @@ static int advk_pcie_rd_conf(struct pci_bus *bus, u32 devfn,/* Program the data strobe */ advk_writel (pcie,0xf ,PIO_WR_DATA_STRB ); -/* Clear PIO DONE ISR and start the transfer */ -advk_writel (pcie,1 ,PIO_ISR ); -advk_writel (pcie,1 ,PIO_START ); + retry_count =0 ; +do { +/* Clear PIO DONE ISR and start the transfer */ +advk_writel (pcie,1 ,PIO_ISR ); +advk_writel (pcie,1 ,PIO_START ); - ret =advk_pcie_wait_pio (pcie); -if (ret <0 ) - goto try_crs; + ret =advk_pcie_wait_pio (pcie); +if (ret <0 ) + goto try_crs; + + retry_count += ret; + +/* Check PIO status and get the read result */ + ret =advk_pcie_check_pio_status (pcie, allow_crs, val); + }while (ret == -EAGAIN && retry_count <PIO_RETRY_CNT ); -/* Check PIO status and get the read result */ - ret =advk_pcie_check_pio_status (pcie, allow_crs, val);if (ret <0 ) goto fail;
@@ -981,6 +996,7 @@ static int advk_pcie_wr_conf(struct pci_bus *bus, u32 devfn,struct advk_pcie *pcie = bus->sysdata;u32 reg;u32 data_strobe =0x0 ; +int retry_count;int offset;int ret;
@@ -1022,19 +1038,22 @@ static int advk_pcie_wr_conf(struct pci_bus *bus, u32 devfn,/* Program the data strobe */ advk_writel (pcie, data_strobe,PIO_WR_DATA_STRB ); -/* Clear PIO DONE ISR and start the transfer */ -advk_writel (pcie,1 ,PIO_ISR ); -advk_writel (pcie,1 ,PIO_START ); + retry_count =0 ; +do { +/* Clear PIO DONE ISR and start the transfer */ +advk_writel (pcie,1 ,PIO_ISR ); +advk_writel (pcie,1 ,PIO_START ); - ret =advk_pcie_wait_pio (pcie); -if (ret <0 ) -return PCIBIOS_SET_FAILED ; + ret =advk_pcie_wait_pio (pcie); +if (ret <0 ) +return PCIBIOS_SET_FAILED ; - ret =advk_pcie_check_pio_status (pcie, false,NULL ); -if (ret <0 ) -return PCIBIOS_SET_FAILED ; + retry_count += ret; -return PCIBIOS_SUCCESSFUL ; + ret =advk_pcie_check_pio_status (pcie, false,NULL ); + }while (ret == -EAGAIN && retry_count <PIO_RETRY_CNT ); + +return ret <0 ?PCIBIOS_SET_FAILED :PCIBIOS_SUCCESSFUL ; }static struct pci_ops advk_pcie_ops = {
Signature · 1 line
2.32.0
PATCH v2 10/13 PCI: aardvark: Simplify initialization of rootcap on virtual bridge
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
PCIe config space can be initialized also before pci_bridge_emul_init() call, so move rootcap initialization after PCI config space initialization.
This simplifies the function a little since it removes one if (ret < 0) check.
--- drivers/pci/controller/pci-aardvark.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/pci/controller/pci-aardvark.c +4 -10
@@ -822,7 +822,6 @@ static struct pci_bridge_emul_ops advk_pci_bridge_emul_ops = {static int advk_sw_pci_bridge_init (struct advk_pcie *pcie) {struct pci_bridge_emul *bridge = &pcie->bridge; -int ret; bridge->conf.vendor =cpu_to_le16 (advk_readl (pcie,PCIE_CORE_DEV_ID_REG ) &0xffff );
@@ -842,19 +841,14 @@ static int advk_sw_pci_bridge_init(struct advk_pcie *pcie)/* Support interrupt A for MSI feature */ bridge->conf.intpin =PCIE_CORE_INT_A_ASSERT_ENABLE ; +/* Indicates supports for Completion Retry Status */ + bridge->pcie_conf.rootcap =cpu_to_le16 (PCI_EXP_RTCAP_CRSVIS ); + bridge->has_pcie = true; bridge->data = pcie; bridge->ops = &advk_pci_bridge_emul_ops; -/* PCIe config space can be initialized after pci_bridge_emul_init() */ - ret =pci_bridge_emul_init (bridge,0 ); -if (ret <0 ) -return ret; - -/* Indicates supports for Completion Retry Status */ - bridge->pcie_conf.rootcap =cpu_to_le16 (PCI_EXP_RTCAP_CRSVIS ); - -return 0 ; +return pci_bridge_emul_init (bridge,0 ); } static bool advk_pcie_valid_device(struct advk_pcie *pcie, struct pci_bus *bus,
Signature · 1 line
2.32.0
PATCH v2 11/13 PCI: aardvark: Fix link training
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
Fix multiple link training issues in aardvark driver. The main reason of these issues was misunderstanding of what certain registers do, since their names and comments were misleading: before commit 96be36dbffac ("PCI:
aardvark: Replace custom macros by standard linux/pci_regs.h macros"), the pci-aardvark.c driver used custom macros for accessing standard PCIe Root Bridge registers, and misleading comments did not help to understand what the code was really doing.
After doing more tests and experiments I've come to the conclusion that the SPEED_GEN register in aardvark sets the PCIe revision / generation compliance and forces maximal link speed. Both GEN3 and GEN2 values set the read-only PCI_EXP_FLAGS_VERS bits (PCIe capabilities version of Root Bridge) to value 2, while GEN1 value sets PCI_EXP_FLAGS_VERS to 1, which matches with PCI Express specifications revisions 3, 2 and 1 respectively. Changing SPEED_GEN also sets the read-only bits PCI_EXP_LNKCAP_SLS and PCI_EXP_LNKCAP2_SLS to corresponding speed.
(Note that PCI Express rev 1 specification does not define PCI_EXP_LNKCAP2
and PCI_EXP_LNKCTL2 registers and when SPEED_GEN is set to GEN1 (which also sets PCI_EXP_FLAGS_VERS set to 1), lspci cannot access PCI_EXP_LNKCAP2 and PCI_EXP_LNKCTL2 registers.)
Changing PCIe link speed can be done via PCI_EXP_LNKCTL2_TLS bits of PCI_EXP_LNKCTL2 register. Armada 3700 Functional Specifications says that the default value of PCI_EXP_LNKCTL2_TLS is based on SPEED_GEN value, but tests showed that the default value is always 8.0 GT/s, independently of speed set by SPEED_GEN. So after setting SPEED_GEN, we must also set value in PCI_EXP_LNKCTL2 register via PCI_EXP_LNKCTL2_TLS bits.
Triggering PCI_EXP_LNKCTL_RL bit immediately after setting LINK_TRAINING_EN bit actually doesn't do anything. Tests have shown that a delay is needed after enabling LINK_TRAINING_EN bit. As triggering PCI_EXP_LNKCTL_RL currently does nothing, remove it.
Commit 43fc679ced18 ("PCI: aardvark: Improve link training") introduced code which sets SPEED_GEN register based on negotiated link speed from PCI_EXP_LNKSTA_CLS bits of PCI_EXP_LNKSTA register. This code was added to fix detection of Compex WLE900VX (Atheros QCA9880) WiFi GEN1 PCIe cards, as otherwise these cards were "invisible" on PCIe bus (probably because they crashed). But apparently more people reported the same issues with these cards also with other PCIe controllers [1] and I was able to reproduce this issue also with other "noname" WiFi cards based on Atheros QCA9890 chip (with the same PCI vendor/device ids as Atheros QCA9880). So this is not an issue in aardvark but rather an issue in Atheros QCA98xx chips. Also, this issue only exists if the kernel is compiled with PCIe ASPM support, and a generic workaround for this is to change PCIe Bridge to 2.5 GT/s link speed via PCI_EXP_LNKCTL2_TLS_2_5GT bits in PCI_EXP_LNKCTL2 register [2], before triggering PCI_EXP_LNKCTL_RL bit. This workaround also works when SPEED_GEN is set to value GEN2 (5 GT/s). So remove this hack completely in the aardvark driver and always set SPEED_GEN to value from 'max-link-speed' DT property. Fix for Atheros QCA98xx chips is handled separately by patch [2].
These two things (code for triggering PCI_EXP_LNKCTL_RL bit and changing SPEED_GEN value) also explain why commit 6964494582f5 ("PCI: aardvark:
Train link immediately after enabling training") somehow fixed detection of those problematic Compex cards with Atheros chips: if triggering link retraining (via PCI_EXP_LNKCTL_RL bit) was done immediately after enabling link training (via LINK_TRAINING_EN), it did nothing. If there was a specific delay, aardvark HW already initialized PCIe link and therefore triggering link retraining caused the above issue. Compex cards triggered link down event and disappeared from the PCIe bus.
Commit f4c7d053d7f7 ("PCI: aardvark: Wait for endpoint to be ready before training link") added 100ms sleep before calling 'Start link training' command and explained that it is a requirement of PCI Express specification. But the code after this 100ms sleep was not doing 'Start link training', rather it triggered PCI_EXP_LNKCTL_RL bit via PCIe Root Bridge to put link into Recovery state.
The required delay after fundamental reset is already done in function advk_pcie_wait_for_link() which also checks whether PCIe link is up. So after removing the code which triggers PCI_EXP_LNKCTL_RL bit on PCIe Root Bridge, there is no need to wait 100ms again. Remove the extra msleep() call and update comment about the delay required by the PCI Express specification.
According to Marvell Armada 3700 Functional Specifications, Link training should be enabled via aardvark register LINK_TRAINING_EN after selecting PCIe generation and x1 lane. There is no need to disable it prior resetting card via PERST# signal. This disabling code was introduced in commit 5169a9851daa ("PCI: aardvark: Issue PERST via GPIO") as a workaround for some Atheros cards. It turns out that this also is Atheros specific issue and affects any PCIe controller, not only aardvark. Moreover this Atheros issue was triggered by juggling with PCI_EXP_LNKCTL_RL, LINK_TRAINING_EN and SPEED_GEN bits interleaved with sleeps. Now, after removing triggering PCI_EXP_LNKCTL_RL, there is no need to explicitly disable LINK_TRAINING_EN bit. So remove this code too. The problematic Compex cards described in previous git commits are correctly detected in advk_pcie_train_link() function even after applying all these changes.
Note that with this patch, and also prior this patch, some NVMe disks which support PCIe GEN3 with 8 GT/s speed are negotiated only at the lowest link speed 2.5 GT/s, independently of SPEED_GEN value. After manually triggering PCI_EXP_LNKCTL_RL bit (e.g. from userspace via setpci), these NVMe disks change link speed to 5 GT/s when SPEED_GEN was configured to GEN2. This issue first needs to be properly investigated. I will send a fix in the future.
On the other hand, some other GEN2 PCIe cards with 5 GT/s speed are autonomously by HW autonegotiated at full 5 GT/s speed without need of any software interaction.
Armada 3700 Functional Specifications describes the following steps for link training: set SPEED_GEN to GEN2, enable LINK_TRAINING_EN, poll until link training is complete, trigger PCI_EXP_LNKCTL_RL, poll until signal rate is 5 GT/s, poll until link training is complete, enable ASPM L0s.
The requirement for triggering PCI_EXP_LNKCTL_RL can be explained by the need to achieve 5 GT/s speed (as changing link speed is done by throw to recovery state entered by PCI_EXP_LNKCTL_RL) or maybe as a part of enabling ASPM L0s (but in this case ASPM L0s should have been enabled prior PCI_EXP_LNKCTL_RL).
It is unknown why the original pci-aardvark.c driver was triggering PCI_EXP_LNKCTL_RL bit before waiting for the link to be up. This does not align with neither PCIe base specifications nor with Armada 3700 Functional Specification. (Note that in older versions of aardvark, this bit was called incorrectly PCIE_CORE_LINK_TRAINING, so this may be the reason.)
It is also unknown why Armada 3700 Functional Specification says that it is needed to trigger PCI_EXP_LNKCTL_RL for GEN2 mode, as according to PCIe base specification 5 GT/s speed negotiation is supposed to be entirely autonomous, even if initial speed is 2.5 GT/s.
[1] - https://lore.kernel.org/linux-pci/[email protected]/
[2] - https://lore.kernel.org/linux-pci/[email protected]/
--- drivers/pci/controller/pci-aardvark.c | 117 ++++++++------------------ 1 file changed, 34 insertions(+), 83 deletions(-)
drivers/pci/controller/pci-aardvark.c +34 -83
@@ -258,11 +258,6 @@ static inline u32 advk_readl(struct advk_pcie *pcie, u64 reg)return readl (pcie->base + reg); } -static inline u16 advk_read16 (struct advk_pcie *pcie,u64 reg) -{ -return advk_readl (pcie, (reg & ~0x3 )) >> ((reg &0x3 ) *8 ); -} -static int advk_pcie_link_up (struct advk_pcie *pcie) {u32 val, ltssm_state;
@@ -300,23 +295,9 @@ static void advk_pcie_wait_for_retrain(struct advk_pcie *pcie)static void advk_pcie_issue_perst (struct advk_pcie *pcie) { -u32 reg; -if (!pcie->reset_gpio)return ; -/* -* As required by PCI Express spec (PCI Express Base Specification, REV. -* 4.0 PCI Express, February 19 2014, 6.6.1 Conventional Reset) a delay -* for at least 100ms after de-asserting PERST# signal is needed before -* link training is enabled. So ensure that link training is disabled -* prior de-asserting PERST# signal to fulfill that PCI Express spec -* requirement. -*/ - reg =advk_readl (pcie,PCIE_CORE_CTRL0_REG ); - reg &= ~LINK_TRAINING_EN ; -advk_writel (pcie, reg,PCIE_CORE_CTRL0_REG ); -/* 10ms delay is needed for some cards */ dev_info (&pcie->pdev->dev,"issuing PERST via reset GPIO for 10ms\n" );gpiod_set_value_cansleep (pcie->reset_gpio,1 );
@@ -324,53 +305,46 @@ static void advk_pcie_issue_perst(struct advk_pcie *pcie)gpiod_set_value_cansleep (pcie->reset_gpio,0 ); } -static int advk_pcie_train_at_gen (struct advk_pcie *pcie,int gen) +static void advk_pcie_train_link (struct advk_pcie *pcie) { -int ret, neg_gen; +struct device *dev = &pcie->pdev->dev;u32 reg; +int ret; -/* Setup link speed */ +/* +* Setup PCIe rev / gen compliance based on device tree property +* 'max-link-speed' which also forces maximal link speed. +*/ reg =advk_readl (pcie,PCIE_CORE_CTRL0_REG ); reg &= ~PCIE_GEN_SEL_MSK ; -if (gen ==3 ) +if (pcie->link_gen ==3 ) reg |=SPEED_GEN_3 ; -else if (gen ==2 ) +else if (pcie->link_gen ==2 ) reg |=SPEED_GEN_2 ;else reg |=SPEED_GEN_1 ;advk_writel (pcie, reg,PCIE_CORE_CTRL0_REG );/* -* Enable link training. This is not needed in every call to this -* function, just once suffices, but it does not break anything either. +* Set maximal link speed value also into PCIe Link Control 2 register. +* Armada 3700 Functional Specification says that default value is based +* on SPEED_GEN but tests showed that default value is always 8.0 GT/s. */ + reg =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP +PCI_EXP_LNKCTL2 ); + reg &= ~PCI_EXP_LNKCTL2_TLS ; +if (pcie->link_gen ==3 ) + reg |=PCI_EXP_LNKCTL2_TLS_8_0GT ; +else if (pcie->link_gen ==2 ) + reg |=PCI_EXP_LNKCTL2_TLS_5_0GT ; +else + reg |=PCI_EXP_LNKCTL2_TLS_2_5GT ; +advk_writel (pcie, reg,PCIE_CORE_PCIEXP_CAP +PCI_EXP_LNKCTL2 ); + +/* Enable link training after selecting PCIe generation */ reg =advk_readl (pcie,PCIE_CORE_CTRL0_REG ); reg |=LINK_TRAINING_EN ;advk_writel (pcie, reg,PCIE_CORE_CTRL0_REG ); -/* -* Start link training immediately after enabling it. -* This solves problems for some buggy cards. -*/ - reg =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP +PCI_EXP_LNKCTL ); - reg |=PCI_EXP_LNKCTL_RL ; -advk_writel (pcie, reg,PCIE_CORE_PCIEXP_CAP +PCI_EXP_LNKCTL ); - - ret =advk_pcie_wait_for_link (pcie); -if (ret) -return ret; - - reg =advk_read16 (pcie,PCIE_CORE_PCIEXP_CAP +PCI_EXP_LNKSTA ); - neg_gen = reg &PCI_EXP_LNKSTA_CLS ; - -return neg_gen; -} - -static void advk_pcie_train_link (struct advk_pcie *pcie) -{ -struct device *dev = &pcie->pdev->dev; -int neg_gen =-1 , gen; -/* * Reset PCIe card via PERST# signal. Some cards are not detected * during link training when they are in some non-initial state.
@@ -381,41 +355,18 @@ static void advk_pcie_train_link(struct advk_pcie *pcie)* PERST# signal could have been asserted by pinctrl subsystem before * probe() callback has been called or issued explicitly by reset gpio * function advk_pcie_issue_perst(), making the endpoint going into -* fundamental reset. As required by PCI Express spec a delay for at -* least 100ms after such a reset before link training is needed. -*/ -msleep (PCI_PM_D3COLD_WAIT ); - -/* -* Try link training at link gen specified by device tree property -* 'max-link-speed'. If this fails, iteratively train at lower gen. -*/ -for (gen = pcie->link_gen; gen >0 ; --gen) { - neg_gen =advk_pcie_train_at_gen (pcie, gen); -if (neg_gen >0 ) -break ; - } - -if (neg_gen <0 ) - goto err; - -/* -* After successful training if negotiated gen is lower than requested, -* train again on negotiated gen. This solves some stability issues for -* some buggy gen1 cards. +* fundamental reset. As required by PCI Express spec (PCI Express +* Base Specification, REV. 4.0 PCI Express, February 19 2014, 6.6.1 +* Conventional Reset) a delay for at least 100ms after such a reset +* before sending a Configuration Request to the device is needed. +* So wait until PCIe link is up. Function advk_pcie_wait_for_link() +* waits for link at least 900ms. */ -if (neg_gen < gen) { - gen = neg_gen; - neg_gen =advk_pcie_train_at_gen (pcie, gen); - } - -if (neg_gen == gen) { -dev_info (dev,"link up at gen %i\n" , gen); -return ; - } - -err: -dev_err (dev,"link never came up\n" ); + ret =advk_pcie_wait_for_link (pcie); +if (ret <0 ) +dev_err (dev,"link never came up\n" ); +else +dev_info (dev,"link up\n" ); }/*
Signature · 1 line
2.32.0
Re: [PATCH v2 11/13] PCI: aardvark: Fix link training
Quoted 139 lines · Marek Behún
From: Pali Rohár <[email protected]>
Fix multiple link training issues in aardvark driver. The main reason of these issues was misunderstanding of what certain registers do, since their names and comments were misleading: before commit
96be36dbffac("PCI:
aardvark: Replace custom macros by standardlinux/pci_regs.hmacros"), thepci-aardvark.cdriver used custom macros for accessing standard PCIe Root Bridge registers, and misleading comments did not help to understand what the code was really doing.After doing more tests and experiments I've come to the conclusion that the
SPEED_GENregister in aardvark sets the PCIe revision / generation compliance and forces maximal link speed. Both GEN3 and GEN2 values set the read-onlyPCI_EXP_FLAGS_VERSbits (PCIe capabilities version of Root Bridge) to value 2, while GEN1 value setsPCI_EXP_FLAGS_VERSto 1, which matches with PCI Express specifications revisions 3, 2 and 1 respectively. ChangingSPEED_GENalso sets the read-only bitsPCI_EXP_LNKCAP_SLSandPCI_EXP_LNKCAP2_SLSto corresponding speed.(Note that PCI Express rev 1 specification does not define
PCI_EXP_LNKCAP2
andPCI_EXP_LNKCTL2registers and whenSPEED_GENis set to GEN1 (which also setsPCI_EXP_FLAGS_VERSset to 1), lspci cannot accessPCI_EXP_LNKCAP2andPCI_EXP_LNKCTL2registers.)Changing PCIe link speed can be done via
PCI_EXP_LNKCTL2_TLSbits ofPCI_EXP_LNKCTL2register. Armada 3700 Functional Specifications says that the default value ofPCI_EXP_LNKCTL2_TLSis based onSPEED_GENvalue, but tests showed that the default value is always 8.0 GT/s, independently of speed set bySPEED_GEN. So after settingSPEED_GEN, we must also set value inPCI_EXP_LNKCTL2register viaPCI_EXP_LNKCTL2_TLSbits.Triggering
PCI_EXP_LNKCTL_RLbit immediately after settingLINK_TRAINING_ENbit actually doesn't do anything. Tests have shown that a delay is needed after enablingLINK_TRAINING_ENbit. As triggeringPCI_EXP_LNKCTL_RLcurrently does nothing, remove it.Commit
43fc679ced18("PCI: aardvark: Improve link training") introduced code which setsSPEED_GENregister based on negotiated link speed fromPCI_EXP_LNKSTA_CLSbits ofPCI_EXP_LNKSTAregister. This code was added to fix detection of Compex WLE900VX (Atheros QCA9880) WiFi GEN1 PCIe cards, as otherwise these cards were "invisible" on PCIe bus (probably because they crashed). But apparently more people reported the same issues with these cards also with other PCIe controllers [1] and I was able to reproduce this issue also with other "noname" WiFi cards based on Atheros QCA9890 chip (with the same PCI vendor/device ids as Atheros QCA9880). So this is not an issue in aardvark but rather an issue in Atheros QCA98xx chips. Also, this issue only exists if the kernel is compiled with PCIe ASPM support, and a generic workaround for this is to change PCIe Bridge to 2.5 GT/s link speed viaPCI_EXP_LNKCTL2_TLS_2_5GTbits inPCI_EXP_LNKCTL2register [2], before triggeringPCI_EXP_LNKCTL_RLbit. This workaround also works whenSPEED_GENis set to value GEN2 (5 GT/s). So remove this hack completely in the aardvark driver and always setSPEED_GENto value from 'max-link-speed' DT property. Fix for Atheros QCA98xx chips is handled separately by patch [2].These two things (code for triggering
PCI_EXP_LNKCTL_RLbit and changingSPEED_GENvalue) also explain why commit6964494582f5("PCI: aardvark:
Train link immediately after enabling training") somehow fixed detection of those problematic Compex cards with Atheros chips: if triggering link retraining (viaPCI_EXP_LNKCTL_RLbit) was done immediately after enabling link training (viaLINK_TRAINING_EN), it did nothing. If there was a specific delay, aardvark HW already initialized PCIe link and therefore triggering link retraining caused the above issue. Compex cards triggered link down event and disappeared from the PCIe bus.Commit
f4c7d053d7f7("PCI: aardvark: Wait for endpoint to be ready before training link") added 100ms sleep before calling 'Start link training' command and explained that it is a requirement of PCI Express specification. But the code after this 100ms sleep was not doing 'Start link training', rather it triggeredPCI_EXP_LNKCTL_RLbit via PCIe Root Bridge to put link into Recovery state.The required delay after fundamental reset is already done in function
advk_pcie_wait_for_link()which also checks whether PCIe link is up. So after removing the code which triggersPCI_EXP_LNKCTL_RLbit on PCIe Root Bridge, there is no need to wait 100ms again. Remove the extramsleep()call and update comment about the delay required by the PCI Express specification.According to Marvell Armada 3700 Functional Specifications, Link training should be enabled via aardvark register
LINK_TRAINING_ENafter selecting PCIe generation and x1 lane. There is no need to disable it prior resetting card via PERST# signal. This disabling code was introduced in commit5169a9851daa("PCI: aardvark: Issue PERST via GPIO") as a workaround for some Atheros cards. It turns out that this also is Atheros specific issue and affects any PCIe controller, not only aardvark. Moreover this Atheros issue was triggered by juggling withPCI_EXP_LNKCTL_RL,LINK_TRAINING_ENandSPEED_GENbits interleaved with sleeps. Now, after removing triggeringPCI_EXP_LNKCTL_RL, there is no need to explicitly disableLINK_TRAINING_ENbit. So remove this code too. The problematic Compex cards described in previous git commits are correctly detected inadvk_pcie_train_link()function even after applying all these changes.Note that with this patch, and also prior this patch, some NVMe disks which support PCIe GEN3 with 8 GT/s speed are negotiated only at the lowest link speed 2.5 GT/s, independently of
SPEED_GENvalue. After manually triggeringPCI_EXP_LNKCTL_RLbit (e.g. from userspace via setpci), these NVMe disks change link speed to 5 GT/s whenSPEED_GENwas configured to GEN2. This issue first needs to be properly investigated. I will send a fix in the future.On the other hand, some other GEN2 PCIe cards with 5 GT/s speed are autonomously by HW autonegotiated at full 5 GT/s speed without need of any software interaction.
Armada 3700 Functional Specifications describes the following steps for link training: set
SPEED_GENto GEN2, enableLINK_TRAINING_EN, poll until link training is complete, triggerPCI_EXP_LNKCTL_RL, poll until signal rate is 5 GT/s, poll until link training is complete, enable ASPM L0s.The requirement for triggering
PCI_EXP_LNKCTL_RLcan be explained by the need to achieve 5 GT/s speed (as changing link speed is done by throw to recovery state entered byPCI_EXP_LNKCTL_RL) or maybe as a part of enabling ASPM L0s (but in this case ASPM L0s should have been enabled priorPCI_EXP_LNKCTL_RL).It is unknown why the original
pci-aardvark.cdriver was triggeringPCI_EXP_LNKCTL_RLbit before waiting for the link to be up. This does not align with neither PCIe base specifications nor with Armada 3700 Functional Specification. (Note that in older versions of aardvark, this bit was called incorrectlyPCIE_CORE_LINK_TRAINING, so this may be the reason.)It is also unknown why Armada 3700 Functional Specification says that it is needed to trigger
PCI_EXP_LNKCTL_RLfor GEN2 mode, as according to PCIe base specification 5 GT/s speed negotiation is supposed to be entirely autonomous, even if initial speed is 2.5 GT/s.[1] - https://lore.kernel.org/linux-pci/[email protected]/
[2] - https://lore.kernel.org/linux-pci/[email protected]/Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>Signed-off-by Marek Behún <[email protected]>Cc [email protected] # f4c7d053d7f7 ("PCI: aardvark: Wait for endpoint to be ready before training link")Cc [email protected] # 6964494582f5 ("PCI: aardvark: Train link immediately after enabling training")Cc [email protected] # 43fc679ced18 ("PCI: aardvark: Improve link training")Cc [email protected] # 5169a9851daa ("PCI: aardvark: Issue PERST via GPIO")Cc [email protected] # 96be36dbffac ("PCI: aardvark: Replace custom macros by standard linux/pci_regs.h macros")Cc [email protected] # d0c6a3475b03 ("PCI: aardvark: Move PCIe reset card code to advk_pcie_train_link()")Cc [email protected] # 1d1cd163d0de ("PCI: aardvark: Update comment about disabling link training")
Quoted 3 lines
--- drivers/pci/controller/pci-aardvark.c | 117 ++++++++------------------ 1 file changed, 34 insertions(+), 83 deletions(-)
This is a very convoluted fix; it is well explained but the number of patches going into stable and the complexity of it make me ask how confident you are this won't trigger any regressions.
It is just a heads-up to make you think whether it is better to hold the stable tags till we are confident enough.
Please let me know.
Thanks,
Lorenzo
Quoted 174 lines
drivers/pci/controller/pci-aardvark.c +34
-83@@ -258,11 +258,6 @@ static inline u32 advk_readl(struct advk_pcie *pcie, u64 reg)return readl (pcie->base + reg); } -static inline u16 advk_read16 (struct advk_pcie *pcie,u64 reg) -{ -return advk_readl (pcie, (reg & ~0x3 )) >> ((reg &0x3 ) *8 ); -} -static int advk_pcie_link_up (struct advk_pcie *pcie) {u32 val, ltssm_state;@@ -300,23 +295,9 @@ static void advk_pcie_wait_for_retrain(struct advk_pcie *pcie)static void advk_pcie_issue_perst (struct advk_pcie *pcie) { -u32 reg; -if (!pcie->reset_gpio)return ; -/* -* As required by PCI Express spec (PCI Express Base Specification, REV. -* 4.0 PCI Express, February 19 2014, 6.6.1 Conventional Reset) a delay -* for at least 100ms after de-asserting PERST# signal is needed before -* link training is enabled. So ensure that link training is disabled -* prior de-asserting PERST# signal to fulfill that PCI Express spec -* requirement. -*/ - reg =advk_readl (pcie,PCIE_CORE_CTRL0_REG ); - reg &= ~LINK_TRAINING_EN ; -advk_writel (pcie, reg,PCIE_CORE_CTRL0_REG ); -/* 10ms delay is needed for some cards */ dev_info (&pcie->pdev->dev,"issuing PERST via reset GPIO for 10ms\n" );gpiod_set_value_cansleep (pcie->reset_gpio,1 );@@ -324,53 +305,46 @@ static void advk_pcie_issue_perst(struct advk_pcie *pcie)gpiod_set_value_cansleep (pcie->reset_gpio,0 ); } -static int advk_pcie_train_at_gen (struct advk_pcie *pcie,int gen) +static void advk_pcie_train_link (struct advk_pcie *pcie) { -int ret, neg_gen; +struct device *dev = &pcie->pdev->dev;u32 reg; +int ret; -/* Setup link speed */ +/* +* Setup PCIe rev / gen compliance based on device tree property +* 'max-link-speed' which also forces maximal link speed. +*/ reg =advk_readl (pcie,PCIE_CORE_CTRL0_REG ); reg &= ~PCIE_GEN_SEL_MSK ; -if (gen ==3 ) +if (pcie->link_gen ==3 ) reg |=SPEED_GEN_3 ; -else if (gen ==2 ) +else if (pcie->link_gen ==2 ) reg |=SPEED_GEN_2 ;else reg |=SPEED_GEN_1 ;advk_writel (pcie, reg,PCIE_CORE_CTRL0_REG );/* -* Enable link training. This is not needed in every call to this -* function, just once suffices, but it does not break anything either. +* Set maximal link speed value also into PCIe Link Control 2 register. +* Armada 3700 Functional Specification says that default value is based +* on SPEED_GEN but tests showed that default value is always 8.0 GT/s. */ + reg =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP +PCI_EXP_LNKCTL2 ); + reg &= ~PCI_EXP_LNKCTL2_TLS ; +if (pcie->link_gen ==3 ) + reg |=PCI_EXP_LNKCTL2_TLS_8_0GT ; +else if (pcie->link_gen ==2 ) + reg |=PCI_EXP_LNKCTL2_TLS_5_0GT ; +else + reg |=PCI_EXP_LNKCTL2_TLS_2_5GT ; +advk_writel (pcie, reg,PCIE_CORE_PCIEXP_CAP +PCI_EXP_LNKCTL2 ); + +/* Enable link training after selecting PCIe generation */ reg =advk_readl (pcie,PCIE_CORE_CTRL0_REG ); reg |=LINK_TRAINING_EN ;advk_writel (pcie, reg,PCIE_CORE_CTRL0_REG ); -/* -* Start link training immediately after enabling it. -* This solves problems for some buggy cards. -*/ - reg =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP +PCI_EXP_LNKCTL ); - reg |=PCI_EXP_LNKCTL_RL ; -advk_writel (pcie, reg,PCIE_CORE_PCIEXP_CAP +PCI_EXP_LNKCTL ); - - ret =advk_pcie_wait_for_link (pcie); -if (ret) -return ret; - - reg =advk_read16 (pcie,PCIE_CORE_PCIEXP_CAP +PCI_EXP_LNKSTA ); - neg_gen = reg &PCI_EXP_LNKSTA_CLS ; - -return neg_gen; -} - -static void advk_pcie_train_link (struct advk_pcie *pcie) -{ -struct device *dev = &pcie->pdev->dev; -int neg_gen =-1 , gen; -/* * Reset PCIe card via PERST# signal. Some cards are not detected * during link training when they are in some non-initial state. @@ -381,41 +355,18 @@ static void advk_pcie_train_link(struct advk_pcie *pcie)* PERST# signal could have been asserted by pinctrl subsystem before * probe() callback has been called or issued explicitly by reset gpio * function advk_pcie_issue_perst(), making the endpoint going into -* fundamental reset. As required by PCI Express spec a delay for at -* least 100ms after such a reset before link training is needed. -*/ -msleep (PCI_PM_D3COLD_WAIT ); - -/* -* Try link training at link gen specified by device tree property -* 'max-link-speed'. If this fails, iteratively train at lower gen. -*/ -for (gen = pcie->link_gen; gen >0 ; --gen) { - neg_gen =advk_pcie_train_at_gen (pcie, gen); -if (neg_gen >0 ) -break ; - } - -if (neg_gen <0 ) - goto err; - -/* -* After successful training if negotiated gen is lower than requested, -* train again on negotiated gen. This solves some stability issues for -* some buggy gen1 cards. +* fundamental reset. As required by PCI Express spec (PCI Express +* Base Specification, REV. 4.0 PCI Express, February 19 2014, 6.6.1 +* Conventional Reset) a delay for at least 100ms after such a reset +* before sending a Configuration Request to the device is needed. +* So wait until PCIe link is up. Function advk_pcie_wait_for_link() +* waits for link at least 900ms. */ -if (neg_gen < gen) { - gen = neg_gen; - neg_gen =advk_pcie_train_at_gen (pcie, gen); - } - -if (neg_gen == gen) { -dev_info (dev,"link up at gen %i\n" , gen); -return ; - } - -err: -dev_err (dev,"link never came up\n" ); + ret =advk_pcie_wait_for_link (pcie); +if (ret <0 ) +dev_err (dev,"link never came up\n" ); +else +dev_info (dev,"link up\n" ); }/* Signature · 1 line
2.32.0
Re: [PATCH v2 11/13] PCI: aardvark: Fix link training
Quoted 144 lines · On Thu, 7 Oct 2021 12:55:22 +0100 Lorenzo Pieralisi…
Quoted 139 lines · Marek Behún
From: Pali Rohár <[email protected]>
Fix multiple link training issues in aardvark driver. The main reason of these issues was misunderstanding of what certain registers do, since their names and comments were misleading: before commit
96be36dbffac("PCI:
aardvark: Replace custom macros by standardlinux/pci_regs.hmacros"), thepci-aardvark.cdriver used custom macros for accessing standard PCIe Root Bridge registers, and misleading comments did not help to understand what the code was really doing.After doing more tests and experiments I've come to the conclusion that the
SPEED_GENregister in aardvark sets the PCIe revision / generation compliance and forces maximal link speed. Both GEN3 and GEN2 values set the read-onlyPCI_EXP_FLAGS_VERSbits (PCIe capabilities version of Root Bridge) to value 2, while GEN1 value setsPCI_EXP_FLAGS_VERSto 1, which matches with PCI Express specifications revisions 3, 2 and 1 respectively. ChangingSPEED_GENalso sets the read-only bitsPCI_EXP_LNKCAP_SLSandPCI_EXP_LNKCAP2_SLSto corresponding speed.(Note that PCI Express rev 1 specification does not define
PCI_EXP_LNKCAP2
andPCI_EXP_LNKCTL2registers and whenSPEED_GENis set to GEN1 (which also setsPCI_EXP_FLAGS_VERSset to 1), lspci cannot accessPCI_EXP_LNKCAP2andPCI_EXP_LNKCTL2registers.)Changing PCIe link speed can be done via
PCI_EXP_LNKCTL2_TLSbits ofPCI_EXP_LNKCTL2register. Armada 3700 Functional Specifications says that the default value ofPCI_EXP_LNKCTL2_TLSis based onSPEED_GENvalue, but tests showed that the default value is always 8.0 GT/s, independently of speed set bySPEED_GEN. So after settingSPEED_GEN, we must also set value inPCI_EXP_LNKCTL2register viaPCI_EXP_LNKCTL2_TLSbits.Triggering
PCI_EXP_LNKCTL_RLbit immediately after settingLINK_TRAINING_ENbit actually doesn't do anything. Tests have shown that a delay is needed after enablingLINK_TRAINING_ENbit. As triggeringPCI_EXP_LNKCTL_RLcurrently does nothing, remove it.Commit
43fc679ced18("PCI: aardvark: Improve link training") introduced code which setsSPEED_GENregister based on negotiated link speed fromPCI_EXP_LNKSTA_CLSbits ofPCI_EXP_LNKSTAregister. This code was added to fix detection of Compex WLE900VX (Atheros QCA9880) WiFi GEN1 PCIe cards, as otherwise these cards were "invisible" on PCIe bus (probably because they crashed). But apparently more people reported the same issues with these cards also with other PCIe controllers [1] and I was able to reproduce this issue also with other "noname" WiFi cards based on Atheros QCA9890 chip (with the same PCI vendor/device ids as Atheros QCA9880). So this is not an issue in aardvark but rather an issue in Atheros QCA98xx chips. Also, this issue only exists if the kernel is compiled with PCIe ASPM support, and a generic workaround for this is to change PCIe Bridge to 2.5 GT/s link speed viaPCI_EXP_LNKCTL2_TLS_2_5GTbits inPCI_EXP_LNKCTL2register [2], before triggeringPCI_EXP_LNKCTL_RLbit. This workaround also works whenSPEED_GENis set to value GEN2 (5 GT/s). So remove this hack completely in the aardvark driver and always setSPEED_GENto value from 'max-link-speed' DT property. Fix for Atheros QCA98xx chips is handled separately by patch [2].These two things (code for triggering
PCI_EXP_LNKCTL_RLbit and changingSPEED_GENvalue) also explain why commit6964494582f5("PCI: aardvark:
Train link immediately after enabling training") somehow fixed detection of those problematic Compex cards with Atheros chips: if triggering link retraining (viaPCI_EXP_LNKCTL_RLbit) was done immediately after enabling link training (viaLINK_TRAINING_EN), it did nothing. If there was a specific delay, aardvark HW already initialized PCIe link and therefore triggering link retraining caused the above issue. Compex cards triggered link down event and disappeared from the PCIe bus.Commit
f4c7d053d7f7("PCI: aardvark: Wait for endpoint to be ready before training link") added 100ms sleep before calling 'Start link training' command and explained that it is a requirement of PCI Express specification. But the code after this 100ms sleep was not doing 'Start link training', rather it triggeredPCI_EXP_LNKCTL_RLbit via PCIe Root Bridge to put link into Recovery state.The required delay after fundamental reset is already done in function
advk_pcie_wait_for_link()which also checks whether PCIe link is up. So after removing the code which triggersPCI_EXP_LNKCTL_RLbit on PCIe Root Bridge, there is no need to wait 100ms again. Remove the extramsleep()call and update comment about the delay required by the PCI Express specification.According to Marvell Armada 3700 Functional Specifications, Link training should be enabled via aardvark register
LINK_TRAINING_ENafter selecting PCIe generation and x1 lane. There is no need to disable it prior resetting card via PERST# signal. This disabling code was introduced in commit5169a9851daa("PCI: aardvark: Issue PERST via GPIO") as a workaround for some Atheros cards. It turns out that this also is Atheros specific issue and affects any PCIe controller, not only aardvark. Moreover this Atheros issue was triggered by juggling withPCI_EXP_LNKCTL_RL,LINK_TRAINING_ENandSPEED_GENbits interleaved with sleeps. Now, after removing triggeringPCI_EXP_LNKCTL_RL, there is no need to explicitly disableLINK_TRAINING_ENbit. So remove this code too. The problematic Compex cards described in previous git commits are correctly detected inadvk_pcie_train_link()function even after applying all these changes.Note that with this patch, and also prior this patch, some NVMe disks which support PCIe GEN3 with 8 GT/s speed are negotiated only at the lowest link speed 2.5 GT/s, independently of
SPEED_GENvalue. After manually triggeringPCI_EXP_LNKCTL_RLbit (e.g. from userspace via setpci), these NVMe disks change link speed to 5 GT/s whenSPEED_GENwas configured to GEN2. This issue first needs to be properly investigated. I will send a fix in the future.On the other hand, some other GEN2 PCIe cards with 5 GT/s speed are autonomously by HW autonegotiated at full 5 GT/s speed without need of any software interaction.
Armada 3700 Functional Specifications describes the following steps for link training: set
SPEED_GENto GEN2, enableLINK_TRAINING_EN, poll until link training is complete, triggerPCI_EXP_LNKCTL_RL, poll until signal rate is 5 GT/s, poll until link training is complete, enable ASPM L0s.The requirement for triggering
PCI_EXP_LNKCTL_RLcan be explained by the need to achieve 5 GT/s speed (as changing link speed is done by throw to recovery state entered byPCI_EXP_LNKCTL_RL) or maybe as a part of enabling ASPM L0s (but in this case ASPM L0s should have been enabled priorPCI_EXP_LNKCTL_RL).It is unknown why the original
pci-aardvark.cdriver was triggeringPCI_EXP_LNKCTL_RLbit before waiting for the link to be up. This does not align with neither PCIe base specifications nor with Armada 3700 Functional Specification. (Note that in older versions of aardvark, this bit was called incorrectlyPCIE_CORE_LINK_TRAINING, so this may be the reason.)It is also unknown why Armada 3700 Functional Specification says that it is needed to trigger
PCI_EXP_LNKCTL_RLfor GEN2 mode, as according to PCIe base specification 5 GT/s speed negotiation is supposed to be entirely autonomous, even if initial speed is 2.5 GT/s.[1] - https://lore.kernel.org/linux-pci/[email protected]/
[2] - https://lore.kernel.org/linux-pci/[email protected]/Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>Signed-off-by Marek Behún <[email protected]>Cc [email protected] # f4c7d053d7f7 ("PCI: aardvark: Wait for endpoint to be ready before training link")Cc [email protected] # 6964494582f5 ("PCI: aardvark: Train link immediately after enabling training")Cc [email protected] # 43fc679ced18 ("PCI: aardvark: Improve link training")Cc [email protected] # 5169a9851daa ("PCI: aardvark: Issue PERST via GPIO")Cc [email protected] # 96be36dbffac ("PCI: aardvark: Replace custom macros by standard linux/pci_regs.h macros")Cc [email protected] # d0c6a3475b03 ("PCI: aardvark: Move PCIe reset card code to advk_pcie_train_link()")Cc [email protected] # 1d1cd163d0de ("PCI: aardvark: Update comment about disabling link training")Quoted 3 lines
--- drivers/pci/controller/pci-aardvark.c | 117 ++++++++------------------ 1 file changed, 34 insertions(+), 83 deletions(-)
Quoted 8 lines
This is a very convoluted fix; it is well explained but the number of patches going into stable and the complexity of it make me ask how confident you are this won't trigger any regressions.
It is just a heads-up to make you think whether it is better to hold the stable tags till we are confident enough.
Please let me know.
Lorenzo,
you are probably right here. It would be better to have this in upstream for some time and let people test it, and only afterward send it into stable.
Let's remove the Fixes tag. We will send this into stable after it is a little tested.
Marek
PATCH v2 12/13 PCI: aardvark: Fix checking for link up via LTSSM state
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
Current implementation of advk_pcie_link_up() is wrong as it marks also link disabled or hot reset states as link up.
Fix it by marking link up only to those states which are defined in PCIe Base specification 3.0, Table 4-14: Link Status Mapped to the LTSSM.
To simplify implementation, Define macros for every LTSSM state which aardvark hardware can return in CFG_REG register.
Fix also checking for link training according to the same Table 4-14. Define a new function advk_pcie_link_training() for this purpose.
--- drivers/pci/controller/pci-aardvark.c | 76 ++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 6 deletions(-)
drivers/pci/controller/pci-aardvark.c +70 -6
@@ -165,8 +165,50 @@#define CFG_REG (LMI_BASE_ADDR + 0x0)#define LTSSM_SHIFT 24#define LTSSM_MASK 0x3f -#define LTSSM_L0 0x10#define RC_BAR_CONFIG 0x300 + +/* LTSSM values in CFG_REG */ +enum { +LTSSM_DETECT_QUIET =0x0 , +LTSSM_DETECT_ACTIVE =0x1 , +LTSSM_POLLING_ACTIVE =0x2 , +LTSSM_POLLING_COMPLIANCE =0x3 , +LTSSM_POLLING_CONFIGURATION =0x4 , +LTSSM_CONFIG_LINKWIDTH_START =0x5 , +LTSSM_CONFIG_LINKWIDTH_ACCEPT =0x6 , +LTSSM_CONFIG_LANENUM_ACCEPT =0x7 , +LTSSM_CONFIG_LANENUM_WAIT =0x8 , +LTSSM_CONFIG_COMPLETE =0x9 , +LTSSM_CONFIG_IDLE =0xa , +LTSSM_RECOVERY_RCVR_LOCK =0xb , +LTSSM_RECOVERY_SPEED =0xc , +LTSSM_RECOVERY_RCVR_CFG =0xd , +LTSSM_RECOVERY_IDLE =0xe , +LTSSM_L0 =0x10 , +LTSSM_RX_L0S_ENTRY =0x11 , +LTSSM_RX_L0S_IDLE =0x12 , +LTSSM_RX_L0S_FTS =0x13 , +LTSSM_TX_L0S_ENTRY =0x14 , +LTSSM_TX_L0S_IDLE =0x15 , +LTSSM_TX_L0S_FTS =0x16 , +LTSSM_L1_ENTRY =0x17 , +LTSSM_L1_IDLE =0x18 , +LTSSM_L2_IDLE =0x19 , +LTSSM_L2_TRANSMIT_WAKE =0x1a , +LTSSM_DISABLED =0x20 , +LTSSM_LOOPBACK_ENTRY_MASTER =0x21 , +LTSSM_LOOPBACK_ACTIVE_MASTER =0x22 , +LTSSM_LOOPBACK_EXIT_MASTER =0x23 , +LTSSM_LOOPBACK_ENTRY_SLAVE =0x24 , +LTSSM_LOOPBACK_ACTIVE_SLAVE =0x25 , +LTSSM_LOOPBACK_EXIT_SLAVE =0x26 , +LTSSM_HOT_RESET =0x27 , +LTSSM_RECOVERY_EQUALIZATION_PHASE0 =0x28 , +LTSSM_RECOVERY_EQUALIZATION_PHASE1 =0x29 , +LTSSM_RECOVERY_EQUALIZATION_PHASE2 =0x2a , +LTSSM_RECOVERY_EQUALIZATION_PHASE3 =0x2b , +}; +#define VENDOR_ID_REG (LMI_BASE_ADDR + 0x44)/* PCIe core controller registers */
@@ -258,13 +300,35 @@ static inline u32 advk_readl(struct advk_pcie *pcie, u64 reg)return readl (pcie->base + reg); } -static int advk_pcie_link_up (struct advk_pcie *pcie) +static u8 advk_pcie_ltssm_state (struct advk_pcie *pcie) { -u32 val, ltssm_state; +u32 val; +u8 ltssm_state; val =advk_readl (pcie,CFG_REG ); ltssm_state = (val >>LTSSM_SHIFT ) <SSM_MASK ; -return ltssm_state >=LTSSM_L0 ; +return ltssm_state; +} + +static inline bool advk_pcie_link_up (struct advk_pcie *pcie) +{ +/* check if LTSSM is in normal operation - some L* state */ +u8 ltssm_state =advk_pcie_ltssm_state (pcie); +return ltssm_state >=LTSSM_L0 && ltssm_state <LTSSM_DISABLED ; +} + +static inline bool advk_pcie_link_training (struct advk_pcie *pcie) +{ +/* +* According to PCIe Base specification 3.0, Table 4-14: Link +* Status Mapped to the LTSSM is Link Training mapped to LTSSM +* Configuration and Recovery states. +*/ +u8 ltssm_state =advk_pcie_ltssm_state (pcie); +return ((ltssm_state >=LTSSM_CONFIG_LINKWIDTH_START && + ltssm_state <LTSSM_L0 ) || + (ltssm_state >=LTSSM_RECOVERY_EQUALIZATION_PHASE0 && + ltssm_state <=LTSSM_RECOVERY_EQUALIZATION_PHASE3 )); }static int advk_pcie_wait_for_link (struct advk_pcie *pcie)
@@ -287,7 +351,7 @@ static void advk_pcie_wait_for_retrain(struct advk_pcie *pcie)size_t retries;for (retries =0 ; retries <RETRAIN_WAIT_MAX_RETRIES ; ++retries) { -if (!advk_pcie_link_up (pcie)) +if (advk_pcie_link_training (pcie))break ;udelay (RETRAIN_WAIT_USLEEP_US ); }
@@ -706,7 +770,7 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,/* u32 contains both PCI_EXP_LNKCTL and PCI_EXP_LNKSTA */ u32 val =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg) & ~(PCI_EXP_LNKSTA_LT <<16 ); -if (!advk_pcie_link_up (pcie)) +if (advk_pcie_link_training (pcie)) val |= (PCI_EXP_LNKSTA_LT <<16 ); *value = val;return PCI_BRIDGE_EMUL_HANDLED ;
Signature · 1 line
2.32.0
PATCH v2 13/13 PCI: aardvark: Fix reporting Data Link Layer Link Active
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
Add support for reporting PCI_EXP_LNKSTA_DLLLA bit in Link Control register on emulated bridge via current LTSSM state. Also correctly indicate DLLLA capability via PCI_EXP_LNKCAP_DLLLARC bit in Link Control Capability register.
--- drivers/pci/controller/pci-aardvark.c | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/pci/controller/pci-aardvark.c +28 -1
@@ -317,6 +317,20 @@ static inline bool advk_pcie_link_up(struct advk_pcie *pcie)return ltssm_state >=LTSSM_L0 && ltssm_state <LTSSM_DISABLED ; } +static inline bool advk_pcie_link_active (struct advk_pcie *pcie) +{ +/* +* According to PCIe Base specification 3.0, Table 4-14: Link +* Status Mapped to the LTSSM, and 4.2.6.3.6 Configuration.Idle +* is Link Up mapped to LTSSM Configuration.Idle, Recovery, L0, +* L0s, L1 and L2 states. And according to 3.2.1. Data Link +* Control and Management State Machine Rules is DL Up status +* reported in DL Active state. +*/ +u8 ltssm_state =advk_pcie_ltssm_state (pcie); +return ltssm_state >=LTSSM_CONFIG_IDLE && ltssm_state <LTSSM_DISABLED ; +} +static inline bool advk_pcie_link_training (struct advk_pcie *pcie) {/*
@@ -766,12 +780,26 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,return PCI_BRIDGE_EMUL_HANDLED ; } +case PCI_EXP_LNKCAP : { +u32 val =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg); +/* +* PCI_EXP_LNKCAP_DLLLARC bit is hardwired in aardvark HW to 0. +* But support for PCI_EXP_LNKSTA_DLLLA is emulated via ltssm +* state so explicitly enable PCI_EXP_LNKCAP_DLLLARC flag. +*/ + val |=PCI_EXP_LNKCAP_DLLLARC ; + *value = val; +return PCI_BRIDGE_EMUL_HANDLED ; + } +case PCI_EXP_LNKCTL : {/* u32 contains both PCI_EXP_LNKCTL and PCI_EXP_LNKSTA */ u32 val =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg) & ~(PCI_EXP_LNKSTA_LT <<16 );if (advk_pcie_link_training (pcie)) val |= (PCI_EXP_LNKSTA_LT <<16 ); +if (advk_pcie_link_active (pcie)) + val |= (PCI_EXP_LNKSTA_DLLLA <<16 ); *value = val;return PCI_BRIDGE_EMUL_HANDLED ; }
@@ -779,7 +807,6 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,case PCI_CAP_LIST_ID :case PCI_EXP_DEVCAP :case PCI_EXP_DEVCTL : -case PCI_EXP_LNKCAP : *value =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg);return PCI_BRIDGE_EMUL_HANDLED ;default :
Signature · 1 line
2.32.0
Quoted 9 lines · Marek Behún
as requested I am sending v2 of this series.
Changes since v1:
- updated commit message in patch 6 as suggested by Mark
- updated patch 6 to also drop the early return
- changed the LTSSM definitions to enum in patch 12
- dropped the Fixes tags for those patches where it was inappropriate[...]
I rewrote some logs, dropped some stable tags. This series raised a couple of interesting questions that may be relevant for PCI core as well, it'd be great if those won't be lost but I feel it is time to merge this series to help Marek/Pali cut the patch delta and give this code wider testing.
I have applied it to pci/aardvark, please _do_ have a look and report back any issue with it.
[01/13] PCI: Add PCI_EXP_DEVCTL_PAYLOAD_* macros
https://git.kernel.org/lpieralisi/pci/c/460275f124 [02/13] PCI: aardvark: Fix PCIe Max Payload Size setting https://git.kernel.org/lpieralisi/pci/c/a4e17d65da [03/13] PCI: aardvark: Don't spam about PIO Response Status https://git.kernel.org/lpieralisi/pci/c/464de7e7ff [04/13] PCI: aardvark: Fix preserving PCI_EXP_RTCTL_CRSSVE flag on emulated bridge https://git.kernel.org/lpieralisi/pci/c/d419052bc6 [05/13] PCI: aardvark: Fix configuring Reference clock https://git.kernel.org/lpieralisi/pci/c/46ef6090db [06/13] PCI: aardvark: Do not clear status bits of masked interrupts https://git.kernel.org/lpieralisi/pci/c/a7ca6d7fa3 [07/13] PCI: aardvark: Do not unmask unused interrupts https://git.kernel.org/lpieralisi/pci/c/1fb95d7d3c [08/13] PCI: aardvark: Deduplicate code in advk_pcie_rd_conf() https://git.kernel.org/lpieralisi/pci/c/67cb2a4c93 [09/13] PCI: aardvark: Implement re-issuing config requests on CRS response https://git.kernel.org/lpieralisi/pci/c/223dec14a0 [10/13] PCI: aardvark: Simplify initialization of rootcap on virtual bridge https://git.kernel.org/lpieralisi/pci/c/454c53271f [11/13] PCI: aardvark: Fix link training https://git.kernel.org/lpieralisi/pci/c/f76b36d40b [12/13] PCI: aardvark: Fix checking for link up via LTSSM state https://git.kernel.org/lpieralisi/pci/c/661c399a65 [13/13] PCI: aardvark: Fix reporting Data Link Layer Link Active https://git.kernel.org/lpieralisi/pci/c/2b650b7ff2
Thanks,
Lorenzo
Quoted 11 lines · On Thu, 7 Oct 2021 14:38:25 +0100 Lorenzo Pieralisi…
Quoted 9 lines · Marek Behún
as requested I am sending v2 of this series.
Changes since v1:
- updated commit message in patch 6 as suggested by Mark
- updated patch 6 to also drop the early return
- changed the LTSSM definitions to enum in patch 12
- dropped the Fixes tags for those patches where it was inappropriate[...]
Quoted 8 lines
I rewrote some logs, dropped some stable tags. This series raised a couple of interesting questions that may be relevant for PCI core as well, it'd be great if those won't be lost but I feel it is time to merge this series to help Marek/Pali cut the patch delta and give this code wider testing.
I have applied it to pci/aardvark, please _do_ have a look and report back any issue with it.
I checked all the commit messages in pci/aardvark.
I also compiled this branch and tested it on my Mox with ath10k card and it works correctly, no regressions.
Marek