PCI: aardvark: Use LTSSM state to build link training flag
Subsystems (3)
PATCH v3 1/1 PCI: aardvark: Use LTSSM state to build link training flag
Aardvark's PCI_EXP_LNKSTA_LT flag in its link status register is not implemented and does not reflect the actual link training state (the flag is always set to 0). In order to support link re-training feature this flag has to be emulated. The Link Training and Status State Machine (LTSSM) flag in Aardvark LMI config register could be used as a link training indicator. Indeed if the LTSSM is in L0 or upper state then link training has completed (see [1]).
Unfortunately because after asking a link retraining it takes a while for the LTSSM state to become less than 0x10 (due to L0s to recovery state transition delays), LTSSM can still be in L0 while link training has not finished yet. So this waits for link to be in recovery or lesser state before returning after asking for a link retrain.
[1] "PCI Express Base Specification", REV. 4.0
PCI Express, February 19 2014, Table 4-14
---
Changes since v1:
- Rename retraining flag field
- Fix DEVCTL register writing
Changes since v2:
- Rewrite patch logic so it is more legible
Please note that I will unlikely be able to answer any comments from May 24th to June 10th.
--- drivers/pci/controller/pci-aardvark.c | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/pci/controller/pci-aardvark.c +28 -1
@@ -180,6 +180,8 @@#define LINK_WAIT_MAX_RETRIES 10#define LINK_WAIT_USLEEP_MIN 90000#define LINK_WAIT_USLEEP_MAX 100000 +#define RETRAIN_WAIT_MAX_RETRIES 10 +#define RETRAIN_WAIT_USLEEP_US 2000#define MSI_IRQ_NUM 32
@@ -239,6 +241,17 @@ static int advk_pcie_wait_for_link(struct advk_pcie *pcie)return -ETIMEDOUT ; } +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)) +break ; +udelay (RETRAIN_WAIT_USLEEP_US ); + } +} +static void advk_pcie_setup_hw (struct advk_pcie *pcie) {u32 reg;
@@ -426,11 +439,20 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,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_up (pcie)) + val |= (PCI_EXP_LNKSTA_LT <<16 ); + *value = val; +return PCI_BRIDGE_EMUL_HANDLED ; + } +case PCI_CAP_LIST_ID :case PCI_EXP_DEVCAP :case PCI_EXP_DEVCTL :case PCI_EXP_LNKCAP : -case PCI_EXP_LNKCTL : *value =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg);return PCI_BRIDGE_EMUL_HANDLED ;default :
@@ -447,8 +469,13 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,switch (reg) {case PCI_EXP_DEVCTL : +advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +break ; +case PCI_EXP_LNKCTL :advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +if (new &PCI_EXP_LNKCTL_RL ) +advk_pcie_wait_for_retrain (pcie);break ;case PCI_EXP_RTCTL :
Signature · 1 line
2.20.1
Quoted 101 lines · Remi Pommarel
Aardvark's
PCI_EXP_LNKSTA_LTflag in its link status register is not implemented and does not reflect the actual link training state (the flag is always set to 0). In order to support link re-training feature this flag has to be emulated. The Link Training and Status State Machine (LTSSM) flag in Aardvark LMI config register could be used as a link training indicator. Indeed if the LTSSM is in L0 or upper state then link training has completed (see [1]).Unfortunately because after asking a link retraining it takes a while for the LTSSM state to become less than
0x10(due to L0s to recovery state transition delays), LTSSM can still be in L0 while link training has not finished yet. So this waits for link to be in recovery or lesser state before returning after asking for a link retrain.[1] "PCI Express Base Specification", REV. 4.0
PCI Express, February 19 2014, Table 4-14Signed-off-by Remi Pommarel <[email protected]>---
Changes since v1:
- Rename retraining flag field
- Fix DEVCTL register writingChanges since v2:
- Rewrite patch logic so it is more legiblePlease note that I will unlikely be able to answer any comments from May 24th to June 10th.
--- drivers/pci/controller/pci-aardvark.c | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)drivers/pci/controller/pci-aardvark.c +28
-1@@ -180,6 +180,8 @@#define LINK_WAIT_MAX_RETRIES 10#define LINK_WAIT_USLEEP_MIN 90000#define LINK_WAIT_USLEEP_MAX 100000 +#define RETRAIN_WAIT_MAX_RETRIES 10 +#define RETRAIN_WAIT_USLEEP_US 2000#define MSI_IRQ_NUM 32@@ -239,6 +241,17 @@ static int advk_pcie_wait_for_link(struct advk_pcie *pcie)return -ETIMEDOUT ; } +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)) +break ; +udelay (RETRAIN_WAIT_USLEEP_US ); + } +} +static void advk_pcie_setup_hw (struct advk_pcie *pcie) {u32 reg;@@ -426,11 +439,20 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,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_up (pcie)) + val |= (PCI_EXP_LNKSTA_LT <<16 ); + *value = val; +return PCI_BRIDGE_EMUL_HANDLED ; + } +case PCI_CAP_LIST_ID :case PCI_EXP_DEVCAP :case PCI_EXP_DEVCTL :case PCI_EXP_LNKCAP : -case PCI_EXP_LNKCTL : *value =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg);return PCI_BRIDGE_EMUL_HANDLED ;default :@@ -447,8 +469,13 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,switch (reg) {case PCI_EXP_DEVCTL : +advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +break ; +case PCI_EXP_LNKCTL :advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +if (new &PCI_EXP_LNKCTL_RL ) +advk_pcie_wait_for_retrain (pcie);break ;case PCI_EXP_RTCTL :Signature · 1 line
2.20.1
Gentle ping.
Please note that the SError problem discussed in V1 has been handled and merged in arm-trusted-firmware's mainline.
Signature · 1 line
Remi
Hello Remi,
Quoted 14 lines · On Wed, 22 May 2019 23:33:51 +0200 Remi Pommarel <[email protected]> wrote:
Aardvark's
PCI_EXP_LNKSTA_LTflag in its link status register is not implemented and does not reflect the actual link training state (the flag is always set to 0). In order to support link re-training feature this flag has to be emulated. The Link Training and Status State Machine (LTSSM) flag in Aardvark LMI config register could be used as a link training indicator. Indeed if the LTSSM is in L0 or upper state then link training has completed (see [1]).Unfortunately because after asking a link retraining it takes a while for the LTSSM state to become less than
0x10(due to L0s to recovery state transition delays), LTSSM can still be in L0 while link training has not finished yet. So this waits for link to be in recovery or lesser state before returning after asking for a link retrain.
Quoted 4 lines
[1] "PCI Express Base Specification", REV. 4.0
PCI Express, February 19 2014, Table 4-14Signed-off-by Remi Pommarel <[email protected]>
Here as well, sorry for the very long delay, and many thanks for the great research work, including the arm-trusted-firmware fix. I reviewed the implementation, and tested on my Armada 3720 DB board with a E1000E NIC, and it all looks good to me.
Thanks!
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 64 lines · Remi Pommarel
Aardvark's
PCI_EXP_LNKSTA_LTflag in its link status register is not implemented and does not reflect the actual link training state (the flag is always set to 0). In order to support link re-training feature this flag has to be emulated. The Link Training and Status State Machine (LTSSM) flag in Aardvark LMI config register could be used as a link training indicator. Indeed if the LTSSM is in L0 or upper state then link training has completed (see [1]).Unfortunately because after asking a link retraining it takes a while for the LTSSM state to become less than
0x10(due to L0s to recovery state transition delays), LTSSM can still be in L0 while link training has not finished yet. So this waits for link to be in recovery or lesser state before returning after asking for a link retrain.[1] "PCI Express Base Specification", REV. 4.0
PCI Express, February 19 2014, Table 4-14Signed-off-by Remi Pommarel <[email protected]>---
Changes since v1:
- Rename retraining flag field
- Fix DEVCTL register writingChanges since v2:
- Rewrite patch logic so it is more legiblePlease note that I will unlikely be able to answer any comments from May 24th to June 10th.
--- drivers/pci/controller/pci-aardvark.c | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)drivers/pci/controller/pci-aardvark.c +13
-0@@ -180,6 +180,8 @@#define LINK_WAIT_MAX_RETRIES 10#define LINK_WAIT_USLEEP_MIN 90000#define LINK_WAIT_USLEEP_MAX 100000 +#define RETRAIN_WAIT_MAX_RETRIES 10 +#define RETRAIN_WAIT_USLEEP_US 2000#define MSI_IRQ_NUM 32@@ -239,6 +241,17 @@ static int advk_pcie_wait_for_link(struct advk_pcie *pcie)return -ETIMEDOUT ; } +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)) +break ; +udelay (RETRAIN_WAIT_USLEEP_US ); + } +} +static void advk_pcie_setup_hw (struct advk_pcie *pcie) {u32 reg;
drivers/pci/controller/pci-aardvark.c advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge, · line 445
Quoted 7 lines
drivers/pci/controller/pci-aardvark.c +4
-0@@ -426,11 +439,20 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,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 );
The commit message says "the flag is always set to 0" - therefore I guess you don't *need* to mask out the LT bit here? I assume this is just belt-and-braces but thought I'd check incase I've misunderstood or if your commit message is inaccurate.
In any case masking out the bit (or adding a comment) makes this code more readable as the reader doesn't need to know what the hardware does with this bit.
Quoted 15 lines
drivers/pci/controller/pci-aardvark.c +6
-1+if (!advk_pcie_link_up (pcie)) + val |= (PCI_EXP_LNKSTA_LT <<16 ); + *value = val; +return PCI_BRIDGE_EMUL_HANDLED ; + } +case PCI_CAP_LIST_ID :case PCI_EXP_DEVCAP :case PCI_EXP_DEVCTL :case PCI_EXP_LNKCAP : -case PCI_EXP_LNKCTL : *value =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg);return PCI_BRIDGE_EMUL_HANDLED ;default :
drivers/pci/controller/pci-aardvark.c advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge, · line 473
Quoted 5 lines
drivers/pci/controller/pci-aardvark.c +2
-0@@ -447,8 +469,13 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,switch (reg) {case PCI_EXP_DEVCTL : +advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +break ;
Why is this here?
Thanks,
Andrew Murray
Quoted 11 lines
drivers/pci/controller/pci-aardvark.c +3
-0+case PCI_EXP_LNKCTL :advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +if (new &PCI_EXP_LNKCTL_RL ) +advk_pcie_wait_for_retrain (pcie);break ;case PCI_EXP_RTCTL :Signature · 1 line
2.20.1
Quoted 78 lines · Andrew Murray
Quoted 64 lines · Remi Pommarel
Aardvark's
PCI_EXP_LNKSTA_LTflag in its link status register is not implemented and does not reflect the actual link training state (the flag is always set to 0). In order to support link re-training feature this flag has to be emulated. The Link Training and Status State Machine (LTSSM) flag in Aardvark LMI config register could be used as a link training indicator. Indeed if the LTSSM is in L0 or upper state then link training has completed (see [1]).Unfortunately because after asking a link retraining it takes a while for the LTSSM state to become less than
0x10(due to L0s to recovery state transition delays), LTSSM can still be in L0 while link training has not finished yet. So this waits for link to be in recovery or lesser state before returning after asking for a link retrain.[1] "PCI Express Base Specification", REV. 4.0
PCI Express, February 19 2014, Table 4-14Signed-off-by Remi Pommarel <[email protected]>---
Changes since v1:
- Rename retraining flag field
- Fix DEVCTL register writingChanges since v2:
- Rewrite patch logic so it is more legiblePlease note that I will unlikely be able to answer any comments from May 24th to June 10th.
--- drivers/pci/controller/pci-aardvark.c | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)drivers/pci/controller/pci-aardvark.c +13
-0@@ -180,6 +180,8 @@#define LINK_WAIT_MAX_RETRIES 10#define LINK_WAIT_USLEEP_MIN 90000#define LINK_WAIT_USLEEP_MAX 100000 +#define RETRAIN_WAIT_MAX_RETRIES 10 +#define RETRAIN_WAIT_USLEEP_US 2000#define MSI_IRQ_NUM 32@@ -239,6 +241,17 @@ static int advk_pcie_wait_for_link(struct advk_pcie *pcie)return -ETIMEDOUT ; } +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)) +break ; +udelay (RETRAIN_WAIT_USLEEP_US ); + } +} +static void advk_pcie_setup_hw (struct advk_pcie *pcie) {u32 reg;drivers/pci/controller/pci-aardvark.c advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge, · line 445
Quoted 7 lines
drivers/pci/controller/pci-aardvark.c +4
-0@@ -426,11 +439,20 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,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 );The commit message says "the flag is always set to 0" - therefore I guess you don't *need* to mask out the LT bit here? I assume this is just belt-and-braces but thought I'd check incase I've misunderstood or if your commit message is inaccurate.
Quoted 3 lines
In any case masking out the bit (or adding a comment) makes this code more readable as the reader doesn't need to know what the hardware does with this bit.
Actually vendor eventually responded that the bit was reserved, but during my tests it remains to 0.
So yes I am masking this out mainly for belt-and-braces and legibility.
Quoted 16 lines
Quoted 16 lines
drivers/pci/controller/pci-aardvark.c +6
-1+if (!advk_pcie_link_up (pcie)) + val |= (PCI_EXP_LNKSTA_LT <<16 ); + *value = val; +return PCI_BRIDGE_EMUL_HANDLED ; + } +case PCI_CAP_LIST_ID :case PCI_EXP_DEVCAP :case PCI_EXP_DEVCTL :case PCI_EXP_LNKCAP : -case PCI_EXP_LNKCTL : *value =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg);return PCI_BRIDGE_EMUL_HANDLED ;default :@@ -447,8 +469,13 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,
Quoted 7 lines
drivers/pci/controller/pci-aardvark.c advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge, · line 473
Quoted 4 lines
drivers/pci/controller/pci-aardvark.c +2
-0switch (reg) {case PCI_EXP_DEVCTL : +advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +break ;Why is this here?
Before PCI_EXP_DEVCTL and PCI_EXP_LNKCTL were doing the same thing, but as now PCI_EXP_LNKCTL does extra things (i.e. wait for link to successfully retrain), they do have different behaviours.
So this is here so PCI_EXP_DEVCTL keeps its old behaviour and do not wait for link retrain in case an unrelated (PCI_EXP_LNKCTL_RL) bit is set.
Signature · 1 line
Remi
Quoted 11 lines
Quoted 11 lines
drivers/pci/controller/pci-aardvark.c +3
-0+case PCI_EXP_LNKCTL :advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +if (new &PCI_EXP_LNKCTL_RL ) +advk_pcie_wait_for_retrain (pcie);break ;case PCI_EXP_RTCTL :Signature · 1 line
2.20.1
Andrew Murray
Reviewed-byQuoted 79 lines · Remi Pommarel
Quoted 78 lines · Andrew Murray
Quoted 64 lines · Remi Pommarel
Aardvark's
PCI_EXP_LNKSTA_LTflag in its link status register is not implemented and does not reflect the actual link training state (the flag is always set to 0). In order to support link re-training feature this flag has to be emulated. The Link Training and Status State Machine (LTSSM) flag in Aardvark LMI config register could be used as a link training indicator. Indeed if the LTSSM is in L0 or upper state then link training has completed (see [1]).Unfortunately because after asking a link retraining it takes a while for the LTSSM state to become less than
0x10(due to L0s to recovery state transition delays), LTSSM can still be in L0 while link training has not finished yet. So this waits for link to be in recovery or lesser state before returning after asking for a link retrain.[1] "PCI Express Base Specification", REV. 4.0
PCI Express, February 19 2014, Table 4-14Signed-off-by Remi Pommarel <[email protected]>---
Changes since v1:
- Rename retraining flag field
- Fix DEVCTL register writingChanges since v2:
- Rewrite patch logic so it is more legiblePlease note that I will unlikely be able to answer any comments from May 24th to June 10th.
--- drivers/pci/controller/pci-aardvark.c | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)drivers/pci/controller/pci-aardvark.c +13
-0@@ -180,6 +180,8 @@#define LINK_WAIT_MAX_RETRIES 10#define LINK_WAIT_USLEEP_MIN 90000#define LINK_WAIT_USLEEP_MAX 100000 +#define RETRAIN_WAIT_MAX_RETRIES 10 +#define RETRAIN_WAIT_USLEEP_US 2000#define MSI_IRQ_NUM 32@@ -239,6 +241,17 @@ static int advk_pcie_wait_for_link(struct advk_pcie *pcie)return -ETIMEDOUT ; } +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)) +break ; +udelay (RETRAIN_WAIT_USLEEP_US ); + } +} +static void advk_pcie_setup_hw (struct advk_pcie *pcie) {u32 reg;drivers/pci/controller/pci-aardvark.c advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge, · line 445
Quoted 7 lines
drivers/pci/controller/pci-aardvark.c +4
-0@@ -426,11 +439,20 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,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 );The commit message says "the flag is always set to 0" - therefore I guess you don't *need* to mask out the LT bit here? I assume this is just belt-and-braces but thought I'd check incase I've misunderstood or if your commit message is inaccurate.
Quoted 8 lines
Quoted 3 lines
In any case masking out the bit (or adding a comment) makes this code more readable as the reader doesn't need to know what the hardware does with this bit.
Actually vendor eventually responded that the bit was reserved, but during my tests it remains to 0.
So yes I am masking this out mainly for belt-and-braces and legibility.
Thanks for the clarification.
Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
drivers/pci/controller/pci-aardvark.c +6
-1+if (!advk_pcie_link_up (pcie)) + val |= (PCI_EXP_LNKSTA_LT <<16 ); + *value = val; +return PCI_BRIDGE_EMUL_HANDLED ; + } +case PCI_CAP_LIST_ID :case PCI_EXP_DEVCAP :case PCI_EXP_DEVCTL :case PCI_EXP_LNKCAP : -case PCI_EXP_LNKCTL : *value =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg);return PCI_BRIDGE_EMUL_HANDLED ;default :@@ -447,8 +469,13 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,Quoted 7 lines
drivers/pci/controller/pci-aardvark.c advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge, · line 473
Quoted 4 lines
drivers/pci/controller/pci-aardvark.c +2
-0switch (reg) {case PCI_EXP_DEVCTL : +advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +break ;Why is this here?
Quoted 7 lines
Before
PCI_EXP_DEVCTLandPCI_EXP_LNKCTLwere doing the same thing, but as nowPCI_EXP_LNKCTLdoes extra things (i.e. wait for link to successfully retrain), they do have different behaviours.So this is here so
PCI_EXP_DEVCTLkeeps its old behaviour and do not wait for link retrain in case an unrelated (PCI_EXP_LNKCTL_RL) bit is set.
Oh yes, of course!
Thanks and:
Quoted 15 lines
Signature · 2 lines
-- RemiQuoted 11 lines
Quoted 11 lines
drivers/pci/controller/pci-aardvark.c +3
-0+case PCI_EXP_LNKCTL :advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +if (new &PCI_EXP_LNKCTL_RL ) +advk_pcie_wait_for_retrain (pcie);break ;case PCI_EXP_RTCTL :Signature · 1 line
2.20.1
Marc Zyngier
Tested-byOn Tue, 1 Oct 2019 09:05:46 +0100
Andrew Murray <[email protected]> wrote:
Hi Lorenzo,
Quoted 124 lines · Remi Pommarel
Quoted 79 lines · Andrew Murray
Quoted 78 lines · Remi Pommarel
Quoted 64 lines
Aardvark's
PCI_EXP_LNKSTA_LTflag in its link status register is not implemented and does not reflect the actual link training state (the flag is always set to 0). In order to support link re-training feature this flag has to be emulated. The Link Training and Status State Machine (LTSSM) flag in Aardvark LMI config register could be used as a link training indicator. Indeed if the LTSSM is in L0 or upper state then link training has completed (see [1]).Unfortunately because after asking a link retraining it takes a while for the LTSSM state to become less than
0x10(due to L0s to recovery state transition delays), LTSSM can still be in L0 while link training has not finished yet. So this waits for link to be in recovery or lesser state before returning after asking for a link retrain.[1] "PCI Express Base Specification", REV. 4.0
PCI Express, February 19 2014, Table 4-14Signed-off-by Remi Pommarel <[email protected]>---
Changes since v1:
- Rename retraining flag field
- Fix DEVCTL register writingChanges since v2:
- Rewrite patch logic so it is more legiblePlease note that I will unlikely be able to answer any comments from May 24th to June 10th.
--- drivers/pci/controller/pci-aardvark.c | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)drivers/pci/controller/pci-aardvark.c +13
-0@@ -180,6 +180,8 @@#define LINK_WAIT_MAX_RETRIES 10#define LINK_WAIT_USLEEP_MIN 90000#define LINK_WAIT_USLEEP_MAX 100000 +#define RETRAIN_WAIT_MAX_RETRIES 10 +#define RETRAIN_WAIT_USLEEP_US 2000#define MSI_IRQ_NUM 32@@ -239,6 +241,17 @@ static int advk_pcie_wait_for_link(struct advk_pcie *pcie)return -ETIMEDOUT ; } +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)) +break ; +udelay (RETRAIN_WAIT_USLEEP_US ); + } +} +static void advk_pcie_setup_hw (struct advk_pcie *pcie) {u32 reg;drivers/pci/controller/pci-aardvark.c advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge, · line 445
Quoted 7 lines
drivers/pci/controller/pci-aardvark.c +4
-0@@ -426,11 +439,20 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,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 );The commit message says "the flag is always set to 0" - therefore I guess you don't *need* to mask out the LT bit here? I assume this is just belt-and-braces but thought I'd check incase I've misunderstood or if your commit message is inaccurate.
Quoted 8 lines
Quoted 3 lines
In any case masking out the bit (or adding a comment) makes this code more readable as the reader doesn't need to know what the hardware does with this bit.
Actually vendor eventually responded that the bit was reserved, but during my tests it remains to 0.
So yes I am masking this out mainly for belt-and-braces and legibility.
Thanks for the clarification.
Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
drivers/pci/controller/pci-aardvark.c +6
-1+if (!advk_pcie_link_up (pcie)) + val |= (PCI_EXP_LNKSTA_LT <<16 ); + *value = val; +return PCI_BRIDGE_EMUL_HANDLED ; + } +case PCI_CAP_LIST_ID :case PCI_EXP_DEVCAP :case PCI_EXP_DEVCTL :case PCI_EXP_LNKCAP : -case PCI_EXP_LNKCTL : *value =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg);return PCI_BRIDGE_EMUL_HANDLED ;default :@@ -447,8 +469,13 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,Quoted 7 lines
drivers/pci/controller/pci-aardvark.c advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge, · line 473
Quoted 4 lines
drivers/pci/controller/pci-aardvark.c +2
-0switch (reg) {case PCI_EXP_DEVCTL : +advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +break ;Why is this here?
Quoted 7 lines
Before
PCI_EXP_DEVCTLandPCI_EXP_LNKCTLwere doing the same thing, but as nowPCI_EXP_LNKCTLdoes extra things (i.e. wait for link to successfully retrain), they do have different behaviours.So this is here so
PCI_EXP_DEVCTLkeeps its old behaviour and do not wait for link retrain in case an unrelated (PCI_EXP_LNKCTL_RL) bit is set.
Quoted 5 lines
Oh yes, of course!
Thanks and:
Reviewed-by Andrew Murray <[email protected]>
Is there any hope for this workaround to make it into 5.4?
My EspressoBin (which is blessed with this joke of a PCIe controller) is pretty much a doorstop without it and dies with a SError early at boot.
FWIW:
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 137 lines · Marc Zyngier
On Tue, 1 Oct 2019 09:05:46 +0100
Andrew Murray <[email protected]> wrote:Hi Lorenzo,
Quoted 124 lines · Remi Pommarel
Quoted 79 lines · Andrew Murray
Quoted 78 lines · Remi Pommarel
Quoted 64 lines
Aardvark's
PCI_EXP_LNKSTA_LTflag in its link status register is not implemented and does not reflect the actual link training state (the flag is always set to 0). In order to support link re-training feature this flag has to be emulated. The Link Training and Status State Machine (LTSSM) flag in Aardvark LMI config register could be used as a link training indicator. Indeed if the LTSSM is in L0 or upper state then link training has completed (see [1]).Unfortunately because after asking a link retraining it takes a while for the LTSSM state to become less than
0x10(due to L0s to recovery state transition delays), LTSSM can still be in L0 while link training has not finished yet. So this waits for link to be in recovery or lesser state before returning after asking for a link retrain.[1] "PCI Express Base Specification", REV. 4.0
PCI Express, February 19 2014, Table 4-14Signed-off-by Remi Pommarel <[email protected]>---
Changes since v1:
- Rename retraining flag field
- Fix DEVCTL register writingChanges since v2:
- Rewrite patch logic so it is more legiblePlease note that I will unlikely be able to answer any comments from May 24th to June 10th.
--- drivers/pci/controller/pci-aardvark.c | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)drivers/pci/controller/pci-aardvark.c +13
-0@@ -180,6 +180,8 @@#define LINK_WAIT_MAX_RETRIES 10#define LINK_WAIT_USLEEP_MIN 90000#define LINK_WAIT_USLEEP_MAX 100000 +#define RETRAIN_WAIT_MAX_RETRIES 10 +#define RETRAIN_WAIT_USLEEP_US 2000#define MSI_IRQ_NUM 32@@ -239,6 +241,17 @@ static int advk_pcie_wait_for_link(struct advk_pcie *pcie)return -ETIMEDOUT ; } +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)) +break ; +udelay (RETRAIN_WAIT_USLEEP_US ); + } +} +static void advk_pcie_setup_hw (struct advk_pcie *pcie) {u32 reg;drivers/pci/controller/pci-aardvark.c advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge, · line 445
Quoted 7 lines
drivers/pci/controller/pci-aardvark.c +4
-0@@ -426,11 +439,20 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,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 );The commit message says "the flag is always set to 0" - therefore I guess you don't *need* to mask out the LT bit here? I assume this is just belt-and-braces but thought I'd check incase I've misunderstood or if your commit message is inaccurate.
Quoted 8 lines
Quoted 3 lines
In any case masking out the bit (or adding a comment) makes this code more readable as the reader doesn't need to know what the hardware does with this bit.
Actually vendor eventually responded that the bit was reserved, but during my tests it remains to 0.
So yes I am masking this out mainly for belt-and-braces and legibility.
Thanks for the clarification.
Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
drivers/pci/controller/pci-aardvark.c +6
-1+if (!advk_pcie_link_up (pcie)) + val |= (PCI_EXP_LNKSTA_LT <<16 ); + *value = val; +return PCI_BRIDGE_EMUL_HANDLED ; + } +case PCI_CAP_LIST_ID :case PCI_EXP_DEVCAP :case PCI_EXP_DEVCTL :case PCI_EXP_LNKCAP : -case PCI_EXP_LNKCTL : *value =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg);return PCI_BRIDGE_EMUL_HANDLED ;default :@@ -447,8 +469,13 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,Quoted 7 lines
drivers/pci/controller/pci-aardvark.c advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge, · line 473
Quoted 4 lines
drivers/pci/controller/pci-aardvark.c +2
-0switch (reg) {case PCI_EXP_DEVCTL : +advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +break ;Why is this here?
Quoted 7 lines
Before
PCI_EXP_DEVCTLandPCI_EXP_LNKCTLwere doing the same thing, but as nowPCI_EXP_LNKCTLdoes extra things (i.e. wait for link to successfully retrain), they do have different behaviours.So this is here so
PCI_EXP_DEVCTLkeeps its old behaviour and do not wait for link retrain in case an unrelated (PCI_EXP_LNKCTL_RL) bit is set.Quoted 5 lines
Oh yes, of course!
Thanks and:
Reviewed-by Andrew Murray <[email protected]>Is there any hope for this workaround to make it into 5.4?
Quoted 7 lines
My EspressoBin (which is blessed with this joke of a PCIe controller) is pretty much a doorstop without it and dies with a SError early at boot.
FWIW:
Tested-by Marc Zyngier <[email protected]>
Hi Marc,
First thing I will have to mark it as a Fixes: (if Remi can provide me with a tag that'd be great), usually we send fixes at -rc* for patches that fix code that went in the current (eg 5.4) material, I will ask Bjorn to see if we can send this in one of the upcoming -rc* even if it fixes older code.
Thanks,
Lorenzo
Hi Lorenzo, Marc,
Quoted 146 lines · Lorenzo Pieralisi
Quoted 137 lines · Marc Zyngier
On Tue, 1 Oct 2019 09:05:46 +0100
Andrew Murray <[email protected]> wrote:Hi Lorenzo,
Quoted 124 lines · Remi Pommarel
Quoted 79 lines · Andrew Murray
Quoted 78 lines · Remi Pommarel
Quoted 64 lines
Aardvark's
PCI_EXP_LNKSTA_LTflag in its link status register is not implemented and does not reflect the actual link training state (the flag is always set to 0). In order to support link re-training feature this flag has to be emulated. The Link Training and Status State Machine (LTSSM) flag in Aardvark LMI config register could be used as a link training indicator. Indeed if the LTSSM is in L0 or upper state then link training has completed (see [1]).Unfortunately because after asking a link retraining it takes a while for the LTSSM state to become less than
0x10(due to L0s to recovery state transition delays), LTSSM can still be in L0 while link training has not finished yet. So this waits for link to be in recovery or lesser state before returning after asking for a link retrain.[1] "PCI Express Base Specification", REV. 4.0
PCI Express, February 19 2014, Table 4-14Signed-off-by Remi Pommarel <[email protected]>---
Changes since v1:
- Rename retraining flag field
- Fix DEVCTL register writingChanges since v2:
- Rewrite patch logic so it is more legiblePlease note that I will unlikely be able to answer any comments from May 24th to June 10th.
--- drivers/pci/controller/pci-aardvark.c | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)drivers/pci/controller/pci-aardvark.c +13
-0@@ -180,6 +180,8 @@#define LINK_WAIT_MAX_RETRIES 10#define LINK_WAIT_USLEEP_MIN 90000#define LINK_WAIT_USLEEP_MAX 100000 +#define RETRAIN_WAIT_MAX_RETRIES 10 +#define RETRAIN_WAIT_USLEEP_US 2000#define MSI_IRQ_NUM 32@@ -239,6 +241,17 @@ static int advk_pcie_wait_for_link(struct advk_pcie *pcie)return -ETIMEDOUT ; } +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)) +break ; +udelay (RETRAIN_WAIT_USLEEP_US ); + } +} +static void advk_pcie_setup_hw (struct advk_pcie *pcie) {u32 reg;drivers/pci/controller/pci-aardvark.c advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge, · line 445
Quoted 7 lines
drivers/pci/controller/pci-aardvark.c +4
-0@@ -426,11 +439,20 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,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 );The commit message says "the flag is always set to 0" - therefore I guess you don't *need* to mask out the LT bit here? I assume this is just belt-and-braces but thought I'd check incase I've misunderstood or if your commit message is inaccurate.
Quoted 8 lines
Quoted 3 lines
In any case masking out the bit (or adding a comment) makes this code more readable as the reader doesn't need to know what the hardware does with this bit.
Actually vendor eventually responded that the bit was reserved, but during my tests it remains to 0.
So yes I am masking this out mainly for belt-and-braces and legibility.
Thanks for the clarification.
Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
drivers/pci/controller/pci-aardvark.c +6
-1+if (!advk_pcie_link_up (pcie)) + val |= (PCI_EXP_LNKSTA_LT <<16 ); + *value = val; +return PCI_BRIDGE_EMUL_HANDLED ; + } +case PCI_CAP_LIST_ID :case PCI_EXP_DEVCAP :case PCI_EXP_DEVCTL :case PCI_EXP_LNKCAP : -case PCI_EXP_LNKCTL : *value =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg);return PCI_BRIDGE_EMUL_HANDLED ;default :@@ -447,8 +469,13 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,Quoted 7 lines
drivers/pci/controller/pci-aardvark.c advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge, · line 473
Quoted 4 lines
drivers/pci/controller/pci-aardvark.c +2
-0switch (reg) {case PCI_EXP_DEVCTL : +advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +break ;Why is this here?
Quoted 7 lines
Before
PCI_EXP_DEVCTLandPCI_EXP_LNKCTLwere doing the same thing, but as nowPCI_EXP_LNKCTLdoes extra things (i.e. wait for link to successfully retrain), they do have different behaviours.So this is here so
PCI_EXP_DEVCTLkeeps its old behaviour and do not wait for link retrain in case an unrelated (PCI_EXP_LNKCTL_RL) bit is set.Quoted 5 lines
Oh yes, of course!
Thanks and:
Reviewed-by Andrew Murray <[email protected]>Is there any hope for this workaround to make it into 5.4?
Quoted 7 lines
My EspressoBin (which is blessed with this joke of a PCIe controller) is pretty much a doorstop without it and dies with a SError early at boot.
FWIW:
Tested-by Marc Zyngier <[email protected]>
Quoted 7 lines
Hi Marc,
First thing I will have to mark it as a Fixes: (if Remi can provide me with a tag that'd be great), usually we send fixes at -rc* for patches that fix code that went in the current (eg 5.4) material, I will ask Bjorn to see if we can send this in one of the upcoming -rc* even if it fixes older code.
Sure, I think this could be considered a fix for the following commit :
Moreover, Marc, I am also a bit supprised that you did not have to use
[1] to even be able to boot.
Also if you want to be completely immune to this kind of SError (that could theoretically happen if the link goes down for other reasons than being retrained) you would have to use mainline ATF along with [2]. But the chances to hit that are low (could only happen in case of link errors).
[1] [v3] PCI: aardvark: Use LTSSM state to build link training flag
https://patchwork.ozlabs.org/patch/1115864/ [2] [v3] PCI: aardvark: Don't rely on jiffies while holding spinlock https://patchwork.ozlabs.org/patch/1168349/
Signature · 1 line
Remi
Hi Remi,
Quoted 190 lines · Remi Pommarel
Hi Lorenzo, Marc,
Quoted 179 lines · Lorenzo Pieralisi
Quoted 8 lines · Marc Zyngier
On Tue, 1 Oct 2019 09:05:46 +0100
Andrew Murray <[email protected]> wrote:Hi Lorenzo,
Quoted 3 lines · Remi Pommarel
Quoted 2 lines · Andrew Murray
Quoted 1 line
On Wed, May 22, 2019 at 11:33:51PM +0200, Remi Pommarel
Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Aardvark's
PCI_EXP_LNKSTA_LTflag in its link statusregister is not
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
implemented and does not reflect the actual link training
state (the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
flag is always set to 0). In order to support link
re-training feature
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
this flag has to be emulated. The Link Training and Status
State
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Machine (LTSSM) flag in Aardvark LMI config register could
be used as
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
a link training indicator. Indeed if the LTSSM is in L0 or
upper state
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
then link training has completed (see [1]).
Unfortunately because after asking a link retraining it
takes a while
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
for the LTSSM state to become less than
0x10(due to L0sto recovery
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
state transition delays), LTSSM can still be in L0 while
link training
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
has not finished yet. So this waits for link to be in
recovery or lesser
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
state before returning after asking for a link retrain.
[1] "PCI Express Base Specification", REV. 4.0
PCI Express, February 19 2014, Table 4-14Signed-off-by Remi Pommarel <[email protected]>---
Changes since v1:
- Rename retraining flag field
- Fix DEVCTL register writingQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Changes since v2:
- Rewrite patch logic so it is more legiblePlease note that I will unlikely be able to answer any
comments from May
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
24th to June 10th.
--- drivers/pci/controller/pci-aardvark.c | 29++++++++++++++++++++++++++-
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Review
Quoted 3 lines
1 file changed, 28 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/pci/controller/pci-aardvark.cQuoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
index
134e0306ff00..8803083b2174100644drivers/pci/controller/pci-aardvark.c +2
-0@@ -180,6 +180,8 @@#define LINK_WAIT_MAX_RETRIES 10#define LINK_WAIT_USLEEP_MIN 90000#define LINK_WAIT_USLEEP_MAX 100000 +#define RETRAIN_WAIT_MAX_RETRIES 10 +#define RETRAIN_WAIT_USLEEP_US 2000Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/pci/controller/pci-aardvark.c static int
Quoted 3 lines
drivers/pci/controller/pci-aardvark.c +0
-0#define MSI_IRQ_NUM 32@@ -239,6 +241,17 @@ static int
advk_pcie_wait_for_link(struct advk_pcie *pcie)Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/pci/controller/pci-aardvark.c static int · line 244
Quoted 4 lines
drivers/pci/controller/pci-aardvark.c +1
-0return -ETIMEDOUT ; } +static void advk_pcie_wait_for_retrain(struct advk_pcie*pcie)
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/pci/controller/pci-aardvark.c static int · line 248
Quoted 4 lines
drivers/pci/controller/pci-aardvark.c +4
-0+{ +size_t retries; + + for (retries = 0; retries < RETRAIN_WAIT_MAX_RETRIES;++retries) {
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/pci/controller/pci-aardvark.c
Quoted 10 lines
drivers/pci/controller/pci-aardvark.c +6
-0+if (!advk_pcie_link_up (pcie)) +break ; +udelay (RETRAIN_WAIT_USLEEP_US ); + } +} +static void advk_pcie_setup_hw (struct advk_pcie *pcie) {u32 reg;@@ -426,11 +439,20 @@advk_pci_bridge_emul_pcie_conf_read(struct
pci_bridge_emul*bridge,Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/pci/controller/pci-aardvark.c line 443
Quoted 5 lines
drivers/pci/controller/pci-aardvark.c +2
-0return PCI_BRIDGE_EMUL_HANDLED ; } +case PCI_EXP_LNKCTL : { +/* u32 contains both PCI_EXP_LNKCTL and PCI_EXP_LNKSTA */
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/pci/controller/pci-aardvark.c line 444
Quoted 1 line
drivers/pci/controller/pci-aardvark.c +1
-0+u32 val =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg)&
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/pci/controller/pci-aardvark.c line 445
Quoted 1 line
drivers/pci/controller/pci-aardvark.c +1
-0+ ~(PCI_EXP_LNKSTA_LT <<16 );The commit message says "the flag is always set to 0" -
therefore I guess
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
you don't *need* to mask out the LT bit here? I assume this
is just
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
belt-and-braces but thought I'd check incase I've
misunderstood or if your
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
commit message is inaccurate.
In any case masking out the bit (or adding a comment) makes
this code more
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
readable as the reader doesn't need to know what the
hardware does with this
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
bit.
Actually vendor eventually responded that the bit was
reserved, but
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
during my tests it remains to 0.
So yes I am masking this out mainly for belt-and-braces and
legibility.
Quoted 4 lines
Quoted 4 lines
Thanks for the clarification.
Quoted 1 line
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/pci/controller/pci-aardvark.c +6
-0+if (!advk_pcie_link_up (pcie)) + val |= (PCI_EXP_LNKSTA_LT <<16 ); + *value = val; +return PCI_BRIDGE_EMUL_HANDLED ; + } +case PCI_CAP_LIST_ID :Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/pci/controller/pci-aardvark.c
Quoted 8 lines
drivers/pci/controller/pci-aardvark.c +0
-1case PCI_EXP_DEVCAP :case PCI_EXP_DEVCTL :case PCI_EXP_LNKCAP : -case PCI_EXP_LNKCTL : *value =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg);return PCI_BRIDGE_EMUL_HANDLED ;default :@@ -447,8 +469,13 @@advk_pci_bridge_emul_pcie_conf_write(struct
pci_bridge_emul*bridge,Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
drivers/pci/controller/pci-aardvark.c line 472
Quoted 5 lines
drivers/pci/controller/pci-aardvark.c +2
-0switch (reg) {case PCI_EXP_DEVCTL : +advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +break ;Why is this here?
Before
PCI_EXP_DEVCTLandPCI_EXP_LNKCTLwere doing the samething, but
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
as now
PCI_EXP_LNKCTLdoes extra things (i.e. wait for link to successfully retrain), they do have different behaviours.So this is here so
PCI_EXP_DEVCTLkeeps its old behaviour anddo not
Quoted 1 line
Quoted 1 line
Quoted 1 line
wait for link retrain in case an unrelated (
PCI_EXP_LNKCTL_RL)bit is
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
set.
Oh yes, of course!
Thanks and:
Reviewed-by Andrew Murray <[email protected]>Is there any hope for this workaround to make it into 5.4?
My EspressoBin (which is blessed with this joke of a PCIe
controller)
Quoted 1 line
is pretty much a doorstop without it and dies with a SError early
at
Quoted 5 lines
boot.
FWIW:
Tested-by Marc Zyngier <[email protected]>Quoted 7 lines
Hi Marc,
First thing I will have to mark it as a Fixes: (if Remi can provide me with a tag that'd be great), usually we send fixes at -rc* for patches that fix code that went in the current (eg 5.4) material, I will ask Bjorn to see if we can send this in one of the upcoming -rc* even if it fixes older code.
Quoted 6 lines
Sure, I think this could be considered a fix for the following commit :
Fixes 8a3ebd8de328 ("PCI: aardvark: Implement emulated root PCIbridge config space")
Moreover, Marc, I am also a bit supprised that you did not have to use
[1] to even be able to boot.
No, I don't have that one, and yet the system boots fine (although PCI doesn't get much use on this box). I guess I'm lucky...
Quoted 5 lines
Also if you want to be completely immune to this kind of SError (that could theoretically happen if the link goes down for other reasons than being retrained) you would have to use mainline ATF along with [2]. But the chances to hit that are low (could only happen in case of link errors).
Now you've got me worried. Can you point me to that ATF patch? I'm quite curious as to how you recover from an SError on a v8.0 CPU given that it has no syndrome information and may as well signal "CPU on fire!"...
Thanks,
M.
Quoted 5 lines
[1] [v3] PCI: aardvark: Use LTSSM state to build link training flag
https://patchwork.ozlabs.org/patch/1115864/ [2] [v3] PCI: aardvark: Don't rely on jiffies while holding spinlock https://patchwork.ozlabs.org/patch/1168349/
Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 209 lines · Marc Zyngier
Hi Remi,
Quoted 190 lines · Remi Pommarel
Hi Lorenzo, Marc,
Quoted 179 lines · Lorenzo Pieralisi
Quoted 8 lines · Marc Zyngier
On Tue, 1 Oct 2019 09:05:46 +0100
Andrew Murray <[email protected]> wrote:Hi Lorenzo,
Quoted 3 lines · Remi Pommarel
Quoted 2 lines · Andrew Murray
Quoted 1 line
On Wed, May 22, 2019 at 11:33:51PM +0200, Remi Pommarel
Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Aardvark's
PCI_EXP_LNKSTA_LTflag in its link statusregister is not
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
implemented and does not reflect the actual link training
state (the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
flag is always set to 0). In order to support link
re-training feature
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
this flag has to be emulated. The Link Training and Status
State
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Machine (LTSSM) flag in Aardvark LMI config register could
be used as
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
a link training indicator. Indeed if the LTSSM is in L0 or
upper state
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
then link training has completed (see [1]).
Unfortunately because after asking a link retraining it
takes a while
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
for the LTSSM state to become less than
0x10(due to L0sto recovery
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
state transition delays), LTSSM can still be in L0 while
link training
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
has not finished yet. So this waits for link to be in
recovery or lesser
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
state before returning after asking for a link retrain.
[1] "PCI Express Base Specification", REV. 4.0
PCI Express, February 19 2014, Table 4-14Signed-off-by Remi Pommarel <[email protected]>---
Changes since v1:
- Rename retraining flag field
- Fix DEVCTL register writingQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Changes since v2:
- Rewrite patch logic so it is more legiblePlease note that I will unlikely be able to answer any
comments from May
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
24th to June 10th.
--- drivers/pci/controller/pci-aardvark.c | 29++++++++++++++++++++++++++-
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Review
Quoted 3 lines
1 file changed, 28 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/pci/controller/pci-aardvark.cQuoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
index
134e0306ff00..8803083b2174100644drivers/pci/controller/pci-aardvark.c +2
-0@@ -180,6 +180,8 @@#define LINK_WAIT_MAX_RETRIES 10#define LINK_WAIT_USLEEP_MIN 90000#define LINK_WAIT_USLEEP_MAX 100000 +#define RETRAIN_WAIT_MAX_RETRIES 10 +#define RETRAIN_WAIT_USLEEP_US 2000Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/pci/controller/pci-aardvark.c static int
Quoted 3 lines
drivers/pci/controller/pci-aardvark.c +0
-0#define MSI_IRQ_NUM 32@@ -239,6 +241,17 @@ static int
advk_pcie_wait_for_link(struct advk_pcie *pcie)Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/pci/controller/pci-aardvark.c static int · line 244
Quoted 4 lines
drivers/pci/controller/pci-aardvark.c +1
-0return -ETIMEDOUT ; } +static void advk_pcie_wait_for_retrain(struct advk_pcie*pcie)
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/pci/controller/pci-aardvark.c static int · line 248
Quoted 4 lines
drivers/pci/controller/pci-aardvark.c +4
-0+{ +size_t retries; + + for (retries = 0; retries < RETRAIN_WAIT_MAX_RETRIES;++retries) {
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/pci/controller/pci-aardvark.c
Quoted 10 lines
drivers/pci/controller/pci-aardvark.c +6
-0+if (!advk_pcie_link_up (pcie)) +break ; +udelay (RETRAIN_WAIT_USLEEP_US ); + } +} +static void advk_pcie_setup_hw (struct advk_pcie *pcie) {u32 reg;@@ -426,11 +439,20 @@advk_pci_bridge_emul_pcie_conf_read(struct
pci_bridge_emul*bridge,Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/pci/controller/pci-aardvark.c line 443
Quoted 5 lines
drivers/pci/controller/pci-aardvark.c +2
-0return PCI_BRIDGE_EMUL_HANDLED ; } +case PCI_EXP_LNKCTL : { +/* u32 contains both PCI_EXP_LNKCTL and PCI_EXP_LNKSTA */
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/pci/controller/pci-aardvark.c line 444
Quoted 1 line
drivers/pci/controller/pci-aardvark.c +1
-0+u32 val =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg)&
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/pci/controller/pci-aardvark.c line 445
Quoted 1 line
drivers/pci/controller/pci-aardvark.c +1
-0+ ~(PCI_EXP_LNKSTA_LT <<16 );The commit message says "the flag is always set to 0" -
therefore I guess
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
you don't *need* to mask out the LT bit here? I assume this
is just
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
belt-and-braces but thought I'd check incase I've
misunderstood or if your
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
commit message is inaccurate.
In any case masking out the bit (or adding a comment) makes
this code more
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
readable as the reader doesn't need to know what the
hardware does with this
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
bit.
Actually vendor eventually responded that the bit was
reserved, but
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
during my tests it remains to 0.
So yes I am masking this out mainly for belt-and-braces and
legibility.
Quoted 4 lines
Quoted 4 lines
Thanks for the clarification.
Quoted 1 line
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/pci/controller/pci-aardvark.c +6
-0+if (!advk_pcie_link_up (pcie)) + val |= (PCI_EXP_LNKSTA_LT <<16 ); + *value = val; +return PCI_BRIDGE_EMUL_HANDLED ; + } +case PCI_CAP_LIST_ID :Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/pci/controller/pci-aardvark.c
Quoted 8 lines
drivers/pci/controller/pci-aardvark.c +0
-1case PCI_EXP_DEVCAP :case PCI_EXP_DEVCTL :case PCI_EXP_LNKCAP : -case PCI_EXP_LNKCTL : *value =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg);return PCI_BRIDGE_EMUL_HANDLED ;default :@@ -447,8 +469,13 @@advk_pci_bridge_emul_pcie_conf_write(struct
pci_bridge_emul*bridge,Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
drivers/pci/controller/pci-aardvark.c line 472
Quoted 5 lines
drivers/pci/controller/pci-aardvark.c +2
-0switch (reg) {case PCI_EXP_DEVCTL : +advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +break ;Why is this here?
Before
PCI_EXP_DEVCTLandPCI_EXP_LNKCTLwere doing the samething, but
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
as now
PCI_EXP_LNKCTLdoes extra things (i.e. wait for link to successfully retrain), they do have different behaviours.So this is here so
PCI_EXP_DEVCTLkeeps its old behaviour anddo not
Quoted 1 line
Quoted 1 line
Quoted 1 line
wait for link retrain in case an unrelated (
PCI_EXP_LNKCTL_RL)bit is
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
set.
Oh yes, of course!
Thanks and:
Reviewed-by Andrew Murray <[email protected]>Is there any hope for this workaround to make it into 5.4?
My EspressoBin (which is blessed with this joke of a PCIe
controller)
Quoted 1 line
is pretty much a doorstop without it and dies with a SError early
at
Quoted 5 lines
boot.
FWIW:
Tested-by Marc Zyngier <[email protected]>Quoted 7 lines
Hi Marc,
First thing I will have to mark it as a Fixes: (if Remi can provide me with a tag that'd be great), usually we send fixes at -rc* for patches that fix code that went in the current (eg 5.4) material, I will ask Bjorn to see if we can send this in one of the upcoming -rc* even if it fixes older code.
Quoted 6 lines
Sure, I think this could be considered a fix for the following commit :
Fixes 8a3ebd8de328 ("PCI: aardvark: Implement emulated root PCIbridge config space")
Moreover, Marc, I am also a bit supprised that you did not have to use
[1] to even be able to boot.No, I don't have that one, and yet the system boots fine (although PCI doesn't get much use on this box). I guess I'm lucky...
Quoted 5 lines
Also if you want to be completely immune to this kind of SError (that could theoretically happen if the link goes down for other reasons than being retrained) you would have to use mainline ATF along with [2]. But the chances to hit that are low (could only happen in case of link errors).
Quoted 4 lines
Now you've got me worried. Can you point me to that ATF patch? I'm quite curious as to how you recover from an SError on a v8.0 CPU given that it has no syndrome information and may as well signal "CPU on fire!"...
The patch is at [1]. Please note that this is done quite similarly for rcar.
[1] https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/1541
Signature · 1 line
Remi
Quoted 5 lines · Remi Pommarel
Quoted 4 lines · Marc Zyngier
Hi Remi,
Quoted 1 line · Remi Pommarel
Hi Lorenzo, Marc,
[...]
Quoted 26 lines
Quoted 16 lines
Quoted 1 line
Sure, I think this could be considered a fix for the following
commit :
Quoted 4 lines
Fixes 8a3ebd8de328 ("PCI: aardvark: Implement emulated root PCIbridge config space")
Moreover, Marc, I am also a bit supprised that you did not have to
use
Quoted 1 line
[1] to even be able to boot.
No, I don't have that one, and yet the system boots fine (although PCI doesn't get much use on this box). I guess I'm lucky...
Quoted 1 line
Also if you want to be completely immune to this kind of SError
(that
Quoted 1 line
could theoretically happen if the link goes down for other reasons
than
Quoted 9 lines
Quoted 1 line
being retrained) you would have to use mainline ATF along with
[2]. But
Quoted 2 lines
the chances to hit that are low (could only happen in case of link errors).
Now you've got me worried. Can you point me to that ATF patch? I'm quite curious as to how you recover from an SError on a v8.0 CPU given that it has no syndrome information and may as well signal "CPU on fire!"...
Quoted 4 lines
The patch is at [1]. Please note that this is done quite similarly for rcar.
[1] https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/1541
That patch, without any other information, looks quite flaky. Unless there is a strong guarantee that ESR_EL3.ISS==2 only when the PCIe controller goes wrong, it looks like this only papers over the issue...
That's pretty much independent from the patch at hand in this thread, but I certainly wouldn't trust this ATF patch without some more information about how the fault is reported to the CPU.
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 23 lines · Remi Pommarel
Aardvark's
PCI_EXP_LNKSTA_LTflag in its link status register is not implemented and does not reflect the actual link training state (the flag is always set to 0). In order to support link re-training feature this flag has to be emulated. The Link Training and Status State Machine (LTSSM) flag in Aardvark LMI config register could be used as a link training indicator. Indeed if the LTSSM is in L0 or upper state then link training has completed (see [1]).Unfortunately because after asking a link retraining it takes a while for the LTSSM state to become less than
0x10(due to L0s to recovery state transition delays), LTSSM can still be in L0 while link training has not finished yet. So this waits for link to be in recovery or lesser state before returning after asking for a link retrain.[1] "PCI Express Base Specification", REV. 4.0
PCI Express, February 19 2014, Table 4-14Signed-off-by Remi Pommarel <[email protected]>---
Changes since v1:
- Rename retraining flag field
- Fix DEVCTL register writing
Quoted 8 lines
Changes since v2:
- Rewrite patch logic so it is more legiblePlease note that I will unlikely be able to answer any comments from May 24th to June 10th.
--- drivers/pci/controller/pci-aardvark.c | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
Merged in pci/aardvark, to be decided if we target one of the upcoming -rc* or v5.5.
Thanks and apologies for the delay.
Lorenzo
Quoted 71 lines
drivers/pci/controller/pci-aardvark.c +28
-1@@ -180,6 +180,8 @@#define LINK_WAIT_MAX_RETRIES 10#define LINK_WAIT_USLEEP_MIN 90000#define LINK_WAIT_USLEEP_MAX 100000 +#define RETRAIN_WAIT_MAX_RETRIES 10 +#define RETRAIN_WAIT_USLEEP_US 2000#define MSI_IRQ_NUM 32@@ -239,6 +241,17 @@ static int advk_pcie_wait_for_link(struct advk_pcie *pcie)return -ETIMEDOUT ; } +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)) +break ; +udelay (RETRAIN_WAIT_USLEEP_US ); + } +} +static void advk_pcie_setup_hw (struct advk_pcie *pcie) {u32 reg;@@ -426,11 +439,20 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,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_up (pcie)) + val |= (PCI_EXP_LNKSTA_LT <<16 ); + *value = val; +return PCI_BRIDGE_EMUL_HANDLED ; + } +case PCI_CAP_LIST_ID :case PCI_EXP_DEVCAP :case PCI_EXP_DEVCTL :case PCI_EXP_LNKCAP : -case PCI_EXP_LNKCTL : *value =advk_readl (pcie,PCIE_CORE_PCIEXP_CAP + reg);return PCI_BRIDGE_EMUL_HANDLED ;default :@@ -447,8 +469,13 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,switch (reg) {case PCI_EXP_DEVCTL : +advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +break ; +case PCI_EXP_LNKCTL :advk_writel (pcie, new,PCIE_CORE_PCIEXP_CAP + reg); +if (new &PCI_EXP_LNKCTL_RL ) +advk_pcie_wait_for_retrain (pcie);break ;case PCI_EXP_RTCTL :Signature · 1 line
2.20.1